/[classpath]/classpath/java/awt/Component.java
ViewVC logotype

Diff of /classpath/java/awt/Component.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26