]> gcc.gnu.org Git - gcc.git/blame - libjava/java/awt/Window.java
Calendar.java: Change ResourceBundle.getBundle() calls to pass ClassLoader argument.
[gcc.git] / libjava / java / awt / Window.java
CommitLineData
7bde45b2 1/* Window.java --
5aac1dac 2 Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
fd164b17 3
3bd483f2
TT
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
92aaa246
MW
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
fd164b17 37
7bde45b2 38
fd164b17 39package java.awt;
7bde45b2 40
86881a7b 41import java.awt.event.ComponentEvent;
e0a339f7 42import java.awt.event.WindowEvent;
30df932c 43import java.awt.event.WindowFocusListener;
fd164b17 44import java.awt.event.WindowListener;
30df932c 45import java.awt.event.WindowStateListener;
e0a339f7 46import java.awt.peer.WindowPeer;
5ec47f60
TF
47import java.lang.ref.Reference;
48import java.lang.ref.WeakReference;
49import java.util.Iterator;
b9960613 50import java.util.EventListener;
e0a339f7 51import java.util.Locale;
b9960613 52import java.util.ResourceBundle;
5ec47f60 53import java.util.Vector;
2f161fa8
MK
54import javax.accessibility.Accessible;
55import javax.accessibility.AccessibleContext;
fd164b17 56
3bd483f2
TT
57/**
58 * This class represents a top-level window with no decorations.
59 *
59b8aa7e 60 * @author Aaron M. Renn <arenn@urbanophile.com>
3bd483f2
TT
61 * @author Warren Levy <warrenl@cygnus.com>
62 */
2f161fa8 63public class Window extends Container implements Accessible
fd164b17 64{
2f161fa8
MK
65 private static final long serialVersionUID = 4497834738069338734L;
66
b9960613 67 // Serialized fields, from Sun's serialization spec.
b9960613 68 private String warningString = null;
b9960613 69 private int windowSerializedDataVersion = 0; // FIXME
eceea301
MK
70 /** @since 1.2 */
71 // private FocusManager focusMgr; // FIXME: what is this?
72 /** @since 1.2 */
73 private int state = 0;
74 /** @since 1.4 */
75 private boolean focusableWindowState = true;
b9960613 76
5ec47f60
TF
77 // A list of other top-level windows owned by this window.
78 private transient Vector ownedWindows = new Vector();
79
b9960613 80 private transient WindowListener windowListener;
30df932c
MK
81 private transient WindowFocusListener windowFocusListener;
82 private transient WindowStateListener windowStateListener;
b9960613 83 private transient GraphicsConfiguration graphicsConfiguration;
2f161fa8 84 private transient AccessibleContext accessibleContext;
b9960613 85
c5d2de6b
GH
86 private transient boolean shown;
87
777e6d79
RR
88 /**
89 * This (package access) constructor is used by subclasses that want
90 * to build windows that do not have parents. Eg. toplevel
91 * application frames. Subclasses cannot call super(null), since
92 * null is an illegal argument.
93 */
94 Window()
95 {
b59b5081 96 visible = false;
c5d2de6b
GH
97 // Windows are the only Containers that default to being focus
98 // cycle roots.
99 focusCycleRoot = true;
59b8aa7e 100 setLayout(new BorderLayout());
777e6d79
RR
101 }
102
103 Window(GraphicsConfiguration gc)
104 {
105 this();
106 graphicsConfiguration = gc;
107 }
2f161fa8 108
3bd483f2
TT
109 /**
110 * Initializes a new instance of <code>Window</code> with the specified
111 * parent. The window will initially be invisible.
112 *
113 * @param parent The owning <code>Frame</code> of this window.
7365ecf7
MK
114 *
115 * @exception IllegalArgumentException If the owner's GraphicsConfiguration
116 * is not from a screen device, or if owner is null; this exception is always
117 * thrown when GraphicsEnvironment.isHeadless returns true.
3bd483f2 118 */
b9960613
BM
119 public Window(Frame owner)
120 {
7365ecf7 121 this (owner, owner.getGraphicsConfiguration ());
b9960613
BM
122 }
123
7365ecf7
MK
124 /**
125 * Initializes a new instance of <code>Window</code> with the specified
126 * parent. The window will initially be invisible.
127 *
128 * @exception IllegalArgumentException If the owner's GraphicsConfiguration
129 * is not from a screen device, or if owner is null; this exception is always
130 * thrown when GraphicsEnvironment.isHeadless returns true.
131 *
132 * @since 1.2
133 */
b9960613 134 public Window(Window owner)
e0a339f7 135 {
7365ecf7 136 this (owner, owner.getGraphicsConfiguration ());
b9960613
BM
137 }
138
7365ecf7
MK
139 /**
140 * Initializes a new instance of <code>Window</code> with the specified
141 * parent. The window will initially be invisible.
142 *
143 * @exception IllegalArgumentException If owner is null or if gc is not from a
144 * screen device; this exception is always thrown when
145 * GraphicsEnvironment.isHeadless returns true.
146 *
147 * @since 1.3
148 */
b9960613
BM
149 public Window(Window owner, GraphicsConfiguration gc)
150 {
7365ecf7 151 this ();
777e6d79 152
f2d0e05d 153 synchronized (getTreeLock())
5ec47f60 154 {
f2d0e05d
TF
155 if (owner == null)
156 throw new IllegalArgumentException ("owner must not be null");
157
158 parent = owner;
5ec47f60
TF
159 owner.ownedWindows.add(new WeakReference(this));
160 }
161
5c798f92
TT
162 // FIXME: make this text visible in the window.
163 SecurityManager s = System.getSecurityManager();
164 if (s != null && ! s.checkTopLevelWindow(this))
165 warningString = System.getProperty("awt.appletWarning");
b9960613
BM
166
167 if (gc != null
168 && gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN)
169 throw new IllegalArgumentException ("gc must be from a screen device");
170
5aac1dac
TT
171 // FIXME: until we implement this, it just causes AWT to crash.
172// if (gc == null)
173// graphicsConfiguration = GraphicsEnvironment.getLocalGraphicsEnvironment()
174// .getDefaultScreenDevice()
175// .getDefaultConfiguration();
176// else
7365ecf7 177 graphicsConfiguration = gc;
777e6d79 178 }
b9960613 179
777e6d79
RR
180 GraphicsConfiguration getGraphicsConfigurationImpl()
181 {
182 if (graphicsConfiguration != null)
183 return graphicsConfiguration;
184
185 return super.getGraphicsConfigurationImpl();
e0a339f7
TT
186 }
187
3bd483f2
TT
188 /**
189 * Creates the native peer for this window.
190 */
b9960613 191 public void addNotify()
e0a339f7
TT
192 {
193 if (peer == null)
7bde45b2
BM
194 peer = getToolkit().createWindow(this);
195 super.addNotify();
e0a339f7 196 }
fd164b17 197
3bd483f2
TT
198 /**
199 * Relays out this window's child components at their preferred size.
200 *
201 * @specnote pack() doesn't appear to be called internally by show(), so
202 * we duplicate some of the functionality.
203 */
b9960613 204 public void pack()
e0a339f7 205 {
ad980a7b 206 if (parent != null && !parent.isDisplayable())
b9960613 207 parent.addNotify();
777e6d79 208 if (peer == null)
b9960613 209 addNotify();
777e6d79
RR
210
211 setSize(getPreferredSize());
ad980a7b 212
b9960613
BM
213 validate();
214 }
215
3bd483f2 216 /**
23a555b0
TF
217 * Shows on-screen this window and any of its owned windows for whom
218 * isVisible returns true.
3bd483f2 219 */
7bde45b2 220 public void show()
b9960613 221 {
ad980a7b
TT
222 if (parent != null && !parent.isDisplayable())
223 parent.addNotify();
777e6d79
RR
224 if (peer == null)
225 addNotify();
b9960613 226
23a555b0 227 // Show visible owned windows.
f2d0e05d 228 synchronized (getTreeLock())
23a555b0
TF
229 {
230 Iterator e = ownedWindows.iterator();
231 while(e.hasNext())
232 {
233 Window w = (Window)(((Reference) e.next()).get());
234 if (w != null)
235 {
236 if (w.isVisible())
237 w.getPeer().setVisible(true);
238 }
239 else
240 // Remove null weak reference from ownedWindows.
241 // Unfortunately this can't be done in the Window's
242 // finalize method because there is no way to guarantee
243 // synchronous access to ownedWindows there.
244 e.remove();
245 }
246 }
ad980a7b 247 validate();
7e89296c 248 super.show();
3bd483f2 249 toFront();
c5d2de6b
GH
250
251 KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
252 manager.setGlobalFocusedWindow (this);
253
254 if (!shown)
255 {
256 FocusTraversalPolicy policy = getFocusTraversalPolicy ();
257 Component initialFocusOwner = null;
258
259 if (policy != null)
260 initialFocusOwner = policy.getInitialComponent (this);
261
262 if (initialFocusOwner != null)
263 initialFocusOwner.requestFocusInWindow (false);
264
265 shown = true;
266 }
b9960613
BM
267 }
268
269 public void hide()
270 {
23a555b0 271 // Hide visible owned windows.
f2d0e05d 272 synchronized (getTreeLock ())
5ec47f60
TF
273 {
274 Iterator e = ownedWindows.iterator();
275 while(e.hasNext())
276 {
277 Window w = (Window)(((Reference) e.next()).get());
278 if (w != null)
23a555b0
TF
279 {
280 if (w.isVisible() && w.getPeer() != null)
281 w.getPeer().setVisible(false);
282 }
5ec47f60 283 else
5ec47f60
TF
284 e.remove();
285 }
286 }
7e89296c 287 super.hide();
b9960613
BM
288 }
289
ad980a7b
TT
290 public boolean isDisplayable()
291 {
292 if (super.isDisplayable())
293 return true;
294 return peer != null;
295 }
296
3bd483f2 297 /**
5ec47f60
TF
298 * Destroys any resources associated with this window. This includes
299 * all components in the window and all owned top-level windows.
3bd483f2 300 */
b9960613
BM
301 public void dispose()
302 {
777e6d79
RR
303 hide();
304
f2d0e05d 305 synchronized (getTreeLock ())
5ec47f60
TF
306 {
307 Iterator e = ownedWindows.iterator();
308 while(e.hasNext())
309 {
310 Window w = (Window)(((Reference) e.next()).get());
311 if (w != null)
312 w.dispose();
313 else
314 // Remove null weak reference from ownedWindows.
315 e.remove();
316 }
777e6d79 317
f2d0e05d
TF
318 for (int i = 0; i < ncomponents; ++i)
319 component[i].removeNotify();
320 this.removeNotify();
321
322 // Post a WINDOW_CLOSED event.
323 WindowEvent we = new WindowEvent(this, WindowEvent.WINDOW_CLOSED);
324 getToolkit().getSystemEventQueue().postEvent(we);
325 }
e0a339f7
TT
326 }
327
3bd483f2
TT
328 /**
329 * Sends this window to the back so that all other windows display in
330 * front of it.
331 */
7bde45b2 332 public void toBack()
e0a339f7 333 {
b9960613
BM
334 if (peer != null)
335 {
336 WindowPeer wp = (WindowPeer) peer;
7bde45b2 337 wp.toBack();
b9960613 338 }
e0a339f7
TT
339 }
340
3bd483f2
TT
341 /**
342 * Brings this window to the front so that it displays in front of
343 * any other windows.
344 */
7bde45b2 345 public void toFront()
e0a339f7 346 {
b9960613
BM
347 if (peer != null)
348 {
7365ecf7
MK
349 WindowPeer wp = (WindowPeer) peer;
350 wp.toFront();
b9960613
BM
351 }
352 }
353
3bd483f2
TT
354 /**
355 * Returns the toolkit used to create this window.
356 *
357 * @return The toolkit used to create this window.
358 *
359 * @specnote Unlike Component.getToolkit, this implementation always
360 * returns the value of Toolkit.getDefaultToolkit().
361 */
b9960613
BM
362 public Toolkit getToolkit()
363 {
7bde45b2 364 return Toolkit.getDefaultToolkit();
b9960613
BM
365 }
366
3bd483f2
TT
367 /**
368 * Returns the warning string that will be displayed if this window is
369 * popped up by an unsecure applet or application.
370 *
371 * @return The unsecure window warning message.
372 */
b9960613
BM
373 public final String getWarningString()
374 {
5c798f92 375 return warningString;
e0a339f7 376 }
fd164b17 377
3bd483f2
TT
378 /**
379 * Returns the locale that this window is configured for.
380 *
381 * @return The locale this window is configured for.
382 */
7bde45b2 383 public Locale getLocale()
e0a339f7 384 {
7bde45b2 385 return locale == null ? Locale.getDefault() : locale;
e0a339f7
TT
386 }
387
b9960613
BM
388 /*
389 /** @since 1.2
390 public InputContext getInputContext()
e0a339f7 391 {
b9960613 392 // FIXME
e0a339f7 393 }
b9960613 394 */
e0a339f7 395
3bd483f2
TT
396 /**
397 * Sets the cursor for this window to the specifiec cursor.
398 *
399 * @param cursor The new cursor for this window.
400 */
b9960613 401 public void setCursor(Cursor cursor)
e0a339f7 402 {
b9960613
BM
403 super.setCursor(cursor);
404 }
405
406 public Window getOwner()
407 {
777e6d79 408 return (Window) parent;
e0a339f7
TT
409 }
410
b9960613
BM
411 /** @since 1.2 */
412 public Window[] getOwnedWindows()
e0a339f7 413 {
5ec47f60 414 Window [] trimmedList;
f2d0e05d 415 synchronized (getTreeLock ())
5ec47f60
TF
416 {
417 // Windows with non-null weak references in ownedWindows.
418 Window [] validList = new Window [ownedWindows.size()];
419
420 Iterator e = ownedWindows.iterator();
421 int numValid = 0;
422 while (e.hasNext())
423 {
424 Window w = (Window)(((Reference) e.next()).get());
425 if (w != null)
426 validList[numValid++] = w;
427 else
428 // Remove null weak reference from ownedWindows.
429 e.remove();
430 }
431
432 if (numValid != validList.length)
433 {
434 trimmedList = new Window [numValid];
435 System.arraycopy (validList, 0, trimmedList, 0, numValid);
436 }
437 else
438 trimmedList = validList;
439 }
440 return trimmedList;
b9960613
BM
441 }
442
3bd483f2
TT
443 /**
444 * Adds the specified listener to the list of <code>WindowListeners</code>
445 * that will receive events for this window.
446 *
447 * @param listener The <code>WindowListener</code> to add.
448 */
7bde45b2 449 public synchronized void addWindowListener(WindowListener listener)
b9960613 450 {
7bde45b2 451 windowListener = AWTEventMulticaster.add(windowListener, listener);
b9960613
BM
452 }
453
3bd483f2
TT
454 /**
455 * Removes the specified listener from the list of
456 * <code>WindowListeners</code> that will receive events for this window.
457 *
458 * @param listener The <code>WindowListener</code> to remove.
459 */
7bde45b2
BM
460 public synchronized void removeWindowListener(WindowListener listener)
461 {
462 windowListener = AWTEventMulticaster.remove(windowListener, listener);
463 }
464
7365ecf7
MK
465 /**
466 * Returns an array of all the window listeners registered on this window.
467 *
468 * @since 1.4
469 */
7bde45b2 470 public synchronized WindowListener[] getWindowListeners()
b9960613 471 {
7bde45b2
BM
472 return (WindowListener[])
473 AWTEventMulticaster.getListeners(windowListener,
474 WindowListener.class);
b9960613
BM
475 }
476
30df932c
MK
477 /**
478 * Returns an array of all the window focus listeners registered on this
479 * window.
480 *
481 * @since 1.4
482 */
483 public synchronized WindowFocusListener[] getWindowFocusListeners()
484 {
485 return (WindowFocusListener[])
486 AWTEventMulticaster.getListeners(windowFocusListener,
487 WindowFocusListener.class);
488 }
489
490 /**
491 * Returns an array of all the window state listeners registered on this
492 * window.
493 *
494 * @since 1.4
495 */
496 public synchronized WindowStateListener[] getWindowStateListeners()
497 {
498 return (WindowStateListener[])
499 AWTEventMulticaster.getListeners(windowStateListener,
500 WindowStateListener.class);
501 }
502
503 /**
504 * Adds the specified listener to this window.
505 */
506 public void addWindowFocusListener (WindowFocusListener wfl)
507 {
f2d0e05d 508 windowFocusListener = AWTEventMulticaster.add (windowFocusListener, wfl);
30df932c
MK
509 }
510
511 /**
512 * Adds the specified listener to this window.
513 *
514 * @since 1.4
515 */
516 public void addWindowStateListener (WindowStateListener wsl)
517 {
f2d0e05d 518 windowStateListener = AWTEventMulticaster.add (windowStateListener, wsl);
30df932c
MK
519 }
520
521 /**
522 * Removes the specified listener from this window.
523 */
524 public void removeWindowFocusListener (WindowFocusListener wfl)
525 {
f2d0e05d 526 windowFocusListener = AWTEventMulticaster.remove (windowFocusListener, wfl);
30df932c
MK
527 }
528
529 /**
530 * Removes the specified listener from this window.
531 *
532 * @since 1.4
533 */
534 public void removeWindowStateListener (WindowStateListener wsl)
535 {
f2d0e05d 536 windowStateListener = AWTEventMulticaster.remove (windowStateListener, wsl);
30df932c
MK
537 }
538
7365ecf7
MK
539 /**
540 * Returns an array of all the objects currently registered as FooListeners
541 * upon this Window. FooListeners are registered using the addFooListener
542 * method.
543 *
544 * @exception ClassCastException If listenerType doesn't specify a class or
545 * interface that implements java.util.EventListener.
546 *
547 * @since 1.3
548 */
b9960613
BM
549 public EventListener[] getListeners(Class listenerType)
550 {
551 if (listenerType == WindowListener.class)
7bde45b2
BM
552 return getWindowListeners();
553 return super.getListeners(listenerType);
b9960613
BM
554 }
555
556 void dispatchEventImpl(AWTEvent e)
557 {
558 // Make use of event id's in order to avoid multiple instanceof tests.
559 if (e.id <= WindowEvent.WINDOW_LAST
560 && e.id >= WindowEvent.WINDOW_FIRST
f2d0e05d
TF
561 && (windowListener != null
562 || windowFocusListener != null
563 || windowStateListener != null
b9960613
BM
564 || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0))
565 processEvent(e);
566 else
567 super.dispatchEventImpl(e);
e0a339f7
TT
568 }
569
3bd483f2
TT
570 /**
571 * Processes the specified event for this window. If the event is an
572 * instance of <code>WindowEvent</code>, then
573 * <code>processWindowEvent()</code> is called to process the event,
574 * otherwise the superclass version of this method is invoked.
575 *
576 * @param event The event to process.
577 */
7bde45b2 578 protected void processEvent(AWTEvent evt)
e0a339f7
TT
579 {
580 if (evt instanceof WindowEvent)
7bde45b2 581 processWindowEvent((WindowEvent) evt);
e0a339f7 582 else
7bde45b2 583 super.processEvent(evt);
e0a339f7
TT
584 }
585
3bd483f2
TT
586 /**
587 * Dispatches this event to any listeners that are listening for
588 * <code>WindowEvents</code> on this window. This method only gets
589 * invoked if it is enabled via <code>enableEvents()</code> or if
590 * a listener has been added.
591 *
592 * @param event The event to process.
593 */
7bde45b2 594 protected void processWindowEvent(WindowEvent evt)
e0a339f7 595 {
f2d0e05d
TF
596 int id = evt.getID();
597
598 if (id == WindowEvent.WINDOW_GAINED_FOCUS
599 || id == WindowEvent.WINDOW_LOST_FOCUS)
600 processWindowFocusEvent (evt);
601 else if (id == WindowEvent.WINDOW_STATE_CHANGED)
602 processWindowStateEvent (evt);
603 else
e0a339f7 604 {
f2d0e05d
TF
605 if (windowListener != null)
606 {
607 switch (evt.getID())
608 {
609 case WindowEvent.WINDOW_ACTIVATED:
610 windowListener.windowActivated(evt);
611 break;
612
613 case WindowEvent.WINDOW_CLOSED:
614 windowListener.windowClosed(evt);
615 break;
616
617 case WindowEvent.WINDOW_CLOSING:
618 windowListener.windowClosing(evt);
619 break;
620
621 case WindowEvent.WINDOW_DEACTIVATED:
622 windowListener.windowDeactivated(evt);
623 break;
624
625 case WindowEvent.WINDOW_DEICONIFIED:
626 windowListener.windowDeiconified(evt);
627 break;
628
629 case WindowEvent.WINDOW_ICONIFIED:
630 windowListener.windowIconified(evt);
631 break;
632
633 case WindowEvent.WINDOW_OPENED:
634 windowListener.windowOpened(evt);
635 break;
636
637 default:
638 break;
639 }
640 }
e0a339f7
TT
641 }
642 }
643
3bd483f2
TT
644 /**
645 * Returns the child window that has focus if this window is active.
646 * This method returns <code>null</code> if this window is not active
647 * or no children have focus.
648 *
649 * @return The component that has focus, or <code>null</code> if no
650 * component has focus.
651 */
c5d2de6b 652 public Component getFocusOwner ()
e0a339f7 653 {
c5d2de6b
GH
654 KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
655
656 Window activeWindow = manager.getActiveWindow ();
657
658 // The currently-focused Component belongs to the active Window.
659 if (activeWindow == this)
660 return manager.getFocusOwner ();
661
b9960613 662 return null;
e0a339f7 663 }
fd164b17 664
3bd483f2
TT
665 /**
666 * Post a Java 1.0 event to the event queue.
667 *
668 * @param event The event to post.
2ff04cc6
MK
669 *
670 * @deprecated
3bd483f2 671 */
b9960613 672 public boolean postEvent(Event e)
fd164b17 673 {
b9960613
BM
674 // FIXME
675 return false;
e0a339f7
TT
676 }
677
3bd483f2
TT
678 /**
679 * Tests whether or not this window is visible on the screen.
680 *
681 * @return <code>true</code> if this window is visible, <code>false</code>
682 * otherwise.
683 */
b9960613 684 public boolean isShowing()
e0a339f7 685 {
3bd483f2 686 return super.isShowing();
fd164b17 687 }
e0a339f7 688
2ff04cc6
MK
689 /**
690 * @since 1.2
691 *
692 * @deprecated
693 */
b9960613 694 public void applyResourceBundle(ResourceBundle rb)
e0a339f7 695 {
2f161fa8 696 throw new Error ("Not implemented");
e0a339f7
TT
697 }
698
2ff04cc6
MK
699 /**
700 * @since 1.2
701 *
702 * @deprecated
703 */
b9960613
BM
704 public void applyResourceBundle(String rbName)
705 {
84b1d821
BM
706 ResourceBundle rb = ResourceBundle.getBundle(rbName, Locale.getDefault(),
707 Window.class.getClassLoader());
b9960613
BM
708 if (rb != null)
709 applyResourceBundle(rb);
710 }
e0a339f7 711
b9960613
BM
712 public AccessibleContext getAccessibleContext()
713 {
714 // FIXME
2f161fa8
MK
715 //return null;
716 throw new Error ("Not implemented");
b9960613 717 }
b9960613 718
777e6d79
RR
719 /**
720 * Get graphics configuration. The implementation for Window will
721 * not ask any parent containers, since Window is a toplevel
722 * window and not actually embedded in the parent component.
723 */
b9960613
BM
724 public GraphicsConfiguration getGraphicsConfiguration()
725 {
777e6d79
RR
726 if (graphicsConfiguration != null) return graphicsConfiguration;
727 if (peer != null) return peer.getGraphicsConfiguration();
728 return null;
b9960613 729 }
2ff04cc6
MK
730
731 protected void processWindowFocusEvent(WindowEvent event)
732 {
733 if (windowFocusListener != null)
734 {
735 switch (event.getID ())
736 {
737 case WindowEvent.WINDOW_GAINED_FOCUS:
738 windowFocusListener.windowGainedFocus (event);
739 break;
740
741 case WindowEvent.WINDOW_LOST_FOCUS:
742 windowFocusListener.windowLostFocus (event);
743 break;
744
745 default:
746 break;
747 }
748 }
749 }
750
751 /**
752 * @since 1.4
753 */
754 protected void processWindowStateEvent(WindowEvent event)
755 {
756 if (windowStateListener != null
757 && event.getID () == WindowEvent.WINDOW_STATE_CHANGED)
758 windowStateListener.windowStateChanged (event);
759 }
eceea301
MK
760
761 /**
762 * Returns whether this <code>Window</code> can get the focus or not.
763 *
764 * @since 1.4
765 */
fe7f8a4e 766 public final boolean isFocusableWindow ()
eceea301
MK
767 {
768 if (getFocusableWindowState () == false)
769 return false;
770
771 if (this instanceof Dialog
772 || this instanceof Frame)
773 return true;
774
775 // FIXME: Implement more possible cases for returning true.
776
777 return false;
778 }
779
780 /**
781 * Returns the value of the focusableWindowState property.
782 *
783 * @since 1.4
784 */
785 public boolean getFocusableWindowState ()
786 {
787 return focusableWindowState;
788 }
789
790 /**
791 * Sets the value of the focusableWindowState property.
792 *
793 * @since 1.4
794 */
795 public void setFocusableWindowState (boolean focusableWindowState)
796 {
797 this.focusableWindowState = focusableWindowState;
798 }
b59b5081
TF
799
800 // setBoundsCallback is needed so that when a user moves a window,
801 // the Window's location can be updated without calling the peer's
802 // setBounds method. When a user moves a window the peer window's
803 // location is updated automatically and the windowing system sends
804 // a message back to the application informing it of its updated
805 // dimensions. We must update the AWT Window class with these new
806 // dimensions. But we don't want to call the peer's setBounds
807 // method, because the peer's dimensions have already been updated.
808 // (Under X, having this method prevents Configure event loops when
809 // moving windows: Component.setBounds -> peer.setBounds ->
810 // postConfigureEvent -> Component.setBounds -> ... In some cases
811 // Configure event loops cause windows to jitter back and forth
812 // continuously).
813 void setBoundsCallback (int x, int y, int w, int h)
814 {
815 if (this.x == x && this.y == y && width == w && height == h)
816 return;
817 invalidate();
86881a7b
GH
818 boolean resized = width != w || height != h;
819 boolean moved = this.x != x || this.y != y;
b59b5081
TF
820 this.x = x;
821 this.y = y;
822 width = w;
823 height = h;
86881a7b
GH
824 if (resized)
825 {
826 ComponentEvent ce =
827 new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);
828 getToolkit().getSystemEventQueue().postEvent(ce);
829 }
830 if (moved)
831 {
832 ComponentEvent ce =
833 new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED);
834 getToolkit().getSystemEventQueue().postEvent(ce);
835 }
b59b5081 836 }
fd164b17 837}
This page took 0.501268 seconds and 5 git commands to generate.