001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------
028: * AbstractTabbedGUI.java
029: * ----------------------
030: * (C)opyright 2004, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: TabbedDialog.java,v 1.5 2005/10/18 13:23:37 mungady Exp $
036: *
037: * Changes
038: * -------------------------
039: * 16-Feb-2004 : Initial version
040: * 07-Jun-2004 : Added standard header (DG);
041: */
042:
043: package org.jfree.ui.tabbedui;
044:
045: import java.awt.BorderLayout;
046: import java.awt.Dialog;
047: import java.awt.Frame;
048: import java.awt.event.ActionEvent;
049: import java.awt.event.WindowAdapter;
050: import java.awt.event.WindowEvent;
051: import java.beans.PropertyChangeEvent;
052: import java.beans.PropertyChangeListener;
053:
054: import javax.swing.JDialog;
055: import javax.swing.JPanel;
056:
057: /**
058: * A JDialog implementation that uses a tabbed UI as backend.
059: *
060: * @author Thomas Morgner
061: */
062: public class TabbedDialog extends JDialog {
063:
064: /** The backend. */
065: private AbstractTabbedUI tabbedUI;
066:
067: /**
068: * A property change listener that waits for the menubar to change.
069: */
070: private class MenuBarChangeListener implements
071: PropertyChangeListener {
072:
073: /**
074: * Creates a new change listener.
075: */
076: public MenuBarChangeListener() {
077: }
078:
079: /**
080: * This method gets called when a bound property is changed.
081: *
082: * @param evt A PropertyChangeEvent object describing the event source
083: * and the property that has changed.
084: */
085: public void propertyChange(final PropertyChangeEvent evt) {
086: if (evt.getPropertyName().equals(
087: AbstractTabbedUI.JMENUBAR_PROPERTY)) {
088: setJMenuBar(getTabbedUI().getJMenuBar());
089: }
090: }
091: }
092:
093: /**
094: * Default constructor.
095: */
096: public TabbedDialog() {
097: }
098:
099: /**
100: * Creates a new dialog.
101: *
102: * @param owner the owner.
103: */
104: public TabbedDialog(final Dialog owner) {
105: super (owner);
106: }
107:
108: /**
109: * Creates a new dialog.
110: *
111: * @param owner the owner.
112: * @param modal modal dialog?
113: */
114: public TabbedDialog(final Dialog owner, final boolean modal) {
115: super (owner, modal);
116: }
117:
118: /**
119: * Creates a new dialog.
120: *
121: * @param owner the owner.
122: * @param title the dialog title.
123: */
124: public TabbedDialog(final Dialog owner, final String title) {
125: super (owner, title);
126: }
127:
128: /**
129: * Creates a new dialog.
130: *
131: * @param owner the owner.
132: * @param title the dialog title.
133: * @param modal modal dialog?
134: */
135: public TabbedDialog(final Dialog owner, final String title,
136: final boolean modal) {
137: super (owner, title, modal);
138: }
139:
140: /**
141: * Creates a new dialog.
142: *
143: * @param owner the owner.
144: */
145: public TabbedDialog(final Frame owner) {
146: super (owner);
147: }
148:
149: /**
150: * Creates a new dialog.
151: *
152: * @param owner the owner.
153: * @param modal modal dialog?
154: */
155: public TabbedDialog(final Frame owner, final boolean modal) {
156: super (owner, modal);
157: }
158:
159: /**
160: * Creates a new dialog.
161: *
162: * @param owner the owner.
163: * @param title the dialog title.
164: */
165: public TabbedDialog(final Frame owner, final String title) {
166: super (owner, title);
167: }
168:
169: /**
170: * Creates a new dialog.
171: *
172: * @param owner the owner.
173: * @param title the dialog title.
174: * @param modal modal dialog?
175: */
176: public TabbedDialog(final Frame owner, final String title,
177: final boolean modal) {
178: super (owner, title, modal);
179: }
180:
181: /**
182: * Returns the UI implementation for the dialog.
183: *
184: * @return Returns the tabbedUI.
185: */
186: protected final AbstractTabbedUI getTabbedUI() {
187: return tabbedUI;
188: }
189:
190: /**
191: * Initialises the dialog.
192: *
193: * @param tabbedUI the UI that controls the dialog.
194: */
195: public void init(final AbstractTabbedUI tabbedUI) {
196:
197: this .tabbedUI = tabbedUI;
198: this .tabbedUI.addPropertyChangeListener(
199: AbstractTabbedUI.JMENUBAR_PROPERTY,
200: new MenuBarChangeListener());
201:
202: addWindowListener(new WindowAdapter() {
203: public void windowClosing(final WindowEvent e) {
204: getTabbedUI().getCloseAction().actionPerformed(
205: new ActionEvent(this ,
206: ActionEvent.ACTION_PERFORMED, null, 0));
207: }
208: });
209:
210: final JPanel panel = new JPanel();
211: panel.setLayout(new BorderLayout());
212: panel.add(tabbedUI, BorderLayout.CENTER);
213: setContentPane(panel);
214: setJMenuBar(tabbedUI.getJMenuBar());
215:
216: }
217:
218: }
|