OSDN Git Service

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