/*
 * $Log$
 */
//////////////////////////////////////////////////
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 network.*;
import general.GeneralProperties;
import general.Set;
import gui.FramedPanel;
//////////////////////////////////////////////////
public class dOptimizeLowerBound extends GridBagDialog {
  public TextArea tx;
  public Label lbLowerBound;
  private Button bOk;
  private Button bStop;
  private Button bHelp;
  private Canvas c;
  private Panel pButtons;
  private GeneralProperties gpData;

//************************************************
/*
public dOptimizeLowerBound(Frame parent, GeneralProperties gp) {
// REQUIRES: 
// RETURNS: nothing.
// PROMISES: 
// 1. Constructs graphics objects required for LinksWindow.
  
  super(parent, "Lower Bound", true);

  gpData = gp;
  Network n = (Network)gpData.get("Network");
  int gap = ((Integer)gpData.get("Inter GUI component gap")).intValue();
  // add cost pCost
  lbLowerBound = new Label("Lower Bound  = " + n.lowerBound);
  gbc.fill = GridBagConstraints.NONE;
  gbc.anchor = GridBagConstraints.CENTER;
  add(lbLowerBound, 0, 0, 1, 1);

  // add ok and cancel buttons to pButtons panel
  pButtons = new Panel();
  pButtons.setLayout(new GridLayout(1,3));
  pButtons.add(bOk = new Button("Ok"));
  pButtons.add(bStop = new Button("Stop"));
  pButtons.add(bHelp = new Button("Help"));
  gbc.fill = GridBagConstraints.NONE;
  gbc.anchor = GridBagConstraints.CENTER;
  add(pButtons, 0, 1, 1, 1);

  // add TextArea
  tx = new TextArea(n.lowerBoundText);
  tx.setEditable(false);

  gbc.fill = GridBagConstraints.BOTH;
  gbc.weightx = 100;
  gbc.weighty = 100;
  add(tx, 0, 2, 1, 6);  

  pack();
  // resize(200,200);
  // show();
}
*/

public dOptimizeLowerBound(Frame parent, GeneralProperties gp,
			   double lowerBound, String rdata) {
  super(parent, "Lower Bound", false);
  gpData = gp;
  // add cost pCost
  lbLowerBound = new Label("Lower Bound  = " + lowerBound);
  gbc.fill = GridBagConstraints.NONE;
  gbc.anchor = GridBagConstraints.CENTER;
  add(lbLowerBound, 0, 0, 1, 1);

  // add ok and cancel buttons to pButtons panel
  pButtons = new Panel();
  pButtons.setLayout(new GridLayout(1,3));
  pButtons.add(bOk = new Button("Ok"));
  pButtons.add(bStop = new Button("Stop"));
  pButtons.add(bHelp = new Button("Help"));
  gbc.fill = GridBagConstraints.NONE;
  gbc.anchor = GridBagConstraints.CENTER;
  add(pButtons, 0, 1, 1, 1);

  // add TextArea
  tx = new TextArea(rdata);
  tx.setEditable(false);

  gbc.fill = GridBagConstraints.BOTH;
  gbc.weightx = 100;
  gbc.weighty = 100;
  add(tx, 0, 2, 1, 6);  
  pack();
  hide();
}

//************************************************
public boolean action(Event evt, Object arg) {
  if (arg.equals("Ok")) {
    hide();
    //dispose();
    return true;
  }
  else if (arg.equals("Stop")) {
    GUIManager gm = (GUIManager)gpData.get("GUIManager");
    gm.stopCalcLowerBoundThread();
    lbLowerBound.setText("Lower Bound Calculation Stopped");
    layout();
    return true;
  }
  else if (arg.equals("Help")) {
    String HelpURL = (String)gpData.
      get("Help URL for Optimize|LowerBound 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); 
    }
    return true;
  }
  return false;
}

//************************************************
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.id == Event.WINDOW_DESTROY && 
     e.target == this)
    //dispose();
    hide();
  else
    super.handleEvent(e);
  return true;			    // No need to pass event to parent as
				    // the dialog box is anyway model. 
}

//************************************************
} // end of class dOptimizeLowerBound
//////////////////////////////////////////////////








