// ExitDialog.java
//
//
// Copyright Henrik Björkman (www.stacken.kth.se/~bjorkman) 1999
//
// History:
//
// Created by Henrik Björkman 1999-08-26 using code from 
// RefDialog.java    
//

package chartplotter_package;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class ExitDialog extends Dialog 
{
  Frame parent;
  int r=UNKNOWN;

  public static final int UNKNOWN=0;
  public static final int CANCEL=2;
  public static final int OK=1;
  public static final int CLOSE=3;

  void close() 
  {
    //this.hide();
    setVisible(false);
    r=CLOSE;
  }

  void buttonOk() 
  {
    close();
    r=OK;
  }

  void buttonCancel() 
  {
    close();
    r=CANCEL;
  }


  // The main constructor of this class.
  public ExitDialog(Frame parent, String title, String message)
  {
    super(parent,title,true);

    this.parent=parent;

    this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) { close(); }
    });


    {
      Panel p1=new Panel();

      Label l=new Label(message,Label.CENTER);
      p1.add("North",l);

      this.add("North",p1);
    }


    {
      Panel p3=new Panel();

      Button b1=new Button("OK");
      b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) { buttonOk(); }
      });
      p3.add("West",b1);

      Button b2=new Button("Cancel");
      b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) { buttonCancel(); }
      });
      p3.add("East",b2);


      this.add("South",p3);
    }

    this.pack();

    //this.show();
  }

  public static int visa(Frame parent, String title, String message)
  {
    int r;
    ExitDialog d=new ExitDialog(parent,title,message);
    d.show();
    r=d.r;
    d.dispose();
    return(r);
  }


}


