// File: AlarmDialog.java // Classes: AlarmDialog // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Button; import java.awt.Frame; import java.awt.Label; import java.awt.BorderLayout; import java.awt.Event; import java.awt.Font; import java.awt.Color; import java.awt.Dialog; import java.awt.Dimension; import java.awt.Point; import java.awt.Panel; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; /* Purpose : Question dialog */ public class AlarmDialog extends Dialog implements ActionListener { private Button _yes,_no,_cancel; private String _choice,_defaultFocus; public AlarmDialog(Frame frame,String title,String message1,String buttonString,String defaultButton) { this( frame,title,message1,null,buttonString,defaultButton) ; } public AlarmDialog(Frame frame,String title,String message1,String message2,String buttonString,String defaultButton) { super(frame,title,true); _defaultFocus = defaultButton; setLayout(new BorderLayout()); Label label1,label2; label1=new Label(message1,Label.CENTER); label1.setFont(new Font("Times Roman",Font.BOLD,12)); add("North",label1); if(message2!=null) { label2=new Label(message2,Label.CENTER); add("Center",label2); } Panel buttonPanel = new Panel(); if(buttonString.indexOf('Y')!=-1) { buttonPanel.add(_yes = new Button("Yes")); _yes.addActionListener(this); } if(buttonString.indexOf('N')!=-1) { buttonPanel.add(_no = new Button("No")); _no.addActionListener(this); } if(buttonString.indexOf('C')!=-1) { buttonPanel.add(_cancel=new Button("Cancel")); _cancel.addActionListener(this); } buttonPanel.setBackground(Color.lightGray); add("South",buttonPanel); pack(); setBackground(Color.lightGray); // jdk 1.1 type window event handling addWindowListener(new ADAdapter()); // using inner class for window handling. } public void setVisible(boolean status) { if(status) { Dimension frameSize = getParent().getSize(); Point frameLoc = getParent().getLocation(); Dimension mySize = getSize(); int x,y; x = frameLoc.x + (frameSize.width/2) -(mySize.width/2); y = frameLoc.y + (frameSize.height/2)-(mySize.height/2); setBounds(x,y,getSize().width,getSize().height); super.setVisible(true); // if(_defaultFocus.equals("Y")) // _yes.requestFocus(); // else // if(_defaultFocus.equals("N")) _no.requestFocus(); // else // if(_defaultFocus.equals("C")) // _cancel.requestFocus(); } else super.setVisible(false); } // jdk 1.1 style event handling. action converted to actionPerformed public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if(source == _no) _choice="NO"; else if(source == _yes) _choice="YES"; else _choice="CANCEL"; close(); } private void close() { setVisible(false); dispose(); } public String getChoice(){return _choice;} // inner class VDAdapter class ADAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) { _choice = "CANCEL"; close(); } } } /* end class AlarmDialog */