home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / Component.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  112.5 KB  |  3,546 lines

  1. /*
  2.  * @(#)Component.java    1.180 98/03/18
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.io.PrintStream;
  17. import java.io.PrintWriter;
  18. import java.util.Vector;
  19. import java.util.Locale;
  20. import java.awt.peer.ComponentPeer;
  21. import java.awt.image.ImageObserver;
  22. import java.awt.image.ImageProducer;
  23. import java.awt.image.ColorModel;
  24. import java.awt.event.*;
  25. import java.awt.datatransfer.Transferable;
  26. import java.awt.dnd.DnDConstants;
  27. import java.awt.dnd.DragSource;
  28. import java.awt.dnd.DragSourceContext;
  29. import java.awt.dnd.DragSourceListener;
  30. import java.awt.dnd.InvalidDnDOperationException;
  31. import java.io.Serializable;
  32. import java.io.ObjectOutputStream;
  33. import java.io.ObjectInputStream;
  34. import java.io.IOException;
  35. import java.beans.PropertyChangeListener;
  36. import java.awt.event.InputMethodListener;
  37. import java.awt.event.InputMethodEvent;
  38. import java.awt.im.InputContext;
  39. import java.awt.im.InputMethodRequests;
  40.  
  41. import java.awt.dnd.DropTarget;
  42.  
  43. /** 
  44.  * A <em>component</em> is an object having a graphical representation 
  45.  * that can be displayed on the screen and that can interact with the 
  46.  * user. Examples of components are the buttons, checkboxes, and scrollbars 
  47.  * of a typical graphical user interface. <p>
  48.  * The <code>Component</code> class is the abstract superclass of 
  49.  * the nonmenu-related Abstract Window Toolkit components. Class 
  50.  * <code>Component</code> can also be extended directly to create a 
  51.  * lightweight component. A lightweight component is a component that is 
  52.  * not associated with a native opaque window.
  53.  *
  54.  * @version     1.180, 03/18/98
  55.  * @author     Arthur van Hoff
  56.  * @author     Sami Shaio
  57.  */
  58. public abstract class Component implements ImageObserver, MenuContainer, 
  59.     Serializable
  60. {
  61.     /**
  62.      * The peer of the component. The peer implements the component's
  63.      * behaviour. The peer is set when the Component is added to a 
  64.      * container that also is a peer.
  65.      * @see #addNotify
  66.      * @see #removeNotify
  67.      */
  68.     transient ComponentPeer peer;
  69.  
  70.     /**
  71.      * The parent of the object. It may be null for top-level components.
  72.      * @see #getParent
  73.      */
  74.     transient Container parent;
  75.  
  76.     /**
  77.      * The x position of the component in the parent's coordinate system.
  78.      * @see #getLocation
  79.      */
  80.     int x;
  81.  
  82.     /**
  83.      * The y position of the component in the parent's coordinate system.
  84.      * @see #getLocation
  85.      */
  86.     int y;
  87.  
  88.     /**
  89.      * The width of the component.
  90.      * @see #getSize
  91.      */
  92.     int width;
  93.  
  94.     /**
  95.      * The height of the component.
  96.      * @see #getSize
  97.      */
  98.     int height;
  99.  
  100.     /**
  101.      * The foreground color for this component.
  102.      * @see #getForeground
  103.      * @see #setForeground
  104.      */
  105.     Color    foreground;
  106.  
  107.     /**
  108.      * The background color for this component.
  109.      * @see #getBackground
  110.      * @see #setBackground
  111.      */
  112.     Color    background;
  113.  
  114.     /**
  115.      * The font used by this component.
  116.      * @see #getFont
  117.      * @see #setFont
  118.      */
  119.     Font    font;
  120.  
  121.     /**
  122.      * The cursor displayed when pointer is over this component.
  123.      * @see #getCursor
  124.      * @see #setCursor
  125.      */
  126.     Cursor    cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
  127.  
  128.     /**
  129.      * The locale for the component.
  130.      * @see #getLocale
  131.      * @see #setLocale
  132.      */
  133.     Locale      locale;
  134.  
  135.     /**
  136.      * True when the object is visible. An object that is not
  137.      * visible is not drawn on the screen.
  138.      * @see #isVisible
  139.      * @see #setVisible
  140.      */
  141.     boolean visible = true;
  142.  
  143.     /**
  144.      * True when the object is enabled. An object that is not
  145.      * enabled does not interact with the user.
  146.      * @see #isEnabled
  147.      * @see #setEnabled
  148.      */
  149.     boolean enabled = true;
  150.  
  151.     /**
  152.      * True when input methods are enabled for this component. If so,
  153.      * incoming events are first offered to input methods so that they
  154.      * can handle text composition.
  155.      * @see #enableInputMethods
  156.      */
  157.     boolean inputMethodsEnabled = true;
  158.  
  159.     /** 
  160.      * True when the object is valid. An invalid object needs to
  161.      * be layed out. This flag is set to false when the object
  162.      * size is changed.
  163.      * @see #isValid
  164.      * @see #validate
  165.      * @see #invalidate
  166.      */
  167.     boolean valid = false;
  168.  
  169.     /**
  170.      * The DropTarget associated with this Component.
  171.      * 
  172.      * @see #setDropTarget
  173.      * @see #getDropTarget
  174.      */
  175.     DropTarget dropTarget;
  176.  
  177.  
  178.     /**
  179.      * True if this component has enabled focus events and currently
  180.      * has the focus.
  181.      * 
  182.      * @see #hasFocus
  183.      * @see #processFocusEvent
  184.      */
  185.     boolean hasFocus = false;
  186.  
  187.  
  188.     Vector popups;
  189.  
  190.     String name;
  191.  
  192.     /**
  193.      * The locking object for AWT component-tree and layout operations.
  194.      *
  195.      * @see #getTreeLock
  196.      */
  197.     static final Object LOCK = new Object();
  198.  
  199.     /** Internal, cached size information */
  200.     Dimension minSize;
  201.  
  202.     /** Internal, cached size information */
  203.     Dimension prefSize;
  204.  
  205.     boolean newEventsOnly = false;
  206.     transient ComponentListener componentListener;
  207.     transient FocusListener focusListener;
  208.     transient KeyListener keyListener;
  209.     transient MouseListener mouseListener;
  210.     transient MouseMotionListener mouseMotionListener;
  211.     transient InputMethodListener inputMethodListener;
  212.  
  213.     /** Internal, constants for serialization */
  214.     final static String actionListenerK = "actionL";
  215.     final static String adjustmentListenerK = "adjustmentL";
  216.     final static String componentListenerK = "componentL";
  217.     final static String containerListenerK = "containerL";
  218.     final static String focusListenerK = "focusL";
  219.     final static String itemListenerK = "itemL";
  220.     final static String keyListenerK = "keyL";
  221.     final static String mouseListenerK = "mouseL";
  222.     final static String mouseMotionListenerK = "mouseMotionL";
  223.     final static String textListenerK = "textL";
  224.     final static String windowListenerK = "windowL";
  225.     final static String inputMethodListenerK = "inputMethodL";
  226.  
  227.     // The eventMask is ONLY set by subclasses via enableEvents.
  228.     // The mask should NOT be set when listeners are registered
  229.     // so that we can distinguish the difference between when
  230.     // listeners request events and subclasses request them.
  231.     long eventMask;
  232.  
  233.     /**
  234.      * Static properties for incremental drawing.
  235.      * @see #imageUpdate
  236.      */
  237.     static boolean isInc;
  238.     static int incRate;
  239.     static {
  240.     /* force the native libraries to be loaded */
  241.     Toolkit.loadLibraries();
  242.     /* initialize JNI field and method ids */
  243.     initIDs();
  244.     
  245.     String s;
  246.     try {
  247.         java.security.AccessController.beginPrivileged();
  248.         s = System.getProperty("awt.image.incrementaldraw");
  249.         isInc = (s == null || s.equals("true"));
  250.  
  251.         s = System.getProperty("awt.image.redrawrate");
  252.         incRate = (s != null) ? Integer.parseInt(s) : 100;
  253.  
  254.     } finally {
  255.         java.security.AccessController.endPrivileged();
  256.     }
  257.     }
  258.  
  259.     /**
  260.      * Ease-of-use constant for <code>getAlignmentY()</code>.  Specifies an
  261.      * alignment to the top of the component.
  262.      * @see     #getAlignmentY
  263.      */
  264.     public static final float TOP_ALIGNMENT = 0.0f;
  265.  
  266.     /**
  267.      * Ease-of-use constant for <code>getAlignmentY</code> and 
  268.      * <code>getAlignmentX</code>. Specifies an alignment to 
  269.      * the center of the component
  270.      * @see     #getAlignmentX
  271.      * @see     #getAlignmentY
  272.      */
  273.     public static final float CENTER_ALIGNMENT = 0.5f;
  274.  
  275.     /**
  276.      * Ease-of-use constant for <code>getAlignmentY</code>.  Specifies an
  277.      * alignment to the bottom of the component.
  278.      * @see     #getAlignmentY
  279.      */
  280.     public static final float BOTTOM_ALIGNMENT = 1.0f;
  281.  
  282.     /**
  283.      * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
  284.      * alignment to the left side of the component.
  285.      * @see     #getAlignmentX
  286.      */
  287.     public static final float LEFT_ALIGNMENT = 0.0f;
  288.  
  289.     /**
  290.      * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
  291.      * alignment to the right side of the component.
  292.      * @see     #getAlignmentX
  293.      */
  294.     public static final float RIGHT_ALIGNMENT = 1.0f;
  295.  
  296.     /*
  297.      * JDK 1.1 serialVersionUID 
  298.      */
  299.     private static final long serialVersionUID = -7644114512714619750L;
  300.  
  301.     /*
  302.      * If any PropertyChangeListeners have been registered, the
  303.      * changeSupport field describes them.
  304.      */
  305.     private java.beans.PropertyChangeSupport changeSupport;
  306.  
  307.     /**
  308.      * Constructs a new component. Class <code>Component</code> can be 
  309.      * extended directly to create a lightweight component that does not 
  310.      * utilize an opaque native window. A lightweight component must be 
  311.      * hosted by a native container somewhere higher up in the component 
  312.      * tree (for example, by a <code>Frame</code> object).
  313.      */
  314.     protected Component() {
  315.     }
  316.  
  317.     /**
  318.      * Gets the name of the component.
  319.      * @return This component's name.
  320.      * @see    #setName
  321.      * @since JDK1.1
  322.      */
  323.     public String getName() {
  324.         return name;
  325.     }
  326.  
  327.     /**
  328.      * Sets the name of the component to the specified string.
  329.      * @param <code>name</code>  The string that is to be this 
  330.      * component's name.
  331.      * @see #getName
  332.      * @since JDK1.1
  333.      */
  334.     public void setName(String name) {
  335.         this.name = name;
  336.     }
  337.  
  338.     /**
  339.      * Gets the parent of this component.
  340.      * @return The parent container of this component.
  341.      * @since JDK1.0
  342.      */
  343.     public Container getParent() {
  344.     return parent;
  345.     }
  346.  
  347.     /**
  348.      * @deprecated As of JDK version 1.1,
  349.      * programs should not directly manipulate peers.
  350.      * replaced by <code>boolean isDisplayable()</code>.
  351.      */
  352.     public ComponentPeer getPeer() {
  353.     return peer;
  354.     }
  355.  
  356.     /**
  357.      * Associate a DropTarget with this Component.
  358.      *
  359.      * @param dt The DropTarget
  360.      *
  361.      * @throw SecurityException
  362.      * @throw IllegalArgumentException
  363.      * @throw UnsupportedOperationException
  364.      */
  365.  
  366.     public synchronized void setDropTarget(DropTarget dt) {
  367.     if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
  368.         return;
  369.  
  370.     DropTarget old;
  371.  
  372.     if ((old = dropTarget) != null) {
  373.         if (peer != null) dropTarget.removeNotify(peer);
  374.  
  375.         DropTarget t = dropTarget;
  376.         
  377.         dropTarget = null;
  378.  
  379.         try {
  380.             t.setComponent(null);
  381.         } catch (IllegalArgumentException iae) {
  382.         // ignore it.
  383.         }
  384.     }
  385.  
  386.     // if we have a new one, and we have a peer, add it!
  387.  
  388.     if ((dropTarget = dt) != null) {
  389.         try {
  390.             dropTarget.setComponent(this);
  391.             if (peer != null) dropTarget.addNotify(peer);
  392.         } catch (IllegalArgumentException iae) {
  393.         if (old != null) {
  394.             try {
  395.                 old.setComponent(this);
  396.                 if (peer != null) dropTarget.addNotify(peer);
  397.             } catch (IllegalArgumentException iae1) {
  398.             // ignore it!
  399.             }
  400.         }
  401.         }
  402.     }
  403.     }
  404.  
  405.     /**
  406.      * Get the DropTarget associated with this Component
  407.      */
  408.  
  409.     public synchronized DropTarget getDropTarget() { return dropTarget; }
  410.  
  411.     /**
  412.      * Gets the locking object for AWT component-tree and layout
  413.      * Gets this component's locking object (the object that owns the thread 
  414.      * sychronization monitor) for AWT component-tree and layout
  415.      * operations.
  416.      * @return This component's locking object.
  417.      */
  418.     public final Object getTreeLock() {
  419.     return LOCK;
  420.     }
  421.  
  422.     /**
  423.      * Gets the toolkit of this component. Note that
  424.      * the frame that contains a component controls which
  425.      * toolkit is used by that component. Therefore if the component  
  426.      * is moved from one frame to another, the toolkit it uses may change.
  427.      * @return  The toolkit of this component.
  428.      * @since JDK1.0
  429.      */
  430.     public Toolkit getToolkit() {
  431.           ComponentPeer peer = this.peer;
  432.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)){
  433.         return peer.getToolkit();
  434.     }
  435.     Container parent = this.parent;
  436.     if (parent != null) {
  437.         return parent.getToolkit();
  438.     }
  439.     return Toolkit.getDefaultToolkit();
  440.     }
  441.  
  442.     /**
  443.      * Determines whether this component is valid. Components are 
  444.      * invalidated when they are first shown on the screen.
  445.      * @return <code>true</code> if the component is valid; <code>false</code> 
  446.      * otherwise.
  447.      * @see #validate
  448.      * @see #invalidate
  449.      * @since JDK1.0
  450.      */
  451.     public boolean isValid() {
  452.     return (peer != null) && valid;
  453.     }
  454.  
  455.     /**
  456.      * Determines whether this component is displayable. Components are 
  457.      * displayable when they are added to a displayable containment
  458.      * hierarchy.  A containment hierarchy becomes displayable
  459.      * when its root Window  object is packed or made visible.
  460.      * @return <code>true</code> if the component is displayable; 
  461.      * <code>false</code> otherwise.
  462.      * @see #addNotify
  463.      * @see #removeNotify
  464.      * @since JDK1.2
  465.      */
  466.     public boolean isDisplayable() {
  467.     return getPeer() != null;
  468.     }   
  469.  
  470.     /**
  471.      * Determines whether this component is visible. Components are 
  472.      * initially visible, with the exception of top level components such 
  473.      * as <code>Frame</code> objects.
  474.      * @return <code>true</code> if the component is visible; 
  475.      * <code>false</code> otherwise.
  476.      * @see #setVisible
  477.      * @since JDK1.0
  478.      */
  479.     public boolean isVisible() {
  480.     return visible;
  481.     }
  482.  
  483.     /**
  484.      * Determines whether this component is showing on screen. This means 
  485.      * that the component must be visible, and it must be in a container 
  486.      * that is visible and showing.
  487.      * @return <code>true</code> if the component is showing; 
  488.      * <code>false</code> otherwise.
  489.      * @see #setVisible
  490.      * @since JDK1.0
  491.      */
  492.     public boolean isShowing() {
  493.     if (visible && (peer != null)) {
  494.             Container parent = this.parent;
  495.         return (parent == null) || parent.isShowing();
  496.     }
  497.     return false;
  498.     }
  499.  
  500.     /**
  501.      * Determines whether this component is enabled. An enabled component 
  502.      * can respond to user input and generate events. Components are 
  503.      * enabled initially by default. A component may be enabled or disabled by 
  504.      * calling its <code>setEnabled</code> method.
  505.      * @return <code>true</code> if the component is enabled; 
  506.      * <code>false</code> otherwise.
  507.      * @see #setEnabled
  508.      * @since JDK1.0
  509.      */
  510.     public boolean isEnabled() {
  511.     return enabled;
  512.     }
  513.  
  514.     /**
  515.      * Enables or disables this component, depending on the value of the 
  516.      * parameter <code>b</code>. An enabled component can respond to user 
  517.      * input and generate events. Components are enabled initially by default.
  518.      * @param     <code>b</code>   If <code>true</code>, this component is 
  519.      *            enabled; otherwise this component is disabled.
  520.      * @see #isEnabled
  521.      * @since JDK1.1
  522.      */
  523.     public void setEnabled(boolean b) {
  524.         enable(b);
  525.     }
  526.  
  527.     /**
  528.      * @deprecated As of JDK version 1.1,
  529.      * replaced by <code>setEnabled(boolean)</code>.
  530.      */
  531.     public void enable() {
  532.         if (enabled != true) {
  533.         synchronized (this) {
  534.         enabled = true;
  535.         ComponentPeer peer = this.peer;
  536.         if (peer != null) {
  537.             peer.enable();
  538.         }
  539.         }
  540.     }
  541.     }
  542.  
  543.     /**
  544.      * @deprecated As of JDK version 1.1,
  545.      * replaced by <code>setEnabled(boolean)</code>.
  546.      */
  547.     public void enable(boolean b) {
  548.     if (b) {
  549.         enable();
  550.     } else {
  551.         disable();
  552.     }
  553.     }
  554.  
  555.     /**
  556.      * @deprecated As of JDK version 1.1,
  557.      * replaced by <code>setEnabled(boolean)</code>.
  558.      */
  559.     public void disable() {
  560.         if (enabled != false) {
  561.         synchronized (this) {
  562.         enabled = false;
  563.         ComponentPeer peer = this.peer;
  564.         if (peer != null) {
  565.             peer.disable();
  566.         }
  567.         }
  568.     }
  569.     }
  570.  
  571.     /**
  572.      * Enables or disables input method support for this component. If input
  573.      * method support is enabled and the component also processes key events,
  574.      * incoming events are offered to
  575.      * the current input method and will only be processed by the component or
  576.      * dispatched to its listeners if the input method does not consume them.
  577.      * By default, input method support is enabled.
  578.      *
  579.      * @param enable true to enable, false to disable.
  580.      * @see java.awt.Component#processKeyEvent
  581.      * @since JDK1.2
  582.      */
  583.     public void enableInputMethods(boolean enable) {
  584.         inputMethodsEnabled = enable;
  585.     }
  586.  
  587.     /**
  588.      * Shows or hides this component depending on the value of parameter 
  589.      * <code>b</code>.
  590.      * @param <code>b</code>  If <code>true</code>, shows this component; 
  591.      * otherwise, hides this component.
  592.      * @see #isVisible
  593.      * @since JDK1.1
  594.      */
  595.     public void setVisible(boolean b) {
  596.         show(b);
  597.     }
  598.  
  599.     /**
  600.      * @deprecated As of JDK version 1.1,
  601.      * replaced by <code>setVisible(boolean)</code>.
  602.      */
  603.     public void show() {
  604.     if (visible != true) {
  605.         synchronized (Component.LOCK) {
  606.         visible = true;
  607.                 ComponentPeer peer = this.peer;
  608.         if (peer != null) {
  609.             peer.show();
  610.             if (peer instanceof java.awt.peer.LightweightPeer) {
  611.             repaint();
  612.             }
  613.         }
  614.                 if (componentListener != null ||
  615.                     (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {                   
  616.                     ComponentEvent e = new ComponentEvent(this, 
  617.                                      ComponentEvent.COMPONENT_SHOWN);
  618.                     Toolkit.getEventQueue().postEvent(e);
  619.                 }
  620.         }
  621.             Container parent = this.parent;
  622.         if (parent != null) {
  623.         parent.invalidate();
  624.         }
  625.     }
  626.     }
  627.  
  628.     /**
  629.      * @deprecated As of JDK version 1.1,
  630.      * replaced by <code>setVisible(boolean)</code>.
  631.      */
  632.     public void show(boolean b) {
  633.     if (b) {
  634.         show();
  635.     } else {
  636.         hide();  
  637.     }
  638.     }
  639.  
  640.     /**
  641.      * @deprecated As of JDK version 1.1,
  642.      * replaced by <code>setVisible(boolean)</code>.
  643.      */
  644.     public void hide() {
  645.     if (visible != false) {
  646.         synchronized (Component.LOCK) {
  647.         visible = false;
  648.                 ComponentPeer peer = this.peer;
  649.         if (peer != null) {
  650.             peer.hide();
  651.             if (peer instanceof java.awt.peer.LightweightPeer) {
  652.             repaint();
  653.             }
  654.         }
  655.                 if (componentListener != null ||
  656.                     (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {             
  657.                     ComponentEvent e = new ComponentEvent(this, 
  658.                                      ComponentEvent.COMPONENT_HIDDEN);
  659.                     Toolkit.getEventQueue().postEvent(e);
  660.                 }
  661.         }
  662.             Container parent = this.parent;
  663.         if (parent != null) {
  664.         parent.invalidate();
  665.         }
  666.     }
  667.     }
  668.  
  669.     /**
  670.      * Gets the foreground color of this component.
  671.      * @return This component's foreground color. If this component does 
  672.      * not have a foreground color, the foreground color of its parent 
  673.      * is returned.
  674.      * @see #java.awt.Component#setForeground(java.awt.Color)
  675.      * @since JDK1.0
  676.      */
  677.     public Color getForeground() {
  678.           Color foreground = this.foreground;
  679.     if (foreground != null) {
  680.         return foreground;
  681.     }
  682.         Container parent = this.parent;
  683.     return (parent != null) ? parent.getForeground() : null;
  684.     }
  685.  
  686.     /** 
  687.      * Sets the foreground color of this component.
  688.      * @param <code>c</code> The color to become this component's 
  689.      * foreground color.
  690.      * @see #getForeground
  691.      * @since JDK1.0
  692.      */
  693.     public void setForeground(Color c) {
  694.     Color oldColor = foreground;
  695.     ComponentPeer peer = this.peer;
  696.     foreground = c;
  697.     if (peer != null) {
  698.         c = getForeground();
  699.         if (c != null) {
  700.         peer.setForeground(c);
  701.         }
  702.     }
  703.     // This is a bound property, so report the change to
  704.     // any registered listeners.  (Cheap if there are none.)
  705.     firePropertyChange("foreground", oldColor, c);
  706.     }
  707.  
  708.     /**
  709.      * Gets the background color of this component.
  710.      * @return This component's background color. If this component does 
  711.      * not have a background color, the background color of its parent 
  712.      * is returned.
  713.      * @see java.awt.Component#setBackground(java.awt.Color)
  714.      * @since JDK1.0
  715.      */
  716.     public Color getBackground() {
  717.         Color background = this.background;
  718.     if (background != null) {
  719.         return background;
  720.     }
  721.         Container parent = this.parent;
  722.     return (parent != null) ? parent.getBackground() : null;
  723.     }
  724.  
  725.     /** 
  726.      * Sets the background color of this component.
  727.      * @param <code>c</code> The color to become this component's 
  728.      * background color.
  729.      * @see #getBackground
  730.      * @since JDK1.0
  731.      */
  732.     public void setBackground(Color c) {
  733.     Color oldColor = background;
  734.     ComponentPeer peer = this.peer;
  735.     background = c;
  736.     if (peer != null) {
  737.         c = getBackground();
  738.         if (c != null) {
  739.         peer.setBackground(c);
  740.         }
  741.     }
  742.     // This is a bound property, so report the change to
  743.     // any registered listeners.  (Cheap if there are none.)
  744.     firePropertyChange("background", oldColor, c);
  745.     }
  746.  
  747.     /**
  748.      * Gets the font of this component.
  749.      * @return This component's font. If a font has not been set 
  750.      * for this component, the font of its parent is returned.
  751.      * @see #setFont
  752.      * @since JDK1.0
  753.      */
  754.     public Font getFont() {
  755.         Font font = this.font;
  756.     if (font != null) {
  757.         return font;
  758.     }
  759.         Container parent = this.parent;
  760.     return (parent != null) ? parent.getFont() : null;
  761.     }
  762.  
  763.     /** 
  764.      * Sets the font of this component.
  765.      * @param <code>f</code> The font to become this component's font.
  766.      * @see #getFont
  767.      * @since JDK1.0
  768.      */
  769.     public synchronized void setFont(Font f) {
  770.         Font oldFont = font;
  771.         ComponentPeer peer = this.peer;
  772.     font = f;
  773.     if (peer != null) {
  774.         f = getFont();
  775.         if (f != null) {
  776.         peer.setFont(f);
  777.         }
  778.     }
  779.     // This is a bound property, so report the change to
  780.     // any registered listeners.  (Cheap if there are none.)
  781.     firePropertyChange("font", oldFont, font);
  782.     }
  783.  
  784.     /**
  785.      * Gets the locale of this component.
  786.      * @return This component's locale. If this component does not 
  787.      * have a locale, the locale of its parent is returned.
  788.      * @see #setLocale
  789.      * @exception IllegalComponentStateException If the Component 
  790.      * does not have its own locale and has not yet been added to
  791.      * a containment hierarchy such that the locale can be determined
  792.      * from the containing parent.
  793.      * @since  JDK1.1
  794.      */
  795.     public Locale getLocale() {
  796.         Locale locale = this.locale;
  797.     if (locale != null) {
  798.       return locale;
  799.     }
  800.         Container parent = this.parent;
  801.  
  802.     if (parent == null) {
  803.         throw new IllegalComponentStateException("This component must have a parent in order to determine its locale");
  804.     } else {
  805.         return parent.getLocale();
  806.     }
  807.     }
  808.  
  809.     /** 
  810.      * Sets the locale of this component.
  811.      * @param <code>l</code> The locale to become this component's locale.
  812.      * @see #getLocale
  813.      * @since JDK1.1
  814.      */
  815.     public void setLocale(Locale l) {
  816.     locale = l;
  817.     }
  818.  
  819.     /**
  820.      * Gets the instance of <code>ColorModel</code> used to display 
  821.      * the component on the output device.
  822.      * @return The color model used by this component.
  823.      * @see java.awt.image.ColorModel
  824.      * @see java.awt.peer.ComponentPeer#getColorModel()
  825.      * @see java.awt.Toolkit#getColorModel()
  826.      * @since JDK1.0
  827.      */
  828.     public ColorModel getColorModel() {
  829.         ComponentPeer peer = this.peer;
  830.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)) {
  831.         return peer.getColorModel();
  832.     }
  833.     return getToolkit().getColorModel();
  834.     }
  835.  
  836.     /** 
  837.      * Gets the location of this component in the form of a 
  838.      * point specifying the component's top-left corner.
  839.      * The location will be relative to the parent's coordinate space.
  840.      * @return An instance of <code>Point</code> representing 
  841.      * the top-left corner of the component's bounds in the coordinate 
  842.      * space of the component's parent.
  843.      * @see #setLocation
  844.      * @see #getLocationOnScreen
  845.      * @since JDK1.1
  846.      */
  847.     public Point getLocation() {
  848.     return location();
  849.     }
  850.  
  851.     /** 
  852.      * Gets the location of this component in the form of a point 
  853.      * specifying the component's top-left corner in the screen's 
  854.      * coordinate space.
  855.      * @return An instance of <code>Point</code> representing 
  856.      * the top-left corner of the component's bounds in the 
  857.      * coordinate space of the screen.
  858.      * @see #setLocation
  859.      * @see #getLocation
  860.      */
  861.     public Point getLocationOnScreen() {
  862.     synchronized (Component.LOCK) {
  863.         if (peer != null && isShowing()) {
  864.         if (peer instanceof java.awt.peer.LightweightPeer) {
  865.             // lightweight component location needs to be translated 
  866.             // relative to a native component.
  867.             Container host = getNativeContainer();
  868.             Point pt = host.peer.getLocationOnScreen();
  869.             for(Component c = this; c != host; c = c.getParent()) {
  870.             pt.x += c.x;
  871.             pt.y += c.y;
  872.             }
  873.             return pt;
  874.         } else {
  875.             Point pt = peer.getLocationOnScreen();
  876.             return pt;
  877.         }
  878.         } else {
  879.             throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
  880.         }
  881.     }
  882.     }
  883.  
  884.  
  885.     /** 
  886.      * @deprecated As of JDK version 1.1,
  887.      * replaced by <code>getLocation()</code>.
  888.      */
  889.     public Point location() {
  890.     return new Point(x, y);
  891.     }
  892.  
  893.     /** 
  894.      * Moves this component to a new location. The top-left corner of 
  895.      * the new location is specified by the <code>x</code> and <code>y</code> 
  896.      * parameters in the coordinate space of this component's parent.
  897.      * @param <code>x</code> The <i>x</i>-coordinate of the new location's 
  898.      * top-left corner in the parent's coordinate space.
  899.      * @param <code>y</code> The <i>y</i>-coordinate of the new location's 
  900.      * top-left corner in the parent's coordinate space.
  901.      * @see #getLocation
  902.      * @see #setBounds
  903.      * @since JDK1.1
  904.      */
  905.     public void setLocation(int x, int y) {
  906.     move(x, y);
  907.     }
  908.  
  909.     /**
  910.      * @deprecated As of JDK version 1.1, 
  911.      * replaced by <code>setLocation(int, int)</code>.
  912.      */
  913.     public void move(int x, int y) {
  914.     setBounds(x, y, width, height);
  915.     }
  916.  
  917.     /** 
  918.      * Moves this component to a new location. The top-left corner of 
  919.      * the new location is specified by point <code>p</code>. Point 
  920.      * <code>p</code> is given in the parent's coordinate space.
  921.      * @param <code>p</code> The point defining the top-left corner 
  922.      * of the new location, given in the coordinate space of this 
  923.      * component's parent.
  924.      * @see #getLocation
  925.      * @see #setBounds
  926.      * @since JDK1.1
  927.      */
  928.     public void setLocation(Point p) {
  929.         setLocation(p.x, p.y);
  930.     }
  931.  
  932.     /** 
  933.      * Returns the size of this component in the form of a 
  934.      * <code>Dimension</code> object. The <code>height</code> 
  935.      * field of the <code>Dimension</code> object contains 
  936.      * this component's height, and the <code>width</code> 
  937.      * field of the <code>Dimension</code> object contains 
  938.      * this component's width.
  939.      * @return A <code>Dimension</code> object that indicates the 
  940.      * size of this component.
  941.      * @see #setSize
  942.      * @since JDK1.1
  943.      */
  944.     public Dimension getSize() {
  945.     return size();
  946.     }
  947.  
  948.     /** 
  949.      * @deprecated As of JDK version 1.1,
  950.      * replaced by <code>getSize()</code>.
  951.      */
  952.     public Dimension size() {
  953.     return new Dimension(width, height);
  954.     }
  955.  
  956.     /**
  957.      * Resizes this component so that it has width <code>width</code> 
  958.      * and <code>height</code>.
  959.      * @param <code>width</code> The new width of this component in pixels.
  960.      * @param <code>height</code> The new height of this component in pixels.
  961.      * @see #getSize
  962.      * @see #setBounds
  963.      * @since JDK1.1
  964.      */
  965.     public void setSize(int width, int height) {
  966.     resize(width, height);
  967.     }
  968.  
  969.     /**
  970.      * @deprecated As of JDK version 1.1,
  971.      * replaced by <code>setSize(int, int)</code>.
  972.      */
  973.     public void resize(int width, int height) {
  974.     setBounds(x, y, width, height);
  975.     }
  976.  
  977.     /** 
  978.      * Resizes this component so that it has width <code>d.width</code> 
  979.      * and height <code>d.height</code>.
  980.      * @param <code>d</code> The dimension specifying the new size 
  981.      * of this component.
  982.      * @see #setSize
  983.      * @see #setBounds
  984.      * @since JDK1.1
  985.      */
  986.     public void setSize(Dimension d) {
  987.     resize(d);
  988.     }
  989.  
  990.     /** 
  991.      * @deprecated As of JDK version 1.1,
  992.      * replaced by <code>setSize(Dimension)</code>.
  993.      */
  994.     public void resize(Dimension d) {
  995.     setSize(d.width, d.height);
  996.     }
  997.  
  998.     /** 
  999.      * Gets the bounds of this component in the form of a 
  1000.      * <code>Rectangle</code> object. The bounds specify this 
  1001.      * component's width, height, and location relative to 
  1002.      * its parent.
  1003.      * @return A rectangle indicating this component's bounds.
  1004.      * @see #setBounds
  1005.      * @see #getLocation
  1006.      * @see #getSize
  1007.      */
  1008.     public Rectangle getBounds() {
  1009.     return bounds();
  1010.     }
  1011.  
  1012.     /**
  1013.      * @deprecated As of JDK version 1.1, 
  1014.      * replaced by <code>getBounds()</code>.
  1015.      */
  1016.     public Rectangle bounds() {
  1017.     return new Rectangle(x, y, width, height);
  1018.     }
  1019.  
  1020.     /** 
  1021.      * Moves and resizes this component. The new location of the top-left 
  1022.      * corner is specified by <code>x</code> and <code>y</code>, and the 
  1023.      * new size is specified by <code>width</code> and <code>height</code>.
  1024.      * @param <code>x</code> The new <i>x</i>-coordinate of this component.
  1025.      * @param <code>y</code> The new <i>y</i>-coordinate of this component.
  1026.      * @param <code>width</code> The new <code>width</code> of this component.
  1027.      * @param <code>height</code> The new <code>height</code> of this 
  1028.      * component.
  1029.      * @see java.awt.Component#getBounds
  1030.      * @see java.awt.Component#setLocation(int, int)
  1031.      * @see java.awt.Component#setLocation(java.awt.Point)
  1032.      * @see java.awt.Component#setSize(int, int)
  1033.      * @see java.awt.Component#setSize(java.awt.Dimension)
  1034.      * @JDK1.1
  1035.      */
  1036.     public void setBounds(int x, int y, int width, int height) {
  1037.     reshape(x, y, width, height);
  1038.     }
  1039.  
  1040.     /** 
  1041.      * @deprecated As of JDK version 1.1,
  1042.      * replaced by <code>setBounds(int, int, int, int)</code>.
  1043.      */
  1044.     public void reshape(int x, int y, int width, int height) {
  1045.     synchronized (Component.LOCK) {
  1046.         boolean resized = (this.width != width) || (this.height != height);
  1047.             boolean moved = (this.x != x) || (this.y != y);
  1048.         boolean isLightweight = peer instanceof java.awt.peer.LightweightPeer;
  1049.  
  1050.         if (resized || moved) {
  1051.         if (isLightweight && visible) {
  1052.                     // Have the parent redraw the area this component occupied.
  1053.             repaint();
  1054.         }
  1055.         this.x = x;
  1056.         this.y = y;
  1057.         this.width = width;
  1058.         this.height = height;
  1059.         if (peer != null) {
  1060.             if (isLightweight) {
  1061.             peer.setBounds(x, y, width, height);
  1062.             } else {
  1063.             // native peer might be offset by more than direct
  1064.             // parent since parent might be lightweight.
  1065.             int nativeX = x;
  1066.             int nativeY = y;
  1067.             for(Component c = parent; (c != null) &&
  1068.                 (c.peer instanceof java.awt.peer.LightweightPeer); 
  1069.                 c = c.parent) {
  1070.  
  1071.                 nativeX += c.x;
  1072.                 nativeY += c.y;
  1073.             }
  1074.             peer.setBounds(nativeX, nativeY, width, height);
  1075.             }
  1076.             if (resized) {
  1077.             invalidate();
  1078.         
  1079.                         if (componentListener != null ||
  1080.                            (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
  1081.                             ComponentEvent e = new ComponentEvent(this, 
  1082.                                      ComponentEvent.COMPONENT_RESIZED);
  1083.                             Toolkit.getEventQueue().postEvent(e);
  1084.                         }
  1085.             }
  1086.                     if (moved && 
  1087.                         (componentListener != null ||
  1088.                          (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)) {
  1089.                             ComponentEvent e = new ComponentEvent(this, 
  1090.                                      ComponentEvent.COMPONENT_MOVED);
  1091.                             Toolkit.getEventQueue().postEvent(e);
  1092.                     }
  1093.             if (parent != null && parent.valid) {
  1094.             parent.invalidate();
  1095.             }
  1096.         }
  1097.                 if (isLightweight && visible) {
  1098.                     // Have the parent redraw the area this component *now* occupies.
  1099.                     repaint();
  1100.                 }
  1101.         }
  1102.     }
  1103.     }
  1104.  
  1105.     /** 
  1106.      * Moves and resizes this component to conform to the new 
  1107.      * bounding rectangle <code>r</code>. This component's new 
  1108.      * position is specified by <code>r.x</code> and <code>r.y</code>, 
  1109.      * and its new size is specified by <code>r.width</code> and 
  1110.      * <code>r.height</code>
  1111.      * @param <code>r<code> The new bounding rectangle for this component.
  1112.      * @see       java.awt.Component#getBounds
  1113.      * @see       java.awt.Component#setLocation(int, int)
  1114.      * @see       java.awt.Component#setLocation(java.awt.Point)
  1115.      * @see       java.awt.Component#setSize(int, int)
  1116.      * @see       java.awt.Component#setSize(java.awt.Dimension)
  1117.      * @since     JDK1.1
  1118.      */
  1119.     public void setBounds(Rectangle r) {
  1120.         setBounds(r.x, r.y, r.width, r.height);
  1121.     }
  1122.  
  1123.  
  1124.     /** 
  1125.      * Return the current x coordinate of the components origin.
  1126.      * This method is preferable to writing component.getBounds().x,
  1127.      * or component.getLocation().x because it doesn't cause any
  1128.      * heap allocations.
  1129.      * 
  1130.      * @return the current x coordinate of the components origin.
  1131.      * @since JDK1.2
  1132.      */
  1133.     public int getX() { 
  1134.     return x; 
  1135.     }
  1136.  
  1137.  
  1138.     /** 
  1139.      * Return the current y coordinate of the components origin.
  1140.      * This method is preferable to writing component.getBounds().y,
  1141.      * or component.getLocation().y because it doesn't cause any
  1142.      * heap allocations.
  1143.      * 
  1144.      * @return the current y coordinate of the components origin.
  1145.      * @since JDK1.2
  1146.      */
  1147.     public int getY() { 
  1148.     return y; 
  1149.     }
  1150.  
  1151.  
  1152.     /** 
  1153.      * Return the current width of this component.
  1154.      * This method is preferable to writing component.getBounds().width,
  1155.      * or component.getSize().width because it doesn't cause any
  1156.      * heap allocations.
  1157.      * 
  1158.      * @return the current width of this component.
  1159.      * @since JDK1.2
  1160.      */
  1161.     public int getWidth() { 
  1162.     return width; 
  1163.     }
  1164.  
  1165.  
  1166.     /** 
  1167.      * Return the current height of this component.
  1168.      * This method is preferable to writing component.getBounds().height,
  1169.      * or component.getSize().height because it doesn't cause any
  1170.      * heap allocations.
  1171.      * 
  1172.      * @return the current height of this component.
  1173.      * @since JDK1.2
  1174.      */
  1175.     public int getHeight() { 
  1176.     return height; 
  1177.     }
  1178.  
  1179.  
  1180.     /**
  1181.      * Returns true if this component is completely opaque, returns
  1182.      * false by default.
  1183.      * <p>
  1184.      * An opaque component paints every pixel within its
  1185.      * rectangular region. A non-opaque component paints only some of
  1186.      * its pixels, allowing the pixels underneath it to "show through".
  1187.      * A component that does not fully paint its pixels therefore
  1188.      * provides a degree of transparency.  Only lightweight
  1189.      * components can be transparent.
  1190.      * <p>
  1191.      * Subclasses that guarantee to always completely paint their 
  1192.      * contents should override this method and return true.  All
  1193.      * of the "heavyweight" AWT components are opaque.
  1194.      * 
  1195.      * @return true if this component is completely opaque.
  1196.      * @see #isLightweight
  1197.      * @since JDK1.2
  1198.      */
  1199.     public boolean isOpaque() {
  1200.     return !isLightweight();
  1201.     }
  1202.  
  1203.  
  1204.     /**
  1205.      * A lightweight component doesn't have a native toolkit peer.
  1206.      * Subclasses of Component and Container, other than the ones
  1207.      * defined in this package like Button or Scrollbar, are lightweight.
  1208.      * All of the Swing components are lightweights.
  1209.      * 
  1210.      * @return true if this component doesn't have a native peer
  1211.      * @since JDK1.2
  1212.      */
  1213.     public boolean isLightweight() {
  1214.         return getPeer() instanceof java.awt.peer.LightweightPeer;
  1215.     }
  1216.  
  1217.  
  1218.     /** 
  1219.      * Gets the preferred size of this component.
  1220.      * @return A dimension object indicating this component's preferred size.
  1221.      * @see #getMinimumSize
  1222.      * @see java.awt.LayoutManager
  1223.      */
  1224.     public Dimension getPreferredSize() {
  1225.     return preferredSize();
  1226.     }
  1227.  
  1228.  
  1229.     /**
  1230.      * @deprecated As of JDK version 1.1,
  1231.      * replaced by <code>getPreferredSize()</code>.
  1232.      */
  1233.     public Dimension preferredSize() {
  1234.     /* Avoid grabbing the lock if a reasonable cached size value
  1235.          * is available.
  1236.      */
  1237.  
  1238.         Dimension dim = prefSize;
  1239.         if (dim != null && isValid()) {
  1240.         return dim;
  1241.     }
  1242.         
  1243.     synchronized (Component.LOCK) {
  1244.         prefSize = (peer != null) ?
  1245.                peer.preferredSize() :
  1246.                getMinimumSize();
  1247.         return prefSize;
  1248.     }
  1249.     }
  1250.  
  1251.     /**
  1252.      * Gets the mininimum size of this component.
  1253.      * @return A dimension object indicating this component's minimum size.
  1254.      * @see #getPreferredSize
  1255.      * @see java.awtLayoutManager
  1256.      */
  1257.     public Dimension getMinimumSize() {
  1258.           return minimumSize();
  1259.     }
  1260.  
  1261.     /**
  1262.      * @deprecated As of JDK version 1.1,
  1263.      * replaced by <code>getMinimumSize()</code>.
  1264.      */
  1265.     public Dimension minimumSize() {
  1266.     /* Avoid grabbing the lock if a reasonable cached size value
  1267.          * is available.
  1268.      */
  1269.         Dimension dim = minSize;
  1270.         if (dim != null && isValid()) {
  1271.         return dim;
  1272.     }
  1273.     synchronized (Component.LOCK) {
  1274.         minSize = (peer != null) ?
  1275.               peer.minimumSize() :
  1276.               size();
  1277.         return minSize;
  1278.     }
  1279.     }
  1280.  
  1281.     /** 
  1282.      * Gets the maximum size of this component.
  1283.      * @return A dimension object indicating this component's maximum size.
  1284.      * @see #getMinimumSize
  1285.      * @see #getPreferredSize
  1286.      * @see LayoutManager
  1287.      */
  1288.     public Dimension getMaximumSize() {
  1289.     return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
  1290.     }
  1291.  
  1292.     /**
  1293.      * Returns the alignment along the x axis.  This specifies how
  1294.      * the component would like to be aligned relative to other 
  1295.      * components.  The value should be a number between 0 and 1
  1296.      * where 0 represents alignment along the origin, 1 is aligned
  1297.      * the furthest away from the origin, 0.5 is centered, etc.
  1298.      */
  1299.     public float getAlignmentX() {
  1300.     return CENTER_ALIGNMENT;
  1301.     }
  1302.  
  1303.     /**
  1304.      * Returns the alignment along the y axis.  This specifies how
  1305.      * the component would like to be aligned relative to other 
  1306.      * components.  The value should be a number between 0 and 1
  1307.      * where 0 represents alignment along the origin, 1 is aligned
  1308.      * the furthest away from the origin, 0.5 is centered, etc.
  1309.      */
  1310.     public float getAlignmentY() {
  1311.     return CENTER_ALIGNMENT;
  1312.     }
  1313.  
  1314.     /**
  1315.      * Prompts the layout manager to lay out this component. This is 
  1316.      * usually called when the component (more specifically, container) 
  1317.      * is validated.
  1318.      * @see #validate
  1319.      * @see LayoutManager
  1320.      */
  1321.     public void doLayout() {
  1322.         layout();
  1323.     }
  1324.  
  1325.     /**
  1326.      * @deprecated As of JDK version 1.1,
  1327.      * replaced by <code>doLayout()</code>.
  1328.      */
  1329.     public void layout() {
  1330.     }
  1331.  
  1332.     /** 
  1333.      * Ensures that this component has a valid layout.  This method is
  1334.      * primarily intended to operate on instances of <code>Container</code>.
  1335.      * @see       java.awt.Component#invalidate      
  1336.      * @see       java.awt.Component#doLayout()
  1337.      * @see       java.awt.LayoutManager
  1338.      * @see       java.awt.Container#validate  
  1339.      * @since     JDK1.0
  1340.      */
  1341.     public void validate() {
  1342.     if (!valid) {
  1343.         synchronized (Component.LOCK) {
  1344.         valid = true;
  1345.         }
  1346.     }
  1347.     }
  1348.  
  1349.     /** 
  1350.      * Invalidates this component.  This component and all parents
  1351.      * above it are marked as needing to be laid out.  This method can
  1352.      * be called often, so it needs to execute quickly.
  1353.      * @see       java.awt.Component#validate
  1354.      * @see       java.awt.Component#doLayout
  1355.      * @see       java.awt.LayoutManager
  1356.      * @since     JDK1.0
  1357.      */
  1358.     public void invalidate() {
  1359.     synchronized (Component.LOCK) {
  1360.         /* Nullify cached layout and size information.
  1361.          * For efficiency, propagate invalidate() upwards only if
  1362.          * some other component hasn't already done so first.
  1363.              */
  1364.         valid = false;
  1365.             prefSize = null;
  1366.             minSize = null;
  1367.         if (parent != null && parent.valid) {
  1368.         parent.invalidate();
  1369.         }
  1370.     }
  1371.     }
  1372.  
  1373.     /**
  1374.      * Creates a graphics context for this component. This method will
  1375.      * return <code>null</code> if this component is currently not on 
  1376.      * the screen.
  1377.      * @return A graphics context for this component, or <code>null</code>
  1378.      *             if it has none.
  1379.      * @see       java.awt.Component#paint
  1380.      * @since     JDK1.0
  1381.      */
  1382.     public Graphics getGraphics() {
  1383.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1384.         // This is for a lightweight component, need to 
  1385.         // translate coordinate spaces and clip relative
  1386.         // to the parent.
  1387.         Graphics g = parent.getGraphics();
  1388.         g.translate(x,y);
  1389.         g.setClip(0, 0, width, height);
  1390.         return g;
  1391.     } else {
  1392.         ComponentPeer peer = this.peer;
  1393.         return (peer != null) ? peer.getGraphics() : null;
  1394.     }
  1395.     }
  1396.  
  1397.     /**
  1398.      * Gets the font metrics for the specified font.
  1399.      * @param <code>font</code> The font for which font metrics is to be 
  1400.      * obtained.
  1401.      * @return The font metrics for <code>font</code>.
  1402.      * @param     font   the font.
  1403.      * @return    the font metrics for the specified font.
  1404.      * @see       java.awt.Component#getFont
  1405.      * @see       java.awt.Component#getPeer()
  1406.      * @see       java.awt.peer.ComponentPeer#getFontMetrics(java.awt.Font)
  1407.      * @see       java.awt.Toolkit#getFontMetrics(java.awt.Font)
  1408.      * @since     JDK1.0
  1409.      */
  1410.     public FontMetrics getFontMetrics(Font font) {
  1411.         ComponentPeer peer = this.peer;
  1412.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)) {
  1413.         return peer.getFontMetrics(font);
  1414.     }
  1415.         /*
  1416.          * If the component is being rendered offscreen then it is wrong to
  1417.          * get font metrics from the FontPeer (via Toolkit) because the new
  1418.          * font metrics model is invoked, which does not rely on native
  1419.          * FontPeer. Font metrics should be gotten from the graphics instead,
  1420.          * which knows if new mechanism for font metrics has been invoked.
  1421.          * REMIND jk. 10/21/97. Ultimately get rid of FontPeer stuff.
  1422.          */
  1423.         if (parent != null) {
  1424.             Graphics g = parent.getGraphics();
  1425.             if (g != null) {
  1426.                 return g.getFontMetrics(font);
  1427.             }
  1428.         }
  1429.         return getToolkit().getFontMetrics(font);
  1430.     }
  1431.  
  1432.     /**
  1433.      * Set the cursor image to a predefined cursor.
  1434.      * @param <code>cursor</code> One of the constants defined 
  1435.      *            by the <code>Cursor</code> class.
  1436.      * @see       java.awt.Component#getCursor
  1437.      * @see       java.awt.Cursor
  1438.      * @since     JDK1.1
  1439.      */
  1440.     public synchronized void setCursor(Cursor cursor) {
  1441.     this.cursor = cursor;
  1442.         ComponentPeer peer = this.peer;
  1443.     if (peer != null) {
  1444.         peer.setCursor(cursor);
  1445.     }
  1446.     }
  1447.  
  1448.     /**
  1449.      * Gets the cursor set on this component.
  1450.      * @return     The cursor for this component.
  1451.      * @see        java.awt.Component#setCursor
  1452.      * @see        java.awt.Cursor
  1453.      * @since      JDK1.1
  1454.      */
  1455.     public Cursor getCursor() {
  1456.     return cursor;
  1457.     }
  1458.  
  1459.     /** 
  1460.      * Paints this component.  This method is called when the contents
  1461.      * of the component should be painted in response to the component
  1462.      * first being shown or damage needing repair.  The clip rectangle
  1463.      * in the Graphics parameter will be set to the area which needs
  1464.      * to be painted.
  1465.      * @param <code>g</code> The graphics context to use for painting.
  1466.      * @see       java.awt.Component#update
  1467.      * @since     JDK1.0
  1468.      */
  1469.     public void paint(Graphics g) {
  1470.     }
  1471.  
  1472.     /** 
  1473.      * Updates this component. 
  1474.      * <p>
  1475.      * The AWT calls the <code>update</code> method in response to a 
  1476.      * call to <code>repaint</code. The appearance of the 
  1477.      * component on the screen has not changed since the last call to 
  1478.      * <code>update</code> or <code>paint</code>. You can assume that
  1479.      * the background is not cleared.  
  1480.      * <p>
  1481.      * The <code>update</code>method of <code>Component</code>
  1482.      * does the following: 
  1483.      * <p>
  1484.      * <blockquote><ul>
  1485.      * <li>Clears this component by filling it 
  1486.      *      with the background color.
  1487.      * <li>Sets the color of the graphics context to be 
  1488.      *     the foreground color of this component.
  1489.      * <li>Calls this component's <code>paint</code> 
  1490.      *     method to completely redraw this component.
  1491.      * </ul></blockquote>
  1492.      * <p>
  1493.      * The origin of the graphics context, its 
  1494.      * (<code>0</code>, <code>0</code>) coordinate point, is the 
  1495.      * top-left corner of this component. The clipping region of the 
  1496.      * graphics context is the bounding rectangle of this component. 
  1497.      * @param g the specified context to use for updating.
  1498.      * @see       java.awt.Component#paint
  1499.      * @see       java.awt.Component#repaint()
  1500.      * @since     JDK1.0
  1501.      */
  1502.     public void update(Graphics g) {
  1503.     if (! (peer instanceof java.awt.peer.LightweightPeer)) {
  1504.         g.clearRect(0, 0, width, height);
  1505.     }
  1506.     paint(g);
  1507.     }
  1508.  
  1509.     /**
  1510.      * Paints this component and all of its subcomponents. 
  1511.      * <p>
  1512.      * The origin of the graphics context, its 
  1513.      * (<code>0</code>, <code>0</code>) coordinate point, is the 
  1514.      * top-left corner of this component. The clipping region of the 
  1515.      * graphics context is the bounding rectangle of this component. 
  1516.      * @param     g   the graphics context to use for painting.
  1517.      * @see       java.awt.Component#paint
  1518.      * @since     JDK1.0
  1519.      */
  1520.     public void paintAll(Graphics g) {
  1521.     ComponentPeer peer = this.peer;
  1522.     if (visible && (peer != null)) {
  1523.         validate();
  1524.         if (peer instanceof java.awt.peer.LightweightPeer) {
  1525.         paint(g);
  1526.         } else {
  1527.         peer.paint(g);
  1528.         }
  1529.     }
  1530.     }
  1531.  
  1532.     /** 
  1533.      * Repaints this component. 
  1534.      * <p>
  1535.      * This method causes a call to this component's <code>update</code> 
  1536.      * method as soon as possible. 
  1537.      * @see       java.awt.Component#update(java.awt.Graphics)
  1538.      * @since     JDK1.0
  1539.      */
  1540.     public void repaint() {
  1541.     repaint(0, 0, 0, width, height);
  1542.     }
  1543.  
  1544.     /** 
  1545.      * Repaints the component. This will result in a
  1546.      * call to <code>update</code> within <em>tm</em> milliseconds.
  1547.      * @param tm maximum time in milliseconds before update
  1548.      * @see #paint
  1549.      * @see java.awt.Component#update(java.awt.Graphics)
  1550.      * @since JDK1.0
  1551.      */
  1552.     public void repaint(long tm) {
  1553.     repaint(tm, 0, 0, width, height);
  1554.     }
  1555.  
  1556.     /** 
  1557.      * Repaints the specified rectangle of this component. 
  1558.      * <p>
  1559.      * This method causes a call to this component's <code>update</code> 
  1560.      * method as soon as possible. 
  1561.      * @param     x   the <i>x</i> coordinate.
  1562.      * @param     y   the <i>y</i> coordinate.
  1563.      * @param     width   the width.
  1564.      * @param     height  the height.
  1565.      * @see       java.awt.Component#update(java.awt.Graphics)
  1566.      * @since     JDK1.0
  1567.      */
  1568.     public void repaint(int x, int y, int width, int height) {
  1569.     repaint(0, x, y, width, height);
  1570.     }
  1571.  
  1572.     /** 
  1573.      * Repaints the specified rectangle of this component within 
  1574.      * <code>tm</code> milliseconds. 
  1575.      * <p>
  1576.      * This method causes a call to this component's 
  1577.      * <code>update</code> method. 
  1578.      * @param     tm   maximum time in milliseconds before update.
  1579.      * @param     x    the <i>x</i> coordinate.
  1580.      * @param     y    the <i>y</i> coordinate.
  1581.      * @param     width    the width.
  1582.      * @param     height   the height.
  1583.      * @see       java.awt.Component#update(java.awt.Graphics)
  1584.      * @since     JDK1.0
  1585.      */
  1586.     public void repaint(long tm, int x, int y, int width, int height) {
  1587.     if (this.peer instanceof java.awt.peer.LightweightPeer) {
  1588.         // Needs to be translated to parent coordinates since
  1589.         // a parent native container provides the actual repaint
  1590.         // services.  Additionally, the request is restricted to
  1591.         // the bounds of the component.
  1592.         int px = this.x + ((x < 0) ? 0 : x);
  1593.         int py = this.y + ((y < 0) ? 0 : y);
  1594.         int pwidth = (width > this.width) ? this.width : width;
  1595.         int pheight = (height > this.height) ? this.height : height;
  1596.         parent.repaint(tm, px, py, pwidth, pheight);
  1597.     } else {
  1598.         ComponentPeer peer = this.peer;
  1599.         if ((peer != null) && (width > 0) && (height > 0)) {
  1600.         peer.repaint(tm, x, y, width, height);
  1601.         }
  1602.     }
  1603.     }
  1604.  
  1605.     /**
  1606.      * Prints this component. Applications should override this method 
  1607.      * for components that must do special processing before being 
  1608.      * printed or should be printed differently than they are painted. 
  1609.      * <p>
  1610.      * The default implementation of this method calls the 
  1611.      * <code>paint</code> method. 
  1612.      * <p>
  1613.      * The origin of the graphics context, its 
  1614.      * (<code>0</code>, <code>0</code>) coordinate point, is the 
  1615.      * top-left corner of this component. The clipping region of the 
  1616.      * graphics context is the bounding rectangle of this component. 
  1617.      * @param     g   the graphics context to use for printing.
  1618.      * @see       java.awt.Component#paint(java.awt.Graphics)
  1619.      * @since     JDK1.0
  1620.      */
  1621.     public void print(Graphics g) {
  1622.     paint(g);
  1623.     }
  1624.  
  1625.     /**
  1626.      * Prints this component and all of its subcomponents. 
  1627.      * <p>
  1628.      * The origin of the graphics context, its 
  1629.      * (<code>0</code>, <code>0</code>) coordinate point, is the 
  1630.      * top-left corner of this component. The clipping region of the 
  1631.      * graphics context is the bounding rectangle of this component. 
  1632.      * @param     g   the graphics context to use for printing.
  1633.      * @see       java.awt.Component#print(java.awt.Graphics)
  1634.      * @since     JDK1.0
  1635.      */
  1636.     public void printAll(Graphics g) {
  1637.     ComponentPeer peer = this.peer;
  1638.     if (visible && (peer != null)) {
  1639.         validate();
  1640.         peer.print(g);
  1641.     }
  1642.     }
  1643.  
  1644.     /**
  1645.      * Repaints the component when the image has changed.
  1646.      * This <code>imageUpdate</code> method of an <code>ImageObserver</code> 
  1647.      * is called when more information about an 
  1648.      * image which had been previously requested using an asynchronous 
  1649.      * routine such as the <code>drawImage</code> method of 
  1650.      * <code>Graphics</code> becomes available. 
  1651.      * See the definition of <code>imageUpdate</code> for 
  1652.      * more information on this method and its arguments. 
  1653.      * <p>
  1654.      * The <code>imageUpdate</code> method of <code>Component</code> 
  1655.      * incrementally draws an image on the component as more of the bits 
  1656.      * of the image are available. 
  1657.      * <p>
  1658.      * If the system property <code>awt.image.incrementalDraw</code> 
  1659.      * is missing or has the value <code>true</code>, the image is 
  1660.      * incrementally drawn, If the system property has any other value, 
  1661.      * then the image is not drawn until it has been completely loaded. 
  1662.      * <p>
  1663.      * Also, if incremental drawing is in effect, the value of the 
  1664.      * system property <code>awt.image.redrawrate</code> is interpreted 
  1665.      * as an integer to give the maximum redraw rate, in milliseconds. If 
  1666.      * the system property is missing or cannot be interpreted as an 
  1667.      * integer, the redraw rate is once every 100ms. 
  1668.      * <p>
  1669.      * The interpretation of the <code>x</code>, <code>y</code>, 
  1670.      * <code>width</code>, and <code>height</code> arguments depends on 
  1671.      * the value of the <code>infoflags</code> argument. 
  1672.      * @param     img   the image being observed.
  1673.      * @param     infoflags   see <code>imageUpdate</code> for more information.
  1674.      * @param     x   the <i>x</i> coordinate.
  1675.      * @param     y   the <i>y</i> coordinate.
  1676.      * @param     width    the width.
  1677.      * @param     height   the height.
  1678.      * @return    <code>true</code> if the flags indicate that the 
  1679.      *            image is completely loaded; 
  1680.      *            <code>false</code> otherwise.     
  1681.      * @see     java.awt.image.ImageObserver
  1682.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.Color, java.awt.image.ImageObserver)
  1683.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  1684.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)
  1685.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)
  1686.      * @see     java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  1687.      * @since   JDK1.0
  1688.      */
  1689.     public boolean imageUpdate(Image img, int flags,
  1690.                    int x, int y, int w, int h) {
  1691.     int rate = -1;
  1692.     if ((flags & (FRAMEBITS|ALLBITS)) != 0) {
  1693.         rate = 0;
  1694.     } else if ((flags & SOMEBITS) != 0) {
  1695.         if (isInc) {
  1696.         try {
  1697.             rate = incRate;
  1698.             if (rate < 0)
  1699.             rate = 0;
  1700.         } catch (Exception e) {
  1701.             rate = 100;
  1702.         }
  1703.         }
  1704.     }
  1705.     if (rate >= 0) {
  1706.         repaint(rate, 0, 0, width, height);
  1707.     }
  1708.     return (flags & (ALLBITS|ABORT)) == 0;
  1709.     }
  1710.  
  1711.     /**
  1712.      * Creates an image from the specified image producer.
  1713.      * @param     producer  the image producer
  1714.      * @return    the image produced.    
  1715.      * @since     JDK1.0
  1716.      */
  1717.     public Image createImage(ImageProducer producer) {
  1718.         ComponentPeer peer = this.peer;
  1719.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)) {
  1720.         return peer.createImage(producer);
  1721.     }
  1722.     return getToolkit().createImage(producer);
  1723.     }
  1724.  
  1725.     /**
  1726.      * Creates an off-screen drawable image 
  1727.      *     to be used for double buffering.
  1728.      * @param     width the specified width.
  1729.      * @param     height the specified height.
  1730.      * @return    an off-screen drawable image, 
  1731.      *            which can be used for double buffering.
  1732.      * @since     JDK1.0
  1733.      */
  1734.     public Image createImage(int width, int height) {
  1735.         ComponentPeer peer = this.peer;
  1736.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1737.         return parent.createImage(width, height);
  1738.     } else {
  1739.         return (peer != null) ? peer.createImage(width, height) : null;
  1740.     }
  1741.     }
  1742.  
  1743.     /**
  1744.      * Prepares an image for rendering on this component.  The image
  1745.      * data is downloaded asynchronously in another thread and the
  1746.      * appropriate screen representation of the image is generated.
  1747.      * @param     image   the <code>Image</code> for which to 
  1748.      *                    prepare a screen representation.
  1749.      * @param     observer   the <code>ImageObserver</code> object 
  1750.      *                       to be notified as the image is being prepared.
  1751.      * @return    <code>true</code> if the image has already been fully prepared; 
  1752.                   <code>false</code> otherwise.     
  1753.      * @since     JDK1.0
  1754.      */
  1755.     public boolean prepareImage(Image image, ImageObserver observer) {
  1756.         return prepareImage(image, -1, -1, observer);
  1757.     }
  1758.  
  1759.     /**
  1760.      * Prepares an image for rendering on this component at the 
  1761.      * specified width and height. 
  1762.      * <p>
  1763.      * The image data is downloaded asynchronously in another thread, 
  1764.      * and an appropriately scaled screen representation of the image is 
  1765.      * generated. 
  1766.      * @param     image    the instance of <code>Image</code> 
  1767.      *            for which to prepare a screen representation.
  1768.      * @param     width    the width of the desired screen representation.
  1769.      * @param     height   the height of the desired screen representation.
  1770.      * @param     observer   the <code>ImageObserver</code> object 
  1771.      *            to be notified as the image is being prepared.
  1772.      * @return    <code>true</code> if the image has already been fully prepared; 
  1773.                   <code>false</code> otherwise.
  1774.      * @see       java.awt.image.ImageObserver     
  1775.      * @since     JDK1.0
  1776.      */
  1777.     public boolean prepareImage(Image image, int width, int height,
  1778.                 ImageObserver observer) {
  1779.         ComponentPeer peer = this.peer;
  1780.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1781.         return parent.prepareImage(image, width, height, observer);
  1782.     } else {
  1783.         return (peer != null)
  1784.         ? peer.prepareImage(image, width, height, observer)
  1785.         : getToolkit().prepareImage(image, width, height, observer);
  1786.     }
  1787.     }
  1788.  
  1789.     /**
  1790.      * Returns the status of the construction of a screen representation 
  1791.      * of the specified image. 
  1792.      * <p>
  1793.      * This method does not cause the image to begin loading. An 
  1794.      * application must use the <code>prepareImage</code> method 
  1795.      * to force the loading of an image. 
  1796.      * <p>
  1797.      * Information on the flags returned by this method can be found 
  1798.      * with the discussion of the <code>ImageObserver</code> interface. 
  1799.      * @param     image   the <code>Image</code> object whose status 
  1800.      *            is being checked.
  1801.      * @param     observer   the <code>ImageObserver</code> 
  1802.      *            object to be notified as the image is being prepared.
  1803.      * @return  the bitwise inclusive <b>OR</b> of 
  1804.      *            <code>ImageObserver</code> flags indicating what 
  1805.      *            information about the image is currently available.     
  1806.      * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  1807.      * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  1808.      * @see      java.awt.image.ImageObserver
  1809.      * @since    JDK1.0
  1810.      */
  1811.     public int checkImage(Image image, ImageObserver observer) {
  1812.         return checkImage(image, -1, -1, observer);
  1813.     }
  1814.  
  1815.     /**
  1816.      * Returns the status of the construction of a screen representation 
  1817.      * of the specified image. 
  1818.      * <p>
  1819.      * This method does not cause the image to begin loading. An 
  1820.      * application must use the <code>prepareImage</code> method 
  1821.      * to force the loading of an image. 
  1822.      * <p>
  1823.      * The <code>checkImage</code> method of <code>Component</code> 
  1824.      * calls its peer's <code>checkImage</code> method to calculate 
  1825.      * the flags. If this component does not yet have a peer, the 
  1826.      * component's toolkit's <code>checkImage</code> method is called 
  1827.      * instead. 
  1828.      * <p>
  1829.      * Information on the flags returned by this method can be found 
  1830.      * with the discussion of the <code>ImageObserver</code> interface. 
  1831.      * @param     image   the <code>Image</code> object whose status 
  1832.      *                    is being checked.
  1833.      * @param     width   the width of the scaled version 
  1834.      *                    whose status is to be checked.
  1835.      * @param     height  the height of the scaled version 
  1836.      *                    whose status is to be checked.
  1837.      * @param     observer   the <code>ImageObserver</code> object 
  1838.      *                    to be notified as the image is being prepared.
  1839.      * @return    the bitwise inclusive <b>OR</b> of 
  1840.      *            <code>ImageObserver</code> flags indicating what 
  1841.      *            information about the image is currently available.     
  1842.      * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  1843.      * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  1844.      * @see      java.awt.image.ImageObserver#_top_
  1845.      * @since    JDK1.0
  1846.      */
  1847.     public int checkImage(Image image, int width, int height,
  1848.               ImageObserver observer) {
  1849.         ComponentPeer peer = this.peer;
  1850.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1851.         return parent.checkImage(image, width, height, observer);
  1852.     } else {
  1853.         return (peer != null)
  1854.         ? peer.checkImage(image, width, height, observer)
  1855.         : getToolkit().checkImage(image, width, height, observer);
  1856.     }
  1857.     }
  1858.  
  1859.     /**  
  1860.      * Checks whether this component "contains" the specified point,
  1861.      * where <code>x</code> and <code>y</code> are defined to be 
  1862.      * relative to the coordinate system of this component.
  1863.      * @param     x   the <i>x</i> coordinate of the point.
  1864.      * @param     y   the <i>y</i> coordinate of the point.
  1865.      * @see       java.awt.Component#getComponentAt(int, int)
  1866.      * @since     JDK1.1
  1867.      */
  1868.     public boolean contains(int x, int y) {
  1869.         return inside(x, y);
  1870.     }
  1871.  
  1872.     /** 
  1873.      * @deprecated As of JDK version 1.1, 
  1874.      * replaced by contains(int, int).
  1875.      */
  1876.     public boolean inside(int x, int y) {
  1877.     return (x >= 0) && (x < width) && (y >= 0) && (y < height);
  1878.     }
  1879.  
  1880.     /**  
  1881.      * Checks whether this component "contains" the specified point,
  1882.      * where the point's <i>x</i> and <i>y</i> coordinates are defined 
  1883.      * to be relative to the coordinate system of this component.  
  1884.      * @param     p     the point.
  1885.      * @see       java.awt.Component#getComponentAt(java.awt.Point)
  1886.      * @since     JDK1.1
  1887.      */
  1888.     public boolean contains(Point p) {
  1889.     return contains(p.x, p.y);
  1890.     }
  1891.  
  1892.     /** 
  1893.      * Determines if this component or one of its immediate 
  1894.      * subcomponents contains the (<i>x</i>, <i>y</i>) location, 
  1895.      * and if so, returns the containing component. This method only 
  1896.      * looks one level deep. If the point (<i>x</i>, <i>y</i>) is 
  1897.      * inside a subcomponent that itself has subcomponents, it does not 
  1898.      * go looking down the subcomponent tree. 
  1899.      * <p>
  1900.      * The <code>locate</code> method of <code>Component</code> simply 
  1901.      * returns the component itself if the (<i>x</i>, <i>y</i>) 
  1902.      * coordinate location is inside its bounding box, and <code>null</code> 
  1903.      * otherwise. 
  1904.      * @param     x   the <i>x</i> coordinate.
  1905.      * @param     y   the <i>y</i> coordinate.
  1906.      * @return    the component or subcomponent that contains the 
  1907.      *                (<i>x</i>, <i>y</i>) location; 
  1908.      *                <code>null</code> if the location 
  1909.      *                is outside this component.
  1910.      * @see       java.awt.Component#contains(int, int)
  1911.      * @since     JDK1.0
  1912.      */
  1913.     public Component getComponentAt(int x, int y) {
  1914.     return locate(x, y);
  1915.     }
  1916.  
  1917.     /** 
  1918.      * @deprecated As of JDK version 1.1,
  1919.      * replaced by getComponentAt(int, int).
  1920.      */
  1921.     public Component locate(int x, int y) {
  1922.     return contains(x, y) ? this : null;
  1923.     }
  1924.  
  1925.     /** 
  1926.      * Returns the component or subcomponent that contains the
  1927.      * specified point.
  1928.      * @param     p   the point.
  1929.      * @see       java.awt.Component#contains
  1930.      * @since     JDK1.1
  1931.      */
  1932.     public Component getComponentAt(Point p) {
  1933.     return getComponentAt(p.x, p.y);
  1934.     }
  1935.  
  1936.     /**
  1937.      * @deprecated As of JDK version 1.1,
  1938.      * replaced by <code>dispatchEvent(AWTEvent e)</code>.
  1939.      */
  1940.     public void deliverEvent(Event e) {
  1941.     postEvent(e);
  1942.     }
  1943.  
  1944.     /**
  1945.      * Dispatches an event to this component or one of its sub components.
  1946.      * @param e the event
  1947.      */
  1948.     public final void dispatchEvent(AWTEvent e) {
  1949.         dispatchEventImpl(e);
  1950.     }
  1951.  
  1952.     void dispatchEventImpl(AWTEvent e) {
  1953.         int id = e.getID();
  1954.  
  1955.         /*
  1956.      * 1. Allow input methods to process the event
  1957.      */
  1958.     if (areInputMethodsEnabled()
  1959.             && (
  1960.             // For passive clients of the input method framework
  1961.                 // we need to pass on InputMethodEvents since some host
  1962.                 // input method adapters send them through the Java
  1963.                 // event queue instead of directly to the component,
  1964.                 // and the input context also handles the Java root window
  1965.                 ((e instanceof InputMethodEvent) && (getInputMethodRequests() == null))
  1966.                 ||
  1967.                 // Otherwise, we only pass on low-level events, because
  1968.                 // a) input methods shouldn't know about semantic events
  1969.                 // b) passing on the events takes time
  1970.                 // c) isConsumed() is always true for semantic events.
  1971.                 // We exclude paint events since they may be numerous and shouldn't matter.
  1972.                 (e instanceof ComponentEvent) && !(e instanceof PaintEvent))) {
  1973.             InputContext inputContext = getInputContext();
  1974.             if (inputContext != null) {
  1975.                 inputContext.dispatchEvent(e);
  1976.             if (e.isConsumed()) {
  1977.                 return;
  1978.             }
  1979.         }
  1980.         }
  1981.  
  1982.         /*
  1983.          * 2. Pre-process any special events before delivery
  1984.          */
  1985.         switch(id) {
  1986.           case PaintEvent.PAINT: 
  1987.           case PaintEvent.UPDATE: 
  1988.             Graphics g = getGraphics();
  1989.             if (g == null) {
  1990.                 return;
  1991.             }
  1992.             Rectangle r = ((PaintEvent)e).getUpdateRect();
  1993.             g.clipRect(r.x, r.y, r.width, r.height);
  1994.             if (id == PaintEvent.PAINT) {
  1995.                 paint(g);
  1996.             } else {
  1997.                 update(g);
  1998.             }
  1999.             g.dispose();
  2000.             return;
  2001.  
  2002.           case FocusEvent.FOCUS_GAINED:
  2003.             if (parent != null && !(this instanceof Window)) {
  2004.                 parent.setFocusOwner(this);
  2005.             }
  2006.             break;
  2007.  
  2008.           case KeyEvent.KEY_PRESSED:
  2009.           case KeyEvent.KEY_RELEASED:
  2010.             Container p = (Container)((this instanceof Container) ? this : parent);
  2011.             if (p != null) {
  2012.                 p.preProcessKeyEvent((KeyEvent)e);
  2013.                 if (e.isConsumed()) {
  2014.                     return;
  2015.                 }
  2016.             }
  2017.             break;
  2018.  
  2019. /*
  2020.           case MouseEvent.MOUSE_PRESSED:
  2021.             if (isFocusTraversable()) {
  2022.                 requestFocus();
  2023.             }
  2024.             break;
  2025.             */
  2026.           default:
  2027.             break;
  2028.         }
  2029.  
  2030.         /*
  2031.          * 3. Deliver event for normal processing
  2032.          */
  2033.         if (newEventsOnly) {
  2034.             // Filtering needs to really be moved to happen at a lower
  2035.             // level in order to get maximum performance gain;  it is
  2036.             // here temporarily to ensure the API spec is honored.
  2037.             //
  2038.             if (eventEnabled(e)) {
  2039.                 processEvent(e);
  2040.             }
  2041.  
  2042.         } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) { 
  2043.             //
  2044.             // backward compatibility
  2045.             //
  2046.             Event olde = e.convertToOld();
  2047.             if (olde != null) {
  2048.                 int key = olde.key;
  2049.                 int modifiers = olde.modifiers;
  2050.  
  2051.                 postEvent(olde);
  2052.                 if (olde.isConsumed()) {
  2053.                     e.consume();
  2054.                 }
  2055.                 // if target changed key or modifier values, copy them
  2056.                 // back to original event
  2057.                 //
  2058.                 switch(olde.id) {
  2059.                   case Event.KEY_PRESS:
  2060.                   case Event.KEY_RELEASE:
  2061.                   case Event.KEY_ACTION:
  2062.                   case Event.KEY_ACTION_RELEASE:
  2063.                     if (olde.key != key) {
  2064.                        ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
  2065.                     }
  2066.                     if (olde.modifiers != modifiers) {
  2067.                        ((KeyEvent)e).setModifiers(olde.modifiers);
  2068.                     }
  2069.                     break;
  2070.                   default:
  2071.                     break;
  2072.                 }
  2073.             } 
  2074.         }
  2075.  
  2076.         /* 
  2077.          * 4. If no one has consumed a key event, propagate it
  2078.          * up the containment hierarchy to ensure that menu shortcuts
  2079.          * and keyboard traversal will work properly.
  2080.          */
  2081.         if (!e.isConsumed() && e instanceof java.awt.event.KeyEvent) {
  2082.             Container p = (Container)((this instanceof Container) ? this : parent);
  2083.             if (p != null) {
  2084.                 p.postProcessKeyEvent((KeyEvent)e);
  2085.             }
  2086.         }
  2087.  
  2088.         /*
  2089.          * 5. Allow the peer to process the event
  2090.          */
  2091.         if (peer != null) {
  2092.             peer.handleEvent(e);
  2093.         }
  2094.     }
  2095.  
  2096.     boolean areInputMethodsEnabled() {
  2097.         // in 1.2, we assume input method support is required for all
  2098.         // components that handle key events, but components can turn off
  2099.         // input methods by calling enableInputMethods(false).
  2100.         return inputMethodsEnabled &&
  2101.             ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
  2102.     }
  2103.  
  2104.     // REMIND: remove when filtering is handled at lower level
  2105.     boolean eventEnabled(AWTEvent e) {
  2106.         switch(e.id) {
  2107.           case ComponentEvent.COMPONENT_MOVED:
  2108.           case ComponentEvent.COMPONENT_RESIZED:
  2109.           case ComponentEvent.COMPONENT_SHOWN:
  2110.           case ComponentEvent.COMPONENT_HIDDEN:
  2111.             if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
  2112.                 componentListener != null) {
  2113.                 return true;
  2114.             }
  2115.             break;
  2116.           case FocusEvent.FOCUS_GAINED:
  2117.           case FocusEvent.FOCUS_LOST:
  2118.             if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 ||
  2119.                 focusListener != null) {
  2120.                 return true;
  2121.             }
  2122.             break;
  2123.           case KeyEvent.KEY_PRESSED:
  2124.           case KeyEvent.KEY_RELEASED:
  2125.           case KeyEvent.KEY_TYPED:
  2126.             if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 ||
  2127.                 keyListener != null) {
  2128.                 return true;
  2129.             }
  2130.             break;
  2131.           case MouseEvent.MOUSE_PRESSED:
  2132.           case MouseEvent.MOUSE_RELEASED:
  2133.           case MouseEvent.MOUSE_ENTERED:
  2134.           case MouseEvent.MOUSE_EXITED:
  2135.           case MouseEvent.MOUSE_CLICKED:
  2136.             if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 ||
  2137.                 mouseListener != null) {
  2138.                 return true;
  2139.             }
  2140.             break;
  2141.           case MouseEvent.MOUSE_MOVED:
  2142.           case MouseEvent.MOUSE_DRAGGED:
  2143.             if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 ||
  2144.                 mouseMotionListener != null) {
  2145.                 return true;
  2146.             }
  2147.             break;
  2148.           case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
  2149.           case InputMethodEvent.CARET_POSITION_CHANGED:
  2150.             if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 ||
  2151.                     inputMethodListener != null) {
  2152.                 return true;
  2153.             }
  2154.             break;
  2155.           default:
  2156.             break;
  2157.         }
  2158.         //
  2159.         // Always pass on events defined by external programs.
  2160.         //
  2161.         if (e.id > AWTEvent.RESERVED_ID_MAX) {
  2162.             return true;
  2163.         }
  2164.         return false;
  2165.     }
  2166.  
  2167.     /**
  2168.      * @deprecated As of JDK version 1.1,
  2169.      * replaced by dispatchEvent(AWTEvent).
  2170.      */
  2171.     public boolean postEvent(Event e) {
  2172.     ComponentPeer peer = this.peer;
  2173.  
  2174.     if (handleEvent(e)) {
  2175.             e.consume();
  2176.         return true;
  2177.     }
  2178.  
  2179.     Component parent = this.parent;
  2180.     int eventx = e.x;
  2181.     int eventy = e.y;
  2182.     if (parent != null) {
  2183.         e.translate(x, y);
  2184.         if (parent.postEvent(e)) {
  2185.                 e.consume();
  2186.             return true;
  2187.         }
  2188.         // restore coords
  2189.            e.x = eventx;
  2190.         e.y = eventy;
  2191.     }
  2192.     return false;
  2193.     }
  2194.  
  2195.     // Event source interfaces
  2196.  
  2197.     /**
  2198.      * Adds the specified component listener to receive component events from
  2199.      * this component.
  2200.      * @param    l   the component listener.
  2201.      * @see      java.awt.event.ComponentEvent
  2202.      * @see      java.awt.event.ComponentListener
  2203.      * @see      java.awt.Component#removeComponentListener
  2204.      * @since    JDK1.1
  2205.      */  
  2206.     public synchronized void addComponentListener(ComponentListener l) {
  2207.         componentListener = AWTEventMulticaster.add(componentListener, l);
  2208.         newEventsOnly = true;
  2209.     }
  2210.     /**
  2211.      * Removes the specified component listener so that it no longer
  2212.      * receives component events from this component.
  2213.      * @param    l   the component listener.
  2214.      * @see      java.awt.event.ComponentEvent
  2215.      * @see      java.awt.event.ComponentListener
  2216.      * @see      java.awt.Component#addComponentListener
  2217.      * @since    JDK1.1
  2218.      */ 
  2219.     public synchronized void removeComponentListener(ComponentListener l) {
  2220.         componentListener = AWTEventMulticaster.remove(componentListener, l);
  2221.     }        
  2222.  
  2223.     /**
  2224.      * Adds the specified focus listener to receive focus events from
  2225.      * this component when this component gains input focus.
  2226.      * 
  2227.      * @param    l   the focus listener.
  2228.      * @see      java.awt.event.FocusEvent
  2229.      * @see      java.awt.event.FocusListener
  2230.      * @see      java.awt.Component#removeFocusListener
  2231.      * @since    JDK1.1
  2232.      */      
  2233.     public synchronized void addFocusListener(FocusListener l) {
  2234.         focusListener = AWTEventMulticaster.add(focusListener, l);
  2235.         newEventsOnly = true;
  2236.  
  2237.     // if this is a lightweight component, enable focus events
  2238.     // in the native container.
  2239.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2240.         parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK);
  2241.     }
  2242.     }
  2243.  
  2244.     /**
  2245.      * Removes the specified focus listener so that it no longer
  2246.      * receives focus events from this component.
  2247.      * @param    l   the focus listener.
  2248.      * @see      java.awt.event.FocusEvent
  2249.      * @see      java.awt.event.FocusListener
  2250.      * @see      java.awt.Component#addFocusListener
  2251.      * @since    JDK1.1
  2252.      */ 
  2253.     public synchronized void removeFocusListener(FocusListener l) {
  2254.         focusListener = AWTEventMulticaster.remove(focusListener, l);
  2255.     }   
  2256.  
  2257.     /**
  2258.      * Adds the specified key listener to receive key events from
  2259.      * this component.
  2260.      * @param    l   the key listener.
  2261.      * @see      java.awt.event.KeyEvent
  2262.      * @see      java.awt.event.KeyListener
  2263.      * @see      java.awt.Component#removeKeyListener
  2264.      * @since    JDK1.1
  2265.      */      
  2266.     public synchronized void addKeyListener(KeyListener l) {
  2267.         keyListener = AWTEventMulticaster.add(keyListener, l);
  2268.         newEventsOnly = true;
  2269.  
  2270.     // if this is a lightweight component, enable key events
  2271.     // in the native container.
  2272.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2273.         parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
  2274.     }
  2275.     }
  2276.  
  2277.     /**
  2278.      * Removes the specified key listener so that it no longer
  2279.      * receives key events from this component.
  2280.      * @param    l   the key listener.
  2281.      * @see      java.awt.event.KeyEvent
  2282.      * @see      java.awt.event.KeyListener
  2283.      * @see      java.awt.Component#addKeyListener
  2284.      * @since    JDK1.1
  2285.      */ 
  2286.     public synchronized void removeKeyListener(KeyListener l) {
  2287.         keyListener = AWTEventMulticaster.remove(keyListener, l);
  2288.     }  
  2289.  
  2290.     /**
  2291.      * Adds the specified mouse listener to receive mouse events from
  2292.      * this component.
  2293.      * @param    l   the mouse listener.
  2294.      * @see      java.awt.event.MouseEvent
  2295.      * @see      java.awt.event.MouseListener
  2296.      * @see      java.awt.Component#removeMouseListener
  2297.      * @since    JDK1.1
  2298.      */      
  2299.     public synchronized void addMouseListener(MouseListener l) {
  2300.         mouseListener = AWTEventMulticaster.add(mouseListener,l);
  2301.         newEventsOnly = true;
  2302.     
  2303.     // if this is a lightweight component, enable mouse events
  2304.     // in the native container.
  2305.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2306.         parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK);
  2307.     }
  2308.     }
  2309.  
  2310.     /**
  2311.      * Removes the specified mouse listener so that it no longer
  2312.      * receives mouse events from this component.
  2313.      * @param    l   the mouse listener.
  2314.      * @see      java.awt.event.MouseEvent
  2315.      * @see      java.awt.event.MouseListener
  2316.      * @see      java.awt.Component#addMouseListener
  2317.      * @since    JDK1.1
  2318.      */ 
  2319.     public synchronized void removeMouseListener(MouseListener l) {
  2320.         mouseListener = AWTEventMulticaster.remove(mouseListener, l);
  2321.     }
  2322.  
  2323.     /**
  2324.      * Adds the specified mouse motion listener to receive mouse motion events from
  2325.      * this component.
  2326.      * @param    l   the mouse motion listener.
  2327.      * @see      java.awt.event.MouseMotionEvent
  2328.      * @see      java.awt.event.MouseMotionListener
  2329.      * @see      java.awt.Component#removeMouseMotionListener
  2330.      * @since    JDK1.1
  2331.      */  
  2332.     public synchronized void addMouseMotionListener(MouseMotionListener l) {
  2333.         mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l);
  2334.         newEventsOnly = true;
  2335.     
  2336.     // if this is a lightweight component, enable mouse events
  2337.     // in the native container.
  2338.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2339.         parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
  2340.     }
  2341.     }
  2342.  
  2343.     /**
  2344.      * Removes the specified mouse motion listener so that it no longer
  2345.      * receives mouse motion events from this component.
  2346.      * @param    l   the mouse motion listener.
  2347.      * @see      java.awt.event.MouseMotionEvent
  2348.      * @see      java.awt.event.MouseMotionListener
  2349.      * @see      java.awt.Component#addMouseMotionListener
  2350.      * @since    JDK1.1
  2351.      */ 
  2352.     public synchronized void removeMouseMotionListener(MouseMotionListener l) {
  2353.         mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
  2354.     }    
  2355.  
  2356.     /**
  2357.      * Adds the specified input method listener to receive
  2358.      * input method events from this component. A component will
  2359.      * only receive input method events if it also overrides
  2360.      * getInputMethodRequests() to return an InputMethodRequests
  2361.      * instance.
  2362.      * @param    l   the input method listener.
  2363.      * @see      java.awt.event.InputMethodEvent
  2364.      * @see      java.awt.event.InputMethodListener
  2365.      * @see      java.awt.Component#removeInputMethodListener
  2366.      * @see      java.awt.Component#getInputMethodRequests
  2367.      * @since    JDK1.2
  2368.      */
  2369.     public synchronized void addInputMethodListener(InputMethodListener l) {
  2370.         inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
  2371.         newEventsOnly = true;
  2372.     }
  2373.  
  2374.     /**
  2375.      * Removes the specified input method listener so that it no longer receives
  2376.      * input method events from this component.
  2377.      * @param    l   the input method listener.
  2378.      * @see      java.awt.event.InputMethodEvent
  2379.      * @see      java.awt.event.InputMethodListener
  2380.      * @see      java.awt.Component#addInputMethodListener
  2381.      * @since    JDK1.2
  2382.      */
  2383.     public synchronized void removeInputMethodListener(InputMethodListener l) {
  2384.         inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
  2385.     }
  2386.  
  2387.     /**
  2388.      * Gets the input method request handler which supports
  2389.      * requests from input methods for this component. A component
  2390.      * that supports on-the-spot text input needs to override this
  2391.      * method to return an InputMethodRequests instance. At the same
  2392.      * time, it has to add an input method listener.
  2393.      *
  2394.      * @return the input method request handler for this component,
  2395.      * null by default.
  2396.      * @see #addInputMethodListener
  2397.      * @since JDK1.2
  2398.      */
  2399.     public InputMethodRequests getInputMethodRequests() {
  2400.         return null;
  2401.     }
  2402.  
  2403.     /**
  2404.      * Gets the input context used by this component for handling the communication
  2405.      * with input methods when text is entered in this component. By default, the
  2406.      * input context used for the parent component is returned. Components may
  2407.      * override this to return a private input context.
  2408.      *
  2409.      * @return The input context used by this component. Null if no context can
  2410.      * be determined.
  2411.      * @since JDK1.2
  2412.      */
  2413.     public InputContext getInputContext() {
  2414.         Container parent = this.parent;
  2415.         if (parent == null) {
  2416.             return null;
  2417.         } else {
  2418.             return parent.getInputContext();
  2419.         }
  2420.     }
  2421.  
  2422.     /**
  2423.      * Enables the events defined by the specified event mask parameter
  2424.      * to be delivered to this component. 
  2425.      * <p>
  2426.      * Event types are automatically enabled when a listener for 
  2427.      * that event type is added to the component.
  2428.      * <p>
  2429.      * This method only needs to be invoked by subclasses of
  2430.      * <code>Component</code> which desire to have the specified event  
  2431.      * types delivered to <code>processEvent</code> regardless of whether 
  2432.      * or not a listener is registered.
  2433.      * @param      eventsToEnable   the event mask defining the event types.
  2434.      * @see        java.awt.Component#processEvent
  2435.      * @see        java.awt.Component#disableEvents
  2436.      * @since      JDK1.1
  2437.      */
  2438.     protected final void enableEvents(long eventsToEnable) {
  2439.         eventMask |= eventsToEnable;
  2440.         newEventsOnly = true;
  2441.    
  2442.     // if this is a lightweight component, enable mouse events
  2443.     // in the native container.
  2444.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2445.         parent.proxyEnableEvents(eventMask);
  2446.     }
  2447.     }
  2448.  
  2449.     /**
  2450.      * Disables the events defined by the specified event mask parameter
  2451.      * from being delivered to this component.  
  2452.      * @param      eventsToDisable   the event mask defining the event types
  2453.      * @see        java.awt.Component#enableEvents
  2454.      * @since      JDK1.1
  2455.      */
  2456.     protected final void disableEvents(long eventsToDisable) {
  2457.         eventMask &= ~eventsToDisable;  
  2458.     }  
  2459.  
  2460.     /**
  2461.      * Potentially coalesce an event being posted with an existing
  2462.      * event.  This method is called by EventQueue.postEvent if an 
  2463.      * event with the same ID as the event to be posted is found in 
  2464.      * the queue (both events must have this component as their source).
  2465.      * This method either returns a coalesced event which replaces
  2466.      * the existing event (and the new event is then discarded), or
  2467.      * null to indicate that no combining should be done (add the
  2468.      * second event to the end of the queue).  Either event parameter
  2469.      * may be modified and returned, as the other one is discarded
  2470.      * unless null is returned.
  2471.      * <p>
  2472.      * This implementation of coalesceEvents coalesces two event types:
  2473.      * mouse move (and drag) events, and paint (and update) events.
  2474.      * For mouse move events the last event is always returned, causing
  2475.      * intermediate moves to be discarded.  For paint events where the
  2476.      * update rectangles intersect, an event is returned which has an
  2477.      * update rectangle which is the union of the two events.
  2478.      * <p>
  2479.      * Note:  this method must never be synchronized (nor methods it
  2480.      * invokes), as it is called from the underlying native event
  2481.      * code.  Any deadlock with an overwritten version of this method
  2482.      * is the responsibility of the party who overwrote this method!
  2483.      * 
  2484.      * @param  existingEvent  the event already on the EventQueue.
  2485.      * @param  newEvent       the event being posted to the EventQueue.
  2486.      * @return a coalesced event, or null indicating that no coalescing
  2487.      *         was done.
  2488.      */
  2489.     protected AWTEvent coalesceEvents(AWTEvent existingEvent, 
  2490.                                       AWTEvent newEvent) {
  2491.         int id = existingEvent.getID();
  2492.         if (id != newEvent.getID() ||
  2493.             !(existingEvent.getSource().equals(newEvent.getSource()))) {
  2494.             // Only coalesce events of the same type and source.
  2495.             return null;
  2496.         }
  2497.  
  2498.         switch (id) {
  2499.           case Event.MOUSE_MOVE:
  2500.           case Event.MOUSE_DRAG:
  2501.               MouseEvent e = (MouseEvent)existingEvent;
  2502.               if (e.getModifiers() == ((MouseEvent)newEvent).getModifiers()) {
  2503.                   // Just return the newEvent, causing the old to be
  2504.                   // discarded.
  2505.                   return newEvent;
  2506.               }
  2507.               break;
  2508.  
  2509.           case PaintEvent.PAINT:
  2510.           case PaintEvent.UPDATE:
  2511.               PaintEvent pe = (PaintEvent)existingEvent;
  2512.               if (pe.getSource() == newEvent.getSource()) {
  2513.                   Rectangle rect = pe.getUpdateRect();
  2514.                   Rectangle newRect = 
  2515.                       ((PaintEvent)newEvent).getUpdateRect();
  2516.                   if (!rect.equals(newRect) && rect.intersects(newRect)) {
  2517.                       // Combine the two events' update rectangles.
  2518.                       pe.setUpdateRect(rect.union(newRect));
  2519.                       return pe;
  2520.                   }
  2521.               }
  2522.               break;
  2523.         }
  2524.         return null;
  2525.     }
  2526.  
  2527.     /** 
  2528.      * Processes events occurring on this component. By default this
  2529.      * method calls the appropriate 
  2530.      * <code>process<event type>Event</code>  
  2531.      * method for the given class of event.
  2532.      * @param     e the event.
  2533.      * @see       java.awt.Component#processComponentEvent
  2534.      * @see       java.awt.Component#processFocusEvent
  2535.      * @see       java.awt.Component#processKeyEvent
  2536.      * @see       java.awt.Component#processMouseEvent
  2537.      * @see       java.awt.Component#processMouseMotionEvent
  2538.      * @see       java.awt.Component#processInputMethodEvent
  2539.      * @since     JDK1.1
  2540.      */   
  2541.     protected void processEvent(AWTEvent e) {
  2542.  
  2543.         //System.err.println("Component.processNewEvent:" + e);
  2544.         if (e instanceof FocusEvent) {  
  2545.             processFocusEvent((FocusEvent)e);
  2546.  
  2547.         } else if (e instanceof MouseEvent) {
  2548.             switch(e.getID()) {
  2549.               case MouseEvent.MOUSE_PRESSED:
  2550.               case MouseEvent.MOUSE_RELEASED:
  2551.               case MouseEvent.MOUSE_CLICKED:
  2552.               case MouseEvent.MOUSE_ENTERED:
  2553.               case MouseEvent.MOUSE_EXITED:
  2554.                 processMouseEvent((MouseEvent)e);
  2555.                 break;
  2556.               case MouseEvent.MOUSE_MOVED:
  2557.               case MouseEvent.MOUSE_DRAGGED:
  2558.                 processMouseMotionEvent((MouseEvent)e);
  2559.                 break;
  2560.             }
  2561.  
  2562.         } else if (e instanceof KeyEvent) {
  2563.             processKeyEvent((KeyEvent)e);
  2564.  
  2565.         } else if (e instanceof ComponentEvent) {
  2566.             processComponentEvent((ComponentEvent)e);
  2567.         } else if (e instanceof InputMethodEvent) {
  2568.             processInputMethodEvent((InputMethodEvent)e);
  2569.         }
  2570.     }
  2571.     
  2572.     /** 
  2573.      * Processes component events occurring on this component by
  2574.      * dispatching them to any registered 
  2575.      * <code>ComponentListener</code> objects. 
  2576.      * <p>
  2577.      * This method is not called unless component events are 
  2578.      * enabled for this component. Component events are enabled 
  2579.      * when one of the following occurs:
  2580.      * <p><ul>
  2581.      * <li>A <code>ComponentListener</code> object is registered 
  2582.      * via <code>addComponentListener</code>.
  2583.      * <li>Component events are enabled via <code>enableEvents</code>.
  2584.      * </ul>
  2585.      * @param       e the component event.
  2586.      * @see         java.awt.event.ComponentEvent
  2587.      * @see         java.awt.event.ComponentListener
  2588.      * @see         java.awt.Component#addComponentListener
  2589.      * @see         java.awt.Component#enableEvents
  2590.      * @since       JDK1.1
  2591.      */   
  2592.     protected void processComponentEvent(ComponentEvent e) {
  2593.         if (componentListener != null) {
  2594.             int id = e.getID();
  2595.             switch(id) {
  2596.               case ComponentEvent.COMPONENT_RESIZED:
  2597.                 componentListener.componentResized(e);
  2598.                 break;
  2599.               case ComponentEvent.COMPONENT_MOVED:
  2600.                 componentListener.componentMoved(e);
  2601.                 break;
  2602.               case ComponentEvent.COMPONENT_SHOWN:
  2603.                 componentListener.componentShown(e);
  2604.                 break;
  2605.               case ComponentEvent.COMPONENT_HIDDEN:
  2606.                 componentListener.componentHidden(e);
  2607.                 break;
  2608.             }
  2609.         }
  2610.     }
  2611.  
  2612.     /** 
  2613.      * Processes focus events occurring on this component by
  2614.      * dispatching them to any registered 
  2615.      * <code>FocusListener</code> objects. 
  2616.      * <p>
  2617.      * This method is not called unless focus events are 
  2618.      * enabled for this component. Focus events are enabled 
  2619.      * when one of the following occurs:
  2620.      * <p><ul>
  2621.      * <li>A <code>FocusListener</code> object is registered 
  2622.      * via <code>addFocusListener</code>.
  2623.      * <li>Focus events are enabled via <code>enableEvents</code>.
  2624.      * </ul>
  2625.      * @param       e the focus event.
  2626.      * @see         java.awt.event.FocusEvent
  2627.      * @see         java.awt.event.FocusListener
  2628.      * @see         java.awt.Component#addFocusListener
  2629.      * @see         java.awt.Component#enableEvents
  2630.      * @since       JDK1.1
  2631.      */       
  2632.     protected void processFocusEvent(FocusEvent e) {
  2633.         if (focusListener != null) {
  2634.             int id = e.getID();
  2635.             switch(id) {
  2636.               case FocusEvent.FOCUS_GAINED:
  2637.                 focusListener.focusGained(e);
  2638.                 break;
  2639.               case FocusEvent.FOCUS_LOST:
  2640.                 focusListener.focusLost(e);
  2641.                 break;
  2642.             }
  2643.         }
  2644.     }
  2645.  
  2646.     /** 
  2647.      * Processes key events occurring on this component by
  2648.      * dispatching them to any registered 
  2649.      * <codeKeyListener</code> objects. 
  2650.      * <p>
  2651.      * This method is not called unless key events are 
  2652.      * enabled for this component. Key events are enabled 
  2653.      * when one of the following occurs:
  2654.      * <p><ul>
  2655.      * <li>A <code>KeyListener</code> object is registered 
  2656.      * via <code>addKeyListener</code>.
  2657.      * <li>Key events are enabled via <code>enableEvents</code>.
  2658.      * </ul>
  2659.      * @param       e the key event.
  2660.      * @see         java.awt.event.KeyEvent
  2661.      * @see         java.awt.event.KeyListener
  2662.      * @see         java.awt.Component#addKeyListener
  2663.      * @see         java.awt.Component#enableEvents
  2664.      * @since       JDK1.1
  2665.      */   
  2666.     protected void processKeyEvent(KeyEvent e) {
  2667.         if (keyListener != null) {
  2668.             int id = e.getID();
  2669.             switch(id) {
  2670.               case KeyEvent.KEY_TYPED:
  2671.                 keyListener.keyTyped(e);
  2672.                 break;
  2673.               case KeyEvent.KEY_PRESSED:
  2674.                 keyListener.keyPressed(e);
  2675.                 break;
  2676.               case KeyEvent.KEY_RELEASED:
  2677.                 keyListener.keyReleased(e);
  2678.                 break;
  2679.             }
  2680.         } 
  2681.     }
  2682.  
  2683.     /** 
  2684.      * Processes mouse events occurring on this component by
  2685.      * dispatching them to any registered 
  2686.      * <code>MouseListener</code> objects. 
  2687.      * <p>
  2688.      * This method is not called unless mouse events are 
  2689.      * enabled for this component. Mouse events are enabled 
  2690.      * when one of the following occurs:
  2691.      * <p><ul>
  2692.      * <li>A <code>MouseListener</code> object is registered 
  2693.      * via <code>addMouseListener</code>.
  2694.      * <li>Mouse events are enabled via <code>enableEvents</code>.
  2695.      * </ul>
  2696.      * @param       e the mouse event.
  2697.      * @see         java.awt.event.MouseEvent
  2698.      * @see         java.awt.event.MouseListener
  2699.      * @see         java.awt.Component#addMouseListener
  2700.      * @see         java.awt.Component#enableEvents
  2701.      * @since       JDK1.1
  2702.      */   
  2703.     protected void processMouseEvent(MouseEvent e) {
  2704.         if (mouseListener != null) {
  2705.             int id = e.getID();
  2706.             switch(id) {
  2707.               case MouseEvent.MOUSE_PRESSED:
  2708.                 mouseListener.mousePressed(e);
  2709.                 break;
  2710.               case MouseEvent.MOUSE_RELEASED:
  2711.                 mouseListener.mouseReleased(e);
  2712.                 break;
  2713.               case MouseEvent.MOUSE_CLICKED:
  2714.                 mouseListener.mouseClicked(e);
  2715.                 break;
  2716.               case MouseEvent.MOUSE_EXITED:
  2717.                 mouseListener.mouseExited(e);
  2718.                 break;
  2719.               case MouseEvent.MOUSE_ENTERED:
  2720.                 mouseListener.mouseEntered(e);
  2721.                 break;
  2722.             }
  2723.         }            
  2724.     }
  2725.  
  2726.     /** 
  2727.      * Processes mouse motion events occurring on this component by
  2728.      * dispatching them to any registered 
  2729.      * <code>MouseMotionListener</code> objects. 
  2730.      * <p>
  2731.      * This method is not called unless mouse motion events are 
  2732.      * enabled for this component. Mouse motion events are enabled 
  2733.      * when one of the following occurs:
  2734.      * <p><ul>
  2735.      * <li>A <code>MouseMotionListener</code> object is registered 
  2736.      * via <code>addMouseMotionListener</code>.
  2737.      * <li>Mouse motion events are enabled via <code>enableEvents</code>.
  2738.      * </ul>
  2739.      * @param       e the mouse motion event.
  2740.      * @see         java.awt.event.MouseMotionEvent
  2741.      * @see         java.awt.event.MouseMotionListener
  2742.      * @see         java.awt.Component#addMouseMotionListener
  2743.      * @see         java.awt.Component#enableEvents
  2744.      * @since       JDK1.1
  2745.      */   
  2746.     protected void processMouseMotionEvent(MouseEvent e) {
  2747.         if (mouseMotionListener != null) {
  2748.             int id = e.getID();
  2749.             switch(id) {
  2750.               case MouseEvent.MOUSE_MOVED:
  2751.                 mouseMotionListener.mouseMoved(e);
  2752.                 break;
  2753.               case MouseEvent.MOUSE_DRAGGED:
  2754.                 mouseMotionListener.mouseDragged(e);
  2755.                 break;
  2756.             }
  2757.         }            
  2758.     }
  2759.  
  2760.     boolean postsOldMouseEvents() {
  2761.         return false;
  2762.     }
  2763.  
  2764.     /** 
  2765.      * Processes input method events occurring on this component by
  2766.      * dispatching them to any registered 
  2767.      * <code>InputMethodListener</code> objects.
  2768.      * <p>
  2769.      * This method is not called unless input method events
  2770.      * are enabled for this component. Input method events are enabled
  2771.      * when one of the following occurs:
  2772.      * <p><ul>
  2773.      * <li>An <code>InputMethodListener</code> object is registered
  2774.      * via <code>addInputMethodListener</code>.
  2775.      * <li>Input method events are enabled via <code>enableEvents</code>.
  2776.      * </ul>
  2777.      * @param       e the input method event
  2778.      * @see         java.awt.event.InputMethodEvent
  2779.      * @see         java.awt.event.InputMethodListener
  2780.      * @see         java.awt.Component#addInputMethodListener
  2781.      * @see         java.awt.Component#enableEvents
  2782.      * @since       JDK1.2
  2783.      */   
  2784.     protected void processInputMethodEvent(InputMethodEvent e) {
  2785.         if (inputMethodListener != null) {
  2786.             int id = e.getID();
  2787.             switch (id) {
  2788.               case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
  2789.                 inputMethodListener.inputMethodTextChanged(e);
  2790.                 break;
  2791.               case InputMethodEvent.CARET_POSITION_CHANGED:
  2792.                 inputMethodListener.caretPositionChanged(e);
  2793.                 break;
  2794.             }
  2795.         }
  2796.     }
  2797.  
  2798.     /**
  2799.      * @deprecated As of JDK version 1.1
  2800.      * replaced by processEvent(AWTEvent).
  2801.      */
  2802.     public boolean handleEvent(Event evt) {
  2803.     switch (evt.id) {
  2804.       case Event.MOUSE_ENTER:
  2805.         return mouseEnter(evt, evt.x, evt.y);
  2806.  
  2807.       case Event.MOUSE_EXIT:
  2808.         return mouseExit(evt, evt.x, evt.y);
  2809.  
  2810.       case Event.MOUSE_MOVE:
  2811.         return mouseMove(evt, evt.x, evt.y);
  2812.  
  2813.       case Event.MOUSE_DOWN:
  2814.         return mouseDown(evt, evt.x, evt.y);
  2815.  
  2816.       case Event.MOUSE_DRAG:
  2817.         return mouseDrag(evt, evt.x, evt.y);
  2818.  
  2819.       case Event.MOUSE_UP:
  2820.         return mouseUp(evt, evt.x, evt.y);
  2821.  
  2822.       case Event.KEY_PRESS:
  2823.       case Event.KEY_ACTION:
  2824.         return keyDown(evt, evt.key);
  2825.  
  2826.       case Event.KEY_RELEASE:
  2827.       case Event.KEY_ACTION_RELEASE:
  2828.         return keyUp(evt, evt.key);
  2829.         
  2830.       case Event.ACTION_EVENT:
  2831.         return action(evt, evt.arg);
  2832.       case Event.GOT_FOCUS:
  2833.         return gotFocus(evt, evt.arg);
  2834.       case Event.LOST_FOCUS:
  2835.         return lostFocus(evt, evt.arg);
  2836.     }
  2837.         return false;
  2838.     }
  2839.  
  2840.     /**
  2841.      * @deprecated As of JDK version 1.1,
  2842.      * replaced by processMouseEvent(MouseEvent).
  2843.      */
  2844.     public boolean mouseDown(Event evt, int x, int y) {
  2845.     return false;
  2846.     }
  2847.  
  2848.     /**
  2849.      * @deprecated As of JDK version 1.1,
  2850.      * replaced by processMouseMotionEvent(MouseEvent).
  2851.      */
  2852.     public boolean mouseDrag(Event evt, int x, int y) {
  2853.     return false;
  2854.     }
  2855.  
  2856.     /**
  2857.      * @deprecated As of JDK version 1.1,
  2858.      * replaced by processMouseEvent(MouseEvent).
  2859.      */
  2860.     public boolean mouseUp(Event evt, int x, int y) {
  2861.     return false;
  2862.     }
  2863.  
  2864.     /**
  2865.      * @deprecated As of JDK version 1.1,
  2866.      * replaced by processMouseMotionEvent(MouseEvent).
  2867.      */
  2868.     public boolean mouseMove(Event evt, int x, int y) {
  2869.     return false;
  2870.     }
  2871.  
  2872.     /**
  2873.      * @deprecated As of JDK version 1.1,
  2874.      * replaced by processMouseEvent(MouseEvent).
  2875.      */
  2876.     public boolean mouseEnter(Event evt, int x, int y) {
  2877.     return false;
  2878.     }
  2879.  
  2880.     /**
  2881.      * @deprecated As of JDK version 1.1,
  2882.      * replaced by processMouseEvent(MouseEvent).
  2883.      */
  2884.     public boolean mouseExit(Event evt, int x, int y) {
  2885.     return false;
  2886.     }
  2887.  
  2888.     /**
  2889.      * @deprecated As of JDK version 1.1,
  2890.      * replaced by processKeyEvent(KeyEvent).
  2891.      */
  2892.     public boolean keyDown(Event evt, int key) {
  2893.     return false;
  2894.     }
  2895.  
  2896.     /**
  2897.      * @deprecated As of JDK version 1.1,
  2898.      * replaced by processKeyEvent(KeyEvent).
  2899.      */
  2900.     public boolean keyUp(Event evt, int key) {
  2901.     return false;
  2902.     }
  2903.  
  2904.     /**
  2905.      * @deprecated As of JDK version 1.1,
  2906.      * should register this component as ActionListener on component
  2907.      * which fires action events.
  2908.      */
  2909.     public boolean action(Event evt, Object what) {
  2910.     return false;
  2911.     }
  2912.  
  2913.     /**
  2914.      * Notifies this component that it has been added to a
  2915.      * displayable containment hierarchy.  Once this method completes,
  2916.      * the component will be "displayable".
  2917.      * This method is called by the toolkit internally, and should
  2918.      * not be invoked by user code directly.
  2919.      * @see #isDisplayable
  2920.      * @see #removeNotify
  2921.      * @since JDK1.0
  2922.      */
  2923.     public void addNotify() {
  2924.     if (peer == null) {
  2925.         peer = getToolkit().createComponent(this);
  2926.  
  2927.         // This is a lightweight component which means it won't be
  2928.         // able to get window-related events by itself.  If any
  2929.         // have been enabled, then the nearest native container must
  2930.         // be enabled.
  2931.         long mask = 0;
  2932.         if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
  2933.         mask |= AWTEvent.MOUSE_EVENT_MASK;
  2934.         }
  2935.         if ((mouseMotionListener != null) ||
  2936.         ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
  2937.         mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
  2938.         }
  2939.         if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
  2940.         mask |= AWTEvent.FOCUS_EVENT_MASK;
  2941.         }
  2942.         if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) {
  2943.         mask |= AWTEvent.KEY_EVENT_MASK;
  2944.         }
  2945.         if (mask != 0) {
  2946.         parent.proxyEnableEvents(mask);
  2947.         }
  2948.     } else {
  2949.         // It's native.  If the parent is lightweight it
  2950.         // will need some help.
  2951.         if (parent != null && parent.peer instanceof java.awt.peer.LightweightPeer) {
  2952.         new NativeInLightFixer();
  2953.         }
  2954.     }
  2955.     invalidate();
  2956.  
  2957.     int npopups = (popups != null? popups.size() : 0);
  2958.     for (int i = 0 ; i < npopups ; i++) {
  2959.         PopupMenu popup = (PopupMenu)popups.elementAt(i);
  2960.         popup.addNotify();
  2961.     }
  2962.         for (Component p = getParent(); p != null; p = p.getParent())
  2963.             if (p instanceof Window) {
  2964.                 if (((Window)p).getWarningString() == null) {
  2965.                     //!CQ set newEventsOnly if appropriate/possible?
  2966.                 }
  2967.                 break;
  2968.             }
  2969.  
  2970.     if (dropTarget != null) dropTarget.addNotify(peer);
  2971.     }
  2972.  
  2973.     /** 
  2974.      * Notifies this component that it has been removed from its
  2975.      * displayable containment hierarchy.  Once this method completes,
  2976.      * this component will no longer be "displayable".
  2977.      * This method is called by the toolkit internally and should
  2978.      * not be invoked by user code directly.
  2979.      * @see #addNotify
  2980.      * @see #isDisplayable
  2981.      */
  2982.     public void removeNotify() {
  2983.         int npopups = (popups != null? popups.size() : 0);
  2984.     for (int i = 0 ; i < npopups ; i++) {
  2985.         PopupMenu popup = (PopupMenu)popups.elementAt(i);
  2986.         popup.removeNotify();
  2987.     }
  2988.     if (peer != null) {
  2989.             ComponentPeer p = peer;
  2990.  
  2991.         if (dropTarget != null) dropTarget.removeNotify(peer);
  2992.  
  2993.             p.hide();    // Hide peer first to stop system events such as cursor moves.
  2994.             peer = null; // Stop peer updates.
  2995.             Toolkit.getEventQueue().removeSourceEvents(this);
  2996.  
  2997.  
  2998.             p.dispose();
  2999.     }
  3000.     }
  3001.  
  3002.     /** 
  3003.      * @deprecated As of JDK version 1.1,
  3004.      * replaced by processFocusEvent(FocusEvent).
  3005.      */
  3006.     public boolean gotFocus(Event evt, Object what) {
  3007.     return false;
  3008.     }
  3009.  
  3010.     /** 
  3011.      * @deprecated As of JDK version 1.1,
  3012.      * replaced by processFocusEvent(FocusEvent).
  3013.      */
  3014.     public boolean lostFocus(Event evt, Object what) {
  3015.     return false;
  3016.     }
  3017.  
  3018.     /**
  3019.      * Returns the value of a flag that indicates whether 
  3020.      * this component can be traversed using
  3021.      * Tab or Shift-Tab keyboard focus traversal.  If this method
  3022.      * returns "false", this component may still request the keyboard
  3023.      * focus using <code>requestFocus()</code>, but it will not automatically
  3024.      * be assigned focus during tab traversal.
  3025.      * @return    <code>true</code> if this component is
  3026.      *            focus-traverable; <code>false</code> otherwise.
  3027.      * @since     JDK1.1
  3028.      */
  3029.     public boolean isFocusTraversable() {
  3030.         ComponentPeer peer = this.peer;
  3031.     if (peer != null) {
  3032.         return peer.isFocusTraversable();
  3033.     }
  3034.     return false;
  3035.     }
  3036.  
  3037.     /** 
  3038.      * Requests that this component get the input focus. 
  3039.      * The component must be visible
  3040.      * on the screen for this request to be granted 
  3041.      * @see FocusEvent
  3042.      * @see #addFocusListener
  3043.      * @see #processFocusEvent
  3044.      * @see #isFocusTraversable
  3045.      * @since JDK1.0
  3046.      */
  3047.     public void requestFocus() {
  3048.         ComponentPeer peer = this.peer;
  3049.     if (peer != null) {
  3050.         if (peer instanceof java.awt.peer.LightweightPeer) {
  3051.         parent.proxyRequestFocus(this);
  3052.         } else {
  3053.         peer.requestFocus();
  3054.                 Toolkit.getEventQueue().changeKeyEventFocus(this);
  3055.         }
  3056.     }
  3057.     }
  3058.  
  3059.     /**
  3060.      * Transfers the focus to the next component.
  3061.      * @see       java.awt.Component#requestFocus
  3062.      * @since     JDK1.1s
  3063.      */
  3064.      public void transferFocus() {
  3065.         nextFocus();
  3066.      }
  3067.  
  3068.     /**
  3069.      * @deprecated As of JDK version 1.1,
  3070.      * replaced by transferFocus().
  3071.      */
  3072.      public void nextFocus() {
  3073.         Container parent = this.parent;
  3074.     if (parent != null) {
  3075.         parent.transferFocus(this);
  3076.     }
  3077.      }
  3078.  
  3079.     
  3080.  
  3081.     /**
  3082.      * Returns true if this Component has the keyboard focus.
  3083.      * 
  3084.      * @return true if this Component has the keyboard focus.
  3085.      * @since JDK1.2
  3086.      */
  3087.     public boolean hasFocus() {
  3088.     if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
  3089.         return hasFocus;
  3090.     }
  3091.     else {
  3092.         for (Container p = getParent(); p != null; p = p.getParent()) {
  3093.         if (p instanceof Window) {
  3094.             return ((Window)p).getFocusOwner() == this;
  3095.         }
  3096.         }
  3097.         return false;
  3098.     }
  3099.     }
  3100.  
  3101.  
  3102.  
  3103.  
  3104.     /**
  3105.      * Adds the specified popup menu to the component.
  3106.      * @param     popup the popup menu to be added to the component.
  3107.      * @see       java.awt.Component#remove(java.awt.MenuComponent)
  3108.      * @since     JDK1.1
  3109.      */
  3110.     public synchronized void add(PopupMenu popup) {
  3111.     if (popup.parent != null) {
  3112.         popup.parent.remove(popup);
  3113.     }
  3114.         if (popups == null) {
  3115.             popups = new Vector();
  3116.         }
  3117.     popups.addElement(popup);
  3118.     popup.parent = this;
  3119.  
  3120.     if (peer != null) {
  3121.         if (popup.peer == null) {
  3122.         popup.addNotify();
  3123.         }
  3124.     }
  3125.     }
  3126.  
  3127.     /**
  3128.      * Removes the specified popup menu from the component.
  3129.      * @param     popup the popup menu to be removed.
  3130.      * @see       java.awt.Component#add(java.awt.PopupMenu)
  3131.      * @since     JDK1.1
  3132.      */
  3133.     public synchronized void remove(MenuComponent popup) {
  3134.         if (popups != null) {
  3135.         int index = popups.indexOf(popup);
  3136.         if (index >= 0) {
  3137.             PopupMenu pmenu = (PopupMenu)popup;
  3138.             if (pmenu.peer != null) {
  3139.             pmenu.removeNotify();
  3140.         }
  3141.         pmenu.parent = null;
  3142.         popups.removeElementAt(index);
  3143.         if (popups.size() == 0) {
  3144.             popups = null;
  3145.         }
  3146.         }
  3147.     }
  3148.     }
  3149.  
  3150.     /**
  3151.      * Returns the parameter string representing the state of this 
  3152.      * component. This string is useful for debugging. 
  3153.      * @return    the parameter string of this component.
  3154.      * @since     JDK1.0
  3155.      */
  3156.     protected String paramString() {
  3157.     String str = (name != null? name : "") + "," + x + "," + y + "," + width + "x" + height;
  3158.     if (!valid) {
  3159.         str += ",invalid";
  3160.     }
  3161.     if (!visible) {
  3162.         str += ",hidden";
  3163.     }
  3164.     if (!enabled) {
  3165.         str += ",disabled";
  3166.     }
  3167.     return str;
  3168.     }
  3169.  
  3170.     /**
  3171.      * Returns a string representation of this component and its values.
  3172.      * @return    a string representation of this component.
  3173.      * @since     JDK1.0
  3174.      */
  3175.     public String toString() {
  3176.     return getClass().getName() + "[" + paramString() + "]";
  3177.     }
  3178.  
  3179.     /**
  3180.      * Prints a listing of this component to the standard system output 
  3181.      * stream <code>System.out</code>. 
  3182.      * @see       java.lang.System#out
  3183.      * @since     JDK1.0
  3184.      */
  3185.     public void list() {
  3186.     list(System.out, 0);
  3187.     }
  3188.  
  3189.     /**
  3190.      * Prints a listing of this component to the specified output 
  3191.      * stream. 
  3192.      * @param    out   a print stream.
  3193.      * @since    JDK1.0
  3194.      */
  3195.     public void list(PrintStream out) {
  3196.     list(out, 0);
  3197.     }
  3198.  
  3199.     /**
  3200.      * Prints out a list, starting at the specified indention, to the 
  3201.      * specified print stream.
  3202.      * @param     out      a print stream.
  3203.      * @param     indent   number of spaces to indent.
  3204.      * @see       java.io.PrintStream#println(java.lang.Object)
  3205.      * @since     JDK1.0  
  3206.      */
  3207.     public void list(PrintStream out, int indent) {
  3208.     for (int i = 0 ; i < indent ; i++) {
  3209.         out.print("  ");
  3210.     }
  3211.     out.println(this);
  3212.     }
  3213.  
  3214.     /**
  3215.      * Prints a listing to the specified print writer.
  3216.      * @param  out  The print writer to print to.
  3217.      * @since JDK1.1
  3218.      */
  3219.     public void list(PrintWriter out) {
  3220.     list(out, 0);
  3221.     }
  3222.  
  3223.     /**
  3224.      * Prints out a list, starting at the specified indention, to 
  3225.      * the specified print writer.
  3226.      * @param out The print writer to print to.
  3227.      * @param indent The number of spaces to indent.
  3228.      * @see       java.io.PrintStream#println(java.lang.Object)
  3229.      * @since JDK1.1
  3230.      */
  3231.     public void list(PrintWriter out, int indent) {
  3232.     for (int i = 0 ; i < indent ; i++) {
  3233.         out.print("  ");
  3234.     }
  3235.     out.println(this);
  3236.     }
  3237.  
  3238.     /*
  3239.      * Fetch the native container somewhere higher up in the component
  3240.      * tree that contains this component.  
  3241.      */
  3242.     Container getNativeContainer() {
  3243.     Container p = parent;
  3244.     while (p != null && p.peer instanceof java.awt.peer.LightweightPeer) {
  3245.         p = p.getParent();
  3246.     }
  3247.     return p;
  3248.     }
  3249.  
  3250.     /**
  3251.      * Add a PropertyChangeListener to the listener list.
  3252.      * The listener is registered for all properties.
  3253.      * <p>
  3254.      * A PropertyChangeEvent will get fired in response to an
  3255.      * explicit setFont, setBackground, or SetForeground on the
  3256.      * current component.  Note that if the current component is
  3257.      * inheriting its foreground, background, or font from its
  3258.      * container, then no event will be fired in response to a
  3259.      * change in the inherited property.
  3260.      *
  3261.      * @param listener  The PropertyChangeListener to be added
  3262.      */
  3263.  
  3264.     public synchronized void addPropertyChangeListener(
  3265.                 PropertyChangeListener listener) {
  3266.     if (changeSupport == null) {
  3267.         changeSupport = new java.beans.PropertyChangeSupport(this);
  3268.     }
  3269.     changeSupport.addPropertyChangeListener(listener);
  3270.     }
  3271.  
  3272.     /**
  3273.      * Remove a PropertyChangeListener from the listener list.
  3274.      * This removes a PropertyChangeListener that was registered
  3275.      * for all properties.
  3276.      *
  3277.      * @param listener  The PropertyChangeListener to be removed
  3278.      */
  3279.  
  3280.     public synchronized void removePropertyChangeListener(
  3281.                 PropertyChangeListener listener) {
  3282.     if (changeSupport == null) {
  3283.         return;
  3284.     }
  3285.     changeSupport.removePropertyChangeListener(listener);
  3286.     }
  3287.  
  3288.     /**
  3289.      * Add a PropertyChangeListener for a specific property.  The listener
  3290.      * will be invoked only when a call on firePropertyChange names that
  3291.      * specific property.
  3292.      *
  3293.      * @param propertyName  The name of the property to listen on.
  3294.      * @param listener  The PropertyChangeListener to be added
  3295.      */
  3296.  
  3297.     public synchronized void addPropertyChangeListener(
  3298.                 String propertyName,
  3299.                 PropertyChangeListener listener) {
  3300.     if (changeSupport == null) {
  3301.         changeSupport = new java.beans.PropertyChangeSupport(this);
  3302.     }
  3303.     changeSupport.addPropertyChangeListener(propertyName, listener);
  3304.     }
  3305.  
  3306.     /**
  3307.      * Remove a PropertyChangeListener for a specific property.
  3308.      *
  3309.      * @param propertyName  The name of the property that was listened on.
  3310.      * @param listener  The PropertyChangeListener to be removed
  3311.      */
  3312.  
  3313.     public synchronized void removePropertyChangeListener(
  3314.                 String propertyName,
  3315.                 PropertyChangeListener listener) {
  3316.     if (changeSupport == null) {
  3317.         return;
  3318.     }
  3319.     changeSupport.removePropertyChangeListener(propertyName, listener);
  3320.     }
  3321.  
  3322.     /**
  3323.      * Support for reporting bound property changes.  This method can be called
  3324.      * when a bound property has changed and it will send the appropriate
  3325.      * PropertyChangeEvent to any registered PropertyChangeListeners.
  3326.      */
  3327.     protected void firePropertyChange(String propertyName,
  3328.                     Object oldValue, Object newValue) {
  3329.     if (changeSupport == null) {
  3330.         return;
  3331.     }
  3332.     changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  3333.     }
  3334.  
  3335.  
  3336.     /* Serialization support.  
  3337.      */
  3338.  
  3339.     private int componentSerializedDataVersion = 2;
  3340.  
  3341.     private void writeObject(ObjectOutputStream s) 
  3342.         throws IOException 
  3343.     {
  3344.       s.defaultWriteObject();
  3345.       
  3346.       AWTEventMulticaster.save(s, componentListenerK, componentListener);
  3347.       AWTEventMulticaster.save(s, focusListenerK, focusListener);
  3348.       AWTEventMulticaster.save(s, keyListenerK, keyListener);
  3349.       AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
  3350.       AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener);
  3351.       AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener);
  3352.       
  3353.       s.writeObject(null);
  3354.     }
  3355.  
  3356.     private void readObject(ObjectInputStream s)
  3357.         throws ClassNotFoundException, IOException 
  3358.     {
  3359.         s.defaultReadObject();
  3360.       
  3361.         Object keyOrNull;
  3362.         while(null != (keyOrNull = s.readObject())) {
  3363.         String key = ((String)keyOrNull).intern();
  3364.  
  3365.         if (componentListenerK == key) 
  3366.             addComponentListener((ComponentListener)(s.readObject()));
  3367.  
  3368.         else if (focusListenerK == key) 
  3369.             addFocusListener((FocusListener)(s.readObject()));
  3370.  
  3371.         else if (keyListenerK == key) 
  3372.             addKeyListener((KeyListener)(s.readObject()));
  3373.  
  3374.         else if (mouseListenerK == key) 
  3375.             addMouseListener((MouseListener)(s.readObject()));
  3376.  
  3377.         else if (mouseMotionListenerK == key)
  3378.             addMouseMotionListener((MouseMotionListener)(s.readObject()));
  3379.  
  3380.         else if (inputMethodListenerK == key)
  3381.             addInputMethodListener((InputMethodListener)(s.readObject()));
  3382.  
  3383.         else // skip value for unrecognized key
  3384.             s.readObject();
  3385.  
  3386.         }
  3387.  
  3388.     if (popups != null) {
  3389.         int npopups = popups.size();
  3390.         for (int i = 0 ; i < npopups ; i++) {
  3391.         PopupMenu popup = (PopupMenu)popups.elementAt(i);
  3392.         popup.parent = this;
  3393.         }
  3394.     }
  3395.     }
  3396.  
  3397.     /**
  3398.      * This odd class is to help out a native component that has been
  3399.      * embedded in a lightweight component.  Moving lightweight
  3400.      * components around and changing their visibility is not seen
  3401.      * by the native window system.  This is a feature for lightweights,
  3402.      * but a problem for native components that depend upon the 
  3403.      * lightweights.  An instance of this class listens to the lightweight
  3404.      * parents of an associated native component (the outer class).
  3405.      *
  3406.      * @author  Timothy Prinzing
  3407.      */
  3408.     private final class NativeInLightFixer implements ComponentListener, ContainerListener {
  3409.  
  3410.     NativeInLightFixer() {
  3411.         lightParents = new Vector();
  3412.         Container p = parent;
  3413.         // stash a reference to the components that are being observed so that
  3414.         // we can reliably remove ourself as a listener later.
  3415.         for (; p.peer instanceof java.awt.peer.LightweightPeer; p = p.parent) {
  3416.  
  3417.         // register listeners and stash a reference 
  3418.         p.addComponentListener(this);
  3419.         p.addContainerListener(this);
  3420.         lightParents.addElement(p);
  3421.         }
  3422.         // register with the native host (native parent of associated native)
  3423.         // to get notified if the top-level lightweight is removed.
  3424.         nativeHost = p;
  3425.         p.addContainerListener(this);
  3426.  
  3427.         // kick start the fixup.  Since the event isn't looked at
  3428.         // we can simulate movement notification.
  3429.         componentMoved(null);
  3430.     }
  3431.  
  3432.     // --- ComponentListener -------------------------------------------
  3433.  
  3434.     /**
  3435.      * Invoked when one of the lightweight parents has been resized.
  3436.      * This doesn't change the position of the native child so it
  3437.      * is ignored.
  3438.      */
  3439.         public void componentResized(ComponentEvent e) {
  3440.     }
  3441.  
  3442.     /**
  3443.      * Invoked when one of the lightweight parents has been moved.  
  3444.      * The native peer must be told of the new position which is
  3445.      * relative to the native container that is hosting the
  3446.      * lightweight components.
  3447.      */    
  3448.         public void componentMoved(ComponentEvent e) {
  3449.         synchronized (Component.LOCK) {
  3450.         int nativeX = x;
  3451.         int nativeY = y;
  3452.         for(Component c = parent; (c != null) &&
  3453.             (c.peer instanceof java.awt.peer.LightweightPeer); 
  3454.             c = c.parent) {
  3455.             
  3456.             nativeX += c.x;
  3457.             nativeY += c.y;
  3458.         }
  3459.         peer.setBounds(nativeX, nativeY, width, height);
  3460.         }
  3461.     }
  3462.  
  3463.     /**
  3464.      * Invoked when a lightweight parent component has been 
  3465.      * shown.  The associated native component must also be
  3466.      * shown if it hasn't had an overriding hide done on it.
  3467.      */
  3468.         public void componentShown(ComponentEvent e) {
  3469.         if (isShowing()) {
  3470.         synchronized (Component.LOCK) {
  3471.             if (peer != null) {
  3472.             peer.show();
  3473.             }
  3474.         }
  3475.         }
  3476.     }
  3477.  
  3478.     /**
  3479.      * Invoked when component has been hidden.
  3480.      */
  3481.         public void componentHidden(ComponentEvent e) {
  3482.         if (visible) {
  3483.         synchronized (Component.LOCK) {
  3484.             if (peer != null) {
  3485.             peer.hide();
  3486.             }
  3487.         }
  3488.         }
  3489.     }
  3490.  
  3491.     // --- ContainerListener ------------------------------------
  3492.  
  3493.     /**
  3494.      * Invoked when a component has been added to a lightweight
  3495.      * parent.  This doesn't effect the native component.
  3496.      */
  3497.         public void componentAdded(ContainerEvent e) {
  3498.     }
  3499.  
  3500.     /**
  3501.      * Invoked when a lightweight parent has been removed.
  3502.      * This means the services of this listener are no longer
  3503.      * required and it should remove all references (ie
  3504.      * registered listeners).
  3505.      */    
  3506.         public void componentRemoved(ContainerEvent e) {
  3507.         Component c = e.getChild();
  3508.         if (c == Component.this) {
  3509.         removeReferences();
  3510.         } else {
  3511.         int n = lightParents.size();
  3512.         for (int i = 0; i < n; i++) {
  3513.             Container p = (Container) lightParents.elementAt(i);
  3514.             if (p == c) {
  3515.             removeReferences();
  3516.             break;
  3517.             }
  3518.         }
  3519.         }
  3520.     }
  3521.  
  3522.     /**
  3523.      * Remove references to this object so it can be
  3524.      * garbage collected.
  3525.      */
  3526.     void removeReferences() {
  3527.         int n = lightParents.size();
  3528.         for (int i = 0; i < n; i++) {
  3529.         Container c = (Container) lightParents.elementAt(i);
  3530.         c.removeComponentListener(this);
  3531.         c.removeContainerListener(this);
  3532.         }
  3533.         nativeHost.removeContainerListener(this);
  3534.     }
  3535.  
  3536.     Vector lightParents;
  3537.     Container nativeHost;
  3538.     }
  3539.  
  3540.     /**
  3541.      * Initialize JNI field and method IDs
  3542.      */
  3543.     private static native void initIDs();
  3544.  
  3545. }
  3546.