view 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
line wrap: on
line source
/*
 *	Dialog.java
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.core.util.swing;
import  samer.core.*;
import  java.awt.*;
import  java.awt.event.*;
import  javax.swing.*;

public class Dialog extends JDialog implements ActionListener, Shell.Dialog
{
	String	result;
	Box	buttons;

	public Dialog( java.awt.Frame owner, String nm, boolean modal)
	{
		super(owner,nm,modal);
		buttons=new Box(BoxLayout.X_AXIS);
		buttons.add( Box.createHorizontalGlue());
		container().setLayout( new BorderLayout());
		container().add( buttons, "South");
		setDefaultCloseOperation(HIDE_ON_CLOSE);
	}

	public Dialog(String nm, boolean modal)
	{
		setModal(modal);
		setTitle(nm);

		buttons=new Box(BoxLayout.X_AXIS);
		buttons.add( Box.createHorizontalGlue());
		container().setLayout( new BorderLayout());
		container().add( buttons, "South");
		setDefaultCloseOperation(HIDE_ON_CLOSE);
	}

	protected void finalize() { Shell.trace("SDialog finalizing"); }

	public void actionPerformed(ActionEvent e)
	{
		result=e.getActionCommand();
		Shell.trace("closing dialog: "+result);
		setVisible(false);
	}

	public void centre() { setLocationRelativeTo(null); }

	public Container container() { return getContentPane(); }
	public String	result() { return result; }
	public void expose() { result="close"; pack(); centre(); setVisible(true); }

	public void addAction(String label)
	{
		JButton btn=new JButton(label);
		btn.addActionListener(this);
		buttons.add(btn);
	}
}