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