Source for org.jfree.ui.tabbedui.TabbedApplet

   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:  * TabbedApplet.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: TabbedApplet.java,v 1.7 2008/09/10 09:19:04 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;
  46: import java.beans.PropertyChangeEvent;
  47: import java.beans.PropertyChangeListener;
  48: import javax.swing.JApplet;
  49: import javax.swing.JPanel;
  50: 
  51: /**
  52:  * An applet implementation that uses a tabbed GUI as backend.
  53:  *
  54:  * @author Thomas Morgner
  55:  */
  56: public class TabbedApplet extends JApplet {
  57: 
  58:     /**
  59:      * A property change listener that waits for the menubar to change.
  60:      */
  61:     private class MenuBarChangeListener implements PropertyChangeListener {
  62:         /**
  63:          * Creates a new change listener.
  64:          */
  65:         public MenuBarChangeListener() {
  66:         }
  67: 
  68:         /**
  69:          * This method gets called when a bound property is changed.
  70:          *
  71:          * @param evt A PropertyChangeEvent object describing the event source
  72:          *            and the property that has changed.
  73:          */
  74:         public void propertyChange(final PropertyChangeEvent evt) {
  75:             if (evt.getPropertyName().equals(AbstractTabbedUI.JMENUBAR_PROPERTY)) {
  76:                 setJMenuBar(getTabbedUI().getJMenuBar());
  77:             }
  78:         }
  79:     }
  80: 
  81:     /** The UI for the applet. */
  82:     private AbstractTabbedUI tabbedUI;
  83: 
  84:     /**
  85:      * Default constructor.
  86:      */
  87:     public TabbedApplet() {
  88:     }
  89: 
  90: 
  91:     /**
  92:      * Returns the UI implementation for the applet.
  93:      *
  94:      * @return Returns the tabbedUI.
  95:      */
  96:     protected final AbstractTabbedUI getTabbedUI()
  97:     {
  98:       return this.tabbedUI;
  99:     }
 100:     /**
 101:      * Initialises the applet.
 102:      *
 103:      * @param tabbedUI  the UI that controls the applet.
 104:      */
 105:     public void init(final AbstractTabbedUI tabbedUI) {
 106: 
 107:         this.tabbedUI = tabbedUI;
 108:         this.tabbedUI.addPropertyChangeListener
 109:             (AbstractTabbedUI.JMENUBAR_PROPERTY, new MenuBarChangeListener());
 110: 
 111:         final JPanel panel = new JPanel();
 112:         panel.setLayout(new BorderLayout());
 113:         panel.add(tabbedUI, BorderLayout.CENTER);
 114:         setContentPane(panel);
 115:         setJMenuBar(tabbedUI.getJMenuBar());
 116:     }
 117: 
 118: }