home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / Component.java < prev    next >
Text File  |  1998-01-28  |  98KB  |  2,971 lines

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