2004-10-22 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / libjava / javax / swing / JFrame.java
blobaa641caa3c40ca3caffaa40b2538b0bfac856311
1 /* JFrame.java --
2 Copyright (C) 2002, 2004 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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.LayoutManager;
49 import java.awt.event.KeyEvent;
50 import java.awt.event.WindowEvent;
52 import javax.accessibility.AccessibleContext;
54 /**
55 * Unlike JComponent derivatives, JFrame inherits from
56 * java.awt.Frame. But also lets a look-and-feel component to its work.
58 * @author Ronald Veldema (rveldema@cs.vu.nl)
60 public class JFrame extends Frame
61 implements WindowConstants, RootPaneContainer
63 private static final long serialVersionUID = -3362141868504252139L;
64 private static boolean defaultLookAndFeelDecorated;
65 private int close_action = HIDE_ON_CLOSE;
66 protected AccessibleContext accessibleContext;
67 protected JRootPane rootPane;
68 protected boolean rootPaneCheckingEnabled;
70 public JFrame()
72 super("JFrame");
73 frameInit();
76 public JFrame(String title)
78 super(title);
79 frameInit();
82 protected void frameInit()
84 super.setLayout(new BorderLayout(1, 1));
85 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
86 getRootPane(); // will do set/create
89 public Dimension getPreferredSize()
91 return super.getPreferredSize();
94 public JMenuBar getJMenuBar()
96 return getRootPane().getJMenuBar();
99 public void setJMenuBar(JMenuBar menubar)
101 getRootPane().setJMenuBar(menubar);
104 public void setLayout(LayoutManager manager)
106 super.setLayout(manager);
109 public void setLayeredPane(JLayeredPane layeredPane)
111 getRootPane().setLayeredPane(layeredPane);
114 public JLayeredPane getLayeredPane()
116 return getRootPane().getLayeredPane();
119 public JRootPane getRootPane()
121 if (rootPane == null)
122 setRootPane(createRootPane());
123 return rootPane;
126 public void setRootPane(JRootPane root)
128 if (rootPane != null)
129 remove(rootPane);
131 rootPane = root;
132 add(rootPane, BorderLayout.CENTER);
135 public JRootPane createRootPane()
137 return new JRootPane();
140 public Container getContentPane()
142 return getRootPane().getContentPane();
145 public void setContentPane(Container contentPane)
147 getRootPane().setContentPane(contentPane);
150 public Component getGlassPane()
152 return getRootPane().getGlassPane();
155 public void setGlassPane(Component glassPane)
157 getRootPane().setGlassPane(glassPane);
160 protected void addImpl(Component comp, Object constraints, int index)
162 super.addImpl(comp, constraints, index);
165 public void remove(Component comp)
167 getContentPane().remove(comp);
170 protected boolean isRootPaneCheckingEnabled()
172 return rootPaneCheckingEnabled;
175 protected void setRootPaneCheckingEnabled(boolean enabled)
177 rootPaneCheckingEnabled = enabled;
180 public void update(Graphics g)
182 paint(g);
185 protected void processKeyEvent(KeyEvent e)
187 super.processKeyEvent(e);
190 public static void setDefaultLookAndFeelDecorated(boolean decorated)
192 defaultLookAndFeelDecorated = decorated;
195 public static boolean isDefaultLookAndFeelDecorated()
197 return defaultLookAndFeelDecorated;
200 public AccessibleContext getAccessibleContext()
202 return accessibleContext;
205 public int getDefaultCloseOperation()
207 return close_action;
210 protected String paramString()
212 return "JFrame";
215 protected void processWindowEvent(WindowEvent e)
217 super.processWindowEvent(e);
218 switch (e.getID())
220 case WindowEvent.WINDOW_CLOSING:
222 switch (close_action)
224 case EXIT_ON_CLOSE:
226 System.exit(0);
227 break;
229 case DISPOSE_ON_CLOSE:
231 dispose();
232 break;
234 case HIDE_ON_CLOSE:
236 setVisible(false);
237 break;
239 case DO_NOTHING_ON_CLOSE:
240 break;
242 break;
244 case WindowEvent.WINDOW_CLOSED:
245 case WindowEvent.WINDOW_OPENED:
246 case WindowEvent.WINDOW_ICONIFIED:
247 case WindowEvent.WINDOW_DEICONIFIED:
248 case WindowEvent.WINDOW_ACTIVATED:
249 case WindowEvent.WINDOW_DEACTIVATED:
250 break;
255 * Defines what happens when this frame is closed. Can be one off
256 * <code>EXIT_ON_CLOSE</code>,
257 * <code>DISPOSE_ON_CLOSE</code>,
258 * <code>HIDE_ON_CLOSE</code> or
259 * <code>DO_NOTHING_ON_CLOSE</code>.
260 * The default is <code>HIDE_ON_CLOSE</code>.
261 * When <code>EXIT_ON_CLOSE</code> is specified this method calls
262 * <code>SecurityManager.checkExit(0)</code> which might throw a
263 * <code>SecurityException</code>. When the specified operation is
264 * not one of the above a <code>IllegalArgumentException</code> is
265 * thrown.
267 public void setDefaultCloseOperation(int operation)
269 SecurityManager sm = System.getSecurityManager();
270 if (sm != null && operation == EXIT_ON_CLOSE)
271 sm.checkExit(0);
273 if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
274 && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
275 throw new IllegalArgumentException("operation = " + operation);
277 close_action = operation;