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 PropertyChangeListener {
071    
072            /**
073             * Creates a new change listener.
074             */
075            public MenuBarChangeListener() {
076            }
077    
078            /**
079             * This method gets called when a bound property is changed.
080             *
081             * @param evt A PropertyChangeEvent object describing the event source
082             *            and the property that has changed.
083             */
084            public void propertyChange(final PropertyChangeEvent evt) {
085                if (evt.getPropertyName().equals(AbstractTabbedUI.JMENUBAR_PROPERTY)) {
086                    setJMenuBar(getTabbedUI().getJMenuBar());
087                }
088            }
089        }
090        /**
091         * Default constructor.
092         */
093        public TabbedDialog() {
094        }
095    
096        /**
097         * Creates a new dialog.
098         * 
099         * @param owner  the owner.
100         */
101        public TabbedDialog(final Dialog 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 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 owner, final String 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 owner, final String 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 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 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 owner, final String 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 owner, final String 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() {
199                public void windowClosing(final WindowEvent e) {
200                    getTabbedUI().getCloseAction().actionPerformed
201                        (new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null, 0));
202                }
203            });
204    
205            final JPanel panel = new JPanel();
206            panel.setLayout(new BorderLayout());
207            panel.add(tabbedUI, BorderLayout.CENTER);
208            setContentPane(panel);
209            setJMenuBar(tabbedUI.getJMenuBar());
210    
211        }
212    
213    }