2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / libjava / classpath / javax / swing / JWindow.java
blob91e0b50698ea375651fe248336bd8b58469547eb
1 /* JWindow.java --
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package javax.swing;
41 import java.awt.AWTEvent;
42 import java.awt.BorderLayout;
43 import java.awt.Component;
44 import java.awt.Container;
45 import java.awt.Dimension;
46 import java.awt.Frame;
47 import java.awt.Graphics;
48 import java.awt.GraphicsConfiguration;
49 import java.awt.LayoutManager;
50 import java.awt.Window;
51 import java.awt.event.KeyEvent;
53 import javax.accessibility.Accessible;
54 import javax.accessibility.AccessibleContext;
56 /**
57 * Unlike JComponent derivatives, JWindow inherits from
58 * java.awt.Window. But also lets a look-and-feel component to its work.
60 * @author Ronald Veldema (rveldema@cs.vu.nl)
62 public class JWindow extends Window implements Accessible, RootPaneContainer
64 /**
65 * Provides accessibility support for <code>JWindow</code>.
67 protected class AccessibleJWindow extends Window.AccessibleAWTWindow
69 /**
70 * Creates a new instance of <code>AccessibleJWindow</code>.
72 protected AccessibleJWindow()
74 super();
75 // Nothing to do here.
79 private static final long serialVersionUID = 5420698392125238833L;
81 protected JRootPane rootPane;
83 /**
84 * @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
86 protected boolean rootPaneCheckingEnabled = false;
88 protected AccessibleContext accessibleContext;
90 /**
91 * Creates a new <code>JWindow</code> that has a shared invisible owner frame
92 * as its parent.
94 public JWindow()
96 super(SwingUtilities.getOwnerFrame(null));
97 windowInit();
101 * Creates a new <code>JWindow</code> that uses the specified graphics
102 * environment. This can be used to open a window on a different screen for
103 * example.
105 * @param gc the graphics environment to use
107 public JWindow(GraphicsConfiguration gc)
109 super(SwingUtilities.getOwnerFrame(null), gc);
110 windowInit();
114 * Creates a new <code>JWindow</code> that has the specified
115 * <code>owner</code> frame. If <code>owner</code> is <code>null</code>, then
116 * an invisible shared owner frame is installed as owner frame.
118 * @param owner the owner frame of this window; if <code>null</code> a shared
119 * invisible owner frame is used
121 public JWindow(Frame owner)
123 super(SwingUtilities.getOwnerFrame(owner));
124 windowInit();
128 * Creates a new <code>JWindow</code> that has the specified
129 * <code>owner</code> window. If <code>owner</code> is <code>null</code>,
130 * then an invisible shared owner frame is installed as owner frame.
132 * @param owner the owner window of this window; if <code>null</code> a
133 * shared invisible owner frame is used
135 public JWindow(Window owner)
137 super(SwingUtilities.getOwnerFrame(owner));
138 windowInit();
142 * Creates a new <code>JWindow</code> for the given graphics configuration
143 * and that has the specified <code>owner</code> window. If
144 * <code>owner</code> is <code>null</code>, then an invisible shared owner
145 * frame is installed as owner frame.
147 * The <code>gc</code> parameter can be used to open the window on a
148 * different screen for example.
150 * @param owner the owner window of this window; if <code>null</code> a
151 * shared invisible owner frame is used
152 * @param gc the graphics configuration to use
154 public JWindow(Window owner, GraphicsConfiguration gc)
156 super(SwingUtilities.getOwnerFrame(owner), gc);
157 windowInit();
160 protected void windowInit()
162 // We need to explicitly enable events here so that our processKeyEvent()
163 // and processWindowEvent() gets called.
164 enableEvents(AWTEvent.KEY_EVENT_MASK);
166 super.setLayout(new BorderLayout(1, 1));
167 getRootPane(); // will do set/create
168 // Now we're done init stage, adds and layouts go to content pane.
169 setRootPaneCheckingEnabled(true);
172 public Dimension getPreferredSize()
174 return super.getPreferredSize();
177 public void setLayout(LayoutManager manager)
179 // Check if we're in initialization stage. If so, call super.setLayout
180 // otherwise, valid calls go to the content pane.
181 if (isRootPaneCheckingEnabled())
182 getContentPane().setLayout(manager);
183 else
184 super.setLayout(manager);
187 public void setLayeredPane(JLayeredPane layeredPane)
189 getRootPane().setLayeredPane(layeredPane);
192 public JLayeredPane getLayeredPane()
194 return getRootPane().getLayeredPane();
197 public JRootPane getRootPane()
199 if (rootPane == null)
200 setRootPane(createRootPane());
201 return rootPane;
204 protected void setRootPane(JRootPane root)
206 if (rootPane != null)
207 remove(rootPane);
209 rootPane = root;
210 add(rootPane, BorderLayout.CENTER);
213 protected JRootPane createRootPane()
215 return new JRootPane();
218 public Container getContentPane()
220 return getRootPane().getContentPane();
223 public void setContentPane(Container contentPane)
225 getRootPane().setContentPane(contentPane);
228 public Component getGlassPane()
230 return getRootPane().getGlassPane();
233 public void setGlassPane(Component glassPane)
235 getRootPane().setGlassPane(glassPane);
239 protected void addImpl(Component comp, Object constraints, int index)
241 // If we're adding in the initialization stage use super.add.
242 // otherwise pass the add onto the content pane.
243 if (isRootPaneCheckingEnabled())
244 getContentPane().add(comp, constraints, index);
245 else
246 super.addImpl(comp, constraints, index);
249 public void remove(Component comp)
251 // If we're removing the root pane, use super.remove. Otherwise
252 // pass it on to the content pane instead.
253 if (comp == rootPane)
254 super.remove(rootPane);
255 else
256 getContentPane().remove(comp);
259 protected boolean isRootPaneCheckingEnabled()
261 return rootPaneCheckingEnabled;
264 protected void setRootPaneCheckingEnabled(boolean enabled)
266 rootPaneCheckingEnabled = enabled;
269 public void update(Graphics g)
271 paint(g);
274 protected void processKeyEvent(KeyEvent e)
276 super.processKeyEvent(e);
279 public AccessibleContext getAccessibleContext()
281 if (accessibleContext == null)
282 accessibleContext = new AccessibleJWindow();
283 return accessibleContext;
286 protected String paramString()
288 return "JWindow";