/*
 * @(#) OkBox.java 1.0 97/07/26 
 * Copyright (c) 1996 Larry Rodrigues
 */
    //package vis.util;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
 
   public class MessageBox extends Dialog {

         int width, height;
         String message; 
         String title;
         Frame parent;
         /**
           * If true, the Box is modal.
           */
         boolean mode; 
         Button okButton;
         Vector MessageBoxListeners = new Vector();
         private TextPanel mainText;
         public MessageBox(Frame fm, int wid, int ht, String heading, String msg, boolean mod){
                super(fm, heading, mod);
                parent = fm;
                title = heading;
                width = wid;
                height = ht;
                mode = mod;
                setSize(wid, ht);
                message = msg;
                createUI();
         }  
         
         public void createUI(){

                 GridBagLayout    gb = new GridBagLayout() ;
                 GridBagConstraints c = new GridBagConstraints();
                 setLayout(gb);
                 setBackground(Color.lightGray);
                 setForeground(Color.black);
                 c.weighty = 0.0; c.weightx = 0.0;
                 c.gridy =0;
                 c.insets = new Insets(10,10,10,10);
                 mainText = new TextPanel(width, height/2, message);
                 mainText.setBackground(Color.gray);
                 gb.setConstraints(mainText,c);
                 add(mainText);

                 Panel btnP = new Panel();
                 okButton = new Button("OK");

                 btnP.add(okButton);

                 c.gridy = 1;
                 c.gridwidth = GridBagConstraints.REMAINDER;
                 gb.setConstraints(btnP,c);
                 add(btnP);
                 addWindowListener(
                    new WindowAdapter(){
                       public void windowClosed(WindowEvent e){
                          dispose();
                       }
                       public void windowClosing(WindowEvent e){
                          dispose();
                       }                             
                    }
                 );
	   	 pack();
          }

       public void setHeader(String str){
          setTitle(str);
       }
       public void setMessage(String message){
          if(mainText != null) mainText.setMessage(message);
       }
       public void addActionListener(ActionListener l){
          okButton.addActionListener(l);
       }

       public void removeActionListener(ActionListener l){
         okButton.removeActionListener(l);
       }

  }
