Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / JFrame.java
blob8d4dcb53b3c785d66b9e186c782a7ce8f4174c92
1 /* JFrame.java --
2 Copyright (C) 2002, 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.event.KeyEvent;
51 import java.awt.event.WindowEvent;
53 import javax.accessibility.Accessible;
54 import javax.accessibility.AccessibleContext;
56 /**
57 * A window that supports window decorations (titlebar and borders).
58 * This is an extension of {@link java.awt.Frame} that provides support
59 * for the Swing architecture. Most importantly it contains a {@link JRootPane}
60 * as it's only top-level child, that manages the content pane, the menu and
61 * a glass pane.
63 * Also, unlike <code>java.awt.Frame</code>s, JFrames support the
64 * Swing Pluggable Look &amp; Feel architecture.
66 * @author Ronald Veldema (rveldema@cs.vu.nl)
68 public class JFrame extends Frame
69 implements WindowConstants, RootPaneContainer, Accessible
71 /**
72 * Provides accessibility support for <code>JFrame</code>s.
74 protected class AccessibleJFrame extends Frame.AccessibleAWTFrame
76 /**
77 * Creates a new instance of <code>AccessibleJFrame</code>.
79 public AccessibleJFrame()
81 super();
82 // Nothing to do here.
86 /**
87 * A flag for {@link #setDefaultCloseOperation(int)}, indicating that the
88 * application should be exited, when this <code>JFrame</code> is closed.
90 * @since 1.3
92 public static final int EXIT_ON_CLOSE = 3;
94 private static final long serialVersionUID = -3362141868504252139L;
95 private static boolean defaultLookAndFeelDecorated;
96 private int close_action = HIDE_ON_CLOSE;
97 protected AccessibleContext accessibleContext;
98 protected JRootPane rootPane;
101 * @specnote rootPaneCheckingEnabled is false to comply with J2SE 5.0
103 protected boolean rootPaneCheckingEnabled = false;
105 public JFrame()
107 super("JFrame");
108 frameInit();
111 public JFrame(String title)
113 super(title);
114 frameInit();
118 * Creates a new JFrame in the specified {@link GraphicsConfiguration}
119 * and with an empty title.
121 * @param gc the <code>GraphicsConfiguration</code> that is used for
122 * the new <code>JFrame</code>
124 * @see Frame#Frame(GraphicsConfiguration)
126 public JFrame(GraphicsConfiguration gc)
128 super(gc);
129 frameInit();
133 * Creates a new JFrame in the specified {@link GraphicsConfiguration}
134 * and with the specified title.
136 * @param title the title for the new <code>JFrame</code>
137 * @param gc the <code>GraphicsConfiguration</code> that is used for
138 * the new <code>JFrame</code>
140 * @see Frame#Frame(String, GraphicsConfiguration)
142 public JFrame(String title, GraphicsConfiguration gc)
144 super(title, gc);
145 frameInit();
148 protected void frameInit()
150 super.setLayout(new BorderLayout(1, 1));
151 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
152 getRootPane(); // will do set/create
153 // We're now done the init stage.
154 setRootPaneCheckingEnabled(true);
157 public Dimension getPreferredSize()
159 return super.getPreferredSize();
162 public JMenuBar getJMenuBar()
164 return getRootPane().getJMenuBar();
167 public void setJMenuBar(JMenuBar menubar)
169 getRootPane().setJMenuBar(menubar);
172 public void setLayout(LayoutManager manager)
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);
182 public void setLayeredPane(JLayeredPane layeredPane)
184 getRootPane().setLayeredPane(layeredPane);
187 public JLayeredPane getLayeredPane()
189 return getRootPane().getLayeredPane();
192 public JRootPane getRootPane()
194 if (rootPane == null)
195 setRootPane(createRootPane());
196 return rootPane;
199 protected void setRootPane(JRootPane root)
201 if (rootPane != null)
202 remove(rootPane);
204 rootPane = root;
205 add(rootPane, BorderLayout.CENTER);
208 protected JRootPane createRootPane()
210 return new JRootPane();
213 public Container getContentPane()
215 return getRootPane().getContentPane();
218 public void setContentPane(Container contentPane)
220 getRootPane().setContentPane(contentPane);
223 public Component getGlassPane()
225 return getRootPane().getGlassPane();
228 public void setGlassPane(Component glassPane)
230 getRootPane().setGlassPane(glassPane);
233 protected void addImpl(Component comp, Object constraints, int index)
235 // If we're adding in the initialization stage use super.add.
236 // Otherwise pass the add onto the content pane.
237 if (isRootPaneCheckingEnabled())
238 getContentPane().add(comp,constraints,index);
239 else
240 super.addImpl(comp, constraints, index);
243 public void remove(Component comp)
245 // If we're removing the root pane, use super.remove. Otherwise
246 // pass it on to the content pane instead.
247 if (comp==rootPane)
248 super.remove(rootPane);
249 else
250 getContentPane().remove(comp);
253 protected boolean isRootPaneCheckingEnabled()
255 return rootPaneCheckingEnabled;
258 protected void setRootPaneCheckingEnabled(boolean enabled)
260 rootPaneCheckingEnabled = enabled;
263 public void update(Graphics g)
265 paint(g);
268 protected void processKeyEvent(KeyEvent e)
270 super.processKeyEvent(e);
273 public static void setDefaultLookAndFeelDecorated(boolean decorated)
275 defaultLookAndFeelDecorated = decorated;
278 public static boolean isDefaultLookAndFeelDecorated()
280 return defaultLookAndFeelDecorated;
283 public AccessibleContext getAccessibleContext()
285 if (accessibleContext == null)
286 accessibleContext = new AccessibleJFrame();
287 return accessibleContext;
290 public int getDefaultCloseOperation()
292 return close_action;
295 protected String paramString()
297 return "JFrame";
300 protected void processWindowEvent(WindowEvent e)
302 super.processWindowEvent(e);
303 switch (e.getID())
305 case WindowEvent.WINDOW_CLOSING:
307 switch (close_action)
309 case EXIT_ON_CLOSE:
311 System.exit(0);
312 break;
314 case DISPOSE_ON_CLOSE:
316 dispose();
317 break;
319 case HIDE_ON_CLOSE:
321 setVisible(false);
322 break;
324 case DO_NOTHING_ON_CLOSE:
325 break;
327 break;
329 case WindowEvent.WINDOW_CLOSED:
330 case WindowEvent.WINDOW_OPENED:
331 case WindowEvent.WINDOW_ICONIFIED:
332 case WindowEvent.WINDOW_DEICONIFIED:
333 case WindowEvent.WINDOW_ACTIVATED:
334 case WindowEvent.WINDOW_DEACTIVATED:
335 break;
340 * Defines what happens when this frame is closed. Can be one off
341 * <code>EXIT_ON_CLOSE</code>,
342 * <code>DISPOSE_ON_CLOSE</code>,
343 * <code>HIDE_ON_CLOSE</code> or
344 * <code>DO_NOTHING_ON_CLOSE</code>.
345 * The default is <code>HIDE_ON_CLOSE</code>.
346 * When <code>EXIT_ON_CLOSE</code> is specified this method calls
347 * <code>SecurityManager.checkExit(0)</code> which might throw a
348 * <code>SecurityException</code>. When the specified operation is
349 * not one of the above a <code>IllegalArgumentException</code> is
350 * thrown.
352 public void setDefaultCloseOperation(int operation)
354 SecurityManager sm = System.getSecurityManager();
355 if (sm != null && operation == EXIT_ON_CLOSE)
356 sm.checkExit(0);
358 if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
359 && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
360 throw new IllegalArgumentException("defaultCloseOperation must be EXIT_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or DO_NOTHING_ON_CLOSE");
362 close_action = operation;