/*
 
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
 
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
*
 
* This code is free software; you can redistribute it and/or modify it
 
* under the terms of the GNU General Public License version 2 only, as
 
* published by the Free Software Foundation.
  
Oracle designates this
 
* particular file as subject to the "Classpath" exception as provided
 
* by Oracle in the LICENSE file that accompanied this code.
 
*
 
* This code is distributed in the hope that it will be useful, but WITHOUT
 
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
* FITNESS FOR A PARTICULAR PURPOSE.
  
See the GNU General Public License
 
* version 2 for more details (a copy is included in the LICENSE file that
 
* accompanied this code).
 
*
 
* You should have received a copy of the GNU General Public License version
 
* 2 along with this work; if not, write to the Free Software Foundation,
 
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
*
 
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 
* or visit www.oracle.com if you need additional information or have any
 
* questions.
 
*/
package java.awt;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Vector;
import java.util.Locale;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Collections;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.awt.image.BufferStrategy;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.ColorModel;
import java.awt.image.VolatileImage;
import java.awt.event.*;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.Transient;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.dnd.DropTarget;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.AccessControlContext;
import javax.accessibility.*;
import java.applet.Applet;

import sun.security.action.GetPropertyAction;
import sun.awt.AppContext;
import sun.awt.AWTAccessor;
import sun.awt.ConstrainableGraphics;
import sun.awt.SubRegionShowable;
import sun.awt.SunToolkit;
import sun.awt.WindowClosingListener;
import sun.awt.CausedFocusEvent;
import sun.awt.EmbeddedFrame;
import sun.awt.dnd.SunDropTargetEvent;
import sun.awt.im.CompositionArea;
import sun.font.FontManager;
import sun.font.FontManagerFactory;
import sun.font.SunFontManager;
import sun.java2d.SunGraphics2D;
import sun.java2d.pipe.Region;
import sun.awt.image.VSyncedBSManager;
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
import sun.awt.RequestFocusController;
import sun.java2d.SunGraphicsEnvironment;
import sun.util.logging.PlatformLogger;

/**
 
* A <em>component</em> is an object having a graphical representation
 
* that can be displayed on the screen and that can interact with the
 
* user. Examples of components are the buttons, checkboxes, and scrollbars
 
* of a typical graphical user interface. <p>
 
* The <code>Component</code> class is the abstract superclass of
 
* the nonmenu-related Abstract Window Toolkit components. Class
 
* <code>Component</code> can also be extended directly to create a
 
* lightweight component. A lightweight component is a component that is
 
* not associated with a native window. On the contrary, a heavyweight
 
* component is associated with a native window. The
 
* method may be used to distinguish between the two kinds of the components.
 
* <p>
 
* Lightweight and heavyweight components may be mixed in a single component
 
* hierarchy. However, for correct operating of such a mixed hierarchy of
 
* components, the whole hierarchy must be valid. When the hierarchy gets
 
* invalidated, like after changing the bounds of components, or
 
* adding/removing components to/from containers, the whole hierarchy must be
 
* validated afterwards by means of the {@link Container#validate()} method
 
* invoked on the top-most invalid container of the hierarchy.
 
*
 
* <h3>Serialization</h3>
 
* It is important to note that only AWT listeners which conform
 
* to the <code>Serializable</code> protocol will be saved when
 
* the object is stored.
  
If an AWT object has listeners that
 
* aren't marked serializable, they will be dropped at
 
* <code>writeObject</code> time.
  
Developers will need, as always,
 
* to consider the implications of making an object serializable.
 
* One situation to watch out for is this:
 
* <pre>
 
*
    
import java.awt.*;
 
*
    
import java.awt.event.*;
 
*
    
import java.io.Serializable;
 
*
 
*
    
class MyApp implements ActionListener, Serializable
 
*
    
{
 
*
        
BigObjectThatShouldNotBeSerializedWithAButton bigOne;
 
*
        
Button aButton = new Button();
 
*
 
*
        
MyApp()
 
*
        
{
 
*
            
// Oops, now aButton has a listener with a reference
 
*
            
// to bigOne!
 
*
            
aButton.addActionListener(this);
 
*
        
}
 
*
 
*
        
public void actionPerformed(ActionEvent e)
 
*
        
{
 
*
            
System.out.println("Hello There");
 
*
        
}
 
*
    
}
 
* </pre>
 
* In this example, serializing <code>aButton</code> by itself
 
* will cause <code>MyApp</code> and everything it refers to
 
* to be serialized as well.
  
The problem is that the listener
 
* is serializable by coincidence, not by design.
  
To separate
 
* the decisions about <code>MyApp</code> and the
 
* <code>ActionListener</code> being serializable one can use a
 
* nested class, as in the following example:
 
* <pre>
 
*
    
import java.awt.*;
 
*
    
import java.awt.event.*;
 
*
    
import java.io.Serializable;
 
*
 
*
    
class MyApp implements java.io.Serializable
 
*
    
{
 
*
         
BigObjectThatShouldNotBeSerializedWithAButton bigOne;
 
*
         
Button aButton = new Button();
 
*
 
*
         
static class MyActionListener implements ActionListener
 
*
         
{
 
*
             
public void actionPerformed(ActionEvent e)
 
*
             
{
 
*
                 
System.out.println("Hello There");
 
*
             
}
 
*
         
}
 
*
 
*
         
MyApp()
 
*
         
{
 
*
             
aButton.addActionListener(new MyActionListener());
 
*
         
}
 
*
    
}
 
* </pre>
 
* <p>
 
* <b>Note</b>: For more information on the paint mechanisms utilitized
 
* by AWT and Swing, including information on how to write the most
 
* efficient painting code, see
 
*<a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
 
* <p>
 
* For details on the focus subsystem, see
 
* <a href=" https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
 
* How to Use the Focus Subsystem</a>,
 
* a section in <em>The Java Tutorial</em>, and the
 
*<a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
 
* for more information.
 
*
 
* @author
      
Arthur van Hoff
 
* @author
      
Sami Shaio
 
*/

public abstract class Component implements ImageObserver, MenuContainer,
                                           
Serializable
{

    
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
    
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
    
private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
    
private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");

    
/**
     
* The peer of the component. The peer implements the component's
     
* behavior. The peer is set when the <code>Component</code> is
     
* added to a container that also is a peer.
     
* @see #addNotify
     
* @see #removeNotify
     
*/

    
transient ComponentPeer peer;

    
/**
     
* The parent of the object. It may be <code>null</code>
     
* for top-level components.
     
* @see #getParent
     
*/

    
transient Container parent;

    
/**
     
* The <code>AppContext</code> of the component. Applets/Plugin may
     
* change the AppContext.
     
*/

    
transient AppContext appContext;

    
/**
     
* The x position of the component in the parent's coordinate system.
     
*
     
* @serial
     
* @see #getLocation
     
*/

    
int x;

    
/**
     
* The y position of the component in the parent's coordinate system.
     
*
     
* @serial
     
* @see #getLocation
     
*/

    
int y;

    
/**
     
* The width of the component.
     
*
     
* @serial
     
* @see #getSize
     
*/
    
int width;

    
/**
     
* The height of the component.
     
*
     
* @serial
     
* @see #getSize
     
*/
    
int height;

    
/**
     
* The foreground color for this component.
     
* <code>foreground</code> can be <code>null</code>.
     
*
     
* @serial
     
* @see #getForeground
     
* @see #setForeground
     
*/

    
Color
       
foreground
;

    
/**
     
* The background color for this component.
     
* <code>background</code> can be <code>null</code>.
     
*
     
* @serial
     
* @see #getBackground
     
* @see #setBackground
     
*/

    
Color
       
background
;

    
/**
     
* The font used by this component.
     
* The <code>font</code> can be <code>null</code>.
     
*
     
* @serial
     
* @see #getFont
     
* @see #setFont
     
*/

    
volatile Font font;

    
/**
     
* The font which the peer is currently using.
     
* (<code>null</code> if no peer exists.)
     
*/

    
Font
        
peerFont
;

    
/**
     
* The cursor displayed when pointer is over this component.
     
* This value can be <code>null</code>.
     
*
     
* @serial
     
* @see #getCursor
     
* @see #setCursor
     
*/

    
Cursor
      
cursor
;

    
/**
     
* The locale for the component.
     
*
     
* @serial
     
* @see #getLocale
     
* @see #setLocale
     
*/

    
Locale
      
locale
;

    
/**
     
* A reference to a <code>GraphicsConfiguration</code> object
     
* used to describe the characteristics of a graphics
     
* destination.
     
* This value can be <code>null</code>.
     
*
     
* @since 1.3
     
* @serial
     
* @see GraphicsConfiguration
     
* @see #getGraphicsConfiguration
     
*/

    
private transient volatile GraphicsConfiguration graphicsConfig;

    
/**
     
* A reference to a <code>BufferStrategy</code> object
     
* used to manipulate the buffers on this component.
     
*
     
* @since 1.4
     
*
 

     
*
 

     
*/

    
transient BufferStrategy bufferStrategy = null;

    
/**
     
* True when the object should ignore all repaint events.
     
*
     
* @since 1.4
     
* @serial
     
* @see #setIgnoreRepaint
     
* @see #getIgnoreRepaint
     
*/

    
boolean ignoreRepaint = false;

    
/**
     
* True when the object is visible. An object that is not
     
* visible is not drawn on the screen.
     
*
     
* @serial
     
* @see #isVisible
     
* @see #setVisible
     
*/

    
boolean visible = true;

    
/**
     
* True when the object is enabled. An object that is not
     
* enabled does not interact with the user.
     
*
     
* @serial
     
* @see #isEnabled
     
* @see #setEnabled
     
*/

    
boolean enabled = true;

    
/**
     
* True when the object is valid. An invalid object needs to
     
* be layed out. This flag is set to false when the object
     
* size is changed.
     
*
     
* @serial
     
* @see #isValid
     
* @see #validate
     
* @see #invalidate
     
*/

    
private volatile boolean valid = false;

    
/**
     
* The <code>DropTarget</code> associated with this component.
     
*
     
* @since 1.2
     
* @serial
     
* @see #setDropTarget
     
* @see #getDropTarget
     
*/

    
DropTarget dropTarget;

    
/**
     
* @serial
     
* @see #add
     
*/
    
Vector<PopupMenu> popups;

    
/**
     
* A component's name.
     
* This field can be <code>null</code>.
     
*
     
* @serial
     
* @see #getName
     
* @see #setName(String)
     
*/

    
private String name;

    
/**
     
* A bool to determine whether the name has
     
* been set explicitly. <code>nameExplicitlySet</code> will
     
* be false if the name has not been set and
     
* true if it has.
     
*
     
* @serial
     
* @see #getName
     
* @see #setName(String)
     
*/

    
private boolean nameExplicitlySet = false;

    
/**
     
* Indicates whether this Component can be focused.
     
*
     
* @serial
     
* @see #setFocusable
     
* @see #isFocusable
     
* @since 1.4
     
*/

    
private boolean focusable = true;

    
private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
    
private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
    
private static final int FOCUS_TRAVERSABLE_SET = 2;

    
/**
     
* Tracks whether this Component is relying on default focus travesability.
     
*
     
* @serial
     
* @since 1.4
     
*/

    
private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;

    
/**
     
* The focus traversal keys. These keys will generate focus traversal
     
* behavior for Components for which focus traversal keys are enabled. If a
     
* value of null is specified for a traversal key, this Component inherits
     
* that traversal key from its parent. If all ancestors of this Component
     
* have null specified for that traversal key, then the current
     
* KeyboardFocusManager's default traversal key is used.
     
*
     
* @serial
     
* @see #setFocusTraversalKeys
     
* @see #getFocusTraversalKeys
     
* @since 1.4
     
*/

    
Set<AWTKeyStroke>[] focusTraversalKeys;

    
private static final String[] focusTraversalKeyPropertyNames = {
        
"forwardFocusTraversalKeys",
        
"backwardFocusTraversalKeys",
        
"upCycleFocusTraversalKeys",
        
"downCycleFocusTraversalKeys"
    
};

    
/**
     
* Indicates whether focus traversal keys are enabled for this Component.
     
* Components for which focus traversal keys are disabled receive key
     
* events for focus traversal keys. Components for which focus traversal
     
* keys are enabled do not see these events; instead, the events are
     
* automatically converted to traversal operations.
     
*
     
* @serial
     
* @see #setFocusTraversalKeysEnabled
     
* @see #getFocusTraversalKeysEnabled
     
* @since 1.4
     
*/

    
private boolean focusTraversalKeysEnabled = true;

    
/**
     
* The locking object for AWT component-tree and layout operations.
     
*
     
* @see #getTreeLock
     
*/

    
static final Object LOCK = new AWTTreeLock();
    
static class AWTTreeLock {}

    
/*
     
* The component's AccessControlContext.
     
*/
    
private transient volatile AccessControlContext acc =
        
AccessController.getContext();

    
/**
     
* Minimum size.
     
* (This field perhaps should have been transient).
     
*
     
* @serial
     
*/

    
Dimension minSize;

    
/**
     
* Whether or not setMinimumSize has been invoked with a non-null value.
     
*/

    
boolean minSizeSet;

    
/**
     
* Preferred size.
     
* (This field perhaps should have been transient).
     
*
     
* @serial
     
*/

    
Dimension prefSize;

    
/**
     
* Whether or not setPreferredSize has been invoked with a non-null value.
     
*/

    
boolean prefSizeSet;

    
/**
     
* Maximum size
     
*
     
* @serial
     
*/
    
Dimension maxSize;

    
/**
     
* Whether or not setMaximumSize has been invoked with a non-null value.
     
*/

    
boolean maxSizeSet;

    
/**
     
* The orientation for this component.
     
* @see #getComponentOrientation
     
* @see #setComponentOrientation
     
*/
    
transient ComponentOrientation componentOrientation
    
= ComponentOrientation.UNKNOWN;

    
/**
     
* <code>newEventsOnly</code> will be true if the event is
     
* one of the event types enabled for the component.
     
* It will then allow for normal processing to
     
* continue.
  
If it is false the event is passed
     
* to the component's parent and up the ancestor
     
* tree until the event has been consumed.
     
*
     
* @serial
     
* @see #dispatchEvent
     
*/

    
boolean newEventsOnly = false;
    
transient ComponentListener componentListener;
    
transient FocusListener focusListener;
    
transient HierarchyListener hierarchyListener;
    
transient HierarchyBoundsListener hierarchyBoundsListener;
    
transient KeyListener keyListener;
    
transient MouseListener mouseListener;
    
transient MouseMotionListener mouseMotionListener;
    
transient MouseWheelListener mouseWheelListener;
    
transient InputMethodListener inputMethodListener;

    
transient RuntimeException windowClosingException = null;

    
/** Internal, constants for serialization */
    
final static String actionListenerK = "actionL";
    
final static String adjustmentListenerK = "adjustmentL";
    
final static String componentListenerK = "componentL";
    
final static String containerListenerK = "containerL";
    
final static String focusListenerK = "focusL";
    
final static String itemListenerK = "itemL";
    
final static String keyListenerK = "keyL";
    
final static String mouseListenerK = "mouseL";
    
final static String mouseMotionListenerK = "mouseMotionL";
    
final static String mouseWheelListenerK = "mouseWheelL";
    
final static String textListenerK = "textL";
    
final static String ownedWindowK = "ownedL";
    
final static String windowListenerK = "windowL";
    
final static String inputMethodListenerK = "inputMethodL";
    
final static String hierarchyListenerK = "hierarchyL";
    
final static String hierarchyBoundsListenerK = "hierarchyBoundsL";
    
final static String windowStateListenerK = "windowStateL";
    
final static String windowFocusListenerK = "windowFocusL";

    
/**
     
* The <code>eventMask</code> is ONLY set by subclasses via
     
* <code>enableEvents</code>.
     
* The mask should NOT be set when listeners are registered
     
* so that we can distinguish the difference between when
     
* listeners request events and subclasses request them.
     
* One bit is used to indicate whether input methods are
     
* enabled; this bit is set by <code>enableInputMethods</code> and is
     
* on by default.
     
*
     
* @serial
     
* @see #enableInputMethods
     
* @see AWTEvent
     
*/

    
long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;

    
/**
     
* Static properties for incremental drawing.
     
* @see #imageUpdate
     
*/

    
static boolean isInc;
    
static int incRate;
    
static {
        
/* ensure that the necessary native libraries are loaded */
        
Toolkit.loadLibraries();
        
/* initialize JNI field and method ids */
        
if (!GraphicsEnvironment.isHeadless()) {
            
initIDs();
        
}

        
String s = java.security.AccessController.doPrivileged(
                                                               
new GetPropertyAction("awt.image.incrementaldraw"));
        
isInc = (s == null || s.equals("true"));

        
s = java.security.AccessController.doPrivileged(
                                                        
new GetPropertyAction("awt.image.redrawrate"));
        
incRate = (s != null) ? Integer.parseInt(s) : 100;
    
}

    
/**
     
* Ease-of-use constant for <code>getAlignmentY()</code>.
     
* Specifies an alignment to the top of the component.
     
* @see#getAlignmentY
     
*/

    
public static final float TOP_ALIGNMENT = 0.0f;

    
/**
     
* Ease-of-use constant for <code>getAlignmentY</code> and
     
* <code>getAlignmentX</code>. Specifies an alignment to
     
* the center of the component
     
* @see#getAlignmentX
     
* @see#getAlignmentY
     
*/

    
public static final float CENTER_ALIGNMENT = 0.5f;

    
/**
     
* Ease-of-use constant for <code>getAlignmentY</code>.
     
* Specifies an alignment to the bottom of the component.
     
* @see#getAlignmentY
     
*/

    
public static final float BOTTOM_ALIGNMENT = 1.0f;

    
/**
     
* Ease-of-use constant for <code>getAlignmentX</code>.
     
* Specifies an alignment to the left side of the component.
     
* @see#getAlignmentX
     
*/

    
public static final float LEFT_ALIGNMENT = 0.0f;

    
/**
     
* Ease-of-use constant for <code>getAlignmentX</code>.
     
* Specifies an alignment to the right side of the component.
     
* @see#getAlignmentX
     
*/

    
public static final float RIGHT_ALIGNMENT = 1.0f;

    
/*
     
* JDK 1.1 serialVersionUID
     
*/
    
private static final long serialVersionUID = -7644114512714619750L;

    
/**
     
* If any <code>PropertyChangeListeners</code> have been registered,
     
* the <code>changeSupport</code> field describes them.
     
*
     
* @serial
     
* @since 1.2
     
* @see #addPropertyChangeListener
     
* @see #removePropertyChangeListener
     
* @see #firePropertyChange
     
*/

    
private PropertyChangeSupport changeSupport;

    
/*
     
* In some cases using "this" as an object to synchronize by
     
* can lead to a deadlock if client code also uses synchronization
     
* by a component object. For every such situation revealed we should
     
* consider possibility of replacing "this" with the package private
     
* objectLock object introduced below. So far there're 3 issues known:
     
* - CR 6708322 (the getName/setName methods);
     
* - CR 6608764 (the PropertyChangeListener machinery);
     
* - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
     
*
     
* Note: this field is considered final, though readObject() prohibits
     
* initializing final fields.
     
*/

    
private transient Object objectLock = new Object();
    
Object getObjectLock() {
        
return objectLock;
    
}

    
/*
     
* Returns the acc this component was constructed with.
     
*/
    
final AccessControlContext getAccessControlContext() {
        
if (acc == null) {
            
throw new SecurityException("Component is missing AccessControlContext");
        
}
        
return acc;
    
}

    
boolean isPacked = false;

    
/**
     
* Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
     
* to signal setBounds what's changing. Should be used under TreeLock.
     
* This is only needed due to the inability to change the cross-calling
     
* order of public and deprecated methods.
     
*/

    
private int boundsOp = ComponentPeer.DEFAULT_OPERATION;

    
/**
     
* Enumeration of the common ways the baseline of a component can
     
* change as the size changes.
  
The baseline resize behavior is
     
* primarily for layout managers that need to know how the
     
* position of the baseline changes as the component size changes.
     
* In general the baseline resize behavior will be valid for sizes
     
* greater than or equal to the minimum size (the actual minimum
     
* size; not a developer specified minimum size).
  
For sizes
     
* smaller than the minimum size the baseline may change in a way
     
* other than the baseline resize behavior indicates.
  
Similarly,
     
* as the size approaches <code>Integer.MAX_VALUE</code> and/or
     
* <code>Short.MAX_VALUE</code> the baseline may change in a way
     
* other than the baseline resize behavior indicates.
     
*
     
* @see #getBaselineResizeBehavior
     
* @see #getBaseline(int,int)
     
* @since 1.6
     
*/

    
public enum BaselineResizeBehavior {
        
/**
         
* Indicates the baseline remains fixed relative to the
         
* y-origin.
  
That is, <code>getBaseline</code> returns
         
* the same value regardless of the height or width.
  
For example, a
         
* <code>JLabel</code> containing non-empty text with a
         
* vertical alignment of <code>TOP</code> should have a
         
* baseline type of <code>CONSTANT_ASCENT</code>.
         
*/

        
CONSTANT_ASCENT,

        
/**
         
* Indicates the baseline remains fixed relative to the height
         
* and does not change as the width is varied.
  
That is, for
         
* any height H the difference between H and
         
* <code>getBaseline(w, H)</code> is the same.
  
For example, a
         
* <code>JLabel</code> containing non-empty text with a
         
* vertical alignment of <code>BOTTOM</code> should have a
         
* baseline type of <code>CONSTANT_DESCENT</code>.
         
*/

        
CONSTANT_DESCENT,

        
/**
         
* Indicates the baseline remains a fixed distance from
         
* the center of the component.
  
That is, for any height H the
         
* difference between <code>getBaseline(w, H)</code> and
         
* <code>H / 2</code> is the same (plus or minus one depending upon
         
* rounding error).
         
* <p>
         
* Because of possible rounding errors it is recommended
         
* you ask for the baseline with two consecutive heights and use
         
* the return value to determine if you need to pad calculations
         
* by 1.
  
The following shows how to calculate the baseline for
         
* any height:
         
* <pre>
         
*
   
Dimension preferredSize = component.getPreferredSize();
         
*
   
int baseline = getBaseline(preferredSize.width,
         
*
                              
preferredSize.height);
         
*
   
int nextBaseline = getBaseline(preferredSize.width,
         
*
                                  
preferredSize.height + 1);
         
*
   
// Amount to add to height when calculating where baseline
         
*
   
// lands for a particular height:
         
*
   
int padding = 0;
         
*
   
// Where the baseline is relative to the mid point
         
*
   
int baselineOffset = baseline - height / 2;
         
*
   
if (preferredSize.height % 2 == 0 &amp;&amp;
         
*
       
baseline != nextBaseline) {
         
*
       
padding = 1;
         
*
   
}
         
*
   
else if (preferredSize.height % 2 == 1 &amp;&amp;
         
*
            
baseline == nextBaseline) {
         
*
       
baselineOffset--;
         
*
       
padding = 1;
         
*
   
}
         
*
   
// The following calculates where the baseline lands for
         
*
   
// the height z:
         
*
   
int calculatedBaseline = (z + padding) / 2 + baselineOffset;
         
* </pre>
         
*/

        
CENTER_OFFSET,

        
/**
         
* Indicates the baseline resize behavior can not be expressed using
         
* any of the other constants.
  
This may also indicate the baseline
         
* varies with the width of the component.
  
This is also returned
         
* by components that do not have a baseline.
         
*/

        
OTHER
    
}

    
/*
     
* The shape set with the applyCompoundShape() method. It uncludes the result
     
* of the HW/LW mixing related shape computation. It may also include
     
* the user-specified shape of the component.
     
* The 'null' value means the component has normal shape (or has no shape at all)
     
* and applyCompoundShape() will skip the following shape identical to normal.
     
*/

    
private transient Region compoundShape = null;

    
/*
     
* Represents the shape of this lightweight component to be cut out from
     
* heavyweight components should they intersect. Possible values:
     
*
    
1. null - consider the shape rectangular
     
*
    
2. EMPTY_REGION - nothing gets cut out (children still get cut out)
     
*
    
3. non-empty - this shape gets cut out.
     
*/

    
private transient Region mixingCutoutRegion = null;

    
/*
     
* Indicates whether addNotify() is complete
     
* (i.e. the peer is created).
     
*/

    
private transient boolean isAddNotifyComplete = false;

    
/**
     
* Should only be used in subclass getBounds to check that part of bounds
     
* is actualy changing
     
*/

    
int getBoundsOp() {
        
assert Thread.holdsLock(getTreeLock());
        
return boundsOp;
    
}

    
void setBoundsOp(int op) {
        
assert Thread.holdsLock(getTreeLock());
        
if (op == ComponentPeer.RESET_OPERATION) {
            
boundsOp = ComponentPeer.DEFAULT_OPERATION;
        
} else
            
if
(boundsOp == ComponentPeer.DEFAULT_OPERATION) {
                
boundsOp = op;
            
}
    
}

    
// Whether this Component has had the background erase flag
    
// specified via SunToolkit.disableBackgroundErase(). This is
    
// needed in order to make this function work on X11 platforms,
    
// where currently there is no chance to interpose on the creation
    
// of the peer and therefore the call to XSetBackground.
    
transient boolean backgroundEraseDisabled;

    
static {
        
AWTAccessor.setComponentAccessor(new AWTAccessor.ComponentAccessor() {
            
public void setBackgroundEraseDisabled(Component comp, boolean disabled) {
                
comp.backgroundEraseDisabled = disabled;
            
}
            
public boolean getBackgroundEraseDisabled(Component comp) {
                
return comp.backgroundEraseDisabled;
            
}
            
public Rectangle getBounds(Component comp) {
                
return new Rectangle(comp.x, comp.y, comp.width, comp.height);
            
}
            
public void setMixingCutoutShape(Component comp, Shape shape) {
                
Region region = shape == null ?
  
null :
                    
Region.getInstance(shape, null);

                
synchronized (comp.getTreeLock()) {
                    
boolean needShowing = false;
                    
boolean needHiding = false;

                    
if (!comp.isNonOpaqueForMixing()) {
                        
needHiding = true;
                    
}

                    
comp.mixingCutoutRegion = region;

                    
if (!comp.isNonOpaqueForMixing()) {
                        
needShowing = true;
                    
}

                    
if (comp.isMixingNeeded()) {
                        
if (needHiding) {
                            
comp.mixOnHiding(comp.isLightweight());
                        
}
                        
if (needShowing) {
                            
comp.mixOnShowing();
                        
}
                    
}
                
}
            
}

            
public void setGraphicsConfiguration(Component comp,
                    
GraphicsConfiguration gc)
            
{
                
comp.setGraphicsConfiguration(gc);
            
}
            
public boolean requestFocus(Component comp, CausedFocusEvent.Cause cause) {
                
return comp.requestFocus(cause);
            
}
            
public boolean canBeFocusOwner(Component comp) {
                
return comp.canBeFocusOwner();
            
}

            
public boolean isVisible(Component comp) {
                
return comp.isVisible_NoClientCode();
            
}
            
public void setRequestFocusController
                
(RequestFocusController requestController)
            
{
                 
Component.setRequestFocusController(requestController);
            
}
            
public AppContext getAppContext(Component comp) {
                 
return comp.appContext;
            
}
            
public void setAppContext(Component comp, AppContext appContext) {
                 
comp.appContext = appContext;
            
}
            
public Container getParent(Component comp) {
                
return comp.getParent_NoClientCode();
            
}
            
public void setParent(Component comp, Container parent) {
                
comp.parent = parent;
            
}
            
public void setSize(Component comp, int width, int height) {
                
comp.width = width;
                
comp.height = height;
            
}
            
public Point getLocation(Component comp) {
                
return comp.location_NoClientCode();
            
}
            
public void setLocation(Component comp, int x, int y) {
                
comp.x = x;
                
comp.y = y;
            
}
            
public boolean isEnabled(Component comp) {
                
return comp.isEnabledImpl();
            
}
            
public boolean isDisplayable(Component comp) {
                
return comp.peer != null;
            
}
            
public Cursor getCursor(Component comp) {
                
return comp.getCursor_NoClientCode();
            
}
            
public ComponentPeer getPeer(Component comp) {
                
return comp.peer;
            
}
            
public void setPeer(Component comp, ComponentPeer peer) {
                
comp.peer = peer;
            
}
            
public boolean isLightweight(Component comp) {
                
return (comp.peer instanceof LightweightPeer);
            
}
            
public boolean getIgnoreRepaint(Component comp) {
                
return comp.ignoreRepaint;
            
}
            
public int getWidth(Component comp) {
                
return comp.width;
            
}
            
public int getHeight(Component comp) {
                
return comp.height;
            
}
            
public int getX(Component comp) {
                
return comp.x;
            
}
            
public int getY(Component comp) {
                
return comp.y;
            
}
            
public Color getForeground(Component comp) {
                
return comp.foreground;
            
}
            
public Color getBackground(Component comp) {
                
return comp.background;
            
}
            
public void setBackground(Component comp, Color background) {
                
comp.background = background;
            
}
            
public Font getFont(Component comp) {
                
return comp.getFont_NoClientCode();
            
}
            
public void processEvent(Component comp, AWTEvent e) {
                
comp.processEvent(e);
            
}

            
public AccessControlContext getAccessControlContext(Component comp) {
                
return comp.getAccessControlContext();
            
}

            
public void revalidateSynchronously(Component comp) {
                
comp.revalidateSynchronously();
            
}
        
});
    
}

    
/**
     
* Constructs a new component. Class <code>Component</code> can be
     
* extended directly to create a lightweight component that does not
     
* utilize an opaque native window. A lightweight component must be
     
* hosted by a native container somewhere higher up in the component
     
* tree (for example, by a <code>Frame</code> object).
     
*/

    
protected Component() {
        
appContext = AppContext.getAppContext();
    
}

    
@SuppressWarnings({"rawtypes", "unchecked"})
    
void initializeFocusTraversalKeys() {
        
focusTraversalKeys = new Set[3];
    
}

    
/**
     
* Constructs a name for this component.
  
Called by <code>getName</code>
     
* when the name is <code>null</code>.
     
*/

    
String constructComponentName() {
        
return null; // For strict compliance with prior platform versions, a Component
                     
// that doesn't set its name should return null from
                     
// getName()
    
}

    
/**
     
* Gets the name of the component.
     
* @return this component's name
     
* @see
    
#setName
     
* @since JDK1.1
     
*/

    
public String getName() {
        
if (name == null && !nameExplicitlySet) {
            
synchronized(getObjectLock()) {
                
if (name == null && !nameExplicitlySet)
                    
name = constructComponentName();
            
}
        
}
        
return name;
    
}

    
/**
     
* Sets the name of the component to the specified string.
     
* @param name
  
the string that is to be this
     
*
           
component's name
     
* @see #getName
     
* @since JDK1.1
     
*/

    
public void setName(String name) {
        
String oldName;
        
synchronized(getObjectLock()) {
            
oldName = this.name;
            
this.name = name;
            
nameExplicitlySet = true;
        
}
        
firePropertyChange("name", oldName, name);
    
}

    
/**
     
* Gets the parent of this component.
     
* @return the parent container of this component
     
* @since JDK1.0
     
*/

    
public Container getParent() {
        
return getParent_NoClientCode();
    
}

    
// NOTE: This method may be called by privileged threads.
    
//
       
This functionality is implemented in a package-private method
    
//
       
to insure that it cannot be overridden by client subclasses.

    
//
       
DO NOT INVOKE CLIENT CODE ON THIS THREAD!
    
final Container getParent_NoClientCode() {
        
return parent;
    
}

    
// This method is overridden in the Window class to return null,
    
//
    
because the parent field of the Window object contains

    
//
    
the owner of the window, not its parent.
    
Container getContainer() {
        
return getParent_NoClientCode();
    
}

    
/**
     
* @deprecated As of JDK version 1.1,
     
* programs should not directly manipulate peers;
     
* replaced by <code>boolean isDisplayable()</code>.
     
*/

    
@Deprecated
    
public ComponentPeer getPeer() {
        
return peer;
    
}

    
/**
     
* Associate a <code>DropTarget</code> with this component.
     
* The <code>Component</code> will receive drops only if it
     
* is enabled.
     
*
     
* @see #isEnabled
     
* @param dt The DropTarget
     
*/


    
public synchronized void setDropTarget(DropTarget dt) {
        
if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
            
return;

        
DropTarget old;

        
if ((old = dropTarget) != null) {
            
if (peer != null) dropTarget.removeNotify(peer);

            
DropTarget t = dropTarget;

            
dropTarget = null;

            
try {
                
t.setComponent(null);
            
} catch (IllegalArgumentException iae) {
                
// ignore it.
            
}
        
}

        
// if we have a new one, and we have a peer, add it!

        
if ((dropTarget = dt) != null) {
            
try {
                
dropTarget.setComponent(this);
                
if (peer != null) dropTarget.addNotify(peer);
            
} catch (IllegalArgumentException iae) {
                
if (old != null) {
                    
try {