/*
 * $Log: dOptionScale.java,v $
# Revision 1.1  1996/07/11  01:22:05  hma
# Initial revision
#
 */
//////////////////////////////////////////////////
package gui;

// Standard packages.
import java.applet.Applet;
import java.awt.*;
import java.util.*;
import java.net.URL;
import java.net.MalformedURLException;

// Network Design Tool Packages.
import general.GeneralProperties;
import physical.PhysicalGraph;
import physical.Place;
import gui.FramedPanel;
import gui.GUICanvas;

//////////////////////////////////////////////////
public class dOptionScale extends Dialog {

private GeneralProperties gpData;
private FramedPanel pMain;		   
private TextField tfScale;	    // inputs scale
private FramedPanel pButtons;	    // Holds buttons.
private Button bOk;		    // Ok button.
private Button bCancel;		    // Cancel button.
private Button bHelp;		    // Help button.
//************************************************
public dOptionScale(Frame parent, GeneralProperties gp) {
// REQUIRES: nothing.
// RETURNS: nothing.
// PROMISES: Creates and displays dialog box Edit|Add|Place.

  super(parent, "Set Scale", true);

  gpData = gp;
  double s = ((GUICanvas)gpData.get("Canvas")).getScale();

  // Making the Main panel.
  pMain = new FramedPanel(FramedPanel.SINGLE_BORDER);
  pMain.add(new Label("Scale: ", Label.LEFT));
  pMain.add(tfScale = new TextField("" + s, 10));
  add("Center", pMain);

  // Add ok, cancel and help buttons at the bottom in a separate panel.
  pButtons = new FramedPanel(FramedPanel.SINGLE_BORDER);
  pButtons.add(bOk = new Button("Ok"));
  pButtons.add(bCancel = new Button("Cancel"));
  pButtons.add(bHelp = new Button("Help"));
  add("South", pButtons);
  pack();
  show();
}

//************************************************
public boolean handleEvent(Event e) {
  if(e.id == Event.KEY_PRESS) {	    // To let components handle keyboard
				    // events. (required due to bug in java). 
    return false;
  }
  else if(e.target == bOk) {
    try{
      double s = (new Double(tfScale.getText())).doubleValue();
      GUICanvas c = (GUICanvas)gpData.get("Canvas");
      c.setScale(s);
      c.paint(c.getGraphics());
      dispose();
    }
    catch(NumberFormatException nfe) {
      new dMessageBox((Frame)getParent(), "Error", "Illegal Input!", gpData,
		  false, null);
    }
  }
  else if(e.target == bCancel) {
    dispose();
  }
  else if(e.target == bHelp) {
    String HelpURL = (String)gpData.
      get("Help URL for Option|Scale Dialog Box"); 
    if( ((Boolean)gpData.get("In Applet?")).equals(Boolean.TRUE) ) {
      // Open connection to URL & display help. 
      try {
	Applet app = (Applet)gpData.get("Applet");
	app.getAppletContext().showDocument(new URL(HelpURL)); 
      }
      catch(MalformedURLException mfue) {
	new dMessageBox((Frame)getParent(), "Help", "Help URL " + HelpURL
			+ " doesn't exist!", gpData, false, null);
      }
    }
    else {
      // Display Help Message in a Dialog Box.
      String HelpMsg = "Please visit " + HelpURL + " for help.";
      new dMessageBox((Frame)getParent(), "Help", HelpMsg, gpData, false,
		      null); 
    }
  }
  else
    super.handleEvent(e);

  return true;
}
//************************************************
} // End of class dOptionScale
//////////////////////////////////////////////////
