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)
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
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
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. */
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
;
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
implements WindowConstants
, RootPaneContainer
62 protected AccessibleContext accessibleContext
;
64 private int close_action
= HIDE_ON_CLOSE
;
67 /***************************************************
81 public JFrame(String title
)
88 /***************************************************
91 * methods, this part is shared with JDialog, JFrame
97 private boolean checking
;
98 protected JRootPane rootPane
;
101 protected void frameInit()
103 super.setLayout(new BorderLayout(1, 1));
104 enableEvents(AWTEvent
.WINDOW_EVENT_MASK
);
105 getRootPane(); // will do set/create
108 public Dimension
getPreferredSize()
110 Dimension d
= super.getPreferredSize();
114 JMenuBar
getJMenuBar()
115 { return getRootPane().getJMenuBar(); }
117 void setJMenuBar(JMenuBar menubar
)
118 { getRootPane().setJMenuBar(menubar
); }
121 public void setLayout(LayoutManager manager
)
122 { super.setLayout(manager
); }
124 public void setLayeredPane(JLayeredPane layeredPane
)
125 { getRootPane().setLayeredPane(layeredPane
); }
127 public JLayeredPane
getLayeredPane()
128 { return getRootPane().getLayeredPane(); }
130 public JRootPane
getRootPane()
132 if (rootPane
== null)
133 setRootPane(createRootPane());
137 public void setRootPane(JRootPane root
)
139 if (rootPane
!= null)
143 add(rootPane
, BorderLayout
.CENTER
);
146 public JRootPane
createRootPane()
147 { return new JRootPane(); }
149 public Container
getContentPane()
150 { return getRootPane().getContentPane(); }
152 public void setContentPane(Container contentPane
)
153 { getRootPane().setContentPane(contentPane
); }
155 public Component
getGlassPane()
156 { return getRootPane().getGlassPane(); }
158 public void setGlassPane(Component glassPane
)
159 { getRootPane().setGlassPane(glassPane
); }
162 protected void addImpl(Component comp
, Object constraints
, int index
)
163 { super.addImpl(comp
, constraints
, index
); }
166 public void remove(Component comp
)
167 { getContentPane().remove(comp
); }
169 protected boolean isRootPaneCheckingEnabled()
173 protected void setRootPaneCheckingEnabled(boolean enabled
)
174 { checking
= enabled
; }
177 public void update(Graphics g
)
180 protected void processKeyEvent(KeyEvent e
)
181 { super.processKeyEvent(e
); }
183 /////////////////////////////////////////////////////////////////////////////////
185 public AccessibleContext
getAccessibleContext()
187 return accessibleContext
;
190 public int getDefaultCloseOperation()
191 { return close_action
; }
195 protected String
paramString()
199 protected void processWindowEvent(WindowEvent e
)
201 super.processWindowEvent(e
);
204 case WindowEvent
.WINDOW_CLOSING
:
213 case DISPOSE_ON_CLOSE
:
223 case DO_NOTHING_ON_CLOSE
:
229 case WindowEvent
.WINDOW_CLOSED
:
230 case WindowEvent
.WINDOW_OPENED
:
231 case WindowEvent
.WINDOW_ICONIFIED
:
232 case WindowEvent
.WINDOW_DEICONIFIED
:
233 case WindowEvent
.WINDOW_ACTIVATED
:
234 case WindowEvent
.WINDOW_DEACTIVATED
:
240 * Defines what happens when this frame is closed. Can be one off
241 * <code>EXIT_ON_CLOSE</code>,
242 * <code>DISPOSE_ON_CLOSE</code>,
243 * <code>HIDE_ON_CLOSE</code> or
244 * <code>DO_NOTHING_ON_CLOSE</code>.
245 * The default is <code>HIDE_ON_CLOSE</code>.
246 * When <code>EXIT_ON_CLOSE</code> is specified this method calls
247 * <code>SecurityManager.checkExit(0)</code> which might throw a
248 * <code>SecurityException</code>. When the specified operation is
249 * not one of the above a <code>IllegalArgumentException</code> is
252 public void setDefaultCloseOperation(int operation
)
254 SecurityManager sm
= System
.getSecurityManager();
255 if (sm
!= null && operation
== EXIT_ON_CLOSE
)
258 if (operation
!= EXIT_ON_CLOSE
&& operation
!= DISPOSE_ON_CLOSE
259 && operation
!= HIDE_ON_CLOSE
&& operation
!= DO_NOTHING_ON_CLOSE
)
260 throw new IllegalArgumentException("operation = " + operation
);
262 close_action
= operation
;