Source for javax.swing.JWindow

   1: /* JWindow.java --
   2:    Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing;
  40: 
  41: import java.awt.BorderLayout;
  42: import java.awt.Component;
  43: import java.awt.Container;
  44: import java.awt.Dimension;
  45: import java.awt.Frame;
  46: import java.awt.Graphics;
  47: import java.awt.GraphicsConfiguration;
  48: import java.awt.LayoutManager;
  49: import java.awt.Window;
  50: import java.awt.event.KeyEvent;
  51: 
  52: import javax.accessibility.Accessible;
  53: import javax.accessibility.AccessibleContext;
  54: 
  55: /**
  56:  * Unlike JComponent derivatives, JWindow inherits from
  57:  * java.awt.Window. But also lets a look-and-feel component to its work.
  58:  *
  59:  * @author Ronald Veldema (rveldema@cs.vu.nl)
  60:  */
  61: public class JWindow extends Window implements Accessible, RootPaneContainer
  62: {
  63:   /**
  64:    * Provides accessibility support for <code>JWindow</code>.
  65:    */
  66:   protected class AccessibleJWindow extends Window.AccessibleAWTWindow
  67:   {
  68:     /**
  69:      * Creates a new instance of <code>AccessibleJWindow</code>.
  70:      */
  71:     public AccessibleJWindow()
  72:     {
  73:       super();
  74:       // Nothing to do here.
  75:     }
  76:   }
  77: 
  78:   private static final long serialVersionUID = 5420698392125238833L;
  79:   
  80:   protected JRootPane rootPane;
  81: 
  82:   /**
  83:    * @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
  84:    */
  85:   protected boolean rootPaneCheckingEnabled = false;
  86: 
  87:   protected AccessibleContext accessibleContext;
  88: 
  89:   public JWindow()
  90:   {
  91:     super(SwingUtilities.getOwnerFrame());
  92:     windowInit();
  93:   }
  94: 
  95:   public JWindow(GraphicsConfiguration gc)
  96:   {
  97:     super(SwingUtilities.getOwnerFrame(), gc);
  98:     windowInit();
  99:   }
 100:   
 101:   public JWindow(Frame owner)
 102:   {
 103:     super(owner);
 104:     windowInit();
 105:   }
 106: 
 107:   public JWindow(Window owner)
 108:   {
 109:     super(owner);
 110:     windowInit();
 111:   }
 112: 
 113:   public JWindow(Window owner, GraphicsConfiguration gc)
 114:   {
 115:     super(owner, gc);
 116:     windowInit();
 117:   }
 118: 
 119:   protected void windowInit()
 120:   {
 121:     super.setLayout(new BorderLayout(1, 1));
 122:     getRootPane(); // will do set/create
 123:     // Now we're done init stage, adds and layouts go to content pane.
 124:     setRootPaneCheckingEnabled(true);
 125:   }
 126: 
 127:   public Dimension getPreferredSize()
 128:   {
 129:     return super.getPreferredSize();
 130:   }
 131: 
 132:   public void setLayout(LayoutManager manager)
 133:   {
 134:     // Check if we're in initialization stage.  If so, call super.setLayout
 135:     // otherwise, valid calls go to the content pane.
 136:     if (isRootPaneCheckingEnabled())
 137:       getContentPane().setLayout(manager);
 138:     else
 139:       super.setLayout(manager);
 140:   }
 141: 
 142:   public void setLayeredPane(JLayeredPane layeredPane)
 143:   {
 144:     getRootPane().setLayeredPane(layeredPane);
 145:   }
 146: 
 147:   public JLayeredPane getLayeredPane()
 148:   {
 149:     return getRootPane().getLayeredPane();
 150:   }
 151: 
 152:   public JRootPane getRootPane()
 153:   {
 154:     if (rootPane == null)
 155:       setRootPane(createRootPane());
 156:     return rootPane;
 157:   }
 158: 
 159:   protected void setRootPane(JRootPane root)
 160:   {
 161:     if (rootPane != null)
 162:       remove(rootPane);
 163: 
 164:     rootPane = root;
 165:     add(rootPane, BorderLayout.CENTER);
 166:   }
 167: 
 168:   protected JRootPane createRootPane()
 169:   {
 170:     return new JRootPane();
 171:   }
 172: 
 173:   public Container getContentPane()
 174:   {
 175:     return getRootPane().getContentPane();
 176:   }
 177: 
 178:   public void setContentPane(Container contentPane)
 179:   {
 180:     getRootPane().setContentPane(contentPane);
 181:   }
 182: 
 183:   public Component getGlassPane()
 184:   {
 185:     return getRootPane().getGlassPane();
 186:   }
 187: 
 188:   public void setGlassPane(Component glassPane)
 189:   {
 190:     getRootPane().setGlassPane(glassPane);
 191:   }
 192: 
 193: 
 194:   protected void addImpl(Component comp, Object constraints, int index)
 195:   {
 196:     // If we're adding in the initialization stage use super.add.
 197:     // otherwise pass the add onto the content pane.
 198:     if (isRootPaneCheckingEnabled())
 199:       getContentPane().add(comp, constraints, index);
 200:     else
 201:       super.addImpl(comp, constraints, index);
 202:   }
 203: 
 204:   public void remove(Component comp)
 205:   {
 206:     // If we're removing the root pane, use super.remove.  Otherwise
 207:     // pass it on to the content pane instead.
 208:     if (comp == rootPane)
 209:       super.remove(rootPane);
 210:     else
 211:       getContentPane().remove(comp);
 212:   }
 213: 
 214:   protected boolean isRootPaneCheckingEnabled()
 215:   {
 216:     return rootPaneCheckingEnabled;
 217:   }
 218: 
 219:   protected void setRootPaneCheckingEnabled(boolean enabled)
 220:   {
 221:     rootPaneCheckingEnabled = enabled;
 222:   }
 223: 
 224:   public void update(Graphics g)
 225:   {
 226:     paint(g);
 227:   }
 228: 
 229:   protected void processKeyEvent(KeyEvent e)
 230:   {
 231:     super.processKeyEvent(e);
 232:   }
 233: 
 234:   public AccessibleContext getAccessibleContext()
 235:   {
 236:     if (accessibleContext == null)
 237:       accessibleContext = new AccessibleJWindow();
 238:     return accessibleContext;
 239:   }
 240: 
 241:   protected String paramString()
 242:   {
 243:     return "JWindow";
 244:   }
 245: }