annotate src/samer/core_/util/swing/Dialog.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /*
samer@0 2 * Dialog.java
samer@0 3 *
samer@0 4 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 5 * All rights reserved.
samer@0 6 *
samer@0 7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 8 * without even the implied warranty of MERCHANTABILITY or
samer@0 9 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 10 */
samer@0 11
samer@0 12 package samer.core.util.swing;
samer@0 13 import samer.core.*;
samer@0 14 import java.awt.*;
samer@0 15 import java.awt.event.*;
samer@0 16 import javax.swing.*;
samer@0 17
samer@0 18 public class Dialog extends JDialog implements ActionListener, Shell.Dialog
samer@0 19 {
samer@0 20 String result;
samer@0 21 Box buttons;
samer@0 22
samer@0 23 public Dialog( java.awt.Frame owner, String nm, boolean modal)
samer@0 24 {
samer@0 25 super(owner,nm,modal);
samer@0 26 buttons=new Box(BoxLayout.X_AXIS);
samer@0 27 buttons.add( Box.createHorizontalGlue());
samer@0 28 container().setLayout( new BorderLayout());
samer@0 29 container().add( buttons, "South");
samer@0 30 setDefaultCloseOperation(HIDE_ON_CLOSE);
samer@0 31 }
samer@0 32
samer@0 33 public Dialog(String nm, boolean modal)
samer@0 34 {
samer@0 35 setModal(modal);
samer@0 36 setTitle(nm);
samer@0 37
samer@0 38 buttons=new Box(BoxLayout.X_AXIS);
samer@0 39 buttons.add( Box.createHorizontalGlue());
samer@0 40 container().setLayout( new BorderLayout());
samer@0 41 container().add( buttons, "South");
samer@0 42 setDefaultCloseOperation(HIDE_ON_CLOSE);
samer@0 43 }
samer@0 44
samer@0 45 protected void finalize() { Shell.trace("SDialog finalizing"); }
samer@0 46
samer@0 47 public void actionPerformed(ActionEvent e)
samer@0 48 {
samer@0 49 result=e.getActionCommand();
samer@0 50 Shell.trace("closing dialog: "+result);
samer@0 51 setVisible(false);
samer@0 52 }
samer@0 53
samer@0 54 public void centre() { setLocationRelativeTo(null); }
samer@0 55
samer@0 56 public Container container() { return getContentPane(); }
samer@0 57 public String result() { return result; }
samer@0 58 public void expose() { result="close"; pack(); centre(); setVisible(true); }
samer@0 59
samer@0 60 public void addAction(String label)
samer@0 61 {
samer@0 62 JButton btn=new JButton(label);
samer@0 63 btn.addActionListener(this);
samer@0 64 buttons.add(btn);
samer@0 65 }
samer@0 66 }
samer@0 67