view src/samer/core_/util/heavy/Dialog.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
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.heavy;
import  samer.core.*;
import  java.awt.*;
import  java.awt.event.*;

public class Dialog extends java.awt.Dialog implements ActionListener, Shell.Dialog
{
	String		result;
	Container	panel;
	Panel			buttons;

	public Dialog( java.awt.Frame owner, String nm, boolean modal)
	{
		super(owner,nm,modal);

		panel = new JPanel(Border.create(Border.NONE));
		panel.setLayout(new GridLayout(0,1));
		buttons=new Panel(); // JPanel(Border.create(Border.NONE));
		buttons.setLayout( new FlowLayout(FlowLayout.RIGHT,6,2));

		setFont(X.font(Shell.datum("dialog.font"),null));
		setLayout( new BorderLayout());
		add( panel, "Center");
		add( buttons, "South");
		addWindowListener( new WindowAdapter() {
			public void windowClosing(WindowEvent e) { 
				result = "close";
				setVisible(false); 
			}
		} );
	}

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

	public void actionPerformed(ActionEvent e)
	{
		result=e.getActionCommand();
		setVisible(false);

		//String cmd=e.getActionCommand();
		//if	     (cmd=="ok")     { result=cmd; setVisible(false); }
		//else if (cmd=="cancel") { result=cmd; setVisible(false); }
	}

	public Container container() { return panel; }
	public String result() { return result; }
	public void expose() { pack(); centre(); setVisible(true); toFront(); }

	public void centre()
	{
		Dimension d=getSize();
		setLocation( (SX-d.width)/2, (SY-d.height)/2);
	}

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

	private static int SX, SY; // screen width and height
	static {
		Dimension s=Toolkit.getDefaultToolkit().getScreenSize();
		SX=s.width;
		SY=s.height;
	}
}