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


   1: /* Component.java -- a graphics component
   2:    Copyright (C) 1999, 2000, 2001, 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.dnd.DropTarget;
  42: import jp.ujihara.java.awt.event.ActionEvent;
  43: import jp.ujihara.java.awt.event.ComponentEvent;
  44: import jp.ujihara.java.awt.event.ComponentListener;
  45: import jp.ujihara.java.awt.event.FocusEvent;
  46: import jp.ujihara.java.awt.event.FocusListener;
  47: import jp.ujihara.java.awt.event.HierarchyBoundsListener;
  48: import jp.ujihara.java.awt.event.HierarchyEvent;
  49: import jp.ujihara.java.awt.event.HierarchyListener;
  50: import jp.ujihara.java.awt.event.InputEvent;
  51: import jp.ujihara.java.awt.event.InputMethodEvent;
  52: import jp.ujihara.java.awt.event.InputMethodListener;
  53: import jp.ujihara.java.awt.event.KeyEvent;
  54: import jp.ujihara.java.awt.event.KeyListener;
  55: import jp.ujihara.java.awt.event.MouseEvent;
  56: import jp.ujihara.java.awt.event.MouseListener;
  57: import jp.ujihara.java.awt.event.MouseMotionListener;
  58: import jp.ujihara.java.awt.event.MouseWheelEvent;
  59: import jp.ujihara.java.awt.event.MouseWheelListener;
  60: import jp.ujihara.java.awt.event.PaintEvent;
  61: import jp.ujihara.java.awt.event.WindowEvent;
  62: import jp.ujihara.java.awt.im.InputContext;
  63: import jp.ujihara.java.awt.im.InputMethodRequests;
  64: import jp.ujihara.java.awt.image.BufferStrategy;
  65: import jp.ujihara.java.awt.image.ColorModel;
  66: import jp.ujihara.java.awt.image.ImageObserver;
  67: import jp.ujihara.java.awt.image.ImageProducer;
  68: import jp.ujihara.java.awt.image.VolatileImage;
  69: import jp.ujihara.java.awt.peer.ComponentPeer;
  70: import jp.ujihara.java.awt.peer.LightweightPeer;
  71: import jp.ujihara.java.beans.PropertyChangeListener;
  72: import jp.ujihara.java.beans.PropertyChangeSupport;
  73: import java.io.IOException;
  74: import java.io.ObjectInputStream;
  75: import java.io.ObjectOutputStream;
  76: import java.io.PrintStream;
  77: import java.io.PrintWriter;
  78: import java.io.Serializable;
  79: import jp.ujihara.java.lang.reflect.Array;
  80: import jp.ujihara.java.util.Collections;
  81: import jp.ujihara.java.util.EventListener;
  82: import jp.ujihara.java.util.HashSet;
  83: import jp.ujihara.java.util.Iterator;
  84: import jp.ujihara.java.util.Locale;
  85: import jp.ujihara.java.util.Set;
  86: import jp.ujihara.java.util.Vector;
  87: 
  88: import jp.ujihara.javax.accessibility.Accessible;
  89: import jp.ujihara.javax.accessibility.AccessibleComponent;
  90: import jp.ujihara.javax.accessibility.AccessibleContext;
  91: import jp.ujihara.javax.accessibility.AccessibleRole;
  92: import jp.ujihara.javax.accessibility.AccessibleState;
  93: import jp.ujihara.javax.accessibility.AccessibleStateSet;
  94: 
  95: /**
  96:  * The root of all evil. All graphical representations are subclasses of this
  97:  * giant class, which is designed for screen display and user interaction.
  98:  * This class can be extended directly to build a lightweight component (one
  99:  * not associated with a native window); lightweight components must reside
 100:  * inside a heavyweight window.
 101:  *
 102:  * <p>This class is Serializable, which has some big implications. A user can
 103:  * save the state of all graphical components in one VM, and reload them in
 104:  * another. Note that this class will only save Serializable listeners, and
 105:  * ignore the rest, without causing any serialization exceptions. However, by
 106:  * making a listener serializable, and adding it to another element, you link
 107:  * in that entire element to the state of this component. To get around this,
 108:  * use the idiom shown in the example below - make listeners non-serializable
 109:  * in inner classes, rather than using this object itself as the listener, if
 110:  * external objects do not need to save the state of this object.
 111:  *
 112:  * <pre>
 113:  * import jp.ujihara.java.awt.*;
 114:  * import jp.ujihara.java.awt.event.*;
 115:  * import java.io.Serializable;
 116:  * class MyApp implements Serializable
 117:	   * {
 118: *   BigObjectThatShouldNotBeSerializedWithAButton bigOne;
 119: *   // Serializing aButton will not suck in an instance of MyApp, with its
 120: *   // accompanying field bigOne.
 121: *   Button aButton = new Button();
 122: *   class MyActionListener implements ActionListener
 123:	   *   {
 124: *     public void actionPerformed(ActionEvent e)
 125:	   *     {
 126: *       ClasspathSystem.out.println("Hello There");
 127: *     }
 128: *   }
 129: *   MyApp()
 130:	   *   {
 131: *     aButton.addActionListener(new MyActionListener());
 132: *   }
 133: * }
 134: * </pre>
 135: *
 136: * <p>Status: Incomplete. The event dispatch mechanism is implemented. All
 137: * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly
 138: * incomplete or only stubs; except for methods relating to the Drag and
 139: * Drop, Input Method, and Accessibility frameworks: These methods are
 140: * present but commented out.
 141: *
 142: * @author original author unknown
 143: * @author Eric Blake <ebb9@email.byu.edu>
 144: * @since 1.0
 145: * @status still missing 1.4 support
 146: */
 147:public abstract class Component
 148:  implements ImageObserver, MenuContainer, Serializable
 149:	  {
 150:  // Word to the wise - this file is huge. Search for '\f' (^L) for logical
 151:  // sectioning by fields, public API, private API, and nested classes.
 152:
 153:
 154:  /**
 155:   * Compatible with JDK 1.0+.
 156:   */
 157:  private static final long serialVersionUID = -7644114512714619750L;
 158:
 159:  /**
 160:   * Constant returned by the <code>getAlignmentY</code> method to indicate
 161:   * that the component wishes to be aligned to the top relative to
 162:   * other components.
 163:   *
 164:   * @see #getAlignmentY()
 165:   */
 166:  public static final float TOP_ALIGNMENT = 0;
 167:
 168:  /**
 169:   * Constant returned by the <code>getAlignmentY</code> and
 170:   * <code>getAlignmentX</code> methods to indicate
 171:   * that the component wishes to be aligned to the center relative to
 172:   * other components.
 173:   *
 174:   * @see #getAlignmentX()
 175:   * @see #getAlignmentY()
 176:   */
 177:  public static final float CENTER_ALIGNMENT = 0.5f;
 178:
 179:  /**
 180:   * Constant returned by the <code>getAlignmentY</code> method to indicate
 181:   * that the component wishes to be aligned to the bottom relative to
 182:   * other components.
 183:   *
 184:   * @see #getAlignmentY()
 185:   */
 186:  public static final float BOTTOM_ALIGNMENT = 1;
 187:
 188:  /**
 189:   * Constant returned by the <code>getAlignmentX</code> method to indicate
 190:   * that the component wishes to be aligned to the right relative to
 191:   * other components.
 192:   *
 193:   * @see #getAlignmentX()
 194:   */
 195:  public static final float RIGHT_ALIGNMENT = 1;
 196:
 197:  /**
 198:   * Constant returned by the <code>getAlignmentX</code> method to indicate
 199:   * that the component wishes to be aligned to the left relative to
 200:   * other components.
 201:   *
 202:   * @see #getAlignmentX()
 203:   */
 204:  public static final float LEFT_ALIGNMENT = 0;
 205:
 206:  /**
 207:   * Make the treelock a String so that it can easily be identified
 208:   * in debug dumps. We clone the String in order to avoid a conflict in
 209:   * the unlikely event that some other package uses exactly the same string
 210:   * as a lock object.
 211:   */
 212:  static final Object treeLock = new String("AWT_TREE_LOCK");
 213:
 214:  // Serialized fields from the serialization spec.
 215:
 216:  /**
 217:   * The x position of the component in the parent's coordinate system.
 218:   *
 219:   * @see #getLocation()
 220:   * @serial the x position
 221:   */
 222:  int x;
 223:
 224:  /**
 225:   * The y position of the component in the parent's coordinate system.
 226:   *
 227:   * @see #getLocation()
 228:   * @serial the y position
 229:   */
 230:  int y;
 231:
 232:  /**
 233:   * The component width.
 234:   *
 235:   * @see #getSize()
 236:   * @serial the width
 237:   */
 238:  int width;
 239:
 240:  /**
 241:   * The component height.
 242:   *
 243:   * @see #getSize()
 244:   * @serial the height
 245:   */
 246:  int height;
 247:
 248:  /**
 249:   * The foreground color for the component. This may be null.
 250:   *
 251:   * @see #getForeground()
 252:   * @see #setForeground(Color)
 253:   * @serial the foreground color
 254:   */
 255:  Color foreground;
 256:
 257:  /**
 258:   * The background color for the component. This may be null.
 259:   *
 260:   * @see #getBackground()
 261:   * @see #setBackground(Color)
 262:   * @serial the background color
 263:   */
 264:  Color background;
 265:
 266:  /**
 267:   * The default font used in the component. This may be null.
 268:   *
 269:   * @see #getFont()
 270:   * @see #setFont(Font)
 271:   * @serial the font
 272:   */
 273:  Font font;
 274:
 275:  /**
 276:   * The font in use by the peer, or null if there is no peer.
 277:   *
 278:   * @serial the peer's font
 279:   */
 280:  Font peerFont;
 281:
 282:  /**
 283:   * The cursor displayed when the pointer is over this component. This may
 284:   * be null.
 285:   *
 286:   * @see #getCursor()
 287:   * @see #setCursor(Cursor)
 288:   */
 289:  Cursor cursor;
 290:
 291:  /**
 292:   * The locale for the component.
 293:   *
 294:   * @see #getLocale()
 295:   * @see #setLocale(Locale)
 296:   */
 297:  Locale locale = Locale.getDefault ();
 298:
 299:  /**
 300:   * True if the object should ignore repaint events (usually because it is
 301:   * not showing).
 302:   *
 303:   * @see #getIgnoreRepaint()
 304:   * @see #setIgnoreRepaint(boolean)
 305:   * @serial true to ignore repaints
 306:   * @since 1.4
 307:   */
 308:  boolean ignoreRepaint;
 309:
 310:  /**
 311:   * True when the object is visible (although it is only showing if all
 312:   * ancestors are likewise visible). For component, this defaults to true.
 313:   *
 314:   * @see #isVisible()
 315:   * @see #setVisible(boolean)
 316:   * @serial true if visible
 317:   */
 318:  boolean visible = true;
 319:
 320:  /**
 321:   * True if the object is enabled, meaning it can interact with the user.
 322:   * For component, this defaults to true.
 323:   *
 324:   * @see #isEnabled()
 325:   * @see #setEnabled(boolean)
 326:   * @serial true if enabled
 327:   */
 328:  boolean enabled = true;
 329:
 330:  /**
 331:   * True if the object is valid. This is set to false any time a size
 332:   * adjustment means the component need to be layed out again.
 333:   *
 334:   * @see #isValid()
 335:   * @see #validate()
 336:   * @see #invalidate()
 337:   * @serial true if layout is valid
 338:   */
 339:  boolean valid;
 340:
 341:  /**
 342:   * The DropTarget for drag-and-drop operations.
 343:   *
 344:   * @see #getDropTarget()
 345:   * @see #setDropTarget(DropTarget)
 346:   * @serial the drop target, or null
 347:   * @since 1.2
 348:   */
 349:  DropTarget dropTarget;
 350:
 351:  /**
 352:   * The list of popup menus for this component.
 353:   *
 354:   * @see #add(PopupMenu)
 355:   * @serial the list of popups
 356:   */
 357:  Vector popups;
 358:
 359:  /**
 360:   * The component's name. May be null, in which case a default name is
 361:   * generated on the first use.
 362:   *
 363:   * @see #getName()
 364:   * @see #setName(String)
 365:   * @serial the name
 366:   */
 367:  String name;
 368:
 369:  /**
 370:   * True once the user has set the name. Note that the user may set the name
 371:   * to null.
 372:   *
 373:   * @see #name
 374:   * @see #getName()
 375:   * @see #setName(String)
 376:   * @serial true if the name has been explicitly set
 377:   */
 378:  boolean nameExplicitlySet;
 379:
 380:  /**
 381:   * Indicates if the object can be focused. Defaults to true for components.
 382:   *
 383:   * @see #isFocusable()
 384:   * @see #setFocusable(boolean)
 385:   * @since 1.4
 386:   */
 387:  boolean focusable = true;
 388:
 389:  /**
 390:   * Tracks whether this component's {@link #isFocusTraversable}
 391:   * method has been overridden.
 392:   *
 393:   * @since 1.4
 394:   */
 395:  int isFocusTraversableOverridden;
 396:
 397:  /**
 398:   * The focus traversal keys, if not inherited from the parent or
 399:   * default keyboard focus manager. These sets will contain only
 400:   * AWTKeyStrokes that represent press and release events to use as
 401:   * focus control.
 402:   *
 403:   * @see #getFocusTraversalKeys(int)
 404:   * @see #setFocusTraversalKeys(int, Set)
 405:   * @since 1.4
 406:   */
 407:  Set[] focusTraversalKeys;
 408:
 409:  /**
 410:   * True if focus traversal keys are enabled. This defaults to true for
 411:   * Component. If this is true, keystrokes in focusTraversalKeys are trapped
 412:   * and processed automatically rather than being passed on to the component.
 413:   *
 414:   * @see #getFocusTraversalKeysEnabled()
 415:   * @see #setFocusTraversalKeysEnabled(boolean)
 416:   * @since 1.4
 417:   */
 418:  boolean focusTraversalKeysEnabled = true;
 419:
 420:  /**
 421:   * Cached information on the minimum size. Should have been transient.
 422:   *
 423:   * @serial ignore
 424:   */
 425:  Dimension minSize;
 426:
 427:  /**
 428:   * Cached information on the preferred size. Should have been transient.
 429:   *
 430:   * @serial ignore
 431:   */
 432:  Dimension prefSize;
 433:
 434:  /**
 435:   * Set to true if an event is to be handled by this component, false if
 436:   * it is to be passed up the hierarcy.
 437:   *
 438:   * @see #dispatchEvent(AWTEvent)
 439:   * @serial true to process event locally
 440:   */
 441:  boolean newEventsOnly;
 442:
 443:  /**
 444:   * Set by subclasses to enable event handling of particular events, and
 445:   * left alone when modifying listeners. For component, this defaults to
 446:   * enabling only input methods.
 447:   *
 448:   * @see #enableInputMethods(boolean)
 449:   * @see AWTEvent
 450:   * @serial the mask of events to process
 451:   */
 452:  long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK;
 453:
 454:  /**
 455:   * Describes all registered PropertyChangeListeners.
 456:   *
 457:   * @see #addPropertyChangeListener(PropertyChangeListener)
 458:   * @see #removePropertyChangeListener(PropertyChangeListener)
 459:   * @see #firePropertyChange(String, Object, Object)
 460:   * @serial the property change listeners
 461:   * @since 1.2
 462:   */
 463:  PropertyChangeSupport changeSupport;
 464:
 465:  /**
 466:   * True if the component has been packed (layed out).
 467:   *
 468:   * @serial true if this is packed
 469:   */
 470:  boolean isPacked;
 471:
 472:  /**
 473:   * The serialization version for this class. Currently at version 4.
 474:   *
 475:   * XXX How do we handle prior versions?
 476:   *
 477:   * @serial the serialization version
 478:   */
 479:  int componentSerializedDataVersion = 4;
 480:
 481:  /**
 482:   * The accessible context associated with this component. This is only set
 483:   * by subclasses.
 484:   *
 485:   * @see #getAccessibleContext()
 486:   * @serial the accessibility context
 487:   * @since 1.2
 488:   */
 489:  AccessibleContext accessibleContext;
 490:
 491:
 492:  // Guess what - listeners are special cased in serialization. See
 493:  // readObject and writeObject.
 494:
 495:  /** Component listener chain. */
 496:  transient ComponentListener componentListener;
 497:
 498:  /** Focus listener chain. */
 499:  transient FocusListener focusListener;
 500:
 501:  /** Key listener chain. */
 502:  transient KeyListener keyListener;
 503:
 504:  /** Mouse listener chain. */
 505:  transient MouseListener mouseListener;
 506:
 507:  /** Mouse motion listener chain. */
 508:  transient MouseMotionListener mouseMotionListener;
 509:
 510:  /**
 511:   * Mouse wheel listener chain.
 512:   *
 513:   * @since 1.4
 514:   */
 515:  transient MouseWheelListener mouseWheelListener;
 516:
 517:  /**
 518:   * Input method listener chain.
 519:   *
 520:   * @since 1.2
 521:   */
 522:  transient InputMethodListener inputMethodListener;
 523:
 524:  /**
 525:   * Hierarcy listener chain.
 526:   *
 527:   * @since 1.3
 528:   */
 529:  transient HierarchyListener hierarchyListener;
 530:
 531:  /**
 532:   * Hierarcy bounds listener chain.
 533:   *
 534:   * @since 1.3
 535:   */
 536:  transient HierarchyBoundsListener hierarchyBoundsListener;
 537:
 538:  // Anything else is non-serializable, and should be declared "transient".
 539:
 540:  /** The parent. */
 541:  transient Container parent;
 542:
 543:  /** The associated native peer. */
 544:  transient ComponentPeer peer;
 545:
 546:  /** The preferred component orientation. */
 547:  transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;
 548:
 549:  /**
 550:   * The associated graphics configuration.
 551:   *
 552:   * @since 1.4
 553:   */
 554:  transient GraphicsConfiguration graphicsConfig;
 555:
 556:  /**
 557:   * The buffer strategy for repainting.
 558:   *
 559:   * @since 1.4
 560:   */
 561:  transient BufferStrategy bufferStrategy;
 562:
 563:  /**
 564:   * true if requestFocus was called on this component when its
 565:   * top-level ancestor was not focusable.
 566:   */
 567:  private transient FocusEvent pendingFocusRequest = null;
 568:
 569:  /**
 570:   * The system properties that affect image updating.
 571:   */
 572:  private static transient boolean incrementalDraw;
 573:  private static transient ClasspathLong redrawRate;
 574:
 575:  static
 576:	    {
 577:    incrementalDraw = ClasspathBoolean.getBoolean ("awt.image.incrementalDraw");
 578:    redrawRate = ClasspathLong.getLong ("awt.image.redrawrate");
 579:  }
 580:
 581:  // Public and protected API.
 582:
 583:  /**
 584:   * Default constructor for subclasses. When Component is extended directly,
 585:   * it forms a lightweight component that must be hosted in an opaque native
 586:   * container higher in the tree.
 587:   */
 588:  protected Component()
 589:	    {
 590:  }
 591:
 592:  /**
 593:   * Returns the name of this component.
 594:   *
 595:   * @return the name of this component
 596:   * @see #setName(String)
 597:   * @since 1.1
 598:   */
 599:  public String getName()
 600:	    {
 601:    if (name == null && ! nameExplicitlySet)
 602:      name = generateName();
 603:    return name;
 604:  }
 605:
 606:  /**
 607:   * Sets the name of this component to the specified name.
 608:   *
 609:   * @param name the new name of this component
 610:   * @see #getName()
 611:   * @since 1.1
 612:   */
 613:  public void setName(String name)
 614:	    {
 615:    nameExplicitlySet = true;
 616:    this.name = name;
 617:  }
 618:
 619:  /**
 620:   * Returns the parent of this component.
 621:   *
 622:   * @return the parent of this component
 623:   */
 624:  public Container getParent()
 625:	    {
 626:    return parent;
 627:  }
 628:
 629:  /**
 630:   * Returns the native windowing system peer for this component. Only the
 631:   * platform specific implementation code should call this method.
 632:   *
 633:   * @return the peer for this component
 634:   * @deprecated user programs should not directly manipulate peers; use
 635:   *             {@link #isDisplayable()} instead
 636:   */
 637:  // Classpath's Gtk peers rely on this.
 638:  public ComponentPeer getPeer()
 639:	    {
 640:    return peer;
 641:  }
 642:
 643:  /**
 644:   * Set the associated drag-and-drop target, which receives events when this
 645:   * is enabled.
 646:   *
 647:   * @param dt the new drop target
 648:   * @see #isEnabled()
 649:   */
 650:  public void setDropTarget(DropTarget dt)
 651:	    {
 652:    this.dropTarget = dt;
 653:  }
 654:
 655:  /**
 656:   * Gets the associated drag-and-drop target, if there is one.
 657:   *
 658:   * @return the drop target
 659:   */
 660:  public DropTarget getDropTarget()
 661:	    {
 662:    return dropTarget;
 663:  }
 664:
 665:  /**
 666:   * Returns the graphics configuration of this component, if there is one.
 667:   * If it has not been set, it is inherited from the parent.
 668:   *
 669:   * @return the graphics configuration, or null
 670:   * @since 1.3
 671:   */
 672:  public GraphicsConfiguration getGraphicsConfiguration()
 673:	    {
 674:    return getGraphicsConfigurationImpl();
 675:  }
 676:
 677:  /**
 678:   * Returns the object used for synchronization locks on this component
 679:   * when performing tree and layout functions.
 680:   *
 681:   * @return the synchronization lock for this component
 682:   */
 683:  public final Object getTreeLock()
 684:	    {
 685:    return treeLock;
 686:  }
 687:
 688:  /**
 689:   * Returns the toolkit in use for this component. The toolkit is associated
 690:   * with the frame this component belongs to.
 691:   *
 692:   * @return the toolkit for this component
 693:   */
 694:  public Toolkit getToolkit()
 695:	    {
 696:    if (peer != null)
 697:	        {
 698:        Toolkit tk = peer.getToolkit();
 699:        if (tk != null)
 700:          return tk;
 701:      }
 702:    // Get toolkit for lightweight component.
 703:    if (parent != null)
 704:      return parent.getToolkit();
 705:    return Toolkit.getDefaultToolkit();
 706:  }
 707:
 708:  /**
 709:   * Tests whether or not this component is valid. A invalid component needs
 710:   * to have its layout redone.
 711:   *
 712:   * @return true if this component is valid
 713:   * @see #validate()
 714:   * @see #invalidate()
 715:   */
 716:  public boolean isValid()
 717:	    {
 718:    return valid;
 719:  }
 720:
 721:  /**
 722:   * Tests if the component is displayable. It must be connected to a native
 723:   * screen resource, and all its ancestors must be displayable. A containment
 724:   * hierarchy is made displayable when a window is packed or made visible.
 725:   *
 726:   * @return true if the component is displayable
 727:   * @see Container#add(Component)
 728:   * @see Container#remove(Component)
 729:   * @see Window#pack()
 730:   * @see Window#show()
 731:   * @see Window#dispose()
 732:   * @since 1.2
 733:   */
 734:  public boolean isDisplayable()
 735:	    {
 736:    if (parent != null)
 737:      return parent.isDisplayable();
 738:    return false;
 739:  }
 740:
 741:  /**
 742:   * Tests whether or not this component is visible. Except for top-level
 743:   * frames, components are initially visible.
 744:   *
 745:   * @return true if the component is visible
 746:   * @see #setVisible(boolean)
 747:   */
 748:  public boolean isVisible()
 749:	    {
 750:    return visible;
 751:  }
 752:
 753:  /**
 754:   * Tests whether or not this component is actually being shown on
 755:   * the screen. This will be true if and only if it this component is
 756:   * visible and its parent components are all visible.
 757:   *
 758:   * @return true if the component is showing on the screen
 759:   * @see #setVisible(boolean)
 760:   */
 761:  public boolean isShowing()
 762:	    {
 763:    if (! visible || peer == null)
 764:      return false;
 765:
 766:    return parent == null ? true : parent.isShowing();
 767:  }
 768:
 769:  /**
 770:   * Tests whether or not this component is enabled. Components are enabled
 771:   * by default, and must be enabled to receive user input or generate events.
 772:   *
 773:   * @return true if the component is enabled
 774:   * @see #setEnabled(boolean)
 775:   */
 776:  public boolean isEnabled()
 777:	    {
 778:    return enabled;
 779:  }
 780:
 781:  /**
 782:   * Enables or disables this component. The component must be enabled to
 783:   * receive events (except that lightweight components always receive mouse
 784:   * events).
 785:   *
 786:   * @param enabled true to enable this component
 787:   * @see #isEnabled()
 788:   * @see #isLightweight()
 789:   * @since 1.1
 790:   */
 791:  public void setEnabled(boolean b)
 792:	    {
 793:    enable (b);
 794:  }
 795:
 796:  /**
 797:   * Enables this component.
 798:   *
 799:   * @deprecated use {@link #setEnabled(boolean)} instead
 800:   */
 801:  public void enable()
 802:	    {
 803:    this.enabled = true;
 804:    if (peer != null)
 805:      peer.setEnabled (true);
 806:  }
 807:
 808:  /**
 809:   * Enables or disables this component.
 810:   *
 811:   * @param enabled true to enable this component
 812:   * @deprecated use {@link #setEnabled(boolean)} instead
 813:   */
 814:  public void enable(boolean b)
 815:	    {
 816:    if (b)
 817:      enable ();
 818:    else
 819:      disable ();
 820:  }
 821:
 822:  /**
 823:   * Disables this component.
 824:   *
 825:   * @deprecated use {@link #setEnabled(boolean)} instead
 826:   */
 827:  public void disable()
 828:	    {
 829:    this.enabled = false;
 830:    if (peer != null)
 831:      peer.setEnabled (false);
 832:  }
 833:
 834:  /**
 835:   * Checks if this image is painted to an offscreen image buffer that is
 836:   * later copied to screen (double buffering reduces flicker). This version
 837:   * returns false, so subclasses must override it if they provide double
 838:   * buffering.
 839:   *
 840:   * @return true if this is double buffered; defaults to false
 841:   */
 842:  public boolean isDoubleBuffered()
 843:	    {
 844:    return false;
 845:  }
 846:
 847:  /**
 848:   * Enables or disables input method support for this component. By default,
 849:   * components have this enabled. Input methods are given the opportunity
 850:   * to process key events before this component and its listeners.
 851:   *
 852:   * @param enable true to enable input method processing
 853:   * @see #processKeyEvent(KeyEvent)
 854:   * @since 1.2
 855:   */
 856:  public void enableInputMethods(boolean enable)
 857:	    {
 858:    // XXX Implement.
 859:    throw new Error("not implemented");
 860:  }
 861:
 862:  /**
 863:   * Makes this component visible or invisible. Note that it wtill might
 864:   * not show the component, if a parent is invisible.
 865:   *
 866:   * @param visible true to make this component visible
 867:   * @see #isVisible()
 868:   * @since 1.1
 869:   */
 870:  public void setVisible(boolean b)
 871:	    {
 872:    // Inspection by subclassing shows that Sun's implementation calls
 873:    // show(boolean) which then calls show() or hide(). It is the show()
 874:    // method that is overriden in subclasses like Window.
 875:    show (b);
 876:  }
 877:
 878:  /**
 879:   * Makes this component visible on the screen.
 880:   *
 881:   * @deprecated use {@link #setVisible(boolean)} instead
 882:   */
 883:  public void show()
 884:	    {
 885:    // We must set visible before showing the peer.  Otherwise the
 886:    // peer could post paint events before visible is true, in which
 887:    // case lightweight components are not initially painted --
 888:    // Container.paint first calls isShowing () before painting itself
 889:    // and its children.
 890:    if(!isVisible())
 891:	        {
 892:        this.visible = true;
 893:        if (peer != null)
 894:          peer.setVisible(true);
 895:        invalidate();
 896:        ComponentEvent ce =
 897:          new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
 898:        getToolkit().getSystemEventQueue().postEvent(ce);
 899:      }
 900:  }
 901:
 902:  /**
 903:   * Makes this component visible or invisible.
 904:   *
 905:   * @param visible true to make this component visible
 906:   * @deprecated use {@link #setVisible(boolean)} instead
 907:   */
 908:  public void show(boolean b)
 909:	    {
 910:    if (b)
 911:      show ();
 912:    else
 913:      hide ();
 914:  }
 915:
 916:  /**
 917:   * Hides this component so that it is no longer shown on the screen.
 918:   *
 919:   * @deprecated use {@link #setVisible(boolean)} instead
 920:   */
 921:  public void hide()
 922:	    {
 923:    if (isVisible())
 924:	        {
 925:        if (peer != null)
 926:          peer.setVisible(false);
 927:        this.visible = false;
 928:        invalidate();
 929:        ComponentEvent ce =
 930:          new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
 931:        getToolkit().getSystemEventQueue().postEvent(ce);
 932:      }
 933:  }
 934:
 935:  /**
 936:   * Returns this component's foreground color. If not set, this is inherited
 937:   * from the parent.
 938:   *
 939:   * @return this component's foreground color, or null
 940:   * @see #setForeground(Color)
 941:   */
 942:  public Color getForeground()
 943:	    {
 944:    if (foreground != null)
 945:      return foreground;
 946:    return parent == null ? SystemColor.windowText : parent.getForeground();
 947:  }
 948:
 949:  /**
 950:   * Sets this component's foreground color to the specified color. This is a
 951:   * bound property.
 952:   *
 953:   * @param c the new foreground color
 954:   * @see #getForeground()
 955:   */
 956:  public void setForeground(Color c)
 957:	    {
 958:    firePropertyChange("foreground", foreground, c);
 959:    if (peer != null)
 960:      peer.setForeground(c);
 961:    foreground = c;
 962:  }
 963:
 964:  /**
 965:   * Tests if the foreground was explicitly set, or just inherited from the
 966:   * parent.
 967:   *
 968:   * @return true if the foreground has been set
 969:   * @since 1.4
 970:   */
 971:  public boolean isForegroundSet()
 972:	    {
 973:    return foreground != null;
 974:  }
 975:
 976:  /**
 977:   * Returns this component's background color. If not set, this is inherited
 978:   * from the parent.
 979:   *
 980:   * @return the background color of the component, or null
 981:   * @see #setBackground(Color)
 982:   */
 983:  public Color getBackground()
 984:	    {
 985:    if (background != null)
 986:      return background;
 987:    return parent == null ? SystemColor.window : parent.getBackground();
 988:  }
 989:
 990:  /**
 991:   * Sets this component's background color to the specified color. The parts
 992:   * of the component affected by the background color may by system dependent.
 993:   * This is a bound property.
 994:   *
 995:   * @param c the new background color
 996:   * @see #getBackground()
 997:   */
 998:  public void setBackground(Color c)
 999:	    {
1000:    // If c is null, inherit from closest ancestor whose bg is set.
1001:    if (c == null && parent != null)
1002:      c = parent.getBackground();
1003:    firePropertyChange("background", background, c);
1004:    if (peer != null && c != null)
1005:      peer.setBackground(c);
1006:    background = c;
1007:  }
1008:
1009:  /**
1010:   * Tests if the background was explicitly set, or just inherited from the
1011:   * parent.
1012:   *
1013:   * @return true if the background has been set
1014:   * @since 1.4
1015:   */
1016:  public boolean isBackgroundSet()
1017:	    {
1018:    return background != null;
1019:  }
1020:
1021:  /**
1022:   * Returns the font in use for this component. If not set, this is inherited
1023:   * from the parent.
1024:   *
1025:   * @return the font for this component
1026:   * @see #setFont(Font)
1027:   */
1028:  public Font getFont()
1029:	    {
1030:    if (font != null)
1031:      return font;
1032:
1033:    if (parent != null)
1034:      return parent.getFont ();
1035:    else
1036:      return new Font ("Dialog", Font.PLAIN, 12);
1037:  }
1038:
1039:  /**
1040:   * Sets the font for this component to the specified font. This is a bound
1041:   * property.
1042:   *
1043:   * @param font the new font for this component
1044:   * @see #getFont()
1045:   */
1046:  public void setFont(Font f)
1047:	    {
1048:    firePropertyChange("font", font, f);
1049:    if (peer != null)
1050:      peer.setFont(f);
1051:    invalidate();
1052:    font = f;
1053:  }
1054:
1055:  /**
1056:   * Tests if the font was explicitly set, or just inherited from the parent.
1057:   *
1058:   * @return true if the font has been set
1059:   * @since 1.4
1060:   */
1061:  public boolean isFontSet()
1062:	    {
1063:    return font != null;
1064:  }
1065:
1066:  /**
1067:   * Returns the locale for this component. If this component does not
1068:   * have a locale, the locale of the parent component is returned.
1069:   *
1070:   * @return the locale for this component
1071:   * @throws IllegalComponentStateException if it has no locale or parent
1072:   * @see setLocale(Locale)
1073:   * @since 1.1
1074:   */
1075:  public Locale getLocale()
1076:	    {
1077:    if (locale != null)
1078:      return locale;
1079:    if (parent == null)
1080:      throw new IllegalComponentStateException
1081:        ("Component has no parent: can't determine Locale");
1082:    return parent.getLocale();
1083:  }
1084:
1085:  /**
1086:   * Sets the locale for this component to the specified locale. This is a
1087:   * bound property.
1088:   *
1089:   * @param locale the new locale for this component
1090:   */
1091:  public void setLocale(Locale l)
1092:	    {
1093:    firePropertyChange("locale", locale, l);
1094:    locale = l;
1095:    // New writing/layout direction or more/less room for localized labels.
1096:    invalidate();
1097:  }
1098:
1099:  /**
1100:   * Returns the color model of the device this componet is displayed on.
1101:   *
1102:   * @return this object's color model
1103:   * @see Toolkit#getColorModel()
1104:   */
1105:  public ColorModel getColorModel()
1106:	    {
1107:    GraphicsConfiguration config = getGraphicsConfiguration();
1108:    return config != null ? config.getColorModel()
1109:      : getToolkit().getColorModel();
1110:  }
1111:
1112:  /**
1113:   * Returns the location of this component's top left corner relative to
1114:   * its parent component. This may be outdated, so for synchronous behavior,
1115:   * you should use a component listner.
1116:   *
1117:   * @return the location of this component
1118:   * @see #setLocation(int, int)
1119:   * @see #getLocationOnScreen()
1120:   * @since 1.1
1121:   */
1122:  public Point getLocation()
1123:	    {
1124:    return location ();
1125:  }
1126:
1127:  /**
1128:   * Returns the location of this component's top left corner in screen
1129:   * coordinates.
1130:   *
1131:   * @return the location of this component in screen coordinates
1132:   * @throws IllegalComponentStateException if the component is not showing
1133:   */
1134:  public Point getLocationOnScreen()
1135:	    {
1136:    if (! isShowing())
1137:      throw new IllegalComponentStateException("component not showing");
1138:    // We know peer != null here.
1139:    return peer.getLocationOnScreen();
1140:  }
1141:
1142:  /**
1143:   * Returns the location of this component's top left corner relative to
1144:   * its parent component.
1145:   *
1146:   * @return the location of this component
1147:   * @deprecated use {@link #getLocation()} instead
1148:   */
1149:  public Point location()
1150:	    {
1151:    return new Point (x, y);
1152:  }
1153:
1154:  /**
1155:   * Moves this component to the specified location, relative to the parent's
1156:   * coordinates. The coordinates are the new upper left corner of this
1157:   * component.
1158:   *
1159:   * @param x the new X coordinate of this component
1160:   * @param y the new Y coordinate of this component
1161:   * @see #getLocation()
1162:   * @see #setBounds(int, int, int, int)
1163:   */
1164:  public void setLocation(int x, int y)
1165:	    {
1166:    move (x, y);
1167:  }
1168:
1169:  /**
1170:   * Moves this component to the specified location, relative to the parent's
1171:   * coordinates. The coordinates are the new upper left corner of this
1172:   * component.
1173:   *
1174:   * @param x the new X coordinate of this component
1175:   * @param y the new Y coordinate of this component
1176:   * @deprecated use {@link #setLocation(int, int)} instead
1177:   */
1178:  public void move(int x, int y)
1179:	    {
1180:    setBounds(x, y, this.width, this.height);
1181:  }
1182:
1183:  /**
1184:   * Moves this component to the specified location, relative to the parent's
1185:   * coordinates. The coordinates are the new upper left corner of this
1186:   * component.
1187:   *
1188:   * @param p new coordinates for this component
1189:   * @throws NullPointerException if p is null
1190:   * @see #getLocation()
1191:   * @see #setBounds(int, int, int, int)
1192:   * @since 1.1
1193:   */
1194:  public void setLocation(Point p)
1195:	    {
1196:    setLocation(p.x, p.y);
1197:  }
1198:
1199:  /**
1200:   * Returns the size of this object.
1201:   *
1202:   * @return the size of this object
1203:   * @see #setSize(int, int)
1204:   * @since 1.1
1205:   */
1206:  public Dimension getSize()
1207:	    {
1208:    return size ();
1209:  }
1210:
1211:  /**
1212:   * Returns the size of this object.
1213:   *
1214:   * @return the size of this object
1215:   * @deprecated use {@link #getSize()} instead
1216:   */
1217:  public Dimension size()
1218:	    {
1219:    return new Dimension (width, height);
1220:  }
1221:
1222:  /**
1223:   * Sets the size of this component to the specified width and height.
1224:   *
1225:   * @param width the new width of this component
1226:   * @param height the new height of this component
1227:   * @see #getSize()
1228:   * @see #setBounds(int, int, int, int)
1229:   */
1230:  public void setSize(int width, int height)
1231:	    {
1232:    resize (width, height);
1233:  }
1234:
1235:  /**
1236:   * Sets the size of this component to the specified value.
1237:   *
1238:   * @param width the new width of the component
1239:   * @param height the new height of the component
1240:   * @deprecated use {@link #setSize(int, int)} instead
1241:   */
1242:  public void resize(int width, int height)
1243:	    {
1244:    setBounds(this.x, this.y, width, height);
1245:  }
1246:
1247:  /**
1248:   * Sets the size of this component to the specified value.
1249:   *
1250:   * @param d the new size of this component
1251:   * @throws NullPointerException if d is null
1252:   * @see #setSize(int, int)
1253:   * @see #setBounds(int, int, int, int)
1254:   * @since 1.1
1255:   */
1256:  public void setSize(Dimension d)
1257:	    {
1258:    resize (d);
1259:  }
1260:
1261:  /**
1262:   * Sets the size of this component to the specified value.
1263:   *
1264:   * @param d the new size of this component
1265:   * @throws NullPointerException if d is null
1266:   * @deprecated use {@link #setSize(Dimension)} instead
1267:   */
1268:  public void resize(Dimension d)
1269:	    {
1270:    resize (d.width, d.height);
1271:  }
1272:
1273:  /**
1274:   * Returns a bounding rectangle for this component. Note that the
1275:   * returned rectange is relative to this component's parent, not to
1276:   * the screen.
1277:   *
1278:   * @return the bounding rectangle for this component
1279:   * @see #setBounds(int, int, int, int)
1280:   * @see #getLocation()
1281:   * @see #getSize()
1282:   */
1283:  public Rectangle getBounds()
1284:	    {
1285:    return bounds ();
1286:  }
1287:
1288:  /**
1289:   * Returns a bounding rectangle for this component. Note that the
1290:   * returned rectange is relative to this component's parent, not to
1291:   * the screen.
1292:   *
1293:   * @return the bounding rectangle for this component
1294:   * @deprecated use {@link #getBounds()} instead
1295:   */
1296:  public Rectangle bounds()
1297:	    {
1298:    return new Rectangle (x, y, width, height);
1299:  }
1300:
1301:  /**
1302:   * Sets the bounding rectangle for this component to the specified values.
1303:   * Note that these coordinates are relative to the parent, not to the screen.
1304:   *
1305:   * @param x the X coordinate of the upper left corner of the rectangle
1306:   * @param y the Y coordinate of the upper left corner of the rectangle
1307:   * @param w the width of the rectangle
1308:   * @param h the height of the rectangle
1309:   * @see #getBounds()
1310:   * @see #setLocation(int, int)
1311:   * @see #setLocation(Point)
1312:   * @see #setSize(int, int)
1313:   * @see #setSize(Dimension)
1314:   * @since 1.1
1315:   */
1316:  public void setBounds(int x, int y, int w, int h)
1317:	    {
1318:    reshape (x, y, w, h);
1319:  }
1320:
1321:  /**
1322:   * Sets the bounding rectangle for this component to the specified values.
1323:   * Note that these coordinates are relative to the parent, not to the screen.
1324:   *
1325:   * @param x the X coordinate of the upper left corner of the rectangle
1326:   * @param y the Y coordinate of the upper left corner of the rectangle
1327:   * @param width the width of the rectangle
1328:   * @param height the height of the rectangle
1329:   * @deprecated use {@link #setBounds(int, int, int, int)} instead
1330:   */
1331:  public void reshape(int x, int y, int width, int height)
1332:	    {
1333:    int oldx = this.x;
1334:    int oldy = this.y;
1335:    int oldwidth = this.width;
1336:    int oldheight = this.height;
1337:
1338:    if (this.x == x && this.y == y
1339:        && this.width == width && this.height == height)
1340:      return;
1341:    invalidate ();
1342:    this.x = x;
1343:    this.y = y;
1344:    this.width = width;
1345:    this.height = height;
1346:    if (peer != null)
1347:      peer.setBounds (x, y, width, height);
1348:
1349:    // Erase old bounds and repaint new bounds for lightweights.
1350:    if (isLightweight())
1351:	        {
1352:        boolean shouldRepaintParent = false;
1353:        boolean shouldRepaintSelf = false;
1354:
1355:        if (parent != null)
1356:	            {
1357:            Rectangle parentBounds = parent.getBounds();
1358:            Rectangle oldBounds = new Rectangle(parent.getX() + oldx,
1359:                                                parent.getY() + oldy,
1360:                                                oldwidth, oldheight);
1361:            Rectangle newBounds = new Rectangle(parent.getX() + x,
1362:                                                parent.getY() + y,
1363:                                                width, height);
1364:            shouldRepaintParent = parentBounds.intersects(oldBounds);
1365:            shouldRepaintSelf = parentBounds.intersects(newBounds);
1366:          }
1367:
1368:        if (shouldRepaintParent)
1369:          parent.repaint(oldx, oldy, oldwidth, oldheight);
1370:        if (shouldRepaintSelf)
1371:          repaint();
1372:      }
1373:
1374:    if (oldx != x || oldy != y)
1375:	        {
1376:        ComponentEvent ce = new ComponentEvent(this,
1377:                                               ComponentEvent.COMPONENT_MOVED);
1378:        getToolkit().getSystemEventQueue().postEvent(ce);
1379:      }
1380:    if (oldwidth != width || oldheight != height)
1381:	        {
1382:        ComponentEvent ce = new ComponentEvent(this,
1383:                                               ComponentEvent.COMPONENT_RESIZED);
1384:        getToolkit().getSystemEventQueue().postEvent(ce);
1385:      }
1386:  }
1387:
1388:  /**
1389:   * Sets the bounding rectangle for this component to the specified
1390:   * rectangle. Note that these coordinates are relative to the parent, not
1391:   * to the screen.
1392:   *
1393:   * @param r the new bounding rectangle
1394:   * @throws NullPointerException if r is null
1395:   * @see #getBounds()
1396:   * @see #setLocation(Point)
1397:   * @see #setSize(Dimension)
1398:   * @since 1.1
1399:   */
1400:  public void setBounds(Rectangle r)
1401:	    {
1402:    setBounds (r.x, r.y, r.width, r.height);
1403:  }
1404:
1405:  /**
1406:   * Gets the x coordinate of the upper left corner. This is more efficient
1407:   * than getBounds().x or getLocation().x.
1408:   *
1409:   * @return the current x coordinate
1410:   * @since 1.2
1411:   */
1412:  public int getX()
1413:	    {
1414:    return x;
1415:  }
1416:
1417:  /**
1418:   * Gets the y coordinate of the upper left corner. This is more efficient
1419:   * than getBounds().y or getLocation().y.
1420:   *
1421:   * @return the current y coordinate
1422:   * @since 1.2
1423:   */
1424:  public int getY()
1425:	    {
1426:    return y;
1427:  }
1428:
1429:  /**
1430:   * Gets the width of the component. This is more efficient than
1431:   * getBounds().width or getSize().width.
1432:   *
1433:   * @return the current width
1434:   * @since 1.2
1435:   */
1436:  public int getWidth()
1437:	    {
1438:    return width;
1439:  }
1440:
1441:  /**
1442:   * Gets the height of the component. This is more efficient than
1443:   * getBounds().height or getSize().height.
1444:   *
1445:   * @return the current width
1446:   * @since 1.2
1447:   */
1448:  public int getHeight()
1449:	    {
1450:    return height;
1451:  }
1452:
1453:  /**
1454:   * Returns the bounds of this component. This allows reuse of an existing
1455:   * rectangle, if r is non-null.
1456:   *
1457:   * @param r the rectangle to use, or null
1458:   * @return the bounds
1459:   */
1460:  public Rectangle getBounds(Rectangle r)
1461:	    {
1462:    if (r == null)
1463:      r = new Rectangle();
1464:    r.x = x;
1465:    r.y = y;
1466:    r.width = width;
1467:    r.height = height;
1468:    return r;
1469:  }
1470:
1471:  /**
1472:   * Returns the size of this component. This allows reuse of an existing
1473:   * dimension, if d is non-null.
1474:   *
1475:   * @param d the dimension to use, or null
1476:   * @return the size
1477:   */
1478:  public Dimension getSize(Dimension d)
1479:	    {
1480:    if (d == null)
1481:      d = new Dimension();
1482:    d.width = width;
1483:    d.height = height;
1484:    return d;
1485:  }
1486:
1487:  /**
1488:   * Returns the location of this component. This allows reuse of an existing
1489:   * point, if p is non-null.
1490:   *
1491:   * @param p the point to use, or null
1492:   * @return the location
1493:   */
1494:  public Point getLocation(Point p)
1495:	    {
1496:    if (p == null)
1497:      p = new Point();
1498:    p.x = x;
1499:    p.y = y;
1500:    return p;
1501:  }
1502:
1503:  /**
1504:   * Tests if this component is opaque. All "heavyweight" (natively-drawn)
1505:   * components are opaque. A component is opaque if it draws all pixels in
1506:   * the bounds; a lightweight component is partially transparent if it lets
1507:   * pixels underneath show through. Subclasses that guarantee that all pixels
1508:   * will be drawn should override this.
1509:   *
1510:   * @return true if this is opaque
1511:   * @see #isLightweight()
1512:   * @since 1.2
1513:   */
1514:  public boolean isOpaque()
1515:	    {
1516:    return ! isLightweight();
1517:  }
1518:
1519:  /**
1520:   * Return whether the component is lightweight. That means the component has
1521:   * no native peer, but is displayable. This applies to subclasses of
1522:   * Component not in this package, such as jp.ujihara.javax.swing.
1523:   *
1524:   * @return true if the component has a lightweight peer
1525:   * @see #isDisplayable()
1526:   * @since 1.2
1527:   */
1528:  public boolean isLightweight()
1529:	    {
1530:    return peer instanceof LightweightPeer;
1531:  }
1532:
1533:  /**
1534:   * Returns the component's preferred size.
1535:   *
1536:   * @return the component's preferred size
1537:   * @see #getMinimumSize()
1538:   * @see LayoutManager
1539:   */
1540:  public Dimension getPreferredSize()
1541:	    {
1542:    return preferredSize();
1543:  }
1544:
1545:  /**
1546:   * Returns the component's preferred size.
1547:   *
1548:   * @return the component's preferred size
1549:   * @deprecated use {@link #getPreferredSize()} instead
1550:   */
1551:  public Dimension preferredSize()
1552:	    {
1553:    if (prefSize == null)
1554:      if (peer == null)
1555:        return new Dimension(width, height);
1556:      else 
1557:        prefSize = peer.getPreferredSize();
1558:    return prefSize;
1559:  }
1560:
1561:  /**
1562:   * Returns the component's minimum size.
1563:   *
1564:   * @return the component's minimum size
1565:   * @see #getPreferredSize()
1566:   * @see LayoutManager
1567:   */
1568:  public Dimension getMinimumSize()
1569:	    {
1570:    return minimumSize();
1571:  }
1572:
1573:  /**
1574:   * Returns the component's minimum size.
1575:   *
1576:   * @return the component's minimum size
1577:   * @deprecated use {@link #getMinimumSize()} instead
1578:   */
1579:  public Dimension minimumSize()
1580:	    {
1581:    if (minSize == null)
1582:      minSize = (peer != null ? peer.getMinimumSize()
1583:                 : new Dimension(width, height));
1584:    return minSize;
1585:  }
1586:
1587:  /**
1588:   * Returns the component's maximum size.
1589:   *
1590:   * @return the component's maximum size
1591:   * @see #getMinimumSize()
1592:   * @see #getPreferredSize()
1593:   * @see LayoutManager
1594:   */
1595:  public Dimension getMaximumSize()
1596:	    {
1597:    return new Dimension(ClasspathInteger.MAX_VALUE, ClasspathInteger.MAX_VALUE);
1598:  }
1599:
1600:  /**
1601:   * Returns the preferred horizontal alignment of this component. The value
1602:   * returned will be between {@link #LEFT_ALIGNMENT} and
1603:   * {@link #RIGHT_ALIGNMENT}, inclusive.
1604:   *
1605:   * @return the preferred horizontal alignment of this component
1606:   */
1607:  public float getAlignmentX()
1608:	    {
1609:    return CENTER_ALIGNMENT;
1610:  }
1611:
1612:  /**
1613:   * Returns the preferred vertical alignment of this component. The value
1614:   * returned will be between {@link #TOP_ALIGNMENT} and
1615:   * {@link #BOTTOM_ALIGNMENT}, inclusive.
1616:   *
1617:   * @return the preferred vertical alignment of this component
1618:   */
1619:  public float getAlignmentY()
1620:	    {
1621:    return CENTER_ALIGNMENT;
1622:  }
1623:
1624:  /**
1625:   * Calls the layout manager to re-layout the component. This is called
1626:   * during validation of a container in most cases.
1627:   *
1628:   * @see #validate()
1629:   * @see LayoutManager
1630:   */
1631:  public void doLayout()
1632:	    {
1633:    layout ();
1634:  }
1635:
1636:  /**
1637:   * Calls the layout manager to re-layout the component. This is called
1638:   * during validation of a container in most cases.
1639:   *
1640:   * @deprecated use {@link #doLayout()} instead
1641:   */
1642:  public void layout()
1643:	    {
1644:    // Nothing to do unless we're a container.
1645:  }
1646:
1647:  /**
1648:   * Called to ensure that the layout for this component is valid. This is
1649:   * usually called on containers.
1650:   *
1651:   * @see #invalidate()
1652:   * @see #doLayout()
1653:   * @see LayoutManager
1654:   * @see Container#validate()
1655:   */
1656:  public void validate()
1657:	    {
1658:    valid = true;
1659:  }
1660:
1661:  /**
1662:   * Invalidates this component and all of its parent components. This will
1663:   * cause them to have their layout redone. This is called frequently, so
1664:   * make it fast.
1665:   */
1666:  public void invalidate()
1667:	    {
1668:    valid = false;
1669:    prefSize = null;
1670:    minSize = null;
1671:    if (parent != null && parent.valid)
1672:      parent.invalidate();
1673:  }
1674:
1675:  /**
1676:   * Returns a graphics object for this component. Returns <code>null</code>
1677:   * if this component is not currently displayed on the screen.
1678:   *
1679:   * @return a graphics object for this component
1680:   * @see #paint(Graphics)
1681:   */
1682:  public Graphics getGraphics()
1683:	    {
1684:    if (peer != null)
1685:	        {
1686:        Graphics gfx = peer.getGraphics();
1687:        if (gfx != null)
1688:          return gfx;
1689:        // create graphics for lightweight:
1690:        Container parent = getParent();
1691:        if (parent != null)
1692:	            {
1693:            gfx = parent.getGraphics();
1694:            Rectangle bounds = getBounds();
1695:            gfx.setClip(bounds);
1696:            gfx.translate(bounds.x, bounds.y);
1697:            return gfx;
1698:          }
1699:      }
1700:    return null;
1701:  }
1702:
1703:  /**
1704:   * Returns the font metrics for the specified font in this component.
1705:   *
1706:   * @param font the font to retrieve metrics for
1707:   * @return the font metrics for the specified font
1708:   * @throws NullPointerException if font is null
1709:   * @see #getFont()
1710:   * @see Toolkit#getFontMetrics(Font)
1711:   */
1712:  public FontMetrics getFontMetrics(Font font)
1713:	    {
1714:    return peer == null ? getToolkit().getFontMetrics(font)
1715:      : peer.getFontMetrics(font);
1716:  }
1717:
1718:  /**
1719:   * Sets the cursor for this component to the specified cursor. The cursor
1720:   * is displayed when the point is contained by the component, and the
1721:   * component is visible, displayable, and enabled. This is inherited by
1722:   * subcomponents unless they set their own cursor.
1723:   *
1724:   * @param cursor the new cursor for this component
1725:   * @see #isEnabled()
1726:   * @see #isShowing()
1727:   * @see #getCursor()
1728:   * @see #contains(int, int)
1729:   * @see Toolkit#createCustomCursor(Image, Point, String)
1730:   */
1731:  public void setCursor(Cursor cursor)
1732:	    {
1733:    this.cursor = cursor;
1734:    if (peer != null)
1735:      peer.setCursor(cursor);
1736:  }
1737:
1738:  /**
1739:   * Returns the cursor for this component. If not set, this is inherited
1740:   * from the parent, or from Cursor.getDefaultCursor().
1741:   *
1742:   * @return the cursor for this component
1743:   */
1744:  public Cursor getCursor()
1745:	    {
1746:    if (cursor != null)
1747:      return cursor;
1748:    return parent != null ? parent.getCursor() : Cursor.getDefaultCursor();
1749:  }
1750:
1751:  /**
1752:   * Tests if the cursor was explicitly set, or just inherited from the parent.
1753:   *
1754:   * @return true if the cursor has been set
1755:   * @since 1.4
1756:   */
1757:  public boolean isCursorSet()
1758:	    {
1759:    return cursor != null;
1760:  }
1761:
1762:  /**
1763:   * Paints this component on the screen. The clipping region in the graphics
1764:   * context will indicate the region that requires painting. This is called
1765:   * whenever the component first shows, or needs to be repaired because
1766:   * something was temporarily drawn on top. It is not necessary for
1767:   * subclasses to call <code>super.paint(g)</code>. Components with no area
1768:   * are not painted.
1769:   *
1770:   * @param g the graphics context for this paint job
1771:   * @see #update(Graphics)
1772:   */
1773:  public void paint(Graphics g)
1774:	    {
1775:    // Paint the heavyweight peer
1776:    if (!isLightweight() && peer != null)
1777:      peer.paint(g);
1778:  }
1779:
1780:  /**
1781:   * Updates this component. This is called in response to
1782:   * <code>repaint</code>. This method fills the component with the
1783:   * background color, then sets the foreground color of the specified
1784:   * graphics context to the foreground color of this component and calls
1785:   * the <code>paint()</code> method. The coordinates of the graphics are
1786:   * relative to this component. Subclasses should call either
1787:   * <code>super.update(g)</code> or <code>paint(g)</code>.
1788:   *
1789:   * @param graphics the graphics context for this update
1790:   * @see #paint(Graphics)
1791:   * @see #repaint()
1792:   */
1793:  public void update(Graphics g)
1794:	    {
1795:    if (!isLightweight())
1796:	        {
1797:        Rectangle clip = g.getClipBounds();
1798:        if (clip == null)
1799:          g.clearRect(0, 0, width, height);
1800:        else
1801:          g.clearRect(clip.x, clip.y, clip.width, clip.height);
1802:      }
1803:
1804:    paint(g);
1805:  }
1806:
1807:  /**
1808:   * Paints this entire component, including any sub-components.
1809:   *
1810:   * @param graphics the graphics context for this paint job
1811:   * @see #paint(Graphics)
1812:   */
1813:  public void paintAll(Graphics g)
1814:	    {
1815:    if (! visible)
1816:      return;
1817:    paint(g);
1818:  }
1819:
1820:  /**
1821:   * Repaint this entire component. The <code>update()</code> method
1822:   * on this component will be called as soon as possible.
1823:   *
1824:   * @see #update(Graphics)
1825:   * @see #repaint(long, int, int, int, int)
1826:   */
1827:  public void repaint()
1828:	    {
1829:    repaint(0, 0, 0, width, height);
1830:  }
1831:
1832:  /**
1833:   * Repaint this entire component. The <code>update()</code> method on this
1834:   * component will be called in approximate the specified number of
1835:   * milliseconds.
1836:   *
1837:   * @param tm milliseconds before this component should be repainted
1838:   * @see #paint(Graphics)
1839:   * @see #repaint(long, int, int, int, int)
1840:   */
1841:  public void repaint(long tm)
1842:	    {
1843:    repaint(tm, 0, 0, width, height);
1844:  }
1845:
1846:  /**
1847:   * Repaints the specified rectangular region within this component. The
1848:   * <code>update</code> method on this component will be called as soon as
1849:   * possible. The coordinates are relative to this component.
1850:   *
1851:   * @param x the X coordinate of the upper left of the region to repaint
1852:   * @param y the Y coordinate of the upper left of the region to repaint
1853:   * @param w the width of the region to repaint
1854:   * @param h the height of the region to repaint
1855:   * @see #update(Graphics)
1856:   * @see #repaint(long, int, int, int, int)
1857:   */
1858:  public void repaint(int x, int y, int w, int h)
1859:	    {
1860:    repaint(0, x, y, w, h);
1861:  }
1862:
1863:  /**
1864:   * Repaints the specified rectangular region within this component. The
1865:   * <code>update</code> method on this component will be called in
1866:   * approximately the specified number of milliseconds. The coordinates
1867:   * are relative to this component.
1868:   *
1869:   * @param tm milliseconds before this component should be repainted
1870:   * @param x the X coordinate of the upper left of the region to repaint
1871:   * @param y the Y coordinate of the upper left of the region to repaint
1872:   * @param w the width of the region to repaint
1873:   * @param h the height of the region to repaint
1874:   * @see #update(Graphics)
1875:   */
1876:  public void repaint(long tm, int x, int y, int width, int height)
1877:	    {
1878:    // Handle lightweight repainting by forwarding to native parent
1879:    if (isLightweight() && parent != null)
1880:	        {
1881:        if (parent != null)
1882:          parent.repaint(tm, x + getX(), y + getY(), width, height);
1883:      }
1884:    else if (peer != null)
1885:      peer.repaint(tm, x, y, width, height);
1886:  }
1887:
1888:  /**
1889:   * Prints this component. This method is provided so that printing can be
1890:   * done in a different manner from painting. However, the implementation
1891:   * in this class simply calls the <code>paint()</code> method.
1892:   *
1893:   * @param graphics the graphics context of the print device
1894:   * @see #paint(Graphics)
1895:   */
1896:  public void print(Graphics g)
1897:	    {
1898:    paint(g);
1899:  }
1900:
1901:  /**
1902:   * Prints this component, including all sub-components. This method is
1903:   * provided so that printing can be done in a different manner from
1904:   * painting. However, the implementation in this class simply calls the
1905:   * <code>paintAll()</code> method.
1906:   *
1907:   * @param graphics the graphics context of the print device
1908:   * @see #paintAll(Graphics)
1909:   */
1910:  public void printAll(Graphics g)
1911:	    {
1912:    paintAll(g);
1913:  }
1914:
1915:  /**
1916:   * Called when an image has changed so that this component is repainted.
1917:   * This incrementally draws an image as more bits are available, when
1918:   * possible. Incremental drawing is enabled if the system property
1919:   * <code>awt.image.incrementalDraw</code> is not present or is true, in which
1920:   * case the redraw rate is set to 100ms or the value of the system property
1921:   * <code>awt.image.redrawrate</code>.
1922:   *
1923:   * <p>The coordinate system used depends on the particular flags.
1924:   *
1925:   * @param image the image that has been updated
1926:   * @param flags tlags as specified in <code>ImageObserver</code>
1927:   * @param x the X coordinate
1928:   * @param y the Y coordinate
1929:   * @param w the width
1930:   * @param h the height
1931:   * @return false if the image is completely loaded, loading has been
1932:   * aborted, or an error has occurred.  true if more updates are
1933:   * required.
1934:   * @see ImageObserver
1935:   * @see Graphics#drawImage(Image, int, int, Color, ImageObserver)
1936:   * @see Graphics#drawImage(Image, int, int, ImageObserver)
1937:   * @see Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver)
1938:   * @see Graphics#drawImage(Image, int, int, int, int, ImageObserver)
1939:   * @see ImageObserver#update(Image, int, int, int, int, int)
1940:   */
1941:  public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
1942:	    {
1943:    if ((flags & (FRAMEBITS | ALLBITS)) != 0)
1944:      repaint ();
1945:    else if ((flags & SOMEBITS) != 0)
1946:	        {
1947:        if (incrementalDraw)
1948:	            {
1949:            if (redrawRate != null)
1950:	                {
1951:                long tm = redrawRate.longValue();
1952:                if (tm < 0)
1953:                  tm = 0;
1954:                repaint (tm);
1955:              }
1956:            else
1957:              repaint (100);
1958:          }
1959:      }
1960:    return (flags & (ALLBITS | ABORT | ERROR)) == 0;
1961:  }
1962:
1963:  /**
1964:   * Creates an image from the specified producer.
1965:   *
1966:   * @param producer the image procedure to create the image from
1967:   * @return the resulting image
1968:   */
1969:  public Image createImage(ImageProducer producer)
1970:	    {
1971:    // Sun allows producer to be null.
1972:    if (peer != null)
1973:      return peer.createImage(producer);
1974:    else
1975:      return getToolkit().createImage(producer);
1976:  }
1977:
1978:  /**
1979:   * Creates an image with the specified width and height for use in
1980:   * double buffering. Headless environments do not support images.
1981:   *
1982:   * @param width the width of the image
1983:   * @param height the height of the image
1984:   * @return the requested image, or null if it is not supported
1985:   */
1986:  public Image createImage(int width, int height)
1987:	    {
1988:    Image returnValue = null;
1989:    if (!GraphicsEnvironment.isHeadless ())
1990:	        {
1991:        if (isLightweight () && parent != null)
1992:          returnValue = parent.createImage (width, height);
1993:        else if (peer != null)
1994:          returnValue = peer.createImage (width, height);
1995:      }
1996:    return returnValue;
1997:  }
1998:
1999:  /**
2000:   * Creates an image with the specified width and height for use in
2001:   * double buffering. Headless environments do not support images.
2002:   *
2003:   * @param width the width of the image
2004:   * @param height the height of the image
2005:   * @return the requested image, or null if it is not supported
2006:   * @since 1.4
2007:   */
2008:  public VolatileImage createVolatileImage(int width, int height)
2009:	    {
2010:    if (GraphicsEnvironment.isHeadless())
2011:      return null;
2012:    GraphicsConfiguration config = getGraphicsConfiguration();
2013:    return config == null ? null
2014:      : config.createCompatibleVolatileImage(width, height);
2015:  }
2016:
2017:  /**
2018:   * Creates an image with the specified width and height for use in
2019:   * double buffering. Headless environments do not support images. The image
2020:   * will support the specified capabilities.
2021:   *
2022:   * @param width the width of the image
2023:   * @param height the height of the image
2024:   * @param caps the requested capabilities
2025:   * @return the requested image, or null if it is not supported
2026:   * @throws AWTException if a buffer with the capabilities cannot be created
2027:   * @since 1.4
2028:   */
2029:  public VolatileImage createVolatileImage(int width, int height,
2030:                                           ImageCapabilities caps)
2031:    throws AWTException
2032:	    {
2033:    if (GraphicsEnvironment.isHeadless())
2034:      return null;
2035:    GraphicsConfiguration config = getGraphicsConfiguration();
2036:    return config == null ? null
2037:      : config.createCompatibleVolatileImage(width, height, caps);
2038:  }
2039:
2040:  /**
2041:   * Prepares the specified image for rendering on this component.
2042:   *
2043:   * @param image the image to prepare for rendering
2044:   * @param observer the observer to notify of image preparation status
2045:   * @return true if the image is already fully prepared
2046:   * @throws NullPointerException if image is null
2047:   */
2048:  public boolean prepareImage(Image image, ImageObserver observer)
2049:	    {
2050:    return prepareImage(image, image.getWidth(observer),
2051:                        image.getHeight(observer), observer);
2052:  }
2053:
2054:  /**
2055:   * Prepares the specified image for rendering on this component at the
2056:   * specified scaled width and height
2057:   *
2058:   * @param image the image to prepare for rendering
2059:   * @param width the scaled width of the image
2060:   * @param height the scaled height of the image
2061:   * @param observer the observer to notify of image preparation status
2062:   * @return true if the image is already fully prepared
2063:   */
2064:  public boolean prepareImage(Image image, int width, int height,
2065:                              ImageObserver observer)
2066:	    {
2067:    if (peer != null)
2068:        return peer.prepareImage(image, width, height, observer);
2069:    else
2070:        return getToolkit().prepareImage(image, width, height, observer);
2071:  }
2072:
2073:  /**
2074:   * Returns the status of the loading of the specified image. The value
2075:   * returned will be those flags defined in <code>ImageObserver</code>.
2076:   *
2077:   * @param image the image to check on
2078:   * @param observer the observer to notify of image loading progress
2079:   * @return the image observer flags indicating the status of the load
2080:   * @see #prepareImage(Image, int, int, ImageObserver)
2081:   * @see #Toolkit#checkImage(Image, int, int, ImageObserver)
2082:   * @throws NullPointerException if image is null
2083:   */
2084:  public int checkImage(Image image, ImageObserver observer)
2085:	    {
2086:    return checkImage(image, -1, -1, observer);
2087:  }
2088:
2089:  /**
2090:   * Returns the status of the loading of the specified image. The value
2091:   * returned will be those flags defined in <code>ImageObserver</code>.
2092:   *
2093:   * @param image the image to check on
2094:   * @param width the scaled image width
2095:   * @param height the scaled image height
2096:   * @param observer the observer to notify of image loading progress
2097:   * @return the image observer flags indicating the status of the load
2098:   * @see #prepareImage(Image, int, int, ImageObserver)
2099:   * @see #Toolkit#checkImage(Image, int, int, ImageObserver)
2100:   */
2101:  public int checkImage(Image image, int width, int height,
2102:                        ImageObserver observer)
2103:	    {
2104:    if (peer != null)
2105:      return peer.checkImage(image, width, height, observer);
2106:    return getToolkit().checkImage(image, width, height, observer);
2107:  }
2108:
2109:  /**
2110:   * Sets whether paint messages delivered by the operating system should be
2111:   * ignored. This does not affect messages from AWT, except for those
2112:   * triggered by OS messages. Setting this to true can allow faster
2113:   * performance in full-screen mode or page-flipping.
2114:   *
2115:   * @param ignoreRepaint the new setting for ignoring repaint events
2116:   * @see #getIgnoreRepaint()
2117:   * @see BufferStrategy
2118:   * @see GraphicsDevice.setFullScreenWindow(Window)
2119:   * @since 1.4
2120:   */
2121:  public void setIgnoreRepaint(boolean ignoreRepaint)
2122:	    {
2123:    this.ignoreRepaint = ignoreRepaint;
2124:  }
2125:
2126:  /**
2127:   * Test whether paint events from the operating system are ignored.
2128:   *
2129:   * @return the status of ignoring paint events
2130:   * @see #setIgnoreRepaint(boolean)
2131:   * @since 1.4
2132:   */
2133:  public boolean getIgnoreRepaint()
2134:	    {
2135:    return ignoreRepaint;
2136:  }
2137:
2138:  /**
2139:   * Tests whether or not the specified point is contained within this
2140:   * component. Coordinates are relative to this component.
2141:   *
2142:   * @param x the X coordinate of the point to test
2143:   * @param y the Y coordinate of the point to test
2144:   * @return true if the point is within this component
2145:   * @see #getComponentAt(int, int)
2146:   */
2147:  public boolean contains(int x, int y)
2148:	    {
2149:    return inside (x, y);
2150:  }
2151:
2152:  /**
2153:   * Tests whether or not the specified point is contained within this
2154:   * component. Coordinates are relative to this component.
2155:   *
2156:   * @param x the X coordinate of the point to test
2157:   * @param y the Y coordinate of the point to test
2158:   * @return true if the point is within this component
2159:   * @deprecated use {@link #contains(int, int)} instead
2160:   */
2161:  public boolean inside(int x, int y)
2162:	    {
2163:    return x >= 0 && y >= 0 && x < width && y < height;
2164:  }
2165:
2166:  /**
2167:   * Tests whether or not the specified point is contained within this
2168:   * component. Coordinates are relative to this component.
2169:   *
2170:   * @param p the point to test
2171:   * @return true if the point is within this component
2172:   * @throws NullPointerException if p is null
2173:   * @see #getComponentAt(Point)
2174:   * @since 1.1
2175:   */
2176:  public boolean contains(Point p)
2177:	    {
2178:    return contains (p.x, p.y);
2179:  }
2180:
2181:  /**
2182:   * Returns the component occupying the position (x,y). This will either
2183:   * be this component, an immediate child component, or <code>null</code>
2184:   * if neither of the first two occupies the specified location.
2185:   *
2186:   * @param x the X coordinate to search for components at
2187:   * @param y the Y coordinate to search for components at
2188:   * @return the component at the specified location, or null
2189:   * @see #contains(int, int)
2190:   */
2191:  public Component getComponentAt(int x, int y)
2192:	    {
2193:    return locate (x, y);
2194:  }
2195:
2196:  /**
2197:   * Returns the component occupying the position (x,y). This will either
2198:   * be this component, an immediate child component, or <code>null</code>
2199:   * if neither of the first two occupies the specified location.
2200:   *
2201:   * @param x the X coordinate to search for components at
2202:   * @param y the Y coordinate to search for components at
2203:   * @return the component at the specified location, or null
2204:   * @deprecated use {@link #getComponentAt(int, int)} instead
2205:   */
2206:  public Component locate(int x, int y)
2207:	    {
2208:    return contains (x, y) ? this : null;
2209:  }
2210:
2211:  /**
2212:   * Returns the component occupying the position (x,y). This will either
2213:   * be this component, an immediate child component, or <code>null</code>
2214:   * if neither of the first two occupies the specified location.
2215:   *
2216:   * @param p the point to search for components at
2217:   * @return the component at the specified location, or null
2218:   * @throws NullPointerException if p is null
2219:   * @see #contains(Point)
2220:   * @since 1.1
2221:   */
2222:  public Component getComponentAt(Point p)
2223:	    {
2224:    return getComponentAt (p.x, p.y);
2225:  }
2226:
2227:  /**
2228:   * AWT 1.0 event delivery.
2229:   *
2230:   * Deliver an AWT 1.0 event to this Component.  This method simply
2231:   * calls {@link #postEvent}.
2232:   *
2233:   * @param e the event to deliver
2234:   * @deprecated use {@link #dispatchEvent (AWTEvent)} instead
2235:   */
2236:  public void deliverEvent(Event e)
2237:	    {
2238:    postEvent (e);
2239:  }
2240:
2241:  /**
2242:   * Forwards AWT events to processEvent() if:<ul>
2243:   * <li>Events have been enabled for this type of event via
2244:   * <code>enableEvents()</code></li>,
2245:   * <li>There is at least one registered listener for this type of event</li>
2246:   * </ul>
2247:   *
2248:   * @param e the event to dispatch
2249:   */
2250:  public final void dispatchEvent(AWTEvent e)
2251:	    {
2252:    // Some subclasses in the AWT package need to override this behavior,
2253:    // hence the use of dispatchEventImpl().
2254:    dispatchEventImpl(e);
2255:    if (peer != null && ! e.consumed)
2256:      peer.handleEvent(e);
2257:  }
2258:
2259:  /**
2260:   * AWT 1.0 event handler.
2261:   *
2262:   * This method simply calls handleEvent and returns the result.
2263:   *
2264:   * @param e the event to handle
2265:   * @return true if the event was handled, false otherwise
2266:   * @deprecated use {@link #dispatchEvent(AWTEvent)} instead
2267:   */
2268:  public boolean postEvent(Event e)
2269:	    {
2270:    boolean handled = handleEvent (e);
2271:
2272:    if (!handled && getParent() != null)
2273:      // FIXME: need to translate event coordinates to parent's
2274:      // coordinate space.
2275:      handled = getParent ().postEvent (e);
2276:
2277:    return handled;
2278:  }
2279:
2280:  /**
2281:   * Adds the specified listener to this component. This is harmless if the
2282:   * listener is null, but if the listener has already been registered, it
2283:   * will now be registered twice.
2284:   *
2285:   * @param listener the new listener to add
2286:   * @see ComponentEvent
2287:   * @see #removeComponentListener(ComponentListener)
2288:   * @see #getComponentListeners()
2289:   * @since 1.1
2290:   */
2291:  public synchronized void addComponentListener(ComponentListener l)
2292:	    {
2293:    componentListener = AWTEventMulticaster.add(componentListener, l);
2294:    if (componentListener != null)
2295:      enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
2296:  }
2297:
2298:  /**
2299:   * Removes the specified listener from the component. This is harmless if
2300:   * the listener was not previously registered.
2301:   *
2302:   * @param listener the listener to remove
2303:   * @see ComponentEvent
2304:   * @see #addComponentListener(ComponentListener)
2305:   * @see #getComponentListeners()
2306:   * @since 1.1
2307:   */
2308:  public synchronized void removeComponentListener(ComponentListener l)
2309:	    {
2310:    componentListener = AWTEventMulticaster.remove(componentListener, l);
2311:  }
2312:
2313:  /**
2314:   * Returns an array of all specified listeners registered on this component.
2315:   *
2316:   * @return an array of listeners
2317:   * @see #addComponentListener(ComponentListener)
2318:   * @see #removeComponentListener(ComponentListener)
2319:   * @since 1.4
2320:   */
2321:  public synchronized ComponentListener[] getComponentListeners()
2322:	    {
2323:    return (ComponentListener[])
2324:      AWTEventMulticaster.getListeners(componentListener,
2325:                                       ComponentListener.class);
2326:  }
2327:
2328:  /**
2329:   * Adds the specified listener to this component. This is harmless if the
2330:   * listener is null, but if the listener has already been registered, it
2331:   * will now be registered twice.
2332:   *
2333:   * @param listener the new listener to add
2334:   * @see FocusEvent
2335:   * @see #removeFocusListener(FocusListener)
2336:   * @see #getFocusListeners()
2337:   * @since 1.1
2338:   */
2339:  public synchronized void addFocusListener(FocusListener l)
2340:	    {
2341:    focusListener = AWTEventMulticaster.add(focusListener, l);
2342:    if (focusListener != null)
2343:      enableEvents(AWTEvent.FOCUS_EVENT_MASK);
2344:  }
2345:
2346:  /**
2347:   * Removes the specified listener from the component. This is harmless if
2348:   * the listener was not previously registered.
2349:   *
2350:   * @param listener the listener to remove
2351:   * @see FocusEvent
2352:   * @see #addFocusListener(FocusListener)
2353:   * @see #getFocusListeners()
2354:   * @since 1.1
2355:   */
2356:  public synchronized void removeFocusListener(FocusListener l)
2357:	    {
2358:    focusListener = AWTEventMulticaster.remove(focusListener, l);
2359:  }
2360:
2361:  /**
2362:   * Returns an array of all specified listeners registered on this component.
2363:   *
2364:   * @return an array of listeners
2365:   * @see #addFocusListener(FocusListener)
2366:   * @see #removeFocusListener(FocusListener)
2367:   * @since 1.4
2368:   */
2369:  public synchronized FocusListener[] getFocusListeners()
2370:	    {
2371:    return (FocusListener[])
2372:      AWTEventMulticaster.getListeners(focusListener, FocusListener.class);
2373:  }
2374:
2375:  /**
2376:   * Adds the specified listener to this component. This is harmless if the
2377:   * listener is null, but if the listener has already been registered, it
2378:   * will now be registered twice.
2379:   *
2380:   * @param listener the new listener to add
2381:   * @see HierarchyEvent
2382:   * @see #removeHierarchyListener(HierarchyListener)
2383:   * @see #getHierarchyListeners()
2384:   * @since 1.3
2385:   */
2386:  public synchronized void addHierarchyListener(HierarchyListener l)
2387:	    {
2388:    hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
2389:    if (hierarchyListener != null)
2390:      enableEvents(AWTEvent.HIERARCHY_EVENT_MASK);
2391:  }
2392:
2393:  /**
2394:   * Removes the specified listener from the component. This is harmless if
2395:   * the listener was not previously registered.
2396:   *
2397:   * @param listener the listener to remove
2398:   * @see HierarchyEvent
2399:   * @see #addHierarchyListener(HierarchyListener)
2400:   * @see #getHierarchyListeners()
2401:   * @since 1.3
2402:   */
2403:  public synchronized void removeHierarchyListener(HierarchyListener l)
2404:	    {
2405:    hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, l);
2406:  }
2407:
2408:  /**
2409:   * Returns an array of all specified listeners registered on this component.
2410:   *
2411:   * @return an array of listeners
2412:   * @see #addHierarchyListener(HierarchyListener)
2413:   * @see #removeHierarchyListener(HierarchyListener)
2414:   * @since 1.4
2415:   */
2416:  public synchronized HierarchyListener[] getHierarchyListeners()
2417:	    {
2418:    return (HierarchyListener[])
2419:      AWTEventMulticaster.getListeners(hierarchyListener,
2420:                                       HierarchyListener.class);
2421:  }
2422:
2423:  /**
2424:   * Adds the specified listener to this component. This is harmless if the
2425:   * listener is null, but if the listener has already been registered, it
2426:   * will now be registered twice.
2427:   *
2428:   * @param listener the new listener to add
2429:   * @see HierarchyEvent
2430:   * @see #removeHierarchyBoundsListener(HierarchyBoundsListener)
2431:   * @see #getHierarchyBoundsListeners()
2432:   * @since 1.3
2433:   */
2434:  public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener l)
2435:	    {
2436:    hierarchyBoundsListener =
2437:      AWTEventMulticaster.add(hierarchyBoundsListener, l);
2438:    if (hierarchyBoundsListener != null)
2439:      enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
2440:  }
2441:
2442:  /**
2443:   * Removes the specified listener from the component. This is harmless if
2444:   * the listener was not previously registered.
2445:   *
2446:   * @param listener the listener to remove
2447:   * @see HierarchyEvent
2448:   * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
2449:   * @see #getHierarchyBoundsListeners()
2450:   * @since 1.3
2451:   */
2452:  public synchronized void removeHierarchyBoundsListener(HierarchyBoundsListener l)
2453:	    {
2454:    hierarchyBoundsListener =
2455:      AWTEventMulticaster.remove(hierarchyBoundsListener, l);
2456:  }
2457:
2458:  /**
2459:   * Returns an array of all specified listeners registered on this component.
2460:   *
2461:   * @return an array of listeners
2462:   * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
2463:   * @see #removeHierarchyBoundsListener(HierarchyBoundsListener)
2464:   * @since 1.4
2465:   */
2466:  public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners()
2467:	    {
2468:    return (HierarchyBoundsListener[])
2469:      AWTEventMulticaster.getListeners(hierarchyBoundsListener,
2470:                                       HierarchyBoundsListener.class);
2471:  }
2472:
2473:  /**
2474:   * Adds the specified listener to this component. This is harmless if the
2475:   * listener is null, but if the listener has already been registered, it
2476:   * will now be registered twice.
2477:   *
2478:   * @param listener the new listener to add
2479:   * @see KeyEvent
2480:   * @see #removeKeyListener(KeyListener)
2481:   * @see #getKeyListeners()
2482:   * @since 1.1
2483:   */
2484:  public synchronized void addKeyListener(KeyListener l)
2485:	    {
2486:    keyListener = AWTEventMulticaster.add(keyListener, l);
2487:    if (keyListener != null)
2488:      enableEvents(AWTEvent.KEY_EVENT_MASK);
2489:  }
2490:
2491:  /**
2492:   * Removes the specified listener from the component. This is harmless if
2493:   * the listener was not previously registered.
2494:   *
2495:   * @param listener the listener to remove
2496:   * @see KeyEvent
2497:   * @see #addKeyListener(KeyListener)
2498:   * @see #getKeyListeners()
2499:   * @since 1.1
2500:   */
2501:  public synchronized void removeKeyListener(KeyListener l)
2502:	    {
2503:    keyListener = AWTEventMulticaster.remove(keyListener, l);
2504:  }
2505:
2506:  /**
2507:   * Returns an array of all specified listeners registered on this component.
2508:   *
2509:   * @return an array of listeners
2510:   * @see #addKeyListener(KeyListener)
2511:   * @see #removeKeyListener(KeyListener)
2512:   * @since 1.4
2513:   */
2514:  public synchronized KeyListener[] getKeyListeners()
2515:	    {
2516:    return (KeyListener[])
2517:      AWTEventMulticaster.getListeners(keyListener, KeyListener.class);
2518:  }
2519:
2520:  /**
2521:   * Adds the specified listener to this component. This is harmless if the
2522:   * listener is null, but if the listener has already been registered, it
2523:   * will now be registered twice.
2524:   *
2525:   * @param listener the new listener to add
2526:   * @see MouseEvent
2527:   * @see #removeMouseListener(MouseListener)
2528:   * @see #getMouseListeners()
2529:   * @since 1.1
2530:   */
2531:  public synchronized void addMouseListener(MouseListener l)
2532:	    {
2533:    mouseListener = AWTEventMulticaster.add(mouseListener, l);
2534:    if (mouseListener != null)
2535:      enableEvents(AWTEvent.MOUSE_EVENT_MASK);
2536:  }
2537:
2538:  /**
2539:   * Removes the specified listener from the component. This is harmless if
2540:   * the listener was not previously registered.
2541:   *
2542:   * @param listener the listener to remove
2543:   * @see MouseEvent
2544:   * @see #addMouseListener(MouseListener)
2545:   * @see #getMouseListeners()
2546:   * @since 1.1
2547:   */
2548:  public synchronized void removeMouseListener(MouseListener l)
2549:	    {
2550:    mouseListener = AWTEventMulticaster.remove(mouseListener, l);
2551:  }
2552:
2553:  /**
2554:   * Returns an array of all specified listeners registered on this component.
2555:   *
2556:   * @return an array of listeners
2557:   * @see #addMouseListener(MouseListener)
2558:   * @see #removeMouseListener(MouseListener)
2559:   * @since 1.4
2560:   */
2561:  public synchronized MouseListener[] getMouseListeners()
2562:	    {
2563:    return (MouseListener[])
2564:      AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
2565:  }
2566:
2567:  /**
2568:   * Adds the specified listener to this component. This is harmless if the
2569:   * listener is null, but if the listener has already been registered, it
2570:   * will now be registered twice.
2571:   *
2572:   * @param listener the new listener to add
2573:   * @see MouseEvent
2574:   * @see #removeMouseMotionListener(MouseMotionListener)
2575:   * @see #getMouseMotionListeners()
2576:   * @since 1.1
2577:   */
2578:  public synchronized void addMouseMotionListener(MouseMotionListener l)
2579:	    {
2580:    mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, l);
2581:    if (mouseMotionListener != null)
2582:      enableEvents(AWTEvent.MOUSE_EVENT_MASK);
2583:  }
2584:
2585:  /**
2586:   * Removes the specified listener from the component. This is harmless if
2587:   * the listener was not previously registered.
2588:   *
2589:   * @param listener the listener to remove
2590:   * @see MouseEvent
2591:   * @see #addMouseMotionListener(MouseMotionListener)
2592:   * @see #getMouseMotionListeners()
2593:   * @since 1.1
2594:   */
2595:  public synchronized void removeMouseMotionListener(MouseMotionListener l)
2596:	    {
2597:    mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
2598:  }
2599:
2600:  /**
2601:   * Returns an array of all specified listeners registered on this component.
2602:   *
2603:   * @return an array of listeners
2604:   * @see #addMouseMotionListener(MouseMotionListener)
2605:   * @see #removeMouseMotionListener(MouseMotionListener)
2606:   * @since 1.4
2607:   */
2608:  public synchronized MouseMotionListener[] getMouseMotionListeners()
2609:	    {
2610:    return (MouseMotionListener[])
2611:      AWTEventMulticaster.getListeners(mouseMotionListener,
2612:                                       MouseMotionListener.class);
2613:  }
2614:
2615:  /**
2616:   * Adds the specified listener to this component. This is harmless if the
2617:   * listener is null, but if the listener has already been registered, it
2618:   * will now be registered twice.
2619:   *
2620:   * @param listener the new listener to add
2621:   * @see MouseEvent
2622:   * @see MouseWheelEvent
2623:   * @see #removeMouseWheelListener(MouseWheelListener)
2624:   * @see #getMouseWheelListeners()
2625:   * @since 1.4
2626:   */
2627:  public synchronized void addMouseWheelListener(MouseWheelListener l)
2628:	    {
2629:    mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, l);
2630:    if (mouseWheelListener != null)
2631:      enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
2632:  }
2633:
2634:  /**
2635:   * Removes the specified listener from the component. This is harmless if
2636:   * the listener was not previously registered.
2637:   *
2638:   * @param listener the listener to remove
2639:   * @see MouseEvent
2640:   * @see MouseWheelEvent
2641:   * @see #addMouseWheelListener(MouseWheelListener)
2642:   * @see #getMouseWheelListeners()
2643:   * @since 1.4
2644:   */
2645:  public synchronized void removeMouseWheelListener(MouseWheelListener l)
2646:	    {
2647:    mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l);
2648:  }
2649:
2650:  /**
2651:   * Returns an array of all specified listeners registered on this component.
2652:   *
2653:   * @return an array of listeners
2654:   * @see #addMouseWheelListener(MouseWheelListener)
2655:   * @see #removeMouseWheelListener(MouseWheelListener)
2656:   * @since 1.4
2657:   */
2658:  public synchronized MouseWheelListener[] getMouseWheelListeners()
2659:	    {
2660:    return (MouseWheelListener[])
2661:      AWTEventMulticaster.getListeners(mouseWheelListener,
2662:                                       MouseWheelListener.class);
2663:  }
2664:
2665:  /**
2666:   * Adds the specified listener to this component. This is harmless if the
2667:   * listener is null, but if the listener has already been registered, it
2668:   * will now be registered twice.
2669:   *
2670:   * @param listener the new listener to add
2671:   * @see InputMethodEvent
2672:   * @see #removeInputMethodListener(InputMethodListener)
2673:   * @see #getInputMethodListeners()
2674:   * @see #getInputMethodRequests()
2675:   * @since 1.2
2676:   */
2677:  public synchronized void addInputMethodListener(InputMethodListener l)
2678:	    {
2679:    inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
2680:    if (inputMethodListener != null)
2681:      enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK);
2682:  }
2683:
2684:  /**
2685:   * Removes the specified listener from the component. This is harmless if
2686:   * the listener was not previously registered.
2687:   *
2688:   * @param listener the listener to remove
2689:   * @see InputMethodEvent
2690:   * @see #addInputMethodListener(InputMethodListener)
2691:   * @see #getInputMethodRequests()
2692:   * @since 1.2
2693:   */
2694:  public synchronized void removeInputMethodListener(InputMethodListener l)
2695:	    {
2696:    inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
2697:  }
2698:
2699:  /**
2700:   * Returns an array of all specified listeners registered on this component.
2701:   *
2702:   * @return an array of listeners
2703:   * @see #addInputMethodListener(InputMethodListener)
2704:   * @see #removeInputMethodListener(InputMethodListener)
2705:   * @since 1.4
2706:   */
2707:  public synchronized InputMethodListener[] getInputMethodListeners()
2708:	    {
2709:    return (InputMethodListener[])
2710:      AWTEventMulticaster.getListeners(inputMethodListener,
2711:                                       InputMethodListener.class);
2712:  }
2713:
2714:  /**
2715:   * Returns all registered EventListers of the given listenerType.
2716:   *
2717:   * @param listenerType the class of listeners to filter
2718:   * @return an array of registered listeners
2719:   * @see #getComponentListeners()
2720:   * @see #getFocusListeners()
2721:   * @see #getHierarchyListeners()
2722:   * @see #getHierarchyBoundsListeners()
2723:   * @see #getKeyListeners()
2724:   * @see #getMouseListeners()
2725:   * @see #getMouseMotionListeners()
2726:   * @see #getMouseWheelListeners()
2727:   * @see #getInputMethodListeners()
2728:   * @see #getPropertyChangeListeners()
2729:   * @since 1.3
2730:   */
2731:  public EventListener[] getListeners(Class listenerType)
2732:	    {
2733:    if (listenerType == ComponentListener.class)
2734:      return getComponentListeners();
2735:    if (listenerType == FocusListener.class)
2736:      return getFocusListeners();
2737:    if (listenerType == HierarchyListener.class)
2738:      return getHierarchyListeners();
2739:    if (listenerType == HierarchyBoundsListener.class)
2740:      return getHierarchyBoundsListeners();
2741:    if (listenerType == KeyListener.class)
2742:      return getKeyListeners();
2743:    if (listenerType == MouseListener.class)
2744:      return getMouseListeners();
2745:    if (listenerType == MouseMotionListener.class)
2746:      return getMouseMotionListeners();
2747:    if (listenerType == MouseWheelListener.class)
2748:      return getMouseWheelListeners();
2749:    if (listenerType == InputMethodListener.class)
2750:      return getInputMethodListeners();
2751:    if (listenerType == PropertyChangeListener.class)
2752:      return getPropertyChangeListeners();
2753:    return (EventListener[]) Array.newInstance(listenerType, 0);
2754:  }
2755:
2756:  /**
2757:   * Returns the input method request handler, for subclasses which support
2758:   * on-the-spot text input. By default, input methods are handled by AWT,
2759:   * and this returns null.
2760:   *
2761:   * @return the input method handler, null by default
2762:   * @since 1.2
2763:   */
2764:  public InputMethodRequests getInputMethodRequests()
2765:	    {
2766:    return null;
2767:  }
2768:
2769:  /**
2770:   * Gets the input context of this component, which is inherited from the
2771:   * parent unless this is overridden.
2772:   *
2773:   * @return the text input context
2774:   * @since 1.2
2775:   */
2776:  public InputContext getInputContext()
2777:	    {
2778:    return parent == null ? null : parent.getInputContext();
2779:  }
2780:
2781:  /**
2782:   * Enables the specified events. The events to enable are specified
2783:   * by OR-ing together the desired masks from <code>AWTEvent</code>.
2784:   *
2785:   * <p>Events are enabled by default when a listener is attached to the
2786:   * component for that event type. This method can be used by subclasses
2787:   * to ensure the delivery of a specified event regardless of whether
2788:   * or not a listener is attached.
2789:   *
2790:   * @param eventsToEnable the desired events to enable
2791:   * @see #processEvent(AWTEvent)
2792:   * @see #disableEvents(long)
2793:   * @see AWTEvent
2794:   * @since 1.1
2795:   */
2796:  protected final void enableEvents(long eventsToEnable)
2797:	    {
2798:    eventMask |= eventsToEnable;
2799:    // TODO: Unlike Sun's implementation, I think we should try and
2800:    // enable/disable events at the peer (gtk/X) level. This will avoid
2801:    // clogging the event pipeline with useless mousemove events that
2802:    // we arn't interested in, etc. This will involve extending the peer
2803:    // interface, but thats okay because the peer interfaces have been
2804:    // deprecated for a long time, and no longer feature in the
2805:    // API specification at all.
2806:    if (isLightweight() && parent != null)
2807:      parent.enableEvents(eventsToEnable);
2808:    else if (peer != null)
2809:      peer.setEventMask(eventMask);
2810:  }
2811:
2812:  /**
2813:   * Disables the specified events. The events to disable are specified
2814:   * by OR-ing together the desired masks from <code>AWTEvent</code>.
2815:   *
2816:   * @param eventsToDisable the desired events to disable
2817:   * @see #enableEvents(long)
2818:   * @since 1.1
2819:   */
2820:  protected final void disableEvents(long eventsToDisable)
2821:	    {
2822:    eventMask &= ~eventsToDisable;
2823:    // forward new event mask to peer?
2824:  }
2825:
2826:  /**
2827:   * This is called by the EventQueue if two events with the same event id
2828:   * and owner component are queued. Returns a new combined event, or null if
2829:   * no combining is done. The coelesced events are currently mouse moves
2830:   * (intermediate ones are discarded) and paint events (a merged paint is
2831:   * created in place of the two events).
2832:   *
2833:   * @param existingEvent the event on the queue
2834:   * @param newEvent the new event that might be entered on the queue
2835:   * @return null if both events are kept, or the replacement coelesced event
2836:   */
2837:  protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
2838:	    {
2839:    switch (existingEvent.id)
2840:	        {
2841:      case MouseEvent.MOUSE_MOVED:
2842:      case MouseEvent.MOUSE_DRAGGED:
2843:        // Just drop the old (intermediate) event and return the new one.
2844:        return newEvent;
2845:      case PaintEvent.PAINT:
2846:      case PaintEvent.UPDATE:
2847:        return coalescePaintEvents((PaintEvent) existingEvent,
2848:                                   (PaintEvent) newEvent);
2849:      default:
2850:        return null;
2851:      }
2852:  }
2853:
2854:  /**
2855:   * Processes the specified event. In this class, this method simply
2856:   * calls one of the more specific event handlers.
2857:   *
2858:   * @param event the event to process
2859:   * @throws NullPointerException if e is null
2860:   * @see #processComponentEvent(ComponentEvent)
2861:   * @see #processFocusEvent(FocusEvent)
2862:   * @see #processKeyEvent(KeyEvent)
2863:   * @see #processMouseEvent(MouseEvent)
2864:   * @see #processMouseMotionEvent(MouseEvent)
2865:   * @see #processInputMethodEvent(InputMethodEvent)
2866:   * @see #processHierarchyEvent(HierarchyEvent)
2867:   * @see #processMouseWheelEvent(MouseWheelEvent)
2868:   * @since 1.1
2869:   */
2870:  protected void processEvent(AWTEvent e)
2871:	    {
2872:    /* Note: the order of these if statements are
2873:       important. Subclasses must be checked first. Eg. MouseEvent
2874:       must be checked before ComponentEvent, since a MouseEvent
2875:       object is also an instance of a ComponentEvent. */
2876:
2877:    if (e instanceof FocusEvent)
2878:      processFocusEvent((FocusEvent) e);
2879:    else if (e instanceof MouseWheelEvent)
2880:      processMouseWheelEvent((MouseWheelEvent) e);
2881:    else if (e instanceof MouseEvent)
2882:	        {
2883:        if (e.id == MouseEvent.MOUSE_MOVED
2884:            || e.id == MouseEvent.MOUSE_DRAGGED)
2885:          processMouseMotionEvent((MouseEvent) e);
2886:        else
2887:          processMouseEvent((MouseEvent) e);
2888:      }
2889:    else if (e instanceof KeyEvent)
2890:      processKeyEvent((KeyEvent) e);
2891:    else if (e instanceof InputMethodEvent)
2892:      processInputMethodEvent((InputMethodEvent) e);
2893:    else if (e instanceof ComponentEvent)
2894:      processComponentEvent((ComponentEvent) e);
2895:    else if (e instanceof HierarchyEvent)
2896:	        {
2897:        if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
2898:          processHierarchyEvent((HierarchyEvent) e);
2899:        else
2900:          processHierarchyBoundsEvent((HierarchyEvent) e);
2901:      }
2902:  }
2903:
2904:  /**
2905:   * Called when a component event is dispatched and component events are
2906:   * enabled. This method passes the event along to any listeners
2907:   * that are attached.
2908:   *
2909:   * @param event the <code>ComponentEvent</code> to process
2910:   * @throws NullPointerException if e is null
2911:   * @see ComponentListener
2912:   * @see #addComponentListener(ComponentListener)
2913:   * @see #enableEvents(long)
2914:   * @since 1.1
2915:   */
2916:  protected void processComponentEvent(ComponentEvent e)
2917:	    {
2918:    if (componentListener == null)
2919:      return;
2920:    switch (e.id)
2921:	        {
2922:      case ComponentEvent.COMPONENT_HIDDEN:
2923:        componentListener.componentHidden(e);
2924:        break;
2925:      case ComponentEvent.COMPONENT_MOVED:
2926:        componentListener.componentMoved(e);
2927:        break;
2928:      case ComponentEvent.COMPONENT_RESIZED:
2929:        componentListener.componentResized(e);
2930:        break;
2931:      case ComponentEvent.COMPONENT_SHOWN:
2932:        componentListener.componentShown(e);
2933:        break;
2934:      }
2935:  }
2936:
2937:  /**
2938:   * Called when a focus event is dispatched and component events are
2939:   * enabled. This method passes the event along to any listeners
2940:   * that are attached.
2941:   *
2942:   * @param event the <code>FocusEvent</code> to process
2943:   * @throws NullPointerException if e is null
2944:   * @see FocusListener
2945:   * @see #addFocusListener(FocusListener)
2946:   * @see #enableEvents(long)
2947:   * @since 1.1
2948:   */
2949:  protected void processFocusEvent(FocusEvent e)
2950:	    {
2951:    if (focusListener == null)
2952:      return;
2953:
2954:    switch (e.id)
2955:	        {
2956:        case FocusEvent.FOCUS_GAINED:
2957:          focusListener.focusGained(e);
2958:        break;
2959:        case FocusEvent.FOCUS_LOST:
2960:          focusListener.focusLost(e);
2961:        break;
2962:      }
2963:  }
2964:
2965:  /**
2966:   * Called when a key event is dispatched and component events are
2967:   * enabled. This method passes the event along to any listeners
2968:   * that are attached.
2969:   *
2970:   * @param event the <code>KeyEvent</code> to process
2971:   * @throws NullPointerException if e is null
2972:   * @see KeyListener
2973:   * @see #addKeyListener(KeyListener)
2974:   * @see #enableEvents(long)
2975:   * @since 1.1
2976:   */
2977:  protected void processKeyEvent(KeyEvent e)
2978:	    {
2979:    if (keyListener == null)
2980:      return;
2981:    switch (e.id)
2982:	        {
2983:        case KeyEvent.KEY_PRESSED:
2984:          keyListener.keyPressed(e);
2985:        break;
2986:        case KeyEvent.KEY_RELEASED:
2987:          keyListener.keyReleased(e);
2988:        break;
2989:        case KeyEvent.KEY_TYPED:
2990:          keyListener.keyTyped(e);
2991:        break;
2992:      }
2993:  }
2994:
2995:  /**
2996:   * Called when a regular mouse event is dispatched and component events are
2997:   * enabled. This method passes the event along to any listeners
2998:   * that are attached.
2999:   *
3000:   * @param event the <code>MouseEvent</code> to process
3001:   * @throws NullPointerException if e is null
3002:   * @see MouseListener
3003:   * @see #addMouseListener(MouseListener)
3004:   * @see #enableEvents(long)
3005:   * @since 1.1
3006:   */
3007:  protected void processMouseEvent(MouseEvent e)
3008:	    {
3009:    if (mouseListener == null)
3010:      return;
3011:    switch (e.id)
3012:	        {
3013:        case MouseEvent.MOUSE_CLICKED:
3014:          mouseListener.mouseClicked(e);
3015:        break;
3016:        case MouseEvent.MOUSE_ENTERED:
3017:          mouseListener.mouseEntered(e);
3018:        break;
3019:        case MouseEvent.MOUSE_EXITED:
3020:          mouseListener.mouseExited(e);
3021:        break;
3022:        case MouseEvent.MOUSE_PRESSED:
3023:          mouseListener.mousePressed(e);
3024:        break;
3025:        case MouseEvent.MOUSE_RELEASED:
3026:          mouseListener.mouseReleased(e);
3027:        break;
3028:      }
3029:      e.consume();
3030:  }
3031:
3032:  /**
3033:   * Called when a mouse motion event is dispatched and component events are
3034:   * enabled. This method passes the event along to any listeners
3035:   * that are attached.
3036:   *
3037:   * @param event the <code>MouseMotionEvent</code> to process
3038:   * @throws NullPointerException if e is null
3039:   * @see MouseMotionListener
3040:   * @see #addMouseMotionListener(MouseMotionListener)
3041:   * @see #enableEvents(long)
3042:   * @since 1.1
3043:   */
3044:  protected void processMouseMotionEvent(MouseEvent e)
3045:	    {
3046:    if (mouseMotionListener == null)
3047:      return;
3048:    switch (e.id)
3049:	        {
3050:        case MouseEvent.MOUSE_DRAGGED:
3051:          mouseMotionListener.mouseDragged(e);
3052:        break;
3053:        case MouseEvent.MOUSE_MOVED:
3054:          mouseMotionListener.mouseMoved(e);
3055:        break;
3056:      }
3057:      e.consume();
3058:  }
3059:
3060:  /**
3061:   * Called when a mouse wheel event is dispatched and component events are
3062:   * enabled. This method passes the event along to any listeners that are
3063:   * attached.
3064:   *
3065:   * @param event the <code>MouseWheelEvent</code> to process
3066:   * @throws NullPointerException if e is null
3067:   * @see MouseWheelListener
3068:   * @see #addMouseWheelListener(MouseWheelListener)
3069:   * @see #enableEvents(long)
3070:   * @since 1.4
3071:   */
3072:  protected void processMouseWheelEvent(MouseWheelEvent e)
3073:	    {
3074:    if (mouseWheelListener != null
3075:        && e.id == MouseEvent.MOUSE_WHEEL)
3076:	      {
3077:      mouseWheelListener.mouseWheelMoved(e);
3078:      e.consume();
3079:    }        
3080:  }
3081:
3082:  /**
3083:   * Called when an input method event is dispatched and component events are
3084:   * enabled. This method passes the event along to any listeners that are
3085:   * attached.
3086:   *
3087:   * @param event the <code>InputMethodEvent</code> to process
3088:   * @throws NullPointerException if e is null
3089:   * @see InputMethodListener
3090:   * @see #addInputMethodListener(InputMethodListener)
3091:   * @see #enableEvents(long)
3092:   * @since 1.2
3093:   */
3094:  protected void processInputMethodEvent(InputMethodEvent e)
3095:	    {
3096:    if (inputMethodListener == null)
3097:      return;
3098:    switch (e.id)
3099:	        {
3100:        case InputMethodEvent.CARET_POSITION_CHANGED:
3101:          inputMethodListener.caretPositionChanged(e);
3102:        break;
3103:        case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
3104:          inputMethodListener.inputMethodTextChanged(e);
3105:        break;
3106:      }
3107:  }
3108:
3109:  /**
3110:   * Called when a hierarchy change event is dispatched and component events
3111:   * are enabled. This method passes the event along to any listeners that are
3112:   * attached.
3113:   *
3114:   * @param event the <code>HierarchyEvent</code> to process
3115:   * @throws NullPointerException if e is null
3116:   * @see HierarchyListener
3117:   * @see #addHierarchyListener(HierarchyListener)
3118:   * @see #enableEvents(long)
3119:   * @since 1.3
3120:   */
3121:  protected void processHierarchyEvent(HierarchyEvent e)
3122:	    {
3123:    if (hierarchyListener == null)
3124:      return;
3125:    if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
3126:      hierarchyListener.hierarchyChanged(e);
3127:  }
3128:
3129:  /**
3130:   * Called when a hierarchy bounds event is dispatched and component events
3131:   * are enabled. This method passes the event along to any listeners that are
3132:   * attached.
3133:   *
3134:   * @param event the <code>HierarchyEvent</code> to process
3135:   * @throws NullPointerException if e is null
3136:   * @see HierarchyBoundsListener
3137:   * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
3138:   * @see #enableEvents(long)
3139:   * @since 1.3
3140:   */
3141:  protected void processHierarchyBoundsEvent(HierarchyEvent e)
3142:	    {
3143:    if (hierarchyBoundsListener == null)
3144:      return;
3145:    switch (e.id)
3146:	        {
3147:        case HierarchyEvent.ANCESTOR_MOVED:
3148:          hierarchyBoundsListener.ancestorMoved(e);
3149:        break;
3150:        case HierarchyEvent.ANCESTOR_RESIZED:
3151:          hierarchyBoundsListener.ancestorResized(e);
3152:        break;
3153:      }
3154:  }
3155:
3156:  /**
3157:   * AWT 1.0 event handler.
3158:   *
3159:   * This method calls one of the event-specific handler methods.  For
3160:	     * example for key events, either {@link #keyDown (Event evt, int
3161:   * key)} or {@link keyUp (Event evt, int key)} is called.  A derived
3162:   * component can override one of these event-specific methods if it
3163:   * only needs to handle certain event types.  Otherwise it can
3164:   * override handleEvent itself and handle any event.
3165:   *
3166:   * @param evt the event to handle
3167:   * @return true if the event was handled, false otherwise
3168:   * @deprecated use {@link #processEvent (AWTEvent)} instead
3169:   */
3170:  public boolean handleEvent(Event evt)
3171:	    {
3172:    switch (evt.id)
3173:	        {
3174:        // Handle key events.
3175:      case Event.KEY_ACTION:
3176:      case Event.KEY_PRESS:
3177:        return keyDown (evt, evt.key);
3178:      case Event.KEY_ACTION_RELEASE:
3179:      case Event.KEY_RELEASE:
3180:        return keyUp (evt, evt.key);
3181:
3182:        // Handle mouse events.
3183:      case Event.MOUSE_DOWN:
3184:        return mouseDown (evt, evt.x, evt.y);
3185:      case Event.MOUSE_UP:
3186:        return mouseUp (evt, evt.x, evt.y);
3187:      case Event.MOUSE_MOVE:
3188:        return mouseMove (evt, evt.x, evt.y);
3189:      case Event.MOUSE_DRAG:
3190:        return mouseDrag (evt, evt.x, evt.y);
3191:      case Event.MOUSE_ENTER:
3192:        return mouseEnter (evt, evt.x, evt.y);
3193:      case Event.MOUSE_EXIT:
3194:        return mouseExit (evt, evt.x, evt.y);
3195:
3196:        // Handle focus events.
3197:      case Event.GOT_FOCUS:
3198:        return gotFocus (evt, evt.arg);
3199:      case Event.LOST_FOCUS:
3200:        return lostFocus (evt, evt.arg);
3201:
3202:        // Handle action event.
3203:      case Event.ACTION_EVENT:
3204:        return action (evt, evt.arg);
3205:      }
3206:    // Unknown event.
3207:    return false;
3208:  }
3209:
3210:  /**
3211:   * AWT 1.0 MOUSE_DOWN event handler.  This method is meant to be
3212:   * overridden by components providing their own MOUSE_DOWN handler.
3213:   * The default implementation simply returns false.
3214:   *
3215:   * @param evt the event to handle
3216:   * @param x the x coordinate, ignored
3217:   * @param y the y coordinate, ignored
3218:   * @return false
3219:   * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
3220:   */
3221:  public boolean mouseDown(Event evt, int x, int y)
3222:	    {
3223:    return false;
3224:  }
3225:
3226:  /**
3227:   * AWT 1.0 MOUSE_DRAG event handler.  This method is meant to be
3228:   * overridden by components providing their own MOUSE_DRAG handler.
3229:   * The default implementation simply returns false.
3230:   *
3231:   * @param evt the event to handle
3232:   * @param x the x coordinate, ignored
3233:   * @param y the y coordinate, ignored
3234:   * @return false
3235:   * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead
3236:   */
3237:  public boolean mouseDrag(Event evt, int x, int y)
3238:	    {
3239:    return false;
3240:  }
3241:
3242:  /**
3243:   * AWT 1.0 MOUSE_UP event handler.  This method is meant to be
3244:   * overridden by components providing their own MOUSE_UP handler.
3245:   * The default implementation simply returns false.
3246:   *
3247:   * @param evt the event to handle
3248:   * @param x the x coordinate, ignored
3249:   * @param y the y coordinate, ignored
3250:   * @return false
3251:   * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
3252:   */
3253:  public boolean mouseUp(Event evt, int x, int y)
3254:	    {
3255:    return false;
3256:  }
3257:
3258:  /**
3259:   * AWT 1.0 MOUSE_MOVE event handler.  This method is meant to be
3260:   * overridden by components providing their own MOUSE_MOVE handler.
3261:   * The default implementation simply returns false.
3262:   *
3263:   * @param evt the event to handle
3264:   * @param x the x coordinate, ignored
3265:   * @param y the y coordinate, ignored
3266:   * @return false
3267:   * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead
3268:   */
3269:  public boolean mouseMove(Event evt, int x, int y)
3270:	    {
3271:    return false;
3272:  }
3273:
3274:  /**
3275:   * AWT 1.0 MOUSE_ENTER event handler.  This method is meant to be
3276:   * overridden by components providing their own MOUSE_ENTER handler.
3277:   * The default implementation simply returns false.
3278:   *
3279:   * @param evt the event to handle
3280:   * @param x the x coordinate, ignored
3281:   * @param y the y coordinate, ignored
3282:   * @return false
3283:   * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
3284:   */
3285:  public boolean mouseEnter(Event evt, int x, int y)
3286:	    {
3287:    return false;
3288:  }
3289:
3290:  /**
3291:   * AWT 1.0 MOUSE_EXIT event handler.  This method is meant to be
3292:   * overridden by components providing their own MOUSE_EXIT handler.
3293:   * The default implementation simply returns false.
3294:   *
3295:   * @param evt the event to handle
3296:   * @param x the x coordinate, ignored
3297:   * @param y the y coordinate, ignored
3298:   * @return false
3299:   * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
3300:   */
3301:  public boolean mouseExit(Event evt, int x, int y)
3302:	    {
3303:    return false;
3304:  }
3305:
3306:  /**
3307:   * AWT 1.0 KEY_PRESS and KEY_ACTION event handler.  This method is
3308:   * meant to be overridden by components providing their own key
3309:   * press handler.  The default implementation simply returns false.
3310:   *
3311:   * @param evt the event to handle
3312:   * @param key the key pressed, ignored
3313:   * @return false
3314:   * @deprecated use {@link #processKeyEvent(KeyEvent)} instead
3315:   */
3316:  public boolean keyDown(Event evt, int key)
3317:	    {
3318:    return false;
3319:  }
3320:
3321:  /**
3322:   * AWT 1.0 KEY_RELEASE and KEY_ACTION_RELEASE event handler.  This
3323:   * method is meant to be overridden by components providing their
3324:   * own key release handler.  The default implementation simply
3325:   * returns false.
3326:   *
3327:   * @param evt the event to handle
3328:   * @param key the key pressed, ignored
3329:   * @return false
3330:   * @deprecated use {@link #processKeyEvent(KeyEvent)} instead
3331:   */
3332:  public boolean keyUp(Event evt, int key)
3333:	    {
3334:    return false;
3335:  }
3336:
3337:  /**
3338:   * AWT 1.0 ACTION_EVENT event handler.  This method is meant to be
3339:   * overridden by components providing their own action event
3340:   * handler.  The default implementation simply returns false.
3341:   *
3342:   * @param evt the event to handle
3343:   * @param what the object acted on, ignored
3344:   * @return false
3345:   * @deprecated in classes which support actions, use
3346:   *             <code>processActionEvent(ActionEvent)</code> instead
3347:   */
3348:  public boolean action(Event evt, Object what)
3349:	    {
3350:    return false;
3351:  }
3352:
3353:  /**
3354:   * Called to inform this component it has been added to a container.
3355:   * A native peer - if any - is created at this time. This method is
3356:   * called automatically by the AWT system and should not be called by
3357:   * user level code.
3358:   *
3359:   * @see #isDisplayable()
3360:   * @see #removeNotify()
3361:   */
3362:  public void addNotify()
3363:	    {
3364:    if (peer == null)
3365:      peer = getToolkit().createComponent(this);
3366:    /* Now that all the children has gotten their peers, we should
3367:       have the event mask needed for this component and its
3368:       lightweight subcomponents. */
3369:    peer.setEventMask(eventMask);
3370:    /* We do not invalidate here, but rather leave that job up to
3371:       the peer. For efficiency, the peer can choose not to
3372:       invalidate if it is happy with the current dimensions,
3373:       etc. */
3374:  }
3375:
3376:  /**
3377:   * Called to inform this component is has been removed from its
3378:   * container. Its native peer - if any - is destroyed at this time.
3379:   * This method is called automatically by the AWT system and should
3380:   * not be called by user level code.
3381:   *
3382:   * @see #isDisplayable()
3383:   * @see #addNotify()
3384:   */
3385:  public void removeNotify()
3386:	    {
3387:    if (peer != null)
3388:      peer.dispose();
3389:    peer = null;
3390:  }
3391:
3392:  /**
3393:   * AWT 1.0 GOT_FOCUS event handler.  This method is meant to be
3394:   * overridden by components providing their own GOT_FOCUS handler.
3395:   * The default implementation simply returns false.
3396:   *
3397:   * @param evt the event to handle
3398:   * @param what the Object focused, ignored
3399:   * @return false
3400:   * @deprecated use {@link #processFocusEvent(FocusEvent)} instead
3401:   */
3402:  public boolean gotFocus(Event evt, Object what)
3403:	    {
3404:    return false;
3405:  }
3406:
3407:  /**
3408:   * AWT 1.0 LOST_FOCUS event handler.  This method is meant to be
3409:   * overridden by components providing their own LOST_FOCUS handler.
3410:   * The default implementation simply returns false.
3411:   *
3412:   * @param evt the event to handle
3413:   * @param what the Object focused, ignored
3414:   * @return false
3415:   * @deprecated use {@link #processFocusEvent(FocusEvent)} instead
3416:   */
3417:  public boolean lostFocus(Event evt, Object what)
3418:	    {
3419:    return false;
3420:  }
3421:
3422:  /**
3423:   * Tests whether or not this component is in the group that can be
3424:   * traversed using the keyboard traversal mechanism (such as the TAB key).
3425:   *
3426:   * @return true if the component is traversed via the TAB key
3427:   * @see #setFocusable(boolean)
3428:   * @since 1.1
3429:   * @deprecated use {@link #isFocusable()} instead
3430:   */
3431:  public boolean isFocusTraversable()
3432:	    {
3433:    return enabled && visible && (peer == null || isLightweight() || peer.isFocusTraversable());
3434:  }
3435:
3436:  /**
3437:   * Tests if this component can receive focus.
3438:   *
3439:   * @return true if this component can receive focus
3440:   * @since 1.4
3441:   */
3442:  public boolean isFocusable()
3443:	    {
3444:    return focusable;
3445:  }
3446:
3447:  /**
3448:   * Specify whether this component can receive focus. This method also
3449:   * sets the {@link #isFocusTraversableOverridden} field to 1, which
3450:	     * appears to be the undocumented way {@link
3451:   * DefaultFocusTraversalPolicy#accept()} determines whether to respect
3452:   * the {@link #isFocusable()} method of the component.
3453:   *
3454:   * @param focusable the new focusable status
3455:   * @since 1.4
3456:   */
3457:  public void setFocusable(boolean focusable)
3458:	    {
3459:    firePropertyChange("focusable", this.focusable, focusable);
3460:    this.focusable = focusable;
3461:    this.isFocusTraversableOverridden = 1;
3462:  }
3463:
3464:  /**
3465:   * Sets the focus traversal keys for one of the three focus
3466:	     * traversal directions supported by Components: {@link
3467:   * #KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}, {@link
3468:   * #KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}, or {@link
3469:   * #KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}. Normally, the
3470:   * default values should match the operating system's native
3471:   * choices. To disable a given traversal, use
3472:   * <code>Collections.EMPTY_SET</code>. The event dispatcher will
3473:   * consume PRESSED, RELEASED, and TYPED events for the specified
3474:   * key, although focus can only transfer on PRESSED or RELEASED.
3475:   *
3476:   * <p>The defaults are:
3477:   * <table>
3478:   *   <th><td>Identifier</td><td>Meaning</td><td>Default</td></th>
3479:   *   <tr><td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td>
3480:   *     <td>Normal forward traversal</td>
3481:   *     <td>TAB on KEY_PRESSED, Ctrl-TAB on KEY_PRESSED</td></tr>
3482:   *   <tr><td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td>
3483:   *     <td>Normal backward traversal</td>
3484:   *     <td>Shift-TAB on KEY_PRESSED, Ctrl-Shift-TAB on KEY_PRESSED</td></tr>
3485:   *   <tr><td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td>
3486:   *     <td>Go up a traversal cycle</td><td>None</td></tr>
3487:   * </table>
3488:   *
3489:   * If keystrokes is null, this component's focus traversal key set
3490:   * is inherited from one of its ancestors.  If none of its ancestors
3491:   * has its own set of focus traversal keys, the focus traversal keys
3492:   * are set to the defaults retrieved from the current
3493:   * KeyboardFocusManager.  If not null, the set must contain only
3494:   * AWTKeyStrokes that are not already focus keys and are not
3495:   * KEY_TYPED events.
3496:   *
3497:   * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or
3498:   *        UP_CYCLE_TRAVERSAL_KEYS
3499:   * @param keystrokes a set of keys, or null
3500:   * @throws IllegalArgumentException if id or keystrokes is invalid
3501:   * @see #getFocusTraversalKeys(int)
3502:   * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
3503:   * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
3504:   * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
3505:   * @since 1.4
3506:   */
3507:  public void setFocusTraversalKeys(int id, Set keystrokes)
3508:	    {
3509:    if (keystrokes == null)
3510:	        {
3511:        Container parent = getParent ();
3512:
3513:        while (parent != null)
3514:	            {
3515:            if (parent.areFocusTraversalKeysSet (id))
3516:	                {
3517:                keystrokes = parent.getFocusTraversalKeys (id);
3518:                break;
3519:              }
3520:            parent = parent.getParent ();
3521:          }
3522:
3523:        if (keystrokes == null)
3524:          keystrokes = KeyboardFocusManager.getCurrentKeyboardFocusManager ().
3525:            getDefaultFocusTraversalKeys (id);
3526:      }
3527:
3528:    Set sa;
3529:    Set sb;
3530:    String name;
3531:    switch (id)
3532:	        {
3533:      case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS:
3534:        sa = getFocusTraversalKeys
3535:          (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
3536:        sb = getFocusTraversalKeys
3537:          (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
3538:        name = "forwardFocusTraversalKeys";
3539:        break;
3540:      case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS:
3541:        sa = getFocusTraversalKeys
3542:          (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
3543:        sb = getFocusTraversalKeys
3544:          (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
3545:        name = "backwardFocusTraversalKeys";
3546:        break;
3547:      case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS:
3548:        sa = getFocusTraversalKeys
3549:          (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
3550:        sb = getFocusTraversalKeys
3551:          (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
3552:        name = "upCycleFocusTraversalKeys";
3553:        break;
3554:      default:
3555:        throw new ClasspathIllegalArgumentException ();
3556:      }
3557:
3558:    int i = keystrokes.size ();
3559:    Iterator iter = keystrokes.iterator ();
3560:
3561:    while (--i >= 0)
3562:	        {
3563:        Object o = iter.next ();
3564:        if (!(o instanceof AWTKeyStroke)
3565:            || sa.contains (o) || sb.contains (o)
3566:            || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED)
3567:          throw new ClasspathIllegalArgumentException ();
3568:      }
3569:
3570:    if (focusTraversalKeys == null)
3571:      focusTraversalKeys = new Set[3];
3572:
3573:    keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes));
3574:    firePropertyChange (name, focusTraversalKeys[id], keystrokes);
3575:
3576:    focusTraversalKeys[id] = keystrokes;
3577:  }
3578:
3579:  /**
3580:   * Returns the set of keys for a given focus traversal action, as
3581:   * defined in <code>setFocusTraversalKeys</code>.  If not set, this
3582:   * is inherited from the parent component, which may have gotten it
3583:   * from the KeyboardFocusManager.
3584:   *
3585:   * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
3586:   * or UP_CYCLE_TRAVERSAL_KEYS
3587:   * @throws IllegalArgumentException if id is invalid
3588:   * @see #setFocusTraversalKeys (int, Set)
3589:   * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
3590:   * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
3591:   * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
3592:   * @since 1.4
3593:   */
3594:  public Set getFocusTraversalKeys(int id)
3595:	    {
3596:    if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
3597:        id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
3598:        id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
3599:      throw new ClasspathIllegalArgumentException();
3600:
3601:    Set s = null;
3602:
3603:    if (focusTraversalKeys != null)
3604:      s = focusTraversalKeys[id];
3605:
3606:    if (s == null && parent != null)
3607:      s = parent.getFocusTraversalKeys (id);
3608:
3609:    return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager()
3610:                        .getDefaultFocusTraversalKeys(id)) : s;
3611:  }
3612:
3613:  /**
3614:   * Tests whether the focus traversal keys for a given action are explicitly
3615:   * set or inherited.
3616:   *
3617:   * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
3618:   * or UP_CYCLE_TRAVERSAL_KEYS
3619:   * @return true if that set is explicitly specified
3620:   * @throws IllegalArgumentException if id is invalid
3621:   * @see #getFocusTraversalKeys (int)
3622:   * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
3623:   * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
3624:   * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
3625:   * @since 1.4
3626:   */
3627:  public boolean areFocusTraversalKeysSet(int id)
3628:	    {
3629:    if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS &&
3630:        id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS &&
3631:        id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
3632:      throw new ClasspathIllegalArgumentException ();
3633:
3634:    return focusTraversalKeys != null && focusTraversalKeys[id] != null;
3635:  }
3636:
3637:  /**
3638:   * Enable or disable focus traversal keys on this Component.  If
3639:   * they are, then the keyboard focus manager consumes and acts on
3640:   * key press and release events that trigger focus traversal, and
3641:   * discards the corresponding key typed events.  If focus traversal
3642:   * keys are disabled, then all key events that would otherwise
3643:   * trigger focus traversal are sent to this Component.
3644:   *
3645:   * @param focusTraversalKeysEnabled the new value of the flag
3646:   * @see #getFocusTraversalKeysEnabled ()
3647:   * @see #setFocusTraversalKeys (int, Set)
3648:   * @see #getFocusTraversalKeys (int)
3649:   * @since 1.4
3650:   */
3651:  public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
3652:	    {
3653:    firePropertyChange ("focusTraversalKeysEnabled",
3654:                        this.focusTraversalKeysEnabled,
3655:                        focusTraversalKeysEnabled);
3656:    this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
3657:  }
3658:
3659:  /**
3660:   * Check whether or not focus traversal keys are enabled on this
3661:   * Component.  If they are, then the keyboard focus manager consumes
3662:   * and acts on key press and release events that trigger focus
3663:   * traversal, and discards the corresponding key typed events.  If
3664:   * focus traversal keys are disabled, then all key events that would
3665:   * otherwise trigger focus traversal are sent to this Component.
3666:   *
3667:   * @return true if focus traversal keys are enabled
3668:   * @see #setFocusTraversalKeysEnabled (boolean)
3669:   * @see #setFocusTraversalKeys (int, Set)
3670:   * @see #getFocusTraversalKeys (int)
3671:   * @since 1.4
3672:   */
3673:  public boolean getFocusTraversalKeysEnabled ()
3674:	    {
3675:    return focusTraversalKeysEnabled;
3676:  }
3677:
3678:  /**
3679:   * Request that this Component be given the keyboard input focus and
3680:   * that its top-level ancestor become the focused Window.
3681:   *
3682:   * For the request to be granted, the Component must be focusable,
3683:   * displayable and showing and the top-level Window to which it
3684:   * belongs must be focusable.  If the request is initially denied on
3685:   * the basis that the top-level Window is not focusable, the request
3686:   * will be remembered and granted when the Window does become
3687:   * focused.
3688:   *
3689:   * Never assume that this Component is the focus owner until it
3690:   * receives a FOCUS_GAINED event.
3691:   *
3692:   * The behaviour of this method is platform-dependent.
3693:   * {@link #requestFocusInWindow} should be used instead.
3694:   *
3695:   * @see #requestFocusInWindow ()
3696:   * @see FocusEvent
3697:   * @see #addFocusListener (FocusListener)
3698:   * @see #isFocusable ()
3699:   * @see #isDisplayable ()
3700:   * @see KeyboardFocusManager#clearGlobalFocusOwner ()
3701:   */
3702:  public void requestFocus ()
3703:	    {
3704:    if (isDisplayable ()
3705:        && isShowing ()
3706:        && isFocusable ())
3707:	        {
3708:        synchronized (getTreeLock ())
3709:	            {
3710:            // Find this Component's top-level ancestor.
3711:            Container parent = getParent ();
3712:
3713:            while (parent != null
3714:                   && !(parent instanceof Window))
3715:              parent = parent.getParent ();
3716:
3717:            Window toplevel = (Window) parent;
3718:            if (toplevel.isFocusableWindow ())
3719:	                {
3720:                if (peer != null && !isLightweight())
3721:                  // This call will cause a FOCUS_GAINED event to be
3722:                  // posted to the system event queue if the native
3723:                  // windowing system grants the focus request.
3724:                  peer.requestFocus ();
3725:                else
3726:	                    {
3727:                    // Either our peer hasn't been created yet or we're a
3728:                    // lightweight component.  In either case we want to
3729:                    // post a FOCUS_GAINED event.
3730:                    EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3731:                    synchronized (eq)
3732:	                        {
3733:                        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
3734:                        Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3735:                        if (currentFocusOwner != null)
3736:	                            {
3737:                            eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
3738:                                                         false, this));
3739:                            eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false,
3740:                                                         currentFocusOwner));
3741:                          }
3742:                        else
3743:                          eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false));
3744:                      }
3745:                  }
3746:              }
3747:            else
3748:              pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED);
3749:          }
3750:      }
3751:  }
3752:
3753:  /**
3754:   * Request that this Component be given the keyboard input focus and
3755:   * that its top-level ancestor become the focused Window.
3756:   *
3757:   * For the request to be granted, the Component must be focusable,
3758:   * displayable and showing and the top-level Window to which it
3759:   * belongs must be focusable.  If the request is initially denied on
3760:   * the basis that the top-level Window is not focusable, the request
3761:   * will be remembered and granted when the Window does become
3762:   * focused.
3763:   *
3764:   * Never assume that this Component is the focus owner until it
3765:   * receives a FOCUS_GAINED event.
3766:   *
3767:   * The behaviour of this method is platform-dependent.
3768:   * {@link #requestFocusInWindow} should be used instead.
3769:   *
3770:   * If the return value is false, the request is guaranteed to fail.
3771:   * If the return value is true, the request will succeed unless it
3772:   * is vetoed or something in the native windowing system intervenes,
3773:   * preventing this Component's top-level ancestor from becoming
3774:   * focused.  This method is meant to be called by derived
3775:   * lightweight Components that want to avoid unnecessary repainting
3776:   * when they know a given focus transfer need only be temporary.
3777:   *
3778:   * @param temporary true if the focus request is temporary
3779:   * @return true if the request has a chance of success
3780:   * @see #requestFocusInWindow ()
3781:   * @see FocusEvent
3782:   * @see #addFocusListener (FocusListener)
3783:   * @see #isFocusable ()
3784:   * @see #isDisplayable ()
3785:   * @see KeyboardFocusManager#clearGlobalFocusOwner ()
3786:   * @since 1.4
3787:   */
3788:  protected boolean requestFocus(boolean temporary)
3789:	    {
3790:    if (isDisplayable ()
3791:        && isShowing ()
3792:        && isFocusable ())
3793:	        {
3794:        synchronized (getTreeLock ())
3795:	            {
3796:            // Find this Component's top-level ancestor.
3797:            Container parent = getParent ();
3798:
3799:            while (parent != null
3800:                   && !(parent instanceof Window))
3801:              parent = parent.getParent ();
3802:
3803:            Window toplevel = (Window) parent;
3804:            if (toplevel.isFocusableWindow ())
3805:	                {
3806:                if (peer != null && !isLightweight())
3807:                  // This call will cause a FOCUS_GAINED event to be
3808:                  // posted to the system event queue if the native
3809:                  // windowing system grants the focus request.
3810:                  peer.requestFocus ();
3811:                else
3812:	                    {
3813:                    // Either our peer hasn't been created yet or we're a
3814:                    // lightweight component.  In either case we want to
3815:                    // post a FOCUS_GAINED event.
3816:                    EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3817:                    synchronized (eq)
3818:	                        {
3819:                        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
3820:                        Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3821:                        if (currentFocusOwner != null)
3822:	                            {
3823:                            eq.postEvent (new FocusEvent(currentFocusOwner,
3824:                                                         FocusEvent.FOCUS_LOST,
3825:                                                         temporary, this));
3826:                            eq.postEvent (new FocusEvent(this,
3827:                                                         FocusEvent.FOCUS_GAINED,
3828:                                                         temporary,
3829:                                                         currentFocusOwner));
3830:                          }
3831:                        else
3832:                          eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
3833:                      }
3834:                  }
3835:              }
3836:            else
3837:              // FIXME: need to add a focus listener to our top-level
3838:              // ancestor, so that we can post this event when it becomes
3839:              // the focused window.
3840:              pendingFocusRequest = new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary);
3841:          }
3842:      }
3843:    // Always return true.
3844:    return true;
3845:  }
3846:
3847:  /**
3848:   * Request that this component be given the keyboard input focus, if
3849:   * its top-level ancestor is the currently focused Window.  A
3850:   * <code>FOCUS_GAINED</code> event will be fired if and only if this
3851:   * request is successful. To be successful, the component must be
3852:   * displayable, showing, and focusable, and its ancestor top-level
3853:   * Window must be focused.
3854:   *
3855:   * If the return value is false, the request is guaranteed to fail.
3856:   * If the return value is true, the request will succeed unless it
3857:   * is vetoed or something in the native windowing system intervenes,
3858:   * preventing this Component's top-level ancestor from becoming
3859:   * focused.
3860:   *
3861:   * @return true if the request has a chance of success
3862:   * @see #requestFocus ()
3863:   * @see FocusEvent
3864:   * @see #addFocusListener (FocusListener)
3865:   * @see #isFocusable ()
3866:   * @see #isDisplayable ()
3867:   * @see KeyboardFocusManager#clearGlobalFocusOwner ()
3868:   * @since 1.4
3869:   */
3870:  public boolean requestFocusInWindow ()
3871:	    {
3872:    return requestFocusInWindow (false);
3873:  }
3874:
3875:  /**
3876:   * Request that this component be given the keyboard input focus, if
3877:   * its top-level ancestor is the currently focused Window.  A
3878:   * <code>FOCUS_GAINED</code> event will be fired if and only if this
3879:   * request is successful. To be successful, the component must be
3880:   * displayable, showing, and focusable, and its ancestor top-level
3881:   * Window must be focused.
3882:   *
3883:   * If the return value is false, the request is guaranteed to fail.
3884:   * If the return value is true, the request will succeed unless it
3885:   * is vetoed or something in the native windowing system intervenes,
3886:   * preventing this Component's top-level ancestor from becoming
3887:   * focused.  This method is meant to be called by derived
3888:   * lightweight Components that want to avoid unnecessary repainting
3889:   * when they know a given focus transfer need only be temporary.
3890:   *
3891:   * @param temporary true if the focus request is temporary
3892:   * @return true if the request has a chance of success
3893:   * @see #requestFocus ()
3894:   * @see FocusEvent
3895:   * @see #addFocusListener (FocusListener)
3896:   * @see #isFocusable ()
3897:   * @see #isDisplayable ()
3898:   * @see KeyboardFocusManager#clearGlobalFocusOwner ()
3899:   * @since 1.4
3900:   */
3901:  protected boolean requestFocusInWindow(boolean temporary)
3902:	    {
3903:    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
3904:
3905:    Window focusedWindow = manager.getFocusedWindow ();
3906:
3907:    if (isDisplayable ()
3908:        && isShowing ()
3909:        && isFocusable ())
3910:	        {
3911:        if (focusedWindow != null)
3912:	            {
3913:            synchronized (getTreeLock ())
3914:	                {
3915:                Container parent = getParent ();
3916:
3917:                while (parent != null
3918:                       && !(parent instanceof Window))
3919:                  parent = parent.getParent ();
3920:
3921:                Window toplevel = (Window) parent;
3922:
3923:                // Check if top-level ancestor is currently focused window.
3924:                if (focusedWindow == toplevel)
3925:	                    {
3926:                    if (peer != null
3927:                        && !isLightweight()
3928:                        && !(this instanceof Window))
3929:                      // This call will cause a FOCUS_GAINED event to be
3930:                      // posted to the system event queue if the native
3931:                      // windowing system grants the focus request.
3932:                      peer.requestFocus ();
3933:                    else
3934:	                        {
3935:                        // Either our peer hasn't been created yet or we're a
3936:                        // lightweight component.  In either case we want to
3937:                        // post a FOCUS_GAINED event.
3938:                        EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
3939:                        synchronized (eq)
3940:	                            {
3941:                            Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
3942:                            if (currentFocusOwner != null)
3943:	                                {
3944:                                eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
3945:                                                             temporary, this));
3946:                                eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary,
3947:                                                             currentFocusOwner));
3948:                              }
3949:                            else
3950:                              eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
3951:                          }
3952:                      }
3953:                  }
3954:                else
3955:                  return false;
3956:              }
3957:          }
3958:
3959:        return true;
3960:      }
3961:    return false;
3962:  }
3963:
3964:  /**
3965:   * Transfers focus to the next component in the focus traversal
3966:   * order, as though this were the current focus owner.
3967:   *
3968:   * @see #requestFocus()
3969:   * @since 1.1
3970:   */
3971:  public void transferFocus ()
3972:	    {
3973:    nextFocus ();
3974:  }
3975:
3976:  /**
3977:   * Returns the root container that owns the focus cycle where this
3978:   * component resides. A focus cycle root is in two cycles, one as
3979:   * the ancestor, and one as the focusable element; this call always
3980:   * returns the ancestor.
3981:   *
3982:   * @return the ancestor container that owns the focus cycle
3983:   * @since 1.4
3984:   */
3985:  public Container getFocusCycleRootAncestor ()
3986:	    {
3987:    if (this instanceof Window
3988:        && ((Container) this).isFocusCycleRoot ())
3989:      return (Container) this;
3990:
3991:    Container parent = getParent ();
3992:
3993:    while (parent != null
3994:           && !parent.isFocusCycleRoot ())
3995:      parent = parent.getParent ();
3996:
3997:    return parent;
3998:  }
3999:
4000:  /**
4001:   * Tests if the container is the ancestor of the focus cycle that
4002:   * this component belongs to.
4003:   *
4004:   * @param c the container to test
4005:   * @return true if c is the focus cycle root
4006:   * @since 1.4
4007:   */
4008:  public boolean isFocusCycleRoot(Container c)
4009:	    {
4010:    return c == getFocusCycleRootAncestor ();
4011:  }
4012:
4013:  /**
4014:   * AWT 1.0 focus event processor.  Transfers focus to the next
4015:   * component in the focus traversal order, as though this were the
4016:   * current focus owner.
4017:   *
4018:   * @deprecated use {@link #transferFocus ()} instead
4019:   */
4020:  public void nextFocus ()
4021:	    {
4022:    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
4023:
4024:    manager.focusNextComponent (this);
4025:  }
4026:
4027:  /**
4028:   * Transfers focus to the previous component in the focus traversal
4029:   * order, as though this were the current focus owner.
4030:   *
4031:   * @see #requestFocus ()
4032:   * @since 1.4
4033:   */
4034:  public void transferFocusBackward ()
4035:	    {
4036:    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
4037:
4038:    manager.focusPreviousComponent (this);
4039:  }
4040:
4041:  /**
4042:   * Transfers focus to the focus cycle root of this component.
4043:   * However, if this is a Window, the default focus owner in the
4044:   * window in the current focus cycle is focused instead.
4045:   *
4046:   * @see #requestFocus ()
4047:   * @see #isFocusCycleRoot ()
4048:   * @since 1.4
4049:   */
4050:  public void transferFocusUpCycle ()
4051:	    {
4052:    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
4053:
4054:    manager.upFocusCycle (this);
4055:  }
4056:
4057:  /**
4058:	     * Tests if this component is the focus owner. Use {@link
4059:   * #isFocusOwner ()} instead.
4060:   *
4061:   * @return true if this component owns focus
4062:   * @since 1.2
4063:   */
4064:  public boolean hasFocus ()
4065:	    {
4066:    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
4067:
4068:    Component focusOwner = manager.getFocusOwner ();
4069:
4070:    return this == focusOwner;
4071:  }
4072:
4073:  /**
4074:   * Tests if this component is the focus owner.
4075:   *
4076:   * @return true if this component owns focus
4077:   * @since 1.4
4078:   */
4079:  public boolean isFocusOwner()
4080:	    {
4081:    return hasFocus ();
4082:  }
4083:
4084:  /**
4085:   * Adds the specified popup menu to this component.
4086:   *
4087:   * @param menu the popup menu to be added
4088:   * @see #remove(MenuComponent)
4089:   * @since 1.1
4090:   */
4091:  public synchronized void add(PopupMenu popup)
4092:	    {
4093:    if (popups == null)
4094:      popups = new Vector();
4095:    popups.add(popup);
4096:
4097:    if (popup.parent != null)
4098:      popup.parent.remove(popup);
4099:    popup.parent = this;
4100:    if (peer != null)
4101:      popup.addNotify();
4102:  }
4103:
4104:  /**
4105:   * Removes the specified popup menu from this component.
4106:   *
4107:   * @param menu the popup menu to remove
4108:   * @see #add(PopupMenu)
4109:   * @since 1.1
4110:   */
4111:  public synchronized void remove(MenuComponent popup)
4112:	    {
4113:    if (popups != null)
4114:      popups.remove(popup);
4115:  }
4116:
4117:  /**
4118:   * Returns a debugging string representing this component. The string may
4119:   * be empty but not null.
4120:   *
4121:   * @return a string representing this component
4122:   */
4123:  protected String paramString()
4124:	    {
4125:    ClasspathStringBuffer param = new ClasspathStringBuffer();
4126:    String name = getName();
4127:    if (name != null)
4128:      param.append(name).append(",");
4129:    param.append(x).append(",").append(y).append(",").append(width)
4130:      .append("x").append(height);
4131:    if (! isValid())
4132:      param.append(",invalid");
4133:    if (! isVisible())
4134:      param.append(",invisible");
4135:    if (! isEnabled())
4136:      param.append(",disabled");
4137:    if (! isOpaque())
4138:      param.append(",translucent");
4139:    if (isDoubleBuffered())
4140:      param.append(",doublebuffered");
4141:    return param.toString();
4142:  }
4143:
4144:  /**
4145:   * Returns a string representation of this component. This is implemented
4146:   * as <code>getClass().getName() + '[' + paramString() + ']'</code>.
4147:   *
4148:   * @return a string representation of this component
4149:   */
4150:  public String toString()
4151:	    {
4152:    return getClass().getName() + '[' + paramString() + ']';
4153:  }
4154:
4155:  /**
4156:   * Prints a listing of this component to <code>ClasspathSystem.out</code>.
4157:   *
4158:   * @see #list(PrintStream)
4159:   */
4160:  public void list()
4161:	    {
4162:    list(ClasspathSystem.out, 0);
4163:  }
4164:
4165:  /**
4166:   * Prints a listing of this component to the specified print stream.
4167:   *
4168:   * @param stream the <code>PrintStream</code> to print to
4169:   */
4170:  public void list(PrintStream out)
4171:	    {
4172:    list(out, 0);
4173:  }
4174:
4175:  /**
4176:   * Prints a listing of this component to the specified print stream,
4177:   * starting at the specified indentation point.
4178:   *
4179:   * @param stream the <code>PrintStream</code> to print to
4180:   * @param indent the indentation point
4181:   */
4182:  public void list(PrintStream out, int indent)
4183:	    {
4184:    for (int i = 0; i < indent; ++i)
4185:      out.print(' ');
4186:    out.println(toString());
4187:  }
4188:
4189:  /**
4190:   * Prints a listing of this component to the specified print writer.
4191:   *
4192:   * @param writer the <code>PrintWrinter</code> to print to
4193:   * @since 1.1
4194:   */
4195:  public void list(PrintWriter out)
4196:	    {
4197:    list(out, 0);
4198:  }
4199:
4200:  /**
4201:   * Prints a listing of this component to the specified print writer,
4202:   * starting at the specified indentation point.
4203:   *
4204:   * @param writer the <code>PrintWriter</code> to print to
4205:   * @param indent the indentation point
4206:   * @since 1.1
4207:   */
4208:  public void list(PrintWriter out, int indent)
4209:	    {
4210:    for (int i = 0; i < indent; ++i)
4211:      out.print(' ');
4212:    out.println(toString());
4213:  }
4214:
4215:  /**
4216:   * Adds the specified property listener to this component. This is harmless
4217:   * if the listener is null, but if the listener has already been registered,
4218:   * it will now be registered twice. The property listener ignores inherited
4219:   * properties. Recognized properties include:<br>
4220:   * <ul>
4221:   * <li>the font (<code>"font"</code>)</li>
4222:   * <li>the background color (<code>"background"</code>)</li>
4223:   * <li>the foreground color (<code>"foreground"</code>)</li>
4224:   * <li>the focusability (<code>"focusable"</code>)</li>
4225:   * <li>the focus key traversal enabled state
4226:   *     (<code>"focusTraversalKeysEnabled"</code>)</li>
4227:   * <li>the set of forward traversal keys
4228:   *     (<code>"forwardFocusTraversalKeys"</code>)</li>
4229:   * <li>the set of backward traversal keys
4230:   *     (<code>"backwardFocusTraversalKeys"</code>)</li>
4231:   * <li>the set of up-cycle traversal keys
4232:   *     (<code>"upCycleFocusTraversalKeys"</code>)</li>
4233:   * </ul>
4234:   *
4235:   * @param listener the new listener to add
4236:   * @see #removePropertyChangeListener(PropertyChangeListener)
4237:   * @see #getPropertyChangeListeners()
4238:   * @see #addPropertyChangeListener(String, PropertyChangeListener)
4239:   * @since 1.1
4240:   */
4241:  public void addPropertyChangeListener(PropertyChangeListener listener)
4242:	    {
4243:    if (changeSupport == null)
4244:      changeSupport = new PropertyChangeSupport(this);
4245:    changeSupport.addPropertyChangeListener(listener);
4246:  }
4247:
4248:  /**
4249:   * Removes the specified property listener from the component. This is
4250:   * harmless if the listener was not previously registered.
4251:   *
4252:   * @param listener the listener to remove
4253:   * @see #addPropertyChangeListener(PropertyChangeListener)
4254:   * @see #getPropertyChangeListeners()
4255:   * @see #removePropertyChangeListener(String, PropertyChangeListener)
4256:   * @since 1.1
4257:   */
4258:  public void removePropertyChangeListener(PropertyChangeListener listener)
4259:	    {
4260:    if (changeSupport != null)
4261:      changeSupport.removePropertyChangeListener(listener);
4262:  }
4263:
4264:  /**
4265:   * Returns an array of all specified listeners registered on this component.
4266:   *
4267:   * @return an array of listeners
4268:   * @see #addPropertyChangeListener(PropertyChangeListener)
4269:   * @see #removePropertyChangeListener(PropertyChangeListener)
4270:   * @see #getPropertyChangeListeners(String)
4271:   * @since 1.4
4272:   */
4273:  public PropertyChangeListener[] getPropertyChangeListeners()
4274:	    {
4275:    return changeSupport == null ? new PropertyChangeListener[0]
4276:      : changeSupport.getPropertyChangeListeners();
4277:  }
4278:
4279:  /**
4280:   * Adds the specified property listener to this component. This is harmless
4281:   * if the listener is null, but if the listener has already been registered,
4282:   * it will now be registered twice. The property listener ignores inherited
4283:   * properties. The listener is keyed to a single property. Recognized
4284:   * properties include:<br>
4285:   * <ul>
4286:   * <li>the font (<code>"font"</code>)</li>
4287:   * <li>the background color (<code>"background"</code>)</li>
4288:   * <li>the foreground color (<code>"foreground"</code>)</li>
4289:   * <li>the focusability (<code>"focusable"</code>)</li>
4290:   * <li>the focus key traversal enabled state
4291:   *     (<code>"focusTraversalKeysEnabled"</code>)</li>
4292:   * <li>the set of forward traversal keys
4293:   *     (<code>"forwardFocusTraversalKeys"</code>)</li>
4294:p   * <li>the set of backward traversal keys
4295:   *     (<code>"backwardFocusTraversalKeys"</code>)</li>
4296:   * <li>the set of up-cycle traversal keys
4297:   *     (<code>"upCycleFocusTraversalKeys"</code>)</li>
4298:   * </ul>
4299:   *
4300:   * @param propertyName the property name to filter on
4301:   * @param listener the new listener to add
4302:   * @see #removePropertyChangeListener(String, PropertyChangeListener)
4303:   * @see #getPropertyChangeListeners(String)
4304:   * @see #addPropertyChangeListener(PropertyChangeListener)
4305:   * @since 1.1
4306:   */
4307:  public void addPropertyChangeListener(String propertyName,
4308:                                        PropertyChangeListener listener)
4309:	    {
4310:    if (changeSupport == null)
4311:      changeSupport = new PropertyChangeSupport(this);
4312:    changeSupport.addPropertyChangeListener(propertyName, listener);
4313:  }
4314:
4315:  /**
4316:   * Removes the specified property listener on a particular property from
4317:   * the component. This is harmless if the listener was not previously
4318:   * registered.
4319:   *
4320:   * @param propertyName the property name to filter on
4321:   * @param listener the listener to remove
4322:   * @see #addPropertyChangeListener(String, PropertyChangeListener)
4323:   * @see #getPropertyChangeListeners(String)
4324:   * @see #removePropertyChangeListener(PropertyChangeListener)
4325:   * @since 1.1
4326:   */
4327:  public void removePropertyChangeListener(String propertyName,
4328:                                           PropertyChangeListener listener)
4329:	    {
4330:    if (changeSupport != null)
4331:      changeSupport.removePropertyChangeListener(propertyName, listener);
4332:  }
4333:
4334:  /**
4335:   * Returns an array of all specified listeners on the named property that
4336:   * are registered on this component.
4337:   *
4338:   * @return an array of listeners
4339:   * @see #addPropertyChangeListener(String, PropertyChangeListener)
4340:   * @see #removePropertyChangeListener(String, PropertyChangeListener)
4341:   * @see #getPropertyChangeListeners()
4342:   * @since 1.4
4343:   */
4344:  public PropertyChangeListener[] getPropertyChangeListeners(String property)
4345:	    {
4346:    return changeSupport == null ? new PropertyChangeListener[0]
4347:      : changeSupport.getPropertyChangeListeners(property);
4348:  }
4349:
4350:  /**
4351:   * Report a change in a bound property to any registered property listeners.
4352:   *
4353:   * @param propertyName the property that changed
4354:   * @param oldValue the old property value
4355:   * @param newValue the new property value
4356:   */
4357:  protected void firePropertyChange(String propertyName, Object oldValue,
4358:                                    Object newValue)
4359:	    {
4360:    if (changeSupport != null)
4361:      changeSupport.firePropertyChange(propertyName, oldValue, newValue);
4362:  }
4363:
4364:  /**
4365:   * Report a change in a bound property to any registered property listeners.
4366:   *
4367:   * @param propertyName the property that changed
4368:   * @param oldValue the old property value
4369:   * @param newValue the new property value
4370:   */
4371:  protected void firePropertyChange(String propertyName, boolean oldValue,
4372:                                    boolean newValue)
4373:	    {
4374:    if (changeSupport != null)
4375:      changeSupport.firePropertyChange(propertyName, oldValue, newValue);
4376:  }
4377:
4378:  /**
4379:   * Report a change in a bound property to any registered property listeners.
4380:   *
4381:   * @param propertyName the property that changed
4382:   * @param oldValue the old property value
4383:   * @param newValue the new property value
4384:   */
4385:  protected void firePropertyChange(String propertyName, int oldValue,
4386:                                    int newValue)
4387:	    {
4388:    if (changeSupport != null)
4389:      changeSupport.firePropertyChange(propertyName, oldValue, newValue);
4390:  }
4391:
4392:  /**
4393:   * Sets the text layout orientation of this component. New components default
4394:   * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only
4395:   * the current component, while
4396:   * {@link #applyComponentOrientation(ComponentOrientation)} affects the
4397:   * entire hierarchy.
4398:   *
4399:   * @param o the new orientation
4400:   * @throws NullPointerException if o is null
4401:   * @see #getComponentOrientation()
4402:   */
4403:  public void setComponentOrientation(ComponentOrientation o)
4404:	    {
4405:    if (o == null)
4406:      throw new NullPointerException();
4407:    orientation = o;
4408:  }
4409:
4410:  /**
4411:   * Determines the text layout orientation used by this component.
4412:   *
4413:   * @return the component orientation
4414:   * @see #setComponentOrientation(ComponentOrientation)
4415:   */
4416:  public ComponentOrientation getComponentOrientation()
4417:	    {
4418:    return orientation;
4419:  }
4420:
4421:  /**
4422:   * Sets the text layout orientation of this component. New components default
4423:   * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects the
4424:   * entire hierarchy, while
4425:   * {@link #setComponentOrientation(ComponentOrientation)} affects only the
4426:   * current component.
4427:   *
4428:   * @param o the new orientation
4429:   * @throws NullPointerException if o is null
4430:   * @see #getComponentOrientation()
4431:   * @since 1.4
4432:   */
4433:  public void applyComponentOrientation(ComponentOrientation o)
4434:	    {
4435:    setComponentOrientation(o);
4436:  }
4437:
4438:  /**
4439:   * Returns the accessibility framework context of this class. Component is
4440:   * not accessible, so the default implementation returns null. Subclasses
4441:   * must override this behavior, and return an appropriate subclass of
4442:   * {@link AccessibleAWTComponent}.
4443:   *
4444:   * @return the accessibility context
4445:   */
4446:  public AccessibleContext getAccessibleContext()
4447:	    {
4448:    return null;
4449:  }
4450:
4451:
4452:  // Helper methods; some are package visible for use by subclasses.
4453:
4454:  /**
4455:   * Subclasses should override this to return unique component names like
4456:   * "menuitem0".
4457:   *
4458:   * @return the generated name for this component
4459:   */
4460:  String generateName()
4461:	    {
4462:    // Component is abstract.
4463:    return null;
4464:  }
4465:
4466:  /**
4467:   * Sets the peer for this component.
4468:   *
4469:   * @param peer the new peer
4470:   */
4471:  final void setPeer(ComponentPeer peer)
4472:	    {
4473:    this.peer = peer;
4474:  }
4475:
4476:  /**
4477:   * Implementation method that allows classes such as Canvas and Window to
4478:   * override the graphics configuration without violating the published API.
4479:   *
4480:   * @return the graphics configuration
4481:   */
4482:  GraphicsConfiguration getGraphicsConfigurationImpl()
4483:	    {
4484:    if (peer != null)
4485:	        {
4486:        GraphicsConfiguration config = peer.getGraphicsConfiguration();
4487:        if (config != null)
4488:          return config;
4489:      }
4490:
4491:    if (parent != null)
4492:      return parent.getGraphicsConfiguration();
4493:
4494:    return null;
4495:  }
4496:
4497:  /**
4498:   * Translate an AWT 1.1 event ({@link AWTEvent}) into an AWT 1.0
4499:   * event ({@link Event}).
4500:   *
4501:   * @param e an AWT 1.1 event to translate
4502:   *
4503:   * @return an AWT 1.0 event representing e
4504:   */
4505:  static Event translateEvent(AWTEvent e)
4506:	    {
4507:    Component target = (Component) e.getSource ();
4508:    Event translated = null;
4509:
4510:    if (e instanceof InputEvent)
4511:	        {
4512:        InputEvent ie = (InputEvent) e;
4513:        long when = ie.getWhen ();
4514:
4515:        int oldID = 0;
4516:        int id = e.getID ();
4517:
4518:        int oldMods = 0;
4519:        int mods = ie.getModifiersEx ();
4520:
4521:        if ((mods & InputEvent.BUTTON2_DOWN_MASK) != 0)
4522:          oldMods |= Event.META_MASK;
4523:        else if ((mods & InputEvent.BUTTON3_DOWN_MASK) != 0)
4524:          oldMods |= Event.ALT_MASK;
4525:
4526:        if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0)
4527:          oldMods |= Event.SHIFT_MASK;
4528:
4529:        if ((mods & InputEvent.CTRL_DOWN_MASK) != 0)
4530:          oldMods |= Event.CTRL_MASK;
4531:
4532:        if ((mods & InputEvent.META_DOWN_MASK) != 0)
4533:          oldMods |= Event.META_MASK;
4534:
4535:        if ((mods & InputEvent.ALT_DOWN_MASK) != 0)
4536:          oldMods |= Event.ALT_MASK;
4537:
4538:        if (e instanceof MouseEvent)
4539:	            {
4540:            if (id == MouseEvent.MOUSE_PRESSED)
4541:              oldID = Event.MOUSE_DOWN;
4542:            else if (id == MouseEvent.MOUSE_RELEASED)
4543:              oldID = Event.MOUSE_UP;
4544:            else if (id == MouseEvent.MOUSE_MOVED)
4545:              oldID = Event.MOUSE_MOVE;
4546:            else if (id == MouseEvent.MOUSE_DRAGGED)
4547:              oldID = Event.MOUSE_DRAG;
4548:            else if (id == MouseEvent.MOUSE_ENTERED)
4549:              oldID = Event.MOUSE_ENTER;
4550:            else if (id == MouseEvent.MOUSE_EXITED)
4551:              oldID = Event.MOUSE_EXIT;
4552:            else
4553:              // No analogous AWT 1.0 mouse event.
4554:              return null;
4555:
4556:            MouseEvent me = (MouseEvent) e;
4557:
4558:            translated = new Event (target, when, oldID,
4559:                                    me.getX (), me.getY (), 0, oldMods);
4560:          }
4561:        else if (e instanceof KeyEvent)
4562:	            {
4563:            if (id == KeyEvent.KEY_PRESSED)
4564:              oldID = Event.KEY_PRESS;
4565:            else if (e.getID () == KeyEvent.KEY_RELEASED)
4566:              oldID = Event.KEY_RELEASE;
4567:            else
4568:              // No analogous AWT 1.0 key event.
4569:              return null;
4570:
4571:            int oldKey = 0;
4572:            int newKey = ((KeyEvent) e).getKeyCode ();
4573:            switch (newKey)
4574:	                {
4575:              case KeyEvent.VK_BACK_SPACE:
4576:                oldKey = Event.BACK_SPACE;
4577:                break;
4578:              case KeyEvent.VK_CAPS_LOCK:
4579:                oldKey = Event.CAPS_LOCK;
4580:                break;
4581:              case KeyEvent.VK_DELETE:
4582:                oldKey = Event.DELETE;
4583:                break;
4584:              case KeyEvent.VK_DOWN:
4585:              case KeyEvent.VK_KP_DOWN:
4586:                oldKey = Event.DOWN;
4587:                break;
4588:              case KeyEvent.VK_END:
4589:                oldKey = Event.END;
4590:                break;
4591:              case KeyEvent.VK_ENTER:
4592:                oldKey = Event.ENTER;
4593:                break;
4594:              case KeyEvent.VK_ESCAPE:
4595:                oldKey = Event.ESCAPE;
4596:                break;
4597:              case KeyEvent.VK_F1:
4598:                oldKey = Event.F1;
4599:                break;
4600:              case KeyEvent.VK_F10:
4601:                oldKey = Event.F10;
4602:                break;
4603:              case KeyEvent.VK_F11:
4604:                oldKey = Event.F11;
4605:                break;
4606:              case KeyEvent.VK_F12:
4607:                oldKey = Event.F12;
4608:                break;
4609:              case KeyEvent.VK_F2:
4610:                oldKey = Event.F2;
4611:                break;
4612:              case KeyEvent.VK_F3:
4613:                oldKey = Event.F3;
4614:                break;
4615:              case KeyEvent.VK_F4:
4616:                oldKey = Event.F4;
4617:                break;
4618:              case KeyEvent.VK_F5:
4619:                oldKey = Event.F5;
4620:                break;
4621:              case KeyEvent.VK_F6:
4622:                oldKey = Event.F6;
4623:                break;
4624:              case KeyEvent.VK_F7:
4625:                oldKey = Event.F7;
4626:                break;
4627:              case KeyEvent.VK_F8:
4628:                oldKey = Event.F8;
4629:                break;
4630:              case KeyEvent.VK_F9:
4631:                oldKey = Event.F9;
4632:                break;
4633:              case KeyEvent.VK_HOME:
4634:                oldKey = Event.HOME;
4635:                break;
4636:              case KeyEvent.VK_INSERT:
4637:                oldKey = Event.INSERT;
4638:                break;
4639:              case KeyEvent.VK_LEFT:
4640:              case KeyEvent.VK_KP_LEFT:
4641:                oldKey = Event.LEFT;
4642:                break;
4643:              case KeyEvent.VK_NUM_LOCK:
4644:                oldKey = Event.NUM_LOCK;
4645:                break;
4646:              case KeyEvent.VK_PAUSE:
4647:                oldKey = Event.PAUSE;
4648:                break;
4649:              case KeyEvent.VK_PAGE_DOWN:
4650:                oldKey = Event.PGDN;
4651:                break;
4652:              case KeyEvent.VK_PAGE_UP:
4653:                oldKey = Event.PGUP;
4654:                break;
4655:              case KeyEvent.VK_PRINTSCREEN:
4656:                oldKey = Event.PRINT_SCREEN;
4657:                break;
4658:              case KeyEvent.VK_RIGHT:
4659:              case KeyEvent.VK_KP_RIGHT:
4660:                oldKey = Event.RIGHT;
4661:                break;
4662:              case KeyEvent.VK_SCROLL_LOCK:
4663:                oldKey = Event.SCROLL_LOCK;
4664:                break;
4665:              case KeyEvent.VK_TAB:
4666:                oldKey = Event.TAB;
4667:                break;
4668:              case KeyEvent.VK_UP:
4669:              case KeyEvent.VK_KP_UP:
4670:                oldKey = Event.UP;
4671:                break;
4672:              default:
4673:                oldKey = newKey;
4674:              }
4675:
4676:            translated = new Event (target, when, oldID,
4677:                                    0, 0, oldKey, oldMods);
4678:          }
4679:      }
4680:    else if (e instanceof ActionEvent)
4681:      translated = new Event (target, Event.ACTION_EVENT,
4682:                              ((ActionEvent) e).getActionCommand ());
4683:
4684: