001: /*
002: * Copyright (C) 2004 Nicky BRAMANTE
003: *
004: * This file is part of FreeQueryBuilder
005: *
006: * FreeQueryBuilder is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Send questions or suggestions to nickyb@interfree.it
021: */
022:
023: package it.frb.admin;
024:
025: import java.awt.Component;
026: import java.awt.Cursor;
027: import java.awt.Dimension;
028:
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.awt.event.WindowAdapter;
032: import java.awt.event.WindowEvent;
033: import java.awt.event.WindowListener;
034:
035: import javax.swing.Box;
036: import javax.swing.BoxLayout;
037: import javax.swing.JButton;
038: import javax.swing.JDialog;
039:
040: import javax.swing.border.EmptyBorder;
041:
042: public abstract class ModalDialog extends JDialog implements
043: ActionListener, Runnable {
044: protected static final int INITIAL_WIDTH = 320;
045: protected static final int INITIAL_HEIGHT = 200;
046:
047: protected Box bar;
048: protected JButton btnExit;
049:
050: protected ModalDialog(Component owner, String title) {
051: this (owner, title, INITIAL_WIDTH, INITIAL_HEIGHT);
052: }
053:
054: protected ModalDialog(Component owner, String title, int width,
055: int height) {
056: this (owner, title, new Dimension(width, height));
057: }
058:
059: protected ModalDialog(Component owner, String title, Dimension size) {
060: super (UIUtilities.getFrameAncestor(owner), title, true);
061:
062: DefaultPanel pnlContent = new DefaultPanel(3, 3);
063: pnlContent.setBorder(new EmptyBorder(3, 3, 3, 3));
064:
065: bar = new Box(BoxLayout.X_AXIS);
066: bar.add(Box.createHorizontalGlue());
067: bar.add(btnExit = UIUtilities.createCustomButton("exit", this ));
068:
069: pnlContent.setSouthComponent(bar);
070:
071: setContentPane(pnlContent);
072: setSize(size.width, size.height);
073: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
074:
075: WindowListener wl = new WindowAdapter() {
076: public void windowOpened(WindowEvent we) {
077: new Thread(ModalDialog.this ).start();
078: }
079: };
080: this .addWindowListener(wl);
081:
082: UIUtilities.centerOnScreen(this );
083: }
084:
085: protected void setBarEnabled(boolean b) {
086: for (int i = 0; i < bar.getComponentCount(); i++) {
087: bar.getComponent(i).setEnabled(b);
088: }
089: }
090:
091: public final void run() {
092: this .setCursor(new Cursor(Cursor.WAIT_CURSOR));
093:
094: setBarEnabled(false);
095: onRunning();
096: setBarEnabled(true);
097:
098: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
099: this .setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
100: }
101:
102: protected abstract void onRunning();
103:
104: public void actionPerformed(ActionEvent ae) {
105: this.dispose();
106: }
107: }
|