samer@0: /* samer@0: * Dialog.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util.swing; samer@0: import samer.core.*; samer@0: import java.awt.*; samer@0: import java.awt.event.*; samer@0: import javax.swing.*; samer@0: samer@0: public class Dialog extends JDialog implements ActionListener, Shell.Dialog samer@0: { samer@0: String result; samer@0: Box buttons; samer@0: samer@0: public Dialog( java.awt.Frame owner, String nm, boolean modal) samer@0: { samer@0: super(owner,nm,modal); samer@0: buttons=new Box(BoxLayout.X_AXIS); samer@0: buttons.add( Box.createHorizontalGlue()); samer@0: container().setLayout( new BorderLayout()); samer@0: container().add( buttons, "South"); samer@0: setDefaultCloseOperation(HIDE_ON_CLOSE); samer@0: } samer@0: samer@0: public Dialog(String nm, boolean modal) samer@0: { samer@0: setModal(modal); samer@0: setTitle(nm); samer@0: samer@0: buttons=new Box(BoxLayout.X_AXIS); samer@0: buttons.add( Box.createHorizontalGlue()); samer@0: container().setLayout( new BorderLayout()); samer@0: container().add( buttons, "South"); samer@0: setDefaultCloseOperation(HIDE_ON_CLOSE); samer@0: } samer@0: samer@0: protected void finalize() { Shell.trace("SDialog finalizing"); } samer@0: samer@0: public void actionPerformed(ActionEvent e) samer@0: { samer@0: result=e.getActionCommand(); samer@0: Shell.trace("closing dialog: "+result); samer@0: setVisible(false); samer@0: } samer@0: samer@0: public void centre() { setLocationRelativeTo(null); } samer@0: samer@0: public Container container() { return getContentPane(); } samer@0: public String result() { return result; } samer@0: public void expose() { result="close"; pack(); centre(); setVisible(true); } samer@0: samer@0: public void addAction(String label) samer@0: { samer@0: JButton btn=new JButton(label); samer@0: btn.addActionListener(this); samer@0: buttons.add(btn); samer@0: } samer@0: } samer@0: