 /*
  * $Log: dMessageBox.java,v $
# Revision 1.15  1996/07/29  15:34:57  hma
# at the  end of handleEvent, change
# return super.handleEvent() to
# super.handleEvent().
#
# Revision 1.14  1996/07/11  01:21:45  hma
# intermediate working version
#
# Revision 1.13  1996/06/10  16:49:33  inder
# minor changes.
#
# Revision 1.12  1996/06/06  05:20:28  inder
# made the button panel vertically unresizable.
#
# Revision 1.11  1996/05/13  08:13:57  inder
# keyboard events now passed to components.
#
# Revision 1.10  1996/05/12  07:28:56  inder
# changed constructor.
#
# Revision 1.9  1996/05/07  04:12:45  inder
# pressing Help in an applet now visits HelpURL.
#
# Revision 1.8  1996/05/06  19:29:45  inder
# Fixed problem of MainWindow disappearing when this dialog box was
# displayed.
#
# Revision 1.7  1996/04/22  06:03:38  inder
# changed layout to GridBagLayout
#
# Revision 1.6  1996/04/19  07:32:22  inder
# defined new constructor. changed panels to FramedPanels.
#
# Revision 1.5  1996/04/15  07:17:18  inder
# trying to display the message box in its correct size.
#
# Revision 1.4  1996/04/15  05:08:31  inder
# fixed error "double definition of bounds" in show()
#
# Revision 1.3  1996/04/15  04:36:25  inder
# minor typo corrections.
#
# Revision 1.2  1996/04/15  04:33:10  inder
# initial revision.
  */
/////////////////////////////////////////////////
package gui;			    // Part of gui package.

import java.applet.Applet;
import java.awt.*;
import java.net.URL;
import java.net.MalformedURLException;

// Network Design Tool Packages.
import general.GeneralProperties;
import gui.FramedPanel;
//////////////////////////////////////////////////
public class dMessageBox extends Dialog {

private GeneralProperties gpData;
private String HelpURL;
private FramedPanel pMsg;	    // holds msg.
private FramedPanel pButtons;	    // Holds buttons.
private Button bOk;		    // Ok button.
private Button bHelp;		    // Help button.
//************************************************
public dMessageBox(Frame parent, String title, String msg,
		   GeneralProperties gp, boolean ShowHelp, String helpURL) {
// REQUIRES: nothing.
// RETURNS: nothing.
// PROMISES: Creates and shows a dialog box with title and displays msg in it.

  super(parent, title, true);

  gpData = gp;
  HelpURL = helpURL;
  GridBagLayout gblOverall = new GridBagLayout();
  setLayout(gblOverall);
  GridBagConstraints gbcOverall = new GridBagConstraints();
  gbcOverall.weightx = 1.0;
  gbcOverall.weighty = 1.0;
  int gap = ((Integer)gpData.get("Inter GUI component gap")).intValue();
  gbcOverall.insets = new Insets(gap, gap, gap, gap);
  gbcOverall.gridwidth = GridBagConstraints.REMAINDER;
  gbcOverall.fill = GridBagConstraints.BOTH;
  
  pMsg = new FramedPanel(FramedPanel.SINGLE_BORDER);
  pMsg.setLayout(new GridLayout(1, 1));
  pMsg.add(new Label(msg), Label.LEFT);

  gblOverall.setConstraints(pMsg, gbcOverall);
  add(pMsg);

  // Add ok and help buttons at the bottom in a separate panel.
  pButtons = new FramedPanel(FramedPanel.SINGLE_BORDER);
  pButtons.add(bOk = new Button("Ok"));
  if(ShowHelp)
    pButtons.add(bHelp = new Button("Help")); // Add help button.

  gbcOverall.weighty = 0.0;
  gbcOverall.fill = GridBagConstraints.HORIZONTAL;
  gbcOverall.insets = new Insets(0, gap, gap, gap);
  gblOverall.setConstraints(pButtons, gbcOverall);
  add(pButtons);

  pack();
  show();
}
//************************************************
public boolean handleEvent(Event e) {
// REQUIRES: nothing.
// RETURNS: true if the event is handled within it, false otherwise.
// PROMISES: Changes web page to HelpURL if InApplet is true. otherwise
// displays HelpMsg.

  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();
  }
    else if(e.target == bOk) {
    dispose();
  }
    else if(e.target == bHelp) {
      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 dMessageBox
//////////////////////////////////////////////////
