1 /* Copyright (C) 1999, 2000, 2002 Free Software Foundation
3 Copyright (C) 1999 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
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)
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.
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
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
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. */
40 import java
.awt
.event
.WindowEvent
;
41 import java
.awt
.event
.WindowListener
;
42 import java
.awt
.peer
.WindowPeer
;
43 import java
.awt
.peer
.ComponentPeer
;
44 import java
.util
.EventListener
;
45 import java
.util
.Locale
;
46 import java
.util
.ResourceBundle
;
49 * This class represents a top-level window with no decorations.
51 * @author Aaron M. Renn (arenn@urbanophile.com)
52 * @author Warren Levy <warrenl@cygnus.com>
54 public class Window
extends Container
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
62 private transient WindowListener windowListener
;
63 private transient GraphicsConfiguration graphicsConfiguration
;
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.
74 setLayout((LayoutManager
) new BorderLayout());
77 Window(GraphicsConfiguration gc
)
80 graphicsConfiguration
= gc
;
84 * Initializes a new instance of <code>Window</code> with the specified
85 * parent. The window will initially be invisible.
87 * @param parent The owning <code>Frame</code> of this window.
89 public Window(Frame owner
)
95 public Window(Window owner
)
99 throw new IllegalArgumentException("owner must not be null");
103 // FIXME: add to owner's "owned window" list
104 //owner.owned.add(this); // this should be a weak reference
108 public Window(Window owner
, GraphicsConfiguration gc
)
112 /* FIXME: Security check
113 SecurityManager.checkTopLevelWindow(...)
116 && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN)
117 throw new IllegalArgumentException ("gc must be from a screen device");
120 graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
121 .getDefaultScreenDevice()
122 .getDefaultConfiguration();
125 graphicsConfiguration
= gc
;
128 GraphicsConfiguration
getGraphicsConfigurationImpl()
130 if (graphicsConfiguration
!= null)
131 return graphicsConfiguration
;
133 return super.getGraphicsConfigurationImpl();
136 protected void finalize() throws Throwable
138 // FIXME: remove from owner's "owned window" list (Weak References)
143 * Creates the native peer for this window.
145 public void addNotify()
148 peer
= getToolkit ().createWindow (this);
153 * Relays out this window's child components at their preferred size.
155 * @specnote pack() doesn't appear to be called internally by show(), so
156 * we duplicate some of the functionality.
161 && !parent
.isDisplayable())
166 setSize(getPreferredSize());
172 * Makes this window visible and brings it to the front.
185 // FIXME: call hide() on amy "owned" children here.
190 * Called to free any resource associated with this window.
192 public void dispose()
196 Window
[] list
= getOwnedWindows();
197 for (int i
=0; i
<list
.length
; i
++)
200 for (int i
= 0; i
< ncomponents
; ++i
)
201 component
[i
].removeNotify();
206 * Sends this window to the back so that all other windows display in
209 public void toBack ()
213 WindowPeer wp
= (WindowPeer
) peer
;
219 * Brings this window to the front so that it displays in front of
222 public void toFront ()
226 WindowPeer wp
= (WindowPeer
) peer
;
232 * Returns the toolkit used to create this window.
234 * @return The toolkit used to create this window.
236 * @specnote Unlike Component.getToolkit, this implementation always
237 * returns the value of Toolkit.getDefaultToolkit().
239 public Toolkit
getToolkit()
241 return Toolkit
.getDefaultToolkit ();
245 * Returns the warning string that will be displayed if this window is
246 * popped up by an unsecure applet or application.
248 * @return The unsecure window warning message.
250 public final String
getWarningString()
252 boolean secure
= true;
253 /* boolean secure = SecurityManager.checkTopLevelWindow(...) */
257 if (warningString
!= null)
258 return warningString
;
261 String warning
= System
.getProperty("awt.appletWarning");
269 * Returns the locale that this window is configured for.
271 * @return The locale this window is configured for.
273 public Locale
getLocale ()
275 return locale
== null ? Locale
.getDefault () : locale
;
280 public InputContext getInputContext()
287 * Sets the cursor for this window to the specifiec cursor.
289 * @param cursor The new cursor for this window.
291 public void setCursor(Cursor cursor
)
293 super.setCursor(cursor
);
296 public Window
getOwner()
298 return (Window
) parent
;
302 public Window
[] getOwnedWindows()
304 // FIXME: return array containing all the windows this window currently
306 return new Window
[0];
310 * Adds the specified listener to the list of <code>WindowListeners</code>
311 * that will receive events for this window.
313 * @param listener The <code>WindowListener</code> to add.
315 public synchronized void addWindowListener (WindowListener listener
)
317 windowListener
= AWTEventMulticaster
.add (windowListener
, listener
);
321 * Removes the specified listener from the list of
322 * <code>WindowListeners</code> that will receive events for this window.
324 * @param listener The <code>WindowListener</code> to remove.
326 public synchronized void removeWindowListener (WindowListener listener
)
328 windowListener
= AWTEventMulticaster
.remove (windowListener
, listener
);
332 public EventListener
[] getListeners(Class listenerType
)
334 if (listenerType
== WindowListener
.class)
335 return getListenersImpl(listenerType
, windowListener
);
336 else return super.getListeners(listenerType
);
339 void dispatchEventImpl(AWTEvent e
)
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))
348 super.dispatchEventImpl(e
);
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.
357 * @param event The event to process.
359 protected void processEvent (AWTEvent evt
)
361 if (evt
instanceof WindowEvent
)
362 processWindowEvent ((WindowEvent
) evt
);
364 super.processEvent (evt
);
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.
373 * @param event The event to process.
375 protected void processWindowEvent (WindowEvent evt
)
377 if (windowListener
!= null)
379 switch (evt
.getID ())
381 case WindowEvent
.WINDOW_ACTIVATED
:
382 windowListener
.windowActivated (evt
);
384 case WindowEvent
.WINDOW_CLOSED
:
385 windowListener
.windowClosed (evt
);
387 case WindowEvent
.WINDOW_CLOSING
:
388 windowListener
.windowClosing (evt
);
390 case WindowEvent
.WINDOW_DEACTIVATED
:
391 windowListener
.windowDeactivated (evt
);
393 case WindowEvent
.WINDOW_DEICONIFIED
:
394 windowListener
.windowDeiconified (evt
);
396 case WindowEvent
.WINDOW_ICONIFIED
:
397 windowListener
.windowIconified (evt
);
399 case WindowEvent
.WINDOW_OPENED
:
400 windowListener
.windowOpened (evt
);
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.
411 * @return The component that has focus, or <code>null</code> if no
412 * component has focus.
414 public Component
getFocusOwner()
421 * Post a Java 1.0 event to the event queue.
423 * @param event The event to post.
425 public boolean postEvent(Event e
)
432 * Tests whether or not this window is visible on the screen.
434 * @return <code>true</code> if this window is visible, <code>false</code>
437 public boolean isShowing()
439 return super.isShowing();
443 public void applyResourceBundle(ResourceBundle rb
)
449 public void applyResourceBundle(String rbName
)
451 ResourceBundle rb
= ResourceBundle
.getBundle(rbName
);
453 applyResourceBundle(rb
);
457 public AccessibleContext getAccessibleContext()
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.
468 public GraphicsConfiguration
getGraphicsConfiguration()
470 if (graphicsConfiguration
!= null) return graphicsConfiguration
;
471 if (peer
!= null) return peer
.getGraphicsConfiguration();