Java Source Code: jp.ujihara.java.awt.Window


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