001: /*
002: ** $Id: DialogView.java,v 1.6 2000/10/26 08:34:15 mrw Exp $
003: **
004: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
005: **
006: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
007: **
008: ** This program is free software; you can redistribute it and/or modify
009: ** it under the terms of the GNU General Public License as published by
010: ** the Free Software Foundation; either version 2 of the License, or
011: ** (at your option) any later version.
012: **
013: ** This program is distributed in the hope that it will be useful,
014: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
015: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: ** GNU General Public License for more details.
017: **
018: ** You should have received a copy of the GNU Library General
019: ** Public License along with this library; if not, write to the
020: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
021: ** Boston, MA 02111-1307 USA.
022: */
023:
024: package uk.co.whisperingwind.framework;
025:
026: import java.awt.event.WindowEvent;
027: import java.awt.event.ActionListener;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.WindowAdapter;
030: import javax.swing.JDialog;
031: import javax.swing.JFrame;
032:
033: /**
034: ** View which is a Dialog. (Actually HAS a Dialog as Java doesn't have
035: ** multiple inheritance. Thankfully).
036: */
037:
038: public abstract class DialogView extends View {
039: protected JDialog content = null;
040: protected AllActionListener actionListener = null;
041:
042: public DialogView() {
043: this (null, true);
044: }
045:
046: public DialogView(JFrame parent, boolean modal) {
047: content = new JDialog(parent, modal);
048: actionListener = new AllActionListener();
049:
050: WindowAdapter windowAdapter = new WindowAdapter() {
051: public void windowClosing(WindowEvent event) {
052: fireEvent("cancel");
053: }
054: };
055:
056: content.addWindowListener(windowAdapter);
057: }
058:
059: /**
060: ** Destroy myself.
061: */
062:
063: public void closeDialog() {
064: content.setVisible(false);
065: cleanUp();
066: ((JDialog) content).dispose();
067: }
068:
069: /**
070: ** Return my content -- the JDialog instance.
071: */
072:
073: public JDialog getContent() {
074: return content;
075: }
076:
077: /**
078: ** Get the dialog's visible state.
079: **
080: ** @return true if the dialog is visible.
081: */
082:
083: public boolean isVisible() {
084: return content.isVisible();
085: }
086:
087: /**
088: ** Show or hide the dialog.
089: **
090: ** @param visible true to show the dialog, false to hide it.
091: */
092:
093: public void setVisible(boolean visible) {
094: content.setVisible(visible);
095: }
096:
097: /**
098: ** DialogView has one instance of this. It listens to all button and
099: ** menu action events and passes them to the controller.
100: */
101:
102: private class AllActionListener implements ActionListener {
103: public void actionPerformed(ActionEvent event) {
104: fireEvent(event.getActionCommand());
105: }
106: }
107:
108: /**
109: ** When the window dies, behave like the Cancel button was
110: ** clicked.
111: */
112:
113: private class DeadlyWindowListener extends WindowAdapter {
114: public void windowClosing(WindowEvent event) {
115: fireEvent("cancel");
116: }
117: }
118: }
|