KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > tabbedui > TabbedDialog


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ----------------------
28  * AbstractTabbedGUI.java
29  * ----------------------
30  * (C)opyright 2004, by Thomas Morgner and Contributors.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: TabbedDialog.java,v 1.5 2005/10/18 13:23:37 mungady Exp $
36  *
37  * Changes
38  * -------------------------
39  * 16-Feb-2004 : Initial version
40  * 07-Jun-2004 : Added standard header (DG);
41  */

42
43 package org.jfree.ui.tabbedui;
44
45 import java.awt.BorderLayout JavaDoc;
46 import java.awt.Dialog JavaDoc;
47 import java.awt.Frame JavaDoc;
48 import java.awt.event.ActionEvent JavaDoc;
49 import java.awt.event.WindowAdapter JavaDoc;
50 import java.awt.event.WindowEvent JavaDoc;
51 import java.beans.PropertyChangeEvent JavaDoc;
52 import java.beans.PropertyChangeListener JavaDoc;
53
54 import javax.swing.JDialog JavaDoc;
55 import javax.swing.JPanel JavaDoc;
56
57 /**
58  * A JDialog implementation that uses a tabbed UI as backend.
59  *
60  * @author Thomas Morgner
61  */

62 public class TabbedDialog extends JDialog JavaDoc {
63
64     /** The backend. */
65     private AbstractTabbedUI tabbedUI;
66
67     /**
68      * A property change listener that waits for the menubar to change.
69      */

70     private class MenuBarChangeListener implements PropertyChangeListener JavaDoc {
71
72         /**
73          * Creates a new change listener.
74          */

75         public MenuBarChangeListener() {
76         }
77
78         /**
79          * This method gets called when a bound property is changed.
80          *
81          * @param evt A PropertyChangeEvent object describing the event source
82          * and the property that has changed.
83          */

84         public void propertyChange(final PropertyChangeEvent JavaDoc evt) {
85             if (evt.getPropertyName().equals(AbstractTabbedUI.JMENUBAR_PROPERTY)) {
86                 setJMenuBar(getTabbedUI().getJMenuBar());
87             }
88         }
89     }
90     /**
91      * Default constructor.
92      */

93     public TabbedDialog() {
94     }
95
96     /**
97      * Creates a new dialog.
98      *
99      * @param owner the owner.
100      */

101     public TabbedDialog(final Dialog JavaDoc owner) {
102         super(owner);
103     }
104
105     /**
106      * Creates a new dialog.
107      *
108      * @param owner the owner.
109      * @param modal modal dialog?
110      */

111     public TabbedDialog(final Dialog JavaDoc owner, final boolean modal) {
112         super(owner, modal);
113     }
114
115     /**
116      * Creates a new dialog.
117      *
118      * @param owner the owner.
119      * @param title the dialog title.
120      */

121     public TabbedDialog(final Dialog JavaDoc owner, final String JavaDoc title) {
122         super(owner, title);
123     }
124
125     /**
126      * Creates a new dialog.
127      *
128      * @param owner the owner.
129      * @param title the dialog title.
130      * @param modal modal dialog?
131      */

132     public TabbedDialog(final Dialog JavaDoc owner, final String JavaDoc title, final boolean modal) {
133         super(owner, title, modal);
134     }
135
136     /**
137      * Creates a new dialog.
138      *
139      * @param owner the owner.
140      */

141     public TabbedDialog(final Frame JavaDoc owner) {
142         super(owner);
143     }
144
145     /**
146      * Creates a new dialog.
147      *
148      * @param owner the owner.
149      * @param modal modal dialog?
150      */

151     public TabbedDialog(final Frame JavaDoc owner, final boolean modal) {
152         super(owner, modal);
153     }
154
155     /**
156      * Creates a new dialog.
157      *
158      * @param owner the owner.
159      * @param title the dialog title.
160      */

161     public TabbedDialog(final Frame JavaDoc owner, final String JavaDoc title) {
162         super(owner, title);
163     }
164
165     /**
166      * Creates a new dialog.
167      *
168      * @param owner the owner.
169      * @param title the dialog title.
170      * @param modal modal dialog?
171      */

172     public TabbedDialog(final Frame JavaDoc owner, final String JavaDoc title, final boolean modal) {
173         super(owner, title, modal);
174     }
175
176     
177     /**
178      * Returns the UI implementation for the dialog.
179      *
180      * @return Returns the tabbedUI.
181      */

182     protected final AbstractTabbedUI getTabbedUI()
183     {
184       return tabbedUI;
185     }
186
187     /**
188      * Initialises the dialog.
189      *
190      * @param tabbedUI the UI that controls the dialog.
191      */

192     public void init(final AbstractTabbedUI tabbedUI) {
193
194         this.tabbedUI = tabbedUI;
195         this.tabbedUI.addPropertyChangeListener
196             (AbstractTabbedUI.JMENUBAR_PROPERTY, new MenuBarChangeListener());
197
198         addWindowListener(new WindowAdapter JavaDoc() {
199             public void windowClosing(final WindowEvent JavaDoc e) {
200                 getTabbedUI().getCloseAction().actionPerformed
201                     (new ActionEvent JavaDoc(this, ActionEvent.ACTION_PERFORMED, null, 0));
202             }
203         });
204
205         final JPanel JavaDoc panel = new JPanel JavaDoc();
206         panel.setLayout(new BorderLayout JavaDoc());
207         panel.add(tabbedUI, BorderLayout.CENTER);
208         setContentPane(panel);
209         setJMenuBar(tabbedUI.getJMenuBar());
210
211     }
212
213 }
214
Popular Tags