Frames | No Frames |
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: protected 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: /** 90: * Creates a new <code>JWindow</code> that has a shared invisible owner frame 91: * as its parent. 92: */ 93: public JWindow() 94: { 95: super(SwingUtilities.getOwnerFrame(null)); 96: windowInit(); 97: } 98: 99: /** 100: * Creates a new <code>JWindow</code> that uses the specified graphics 101: * environment. This can be used to open a window on a different screen for 102: * example. 103: * 104: * @param gc the graphics environment to use 105: */ 106: public JWindow(GraphicsConfiguration gc) 107: { 108: super(SwingUtilities.getOwnerFrame(null), gc); 109: windowInit(); 110: } 111: 112: /** 113: * Creates a new <code>JWindow</code> that has the specified 114: * <code>owner</code> frame. If <code>owner</code> is <code>null</code>, then 115: * an invisible shared owner frame is installed as owner frame. 116: * 117: * @param owner the owner frame of this window; if <code>null</code> a shared 118: * invisible owner frame is used 119: */ 120: public JWindow(Frame owner) 121: { 122: super(SwingUtilities.getOwnerFrame(owner)); 123: windowInit(); 124: } 125: 126: /** 127: * Creates a new <code>JWindow</code> that has the specified 128: * <code>owner</code> window. If <code>owner</code> is <code>null</code>, 129: * then an invisible shared owner frame is installed as owner frame. 130: * 131: * @param owner the owner window of this window; if <code>null</code> a 132: * shared invisible owner frame is used 133: */ 134: public JWindow(Window owner) 135: { 136: super(SwingUtilities.getOwnerFrame(owner)); 137: windowInit(); 138: } 139: 140: /** 141: * Creates a new <code>JWindow</code> for the given graphics configuration 142: * and that has the specified <code>owner</code> window. If 143: * <code>owner</code> is <code>null</code>, then an invisible shared owner 144: * frame is installed as owner frame. 145: * 146: * The <code>gc</code> parameter can be used to open the window on a 147: * different screen for example. 148: * 149: * @param owner the owner window of this window; if <code>null</code> a 150: * shared invisible owner frame is used 151: * @param gc the graphics configuration to use 152: */ 153: public JWindow(Window owner, GraphicsConfiguration gc) 154: { 155: super(SwingUtilities.getOwnerFrame(owner), gc); 156: windowInit(); 157: } 158: 159: protected void windowInit() 160: { 161: super.setLayout(new BorderLayout(1, 1)); 162: getRootPane(); // will do set/create 163: // Now we're done init stage, adds and layouts go to content pane. 164: setRootPaneCheckingEnabled(true); 165: } 166: 167: public Dimension getPreferredSize() 168: { 169: return super.getPreferredSize(); 170: } 171: 172: public void setLayout(LayoutManager manager) 173: { 174: // Check if we're in initialization stage. If so, call super.setLayout 175: // otherwise, valid calls go to the content pane. 176: if (isRootPaneCheckingEnabled()) 177: getContentPane().setLayout(manager); 178: else 179: super.setLayout(manager); 180: } 181: 182: public void setLayeredPane(JLayeredPane layeredPane) 183: { 184: getRootPane().setLayeredPane(layeredPane); 185: } 186: 187: public JLayeredPane getLayeredPane() 188: { 189: return getRootPane().getLayeredPane(); 190: } 191: 192: public JRootPane getRootPane() 193: { 194: if (rootPane == null) 195: setRootPane(createRootPane()); 196: return rootPane; 197: } 198: 199: protected void setRootPane(JRootPane root) 200: { 201: if (rootPane != null) 202: remove(rootPane); 203: 204: rootPane = root; 205: add(rootPane, BorderLayout.CENTER); 206: } 207: 208: protected JRootPane createRootPane() 209: { 210: return new JRootPane(); 211: } 212: 213: public Container getContentPane() 214: { 215: return getRootPane().getContentPane(); 216: } 217: 218: public void setContentPane(Container contentPane) 219: { 220: getRootPane().setContentPane(contentPane); 221: } 222: 223: public Component getGlassPane() 224: { 225: return getRootPane().getGlassPane(); 226: } 227: 228: public void setGlassPane(Component glassPane) 229: { 230: getRootPane().setGlassPane(glassPane); 231: } 232: 233: 234: protected void addImpl(Component comp, Object constraints, int index) 235: { 236: // If we're adding in the initialization stage use super.add. 237: // otherwise pass the add onto the content pane. 238: if (isRootPaneCheckingEnabled()) 239: getContentPane().add(comp, constraints, index); 240: else 241: super.addImpl(comp, constraints, index); 242: } 243: 244: public void remove(Component comp) 245: { 246: // If we're removing the root pane, use super.remove. Otherwise 247: // pass it on to the content pane instead. 248: if (comp == rootPane) 249: super.remove(rootPane); 250: else 251: getContentPane().remove(comp); 252: } 253: 254: protected boolean isRootPaneCheckingEnabled() 255: { 256: return rootPaneCheckingEnabled; 257: } 258: 259: protected void setRootPaneCheckingEnabled(boolean enabled) 260: { 261: rootPaneCheckingEnabled = enabled; 262: } 263: 264: public void update(Graphics g) 265: { 266: paint(g); 267: } 268: 269: protected void processKeyEvent(KeyEvent e) 270: { 271: super.processKeyEvent(e); 272: } 273: 274: public AccessibleContext getAccessibleContext() 275: { 276: if (accessibleContext == null) 277: accessibleContext = new AccessibleJWindow(); 278: return accessibleContext; 279: } 280: 281: protected String paramString() 282: { 283: return "JWindow"; 284: } 285: }