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