Component.java 64 KB
Newer Older
1
/* Copyright (C) 1999, 2000, 2001, 2002  Free Software Foundation
2

3
This file is part of GNU Classpath.
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */
36 37 38

package java.awt;
import java.awt.event.*;
Bryce McKinlay committed
39 40 41 42 43 44 45 46 47
import java.awt.image.*;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.*;
import java.util.EventListener;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Vector;
import java.awt.peer.ComponentPeer;
48
import java.awt.peer.LightweightPeer;
Bryce McKinlay committed
49 50 51
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
// import javax.accessibility.AccessibleContext;
52

53 54 55 56 57 58 59 60 61
/**
  * The root of all evil.
  *
  * Status: Incomplete. The event dispatch mechanism is implemented. All 
  * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly 
  * incomplete or only stubs; except for methods relating to the Drag and Drop, 
  * Input Method, and Accessibility frameworks: These methods are present but 
  * commented out.
  */
Bryce McKinlay committed
62 63
public abstract class Component implements ImageObserver, MenuContainer, 
					   java.io.Serializable
64
{
65 66 67 68 69 70 71 72 73 74 75 76 77 78
  /**
   * Constant returned by the <code>getAlignmentY</code> method to indicate
   * that the component wishes to be aligned to the bottom relative to
   * other components.
   */
  public static final float BOTTOM_ALIGNMENT = (float)1.0;

  /**
   * Constant returned by the <code>getAlignmentY</code> and 
   * <code>getAlignmentX</code> methods to indicate
   * that the component wishes to be aligned to the center relative to
   * other components.
   */
  public static final float CENTER_ALIGNMENT = (float)0.5;
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  /**
   * Constant returned by the <code>getAlignmentY</code> method to indicate
   * that the component wishes to be aligned to the top relative to
   * other components.
   */
  public static final float TOP_ALIGNMENT = (float)0.0;

  /**
   * Constant returned by the <code>getAlignmentX</code> method to indicate
   * that the component wishes to be aligned to the right relative to
   * other components.
   */
  public static final float RIGHT_ALIGNMENT = (float)1.0;

  /**
   * Constant returned by the <code>getAlignmentX</code> method to indicate
   * that the component wishes to be aligned to the left relative to
   * other components.
   */
  public static final float LEFT_ALIGNMENT = (float)0.0;
100

101 102 103 104 105
  /* Make the treelock a String so that it can easily be identified
     in debug dumps. We clone the String in order to avoid a conflict in 
     the unlikely event that some other package uses exactly the same string
     as a lock object. */
  static Object treeLock = new String("AWT_TREE_LOCK");
106

Bryce McKinlay committed
107 108 109 110 111 112 113 114 115 116 117 118
  /* Serialized fields from the serialization spec. */
  // FIXME: Default values?
  int x;
  int y;
  int width;
  int height;
  Color foreground;
  Color background;
  Font font;
  Font peerFont;
  Cursor cursor;
  Locale locale;
119 120
  boolean visible = true; // default (except for Window)
  boolean enabled = true;
Bryce McKinlay committed
121 122 123 124 125 126 127 128 129
  boolean valid;
  boolean hasFocus;
  //DropTarget dropTarget;
  Vector popups;
  String name;
  boolean nameExplicitlySet;
  Dimension minSize;
  Dimension prefSize;
  boolean newEventsOnly;  
130
  long eventMask = AWTEvent.PAINT_EVENT_MASK;
Bryce McKinlay committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  PropertyChangeSupport changeSupport;
  boolean isPacked;
  int componentSerializedDataVersion;
  /* AccessibleContext accessibleContext; */

  /* Anything else is non-serializable, and should be declared "transient". */
  transient Container parent;
  transient java.awt.peer.ComponentPeer peer;

  transient ComponentListener componentListener;
  transient FocusListener focusListener;
  transient KeyListener keyListener;
  transient MouseListener mouseListener;
  transient MouseMotionListener mouseMotionListener;
  transient InputMethodListener inputMethodListener;
  transient HierarchyListener hierarchyListener;
  transient HierarchyBoundsListener hierarchyBoundsListener;

149 150
  transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;

151 152 153
  /**
   * Default constructor for subclasses.
   */
Bryce McKinlay committed
154 155 156 157
  protected Component()
  {
  }

158 159 160 161 162
  /**
   * Returns the name of this component.
   *
   * @return The name of this component.
   */
Bryce McKinlay committed
163 164 165 166 167 168
  public String getName()
  {
    if (name == null && !nameExplicitlySet)
      name = generateName();
    return name;
  }
169 170 171 172 173 174

  /**
   * Sets the name of this component to the specified name.
   *
   * @param name The new name of this component.
   */
Bryce McKinlay committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188
  public void setName(String name)
  {
    nameExplicitlySet = true;
    this.name = name;
  }
  
  /** Subclasses should override this to return unique component names like 
    * "menuitem0".
    */
  String generateName()
  {
    // Component is abstract.
    return null;
  }
189 190 191 192 193 194

  /**
   * Returns the parent of this component.
   * 
   * @return The parent of this component.
   */
Bryce McKinlay committed
195 196 197 198
  public Container getParent()
  {
    return parent;  
  }
199 200 201 202 203 204 205 206 207 208 209 210 211 212

  // Sets the peer for this component.
  final void setPeer (ComponentPeer peer)
  {
    this.peer = peer;
  }

  /**
   * Returns the native windowing system peer for this component.
   *
   * @return The peer for this component.
   * @deprecated
   */
  // Classpath's Gtk peers rely on this.
Bryce McKinlay committed
213 214 215 216
  public java.awt.peer.ComponentPeer getPeer()
  {
    return peer;
  }
217

Bryce McKinlay committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  // FIXME: java.awt.dnd classes not yet implemented
  /*
  public void setDropTarget(DropTarget dt)
  {
    this.dropTarget = dt;
  }
  
  public DropTarget getDropTarget()
  {
    return dropTarget;
  }
  */
  
  /** @since 1.3 */
  public GraphicsConfiguration getGraphicsConfiguration()
  {
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
    return getGraphicsConfigurationImpl();
  }

  /** Implementation method that allows classes such as Canvas and
      Window to override the graphics configuration without violating
      the published API. */
  GraphicsConfiguration getGraphicsConfigurationImpl()
  {
    if (peer != null)
      {
	GraphicsConfiguration config = peer.getGraphicsConfiguration();
	if (config != null)
	  return config;
      }

249 250
    if (parent != null)
      return parent.getGraphicsConfiguration();
251

Bryce McKinlay committed
252 253
    return null;
  }
254

255 256 257 258 259 260
  /**
   * Returns the object used for synchronization locks on this component
   * when performing tree and layout functions.
   *
   * @return The synchronization lock for this component.
   */
Bryce McKinlay committed
261 262
  public final Object getTreeLock()
  {
263
    return treeLock;
Bryce McKinlay committed
264
  }
265

266 267 268 269 270 271 272 273 274 275 276
  // The sync lock object for this component.
  final void setTreeLock(Object tree_lock)
  {
    this.treeLock = tree_lock;
  }

  /**
   * Returns the toolkit in use for this component.
   *
   * @return The toolkit for this component.
   */
Bryce McKinlay committed
277 278
  public Toolkit getToolkit()
  {
279
    if (peer != null)
280 281 282 283 284
      {
	Toolkit tk = peer.getToolkit();
	if (tk != null)
	  return tk;
      }
285 286 287
    if (parent != null)
      return parent.getToolkit ();
    return Toolkit.getDefaultToolkit ();
Bryce McKinlay committed
288
  }
289

290 291 292 293 294 295 296
  /**
   * Tests whether or not this component is valid.  A invalid component needs
   * to have its layout redone.
   *
   * @return <code>true</code> if this component is valid, <code>false</code>
   * otherwise.
   */
Bryce McKinlay committed
297 298
  public boolean isValid()
  {
299
    return valid;
Bryce McKinlay committed
300 301 302 303 304
  }
  
  /** @since 1.2 */
  public boolean isDisplayable()
  {
305 306 307
    if (parent != null)
      return parent.isDisplayable();
    return false;
Bryce McKinlay committed
308
  }
309 310 311 312 313 314 315

  /**
   * Tests whether or not this component is visible.
   *
   * @return <code>true</code> if the component is visible,
   * <code>false</code> otherwise.
   */
Bryce McKinlay committed
316 317 318 319
  public boolean isVisible()
  {
    return visible;
  }
320 321 322 323 324 325 326 327 328

  /**
   * Tests whether or not this component is actually being shown on
   * the screen.  This will be true if and only if it this component is
   * visible and its parent components are all visible.
   *
   * @return <code>true</code> if the component is showing on the screen,
   * <code>false</code> otherwise.
   */
Bryce McKinlay committed
329 330
  public boolean isShowing()
  {
Tom Tromey committed
331
    if (! visible || peer == null)
332 333
      return false;

Tom Tromey committed
334
    return parent == null ? true : parent.isShowing ();
Bryce McKinlay committed
335
  }
336 337 338 339 340 341 342

  /**
   * Tests whether or not this component is enabled.
   *
   * @return <code>true</code> if the component is enabled,
   * <code>false</code> otherwise.
   */
Bryce McKinlay committed
343 344 345 346
  public boolean isEnabled()
  {
    return enabled;
  }
347 348 349 350 351 352 353 354 355

  /**
   * Enables or disables this component.
   *
   * @param enabled <code>true</code> to enable this component, 
   * <code>false</code> to disable it.
   *
   * @deprecated Deprecated in favor of <code>setEnabled()</code>.
   */
Bryce McKinlay committed
356 357 358
  public void setEnabled(boolean b)
  {
    this.enabled = b;
359 360
    if (peer != null)
      peer.setEnabled(b);
Bryce McKinlay committed
361
  }
362 363 364 365 366 367

  /**
   * Enables this component.
   *
   * @deprecated Deprecated in favor of <code>setEnabled()</code>.
   */
Bryce McKinlay committed
368 369 370 371
  public void enable()
  {
    setEnabled(true);
  }
372 373 374 375 376 377 378 379 380

  /**
   * Enables or disables this component.
   *
   * @param enabled <code>true</code> to enable this component, 
   * <code>false</code> to disable it.
   *
   * @deprecated Deprecated in favor of <code>setEnabled()</code>.
   */
Bryce McKinlay committed
381 382 383 384
  public void enable(boolean b)
  {
    setEnabled(b);
  }
385 386 387 388 389 390

  /**
   * Disables this component.
   *
   * @deprecated Deprecated in favor of <code>setEnabled()</code>.
   */
Bryce McKinlay committed
391 392 393 394
  public void disable()
  {
    setEnabled(false);
  }
395

Bryce McKinlay committed
396 397 398 399
  public boolean isDoubleBuffered()
  {
    return false;
  }
400

Bryce McKinlay committed
401 402 403 404 405
  /** @since 1.2 */
  public void enableInputMethods(boolean enable)
  {
    // FIXME
  }
406 407 408 409 410 411 412 413 414 415 416

  /**
   * Makes this component visible or invisible.
   *
   * @param visible <code>true</code> to make this component visible,
   * </code>false</code> to make it invisible.
   * @specnote  Inspection by subclassing shows that Sun's implementation
   * calls show(boolean) which then calls show() or hide(). It is
   * the show() method that is overriden in subclasses like Window.
   * We do the same to preserve compatibility for subclasses.
   */
Bryce McKinlay committed
417 418
  public void setVisible(boolean b)
  {
419 420 421
    if (peer != null)
      peer.setVisible (b);
    this.visible = b;
Bryce McKinlay committed
422
  }
423 424 425 426 427 428

  /**
   * Makes this component visible on the screen.
   *
   * @deprecated Deprecated in favor of <code>setVisible()</code>.
   */
Bryce McKinlay committed
429 430
  public void show()
  {
431
    setVisible (true);
Bryce McKinlay committed
432
  }
433 434 435 436 437 438 439 440 441

  /**
   * Makes this component visible or invisible.
   *
   * @param visible <code>true</code> to make this component visible,
   * </code>false</code> to make it invisible.
   *
   * @deprecated Deprecated in favor of <code>setVisible()</code>.
   */
Bryce McKinlay committed
442 443
  public void show(boolean b)
  {
444
    setVisible (b);
Bryce McKinlay committed
445
  }
446 447 448 449 450 451

  /**
   * Hides this component so that it is no longer shown on the screen.
   *
   * @deprecated Deprecated in favor of <code>setVisible()</code>.
   */
Bryce McKinlay committed
452 453
  public void hide()
  {
454
    setVisible (false);
Bryce McKinlay committed
455
  }
456 457 458 459 460 461

  /**
   * Returns this component's foreground color.
   *
   * @return This component's foreground color.
   */
Bryce McKinlay committed
462 463
  public Color getForeground()
  {
464 465 466 467 468
    if (foreground != null)
      return foreground;
    if (parent != null)
      return parent.getForeground();
    return null;
Bryce McKinlay committed
469
  }
470 471 472 473 474 475

  /**
   * Sets this component's foreground color to the specified color.
   *
   * @param foreground_color The new foreground color.
   */
Bryce McKinlay committed
476 477
  public void setForeground(Color c)
  {
478 479
    if (peer != null)
      peer.setForeground(c);
Bryce McKinlay committed
480 481
    this.foreground = c;
  }
482

483 484 485 486 487 488 489 490
  /**
   * Returns this component's background color.
   *
   * @return the background color of the component. null may be
   * returned instead of the actual background color, if this
   * method is called before the component is added to the
   * component hierarchy.
   */
Bryce McKinlay committed
491 492
  public Color getBackground()
  {
493 494 495 496 497
    if (background != null)
      return background;
    if (parent != null)
      return parent.getBackground();
    return null;
Bryce McKinlay committed
498
  }
499 500 501 502 503 504

  /**
   * Sets this component's background color to the specified color.
   *
   * @param background_color The new background color
   */
Bryce McKinlay committed
505 506
  public void setBackground(Color c)
  {
507 508
    if (peer != null)
      peer.setBackground(c);
Bryce McKinlay committed
509 510
    this.background = c;
  }
511 512 513 514 515 516

  /**
   * Returns the font in use for this component.
   *
   * @return The font for this component.
   */
Bryce McKinlay committed
517 518
  public Font getFont()
  {
519 520 521 522 523
    if (font != null)
      return font;
    if (parent != null)
      return parent.getFont();
    return null;
Bryce McKinlay committed
524
  }
525 526 527 528 529 530

  /**
   * Sets the font for this component to the specified font.
   *
   * @param font The new font for this component.
   */
Bryce McKinlay committed
531 532
  public void setFont(Font f)
  {
533 534
    if (peer != null)
      peer.setFont(f);
Bryce McKinlay committed
535 536
    this.font = f;
  }
537

538 539 540 541 542 543 544
  /**
   * Returns the locale for this component.  If this component does not
   * have a locale, the locale of the parent component is returned.  If the
   * component has no parent, the system default locale is returned.
   *
   * @return The locale for this component.
   */
Bryce McKinlay committed
545 546 547 548 549 550 551 552 553
  public Locale getLocale() throws IllegalComponentStateException
  {
    if (locale != null)
      return locale;
    if (parent == null)
      throw new IllegalComponentStateException
        ("Component has no parent: Can not determine Locale");
    return parent.getLocale();
  }
554 555 556 557 558 559

  /**
   * Sets the locale for this component to the specified locale.
   *
   * @param locale The new locale for this component.
   */
Bryce McKinlay committed
560 561 562
  public void setLocale(Locale l)  
  {
    this.locale = l;
563

564 565 566
    /* new writing/layout direction perhaps, or make more/less
       room for localized text labels */
    invalidate();
Bryce McKinlay committed
567
  }
568 569 570 571 572 573

  /**
   * Returns the color model of the device this componet is displayed on.
   *
   * @return This object's color model.
   */
Bryce McKinlay committed
574 575
  public ColorModel getColorModel()
  {
576 577 578 579 580 581
    GraphicsConfiguration config = getGraphicsConfiguration();

    if (config != null)
      return config.getColorModel();

    return getToolkit().getColorModel();    
Bryce McKinlay committed
582
  }
583

584 585 586 587 588 589
  /**
   * Returns the location of this component's top left corner relative to
   * its parent component.
   *
   * @return The location of this component.
   */
Bryce McKinlay committed
590 591 592 593
  public Point getLocation()
  {
    return new Point(x, y);
  }
594

595 596 597 598 599 600
  /**
   * Returns the location of this component's top left corner in screen
   * coordinates.
   *
   * @return The location of this component in screen coordinates.
   */
Bryce McKinlay committed
601
  public Point getLocationOnScreen()
602
  {
Tom Tromey committed
603 604 605 606 607
    if (! isShowing ())
      throw new IllegalComponentStateException ("component not showing");

    // We know peer != null here.
    return peer.getLocationOnScreen ();
Bryce McKinlay committed
608 609
  }

610 611 612 613 614 615 616 617 618
  /**
   * Returns the location of this component's top left corner relative to
   * its parent component.
   *
   * @return The location of this component.
   *
   * @deprecated This method is deprecated in favor of 
   * <code>getLocation()</code>.
   */
Bryce McKinlay committed
619 620 621
  public Point location()
  {
    return getLocation();
622 623
  }

624 625 626 627 628 629 630
  /**
   * Moves this component to the specified location.  The coordinates are
   * the new upper left corner of this component.
   *
   * @param x The new X coordinate of this component.
   * @param y The new Y coordinate of this component.
   */
631 632
  public void setLocation (int x, int y)
  {
633 634
    if ((this.x == x) && (this.y == y))
      return;
635

636
    invalidate();
637

Bryce McKinlay committed
638 639
    this.x = x;
    this.y = y;
640 641 642 643
    if (peer != null)
      peer.setBounds(x, y, width, height);
  }

644 645 646 647 648 649 650 651 652
  /**
   * Moves this component to the specified location.  The coordinates are
   * the new upper left corner of this component.
   *
   * @param x The new X coordinate of this component.
   * @param y The new Y coordinate of this component.
   *
   * @deprecated Deprecated in favor for <code>setLocation</code>.
   */
Bryce McKinlay committed
653 654 655 656
  public void move(int x, int y)
  {
    setLocation(x,y);
  }
657 658 659 660 661 662 663

  /**
   * Moves this component to the specified location.  The coordinates are
   * the new upper left corner of this component.
   *
   * @param p New coordinates for this component.
   */
Bryce McKinlay committed
664 665 666 667
  public void setLocation(Point p)
  {
    setLocation(p.x, p.y);
  }
668 669 670 671 672 673

  /**
   * Returns the size of this object.
   *
   * @return The size of this object.
   */
Bryce McKinlay committed
674 675 676 677
  public Dimension getSize()
  {
    return new Dimension(width, height);
  }
678 679 680 681 682 683 684 685

  /**
   * Returns the size of this object.
   *
   * @return The size of this object.
   *
   * @deprecated This method is deprecated in favor of <code>getSize</code>.
   */
Bryce McKinlay committed
686 687 688 689
  public Dimension size()
  {
    return getSize();
  }
690 691 692 693 694 695 696

  /**
   * Sets the size of this component to the specified width and height.
   * 
   * @param width The new width of this component.
   * @param height The new height of this component.
   */
Bryce McKinlay committed
697
  public void setSize(int width, int height)
698
  {
699 700 701 702 703
    if ((this.width == width) && (this.height == height))
      return;

    invalidate();

Bryce McKinlay committed
704 705
    this.width = width;
    this.height = height;
706
    if (peer != null)
Bryce McKinlay committed
707 708
      peer.setBounds(x, y, width, height);
  }
709 710 711 712 713 714 715 716 717

  /**
   * Sets the size of this component to the specified value.
   * 
   * @param width The new width of the component.
   * @param height The new height of the component.
   *
   * @deprecated This method is deprecated in favor of <code>setSize</code>.
   */
Bryce McKinlay committed
718 719 720 721
  public void resize(int width, int height)
  {
    setSize(width, height);
  }
722 723 724 725 726 727

  /**
   * Sets the size of this component to the specified value.
   * 
   * @param dim The new size of this component.
   */
Bryce McKinlay committed
728 729 730
  public void setSize(Dimension d)
  {
    setSize(d.width, d.height);
731 732
  }

733 734 735 736 737 738 739
  /**
   * Sets the size of this component to the specified value.
   * 
   * @param dim The new size of this component.
   *
   * @deprecated This method is deprecated in favor of <code>setSize</code>.
   */
Bryce McKinlay committed
740
  public void resize(Dimension d)
741
  {
Bryce McKinlay committed
742
    setSize(d.width, d.height);
743 744
  }

745 746 747 748 749 750 751
  /**
   * Returns a bounding rectangle for this component.  Note that the
   * returned rectange is relative to this component's parent, not to
   * the screen.
   *
   * @return The bounding rectangle for this component.
   */
Bryce McKinlay committed
752
  public Rectangle getBounds()
753
  {
Bryce McKinlay committed
754
    return new Rectangle (x, y, width, height);
755 756
  }

757 758 759 760 761 762 763 764 765
  /**
   * Returns a bounding rectangle for this component.  Note that the
   * returned rectange is relative to this component's parent, not to
   * the screen.
   *
   * @return The bounding rectangle for this component.
   *
   * @deprecated Deprecated in favor of <code>getBounds()</code>.
   */
Bryce McKinlay committed
766 767 768 769
  public Rectangle bounds()
  {
    return getBounds();
  }
770 771 772 773 774 775 776 777 778 779 780

  /**
   * Sets the bounding rectangle for this component to the specified
   * values.  Note that these coordinates are relative to the parent,
   * not to the screen.
   *
   * @param x The X coordinate of the upper left corner of the rectangle.
   * @param y The Y coordinate of the upper left corner of the rectangle.
   * @param width The width of the rectangle.
   * @param height The height of the rectangle.
   */
Bryce McKinlay committed
781 782
  public void setBounds(int x, int y, int w, int h)
  {
783 784 785 786 787 788 789 790
    if (this.x == x
	&& this.y == y
	&& this.width == w
	&& this.height == h)
      return;

    invalidate();

Bryce McKinlay committed
791 792 793 794
    this.x = x;
    this.y = y;
    this.width = w;
    this.height = h;
795

Bryce McKinlay committed
796 797 798
    if (peer != null)
      peer.setBounds(x, y, w, h);
  }
799 800 801 802 803 804 805 806 807 808 809 810 811 812

  /**
   * Sets the bounding rectangle for this component to the specified
   * values.  Note that these coordinates are relative to the parent,
   * not to the screen.
   *
   * @param x The X coordinate of the upper left corner of the rectangle.
   * @param y The Y coordinate of the upper left corner of the rectangle.
   * @param width The width of the rectangle.
   * @param height The height of the rectangle.
   *
   * @deprecated This method is deprecated in favor of
   * <code>setBounds(int, int, int, int)</code>.
   */
Bryce McKinlay committed
813 814 815 816
  public void reshape(int x, int y, int width, int height)
  {
    setBounds(x, y, width, height);
  }
817 818 819 820 821 822 823 824

  /**
   * Sets the bounding rectangle for this component to the specified
   * rectangle.  Note that these coordinates are relative to the parent,
   * not to the screen.
   *
   * @param bounding_rectangle The new bounding rectangle.
   */
Bryce McKinlay committed
825 826 827 828 829 830 831
  public void setBounds(Rectangle r)
  { 
    setBounds(r.x, r.y, r.width, r.height);
  }
  
  /** @since 1.2 */
  public int getX()
Tom Tromey committed
832 833 834
  {
    return x;
  }
Bryce McKinlay committed
835 836 837
  
  /** @since 1.2 */
  public int getY()
Tom Tromey committed
838 839 840
  {
    return y;
  }
Bryce McKinlay committed
841 842 843
  
  /** @since 1.2 */
  public int getWidth()
844
  {
Bryce McKinlay committed
845
    return width;
846
  }
Bryce McKinlay committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
  
  /** @since 1.2 */
  public int getHeight()
  {
    return height;
  }
  
  public Rectangle getBounds(Rectangle r)
  {
    r.x = this.x;
    r.y = this.y;
    r.width = this.width;
    r.height = this.height;
    return r;
  }
  
  public Dimension getSize(Dimension d)
  {
    d.width = this.width;
    d.height = this.height;
    return d;
  }
  
  public Point getLocation(Point p)
  {
    p.x = x;
    p.y = y;
    return p;
  }
  
  /** @since 1.2 */
  public boolean isOpaque()
  {
880
    return !isLightweight();
Bryce McKinlay committed
881 882
  }
  
883 884 885 886 887 888 889
  /** 
   * Return whether the component is lightweight.
   *
   * @return true if component has a peer and and the peer is lightweight.
   *
   * @since 1.2
   */  
Bryce McKinlay committed
890 891
  public boolean isLightweight()
  {
892
    return (peer != null) && (peer instanceof LightweightPeer);
Bryce McKinlay committed
893
  }
894 895 896 897 898 899

  /**
   * Returns the component's preferred size.
   *
   * @return The component's preferred size.
   */
Bryce McKinlay committed
900
  public Dimension getPreferredSize()
901 902 903 904
  {
    if (peer == null)
      return new Dimension(width, height);
    else
Bryce McKinlay committed
905
      return peer.getPreferredSize();
906 907
  }

908 909 910 911 912 913 914
  /**
   * Returns the component's preferred size.
   *
   * @return The component's preferred size.
   *
   * @deprecated Deprecated in favor of <code>getPreferredSize()</code>.
   */
Bryce McKinlay committed
915
  public Dimension preferredSize()
916
  {
Bryce McKinlay committed
917 918
    return getPreferredSize();
  }
919 920 921 922 923 924

  /**
   * Returns the component's minimum size.
   *
   * @return The component's minimum size.
   */
Bryce McKinlay committed
925 926
  public Dimension getMinimumSize()
  {
927 928 929
    if (peer == null)
      return new Dimension(width, height);
    else
Bryce McKinlay committed
930
      return peer.getMinimumSize();
931 932
  }

933 934 935 936 937 938 939
  /**
   * Returns the component's minimum size.
   *
   * @return The component's minimum size.
   *
   * @deprecated Deprecated in favor of <code>getMinimumSize()</code>
   */
Bryce McKinlay committed
940 941 942 943
  public Dimension minimumSize()
  {
    return getMinimumSize();
  }
Tom Tromey committed
944

945 946 947 948 949
  /**
   * Returns the component's maximum size.
   *
   * @return The component's maximum size.
   */
Bryce McKinlay committed
950 951
  public Dimension getMaximumSize()
  {
952
    return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
Bryce McKinlay committed
953
  }
Tom Tromey committed
954

955 956 957 958 959 960
  /**
   * Returns the preferred horizontal alignment of this component.  The
   * value returned will be one of the constants defined in this class.
   *
   * @return The preferred horizontal alignment of this component.
   */
Bryce McKinlay committed
961 962
  public float getAlignmentX()
  {
Tom Tromey committed
963
    return CENTER_ALIGNMENT;
Bryce McKinlay committed
964
  }
Tom Tromey committed
965

966 967 968 969 970 971
  /**
   * Returns the preferred vertical alignment of this component.  The
   * value returned will be one of the constants defined in this class.
   *
   * @return The preferred vertical alignment of this component.
   */
Bryce McKinlay committed
972 973
  public float getAlignmentY()
  {
Tom Tromey committed
974
    return CENTER_ALIGNMENT;
Bryce McKinlay committed
975
  }
Tom Tromey committed
976

977 978 979 980
  /**
   * Calls the layout manager to re-layout the component.  This is called
   * during validation of a container in most cases.
   */
Bryce McKinlay committed
981 982
  public void doLayout()
  {
983
    // nothing to do unless we're a container
Bryce McKinlay committed
984
  }
985 986 987 988 989 990 991

  /**
   * Calls the layout manager to re-layout the component.  This is called
   * during validation of a container in most cases.
   *
   * @deprecated This method is deprecated in favor of <code>doLayout()</code>.
   */
Bryce McKinlay committed
992 993 994 995
  public void layout()
  {
    doLayout();
  }
996 997 998 999

  /**
   * Called to ensure that the layout for this component is valid.
   */
Bryce McKinlay committed
1000 1001
  public void validate()
  {
1002
    valid = true;
Bryce McKinlay committed
1003
  }
1004 1005 1006 1007 1008

  /**
   * Invalidates this component and all of its parent components.  This will
   * cause them to have their layout redone.
   */
Bryce McKinlay committed
1009 1010
  public void invalidate()
  {
1011
    valid = false;
1012 1013

    if ((parent != null) && parent.valid)
Tom Tromey committed
1014
      parent.invalidate ();
Bryce McKinlay committed
1015
  }
Tom Tromey committed
1016

1017 1018 1019 1020 1021 1022
  /**
   * Returns a graphics object for this component.  Returns <code>null</code>
   * if this component is not currently displayed on the screen.
   *
   * @return A graphics object for this component.
   */
Bryce McKinlay committed
1023 1024
  public Graphics getGraphics()
  {
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
    if (peer != null)
      {
	Graphics gfx = peer.getGraphics();
	if (gfx != null)
	  return gfx;
      
	// create graphics for lightweight:
	Container parent = getParent();
	if (parent != null)
	  {
	    gfx = parent.getGraphics();
	    Rectangle bounds = getBounds();
	    gfx.setClip(bounds);
	    gfx.translate(bounds.x, bounds.y);
	    return gfx;
	  }
      }
Bryce McKinlay committed
1042 1043
    return null;
  }
1044 1045 1046 1047 1048 1049 1050 1051

  /**
   * Returns the font metrics for the specified font in this component.
   *
   * @param font The font to retrieve metrics for.
   *
   * @return The font metrics for the specified font.
   */
Bryce McKinlay committed
1052 1053
  public FontMetrics getFontMetrics(Font font)
  {
Tom Tromey committed
1054 1055 1056
    if (peer == null)
      return getToolkit().getFontMetrics(font);
    return peer.getFontMetrics (font);
Bryce McKinlay committed
1057
  }
Tom Tromey committed
1058

1059 1060 1061 1062 1063
  /**
   * Sets the cursor for this component to the specified cursor.
   *
   * @param cursor The new cursor for this component.
   */
Bryce McKinlay committed
1064 1065 1066
  public void setCursor(Cursor cursor)
  {
    this.cursor = cursor;
Tom Tromey committed
1067 1068
    if (peer != null)
      peer.setCursor (cursor);
Bryce McKinlay committed
1069
  }
Tom Tromey committed
1070

1071 1072 1073 1074 1075
  /**
   * Returns the cursor for this component.
   *
   * @return The cursor for this component.
   */
Bryce McKinlay committed
1076 1077 1078 1079
  public Cursor getCursor()
  {
    return this.cursor;
  }
1080 1081 1082 1083 1084 1085 1086

  /**
   * Paints this component on the screen.  The clipping region in the
   * graphics context will indicate the region that requires painting.
   *
   * @param graphics The graphics context for this paint job.
   */
Bryce McKinlay committed
1087
  public void paint(Graphics g)
1088
  {
Bryce McKinlay committed
1089
  }
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099

  /**
   * Updates this component.  This method fills the component
   * with the background color, then sets the foreground color of the
   * specified graphics context to the foreground color of this component
   * and calls the <code>paint()</code> method.
   * // FIXME: What are the coords relative to?
   *
   * @param graphics The graphics context for this update.
   */
Bryce McKinlay committed
1100 1101
  public void update(Graphics g)
  {
1102
    paint(g);
Bryce McKinlay committed
1103
  }
1104 1105 1106 1107 1108 1109

  /**
   * Paints this entire component, including any sub-components.
   *
   * @param graphics The graphics context for this paint job.
   */
Bryce McKinlay committed
1110 1111
  public void paintAll(Graphics g)
  {    
1112 1113 1114 1115 1116 1117
    if (!visible)
      return;
	
    if (peer != null)
      peer.paint(g);
    paint(g);
Bryce McKinlay committed
1118
  }
1119 1120 1121 1122 1123 1124

  /**
   * Repaint this entire component.  The <code>update()</code> method
   * on this component will be called as soon as possible.
   * // FIXME: What are the coords relative to?
   */
Bryce McKinlay committed
1125 1126
  public void repaint()
  {
1127
    repaint(0, 0, 0, getWidth(), getHeight());
Bryce McKinlay committed
1128
  }
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138

  /**
   * Repaint this entire component.  The <code>update()</code> method
   * on this component will be called in approximate the specified number
   * of milliseconds.
   * // FIXME: What are the coords relative to?
   *
   * @param tm The number of milliseconds before this component should
   * be repainted.
   */
Bryce McKinlay committed
1139 1140
  public void repaint(long tm)
  {
1141
    repaint(tm, 0, 0, getWidth(), getHeight());
Bryce McKinlay committed
1142
  }
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154

  /**
   * Repaints the specified rectangular region within this component.
   * This <code>update</code> method on this component will be called as
   * soon as possible.
   * // FIXME: What are the coords relative to?
   *
   * @param x The X coordinate of the upper left of the region to repaint
   * @param y The Y coordinate of the upper left of the region to repaint
   * @param width The width of the region to repaint.
   * @param height The height of the region to repaint.
   */
Bryce McKinlay committed
1155 1156
  public void repaint(int x, int y, int width, int height)
  {
1157
    repaint(0, x, y, width, height);
Bryce McKinlay committed
1158
  }
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172

  /**
   * Repaints the specified rectangular region within this component.
   * This <code>update</code> method on this component will be called in
   * approximately the specified number of milliseconds.
   * // FIXME: What are the coords relative to?
   *
   * @param tm The number of milliseconds before this component should
   * be repainted.
   * @param x The X coordinate of the upper left of the region to repaint
   * @param y The Y coordinate of the upper left of the region to repaint
   * @param width The width of the region to repaint.
   * @param height The height of the region to repaint.
   */
Bryce McKinlay committed
1173 1174
  public void repaint(long tm, int x, int y, int width, int height)
  {    
1175 1176 1177 1178 1179 1180 1181
    // Handle lightweight repainting by forwarding to native parent
    if (isLightweight() && (parent != null))
      {
	if (parent != null)
	  parent.repaint(tm, x+getX(), y+getY(), width, height);
	return;
      }
Tom Tromey committed
1182

1183 1184
    if (peer != null)
      peer.repaint(tm, x, y, width, height);
Bryce McKinlay committed
1185
  }
Tom Tromey committed
1186

1187 1188 1189 1190 1191 1192 1193 1194
  /**
   * Prints this component.  This method is
   * provided so that printing can be done in a different manner from
   * painting.  However, the implementation in this class simply calls
   * the <code>paint()</code> method.
   *
   * @param graphics The graphics context of the print device.
   */
Bryce McKinlay committed
1195 1196
  public void print(Graphics g)
  {
1197
    paint(g);
Bryce McKinlay committed
1198
  }
Tom Tromey committed
1199

1200 1201 1202 1203 1204 1205 1206 1207
  /**
   * Prints this component, including all sub-components.  This method is
   * provided so that printing can be done in a different manner from
   * painting.  However, the implementation in this class simply calls
   * the <code>paintAll()</code> method.
   *
   * @param graphics The graphics context of the print device.
   */
Bryce McKinlay committed
1208 1209
  public void printAll(Graphics g)
  {
1210
    paintAll(g);
Bryce McKinlay committed
1211
  }
Tom Tromey committed
1212

1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
  /**
   * Called when an image has changed so that this component is
   * repainted.
   *
   * @param image The image that has been updated.
   * @param flags Flags as specified in <code>ImageObserver</code>.
   * @param x The X coordinate 
   * @param y The Y coordinate
   * @param width The width
   * @param height The height
   *
   * @return <code>true</code> if the image has been fully loaded,
   * <code>false</code> otherwise.
   */
Tom Tromey committed
1227 1228
  public boolean imageUpdate (Image img, int infoflags, int x, int y,
			      int w, int h)
Bryce McKinlay committed
1229 1230 1231 1232
  {
    // FIXME
    return false;
  }
Tom Tromey committed
1233

1234 1235 1236 1237 1238 1239 1240
  /**
   * Creates an image from the specified producer.
   *
   * @param producer The image procedure to create the image from.
   *
   * @return The resulting image.
   */
Bryce McKinlay committed
1241 1242
  public Image createImage(ImageProducer producer)
  {
1243
    return peer.createImage(producer);
Bryce McKinlay committed
1244
  }
Tom Tromey committed
1245

1246 1247 1248 1249 1250 1251 1252 1253 1254
  /**
   * Creates an image with the specified width and height for use in
   * double buffering.
   *
   * @param width The width of the image.
   * @param height The height of the image.
   *
   * @return The requested image.
   */
Bryce McKinlay committed
1255 1256
  public Image createImage(int width, int height)
  {
1257
    return getGraphicsConfiguration().createCompatibleImage(width, height);
Bryce McKinlay committed
1258
  }
Tom Tromey committed
1259

1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
  /**
   * Prepares the specified image for rendering on this component.
   *
   * @param image The image to prepare for rendering.
   * @param observer The image observer to notify of the status of the
   * image preparation.
   *
   * @return <code>true</code> if the image is already fully prepared
   * for rendering, <code>false</code> otherwise.
   */
Bryce McKinlay committed
1270 1271
  public boolean prepareImage(Image image, ImageObserver observer)
  {
1272 1273
    return prepareImage(image, image.getWidth(observer), 
			image.getHeight(observer), observer);
Bryce McKinlay committed
1274
  }
Tom Tromey committed
1275

1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
  /**
   * Prepares the specified image for rendering on this component at the
   * specified scaled width and height
   *
   * @param image The image to prepare for rendering.
   * @param width The scaled width of the image.
   * @param height The scaled height of the image.
   * @param observer The image observer to notify of the status of the
   * image preparation.
   *
   * @return <code>true</code> if the image is already fully prepared
   * for rendering, <code>false</code> otherwise.
   */
  public boolean prepareImage(Image image, int width, int height,
			      ImageObserver observer)
Bryce McKinlay committed
1291
  {
1292
    return peer.prepareImage(image, width, height, observer);
Bryce McKinlay committed
1293
  }
1294

1295 1296 1297 1298 1299 1300 1301 1302 1303 1304
  /**
   * Returns the status of the loading of the specified image. The value
   * returned will be those flags defined in <code>ImageObserver</code>.
   *
   * @param image The image to check on.
   * @param observer The observer to be notified as the image loading
   * progresses.
   *
   * @return The image observer flags indicating the status of the load.
   */
Bryce McKinlay committed
1305 1306
  public int checkImage(Image image, ImageObserver observer)
  {
1307 1308
    return checkImage(image, image.getWidth(observer), 
		      image.getHeight(observer), observer);
Bryce McKinlay committed
1309
  }
Tom Tromey committed
1310

1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
  /**
   * Returns the status of the loading of the specified image. The value
   * returned will be those flags defined in <code>ImageObserver</code>.
   *
   * @param image The image to check on.
   * @param width The scaled image width.
   * @param height The scaled image height.
   * @param observer The observer to be notified as the image loading
   * progresses.
   *
   * @return The image observer flags indicating the status of the load.
   */
  public int checkImage (Image image, int width, int height,
			 ImageObserver observer)
Bryce McKinlay committed
1325
  {
Tom Tromey committed
1326 1327 1328
    if (peer != null)
      return peer.checkImage (image, width, height, observer);
    return getToolkit ().checkImage (image, width, height, observer);
Bryce McKinlay committed
1329
  }
Tom Tromey committed
1330

1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
  /**
   * Tests whether or not the specified point is contained within this
   * component.  Coordinates are relative to this component.
   *
   * @param x The X coordinate of the point to test.
   * @param y The Y coordinate of the point to test.
   *
   * @return <code>true</code> if the point is within this component,
   * <code>false</code> otherwise.
   */
Tom Tromey committed
1341
  public boolean contains (int x, int y)
Bryce McKinlay committed
1342 1343 1344
  {
    return (x >= 0) && (y >= 0) && (x < width) && (y < height);
  }
Tom Tromey committed
1345

1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
  /**
   * Tests whether or not the specified point is contained within this
   * component.  Coordinates are relative to this component.
   *
   * @param x The X coordinate of the point to test.
   * @param y The Y coordinate of the point to test.
   *
   * @return <code>true</code> if the point is within this component,
   * <code>false</code> otherwise.
   *
   * @deprecated Deprecated in favor of <code>contains(int, int)</code>.
   */
Bryce McKinlay committed
1358 1359 1360 1361
  public boolean inside(int x, int y)
  {
    return contains(x,y);
  }
Tom Tromey committed
1362

1363 1364 1365 1366 1367 1368 1369 1370 1371
  /**
   * Tests whether or not the specified point is contained within this
   * component.  Coordinates are relative to this component.
   *
   * @param point The point to test.
   *
   * @return <code>true</code> if the point is within this component,
   * <code>false</code> otherwise.
   */
Bryce McKinlay committed
1372 1373 1374 1375
  public boolean contains(Point p)
  {
    return contains(p.x, p.y);
  }
Tom Tromey committed
1376

1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
  /**
   * Returns the component occupying the position (x,y).  This will either
   * be this component, an immediate child component, or <code>null</code>
   * if neither of the first two occupies the specified location.
   *
   * @param x The X coordinate to search for components at.
   * @param y The Y coordinate to search for components at.
   *
   * @return The component at the specified location, for <code>null</code>
   * if there is none.
   */
Bryce McKinlay committed
1388 1389 1390 1391 1392 1393
  public Component getComponentAt(int x, int y)
  {
    if (contains(x,y))
      return this;
    return null;
  }
Tom Tromey committed
1394

1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
  /**
   * Returns the component occupying the position (x,y).  This will either
   * be this component, an immediate child component, or <code>null</code>
   * if neither of the first two occupies the specified location.
   *
   * @param x The X coordinate to search for components at.
   * @param y The Y coordinate to search for components at.
   *
   * @return The component at the specified location, for <code>null</code>
   * if there is none.
   *
   * @deprecated The method is deprecated in favor of 
   * <code>getComponentAt()</code>.
   */
Bryce McKinlay committed
1409 1410 1411 1412
  public Component locate(int x, int y)
  {
    return getComponentAt(x, y);
  }
Tom Tromey committed
1413

1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
  /**
   * Returns the component occupying the specified point  This will either
   * be this component, an immediate child component, or <code>null</code>
   * if neither of the first two occupies the specified location.
   *
   * @param point The point to search for components at.
   *
   * @return The component at the specified location, for <code>null</code>
   * if there is none.
   */
Bryce McKinlay committed
1424 1425 1426 1427
  public Component getComponentAt(Point p)
  {
    return getComponentAt(p.x, p.y);
  }
Tom Tromey committed
1428

1429 1430 1431 1432 1433
  /**
   * AWT 1.0 event dispatcher.
   *
   * @deprecated Deprecated in favor of <code>dispatchEvent()</code>.
   */
Bryce McKinlay committed
1434 1435 1436
  public void deliverEvent(Event e)
  {
  }
Tom Tromey committed
1437

Bryce McKinlay committed
1438 1439 1440 1441 1442
  /** Forward AWT events to processEvent() if:
    *     - Events have been enabled for this type of event via enableEvents(),
    *   OR:
    *	 - There is at least one registered listener for this type of event
    * 
1443 1444
    * @param event The event to dispatch
    *
Bryce McKinlay committed
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
    * @specnote This method is final, but we need to be able to 
    *           override it in order to handle other event types in our 
    *	        subclasses. The solution is to define a second, non-final
    *           method - dispatchEventImpl() - to actually do the work. 
    *           Investigations with Thread.dumpStack() on the dispatch thread 
    *           in JDK 1.3 show Sun's implementation is doing the same 
    *           thing.
    */
  public final void dispatchEvent(AWTEvent e)
  {
    dispatchEventImpl(e);
1456 1457 1458 1459

    /* Give the peer a chance to handle the event. */
    if (peer != null)
      peer.handleEvent(e);
Bryce McKinlay committed
1460
  }
Tom Tromey committed
1461

Bryce McKinlay committed
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
  void dispatchEventImpl(AWTEvent e)
  {
    // Make use of event id's in order to avoid multiple instanceof tests.
    if (e.id <= ComponentEvent.COMPONENT_LAST 
        && e.id >= ComponentEvent.COMPONENT_FIRST
        && (componentListener != null 
	    || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0))
      processEvent(e);
    else if (e.id <= KeyEvent.KEY_LAST
             && e.id >= KeyEvent.KEY_FIRST
	     && (keyListener != null
		 || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0))
      processEvent(e);
    else if (e.id <= MouseEvent.MOUSE_LAST
             && e.id >= MouseEvent.MOUSE_FIRST
	     && (mouseListener != null
		 || mouseMotionListener != null
		 || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0))
      processEvent(e);
    else if (e.id <= FocusEvent.FOCUS_LAST
             && e.id >= FocusEvent.FOCUS_FIRST
	     && (focusListener != null
		 || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0))
      processEvent(e);
    else if (e.id <= InputMethodEvent.INPUT_METHOD_LAST
             && e.id >= InputMethodEvent.INPUT_METHOD_FIRST
	     && (inputMethodListener != null
		 || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0))
      processEvent(e);
    else if (e.id <= HierarchyEvent.HIERARCHY_LAST
             && e.id >= HierarchyEvent.HIERARCHY_FIRST
	     && (hierarchyListener != null
		 || hierarchyBoundsListener != null
		 || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0))
      processEvent(e);
1497 1498 1499 1500
    else if (e.id <= PaintEvent.PAINT_LAST
	     && e.id >= PaintEvent.PAINT_FIRST
	     && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0)      
      processEvent(e);
Bryce McKinlay committed
1501 1502
  }
  
1503 1504 1505 1506 1507
  /**
   * AWT 1.0 event dispatcher.
   *
   * @deprecated Deprecated in favor of <code>dispatchEvent()</code>.
   */
Bryce McKinlay committed
1508 1509 1510 1511
  public boolean postEvent(Event e)
  {
    return false;
  }
1512 1513 1514 1515 1516 1517

  /**
   * Adds the specified listener to this component.
   *
   * @param listener The new listener to add.
   */
Bryce McKinlay committed
1518 1519 1520 1521 1522 1523
  public synchronized void addComponentListener(ComponentListener l)
  {
    componentListener = AWTEventMulticaster.add(componentListener, l);
    if (componentListener != null)
      enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
  }
1524 1525 1526 1527 1528 1529

  /**
   * Removes the specified listener from the component.
   *
   * @param listener The listener to remove.
   */
Bryce McKinlay committed
1530 1531 1532 1533
  public synchronized void removeComponentListener(ComponentListener l)
  {
    componentListener = AWTEventMulticaster.remove(componentListener, l);
  }
1534 1535 1536 1537 1538 1539

  /**
   * Adds the specified listener to this component.
   *
   * @param listener The new listener to add.
   */
Bryce McKinlay committed
1540 1541 1542 1543 1544 1545
  public synchronized void addFocusListener(FocusListener l)
  {
    focusListener = AWTEventMulticaster.add(focusListener, l);
    if (focusListener != null)
      enableEvents(AWTEvent.FOCUS_EVENT_MASK);    
  }
1546 1547 1548 1549 1550 1551

  /**
   * Removes the specified listener from the component.
   *
   * @param listener The listener to remove.
   */
Bryce McKinlay committed
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
  public synchronized void removeFocusListener(FocusListener l)
  {
    focusListener = AWTEventMulticaster.remove(focusListener, l);
  }
  
  /** @since 1.3 */
  public synchronized void addHierarchyListener(HierarchyListener l)
  {
    hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
    if (hierarchyListener != null)
      enableEvents(AWTEvent.HIERARCHY_EVENT_MASK);    
  }
  
  /** @since 1.3 */
  public synchronized void removeHierarchyListener(HierarchyListener l)
  {
    hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, l);
  }

  /** @since 1.3 */
  public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener l)
  {
    hierarchyBoundsListener = 
      AWTEventMulticaster.add(hierarchyBoundsListener, l);
    if (hierarchyBoundsListener != null)
      enableEvents(AWTEvent.HIERARCHY_EVENT_MASK);    
  }

  /** @since 1.3 */
  public synchronized void 
    removeHierarchyBoundsListener(HierarchyBoundsListener l)
  {
    hierarchyBoundsListener = 
      AWTEventMulticaster.remove(hierarchyBoundsListener, l);
  }

1588 1589 1590 1591 1592
  /**
   * Adds the specified listener to this component.
   *
   * @param listener The new listener to add.
   */
Bryce McKinlay committed
1593 1594 1595 1596 1597 1598 1599
  public synchronized void addKeyListener(KeyListener l)
  {
    keyListener = AWTEventMulticaster.add(keyListener, l);
    if (keyListener != null)
      enableEvents(AWTEvent.KEY_EVENT_MASK);    
  }

1600 1601 1602 1603 1604
  /**
   * Removes the specified listener from the component.
   *
   * @param listener The listener to remove.
   */
Bryce McKinlay committed
1605 1606 1607 1608
  public synchronized void removeKeyListener(KeyListener l)
  {
    keyListener = AWTEventMulticaster.remove(keyListener, l);
  }
1609

1610 1611 1612 1613 1614
  /**
   * Adds the specified listener to this component.
   *
   * @param listener The new listener to add.
   */
Bryce McKinlay committed
1615 1616 1617 1618 1619 1620 1621
  public synchronized void addMouseListener(MouseListener l)
  {
    mouseListener = AWTEventMulticaster.add(mouseListener, l);
    if (mouseListener != null)
      enableEvents(AWTEvent.MOUSE_EVENT_MASK);    
  }

1622 1623 1624 1625 1626
  /**
   * Removes the specified listener from the component.
   *
   * @param listener The listener to remove.
   */
Bryce McKinlay committed
1627 1628 1629 1630 1631
  public synchronized void removeMouseListener(MouseListener l)
  {
    mouseListener = AWTEventMulticaster.remove(mouseListener, l);    
  }

1632 1633 1634 1635 1636
  /**
   * Adds the specified listener to this component.
   *
   * @param listener The new listener to add.
   */
Bryce McKinlay committed
1637 1638 1639 1640 1641 1642 1643
  public synchronized void addMouseMotionListener(MouseMotionListener l)
  {
    mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, l);
    if (mouseMotionListener != null)
      enableEvents(AWTEvent.MOUSE_EVENT_MASK);    
  }

1644 1645 1646 1647 1648
  /**
   * Removes the specified listener from the component.
   *
   * @param listener The listener to remove.
   */
Bryce McKinlay committed
1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
  public synchronized void removeMouseMotionListener(MouseMotionListener l)
  {
    mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
  }

  /** @since 1.2 */
  public synchronized void addInputMethodListener(InputMethodListener l)
  {
    inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
    if (inputMethodListener != null)
      enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK);    
  }

  /** @since 1.2 */
  public synchronized void removeInputMethodListener(InputMethodListener l)
  {
    inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
  }

  /** Returns all registered EventListers of the given listenerType. 
    * listenerType must be a subclass of EventListener, or a 
    * ClassClassException is thrown.
    * @since 1.3 
    */
  public EventListener[] getListeners(Class listenerType)
  {
    if (listenerType == ComponentListener.class)
      return getListenersImpl(listenerType, componentListener);
    else if (listenerType == FocusListener.class)
      return getListenersImpl(listenerType, focusListener);
    else if (listenerType == KeyListener.class)
      return getListenersImpl(listenerType, keyListener);
    else if (listenerType == MouseListener.class)
      return getListenersImpl(listenerType, mouseListener);
    else if (listenerType == MouseMotionListener.class)
      return getListenersImpl(listenerType, mouseMotionListener);
    else if (listenerType == InputMethodListener.class)
      return getListenersImpl(listenerType, inputMethodListener);
    else if (listenerType == HierarchyListener.class)
      return getListenersImpl(listenerType, hierarchyListener);
    else if (listenerType == HierarchyBoundsListener.class)
      return getListenersImpl(listenerType, hierarchyBoundsListener);
    else
      return getListenersImpl(listenerType, null);
  }
  
  static EventListener[] getListenersImpl(Class listenerType, EventListener el)
  {
    if (! EventListener.class.isAssignableFrom(listenerType))
      throw new ClassCastException();
    
    Vector v = new Vector();
    if (el != null)
      getListenerList (el, v);    
    EventListener[] el_a = (EventListener[]) Array.newInstance(listenerType, 
							       v.size());
    v.copyInto(el_a);
    return el_a;
  }
Tom Tromey committed
1708

Bryce McKinlay committed
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
  static void getListenerList(EventListener el, Vector v)
  {
    if (el instanceof AWTEventMulticaster)
      {
        AWTEventMulticaster mc = (AWTEventMulticaster) el;
        getListenerList(mc.a, v);
	getListenerList(mc.b, v);
      }
    else
      v.addElement(el);      
  }

  // The input method framework is currently unimplemented.  
  // /** @since 1.2 */
  //
  //public InputMethodRequests getInputMethodRequests()
  //
  // /** @since 1.2 */
  //
  // public InputContext getInputContext()
Tom Tromey committed
1729

1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
  /**
   * Enables the specified events.  The events to enable are specified
   * by OR-ing together the desired masks from <code>AWTEvent</code>.
   * <p>
   * Events are enabled by default when a listener is attached to the
   * component for that event type.  This method can be used by subclasses
   * to ensure the delivery of a specified event regardless of whether
   * or not a listener is attached.
   *
   * @param enable_events The desired events to enable.
   */
Bryce McKinlay committed
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
  protected final void enableEvents(long eventsToEnable)
  {
    eventMask |= eventsToEnable;
    // TODO: Unlike Sun's implementation, I think we should try and 
    // enable/disable events at the peer (gtk/X) level. This will avoid 
    // clogging the event pipeline with useless mousemove events that 
    // we arn't interested in, etc. This will involve extending the peer 
    // interface, but thats okay because the peer interfaces have been
    // deprecated for a long time, and no longer feature in the 
    // API specification at all.
1751 1752 1753

    if (isLightweight() && (parent != null))
      parent.enableEvents(eventsToEnable);
Tom Tromey committed
1754 1755
    else if (peer != null)
      peer.setEventMask (eventMask);
Bryce McKinlay committed
1756
  }
Tom Tromey committed
1757

1758 1759 1760 1761 1762 1763
  /**
   * Disables the specified events.  The events to disable are specified
   * by OR-ing together the desired masks from <code>AWTEvent</code>.
   *
   * @param disable_events The desired events to disable.
   */
Bryce McKinlay committed
1764 1765 1766 1767 1768
  protected final void disableEvents(long eventsToDisable)
  {
    eventMask &= ~eventsToDisable;
    // forward new event mask to peer?
  }
Tom Tromey committed
1769

Bryce McKinlay committed
1770 1771 1772 1773 1774 1775
  /** coalesceEvents is called by the EventQueue if two events with the same 
    * event id are queued. Returns a new combined event, or null if no 
    * combining is done. 
    */
  protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
  {
1776
    switch (existingEvent.id)
Bryce McKinlay committed
1777
      {
1778 1779 1780
      case MouseEvent.MOUSE_MOVED:
      case MouseEvent.MOUSE_DRAGGED:
	// Just drop the old (intermediate) event and return the new one.
Bryce McKinlay committed
1781
	return newEvent;
1782 1783 1784 1785
      case PaintEvent.PAINT:
      case PaintEvent.UPDATE:
	return coalescePaintEvents((PaintEvent) existingEvent,
				   (PaintEvent) newEvent);
Bryce McKinlay committed
1786 1787 1788 1789
      }
    return null;
  }
  
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
  /**
   * Coalesce paint events. Current heuristic is: Merge if the union of
   * areas is less than twice that of the sum of the areas. The X server
   * tend to create a lot of paint events that are adjacent but not
   * overlapping.
   *
   * <pre>
   * +------+
   * |      +-----+  ...will be merged
   * |      |     |
   * |      |     |
   * +------+     |
   *        +-----+
   * 
   * +---------------+--+
   * |               |  |  ...will not be merged
   * +---------------+  |
   *                 |  |
   *                 |  |
   *                 |  |
   *                 |  |
   *                 |  |
   *                 +--+
   * </pre>
   */
  private PaintEvent coalescePaintEvents(PaintEvent queuedEvent,
					 PaintEvent newEvent)
  {
    Rectangle r1 = queuedEvent.getUpdateRect();
    Rectangle r2 = newEvent.getUpdateRect();
    Rectangle union = r1.union(r2);
    
    int r1a = r1.width * r1.height;
    int r2a = r2.width * r2.height;
    int ua  = union.width * union.height;
    
    if (ua > (r1a+r2a)*2)
      return null;
    /* The 2 factor should maybe be reconsidered. Perhaps 3/2
       would be better? */

    newEvent.setUpdateRect(union);
    return newEvent;
  }

1835 1836 1837 1838 1839 1840
  /**
   * Processes the specified event.  In this class, this method simply
   * calls one of the more specific event handlers.
   * 
   * @param event The event to process.
   */
Bryce McKinlay committed
1841 1842
  protected void processEvent(AWTEvent e)
  {
1843 1844 1845 1846 1847 1848 1849

    /* Note: the order of these if statements are
       important. Subclasses must be checked first. Eg. MouseEvent
       must be checked before ComponentEvent, since a MouseEvent
       object is also an instance of a ComponentEvent. */

    if (e instanceof FocusEvent)
Bryce McKinlay committed
1850
      processFocusEvent((FocusEvent) e);
1851 1852
    else if (e instanceof PaintEvent)
      processPaintEvent((PaintEvent) e);
Bryce McKinlay committed
1853 1854 1855 1856 1857 1858 1859 1860
    else if (e instanceof MouseEvent)
      {
        if (e.id == MouseEvent.MOUSE_MOVED 
	    || e.id == MouseEvent.MOUSE_DRAGGED)
	  processMouseMotionEvent((MouseEvent) e);
	else
	  processMouseEvent((MouseEvent) e);
      }
1861 1862
    else if (e instanceof KeyEvent)
      processKeyEvent((KeyEvent) e);
Bryce McKinlay committed
1863 1864
    else if (e instanceof InputMethodEvent)
      processInputMethodEvent((InputMethodEvent) e);
1865 1866
    else if (e instanceof ComponentEvent)
      processComponentEvent((ComponentEvent) e);
Bryce McKinlay committed
1867 1868 1869 1870 1871 1872 1873 1874
    else if (e instanceof HierarchyEvent)
      {
        if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
	  processHierarchyEvent((HierarchyEvent) e);
	else
	  processHierarchyBoundsEvent((HierarchyEvent) e);
      }
  }
1875 1876 1877 1878 1879 1880 1881 1882

  /**
   * Called when a component event is dispatched and component events are
   * enabled.  This method passes the event along to any listeners
   * that are attached.
   *
   * @param event The <code>ComponentEvent</code> to process.
   */
Bryce McKinlay committed
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
  protected void processComponentEvent(ComponentEvent e)
  {
    if (componentListener == null)
      return;
    switch (e.id)
      {
        case ComponentEvent.COMPONENT_HIDDEN:
	  componentListener.componentHidden(e);
	break;
		
        case ComponentEvent.COMPONENT_MOVED:
	  componentListener.componentMoved(e);
	break;
	
	case ComponentEvent.COMPONENT_RESIZED:
	  componentListener.componentResized(e);
	break;
	
	case ComponentEvent.COMPONENT_SHOWN:
	  componentListener.componentShown(e);
	break;
      }
  }
1906 1907 1908 1909 1910 1911 1912 1913

  /**
   * Called when a focus event is dispatched and component events are
   * enabled.  This method passes the event along to any listeners
   * that are attached.
   *
   * @param event The <code>FocusEvent</code> to process.
   */
Bryce McKinlay committed
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  protected void processFocusEvent(FocusEvent e)
  {
    if (focusListener == null)
      return;
    switch (e.id)
      {
        case FocusEvent.FOCUS_GAINED:
	  focusListener.focusGained(e);
	break;
        case FocusEvent.FOCUS_LOST:
	  focusListener.focusLost(e);
	break;
      }    
  }
1928 1929 1930 1931 1932 1933 1934 1935

  /**
   * Called when a key event is dispatched and component events are
   * enabled.  This method passes the event along to any listeners
   * that are attached.
   *
   * @param event The <code>KeyEvent</code> to process.
   */
Bryce McKinlay committed
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
  protected void processKeyEvent(KeyEvent e)
  {
    if (keyListener == null)
      return;
    switch (e.id)
      {
	case KeyEvent.KEY_PRESSED:
	  keyListener.keyPressed(e);
	break;
	case KeyEvent.KEY_RELEASED:
	  keyListener.keyReleased(e);
	break;
	case KeyEvent.KEY_TYPED:
	  keyListener.keyTyped(e);
	break;
      }
  }
1953 1954 1955 1956 1957 1958 1959 1960

  /**
   * Called when a regular mouse event is dispatched and component events are
   * enabled.  This method passes the event along to any listeners
   * that are attached.
   *
   * @param event The <code>MouseEvent</code> to process.
   */
Bryce McKinlay committed
1961 1962 1963 1964 1965 1966 1967
  protected void processMouseEvent(MouseEvent e)
  {
    if (mouseListener == null)
      return;
    switch (e.id)
      {
	case MouseEvent.MOUSE_CLICKED:
1968
	  mouseListener.mouseClicked(e);
Bryce McKinlay committed
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
	break;
        case MouseEvent.MOUSE_ENTERED:
	  mouseListener.mouseEntered(e);
	break;
	case MouseEvent.MOUSE_EXITED:
	  mouseListener.mouseExited(e);
	break;
	case MouseEvent.MOUSE_PRESSED:
	  mouseListener.mousePressed(e);
	break;
	case MouseEvent.MOUSE_RELEASED:
	  mouseListener.mouseReleased(e);
	break;
      }
  }

1985 1986 1987 1988 1989 1990 1991
  /**
   * Called when a mouse motion event is dispatched and component events are
   * enabled.  This method passes the event along to any listeners
   * that are attached.
   *
   * @param event The <code>MouseMotionEvent</code> to process.
   */
Bryce McKinlay committed
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
  protected void processMouseMotionEvent(MouseEvent e)
  {
    if (mouseMotionListener == null)
      return;
    switch (e.id)
      {
	case MouseEvent.MOUSE_DRAGGED:
	  mouseMotionListener.mouseDragged(e);
	break;
        case MouseEvent.MOUSE_MOVED:
	  mouseMotionListener.mouseMoved(e);
	break;
      }	
  }
2006

Bryce McKinlay committed
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
  /** @since 1.2 */
  protected void processInputMethodEvent(InputMethodEvent e)
  {
    if (inputMethodListener == null)
      return;
    switch (e.id)
      {
	case InputMethodEvent.CARET_POSITION_CHANGED:
          inputMethodListener.caretPositionChanged(e);
	break;
	case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
          inputMethodListener.inputMethodTextChanged(e);
	break;
      }	
  }
  
  /** @since 1.3 */
  protected void processHierarchyEvent(HierarchyEvent e)
  {
    if (hierarchyListener == null)
      return;
    if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
      hierarchyListener.hierarchyChanged(e);
  }
  
  /** @since 1.3 */
  protected void processHierarchyBoundsEvent(HierarchyEvent e)
  {
    if (hierarchyBoundsListener == null)
      return;
    switch (e.id)
      {
        case HierarchyEvent.ANCESTOR_MOVED:
	  hierarchyBoundsListener.ancestorMoved(e);
	break;
	case HierarchyEvent.ANCESTOR_RESIZED:
	  hierarchyBoundsListener.ancestorResized(e);
	break;
      }
  }
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060

  private void processPaintEvent(PaintEvent event)
  {
    // Can't do graphics without peer
    if (peer == null)
      return;

    Graphics gfx = getGraphics();
    Shape clip = event.getUpdateRect();
    gfx.setClip(clip);

    switch (event.id)
      {
      case PaintEvent.PAINT:
2061
	paint(gfx);
2062 2063
	break;
      case PaintEvent.UPDATE:
2064
	update(gfx);
2065 2066 2067 2068 2069
	break;
      default:
	throw new IllegalArgumentException("unknown paint event");
      }
  }
2070 2071 2072 2073 2074 2075

  /**
   * AWT 1.0 event processor.
   *
   * @deprecated Deprecated in favor of <code>processEvent</code>.
   */
Bryce McKinlay committed
2076 2077 2078 2079
  public boolean handleEvent(Event evt)
  {
    return false;
  }
2080 2081 2082 2083 2084 2085

  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseEvent()</code>.
   */
Bryce McKinlay committed
2086 2087 2088 2089 2090
  public boolean mouseDown(Event evt, int x, int y)
  {
    return false;
  }
  
2091 2092 2093 2094 2095
  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseMotionEvent()</code>.
   */
Bryce McKinlay committed
2096 2097 2098 2099 2100
  public boolean mouseDrag(Event evt, int x, int y)
  {
    return false;
  }

2101 2102 2103 2104 2105
  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseEvent()</code>.
   */
Bryce McKinlay committed
2106 2107 2108 2109 2110
  public boolean mouseUp(Event evt, int x, int y)
  {
    return false;
  }

2111 2112 2113 2114 2115
  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseMotionEvent()</code>.
   */
Bryce McKinlay committed
2116 2117 2118 2119 2120
  public boolean mouseMove(Event evt, int x, int y)
  {
    return false;
  }

2121 2122 2123 2124 2125
  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseEvent()</code>.
   */
Bryce McKinlay committed
2126 2127 2128 2129 2130
  public boolean mouseEnter(Event evt, int x, int y)
  {
    return false;
  }

2131 2132 2133 2134 2135
  /**
   * AWT 1.0 mouse event.
   *
   * @deprecated Deprecated in favor of <code>processMouseEvent()</code>.
   */
Bryce McKinlay committed
2136 2137 2138 2139 2140
  public boolean mouseExit(Event evt, int x, int y)
  {
    return false;
  }

2141 2142 2143 2144 2145
  /**
   * AWT 1.0 key press event.
   *
   * @deprecated Deprecated in favor of <code>processKeyEvent</code>.
   */
Bryce McKinlay committed
2146 2147 2148 2149 2150
  public boolean keyDown(Event evt, int key)
  {
    return false;
  }

2151 2152 2153 2154 2155
  /**
   * AWT 1.0 key press event.
   *
   * @deprecated Deprecated in favor of <code>processKeyEvent</code>.
   */
Bryce McKinlay committed
2156 2157 2158 2159 2160
  public boolean keyUp(Event evt, int key)
  {
    return false;
  }

2161 2162 2163 2164 2165 2166
  /**
   * AWT 1.0 action event processor.
   *
   * @deprecated Deprecated in favor of the <code>ActionListener</code>
   * interface.
   */
Bryce McKinlay committed
2167 2168 2169 2170 2171
  public boolean action(Event evt, Object what)
  {
    return false;
  }

2172 2173 2174 2175 2176 2177
  /**
   * Called to inform this component it has been added to a container.
   * A native peer - if any - is created at this time.  This method is
   * called automatically by the AWT system and should not be called by
   * user level code.
   */
Bryce McKinlay committed
2178 2179
  public void addNotify()
  {
2180 2181
    if (peer == null)
      peer = getToolkit().createComponent(this);
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192

    /* Now that all the children has gotten their peers, we should
       have the event mask needed for this component and its
       lightweight subcomponents. */

    peer.setEventMask(eventMask);

    /* We do not invalidate here, but rather leave that job up to
       the peer. For efficiency, the peer can choose not to
       invalidate if it is happy with the current dimensions,
       etc. */
Bryce McKinlay committed
2193
  }
2194

2195 2196 2197 2198 2199 2200
  /**
   * Called to inform this component is has been removed from its
   * container.  Its native peer - if any - is destroyed at this time.
   * This method is called automatically by the AWT system and should
   * not be called by user level code.
   */
Bryce McKinlay committed
2201
  public void removeNotify()
2202 2203 2204 2205
  {    
    if (peer != null)
      peer.dispose();
    peer = null;
Bryce McKinlay committed
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219
  }
  
  /** @deprecated */
  public boolean gotFocus(Event evt, Object what)
  {
    return false;
  }
  
  /** @deprecated */
  public boolean lostFocus(Event evt, Object what)
  {
    return false;
  }

2220 2221 2222 2223 2224 2225 2226 2227
  /**
   * Tests whether or not this component is in the group that can
   * be traversed using the keyboard traversal mechanism (such as the TAB
   * key).
   *
   * @return <code>true</code> if the component is traversed via the TAB
   * key, <code>false</code> otherwise.
   */
Bryce McKinlay committed
2228 2229
  public boolean isFocusTraversable()
  {
Tom Tromey committed
2230
    return enabled && visible && (peer == null || peer.isFocusTraversable ());
Bryce McKinlay committed
2231
  }
Tom Tromey committed
2232

2233 2234 2235 2236 2237
  /**
   * Requests that this component be given focus.  The <code>gotFocus()</code>
   * method on this event will be called when and if this request was
   * successful.
   */
Bryce McKinlay committed
2238 2239
  public void requestFocus()
  {
Tom Tromey committed
2240 2241 2242 2243
    // If there's no peer then this component can't get the focus.  We
    // treat it as a silent rejection of the request.
    if (peer != null)
      peer.requestFocus ();
Bryce McKinlay committed
2244
  }
Tom Tromey committed
2245 2246 2247 2248 2249 2250 2251 2252 2253 2254

  // This method is used to implement transferFocus().
  // CHILD is the child making the request.
  // This is overridden by Container; when called for an ordinary
  // component there is no child and so we always return null.
  Component findNextFocusComponent (Component child)
  {
    return null;
  }

2255 2256 2257
  /**
   * Transfers focus to the next component in the focus traversal order.
   */
Bryce McKinlay committed
2258 2259
  public void transferFocus()
  {
Tom Tromey committed
2260 2261 2262 2263 2264 2265 2266
    Component next;
    if (parent == null)
      next = findNextFocusComponent (null);
    else
      next = parent.findNextFocusComponent (this);
    if (next != null && next != this)
      next.requestFocus ();
Bryce McKinlay committed
2267
  }
Tom Tromey committed
2268

2269 2270 2271 2272 2273
  /**
   * AWT 1.0 focus event processor.
   *
   * @deprecated Deprecated in favor of <code>transferFocus()</code>.
   */
Bryce McKinlay committed
2274 2275 2276 2277
  public void nextFocus()
  {
    transferFocus();
  }
Tom Tromey committed
2278

Bryce McKinlay committed
2279 2280 2281
  /** @since 1.2 */
  public boolean hasFocus()
  {
Tom Tromey committed
2282
    return hasFocus;
Bryce McKinlay committed
2283
  }
Tom Tromey committed
2284

2285 2286 2287 2288 2289
  /**
   * Adds the specified popup menu to this component.
   *
   * @param menu The popup menu to be added.
   */
Bryce McKinlay committed
2290 2291 2292 2293 2294 2295
  public synchronized void add(PopupMenu popup)
  {
    if (popups == null)
      popups = new Vector();
    popups.addElement(popup);    
  }
Tom Tromey committed
2296

2297 2298 2299 2300 2301
  /**
   * Removes the specified popup menu from this component.
   *
   * @param menu The popup menu to remove.
   */
Bryce McKinlay committed
2302 2303 2304 2305
  public synchronized void remove(MenuComponent popup)
  {
    popups.removeElement(popup);
  }
Tom Tromey committed
2306

2307 2308 2309 2310 2311
  /**
   * Returns a debugging string representing this component.
   *
   * @return A string representing this component.
   */
Bryce McKinlay committed
2312 2313
  protected String paramString()
  {
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340
    StringBuffer param = new StringBuffer();
    String name = getName();
    if (name != null)
      {
	param.append(name);
	param.append(",");
      }
    param.append(width);
    param.append("x");
    param.append(height);
    param.append("+");
    param.append(x);
    param.append("+");
    param.append(y);
    
    if (!isValid())
      param.append(",invalid");
    if (!isVisible())
      param.append(",invisible");
    if (!isEnabled())
      param.append(",disabled");
    if (!isOpaque())
      param.append(",translucent");
    if (isDoubleBuffered())
      param.append(",doublebuffered");
    
    return param.toString();
Bryce McKinlay committed
2341
  }
Tom Tromey committed
2342

2343 2344 2345 2346 2347
  /**
   * Returns a string representation of this component.
   *
   * @return A string representation of this component
   */
Bryce McKinlay committed
2348 2349
  public String toString()
  {
2350
    return this.getClass().getName() + "[" + paramString() + "]";
Bryce McKinlay committed
2351
  }
Tom Tromey committed
2352

2353 2354 2355
  /**
   * Prints a listing of this component to the standard output.
   */
Tom Tromey committed
2356
  public void list ()
Bryce McKinlay committed
2357
  {
Tom Tromey committed
2358
    list (System.out, 0);
Bryce McKinlay committed
2359
  }
Tom Tromey committed
2360

2361 2362 2363 2364 2365
  /**
   * Prints a listing of this component to the specified print stream.
   *
   * @param stream The <code>PrintStream</code> to print to.
   */
Tom Tromey committed
2366
  public void list (PrintStream out)
Bryce McKinlay committed
2367
  {
Tom Tromey committed
2368
    list (out, 0);
Bryce McKinlay committed
2369
  }
Tom Tromey committed
2370

2371 2372 2373 2374 2375 2376 2377
  /**
   * Prints a listing of this component to the specified print stream,
   * starting at the specified indentation point.
   *
   * @param stream The <code>PrintStream</code> to print to.
   * @param indent The indentation point.
   */
Tom Tromey committed
2378
  public void list (PrintStream out, int indent)
Bryce McKinlay committed
2379
  {
Tom Tromey committed
2380 2381 2382
    for (int i = 0; i < indent; ++i)
      out.print (' ');
    out.println (toString ());
Bryce McKinlay committed
2383
  }
Tom Tromey committed
2384

2385 2386 2387 2388 2389
  /**
   * Prints a listing of this component to the specified print writer.
   *
   * @param writer The <code>PrintWrinter</code> to print to.
   */
Tom Tromey committed
2390
  public void list (PrintWriter out)
Bryce McKinlay committed
2391
  {
Tom Tromey committed
2392
    list (out, 0);
Bryce McKinlay committed
2393
  }
Tom Tromey committed
2394

2395 2396 2397 2398 2399 2400 2401
  /**
   * Prints a listing of this component to the specified print writer,
   * starting at the specified indentation point.
   *
   * @param writer The <code>PrintWriter</code> to print to.
   * @param indent The indentation point.
   */
Tom Tromey committed
2402
  public void list (PrintWriter out, int indent)
Bryce McKinlay committed
2403
  {
Tom Tromey committed
2404 2405 2406
    for (int i = 0; i < indent; ++i)
      out.print (' ');
    out.println (toString ());
Bryce McKinlay committed
2407
  }
Tom Tromey committed
2408

Bryce McKinlay committed
2409 2410
  public void addPropertyChangeListener(PropertyChangeListener listener)
  {
2411 2412 2413
    if (changeSupport == null)
      changeSupport = new PropertyChangeSupport(this);
    changeSupport.addPropertyChangeListener(listener);
Bryce McKinlay committed
2414
  }
Tom Tromey committed
2415

Bryce McKinlay committed
2416 2417
  public void removePropertyChangeListener(PropertyChangeListener listener)
  {
2418 2419
    if (changeSupport != null)
      changeSupport.removePropertyChangeListener(listener);         
Bryce McKinlay committed
2420
  }
Tom Tromey committed
2421

Bryce McKinlay committed
2422 2423 2424
  public void addPropertyChangeListener(String propertyName,
                                	PropertyChangeListener listener)
  {
2425 2426 2427
    if (changeSupport == null)
      changeSupport = new PropertyChangeSupport(this);
    changeSupport.addPropertyChangeListener(propertyName, listener);  
Bryce McKinlay committed
2428
  }
Tom Tromey committed
2429

Bryce McKinlay committed
2430 2431 2432
  public void removePropertyChangeListener(String propertyName,
                                           PropertyChangeListener listener)
  {
2433 2434
    if (changeSupport != null)
      changeSupport.removePropertyChangeListener(propertyName, listener);
Bryce McKinlay committed
2435
  }
Tom Tromey committed
2436

Bryce McKinlay committed
2437 2438 2439
  protected void firePropertyChange(String propertyName, Object oldValue, 
                                    Object newValue)
  {
2440 2441
    if (changeSupport != null)
      changeSupport.firePropertyChange(propertyName, oldValue, newValue);    
Bryce McKinlay committed
2442
  }
Tom Tromey committed
2443

Bryce McKinlay committed
2444 2445
  public void setComponentOrientation(ComponentOrientation o)
  {
2446
    orientation = o;
Bryce McKinlay committed
2447
  }
2448

Bryce McKinlay committed
2449 2450
  public ComponentOrientation getComponentOrientation()
  {
2451
    return orientation;
Bryce McKinlay committed
2452
  }
2453

Bryce McKinlay committed
2454 2455 2456 2457 2458 2459
  /*
  public AccessibleContext getAccessibleContext()
  {
    return accessibleContext;
  }
  */
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484

/**
  * AWT 1.0 focus event processor.
  *
  * @deprecated Deprecated in favor of <code>processFocusEvent</code>.
  
public boolean
gotFocus(Event event, Object what)
{
  return(true);
}
*/

/**
  * AWT 1.0 focus event processor.
  *
  * @deprecated Deprecated in favor of <code>processFocusEvent</code>.
  
public boolean
lostFocus(Event event, Object what)
{
  return(true);
}
*/

2485
}