]>
Commit | Line | Data |
---|---|---|
3bd483f2 | 1 | /* Copyright (C) 1999, 2000, 2002 Free Software Foundation |
fd164b17 | 2 | |
3bd483f2 | 3 | Copyright (C) 1999 Free Software Foundation, Inc. |
fd164b17 | 4 | |
3bd483f2 TT |
5 | This file is part of GNU Classpath. |
6 | ||
7 | GNU Classpath is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU Classpath is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Classpath; see the file COPYING. If not, write to the | |
19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
20 | 02111-1307 USA. | |
21 | ||
22 | As a special exception, if you link this library with other files to | |
23 | produce an executable, this library does not by itself cause the | |
24 | resulting executable to be covered by the GNU General Public License. | |
25 | This exception does not however invalidate any other reasons why the | |
26 | executable file might be covered by the GNU General Public License. */ | |
fd164b17 PB |
27 | |
28 | package java.awt; | |
e0a339f7 | 29 | import java.awt.event.WindowEvent; |
fd164b17 | 30 | import java.awt.event.WindowListener; |
e0a339f7 TT |
31 | import java.awt.peer.WindowPeer; |
32 | import java.awt.peer.ComponentPeer; | |
b9960613 | 33 | import java.util.EventListener; |
e0a339f7 | 34 | import java.util.Locale; |
b9960613 | 35 | import java.util.ResourceBundle; |
fd164b17 | 36 | |
3bd483f2 TT |
37 | /** |
38 | * This class represents a top-level window with no decorations. | |
39 | * | |
40 | * @author Aaron M. Renn (arenn@urbanophile.com) | |
41 | * @author Warren Levy <warrenl@cygnus.com> | |
42 | */ | |
fd164b17 PB |
43 | public class Window extends Container |
44 | { | |
b9960613 BM |
45 | // Serialized fields, from Sun's serialization spec. |
46 | // private FocusManager focusMgr; // FIXME: what is this? | |
47 | private String warningString = null; | |
48 | private int state = 0; | |
49 | private int windowSerializedDataVersion = 0; // FIXME | |
50 | ||
51 | private transient WindowListener windowListener; | |
52 | private transient GraphicsConfiguration graphicsConfiguration; | |
53 | ||
777e6d79 RR |
54 | /** |
55 | * This (package access) constructor is used by subclasses that want | |
56 | * to build windows that do not have parents. Eg. toplevel | |
57 | * application frames. Subclasses cannot call super(null), since | |
58 | * null is an illegal argument. | |
59 | */ | |
60 | Window() | |
61 | { | |
62 | setVisible(false); | |
63 | setLayout((LayoutManager) new BorderLayout()); | |
64 | } | |
65 | ||
66 | Window(GraphicsConfiguration gc) | |
67 | { | |
68 | this(); | |
69 | graphicsConfiguration = gc; | |
70 | } | |
71 | ||
3bd483f2 TT |
72 | /** |
73 | * Initializes a new instance of <code>Window</code> with the specified | |
74 | * parent. The window will initially be invisible. | |
75 | * | |
76 | * @param parent The owning <code>Frame</code> of this window. | |
77 | */ | |
b9960613 BM |
78 | public Window(Frame owner) |
79 | { | |
777e6d79 | 80 | this((Window) owner); |
b9960613 BM |
81 | } |
82 | ||
83 | /** @since 1.2 */ | |
84 | public Window(Window owner) | |
e0a339f7 | 85 | { |
777e6d79 RR |
86 | this(); |
87 | if (owner == null) | |
88 | throw new IllegalArgumentException("owner must not be null"); | |
89 | ||
90 | this.parent = owner; | |
91 | ||
92 | // FIXME: add to owner's "owned window" list | |
93 | //owner.owned.add(this); // this should be a weak reference | |
b9960613 BM |
94 | } |
95 | ||
96 | /** @since 1.3 */ | |
97 | public Window(Window owner, GraphicsConfiguration gc) | |
98 | { | |
777e6d79 RR |
99 | this(owner); |
100 | ||
b9960613 BM |
101 | /* FIXME: Security check |
102 | SecurityManager.checkTopLevelWindow(...) | |
103 | ||
104 | if (gc != null | |
105 | && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN) | |
106 | throw new IllegalArgumentException ("gc must be from a screen device"); | |
107 | ||
108 | if (gc == null) | |
109 | graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment() | |
110 | .getDefaultScreenDevice() | |
111 | .getDefaultConfiguration(); | |
112 | else | |
113 | */ | |
777e6d79 RR |
114 | graphicsConfiguration = gc; |
115 | } | |
b9960613 | 116 | |
777e6d79 RR |
117 | GraphicsConfiguration getGraphicsConfigurationImpl() |
118 | { | |
119 | if (graphicsConfiguration != null) | |
120 | return graphicsConfiguration; | |
121 | ||
122 | return super.getGraphicsConfigurationImpl(); | |
e0a339f7 TT |
123 | } |
124 | ||
b9960613 BM |
125 | protected void finalize() throws Throwable |
126 | { | |
127 | // FIXME: remove from owner's "owned window" list (Weak References) | |
777e6d79 | 128 | super.finalize(); |
b9960613 BM |
129 | } |
130 | ||
3bd483f2 TT |
131 | /** |
132 | * Creates the native peer for this window. | |
133 | */ | |
b9960613 | 134 | public void addNotify() |
e0a339f7 TT |
135 | { |
136 | if (peer == null) | |
da68e693 | 137 | peer = getToolkit ().createWindow (this); |
777e6d79 | 138 | super.addNotify (); |
e0a339f7 | 139 | } |
fd164b17 | 140 | |
3bd483f2 TT |
141 | /** |
142 | * Relays out this window's child components at their preferred size. | |
143 | * | |
144 | * @specnote pack() doesn't appear to be called internally by show(), so | |
145 | * we duplicate some of the functionality. | |
146 | */ | |
b9960613 | 147 | public void pack() |
e0a339f7 | 148 | { |
b9960613 BM |
149 | if (parent != null |
150 | && !parent.isDisplayable()) | |
151 | parent.addNotify(); | |
777e6d79 | 152 | if (peer == null) |
b9960613 | 153 | addNotify(); |
777e6d79 RR |
154 | |
155 | setSize(getPreferredSize()); | |
b9960613 BM |
156 | |
157 | validate(); | |
158 | } | |
159 | ||
3bd483f2 TT |
160 | /** |
161 | * Makes this window visible and brings it to the front. | |
162 | */ | |
b9960613 BM |
163 | public void show () |
164 | { | |
777e6d79 RR |
165 | if (peer == null) |
166 | addNotify(); | |
b9960613 | 167 | |
3bd483f2 TT |
168 | super.show(); |
169 | toFront(); | |
b9960613 BM |
170 | } |
171 | ||
172 | public void hide() | |
173 | { | |
174 | // FIXME: call hide() on amy "owned" children here. | |
175 | super.hide(); | |
176 | } | |
177 | ||
3bd483f2 TT |
178 | /** |
179 | * Called to free any resource associated with this window. | |
180 | */ | |
b9960613 BM |
181 | public void dispose() |
182 | { | |
777e6d79 RR |
183 | hide(); |
184 | ||
185 | Window[] list = getOwnedWindows(); | |
186 | for (int i=0; i<list.length; i++) | |
187 | list[i].dispose(); | |
188 | ||
b9960613 BM |
189 | for (int i = 0; i < ncomponents; ++i) |
190 | component[i].removeNotify(); | |
191 | this.removeNotify(); | |
e0a339f7 TT |
192 | } |
193 | ||
3bd483f2 TT |
194 | /** |
195 | * Sends this window to the back so that all other windows display in | |
196 | * front of it. | |
197 | */ | |
b9960613 | 198 | public void toBack () |
e0a339f7 | 199 | { |
b9960613 BM |
200 | if (peer != null) |
201 | { | |
202 | WindowPeer wp = (WindowPeer) peer; | |
203 | wp.toBack (); | |
204 | } | |
e0a339f7 TT |
205 | } |
206 | ||
3bd483f2 TT |
207 | /** |
208 | * Brings this window to the front so that it displays in front of | |
209 | * any other windows. | |
210 | */ | |
b9960613 | 211 | public void toFront () |
e0a339f7 | 212 | { |
b9960613 BM |
213 | if (peer != null) |
214 | { | |
215 | WindowPeer wp = (WindowPeer) peer; | |
216 | wp.toFront (); | |
217 | } | |
218 | } | |
219 | ||
3bd483f2 TT |
220 | /** |
221 | * Returns the toolkit used to create this window. | |
222 | * | |
223 | * @return The toolkit used to create this window. | |
224 | * | |
225 | * @specnote Unlike Component.getToolkit, this implementation always | |
226 | * returns the value of Toolkit.getDefaultToolkit(). | |
227 | */ | |
b9960613 BM |
228 | public Toolkit getToolkit() |
229 | { | |
0acff4bc | 230 | return Toolkit.getDefaultToolkit (); |
b9960613 BM |
231 | } |
232 | ||
3bd483f2 TT |
233 | /** |
234 | * Returns the warning string that will be displayed if this window is | |
235 | * popped up by an unsecure applet or application. | |
236 | * | |
237 | * @return The unsecure window warning message. | |
238 | */ | |
b9960613 BM |
239 | public final String getWarningString() |
240 | { | |
241 | boolean secure = true; | |
242 | /* boolean secure = SecurityManager.checkTopLevelWindow(...) */ | |
243 | ||
244 | if (!secure) | |
245 | { | |
246 | if (warningString != null) | |
247 | return warningString; | |
248 | else | |
249 | { | |
250 | String warning = System.getProperty("awt.appletWarning"); | |
251 | return warning; | |
252 | } | |
253 | } | |
254 | return null; | |
e0a339f7 | 255 | } |
fd164b17 | 256 | |
3bd483f2 TT |
257 | /** |
258 | * Returns the locale that this window is configured for. | |
259 | * | |
260 | * @return The locale this window is configured for. | |
261 | */ | |
e0a339f7 TT |
262 | public Locale getLocale () |
263 | { | |
264 | return locale == null ? Locale.getDefault () : locale; | |
265 | } | |
266 | ||
b9960613 BM |
267 | /* |
268 | /** @since 1.2 | |
269 | public InputContext getInputContext() | |
e0a339f7 | 270 | { |
b9960613 | 271 | // FIXME |
e0a339f7 | 272 | } |
b9960613 | 273 | */ |
e0a339f7 | 274 | |
3bd483f2 TT |
275 | /** |
276 | * Sets the cursor for this window to the specifiec cursor. | |
277 | * | |
278 | * @param cursor The new cursor for this window. | |
279 | */ | |
b9960613 | 280 | public void setCursor(Cursor cursor) |
e0a339f7 | 281 | { |
b9960613 BM |
282 | super.setCursor(cursor); |
283 | } | |
284 | ||
285 | public Window getOwner() | |
286 | { | |
777e6d79 | 287 | return (Window) parent; |
e0a339f7 TT |
288 | } |
289 | ||
b9960613 BM |
290 | /** @since 1.2 */ |
291 | public Window[] getOwnedWindows() | |
e0a339f7 | 292 | { |
b9960613 BM |
293 | // FIXME: return array containing all the windows this window currently |
294 | // owns. | |
295 | return null; | |
296 | } | |
297 | ||
3bd483f2 TT |
298 | /** |
299 | * Adds the specified listener to the list of <code>WindowListeners</code> | |
300 | * that will receive events for this window. | |
301 | * | |
302 | * @param listener The <code>WindowListener</code> to add. | |
303 | */ | |
b9960613 BM |
304 | public synchronized void addWindowListener (WindowListener listener) |
305 | { | |
306 | windowListener = AWTEventMulticaster.add (windowListener, listener); | |
307 | } | |
308 | ||
3bd483f2 TT |
309 | /** |
310 | * Removes the specified listener from the list of | |
311 | * <code>WindowListeners</code> that will receive events for this window. | |
312 | * | |
313 | * @param listener The <code>WindowListener</code> to remove. | |
314 | */ | |
b9960613 BM |
315 | public synchronized void removeWindowListener (WindowListener listener) |
316 | { | |
317 | windowListener = AWTEventMulticaster.remove (windowListener, listener); | |
318 | } | |
319 | ||
320 | /** @since 1.3 */ | |
321 | public EventListener[] getListeners(Class listenerType) | |
322 | { | |
323 | if (listenerType == WindowListener.class) | |
324 | return getListenersImpl(listenerType, windowListener); | |
325 | else return super.getListeners(listenerType); | |
326 | } | |
327 | ||
328 | void dispatchEventImpl(AWTEvent e) | |
329 | { | |
330 | // Make use of event id's in order to avoid multiple instanceof tests. | |
331 | if (e.id <= WindowEvent.WINDOW_LAST | |
332 | && e.id >= WindowEvent.WINDOW_FIRST | |
333 | && (windowListener != null | |
334 | || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) | |
335 | processEvent(e); | |
336 | else | |
337 | super.dispatchEventImpl(e); | |
e0a339f7 TT |
338 | } |
339 | ||
3bd483f2 TT |
340 | /** |
341 | * Processes the specified event for this window. If the event is an | |
342 | * instance of <code>WindowEvent</code>, then | |
343 | * <code>processWindowEvent()</code> is called to process the event, | |
344 | * otherwise the superclass version of this method is invoked. | |
345 | * | |
346 | * @param event The event to process. | |
347 | */ | |
e0a339f7 TT |
348 | protected void processEvent (AWTEvent evt) |
349 | { | |
350 | if (evt instanceof WindowEvent) | |
351 | processWindowEvent ((WindowEvent) evt); | |
352 | else | |
353 | super.processEvent (evt); | |
354 | } | |
355 | ||
3bd483f2 TT |
356 | /** |
357 | * Dispatches this event to any listeners that are listening for | |
358 | * <code>WindowEvents</code> on this window. This method only gets | |
359 | * invoked if it is enabled via <code>enableEvents()</code> or if | |
360 | * a listener has been added. | |
361 | * | |
362 | * @param event The event to process. | |
363 | */ | |
e0a339f7 TT |
364 | protected void processWindowEvent (WindowEvent evt) |
365 | { | |
366 | if (windowListener != null) | |
367 | { | |
368 | switch (evt.getID ()) | |
369 | { | |
370 | case WindowEvent.WINDOW_ACTIVATED: | |
371 | windowListener.windowActivated (evt); | |
372 | break; | |
373 | case WindowEvent.WINDOW_CLOSED: | |
374 | windowListener.windowClosed (evt); | |
375 | break; | |
376 | case WindowEvent.WINDOW_CLOSING: | |
377 | windowListener.windowClosing (evt); | |
378 | break; | |
379 | case WindowEvent.WINDOW_DEACTIVATED: | |
380 | windowListener.windowDeactivated (evt); | |
381 | break; | |
382 | case WindowEvent.WINDOW_DEICONIFIED: | |
383 | windowListener.windowDeiconified (evt); | |
384 | break; | |
385 | case WindowEvent.WINDOW_ICONIFIED: | |
386 | windowListener.windowIconified (evt); | |
387 | break; | |
388 | case WindowEvent.WINDOW_OPENED: | |
389 | windowListener.windowOpened (evt); | |
390 | break; | |
391 | } | |
392 | } | |
393 | } | |
394 | ||
3bd483f2 TT |
395 | /** |
396 | * Returns the child window that has focus if this window is active. | |
397 | * This method returns <code>null</code> if this window is not active | |
398 | * or no children have focus. | |
399 | * | |
400 | * @return The component that has focus, or <code>null</code> if no | |
401 | * component has focus. | |
402 | */ | |
b9960613 | 403 | public Component getFocusOwner() |
e0a339f7 | 404 | { |
b9960613 BM |
405 | // FIXME |
406 | return null; | |
e0a339f7 | 407 | } |
fd164b17 | 408 | |
3bd483f2 TT |
409 | /** |
410 | * Post a Java 1.0 event to the event queue. | |
411 | * | |
412 | * @param event The event to post. | |
413 | */ | |
b9960613 | 414 | public boolean postEvent(Event e) |
fd164b17 | 415 | { |
b9960613 BM |
416 | // FIXME |
417 | return false; | |
e0a339f7 TT |
418 | } |
419 | ||
3bd483f2 TT |
420 | /** |
421 | * Tests whether or not this window is visible on the screen. | |
422 | * | |
423 | * @return <code>true</code> if this window is visible, <code>false</code> | |
424 | * otherwise. | |
425 | */ | |
b9960613 | 426 | public boolean isShowing() |
e0a339f7 | 427 | { |
3bd483f2 | 428 | return super.isShowing(); |
fd164b17 | 429 | } |
e0a339f7 | 430 | |
b9960613 BM |
431 | /** @since 1.2 */ |
432 | public void applyResourceBundle(ResourceBundle rb) | |
e0a339f7 | 433 | { |
b9960613 | 434 | // FIXME |
e0a339f7 TT |
435 | } |
436 | ||
b9960613 BM |
437 | /** @since 1.2 */ |
438 | public void applyResourceBundle(String rbName) | |
439 | { | |
440 | ResourceBundle rb = ResourceBundle.getBundle(rbName); | |
441 | if (rb != null) | |
442 | applyResourceBundle(rb); | |
443 | } | |
e0a339f7 | 444 | |
b9960613 BM |
445 | /* |
446 | public AccessibleContext getAccessibleContext() | |
447 | { | |
448 | // FIXME | |
449 | } | |
450 | */ | |
451 | ||
777e6d79 RR |
452 | /** |
453 | * Get graphics configuration. The implementation for Window will | |
454 | * not ask any parent containers, since Window is a toplevel | |
455 | * window and not actually embedded in the parent component. | |
456 | */ | |
b9960613 BM |
457 | public GraphicsConfiguration getGraphicsConfiguration() |
458 | { | |
777e6d79 RR |
459 | if (graphicsConfiguration != null) return graphicsConfiguration; |
460 | if (peer != null) return peer.getGraphicsConfiguration(); | |
461 | return null; | |
b9960613 | 462 | } |
777e6d79 | 463 | |
fd164b17 | 464 | } |