]> gcc.gnu.org Git - gcc.git/blob - libjava/javax/swing/JFrame.java
[multiple changes]
[gcc.git] / libjava / javax / swing / JFrame.java
1 /* JFrame.java --
2 Copyright (C) 2002, 2004 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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.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;
51
52 import javax.accessibility.AccessibleContext;
53
54 /**
55 * Unlike JComponent derivatives, JFrame inherits from
56 * java.awt.Frame. But also lets a look-and-feel component to its work.
57 *
58 * @author Ronald Veldema (rveldema@cs.vu.nl)
59 */
60 public class JFrame extends Frame implements WindowConstants, RootPaneContainer
61 {
62 protected AccessibleContext accessibleContext;
63
64 private int close_action = HIDE_ON_CLOSE;
65
66
67 /***************************************************
68 *
69 * initia
70 *
71 *
72 *************/
73
74
75 public JFrame()
76 {
77 super("JFrame");
78 frameInit();
79 }
80
81 public JFrame(String title)
82 {
83 super(title);
84 frameInit();
85 }
86
87
88 /***************************************************
89 *
90 *
91 * methods, this part is shared with JDialog, JFrame
92 *
93 *
94 *************/
95
96
97 private boolean checking;
98 protected JRootPane rootPane;
99
100
101 protected void frameInit()
102 {
103 super.setLayout(new BorderLayout(1, 1));
104 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
105 getRootPane(); // will do set/create
106 }
107
108 public Dimension getPreferredSize()
109 {
110 Dimension d = super.getPreferredSize();
111 return d;
112 }
113
114 JMenuBar getJMenuBar()
115 { return getRootPane().getJMenuBar(); }
116
117 void setJMenuBar(JMenuBar menubar)
118 { getRootPane().setJMenuBar(menubar); }
119
120
121 public void setLayout(LayoutManager manager)
122 { super.setLayout(manager); }
123
124 public void setLayeredPane(JLayeredPane layeredPane)
125 { getRootPane().setLayeredPane(layeredPane); }
126
127 public JLayeredPane getLayeredPane()
128 { return getRootPane().getLayeredPane(); }
129
130 public JRootPane getRootPane()
131 {
132 if (rootPane == null)
133 setRootPane(createRootPane());
134 return rootPane;
135 }
136
137 public void setRootPane(JRootPane root)
138 {
139 if (rootPane != null)
140 remove(rootPane);
141
142 rootPane = root;
143 add(rootPane, BorderLayout.CENTER);
144 }
145
146 public JRootPane createRootPane()
147 { return new JRootPane(); }
148
149 public Container getContentPane()
150 { return getRootPane().getContentPane(); }
151
152 public void setContentPane(Container contentPane)
153 { getRootPane().setContentPane(contentPane); }
154
155 public Component getGlassPane()
156 { return getRootPane().getGlassPane(); }
157
158 public void setGlassPane(Component glassPane)
159 { getRootPane().setGlassPane(glassPane); }
160
161
162 protected void addImpl(Component comp, Object constraints, int index)
163 { super.addImpl(comp, constraints, index); }
164
165
166 public void remove(Component comp)
167 { getContentPane().remove(comp); }
168
169 protected boolean isRootPaneCheckingEnabled()
170 { return checking; }
171
172
173 protected void setRootPaneCheckingEnabled(boolean enabled)
174 { checking = enabled; }
175
176
177 public void update(Graphics g)
178 { paint(g); }
179
180 protected void processKeyEvent(KeyEvent e)
181 { super.processKeyEvent(e); }
182
183 /////////////////////////////////////////////////////////////////////////////////
184
185 public AccessibleContext getAccessibleContext()
186 {
187 return accessibleContext;
188 }
189
190 public int getDefaultCloseOperation()
191 { return close_action; }
192
193
194
195 protected String paramString()
196 { return "JFrame"; }
197
198
199 protected void processWindowEvent(WindowEvent e)
200 {
201 super.processWindowEvent(e);
202 switch (e.getID())
203 {
204 case WindowEvent.WINDOW_CLOSING:
205 {
206 switch(close_action)
207 {
208 case EXIT_ON_CLOSE:
209 {
210 System.exit(0);
211 break;
212 }
213 case DISPOSE_ON_CLOSE:
214 {
215 dispose();
216 break;
217 }
218 case HIDE_ON_CLOSE:
219 {
220 setVisible(false);
221 break;
222 }
223 case DO_NOTHING_ON_CLOSE:
224 break;
225 }
226 break;
227 }
228
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:
235 break;
236 }
237 }
238
239 /**
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
250 * thrown.
251 */
252 public void setDefaultCloseOperation(int operation)
253 {
254 SecurityManager sm = System.getSecurityManager();
255 if (sm != null && operation == EXIT_ON_CLOSE)
256 sm.checkExit(0);
257
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);
261
262 close_action = operation;
263 }
264
265 }
This page took 0.043593 seconds and 5 git commands to generate.