]> gcc.gnu.org Git - gcc.git/blob - libjava/java/awt/Window.java
jcf-write.c (get_access_flags): Return correct access flags for private and protected...
[gcc.git] / libjava / java / awt / Window.java
1 /* Copyright (C) 1999, 2000, 2002 Free Software Foundation
2
3 Copyright (C) 1999 Free Software Foundation, Inc.
4
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 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. */
38
39 package java.awt;
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;
47
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 */
54 public class Window extends Container
55 {
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
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
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 */
89 public Window(Frame owner)
90 {
91 this((Window) owner);
92 }
93
94 /** @since 1.2 */
95 public Window(Window owner)
96 {
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
105 }
106
107 /** @since 1.3 */
108 public Window(Window owner, GraphicsConfiguration gc)
109 {
110 this(owner);
111
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 */
125 graphicsConfiguration = gc;
126 }
127
128 GraphicsConfiguration getGraphicsConfigurationImpl()
129 {
130 if (graphicsConfiguration != null)
131 return graphicsConfiguration;
132
133 return super.getGraphicsConfigurationImpl();
134 }
135
136 protected void finalize() throws Throwable
137 {
138 // FIXME: remove from owner's "owned window" list (Weak References)
139 super.finalize();
140 }
141
142 /**
143 * Creates the native peer for this window.
144 */
145 public void addNotify()
146 {
147 if (peer == null)
148 peer = getToolkit ().createWindow (this);
149 super.addNotify ();
150 }
151
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 */
158 public void pack()
159 {
160 if (parent != null
161 && !parent.isDisplayable())
162 parent.addNotify();
163 if (peer == null)
164 addNotify();
165
166 setSize(getPreferredSize());
167
168 validate();
169 }
170
171 /**
172 * Makes this window visible and brings it to the front.
173 */
174 public void show ()
175 {
176 if (peer == null)
177 addNotify();
178
179 super.show();
180 toFront();
181 }
182
183 public void hide()
184 {
185 // FIXME: call hide() on amy "owned" children here.
186 super.hide();
187 }
188
189 /**
190 * Called to free any resource associated with this window.
191 */
192 public void dispose()
193 {
194 hide();
195
196 Window[] list = getOwnedWindows();
197 for (int i=0; i<list.length; i++)
198 list[i].dispose();
199
200 for (int i = 0; i < ncomponents; ++i)
201 component[i].removeNotify();
202 this.removeNotify();
203 }
204
205 /**
206 * Sends this window to the back so that all other windows display in
207 * front of it.
208 */
209 public void toBack ()
210 {
211 if (peer != null)
212 {
213 WindowPeer wp = (WindowPeer) peer;
214 wp.toBack ();
215 }
216 }
217
218 /**
219 * Brings this window to the front so that it displays in front of
220 * any other windows.
221 */
222 public void toFront ()
223 {
224 if (peer != null)
225 {
226 WindowPeer wp = (WindowPeer) peer;
227 wp.toFront ();
228 }
229 }
230
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 */
239 public Toolkit getToolkit()
240 {
241 return Toolkit.getDefaultToolkit ();
242 }
243
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 */
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;
266 }
267
268 /**
269 * Returns the locale that this window is configured for.
270 *
271 * @return The locale this window is configured for.
272 */
273 public Locale getLocale ()
274 {
275 return locale == null ? Locale.getDefault () : locale;
276 }
277
278 /*
279 /** @since 1.2
280 public InputContext getInputContext()
281 {
282 // FIXME
283 }
284 */
285
286 /**
287 * Sets the cursor for this window to the specifiec cursor.
288 *
289 * @param cursor The new cursor for this window.
290 */
291 public void setCursor(Cursor cursor)
292 {
293 super.setCursor(cursor);
294 }
295
296 public Window getOwner()
297 {
298 return (Window) parent;
299 }
300
301 /** @since 1.2 */
302 public Window[] getOwnedWindows()
303 {
304 // FIXME: return array containing all the windows this window currently
305 // owns.
306 return new Window[0];
307 }
308
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 */
315 public synchronized void addWindowListener (WindowListener listener)
316 {
317 windowListener = AWTEventMulticaster.add (windowListener, listener);
318 }
319
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 */
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);
349 }
350
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 */
359 protected void processEvent (AWTEvent evt)
360 {
361 if (evt instanceof WindowEvent)
362 processWindowEvent ((WindowEvent) evt);
363 else
364 super.processEvent (evt);
365 }
366
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 */
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
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 */
414 public Component getFocusOwner()
415 {
416 // FIXME
417 return null;
418 }
419
420 /**
421 * Post a Java 1.0 event to the event queue.
422 *
423 * @param event The event to post.
424 */
425 public boolean postEvent(Event e)
426 {
427 // FIXME
428 return false;
429 }
430
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 */
437 public boolean isShowing()
438 {
439 return super.isShowing();
440 }
441
442 /** @since 1.2 */
443 public void applyResourceBundle(ResourceBundle rb)
444 {
445 // FIXME
446 }
447
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 }
455
456 /*
457 public AccessibleContext getAccessibleContext()
458 {
459 // FIXME
460 }
461 */
462
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 */
468 public GraphicsConfiguration getGraphicsConfiguration()
469 {
470 if (graphicsConfiguration != null) return graphicsConfiguration;
471 if (peer != null) return peer.getGraphicsConfiguration();
472 return null;
473 }
474
475 }
This page took 0.062231 seconds and 6 git commands to generate.