// JDraw - MsgDialog class
// Written by Jim Calciano, implemented into JDraw by the rest of us
// November 18, 1998
// Class to help display errors, if and when they occur, to the user

import java.awt.*;
import java.awt.event.*;

public class MsgDialog extends Dialog{
  Button b = new Button();
  Label label = new Label();
  Panel panel = new Panel();
  public MsgDialog(Frame parent){
    super(parent,true);
    add("North", label);
    b.addActionListener(new PressListener());
    panel.add(b);
    add("South",panel);
    pack();
  }
  public MsgDialog(Frame parent, String message, String title){
    super(parent,true);
    label.setText(message);
    add("North",label);
    setTitle(title);
    b.setLabel("OK");
    b.addActionListener(new PressListener());
    panel.add(b);
    add("South",panel);
    pack();
  }
  class PressListener implements ActionListener{
    public void actionPerformed(ActionEvent e){
      setVisible(false);
    }
  }
  public void setMessage(String message){
    label.setText(message);
    add("North",label);
    pack();
  }
  public void setButtonText(String text){
    b.setLabel(text);
    panel.add(b);
    add("South", panel);
    pack();
  }
  public void setTitle(String title){
    super.setTitle(title);
    pack();
  }
  public void setFont(Font f){
    super.setFont(f);
    pack();
  }
  public void setVisible(boolean yesorno){
    if (yesorno) {
        pack();
        center();
    }
    super.setVisible(yesorno);
  }
  private void center(){
    Dimension d = getSize();
    Toolkit t = Toolkit.getDefaultToolkit();
    Dimension s =t.getScreenSize();
    setLocation((s.width - d.width)/2, 
                (s.height - d.height)/2);
  }
}