|
From: <ls...@us...> - 2008-03-16 20:00:43
|
Revision: 3845
http://jnode.svn.sourceforge.net/jnode/?rev=3845&view=rev
Author: lsantha
Date: 2008-03-16 13:00:41 -0700 (Sun, 16 Mar 2008)
Log Message:
-----------
OpenJDK AWT & Swing integration.
Modified Paths:
--------------
trunk/core/src/classpath/java/java/awt/Toolkit.java
Removed Paths:
-------------
trunk/core/src/classpath/java/java/awt/AWTEvent.java
trunk/core/src/classpath/java/java/awt/Component.java
trunk/core/src/classpath/java/java/awt/Container.java
trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java
trunk/core/src/classpath/java/java/awt/Dialog.java
trunk/core/src/classpath/java/java/awt/Frame.java
trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java
trunk/core/src/classpath/java/java/awt/Window.java
Deleted: trunk/core/src/classpath/java/java/awt/AWTEvent.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/AWTEvent.java 2008-03-16 13:55:01 UTC (rev 3844)
+++ trunk/core/src/classpath/java/java/awt/AWTEvent.java 2008-03-16 20:00:41 UTC (rev 3845)
@@ -1,570 +0,0 @@
-
-/* AWTEvent.java -- the root event in AWT
- Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath 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 for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.awt;
-
-import java.awt.event.*;
-import java.util.EventObject;
-import java.lang.reflect.Field;
-
-/**
- * AWTEvent is the root event class for all AWT events in the JDK 1.1 event
- * model. It supersedes the Event class from JDK 1.0. Subclasses outside of
- * the java.awt package should have IDs greater than RESERVED_ID_MAX.
- *
- * <p>Event masks defined here are used by components in
- * <code>enableEvents</code> to select event types not selected by registered
- * listeners. Event masks are appropriately set when registering on
- * components.
- *
- * @author Warren Levy (wa...@cy...)
- * @author Aaron M. Renn (ar...@ur...)
- * @since 1.1
- * @status updated to 1.4
- */
-public abstract class AWTEvent extends EventObject
-{
- /**
- * Compatible with JDK 1.1+.
- */
- private static final long serialVersionUID = -1825314779160409405L;
-
- transient boolean focusManagerIsDispatching = false;
- transient boolean isPosted;
- /**
- * The ID of the event.
- *
- * @see #getID()
- * @see #AWTEvent(Object, int)
- * @serial the identifier number of this event
- */
- protected int id;
-
- /**
- * Indicates if the event has been consumed. False mean it is passed to
- * the peer, true means it has already been processed. Semantic events
- * generated by low-level events always have the value true.
- *
- * @see #consume()
- * @see #isConsumed()
- * @serial whether the event has been consumed
- */
- protected boolean consumed;
-
- /**
- * Used for implementing a simple linked list in EventQueue.
- */
- transient AWTEvent queueNext;
-
- /**
- * Who knows? It's in the serial version.
- *
- * @serial No idea what this is for.
- */
- byte[] bdata;
-
- /**
- * Indicates if this event is dispatched by the KeyboardFocusManager.
- */
- boolean isFocusManagerEvent = false;
-
- /** Mask for selecting component events. */
- public static final long COMPONENT_EVENT_MASK = 0x00001;
-
- /** Mask for selecting container events. */
- public static final long CONTAINER_EVENT_MASK = 0x00002;
-
- /** Mask for selecting component focus events. */
- public static final long FOCUS_EVENT_MASK = 0x00004;
-
- /** Mask for selecting keyboard events. */
- public static final long KEY_EVENT_MASK = 0x00008;
-
- /** Mask for mouse button events. */
- public static final long MOUSE_EVENT_MASK = 0x00010;
-
- /** Mask for mouse motion events. */
- public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;
-
- /** Mask for window events. */
- public static final long WINDOW_EVENT_MASK = 0x00040;
-
- /** Mask for action events. */
- public static final long ACTION_EVENT_MASK = 0x00080;
-
- /** Mask for adjustment events. */
- public static final long ADJUSTMENT_EVENT_MASK = 0x00100;
-
- /** Mask for item events. */
- public static final long ITEM_EVENT_MASK = 0x00200;
-
- /** Mask for text events. */
- public static final long TEXT_EVENT_MASK = 0x00400;
-
- /**
- * Mask for input method events.
- * @since 1.3
- */
- public static final long INPUT_METHOD_EVENT_MASK = 0x00800;
-
- /**
- * Mask if input methods are enabled. Package visible only.
- */
- static final long INPUT_ENABLED_EVENT_MASK = 0x01000;
-
- /**
- * Mask for paint events.
- * @since 1.3
- */
- public static final long PAINT_EVENT_MASK = 0x02000;
-
- /**
- * Mask for invocation events.
- * @since 1.3
- */
- public static final long INVOCATION_EVENT_MASK = 0x04000;
-
- /**
- * Mask for hierarchy events.
- * @since 1.3
- */
- public static final long HIERARCHY_EVENT_MASK = 0x08000;
-
- /**
- * Mask for hierarchy bounds events.
- * @since 1.3
- */
- public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000;
-
- /**
- * Mask for mouse wheel events.
- * @since 1.4
- */
- public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
-
- /**
- * Mask for window state events.
- * @since 1.4
- */
- public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
-
- /**
- * Mask for window focus events.
- * @since 1.4
- */
- public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000;
-
- /**
- * This is the highest number for event ids that are reserved for use by
- * the AWT system itself. Subclasses outside of java.awt should use higher
- * ids.
- */
- public static final int RESERVED_ID_MAX = 1999;
-
-
- /**
- * Initializes a new AWTEvent from the old Java 1.0 event object.
- *
- * @param event the old-style event
- * @throws NullPointerException if event is null
- */
- public AWTEvent(Event event)
- {
- this(event.target, event.id);
- consumed = event.consumed;
- }
-
- /**
- * Create an event on the specified source object and id.
- *
- * @param source the object that caused the event
- * @param id the event id
- * @throws IllegalArgumentException if source is null
- */
- public AWTEvent(Object source, int id)
- {
- super(source);
- this.id = id;
- }
-
- /**
- * Retarget the event, such as converting a heavyweight component to a
- * lightweight child of the original. This is not for general use, but
- * is for event targeting systems like KeyboardFocusManager.
- *
- * @param source the new source
- */
- public void setSource(Object source)
- {
- this.source = source;
- }
-
- /**
- * Returns the event type id.
- *
- * @return the id number of this event
- */
- public int getID()
- {
- return id;
- }
-
- /**
- * Create a string that represents this event in the format
- * <code>classname[eventstring] on sourcecomponentname</code>.
- *
- * @return a string representing this event
- */
- public String toString ()
- {
- String src;
- if (source instanceof Component)
- src = ((Component) source).getName();
- else if (source instanceof MenuComponent)
- src = ((MenuComponent) source).getName();
- else if (source != null)
- src = source.toString();
- else
- src = "null";
- String string = getClass ().getName () + "[" + paramString () + "] on "
- + src;
- return string;
- }
-
- /**
- * Returns a string representation of the state of this event. It may be
- * empty, but must not be null; it is implementation defined.
- *
- * @return a string representation of this event
- */
- public String paramString()
- {
- return "";
- }
-
- /**
- * Consumes this event so that it will not be processed in the default
- * manner.
- */
- protected void consume()
- {
- consumed = true;
- }
-
- /**
- * Tests whether not not this event has been consumed. A consumed event
- * is not processed in the default manner.
- *
- * @return true if this event has been consumed
- */
- protected boolean isConsumed()
- {
- return consumed;
- }
-
- /**
- * Converts an event id to the appropriate event mask.
- *
- * @param id the event id
- *
- * @return the event mask for the specified id
- */
- static long eventIdToMask(int id)
- {
- long mask = 0;
- switch (id)
- {
- case ActionEvent.ACTION_PERFORMED:
- mask = ACTION_EVENT_MASK;
- break;
- case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
- mask = ADJUSTMENT_EVENT_MASK;
- break;
- case ComponentEvent.COMPONENT_MOVED:
- case ComponentEvent.COMPONENT_RESIZED:
- case ComponentEvent.COMPONENT_SHOWN:
- case ComponentEvent.COMPONENT_HIDDEN:
- mask = COMPONENT_EVENT_MASK;
- break;
- case ContainerEvent.COMPONENT_ADDED:
- case ContainerEvent.COMPONENT_REMOVED:
- mask = CONTAINER_EVENT_MASK;
- break;
- case FocusEvent.FOCUS_GAINED:
- case FocusEvent.FOCUS_LOST:
- mask = FOCUS_EVENT_MASK;
- break;
- case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
- case InputMethodEvent.CARET_POSITION_CHANGED:
- mask = INPUT_METHOD_EVENT_MASK;
- break;
- case InvocationEvent.INVOCATION_DEFAULT:
- mask = INVOCATION_EVENT_MASK;
- break;
- case ItemEvent.ITEM_STATE_CHANGED:
- mask = ITEM_EVENT_MASK;
- break;
- case KeyEvent.KEY_TYPED:
- case KeyEvent.KEY_PRESSED:
- case KeyEvent.KEY_RELEASED:
- mask = KEY_EVENT_MASK;
- break;
- case MouseEvent.MOUSE_CLICKED:
- case MouseEvent.MOUSE_PRESSED:
- case MouseEvent.MOUSE_RELEASED:
- mask = MOUSE_EVENT_MASK;
- break;
- case MouseEvent.MOUSE_MOVED:
- case MouseEvent.MOUSE_ENTERED:
- case MouseEvent.MOUSE_EXITED:
- case MouseEvent.MOUSE_DRAGGED:
- mask = MOUSE_MOTION_EVENT_MASK;
- break;
- case MouseEvent.MOUSE_WHEEL:
- mask = MOUSE_WHEEL_EVENT_MASK;
- break;
- case PaintEvent.PAINT:
- case PaintEvent.UPDATE:
- mask = PAINT_EVENT_MASK;
- break;
- case TextEvent.TEXT_VALUE_CHANGED:
- mask = TEXT_EVENT_MASK;
- break;
- case WindowEvent.WINDOW_OPENED:
- case WindowEvent.WINDOW_CLOSING:
- case WindowEvent.WINDOW_CLOSED:
- case WindowEvent.WINDOW_ICONIFIED:
- case WindowEvent.WINDOW_DEICONIFIED:
- case WindowEvent.WINDOW_ACTIVATED:
- case WindowEvent.WINDOW_DEACTIVATED:
- mask = WINDOW_EVENT_MASK;
- break;
- case WindowEvent.WINDOW_GAINED_FOCUS:
- case WindowEvent.WINDOW_LOST_FOCUS:
- mask = WINDOW_FOCUS_EVENT_MASK;
- break;
- case WindowEvent.WINDOW_STATE_CHANGED:
- mask = WINDOW_STATE_EVENT_MASK;
- break;
- default:
- mask = 0;
- }
- return mask;
- }
-
- //jnode openjdk
-/**
- * Converts a new event to an old one (used for compatibility).
- * If the new event cannot be converted (because no old equivalent
- * exists) then this returns null.
- *
- * Note: this method is here instead of in each individual new
- * event class in java.awt.event because we don't want to make
- * it public and it needs to be called from java.awt.
- */
- Event convertToOld() {
- Object src = getSource();
- int newid = id;
-
- switch(id) {
- case KeyEvent.KEY_PRESSED:
- case KeyEvent.KEY_RELEASED:
- KeyEvent ke = (KeyEvent)this;
- if (ke.isActionKey()) {
- newid = (id == KeyEvent.KEY_PRESSED?
- Event.KEY_ACTION : Event.KEY_ACTION_RELEASE);
- }
- int keyCode = ke.getKeyCode();
- if (keyCode == KeyEvent.VK_SHIFT ||
- keyCode == KeyEvent.VK_CONTROL ||
- keyCode == KeyEvent.VK_ALT) {
- return null; // suppress modifier keys in old event model.
- }
- // no mask for button1 existed in old Event - strip it out
- return new Event(src, ke.getWhen(), newid, 0, 0,
- Event.getOldEventKey(ke),
- (ke.getModifiers() & ~InputEvent.BUTTON1_MASK));
-
- case MouseEvent.MOUSE_PRESSED:
- case MouseEvent.MOUSE_RELEASED:
- case MouseEvent.MOUSE_MOVED:
- case MouseEvent.MOUSE_DRAGGED:
- case MouseEvent.MOUSE_ENTERED:
- case MouseEvent.MOUSE_EXITED:
- MouseEvent me = (MouseEvent)this;
- // no mask for button1 existed in old Event - strip it out
- Event olde = new Event(src, me.getWhen(), newid,
- me.getX(), me.getY(), 0,
- (me.getModifiers() & ~InputEvent.BUTTON1_MASK));
- olde.clickCount = me.getClickCount();
- return olde;
-
- case FocusEvent.FOCUS_GAINED:
- return new Event(src, Event.GOT_FOCUS, null);
-
- case FocusEvent.FOCUS_LOST:
- return new Event(src, Event.LOST_FOCUS, null);
-
- case WindowEvent.WINDOW_CLOSING:
- case WindowEvent.WINDOW_ICONIFIED:
- case WindowEvent.WINDOW_DEICONIFIED:
- return new Event(src, newid, null);
-
- case ComponentEvent.COMPONENT_MOVED:
- if (src instanceof Frame || src instanceof Dialog) {
- Point p = ((Component)src).getLocation();
- return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0);
- }
- break;
-
- case ActionEvent.ACTION_PERFORMED:
- ActionEvent ae = (ActionEvent)this;
- String cmd;
- if (src instanceof Button) {
- cmd = ((Button)src).getLabel();
- } else if (src instanceof MenuItem) {
- cmd = ((MenuItem)src).getLabel();
- } else {
- cmd = ae.getActionCommand();
- }
- return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd);
-
- case ItemEvent.ITEM_STATE_CHANGED:
- ItemEvent ie = (ItemEvent)this;
- Object arg;
- if (src instanceof List) {
- newid = (ie.getStateChange() == ItemEvent.SELECTED?
- Event.LIST_SELECT : Event.LIST_DESELECT);
- arg = ie.getItem();
- } else {
- newid = Event.ACTION_EVENT;
- if (src instanceof Choice) {
- arg = ie.getItem();
-
- } else { // Checkbox
- arg = Boolean.valueOf(ie.getStateChange() == ItemEvent.SELECTED);
- }
- }
- return new Event(src, newid, arg);
-
- case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
- AdjustmentEvent aje = (AdjustmentEvent)this;
- switch(aje.getAdjustmentType()) {
- case AdjustmentEvent.UNIT_INCREMENT:
- newid = Event.SCROLL_LINE_DOWN;
- break;
- case AdjustmentEvent.UNIT_DECREMENT:
- newid = Event.SCROLL_LINE_UP;
- break;
- case AdjustmentEvent.BLOCK_INCREMENT:
- newid = Event.SCROLL_PAGE_DOWN;
- break;
- case AdjustmentEvent.BLOCK_DECREMENT:
- newid = Event.SCROLL_PAGE_UP;
- break;
- case AdjustmentEvent.TRACK:
- if (aje.getValueIsAdjusting()) {
- newid = Event.SCROLL_ABSOLUTE;
- }
- else {
- newid = Event.SCROLL_END;
- }
- break;
- default:
- return null;
- }
- return new Event(src, newid, Integer.valueOf(aje.getValue()));
-
- default:
- }
- return null;
- }
- /**
- * The pseudo event mask for enabling input methods.
- * We're using one bit in the eventMask so we don't need
- * a separate field inputMethodsEnabled.
- */
- final static long INPUT_METHODS_ENABLED_MASK = 0x1000;
-
- /**
- * Copies all private data from this event into that.
- * Space is allocated for the copied data that will be
- * freed when the that is finalized. Upon completion,
- * this event is not changed.
- */
- void copyPrivateDataInto(AWTEvent that) {
- that.bdata = this.bdata;
- // Copy canAccessSystemClipboard value from this into that.
- if (this instanceof InputEvent && that instanceof InputEvent) {
- Field field = get_InputEvent_CanAccessSystemClipboard();
- if (field != null) {
- try {
- boolean b = field.getBoolean(this);
- field.setBoolean(that, b);
- } catch(IllegalAccessException e) {
- }
- }
- }
- }
-
- private static synchronized Field get_InputEvent_CanAccessSystemClipboard() {
- if (inputEvent_CanAccessSystemClipboard_Field == null) {
- inputEvent_CanAccessSystemClipboard_Field =
- (Field)java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- Field field = null;
- try {
- field = InputEvent.class.
- getDeclaredField("canAccessSystemClipboard");
- field.setAccessible(true);
- return field;
- } catch (SecurityException e) {
- } catch (NoSuchFieldException e) {
- }
- return null;
- }
- });
- }
-
- return inputEvent_CanAccessSystemClipboard_Field;
- }
- // security stuff
- private static Field inputEvent_CanAccessSystemClipboard_Field = null;
-} // class AWTEvent
Deleted: trunk/core/src/classpath/java/java/awt/Component.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/Component.java 2008-03-16 13:55:01 UTC (rev 3844)
+++ trunk/core/src/classpath/java/java/awt/Component.java 2008-03-16 20:00:41 UTC (rev 3845)
@@ -1,7928 +0,0 @@
-/* Component.java -- a graphics component
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006
- Free Software Foundation
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath 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 for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.awt;
-
-//import gnu.java.awt.dnd.peer.gtk.GtkDropTargetContextPeer;
-
-import java.awt.dnd.DropTarget;
-import java.awt.event.*;
-import java.awt.im.InputContext;
-import java.awt.im.InputMethodRequests;
-import java.awt.image.BufferStrategy;
-import java.awt.image.ColorModel;
-import java.awt.image.ImageObserver;
-import java.awt.image.ImageProducer;
-import java.awt.image.VolatileImage;
-import java.awt.peer.ComponentPeer;
-import java.awt.peer.LightweightPeer;
-import java.awt.peer.ContainerPeer;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.util.Collections;
-import java.util.EventListener;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Set;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.accessibility.Accessible;
-import javax.accessibility.AccessibleComponent;
-import javax.accessibility.AccessibleContext;
-import javax.accessibility.AccessibleRole;
-import javax.accessibility.AccessibleState;
-import javax.accessibility.AccessibleStateSet;
-import sun.awt.*;
-import sun.awt.im.CompositionArea;
-import sun.awt.dnd.SunDropTargetEvent;
-import sun.java2d.SunGraphics2D;
-
-/**
- * The root of all evil. All graphical representations are subclasses of this
- * giant class, which is designed for screen display and user interaction.
- * This class can be extended directly to build a lightweight component (one
- * not associated with a native window); lightweight components must reside
- * inside a heavyweight window.
- *
- * <p>This class is Serializable, which has some big implications. A user can
- * save the state of all graphical components in one VM, and reload them in
- * another. Note that this class will only save Serializable listeners, and
- * ignore the rest, without causing any serialization exceptions. However, by
- * making a listener serializable, and adding it to another element, you link
- * in that entire element to the state of this component. To get around this,
- * use the idiom shown in the example below - make listeners non-serializable
- * in inner classes, rather than using this object itself as the listener, if
- * external objects do not need to save the state of this object.
- *
- * <pre>
- * import java.awt.*;
- * import java.awt.event.*;
- * import java.io.Serializable;
- * class MyApp implements Serializable
- * {
- * BigObjectThatShouldNotBeSerializedWithAButton bigOne;
- * // Serializing aButton will not suck in an instance of MyApp, with its
- * // accompanying field bigOne.
- * Button aButton = new Button();
- * class MyActionListener implements ActionListener
- * {
- * public void actionPerformed(ActionEvent e)
- * {
- * System.out.println("Hello There");
- * }
- * }
- * MyApp()
- * {
- * aButton.addActionListener(new MyActionListener());
- * }
- * }
- * </pre>
- *
- * <p>Status: Incomplete. The event dispatch mechanism is implemented. All
- * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly
- * incomplete or only stubs; except for methods relating to the Drag and
- * Drop, Input Method, and Accessibility frameworks: These methods are
- * present but commented out.
- *
- * @author original author unknown
- * @author Eric Blake (eb...@em...)
- * @since 1.0
- * @status still missing 1.4 support
- */
-public abstract class Component
- implements ImageObserver, MenuContainer, Serializable
-{
- // Word to the wise - this file is huge. Search for '\f' (^L) for logical
- // sectioning by fields, public API, private API, and nested classes.
-
-
- /**
- * Compatible with JDK 1.0+.
- */
- private static final long serialVersionUID = -7644114512714619750L;
-
- /**
- * Constant returned by the <code>getAlignmentY</code> method to indicate
- * that the component wishes to be aligned to the top relative to
- * other components.
- *
- * @see #getAlignmentY()
- */
- public static final float TOP_ALIGNMENT = 0;
-
- /**
- * Constant returned by the <code>getAlignmentY</code> and
- * <code>getAlignmentX</code> methods to indicate
- * that the component wishes to be aligned to the center relative to
- * other components.
- *
- * @see #getAlignmentX()
- * @see #getAlignmentY()
- */
- public static final float CENTER_ALIGNMENT = 0.5f;
-
- /**
- * Constant returned by the <code>getAlignmentY</code> method to indicate
- * that the component wishes to be aligned to the bottom relative to
- * other components.
- *
- * @see #getAlignmentY()
- */
- public static final float BOTTOM_ALIGNMENT = 1;
-
- /**
- * Constant returned by the <code>getAlignmentX</code> method to indicate
- * that the component wishes to be aligned to the right relative to
- * other components.
- *
- * @see #getAlignmentX()
- */
- public static final float RIGHT_ALIGNMENT = 1;
-
- /**
- * Constant returned by the <code>getAlignmentX</code> method to indicate
- * that the component wishes to be aligned to the left relative to
- * other components.
- *
- * @see #getAlignmentX()
- */
- public static final float LEFT_ALIGNMENT = 0;
-
- /**
- * Make the treelock a String so that it can easily be identified
- * in debug dumps. We clone the String in order to avoid a conflict in
- * the unlikely event that some other package uses exactly the same string
- * as a lock object.
- */
- static final Object LOCK = new String("AWT_TREE_LOCK");
-
- /**
- * The default maximum size.
- */
- private static final Dimension DEFAULT_MAX_SIZE
- = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
-
- // Serialized fields from the serialization spec.
-
- /**
- * The x position of the component in the parent's coordinate system.
- *
- * @see #getLocation()
- * @serial the x position
- */
- int x;
-
- /**
- * The y position of the component in the parent's coordinate system.
- *
- * @see #getLocation()
- * @serial the y position
- */
- int y;
-
- /**
- * The component width.
- *
- * @see #getSize()
- * @serial the width
- */
- int width;
-
- /**
- * The component height.
- *
- * @see #getSize()
- * @serial the height
- */
- int height;
-
- /**
- * The foreground color for the component. This may be null.
- *
- * @see #getForeground()
- * @see #setForeground(Color)
- * @serial the foreground color
- */
- Color foreground;
-
- /**
- * The background color for the component. This may be null.
- *
- * @see #getBackground()
- * @see #setBackground(Color)
- * @serial the background color
- */
- Color background;
-
- /**
- * The default font used in the component. This may be null.
- *
- * @see #getFont()
- * @see #setFont(Font)
- * @serial the font
- */
- Font font;
-
- /**
- * The font in use by the peer, or null if there is no peer.
- *
- * @serial the peer's font
- */
- Font peerFont;
-
- /**
- * The cursor displayed when the pointer is over this component. This may
- * be null.
- *
- * @see #getCursor()
- * @see #setCursor(Cursor)
- */
- Cursor cursor;
-
- /**
- * The locale for the component.
- *
- * @see #getLocale()
- * @see #setLocale(Locale)
- */
- Locale locale = Locale.getDefault ();
-
- /**
- * True if the object should ignore repaint events (usually because it is
- * not showing).
- *
- * @see #getIgnoreRepaint()
- * @see #setIgnoreRepaint(boolean)
- * @serial true to ignore repaints
- * @since 1.4
- */
- boolean ignoreRepaint;
-
- /**
- * True when the object is visible (although it is only showing if all
- * ancestors are likewise visible). For component, this defaults to true.
- *
- * @see #isVisible()
- * @see #setVisible(boolean)
- * @serial true if visible
- */
- boolean visible = true;
-
- /**
- * True if the object is enabled, meaning it can interact with the user.
- * For component, this defaults to true.
- *
- * @see #isEnabled()
- * @see #setEnabled(boolean)
- * @serial true if enabled
- */
- boolean enabled = true;
-
- /**
- * True if the object is valid. This is set to false any time a size
- * adjustment means the component need to be layed out again.
- *
- * @see #isValid()
- * @see #validate()
- * @see #invalidate()
- * @serial true if layout is valid
- */
- boolean valid;
-
- /**
- * The DropTarget for drag-and-drop operations.
- *
- * @see #getDropTarget()
- * @see #setDropTarget(DropTarget)
- * @serial the drop target, or null
- * @since 1.2
- */
- DropTarget dropTarget;
-
- /**
- * The list of popup menus for this component.
- *
- * @see #add(PopupMenu)
- * @serial the list of popups
- */
- Vector popups;
-
- /**
- * The component's name. May be null, in which case a default name is
- * generated on the first use.
- *
- * @see #getName()
- * @see #setName(String)
- * @serial the name
- */
- String name;
-
- /**
- * True once the user has set the name. Note that the user may set the name
- * to null.
- *
- * @see #name
- * @see #getName()
- * @see #setName(String)
- * @serial true if the name has been explicitly set
- */
- boolean nameExplicitlySet;
-
- /**
- * Indicates if the object can be focused. Defaults to true for components.
- *
- * @see #isFocusable()
- * @see #setFocusable(boolean)
- * @since 1.4
- */
- boolean focusable = true;
-
- /**
- * Tracks whether this component's {@link #isFocusTraversable}
- * method has been overridden.
- *
- * @since 1.4
- */
- int isFocusTraversableOverridden;
-
- /**
- * The focus traversal keys, if not inherited from the parent or
- * default keyboard focus manager. These sets will contain only
- * AWTKeyStrokes that represent press and release events to use as
- * focus control.
- *
- * @see #getFocusTraversalKeys(int)
- * @see #setFocusTraversalKeys(int, Set)
- * @since 1.4
- */
- Set[] focusTraversalKeys;
-
- /**
- * True if focus traversal keys are enabled. This defaults to true for
- * Component. If this is true, keystrokes in focusTraversalKeys are trapped
- * and processed automatically rather than being passed on to the component.
- *
- * @see #getFocusTraversalKeysEnabled()
- * @see #setFocusTraversalKeysEnabled(boolean)
- * @since 1.4
- */
- boolean focusTraversalKeysEnabled = true;
-
- /**
- * Cached information on the minimum size. Should have been transient.
- *
- * @serial ignore
- */
- Dimension minSize;
-
- /**
- * Flag indicating whether the minimum size for the component has been set
- * by a call to {@link #setMinimumSize(Dimension)} with a non-null value.
- */
- boolean minSizeSet;
-
- /**
- * The maximum size for the component.
- * @see #setMaximumSize(Dimension)
- */
- Dimension maxSize;
-
- /**
- * A flag indicating whether the maximum size for the component has been set
- * by a call to {@link #setMaximumSize(Dimension)} with a non-null value.
- */
- boolean maxSizeSet;
-
- /**
- * Cached information on the preferred size. Should have been transient.
- *
- * @serial ignore
- */
- Dimension prefSize;
-
- /**
- * Flag indicating whether the preferred size for the component has been set
- * by a call to {@link #setPreferredSize(Dimension)} with a non-null value.
- */
- boolean prefSizeSet;
-
- /**
- * Set to true if an event is to be handled by this component, false if
- * it is to be passed up the hierarcy.
- *
- * @see #dispatchEvent(AWTEvent)
- * @serial true to process event locally
- */
- boolean newEventsOnly;
-
- /**
- * Set by subclasses to enable event handling of particular events, and
- * left alone when modifying listeners. For component, this defaults to
- * enabling only input methods.
- *
- * @see #enableInputMethods(boolean)
- * @see AWTEvent
- * @serial the mask of events to process
- */
- long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK;
-
- /**
- * Describes all registered PropertyChangeListeners.
- *
- * @see #addPropertyChangeListener(PropertyChangeListener)
- * @see #removePropertyChangeListener(PropertyChangeListener)
- * @see #firePropertyChange(String, Object, Object)
- * @serial the property change listeners
- * @since 1.2
- */
- PropertyChangeSupport changeSupport;
-
- /**
- * True if the component has been packed (layed out).
- *
- * @serial true if this is packed
- */
- boolean isPacked;
-
- /**
- * The serialization version for this class. Currently at version 4.
- *
- * XXX How do we handle prior versions?
- *
- * @serial the serialization version
- */
- int componentSerializedDataVersion = 4;
-
- /**
- * The accessible context associated with this component. This is only set
- * by subclasses.
- *
- * @see #getAccessibleContext()
- * @serial the accessibility context
- * @since 1.2
- */
- AccessibleContext accessibleContext;
-
-
- // Guess what - listeners are special cased in serialization. See
- // readObject and writeObject.
-
- /** Component listener chain. */
- transient ComponentListener componentListener;
-
- /** Focus listener chain. */
- transient FocusListener focusListener;
-
- /** Key listener chain. */
- transient KeyListener keyListener;
-
- /** Mouse listener chain. */
- transient MouseListener mouseListener;
-
- /** Mouse motion listener chain. */
- transient MouseMotionListener mouseMotionListener;
-
- /**
- * Mouse wheel listener chain.
- *
- * @since 1.4
- */
- transient MouseWheelListener mouseWheelListener;
-
- /**
- * Input method listener chain.
- *
- * @since 1.2
- */
- transient InputMethodListener inputMethodListener;
-
- /**
- * Hierarcy listener chain.
- *
- * @since 1.3
- */
- transient HierarchyListener hierarchyListener;
-
- /**
- * Hierarcy bounds listener chain.
- *
- * @since 1.3
- */
- transient HierarchyBoundsListener hierarchyBoundsListener;
-
- // Anything else is non-serializable, and should be declared "transient".
-
- /** The parent. */
- transient Container parent;
-
- /** The associated native peer. */
- transient ComponentPeer peer;
-
- /** The preferred component orientation. */
- transient ComponentOrientation componentOrientation = ComponentOrientation.UNKNOWN;
-
- /**
- * The associated graphics configuration.
- *
- * @since 1.4
- */
- transient GraphicsConfiguration graphicsConfig;
-
- /**
- * The buffer strategy for repainting.
- *
- * @since 1.4
- */
- transient BufferStrategy bufferStrategy;
-
- /**
- * The number of hierarchy listeners of this container plus all of its
- * children. This is needed for efficient handling of HierarchyEvents.
- * These must be propagated to all child components with HierarchyListeners
- * attached. To avoid traversal of the whole subtree, we keep track of
- * the number of HierarchyListeners here and only walk the paths that
- * actually have listeners.
- */
- int numHierarchyListeners;
- int numHierarchyBoundsListeners;
-
- /**
- * true if requestFocus was called on this component when its
- * top-level ancestor was not focusable.
- */
- private transient FocusEvent pendingFocusRequest = null;
-
- /**
- * The system properties that affect image updating.
- */
- private static transient boolean incrementalDraw;
- private static transient Long redrawRate;
-
- static
- {
- incrementalDraw = Boolean.getBoolean ("awt.image.incrementalDraw");
- redrawRate = Long.getLong ("awt.image.redrawrate");
- }
-
- // Public and protected API.
-
- /**
- * Default constructor for subclasses. When Component is extended directly,
- * it forms a lightweight component that must be hosted in an opaque native
- * container higher in the tree.
- */
- protected Component()
- {
- // Nothing to do here.
- }
-
- /**
- * Returns the name of this component.
- *
- * @return the name of this component
- * @see #setName(String)
- * @since 1.1
- */
- public String getName()
- {
- if (name == null && ! nameExplicitlySet)
- name = generateName();
- return name;
- }
-
- /**
- * Sets the name of this component to the specified name (this is a bound
- * property with the name 'name').
- *
- * @param name the new name (<code>null</code> permitted).
- * @see #getName()
- * @since 1.1
- */
- public void setName(String name)
- {
- nameExplicitlySet = true;
- String old = this.name;
- this.name = name;
- firePropertyChange("name", old, name);
- }
-
- /**
- * Returns the parent of this component.
- *
- * @return the parent of this component
- */
- public Container getParent()
- {
- return parent;
- }
-
- /**
- * Returns the native windowing system peer for this component. Only the
- * platform specific implementation code should call this method.
- *
- * @return the peer for this component
- * @deprecated user programs should not directly manipulate peers; use
- * {@link #isDisplayable()} instead
- */
- // Classpath's Gtk peers rely on this.
- public ComponentPeer getPeer()
- {
- return peer;
- }
-
- /**
- * Set the associated drag-and-drop target, which receives events when this
- * is enabled.
- *
- * @param dt the new drop target
- * @see #isEnabled()
- */
- public void setDropTarget(DropTarget dt)
- {
- this.dropTarget = dt;
-
- if (peer != null)
- dropTarget.addNotify(peer);
- }
-
- /**
- * Gets the associated drag-and-drop target, if there is one.
- *
- * @return the drop target
- */
- public DropTarget getDropTarget()
- {
- return dropTarget;
- }
-
- /**
- * Returns the graphics configuration of this component, if there is one.
- * If it has not been set, it is inherited from the parent.
- *
- * @return the graphics configuration, or null
- * @since 1.3
- */
- public GraphicsConfiguration getGraphicsConfiguration()
- {
- return getGraphicsConfigurationImpl();
- }
-
- /**
- * Returns the object used for synchronization locks on this component
- * when performing tree and layout functions.
- *
- * @return the synchronization lock for this component
- */
- public final Object getTreeLock()
- {
- return LOCK;
- }
-
- /**
- * Returns the toolkit in use for this component. The toolkit is associated
- * with the frame this component belongs to.
- *
- * @return the toolkit for this component
- */
- public Toolkit getToolkit()
- {
- // Only heavyweight peers can handle this.
- ComponentPeer p = peer;
- Component comp = this;
- while (p instanceof LightweightPeer)
- {
- comp = comp.parent;
- p = comp == null ? null : comp.peer;
- }
-
- Toolkit tk = null;
- if (p != null)
- {
- tk = peer.getToolkit();
- }
- if (tk == null)
- tk = Toolkit.getDefaultToolkit();
- return tk;
- }
-
- /**
- * Tests whether or not this component is valid. A invalid component needs
- * to have its layout redone.
- *
- * @return true if this component is valid
- * @see #validate()
- * @see #invalidate()
- */
- public boolean isValid()
- {
- // Tests show that components are invalid as long as they are not showing, even after validate()
- // has been called on them.
- return peer != null && valid;
- }
-
- /**
- * Tests if the component is displayable. It must be connected to a native
- * screen resource. This reduces to checking that peer is not null. A
- * containment hierarchy is made displayable when a window is packed or
- * made visible.
- *
- * @return true if the component is displayable
- * @see Container#add(Component)
- * @see Container#remove(Component)
- * @see Window#pack()
- * @see Window#show()
- * @see Window#dispose()
- * @since 1.2
- */
- public boolean isDisplayable()
- {
- return peer != null;
- }
-
- /**
- * Tests whether or not this component is visible. Except for top-level
- * frames, components are initially visible.
- *
- * @return true if the component is visible
- * @see #setVisible(boolean)
- */
- public boolean isVisible()
- {
- return visible;
- }
-
- /**
- * Tests whether or not this component is actually being shown on
- * the screen. This will be true if and only if it this component is
- * visible and its parent components are all visible.
- *
- * @return true if the component is showing on the screen
- * @see #setVisible(boolean)
- */
- public boolean isShowing()
- {
- Component par = parent;
- return visible && peer != null && (par == null || par.isShowing());
- }
-
- /**
- * Tests whether or not this component is enabled. Components are enabled
- * by default, and must be enabled to receive user input or generate events.
- *
- * @return true if the component is enabled
- * @see #setEnabled(boolean)
- */
- public boolean isEnabled()
- {
- return enabled;
- }
-
- /**
- * Enables or disables this component. The component must be enabled to
- * receive events (except that lightweight components always receive mouse
- * events).
- *
- * @param enabled true to enable this component
- *
- * @see #isEnabled()
- * @see #isLightweight()
- *
- * @since 1.1
- */
- public void setEnabled(boolean enabled)
- {
- enable(enabled);
- }
-
- /**
- * Enables this component.
- *
- * @deprecated use {@link #setEnabled(boolean)} instead
- */
- public void enable()
- {
- if (! enabled)
- {
- // Need to lock the tree here, because the peers are involved.
- synchronized (getTreeLock())
- {
- enabled = true;
- ComponentPeer p = peer;
- if (p != null)
- p.enable();
- }
- }
- }
-
- /**
- * Enables or disables this component.
- *
- * @param enabled true to enable this component
- *
- * @deprecated use {@link #setEnabled(boolean)} instead
- */
- public void enable(boolean enabled)
- {
- if (enabled)
- enable();
- else
- disable();
- }
-
- /**
- * Disables this component.
- *
- * @deprecated use {@link #setEnabled(boolean)} instead
- */
- public void disable()
- {
- if (enabled)
- {
- // Need to lock the tree here, because the peers are involved.
- synchronized (getTreeLock())
- {
- enabled = false;
- ComponentPeer p = peer;
- if (p != null)
- p.disable();
- }
- }
- }
-
- /**
- * Checks if this image is painted to an offscreen image buffer that is
- * later copied to screen (double buffering reduces flicker). This version
- * returns false, so subclasses must override it if they provide double
- * buffering.
- *
- * @return true if this is double buffered; defaults to false
- */
- public boolean isDoubleBuffered()
- {
- return false;
- }
-
- /**
- * Enables or disables input method support for this component. By default,
- * components have this enabled. Input methods are given the opportunity
- * to process key events before this component and its listeners.
- *
- * @param enable true to enable input method processing
- * @see #processKeyEvent(KeyEvent)
- * @since 1.2
- */
- public void enableInputMethods(boolean enable)
- {
- if (enable)
- eventMask |= AWTEvent.INPUT_ENABLED_EVENT_MASK;
- else
- eventMask &= ~AWTEvent.INPUT_ENABLED_EVENT_MASK;
- }
-
- /**
- * Makes this component visible or invisible. Note that it wtill might
- * not show the component, if a parent is invisible.
- *
- * @param visible true to make this component visible
- *
- * @see #isVisible()
- *
- * @since 1.1
- */
- public void setVisible(boolean visible)
- {
- // Inspection by subclassing shows that Sun's implementation calls
- // show(boolean) which then calls show() or hide(). It is the show()
- // method that is overriden in subclasses like Window.
- show(visible);
- }
-
- /**
- * Makes this component visible on the screen.
- *
- * @deprecated use {@link #setVisible(boolean)} instead
- */
- public void show()
- {
- // We must set visible before showing the peer. Otherwise the
- // peer could post paint events before visible is true, in which
- // case lightweight components are not initially painted --
- // Container.paint first calls isShowing () before painting itself
- // and its children.
- if(! visible)
- {
- // Need to lock the tree here to avoid races and inconsistencies.
- synchronized (getTreeLock())
- {
- visible = true;
- // Avoid NullPointerExceptions by creating a local reference.
- ComponentPeer currentPeer=peer;
- if (currentPeer != null)
- {
- currentPeer.show();
-
- // Fire HierarchyEvent.
- fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED,
- this, parent,
- HierarchyEvent.SHOWING_CHANGED);
-
- // The JDK repaints the component before invalidating the parent.
- // So do we.
- if (peer instanceof LightweightPeer)
- repaint();
- }
-
- // Only post an event if this component actually has a listener
- // or has this event explicitly enabled.
- if (componentListener != null
- || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
- {
- ComponentEvent ce =
- new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
- }
-
- // Invalidate the parent if we have one. The component itself must
- // not be invalidated. We also avoid NullPointerException with
- // a local reference here.
- Container currentParent = parent;
- if (currentParent != null)
- currentParent.invalidate();
-
- }
- }
-
- /**
- * Makes this component visible or invisible.
- *
- * @param visible true to make this component visible
- *
- * @deprecated use {@link #setVisible(boolean)} instead
- */
- public void show(boolean visible)
- {
- if (visible)
- show();
- else
- hide();
- }
-
- /**
- * Hides this component so that it is no longer shown on the screen.
- *
- * @deprecated use {@link #setVisible(boolean)} instead
- */
- public void hide()
- {
- if (visible)
- {
- // Need to lock the tree here to avoid races and inconsistencies.
- synchronized (getTreeLock())
- {
- visible = false;
-
- // Avoid NullPointerExceptions by creating a local reference.
- ComponentPeer currentPeer=peer;
- if (currentPeer != null)
- {
- currentPeer.hide();
-
- // Fire hierarchy event.
- fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED,
- this, parent,
- HierarchyEvent.SHOWING_CHANGED);
- // The JDK repaints the component before invalidating the
- // parent. So do we. This only applies for lightweights.
- if (peer instanceof LightweightPeer)
- repaint();
- }
-
- // Only post an event if this component actually has a listener
- // or has this event explicitly enabled.
- if (componentListener != null
- || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
- {
- ComponentEvent ce =
- new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
- }
-
- // Invalidate the parent if we have one. The component itself need
- // not be invalidated. We also avoid NullPointerException with
- // a local reference here.
- Container currentParent = parent;
- if (currentParent != null)
- currentParent.invalidate();
-
- }
- }
-
- /**
- * Returns this component's foreground color. If not set, this is inherited
- * from the parent.
- *
- * @return this component's foreground color, or null
- * @see #setForeground(Color)
- */
- public Color getForeground()
- {
- if (foreground != null)
- return foreground;
- return parent == null ? null : parent.getForeground();
- }
-
- /**
- * Sets this component's foreground color to the specified color. This is a
- * bound property.
- *
- * @param c the new foreground color
- * @see #getForeground()
- */
- public void setForeground(Color c)
- {
- if (peer != null)
- peer.setForeground(c);
-
- Color previous = foreground;
- foreground = c;
- firePropertyChange("foreground", previous, c);
- }
-
- /**
- * Tests if the foreground was explicitly set, or just inherited from the
- * parent.
- *
- * @return true if the foreground has been set
- * @since 1.4
- */
- public boolean isForegroundSet()
- {
- return foreground != null;
- }
-
- /**
- * Returns this component's background color. If not set, this is inherited
- * from the parent.
- *
- * @return the background color of the component, or null
- * @see #setBackground(Color)
- */
- public Color getBackground()
- {
- if (background != null)
- return background;
- return parent == null ? null : parent.getBackground();
- }
-
- /**
- * Sets this component's background color to the specified color. The parts
- * of the component affected by the background color may by system dependent.
- * This is a bound property.
- *
- * @param c the new background color
- * @see #getBackground()
- */
- public void setBackground(Color c)
- {
- // return if the background is already set to that color.
- if ((c != null) && c.equals(background))
- return;
-
- Color previous = background;
- background = c;
- if (peer != null && c != null)
- peer.setBackground(c);
- firePropertyChange("background", previous, c);
- }
-
- /**
- * Tests if the background was explicitly set, or just inherited from the
- * parent.
- *
- * @return true if the background has been set
- * @since 1.4
- */
- public boolean isBackgroundSet()
- {
- return background != null;
- }
-
- /**
- * Returns the font in use for this component. If not set, this is inherited
- * from the parent.
- *
- * @return the font for this component
- * @see #setFont(Font)
- */
- public Font getFont()
- {
- return getFontImpl();
- }
-
- /**
- * Implementation of getFont(). This is pulled out of getFont() to prevent
- * client programs from overriding this.
- *
- * @return the font of this component
- */
- private final Font getFontImpl()
- {
- Font f = font;
- if (f == null)
- {
- Component p = parent;
- if (p != null)
- f = p.getFontImpl();
- else
- {
- // It is important to return null here and not some kind of default
- // font, otherwise the Swing UI would not install its fonts because
- // it keeps non-UIResource fonts.
- f = null;
- }
- }
- return f;
- }
-
- /**
- * Sets the font for this component to the specified font. This is a bound
- * property.
- *
- * @param f the new font for this component
- *
- * @see #getFont()
- */
- public void setFont(Font f)
- {
- Font oldFont;
- Font newFont;
- // Synchronize on the tree because getFontImpl() relies on the hierarchy
- // not beeing changed.
- synchronized (getTreeLock())
- {
- // Synchronize on this here to guarantee thread safety wrt to the
- // property values.
- synchronized (this)
- {
- oldFont = font;
- font = f;
- newFont = f;
- }
- // Create local variable here for thread safety.
- ComponentPeer p = peer;
- if (p != null)
- {
- // The peer receives the real font setting, which can depend on
- // the parent font when this component's font has been set to null.
- f = getFont();
- if (f != null)
- {
- p.setFont(f);
- peerFont = f;
- }
- }
- }
-
- // Fire property change event.
- firePropertyChange("font", oldFont, newFont);
-
- // Invalidate when necessary as font changes can change the size of the
- // component.
- if (valid)
- invalidate();
- }
-
- /**
- * Tests if the font was explicitly set, or just inherited from the parent.
- *
- * @return true if the font has been set
- * @since 1.4
- */
- public boolean isFontSet()
- {
- return font != null;
- }
-
- /**
- * Returns the locale for this component. If this component does not
- * have a locale, the locale of the parent component is returned.
- *
- * @return the locale for this component
- * @throws IllegalComponentStateException if it has no locale or parent
- * @see #setLocale(Locale)
- * @since 1.1
- */
- public Locale getLocale()
- {
- if (locale != null)
- return locale;
- if (parent == null)
- throw new IllegalComponentStateException
- ("Component has no parent: can't determine Locale");
- return parent.getLocale();
- }
-
- /**
- * Sets the locale for this component to the specified locale. This is a
- * bound property.
- *
- * @param newLocale the new locale for this component
- */
- public void setLocale(Locale newLocale)
- {
- if (locale == newLocale)
- return;
-
- Locale oldLocale = locale;
- locale = newLocale;
- firePropertyChange("locale", oldLocale, newLocale);
- // New writing/layout direction or more/less room for localized labels.
- invalidate();
- }
-
- /**
- * Returns the color model of the device this componet is displayed on.
- *
- * @return this object's color model
- * @see Toolkit#getColorModel()
- */
- public ColorModel getColorModel()
- {
- GraphicsConfiguration config = getGraphicsConfiguration();
- return config != null ? config.getColorModel()
- : getToolkit().getColorModel();
- }
-
- /**
- * Returns the location of this component's top left corner relative to
- * its parent component. This may be outdated, so for synchronous behavior,
- * you should use a component listner.
- *
- * @return the location of this component
- * @see #setLocation(int, int)
- * @see #getLocationOnScreen()
- * @since 1.1
- */
- public Point getLocation()
- {
- return location ();
- }
-
- /**
- * Returns the location of this component's top left corner in screen
- * coordinates.
- *
- * @return the location of this component in screen coordinates
- * @throws IllegalComponentStateException if the component is not showing
- */
- public Point getLocationOnScreen()
- {
- if (! isShowing())
- throw new IllegalComponentStateException("component "
- + getClass().getName()
- + " not showing");
- // We know peer != null here.
- return peer.getLocationOnScreen();
- }
-
- /**
- * Returns the location of this component's top left corner relative to
- * its parent component.
- *
- * @return the location of this component
- * @deprecated use {@link #getLocation()} instead
- */
- public Point location()
- {
- return new Point (x, y);
- }
-
- /**
- * Moves this component to the specified location, relative to the parent's
- * coordinates. The coordinates are the new upper left corner of this
- * component.
- *
- * @param x the new X coordinate of this component
- * @param y the new Y coordinate of this component
- * @see #getLocation()
- * @see #setBounds(int, int, int, int)
- */
- public void setLocation(int x, int y)
- {
- move (x, y);
- }
-
- /**
- * Moves this component to the specified location, relative to the parent's
- * coordinates. The coordinates are the new upper left corner of this
- * component.
- *
- * @param x the new X coordinate of this component
- * @param y the new Y coordinate of this component
- * @deprecated use {@link #setLocation(int, int)} instead
- */
- public void move(int x, int y)
- {
- setBounds(x, y, this.width, this.height);
- }
-
- /**
- * Moves this component to the specified location, relative to the parent's
- * coordinates. The coordinates are the new upper left corner of this
- * component.
- *
- * @param p new coordinates for this component
- * @throws NullPointerException if p is null
- * @see #getLocation()
- * @see #setBounds(int, int, int, int)
- * @since 1.1
- */
- public void setLocation(Point p)
- {
- setLocation(p.x, p.y);
- }
-
- /**
- * Returns the size of this object.
- *
- * @return the size of this object
- * @see #setSize(int, int)
- * @since 1.1
- */
- public Dimension getSize()
- {
- return size ();
- }
-
- /**
- * Returns the size of this object.
- *
- * @return the size of this object
- * @deprecated use {@link #getSize()} instead
- */
- public Dimension size()
- {
- return new Dimension (width, height);
- }
-
- /**
- * Sets the size of this component to the specified width and height.
- *
- * @param width the new width of this component
- * @param height the new height of this component
- * @see #getSize()
- * @see #setBounds(int, int, int, int)
- */
- public void setSize(int width, int height)
- {
- resize (width, height);
- }
-
- /**
- * Sets the size of this component to the specified value.
- *
- * @param width the new width of the component
- * @param height the new height of the component
- * @deprecated use {@link #setSize(int, int)} instead
- */
- public void resize(int width, int height)
- {
- setBounds(this.x, this.y, width, height);
- }
-
- /**
- * Sets the size of this component to the specified value.
- *
- * @param d the new size of this component
- * @throws NullPointerException if d is null
- * @see #setSize(int, int)
- * @see #setBounds(int, int, int, int)
- * @since 1.1
- */
- public void setSize(Dimension d)
- {
- resize (d);
- }
-
- /**
- * Sets the size of this component to the specified value.
- *
- * @param d the new size of this component
- * @throws NullPointerException if d is null
- * @deprecated use {@link #setSize(Dimension)} instead
- */
- public void resize(Dimension d)
- {
- resize (d.width, d.height);
- }
-
- /**
- * Returns a bounding rectangle for this component. Note that the
- * returned rectange is relative to this component's parent, not to
- * the screen.
- *
...
[truncated message content] |