summaryrefslogtreecommitdiff
path: root/java/awt
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2002-03-20 04:56:08 +0000
committerEric Blake <ebb9@byu.net>2002-03-20 04:56:08 +0000
commit3865f3b02ec80f548b6118000220225af62c866d (patch)
tree676170760d4aafa7b15f6cad706c75454332aad9 /java/awt
parent0722b105f2e9687cd8f9fe1e5a6401a354184eff (diff)
downloadclasspath-3865f3b02ec80f548b6118000220225af62c866d.tar.gz
2002-03-19 Eric Blake <ebb9@email.byu.edu>
* java/awt/Makefile.am (EXTRA_DIST): Add new files. * java/awt/AWTEvent.java: Update to 1.4. * java/awt/ActiveEvent.java: Update to 1.4. * java/awt/Adjustable.java: Update to 1.4. * java/awt/Composite.java: New file. * java/awt/CompositeContext.java: New file. * java/awt/ItemSelectable.java: Update to 1.4. * java/awt/KeyEventDispatcher.java: New file. * java/awt/KeyEventPostProcessor.java: New file. * java/awt/LayoutManager.java: Update to 1.4. * java/awt/LayoutManager2.java: Update to 1.4. * java/awt/MenuContainer.java: Update to 1.4. * java/awt/Paint.java: Update to 1.4. * java/awt/PaintContext.java: Update to 1.4. * java/awt/Polygon.java: Update to 1.4, including new methods. * java/awt/PrintGraphics.java: Update to 1.4. * java/awt/Shape.java: Update to 1.4. * java/awt/Stroke.java: New file. * java/awt/Transparency.java: Update to 1.4.
Diffstat (limited to 'java/awt')
-rw-r--r--java/awt/AWTEvent.java234
-rw-r--r--java/awt/ActiveEvent.java25
-rw-r--r--java/awt/Adjustable.java306
-rw-r--r--java/awt/Composite.java73
-rw-r--r--java/awt/CompositeContext.java71
-rw-r--r--java/awt/ItemSelectable.java71
-rw-r--r--java/awt/KeyEventDispatcher.java82
-rw-r--r--java/awt/KeyEventPostProcessor.java81
-rw-r--r--java/awt/LayoutManager.java114
-rw-r--r--java/awt/LayoutManager2.java126
-rw-r--r--java/awt/Makefile.am5
-rw-r--r--java/awt/MenuContainer.java61
-rw-r--r--java/awt/Paint.java52
-rw-r--r--java/awt/PaintContext.java45
-rw-r--r--java/awt/Polygon.java954
-rw-r--r--java/awt/PrintGraphics.java32
-rw-r--r--java/awt/Shape.java173
-rw-r--r--java/awt/Stroke.java65
-rw-r--r--java/awt/Transparency.java38
19 files changed, 1792 insertions, 816 deletions
diff --git a/java/awt/AWTEvent.java b/java/awt/AWTEvent.java
index 1b9e95e2e..e74338959 100644
--- a/java/awt/AWTEvent.java
+++ b/java/awt/AWTEvent.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
+/* AWTEvent.java -- the root event in AWT
+ Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,145 +38,164 @@ exception statement from your version. */
package java.awt;
-/* Written using on-line Java 2 Platform Standard Edition v1.3 API
- * Specification, as well as "The Java Class Libraries", 2nd edition
- * (Addison-Wesley, 1998).
- * Status: Believed complete and correct, except for the java.awt.Event
- * compatibility constructor.
- */
+import java.util.EventObject;
/**
* 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.
+ * 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 <warrenl@cygnus.com>
- * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.1
+ * @status updated to 1.4
*/
-public abstract class AWTEvent extends java.util.EventObject
+public abstract class AWTEvent extends EventObject
{
/**
- * @serial Indicates whether or not this event has been consumed.
+ * Compatible with JDK 1.1+.
*/
- protected boolean consumed;
+ private static final long serialVersionUID = -1825314779160409405L;
/**
- * @serial The identifier number of this event.
+ * The ID of the event.
+ *
+ * @see #getID()
+ * @see #AWTEvent(Object, int)
+ * @serial the identifier number of this event
*/
protected int id;
/**
- * Mask for selecting component events.
- */
- public static final long COMPONENT_EVENT_MASK = 0x001;
+ * 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;
/**
- * Mask for selecting container events.
- */
- public static final long CONTAINER_EVENT_MASK = 0x002;
+ * Who knows? It's in the serial version.
+ *
+ * @serial No idea what this is for.
+ */
+ byte[] bdata;
- /**
- * Mask for selecting component focus events.
- */
- public static final long FOCUS_EVENT_MASK = 0x004;
+ /** Mask for selecting component events. */
+ public static final long COMPONENT_EVENT_MASK = 0x00001;
- /**
- * Mask for selecting keyboard events.
- */
- public static final long KEY_EVENT_MASK = 0x008;
+ /** Mask for selecting container events. */
+ public static final long CONTAINER_EVENT_MASK = 0x00002;
- /**
- * Mask for mouse button events.
- */
- public static final long MOUSE_EVENT_MASK = 0x010;
+ /** Mask for selecting component focus events. */
+ public static final long FOCUS_EVENT_MASK = 0x00004;
- /**
- * Mask for mouse motion events.
- */
- public static final long MOUSE_MOTION_EVENT_MASK = 0x020;
+ /** Mask for selecting keyboard events. */
+ public static final long KEY_EVENT_MASK = 0x00008;
- /**
- * Mask for window events.
- */
- public static final long WINDOW_EVENT_MASK = 0x040;
+ /** Mask for mouse button events. */
+ public static final long MOUSE_EVENT_MASK = 0x00010;
- /**
- * Mask for action events.
- */
- public static final long ACTION_EVENT_MASK = 0x080;
+ /** Mask for mouse motion events. */
+ public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;
- /**
- * Mask for adjustment events.
- */
- public static final long ADJUSTMENT_EVENT_MASK = 0x100;
+ /** Mask for window events. */
+ public static final long WINDOW_EVENT_MASK = 0x00040;
- /**
- * Mask for item events.
- */
- public static final long ITEM_EVENT_MASK = 0x200;
+ /** 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 text events.
- */
- public static final long TEXT_EVENT_MASK = 0x400;
+ * Mask for input method events.
+ * @since 1.3
+ */
+ public static final long INPUT_METHOD_EVENT_MASK = 0x00800;
/**
- * This is the highest number for event ids that are reserved for use by
- * the AWT system itself.
- */
- public static final int RESERVED_ID_MAX = 1999;
+ * Mask for paint events.
+ * @since 1.3
+ */
+ public static final long PAINT_EVENT_MASK = 0x02000;
- public static final long INPUT_METHOD_EVENT_MASK = 1 << 11;
+ /**
+ * Mask for invocation events.
+ * @since 1.3
+ */
+ public static final long INVOCATION_EVENT_MASK = 0x04000;
- /* Additional event selection masks from JDK 1.3 javadocs */
- public static final long PAINT_EVENT_MASK = 1 << 13,
- INVOCATION_EVENT_MASK = 1 << 14,
- HIERARCHY_EVENT_MASK = 1 << 15,
- HIERARCHY_BOUNDS_EVENT_MASK = 1 << 16;
+ /**
+ * 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;
/**
- * The mask for mouse wheel events.
+ * Mask for mouse wheel events.
* @since 1.4
*/
- public static final long MOUSE_WHEEL_EVENT_MASK = 1 << 17;
-
+ public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
/**
- * The mask for window state events.
+ * Mask for window state events.
* @since 1.4
*/
- public static final long WINDOW_STATE_EVENT_MASK = 1 << 18;
-
+ public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
/**
- * The mask for window focus events.
+ * Mask for window focus events.
* @since 1.4
*/
- public static final long WINDOW_FOCUS_EVENT_MASK = 1 << 19;
+ 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 instance of <code>AWTEvent</code> from the
- * specified Java 1.0 event object.
- *
- * @param event The Java 1.0 event to initialize from.
- *
- *
- * Removed this method because we no longer support Java 1.0
+ * 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)
{
- // FIXME??
- super(event.target);
- this.id = event.id;
+ this(event.target, event.id);
+ consumed = event.consumed;
}
/**
- * Initializes a new instance of <code>AWTEvent</code> with the specified
- * source and id.
+ * Create an event on the specified source object and id.
*
- * @param source The object that caused the event.
- * @param id The event 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)
{
@@ -184,9 +204,21 @@ public abstract class AWTEvent extends java.util.EventObject
}
/**
- * Returns the id number of this event.
+ * 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.
*
- * @return The id number of this event.
+ * @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()
{
@@ -194,23 +226,26 @@ public abstract class AWTEvent extends java.util.EventObject
}
/**
- * Returns a string representation of this event.
+ * Returns a string representation of this event. This is in the format
+ * <code>getClass().getName() + '[' + paramString() + "] on "
+ * + source</code>.
*
- * @return A string representation of this event.
+ * @return a string representation of this event
*/
- public String paramString ()
+ public String toString()
{
- return "";
+ return getClass().getName() + "[" + paramString() + "] on " + source;
}
/**
- * Returns a string representation of this event.
+ * 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.
+ * @return a string representation of this event
*/
- public String toString ()
+ public String paramString()
{
- return getClass().getName() + "[" + paramString() + "] on " + source;
+ return "";
}
/**
@@ -223,14 +258,13 @@ public abstract class AWTEvent extends java.util.EventObject
}
/**
- * Tests whether not not this event has been consumed. A consumed event
+ * Tests whether not not this event has been consumed. A consumed event
* is not processed in the default manner.
*
- * @return <code>true</code> if this event has been consumed,
- * <code>false</code> otherwise.
+ * @return true if this event has been consumed
*/
protected boolean isConsumed()
{
return consumed;
}
-}
+} // class AWTEvent
diff --git a/java/awt/ActiveEvent.java b/java/awt/ActiveEvent.java
index d48a09b32..357627dbd 100644
--- a/java/awt/ActiveEvent.java
+++ b/java/awt/ActiveEvent.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* ActiveEvent.java -- a self-dispatching event
+ Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -38,13 +39,23 @@ exception statement from your version. */
package java.awt;
/**
+ * An interface for events which can dispatch themselves in another thread.
+ * This has two uses: first, if your code is in a critical section, calling a
+ * synchronized method might deadlock. But by using an ActiveEvent to call
+ * the second section, it will not obtain the lock until you have left the
+ * critical section, avoiding deadlock. The second use is for calling
+ * untrusted code. For example, system code should use an ActiveEvent to
+ * invoke user code securely.
+ *
* @author Tom Tromey <tromey@cygnus.com>
- * @date April 8, 2000
+ * @since 1.2
+ * @status updated to 1.4
*/
-
-/* Status: Believed complete and correct to JDK 1.2. */
-
public interface ActiveEvent
{
- public void dispatch ();
-}
+ /**
+ * Dispatch the event, according to what the event needs done. Invoked
+ * automatically if this is placed on the <code>EventDispatchQueue</code>.
+ */
+ public void dispatch();
+} // interface ActiveEvent
diff --git a/java/awt/Adjustable.java b/java/awt/Adjustable.java
index ce7b5bb8d..58116e4e5 100644
--- a/java/awt/Adjustable.java
+++ b/java/awt/Adjustable.java
@@ -1,5 +1,5 @@
-/* Adjustable.java -- Objects with a numeric adjustment scale.
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* Adjustable.java -- Objects with a numeric adjustment scale
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,183 +41,131 @@ package java.awt;
import java.awt.event.AdjustmentListener;
/**
- * This interface is for objects that take a numeric value that
- * can be adjusted within a bounded range. For example, a scroll bar.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface is for objects that take a numeric value that can be
+ * adjusted within a bounded range. For example, a scroll bar.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface Adjustable
{
-
-/*
- * Static Variables
- */
-
-/**
- * Constant for a horizontal orientation
- */
-public static final int HORIZONTAL = 0;
-
-/**
- * Constant for a vertical orientation
- */
-public static final int VERTICAL = 1;
-
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
-/**
- * Returns the current value of the object.
- *
- * @return The current value of the object.
- */
-public abstract int
-getValue();
-
-/*************************************************************************/
-
-/**
- * Sets the current value of the object.
- *
- * @param value The current value of the object.
- */
-public abstract void
-setValue(int value);
-
-/*************************************************************************/
-
-/**
- * Returns the orientation of the object, either <code>HORIZONTAL</code>
- * or <code>VERTICAL</code>.
- *
- * @return The orientation of this object.
- */
-public abstract int
-getOrientation();
-
-/*************************************************************************/
-
-/**
- * Returns the minimum value this object can take.
- *
- * @return The minimum value this object can take.
- */
-public abstract int
-getMinimum();
-
-/*************************************************************************/
-
-/**
- * Sets the minimum value this object can take to the specified value.
- *
- * @param minimum The new minimum value for this object.
- */
-public abstract void
-setMinimum(int minimum);
-
-/*************************************************************************/
-
-/**
- * Returns the maximum value this object can take.
- *
- * @return The maximum value this object can take.
- */
-public abstract int
-getMaximum();
-
-/*************************************************************************/
-
-/**
- * Sets the maximum value this object can take to the specified value.
- *
- * @param maximum The new maximum value for this object.
- */
-public abstract void
-setMaximum(int maximum);
-
-/*************************************************************************/
-
-/**
- * Returns the increment value for incrementing by units.
- *
- * @return The unit increment value.
- */
-public abstract int
-getUnitIncrement();
-
-/*************************************************************************/
-
-/**
- * Sets the increment value for incrementing by units to the specified value.
- *
- * @param increment The unit increment value.
- */
-public abstract void
-setUnitIncrement(int increment);
-
-/*************************************************************************/
-
-/**
- * Returns the increment value for incrementing by blocks.
- *
- * @return The block increment value.
- */
-public abstract int
-getBlockIncrement();
-
-/*************************************************************************/
-
-/**
- * Sets the increment value for incrementing by blocks to the specified value.
- *
- * @param increment The block increment value.
- */
-public abstract void
-setBlockIncrement(int increment);
-
-/*************************************************************************/
-
-/**
- * Returns the length of the indicator for this object.
- *
- * @return The indicator length.
- */
-public abstract int
-getVisibleAmount();
-
-/*************************************************************************/
-
-/**
- * Sets the length of the indicator for this object to the specified value.
- *
- * @param length The indicator length
- */
-public abstract void
-setVisibleAmount(int length);
-
-/*************************************************************************/
-
-/**
- * Adds a listener that will receive adjustment events for this object.
- *
- * @param listener The adjustment listener to add.
- */
-public abstract void
-addAdjustmentListener(AdjustmentListener listener);
-
-/*************************************************************************/
-
-/**
- * Removes an adjustment listener from this object. It will no longer
- * receive adjustment events.
- *
- * @param listener The adjustment listener to remove.
- */
-public abstract void
-removeAdjustmentListener(AdjustmentListener listener);
-
+ /** Constant for an adjustable object with horizontal orientation. */
+ int HORIZONTAL = 0;
+
+ /** Constant for an adjustable object with vertical orientation. */
+ int VERTICAL = 1;
+
+ /** Constant for an adjustable object with no orientation. */
+ int NO_ORIENTATION = 2;
+
+ /**
+ * Returns a constant representing the orientation of the object.
+ *
+ * @return the orientation of this object
+ * @see #HORIZONTAL
+ * @see #VERTICAL
+ * @see #NO_ORIENTATION
+ */
+ int getOrientation();
+
+ /**
+ * Sets the minimum value this object can have.
+ *
+ * @param minimum the new minimum value
+ */
+ void setMinimum(int minimum);
+
+ /**
+ * Returns the minimum value this object can have.
+ *
+ * @return the minimum value
+ */
+ int getMinimum();
+
+ /**
+ * Sets the maximum value this object can have.
+ *
+ * @param maximum the new maximum value
+ */
+ void setMaximum(int maximum);
+
+ /**
+ * Returns the maximum value this object can have.
+ *
+ * @return the maximum value
+ */
+ int getMaximum();
+
+ /**
+ * Sets the increment value for incrementing the value by units.
+ *
+ * @param increment the unit increment value
+ */
+ void setUnitIncrement(int increment);
+
+ /**
+ * Returns the increment value for incrementing the value by units.
+ *
+ * @return the unit increment value
+ */
+ int getUnitIncrement();
+
+ /**
+ * Sets the increment value for incrementing the value by blocks.
+ *
+ * @param increment the block increment value
+ */
+ void setBlockIncrement(int increment);
+
+ /**
+ * Returns the increment value for incrementing the value by blocks.
+ *
+ * @return the block increment value
+ */
+ int getBlockIncrement();
+
+ /**
+ * Sets the length of the indicator for this object to the specified value.
+ *
+ * @param length the indicator length
+ */
+ void setVisibleAmount(int length);
+
+ /**
+ * Returns the length of the indicator for this object.
+ *
+ * @return the indicator length
+ */
+ int getVisibleAmount();
+
+ /**
+ * Sets the current value of the object.
+ *
+ * @param value the new value
+ */
+ void setValue(int value);
+
+ /**
+ * Returns the current value of the object.
+ *
+ * @return the current value
+ */
+ int getValue();
+
+ /**
+ * Adds a listener that will receive adjustment events for this object.
+ *
+ * @param listener the adjustment listener to add
+ * @see AdjustmentEvent
+ */
+ void addAdjustmentListener(AdjustmentListener listener);
+
+ /**
+ * Removes an adjustment listener from this object.
+ *
+ * @param listener the adjustment listener to remove
+ * @see AdjustmentEvent
+ */
+ void removeAdjustmentListener(AdjustmentListener listener);
} // interface Adjustable
-
diff --git a/java/awt/Composite.java b/java/awt/Composite.java
new file mode 100644
index 000000000..de8739816
--- /dev/null
+++ b/java/awt/Composite.java
@@ -0,0 +1,73 @@
+/* Composite.java -- graphics formed from composite layers
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image.ColorModel;
+
+/**
+ * This interface is for graphics which are formed as composites of others.
+ * It combines {@link Graphics2D} shapes according to defined rules to form
+ * the new image. Implementations of this interface must be immutable, because
+ * they are not cloned when a Graphics2D container is cloned.
+ *
+ * <p>Since this can expose pixels to untrusted code, there is a security
+ * check on custom objects, <code>readDisplayPixels</code>, to prevent leaking
+ * restricted information graphically.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see AlphaComposite
+ * @see CompositeContext
+ * @see Graphics2D#setComposite(Composite)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface Composite
+{
+ /**
+ * Create a context state for performing the compositing operation. Several
+ * contexts may exist for this object, in a multi-threaded environment.
+ *
+ * @param srcColorModel the color model of the source
+ * @param dstColorModel the color model of the destination
+ * @param hints hints for choosing between rendering alternatives
+ */
+ CompositeContext createContext(ColorModel srcColorModel,
+ ColorModel dstColorModel,
+ RenderingHints hints);
+} // interface Composite
diff --git a/java/awt/CompositeContext.java b/java/awt/CompositeContext.java
new file mode 100644
index 000000000..dc3448b11
--- /dev/null
+++ b/java/awt/CompositeContext.java
@@ -0,0 +1,71 @@
+/* Composite.java -- the context for compositing graphics layers
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.image.Raster;
+import java.awt.image.WritableRaster;
+
+/**
+ * This interface provides an optimized environment for compositing graphics.
+ * Several such contexts may exist for a given <code>Composite</code> object.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see Composite
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface CompositeContext
+{
+ /**
+ * Release resources allocated for the compositing.
+ */
+ void dispose();
+
+ /**
+ * Compose the two source images into the composite image. The destination
+ * can be the same as one of the two inputs, and the destination must be
+ * compatible with the ColorModel chosen in {@link Composite#createContext}.
+ *
+ * @param src the lower image source in compositing
+ * @param dstIn the upper image source in compositing
+ * @param dstOut the destination for the composite
+ * @see Composite
+ */
+ void compose(Raster src, Raster dstIn, WritableRaster dstOut);
+} // interface CompositeContext
diff --git a/java/awt/ItemSelectable.java b/java/awt/ItemSelectable.java
index 4d1314fc3..ddf77aeb1 100644
--- a/java/awt/ItemSelectable.java
+++ b/java/awt/ItemSelectable.java
@@ -1,5 +1,5 @@
-/* ItemSelectable.java -- Items that can be selected
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* ItemSelectable.java -- items that can be selected
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,44 +41,35 @@ package java.awt;
import java.awt.event.ItemListener;
/**
- * This interface is for objects that can have one or more items
- * selected. For example, radio buttons.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface is for objects that can have one or more items selected.
+ * For example, radio buttons.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface ItemSelectable
{
-
-/**
- * Returns the list of objects that are selected in this component.
- *
- * @return The list of objects that are selected, or <code>null</code> if
- * no objects are selected.
- */
-public abstract Object[]
-getSelectedObjects();
-
-/*************************************************************************/
-
-/**
- * Adds an item listener to this object. It will receive
- * selection events for this object.
- *
- * @param listener The item listener to add.
- */
-public abstract void
-addItemListener(ItemListener listener);
-
-/*************************************************************************/
-
-/**
- * Removes an item listener from this object. It will no longer receive
- * selection change events.
- *
- * @param listener The item listener to remove.
- */
-public abstract void
-removeItemListener(ItemListener listener);
-
+ /**
+ * Returns the list of objects that are selected in this component.
+ *
+ * @return the list of selected objects, or null
+ */
+ Object[] getSelectedObjects();
+
+ /**
+ * Adds an item listener to this object. It will receive selection events
+ * for this object by the user (but not programatically). If listener is
+ * null, it is ignored.
+ *
+ * @param listener the item listener to add
+ */
+ void addItemListener(ItemListener listener);
+
+ /**
+ * Removes an item listener from this object.
+ *
+ * @param listener the item listener to remove
+ */
+ void removeItemListener(ItemListener listener);
} // interface ItemSelectable
-
diff --git a/java/awt/KeyEventDispatcher.java b/java/awt/KeyEventDispatcher.java
new file mode 100644
index 000000000..95aad8030
--- /dev/null
+++ b/java/awt/KeyEventDispatcher.java
@@ -0,0 +1,82 @@
+/* KeyEventDispatcher.java -- dispatches key events
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.KeyEvent;
+
+/**
+ * An instance of this interface coordinates with a KeyboardFocusManager to
+ * target and dispatch all key events. This allows retargeting, consuming,
+ * changing, or otherwise manipulating the key event before sending it on to
+ * a target.
+ *
+ * <p>By default, the KeyboardFocusManager is the sink for all key events not
+ * dispatched by other dispatchers. Therefore, it is unnecessary for the user
+ * to register the focus manager as a dispatcher.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)
+ * @see KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public interface KeyEventDispatcher
+{
+ /**
+ * Called by the KeyboardFocusManager to request that a key event be
+ * dispatched. The dispatcher is free to retarget the event, consume it,
+ * dispatch it, or make other changes. This is usually done to allow
+ * delivery of key events to objects other than the window in focus, such
+ * as for navigating non-focusable components. If this dispatcher chooses
+ * to dispatch the event itself, it should call <code>redispatchEvent</code>
+ * to avoid infinite recursion.
+ *
+ * <p>If the return value is false, the KeyEvent is passed to the next
+ * dispatcher in the chain, ending with the KeyboardFocusManager. If the
+ * return value is true, the event has been consumed (although it might
+ * have been ignored), and no further action will be taken on the event. Be
+ * sure to check whether the event was consumed before dispatching it
+ * further.
+ *
+ * @param e the key event
+ * @return true if the event has been consumed
+ * @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent)
+ */
+ boolean dispatchKeyEvent(KeyEvent e);
+} // interface KeyEventDispatcher
diff --git a/java/awt/KeyEventPostProcessor.java b/java/awt/KeyEventPostProcessor.java
new file mode 100644
index 000000000..5069aaf51
--- /dev/null
+++ b/java/awt/KeyEventPostProcessor.java
@@ -0,0 +1,81 @@
+/* KeyEventPostProcessor.java -- performs actions after a key event dispatch
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.KeyEvent;
+
+/**
+ * An instance of this interface coordinates with a KeyboardFocusManager to
+ * target and dispatch all key events that are otherwise unconsumed. This
+ * allows events which take place when nothing has focus to still operate,
+ * such as menu keyboard shortcuts.
+ *
+ * <p>By default, the KeyboardFocusManager is the sink for all key events not
+ * post-processed elsewhere. Therefore, it is unnecessary for the user
+ * to register the focus manager as a dispatcher.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)
+ * @see KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public interface KeyEventPostProcessor
+{
+ /**
+ * Called by the KeyboardFocusManager to request that a key event be
+ * post-processed. Typically, the event has already been dispatched and
+ * handled, unless no object has focus. Thus, this allows global event
+ * handling for things like menu shortcuts. If this post-processor chooses
+ * to dispatch the event, it should call <code>redispatchEvent</code>
+ * to avoid infinite recursion.
+ *
+ * <p>If the return value is false, the KeyEvent is passed to the next
+ * dispatcher in the chain, ending with the KeyboardFocusManager. If the
+ * return value is true, the event has been consumed (although it might
+ * have been ignored), and no further action will be taken on the event. Be
+ * sure to check whether the event was consumed before dispatching it
+ * further.
+ *
+ * @param e the key event
+ * @return true if the event has been consumed
+ * @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent)
+ */
+ boolean postProcessKeyEvent(KeyEvent e);
+} // interface KeyEventPostProcessor
diff --git a/java/awt/LayoutManager.java b/java/awt/LayoutManager.java
index 695755b62..1231c3eb6 100644
--- a/java/awt/LayoutManager.java
+++ b/java/awt/LayoutManager.java
@@ -1,5 +1,5 @@
-/* LayoutManager.java -- Layout containers in a Window
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* LayoutManager.java -- lay out elements in a Container
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,68 +39,54 @@ exception statement from your version. */
package java.awt;
/**
- * This interface is for laying out containers.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface is for laying out containers in a particular sequence.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @see Container
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface LayoutManager
{
-
-/**
- * Adds the specified component to the layout group.
- *
- * @param name The name of the component to add.
- * @param component The component to add.
- */
-public abstract void
-addLayoutComponent(String name, Component component);
-
-/*************************************************************************/
-
-/**
- * Removes the specified component from the layout group.
- *
- * @param component The component to remove.
- */
-public abstract void
-removeLayoutComponent(Component component);
-
-/*************************************************************************/
-
-/**
- * Calculates the preferred size for this container, taking into account
- * the components in the specified parent container.
- *
- * @param parent The parent container.
- *
- * @return The preferred dimensions of this container.
- */
-public abstract Dimension
-preferredLayoutSize(Container parent);
-
-/*************************************************************************/
-
-/**
- * Calculates the minimum size for this container, taking into account
- * the components in the specified parent container.
- *
- * @param parent The parent container.
- *
- * @return The minimum dimensions of this container.
- */
-public abstract Dimension
-minimumLayoutSize(Container parent);
-
-/*************************************************************************/
-
-/**
- * Lays out the components in this container on the specified parent
- * container.
- *
- * @param parent The parent container.
- */
-public abstract void
-layoutContainer(Container parent);
-
+ /**
+ * Adds the specified component to the layout group.
+ *
+ * @param name the name of the component to add
+ * @param component the component to add
+ */
+ void addLayoutComponent(String name, Component component);
+
+ /**
+ * Removes the specified component from the layout group.
+ *
+ * @param component the component to remove
+ */
+ void removeLayoutComponent(Component component);
+
+ /**
+ * Calculates the preferred size for this container, taking into account
+ * the components it contains.
+ *
+ * @param parent the parent container to lay out
+ * @return the preferred dimensions of this container
+ * @see #minimumLayoutSize(Container)
+ */
+ Dimension preferredLayoutSize(Container parent);
+
+ /**
+ * Calculates the minimum size for this container, taking into account
+ * the components it contains.
+ *
+ * @param parent the parent container to lay out
+ * @return the minimum dimensions of this container
+ * @see #preferredLayoutSize(Container)
+ */
+ Dimension minimumLayoutSize(Container parent);
+
+ /**
+ * Lays out the components in the given container.
+ *
+ * @param parent the container to lay out
+ */
+ void layoutContainer(Container parent);
} // interface LayoutManager
-
diff --git a/java/awt/LayoutManager2.java b/java/awt/LayoutManager2.java
index 77c021d0c..418e4d886 100644
--- a/java/awt/LayoutManager2.java
+++ b/java/awt/LayoutManager2.java
@@ -1,5 +1,5 @@
-/* LayoutManager2.java -- Enhanced layout manager.
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* LayoutManager2.java -- enhanced layout manager
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,70 +39,62 @@ exception statement from your version. */
package java.awt;
/**
- * Layout manager for laying out containers based on contraints.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * Layout manager for laying out containers based on contraints. The
+ * constraints control how the layout will proceed.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @see LayoutManager
+ * @see Container
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface LayoutManager2 extends LayoutManager
{
-
-/**
- * Adds the specified component to the layout, with the specified
- * constraint object.
- *
- * @param component The component to add.
- * @param constraint The constraint object.
- */
-public abstract void
-addLayoutComponent(Component component, Object contraint);
-
-/*************************************************************************/
-
-/**
- * Determines the minimum size of the specified target container.
- *
- * @param target The target container.
- */
-public abstract Dimension
-maximumLayoutSize(Container target);
-
-/*************************************************************************/
-
-/**
- * Returns the preferred X axis alignment for the specified target
- * container. This value will range from 0 to 1 where 0 is alignment
- * closest to the origin, 0.5 is centered, and 1 is aligned furthest
- * from the origin.
- *
- * @param target The target container.
- */
-public abstract float
-getLayoutAlignmentX(Container target);
-
-/*************************************************************************/
-
-/**
- * Returns the preferred Y axis alignment for the specified target
- * container. This value will range from 0 to 1 where 0 is alignment
- * closest to the origin, 0.5 is centered, and 1 is aligned furthest
- * from the origin.
- *
- * @param target The target container.
- */
-public abstract float
-getLayoutAlignmentY(Container target);
-
-/*************************************************************************/
-
-/**
- * Forces the layout manager to purge any cached information about
- * the layout of the target container. This will force it to be
- * recalculated.
- *
- * @param target The target container.
- */
-public abstract void
-invalidateLayout(Container target);
-
-} // interface LayoutManager2
-
+ /**
+ * Adds the specified component to the layout, with the specified
+ * constraint object.
+ *
+ * @param component the component to add
+ * @param constraint the constraint to satisfy
+ */
+ void addLayoutComponent(Component component, Object contraint);
+
+ /**
+ * Determines the maximum size of the specified target container.
+ *
+ * @param target the container to lay out
+ * @return the maximum size of the container
+ * @see Component#getMaximumSize()
+ */
+ Dimension maximumLayoutSize(Container target);
+
+ /**
+ * Returns the preferred X axis alignment for the specified target
+ * container. This value will range from 0 to 1 where 0 is alignment
+ * closest to the origin, 0.5 is centered, and 1 is aligned furthest
+ * from the origin.
+ *
+ * @param target the target container
+ * @return the x-axis alignment preference
+ */
+ float getLayoutAlignmentX(Container target);
+
+ /**
+ * Returns the preferred Y axis alignment for the specified target
+ * container. This value will range from 0 to 1 where 0 is alignment
+ * closest to the origin, 0.5 is centered, and 1 is aligned furthest
+ * from the origin.
+ *
+ * @param target the target container
+ * @return the y-axis alignment preference
+ */
+ float getLayoutAlignmentY(Container target);
+
+ /**
+ * Forces the layout manager to purge any cached information about the
+ * layout of the target container. This will force it to be recalculated.
+ *
+ * @param target the target container
+ */
+ void invalidateLayout(Container target);
+} // interface LayoutManager2
diff --git a/java/awt/Makefile.am b/java/awt/Makefile.am
index f429e854b..765a7a8c0 100644
--- a/java/awt/Makefile.am
+++ b/java/awt/Makefile.am
@@ -21,6 +21,8 @@ Choice.java \
Color.java \
Component.java \
ComponentOrientation.java \
+Composite.java \
+CompositeContext.java \
Container.java \
Cursor.java \
Dialog.java \
@@ -48,6 +50,8 @@ IllegalComponentStateException.java \
Image.java \
Insets.java \
ItemSelectable.java \
+KeyEventDispatcher.java \
+KeyEventPostProcessor.java \
Label.java \
LayoutManager2.java \
LayoutManager.java \
@@ -73,6 +77,7 @@ Scrollbar.java \
ScrollPaneAdjustable.java \
ScrollPane.java \
Shape.java \
+Stroke.java \
SystemColor.java \
TextArea.java \
TextComponent.java \
diff --git a/java/awt/MenuContainer.java b/java/awt/MenuContainer.java
index 33ac07d83..dd8b3412e 100644
--- a/java/awt/MenuContainer.java
+++ b/java/awt/MenuContainer.java
@@ -1,4 +1,4 @@
-/* MenuContainer.java -- Container for menu items.
+/* MenuContainer.java -- container for menu items
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,42 +39,33 @@ exception statement from your version. */
package java.awt;
/**
- * This interface is a container for menu components.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface is a container for menu components.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface MenuContainer
{
+ /**
+ * Returns the font in use by this container.
+ *
+ * @return the menu font
+ */
+ Font getFont();
-/**
- * Returns the font in use by this container.
- *
- * @return The font in use by this container.
- */
-public abstract Font
-getFont();
-
-/*************************************************************************/
-
-/**
- * Removes the specified menu component from the menu.
- *
- * @param component The menu component to remove.
- */
-public abstract void
-remove(MenuComponent component);
-
-/*************************************************************************/
-
-/**
- * Posts and event to the listeners. This is replaced by
- * <code>dispatchEvent</code>.
- *
- * @param event The event to dispatch.
- *
- * @deprecated
- */
-public abstract boolean
-postEvent(Event event);
+ /**
+ * Removes the specified menu component from the menu.
+ *
+ * @param component the menu component to remove
+ */
+ void remove(MenuComponent component);
+ /**
+ * Posts an event to the listeners.
+ *
+ * @param event the event to dispatch
+ * @deprecated use {@link MenuComponent#dispatchEvent(AWTEvent)} instead
+ */
+ boolean postEvent(Event event);
} // interface MenuContainer
diff --git a/java/awt/Paint.java b/java/awt/Paint.java
index 1bba0735c..94c30c0ff 100644
--- a/java/awt/Paint.java
+++ b/java/awt/Paint.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Paint.java -- generate colors for Graphics2D operations
+ Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,23 +38,42 @@ exception statement from your version. */
package java.awt;
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 15, 2000.
- */
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.ColorModel;
/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Stubbed.
+ * Defines how color patterns are generated for Graphics2D operations. This
+ * is used to perform the <code>draw</code> and <code>fill</code> methods
+ * of the graphics object. Instances must be immutable, because the graphics
+ * object does not clone them.
+ *
+ * @author Warren Levy <warrenl@cygnus.com>
+ * @see PaintContext
+ * @see Color
+ * @see GradientPaint
+ * @see TexturePaint
+ * @see Graphics2D#setPaint(Paint)
+ * @since 1.1
+ * @status updated to 1.4
*/
-
public interface Paint extends Transparency
{
- // FIXME
- // public PaintContext createContext(ColorModel cm,
- // Rectangle deviceBounds,
- // Rectangle2D userBounds,
- // AffineTransform xform,
- // RenderingHints hints);
-}
+ /**
+ * Create the context necessary for performing the color pattern generation.
+ * The color model is a hint, and may be null for Classpath implementations;
+ * however some legacy code may throw a NullPointerException when passed a
+ * null. Leaving the color model null provides the most efficiency and leeway
+ * in the generation of the color pattern.
+ *
+ * @param cm the color model, used as a hint
+ * @param deviceBounds the device space bounding box of the painted area
+ * @param userBounds the user space bounding box of the painted area
+ * @param xform the transformation from user space to device space
+ * @param hints any hints for choosing between rendering alternatives
+ * @return the context for performing the paint
+ */
+ PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
+ Rectangle2D userBounds, AffineTransform xform,
+ RenderingHints hints);
+} // interface Paint
diff --git a/java/awt/PaintContext.java b/java/awt/PaintContext.java
index 639311869..e080dc0dd 100644
--- a/java/awt/PaintContext.java
+++ b/java/awt/PaintContext.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* PaintContext.java -- the environment for performing a paint operation
+ Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,21 +38,39 @@ exception statement from your version. */
package java.awt;
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 16, 2000.
- */
+import java.awt.image.ColorModel;
+import java.awt.image.Raster;
/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Partially stubbed.
+ * @author Warren Levy <warrenl@cygnus.com>
+ * @see Paint
+ * @since 1.1
+ * @status updated to 1.4
*/
-
public interface PaintContext
{
+ /**
+ * Release the resources allocated for the paint.
+ */
public void dispose();
- // FIXME
- // public ColorModel getColorModel();
- // public Raster getRaster(int x, int y, int w, int h);
-}
+
+ /**
+ * Return the color model of this context. It may be different from the
+ * hint specified during createContext, as not all contexts can generate
+ * color patterns in an arbitrary model.
+ *
+ * @return the context color model
+ */
+ ColorModel getColorModel();
+
+ /**
+ * Return a raster containing the colors for the graphics operation.
+ *
+ * @param x the x-coordinate, in device space
+ * @param y the y-coordinate, in device space
+ * @param w the width, in device space
+ * @param h the height, in device space
+ * @return a raster for the given area and color
+ */
+ Raster getRaster(int x, int y, int w, int h);
+} // interface PaintContext
diff --git a/java/awt/Polygon.java b/java/awt/Polygon.java
index 09cbf2b6c..52952700f 100644
--- a/java/awt/Polygon.java
+++ b/java/awt/Polygon.java
@@ -1,5 +1,5 @@
-/* Polygon.java -- Class representing a polygon
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* Polygon.java -- class representing a polygon
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,256 +38,710 @@ exception statement from your version. */
package java.awt;
-/**
- * This class represents a polygon
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
-public class Polygon implements Shape, java.io.Serializable
-{
-
-/*
- * Instance Variables
- */
-
-/**
- * This total number of endpoints
- */
-public int npoints;
-
-/**
- * The array of X coordinates of endpoints.
- */
-public int xpoints[];
-
-/**
- * The array of Y coordinates of endpoints.
- */
-public int ypoints[];
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.io.Serializable;
/**
- * The bounding box of this polygon
- */
-protected Rectangle bounds;
-
-/*************************************************************************/
-
-/*
- * Constructors
+ * This class represents a polygon, a closed, two-dimensional region in a
+ * coordinate space. The region is bounded by an arbitrary number of line
+ * segments, between (x,y) coordinate vertices. The polygon has even-odd
+ * winding, meaning that a point is inside the shape if it crosses the
+ * boundary an odd number of times on the way to infinity.
+ *
+ * <p>There are some public fields; if you mess with them in an inconsistent
+ * manner, it is your own fault when you get NullPointerException,
+ * ArrayIndexOutOfBoundsException, or invalid results. Also, this class is
+ * not threadsafe.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @since 1.0
+ * @status updated to 1.4
*/
-
-/**
- * Initializes a new instance of <code>Polygon</code> that is empty.
- */
-public
-Polygon()
-{
- xpoints = new int[0];
- ypoints = new int[0];
-
- bounds = new Rectangle(0,0,0,0);
-}
-
-/*************************************************************************/
-
-/**
- * Initializes a new instance of <code>Polygon</code> that has the
- * specified endpoints.
- *
- * @param xpoints The array of X coordinates for this polygon.
- * @param ypoints The array of Y coordinates for this polygon.
- * @param npoints The total number of endpoints in this polygon.
- *
- * @exception NegativeArraySizeException If <code>npoints</code> is negative.
- */
-public
-Polygon(int[] xpoints, int[] ypoints, int npoints)
-{
- if (npoints < 0)
- throw new NegativeArraySizeException();
-
- this.xpoints = xpoints;
- this.ypoints = ypoints;
- this.npoints = npoints;
-
- calculateBounds();
-}
-
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
-/**
- * Calculates the bounding rectangle of this polygon.
- */
-public void
-calculateBounds()
-{
- int minx = xpoints[0], maxx = xpoints[0];
- int miny = ypoints[0], maxy = ypoints[0];
-
- for (int i = 0; i < npoints; i++)
- {
- if (xpoints[i] < minx)
- minx = xpoints[i];
-
- if (xpoints[i] > maxx)
- maxx = xpoints[i];
-
- if (ypoints[i] < miny)
- miny = ypoints[i];
-
- if (ypoints[i] > maxy)
- maxy = ypoints[i];
- }
-
- bounds = new Rectangle(minx, maxy, maxx-minx, maxy-miny);
-}
-
-/*************************************************************************/
-
-/**
- * Translates the polygon by adding the specified values to all X and Y
- * coordinates.
- *
- * @param dx The amount to add to all X coordinates.
- * @param dy The amount to add to all Y coordinates.
- */
-public void
-translate(int dx, int dy)
+public class Polygon implements Shape, Serializable
{
- for (int i = 0; i < npoints; i++)
+ /**
+ * Compatible with JDK 1.0+.
+ */
+ private static final long serialVersionUID = -6460061437900069969L;
+
+ /**
+ * This total number of endpoints.
+ *
+ * @serial the number of endpoints, possibly less than the array sizes
+ */
+ public int npoints;
+
+ /**
+ * The array of X coordinates of endpoints. This should not be null.
+ *
+ * @see #addPoint(int, int)
+ * @serial the x coordinates
+ */
+ public int[] xpoints;
+
+ /**
+ * The array of Y coordinates of endpoints. This should not be null.
+ *
+ * @see #addPoint(int, int)
+ * @serial the y coordinates
+ */
+ public int[] ypoints;
+
+ /**
+ * The bounding box of this polygon. This is lazily created and cached, so
+ * it must be invalidated after changing points.
+ *
+ * @see #getBounds()
+ * @serial the bounding box, or null
+ */
+ protected Rectangle bounds;
+
+ /**
+ * Cached flattened version - condense points and parallel lines, so the
+ * result has area if there are >= 3 condensed vertices. flat[0] is the
+ * number of condensed points, and (flat[odd], flat[odd+1]) form the
+ * condensed points.
+ *
+ * @see #condense()
+ * @see #contains(double, double)
+ * @see #contains(double, double, double, double)
+ */
+ private transient int[] condensed;
+
+ /**
+ * Initializes an empty polygon.
+ */
+ public Polygon()
+ {
+ // Leave room for growth.
+ xpoints = new int[4];
+ ypoints = new int[4];
+ }
+
+ /**
+ * Create a new polygon with the specified endpoints.
+ *
+ * @param xpoints the array of X coordinates for this polygon
+ * @param ypoints the array of Y coordinates for this polygon
+ * @param npoints the total number of endpoints in this polygon
+ * @throws NegativeArraySizeException if npoints is negative
+ * @throws IndexOutOfBoundsException if npoints exceeds either array
+ * @throws NullPointerException if xpoints or ypoints is null
+ */
+ public Polygon(int[] xpoints, int[] ypoints, int npoints)
+ {
+ if (npoints < 0)
+ throw new NegativeArraySizeException();
+ if (npoints > xpoints.length || npoints > ypoints.length)
+ throw new IndexOutOfBoundsException();
+ this.xpoints = xpoints;
+ this.ypoints = ypoints;
+ this.npoints = npoints;
+ }
+
+ /**
+ * Reset the polygon to be empty. The arrays are left alone, to avoid object
+ * allocation, but the number of points is set to 0, and all cached data
+ * is discarded. If you are discarding a huge number of points, it may be
+ * more efficient to just create a new Polygon.
+ *
+ * @see #invalidate()
+ * @since 1.4
+ */
+ public void reset()
+ {
+ npoints = 0;
+ invalidate();
+ }
+
+ /**
+ * Invalidate or flush all cached data. After direct manipulation of the
+ * public member fields, this is necessary to avoid inconsistent results
+ * in methods like <code>contains</code>.
+ *
+ * @see #getBounds()
+ * @since 1.4
+ */
+ public void invalidate()
+ {
+ bounds = null;
+ condensed = null;
+ }
+
+ /**
+ * Translates the polygon by adding the specified values to all X and Y
+ * coordinates. This updates the bounding box, if it has been calculated.
+ *
+ * @param dx the amount to add to all X coordinates
+ * @param dy the amount to add to all Y coordinates
+ * @since 1.1
+ */
+ public void translate(int dx, int dy)
+ {
+ int i = npoints;
+ while (--i >= 0)
+ {
+ xpoints[i] += dx;
+ xpoints[i] += dy;
+ }
+ if (bounds != null)
+ {
+ bounds.x += dx;
+ bounds.y += dy;
+ }
+ condensed = null;
+ }
+
+ /**
+ * Adds the specified endpoint to the polygon. This updates the bounding
+ * box, if it has been created.
+ *
+ * @param x the X coordinate of the point to add
+ * @param y the Y coordiante of the point to add
+ */
+ public void addPoint(int x, int y)
+ {
+ if (npoints + 1 > xpoints.length)
+ {
+ int[] newx = new int[npoints + 1];
+ System.arraycopy(xpoints, 0, newx, 0, npoints);
+ xpoints = newx;
+ }
+ if (npoints + 1 > ypoints.length)
+ {
+ int[] newy = new int[npoints + 1];
+ System.arraycopy(ypoints, 0, newy, 0, npoints);
+ ypoints = newy;
+ }
+ xpoints[npoints] = x;
+ ypoints[npoints] = y;
+ npoints++;
+ if (bounds != null)
+ {
+ if (npoints == 1)
+ {
+ bounds.x = x;
+ bounds.y = y;
+ }
+ else
+ {
+ if (x < bounds.x)
+ {
+ bounds.width += bounds.x - x;
+ bounds.x = x;
+ }
+ else if (x > bounds.x + bounds.width)
+ bounds.width = x - bounds.x;
+ if (y < bounds.y)
+ {
+ bounds.height += bounds.y - y;
+ bounds.y = y;
+ }
+ else if (y > bounds.y + bounds.height)
+ bounds.height = y - bounds.y;
+ }
+ }
+ condensed = null;
+ }
+
+ /**
+ * Returns the bounding box of this polygon. This is the smallest
+ * rectangle with sides parallel to the X axis that will contain this
+ * polygon.
+ *
+ * @return the bounding box for this polygon
+ * @see #getBounds2D()
+ * @since 1.1
+ */
+ public Rectangle getBounds()
+ {
+ if (bounds == null)
+ {
+ if (npoints == 0)
+ return bounds = new Rectangle();
+ int i = npoints - 1;
+ int minx = xpoints[i];
+ int maxx = minx;
+ int miny = ypoints[i];
+ int maxy = miny;
+ while (--i >= 0)
+ {
+ int x = xpoints[i];
+ int y = ypoints[i];
+ if (x < minx)
+ minx = x;
+ else if (x > maxx)
+ maxx = x;
+ if (y < miny)
+ miny = y;
+ else if (y > maxy)
+ maxy = y;
+ }
+ bounds = new Rectangle(minx, maxy, maxx - minx, maxy - miny);
+ }
+ return bounds;
+ }
+
+ /**
+ * Returns the bounding box of this polygon. This is the smallest
+ * rectangle with sides parallel to the X axis that will contain this
+ * polygon.
+ *
+ * @return the bounding box for this polygon
+ * @see #getBounds2D()
+ * @deprecated use {@link #getBounds()} instead
+ */
+ public Rectangle getBoundingBox()
+ {
+ return getBounds();
+ }
+
+ /**
+ * Tests whether or not the specified point is inside this polygon.
+ *
+ * @param p the point to test
+ * @return true if the point is inside this polygon
+ * @throws NullPointerException if p is null
+ * @see #contains(double, double)
+ */
+ public boolean contains(Point p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Tests whether or not the specified point is inside this polygon.
+ *
+ * @param x the X coordinate of the point to test
+ * @param y the Y coordinate of the point to test
+ * @return true if the point is inside this polygon
+ * @see #contains(double, double)
+ * @since 1.1
+ */
+ public boolean contains(int x, int y)
+ {
+ return contains((double) x, (double) y);
+ }
+
+ /**
+ * Tests whether or not the specified point is inside this polygon.
+ *
+ * @param x the X coordinate of the point to test
+ * @param y the Y coordinate of the point to test
+ * @return true if the point is inside this polygon
+ * @see #contains(double, double)
+ * @deprecated use {@link #contains(int, int)} instead
+ */
+ public boolean inside(int x, int y)
+ {
+ return contains((double) x, (double) y);
+ }
+
+ /**
+ * Returns a high-precision bounding box of this polygon. This is the
+ * smallest rectangle with sides parallel to the X axis that will contain
+ * this polygon.
+ *
+ * @return the bounding box for this polygon
+ * @see #getBounds()
+ * @since 1.2
+ */
+ public Rectangle2D getBounds2D()
+ {
+ // For polygons, the integer version is exact!
+ return getBounds();
+ }
+
+ /**
+ * Tests whether or not the specified point is inside this polygon.
+ *
+ * @param x the X coordinate of the point to test
+ * @param y the Y coordinate of the point to test
+ * @return true if the point is inside this polygon
+ * @since 1.2
+ */
+ public boolean contains(double x, double y)
+ {
+ // First, the obvious bounds checks.
+ if (! condense() || ! getBounds().contains(x, y))
+ return false;
+ // A point is contained if a ray to (-inf, y) crosses an odd number
+ // of segments. This must obey the semantics of Shape when the point is
+ // exactly on a segment or vertex. Note that we are guaranteed that the
+ // condensed polygon has area, and no two segments with identical slope.
+ int intersections = 0;
+ int limit = condensed[0];
+ int curx = condensed[(limit << 1) - 1];
+ int cury = condensed[limit << 1];
+ for (int i = 1; i <= limit; i++)
+ {
+ int priorx = curx;
+ int priory = cury;
+ curx = condensed[(i << 1) - 1];
+ cury = condensed[i << 1];
+ if ((priorx > x && curx > x) // Left of segment, or NaN.
+ || (priory > y && cury > y) // Below segment, or NaN.
+ || (priory < y && cury < y)) // Above segment.
+ continue;
+ if (priory == cury) // Horizontal segment, y == cury == priory
+ {
+ if (priorx < x && curx < x) // Right of segment.
+ {
+ intersections++;
+ continue;
+ }
+ // Did we approach this segment from above or below?
+ // This mess is necessary to obey rules of Shape.
+ priory = condensed[((limit + i - 2) % limit) << 1];
+ boolean above = priory > cury;
+ if ((curx == x && (curx > priorx || above))
+ || (priorx == x && (curx < priorx || ! above))
+ || (curx > priorx && ! above) || above)
+ intersections++;
+ continue;
+ }
+ if (priorx == x && priory == y) // On prior vertex.
+ continue;
+ if (priorx == curx // Vertical segment.
+ || (priorx < x && curx < x)) // Right of segment.
+ {
+ intersections++;
+ continue;
+ }
+ // The point is inside the segment's bounding box, compare slopes.
+ double slopeseg = (double) (cury - priory) / (curx - priorx);
+ double slopepoint = (double) (y - priory) / (x - priorx);
+ if ((slopeseg > 0 && slopeseg > slopepoint)
+ || slopeseg < slopepoint)
+ intersections++;
+ }
+ return (intersections & 1) != 0;
+ }
+
+ /**
+ * Tests whether or not the specified point is inside this polygon.
+ *
+ * @param p the point to test
+ * @return true if the point is inside this polygon
+ * @throws NullPointerException if p is null
+ * @see #contains(double, double)
+ * @since 1.2
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Test if a high-precision rectangle intersects the shape. This is true
+ * if any point in the rectangle is in the shape. This implementation is
+ * precise.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle, treated as point if negative
+ * @param h the height of the rectangle, treated as point if negative
+ * @return true if the rectangle intersects this shape
+ * @since 1.2
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ // First, the obvious bounds checks.
+ if (w <= 0 || h <= 0 || npoints == 0 ||
+ ! getBounds().intersects(x, y, w, h))
+ return false; // Disjoint bounds.
+ if ((x <= bounds.x && x + w >= bounds.x + bounds.width
+ && y <= bounds.y && y + h >= bounds.y + bounds.height)
+ || contains(x, y))
+ return true; // Rectangle contains the polygon, or one point matches.
+ // If any vertex is in the rectangle, the two might intersect.
+ int curx = 0;
+ int cury = 0;
+ for (int i = 0; i < npoints; i++)
+ {
+ curx = xpoints[i];
+ cury = ypoints[i];
+ if (curx >= x && curx < x + w && cury >= y && cury < y + h
+ && contains(curx, cury)) // Boundary check necessary.
+ return true;
+ }
+ // Finally, if at least one of the four bounding lines intersect any
+ // segment of the polygon, return true. Be careful of the semantics of
+ // Shape; coinciding lines do not necessarily return true.
+ for (int i = 0; i < npoints; i++)
+ {
+ int priorx = curx;
+ int priory = cury;
+ curx = xpoints[i];
+ cury = ypoints[i];
+ if (priorx == curx) // Vertical segment.
+ {
+ if (curx < x || curx >= x + w) // Outside rectangle.
+ continue;
+ if ((cury >= y + h && priory <= y)
+ || (cury <= y && priory >= y + h))
+ return true; // Bisects rectangle.
+ continue;
+ }
+ if (priory == cury) // Horizontal segment.
+ {
+ if (cury < y || cury >= y + h) // Outside rectangle.
+ continue;
+ if ((curx >= x + w && priorx <= x)
+ || (curx <= x && priorx >= x + w))
+ return true; // Bisects rectangle.
+ continue;
+ }
+ // Slanted segment.
+ double slope = (double) (cury - priory) / (curx - priorx);
+ double intersect = slope * (x - curx) + cury;
+ if (intersect > y && intersect < y + h) // Intersects left edge.
+ return true;
+ intersect = slope * (x + w - curx) + cury;
+ if (intersect > y && intersect < y + h) // Intersects right edge.
+ return true;
+ intersect = (y - cury) / slope + curx;
+ if (intersect > x && intersect < x + w) // Intersects bottom edge.
+ return true;
+ intersect = (y + h - cury) / slope + cury;
+ if (intersect > x && intersect < x + w) // Intersects top edge.
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Test if a high-precision rectangle intersects the shape. This is true
+ * if any point in the rectangle is in the shape. This implementation is
+ * precise.
+ *
+ * @param r the rectangle
+ * @return true if the rectangle intersects this shape
+ * @throws NullPointerException if r is null
+ * @see #intersects(double, double, double, double)
+ * @since 1.2
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Test if a high-precision rectangle lies completely in the shape. This is
+ * true if all points in the rectangle are in the shape. This implementation
+ * is precise.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle, treated as point if negative
+ * @param h the height of the rectangle, treated as point if negative
+ * @return true if the rectangle is contained in this shape
+ * @since 1.2
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ // First, the obvious bounds checks.
+ if (w <= 0 || h <= 0 || ! contains(x, y)
+ || ! bounds.contains(x, y, w, h))
+ return false;
+ // Now, if any of the four bounding lines intersects a polygon segment,
+ // return false. The previous check had the side effect of setting
+ // the condensed array, which we use. Be careful of the semantics of
+ // Shape; coinciding lines do not necessarily return false.
+ int limit = condensed[0];
+ int curx = condensed[(limit << 1) - 1];
+ int cury = condensed[limit << 1];
+ for (int i = 1; i <= limit; i++)
+ {
+ int priorx = curx;
+ int priory = cury;
+ curx = condensed[(i << 1) - 1];
+ cury = condensed[i << 1];
+ if (curx > x && curx < x + w && cury > y && cury < y + h)
+ return false; // Vertex is in rectangle.
+ if (priorx == curx) // Vertical segment.
+ {
+ if (curx < x || curx > x + w) // Outside rectangle.
+ continue;
+ if ((cury >= y + h && priory <= y)
+ || (cury <= y && priory >= y + h))
+ return false; // Bisects rectangle.
+ continue;
+ }
+ if (priory == cury) // Horizontal segment.
+ {
+ if (cury < y || cury > y + h) // Outside rectangle.
+ continue;
+ if ((curx >= x + w && priorx <= x)
+ || (curx <= x && priorx >= x + w))
+ return false; // Bisects rectangle.
+ continue;
+ }
+ // Slanted segment.
+ double slope = (double) (cury - priory) / (curx - priorx);
+ double intersect = slope * (x - curx) + cury;
+ if (intersect > y && intersect < y + h) // Intersects left edge.
+ return false;
+ intersect = slope * (x + w - curx) + cury;
+ if (intersect > y && intersect < y + h) // Intersects right edge.
+ return false;
+ intersect = (y - cury) / slope + curx;
+ if (intersect > x && intersect < x + w) // Intersects bottom edge.
+ return false;
+ intersect = (y + h - cury) / slope + cury;
+ if (intersect > x && intersect < x + w) // Intersects top edge.
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Test if a high-precision rectangle lies completely in the shape. This is
+ * true if all points in the rectangle are in the shape. This implementation
+ * is precise.
+ *
+ * @param r the rectangle
+ * @return true if the rectangle is contained in this shape
+ * @throws NullPointerException if r is null
+ * @see #contains(double, double, double, double)
+ * @since 1.2
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Return an iterator along the shape boundary. If the optional transform
+ * is provided, the iterator is transformed accordingly. Each call returns
+ * a new object, independent from others in use. This class is not
+ * threadsafe to begin with, so the path iterator is not either.
+ *
+ * @param transform an optional transform to apply to the iterator
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ public PathIterator getPathIterator(final AffineTransform transform)
+ {
+ return new PathIterator()
{
- xpoints[i] += dx;
- xpoints[i] += dy;
- }
-
- calculateBounds();
-}
-
-/*************************************************************************/
-
-/**
- * Adds the specified endpoint to the polygon.
- *
- * @param x The X coordinate of the point to add.
- * @param y The Y coordiante of the point to add.
- */
-public void
-addPoint(int x, int y)
-{
- int newxpoints[] = new int[npoints + 1];
- int newypoints[] = new int[npoints + 1];
-
- System.arraycopy(xpoints, 0, newxpoints, 0, npoints);
- System.arraycopy(ypoints, 0, newypoints, 0, npoints);
-
- newxpoints[npoints] = x;
- newypoints[npoints] = y;
-
- xpoints = newxpoints;
- ypoints = newypoints;
- ++npoints;
-}
-
-/*************************************************************************/
-
-/**
- * Returns the bounding box of this polygon. This is the smallest
- * rectangle with sides parallel to the X axis that will contain this
- * polygon.
- *
- * @return The bounding box for this polygon.
- */
-public Rectangle
-getBounds()
-{
- return(bounds);
-}
-
-/*************************************************************************/
-
-/**
- * Returns the bounding box of this polygon. This is the smallest
- * rectangle with sides parallel to the X axis that will contain this
- * polygon.
- *
- * @return The bounding box for this polygon.
- *
- * @deprecated This method has been replaced by <code>getBounds()</code>.
- */
-public Rectangle
-getBoundingBox()
-{
- return(bounds);
-}
-
-/*************************************************************************/
-
-/**
- * Tests whether or not the specified point is inside this polygon.
- *
- * @param x The X coordinate of the point to test.
- * @param y the Y coordinate of the point to test.
- *
- * @return <code>true</code> if the point is inside this polygon,
- * <code>false</code> otherwise.
- */
-public boolean
-contains(int x, int y)
-{
- // Is inside bounding box.
- if (!bounds.contains(x, y))
- return(false);
-
- int sign = 0;
- for (int i = 0; i < npoints; i ++)
- {
- int nx = xpoints[(i + 1) % npoints] - xpoints[i];
- int ny = ypoints[(i + 1) % npoints] - ypoints[i];
-
- int dx = x - xpoints[i];
- int dy = y - ypoints[i];
-
- int val = (dx*nx) + (dy*nx);
-
- if (sign == 0)
- {
- if (val < 1)
- sign = -1;
- else if (val > 1)
- sign = 1;
- }
-
- if ((val > 1) && (sign < 1))
- return(false);
- if ((val < 1) && (sign > 1))
- return(false);
- }
-
- return(true);
-}
-
-/*************************************************************************/
-
-/**
- * Tests whether or not the specified point is inside this polygon.
- *
- * @param x The X coordinate of the point to test.
- * @param y the Y coordinate of the point to test.
- *
- * @return <code>true</code> if the point is inside this polygon,
- * <code>false</code> otherwise.
- *
- * @deprecated This method has been replaced by <code>contains()</code>.
- */
-public boolean
-inside(int x, int y)
-{
- return(contains(x, y));
-}
-
-} // class Polygon
-
+ /** The current vertex of iteration. */
+ private int vertex;
+
+ public int getWindingRule()
+ {
+ return WIND_EVEN_ODD;
+ }
+
+ public boolean isDone()
+ {
+ return vertex >= npoints;
+ }
+
+ public void next()
+ {
+ vertex++;
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ if (vertex >= npoints)
+ return SEG_CLOSE;
+ coords[0] = xpoints[vertex];
+ coords[1] = ypoints[vertex];
+ if (transform != null)
+ transform.transform(coords, 0, coords, 0, 1);
+ return SEG_LINETO;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ if (vertex >= npoints)
+ return SEG_CLOSE;
+ coords[0] = xpoints[vertex];
+ coords[1] = ypoints[vertex];
+ if (transform != null)
+ transform.transform(coords, 0, coords, 0, 1);
+ return SEG_LINETO;
+ }
+ };
+ }
+
+ /**
+ * Return an iterator along the flattened version of the shape boundary.
+ * Since rectangles are already flat, the flatness parameter is ignored, and
+ * the resulting iterator only has SEG_LINETO and SEG_CLOSE points. If the
+ * optional transform is provided, the iterator is transformed accordingly.
+ * Each call returns a new object, independent from others in use. This
+ * class is not threadsafe to begin with, so the path iterator is not either.
+ *
+ * @param transform an optional transform to apply to the iterator
+ * @param double the maximum distance for deviation from the real boundary
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ public PathIterator getPathIterator(AffineTransform transform,
+ double flatness)
+ {
+ return getPathIterator(transform);
+ }
+
+ /**
+ * Helper for contains, which caches a condensed version of the polygon.
+ * This condenses all colinear points, so that consecutive segments in
+ * the condensed version always have different slope.
+ *
+ * @return true if the condensed polygon has area
+ * @see #condensed
+ * @see #contains(double, double)
+ */
+ private boolean condense()
+ {
+ if (npoints <= 2)
+ return false;
+ if (condensed != null)
+ return condensed[0] > 2;
+ condensed = new int[npoints * 2 + 1];
+ int curx = xpoints[npoints - 1];
+ int cury = ypoints[npoints - 1];
+ double curslope = Double.NaN;
+ int count = 0;
+ outer:
+ for (int i = 0; i < npoints; i++)
+ {
+ int priorx = curx;
+ int priory = cury;
+ double priorslope = curslope;
+ curx = xpoints[i];
+ cury = ypoints[i];
+ while (curx == priorx && cury == priory)
+ {
+ if (++i == npoints)
+ break outer;
+ curx = xpoints[i];
+ cury = ypoints[i];
+ }
+ curslope = (curx == priorx ? Double.POSITIVE_INFINITY
+ : (double) (cury - priory) / (curx - priorx));
+ if (priorslope == curslope)
+ {
+ if (count > 1 && condensed[(count << 1) - 3] == curx
+ && condensed[(count << 1) - 2] == cury)
+ {
+ count--;
+ continue;
+ }
+ }
+ else
+ count++;
+ condensed[(count << 1) - 1] = curx;
+ condensed[count << 1] = cury;
+ }
+ condensed[0] = count;
+ return count > 2;
+ }
+} // class Polygon
diff --git a/java/awt/PrintGraphics.java b/java/awt/PrintGraphics.java
index 3d1ee6326..4a65fcec5 100644
--- a/java/awt/PrintGraphics.java
+++ b/java/awt/PrintGraphics.java
@@ -1,5 +1,5 @@
-/* PrintGraphics.java -- A print graphics context.
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* PrintGraphics.java -- a print graphics context
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,21 +39,19 @@ exception statement from your version. */
package java.awt;
/**
- * This interface allows the originating print job to be obtained.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface allows the originating print job to be obtained.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface PrintGraphics
{
-
-/**
- * Returns the <code>PrintJob</code> that this object is being
- * managed by.
- *
- * @return The print job for this object.
- */
-public abstract PrintJob
-getPrintJob();
-
+ /**
+ * Returns the <code>PrintJob</code> that this object is being
+ * managed by.
+ *
+ * @return the print job for this object
+ */
+ PrintJob getPrintJob();
} // interface PrintGraphics
-
diff --git a/java/awt/Shape.java b/java/awt/Shape.java
index c017aaa6a..8d61c4a9a 100644
--- a/java/awt/Shape.java
+++ b/java/awt/Shape.java
@@ -1,5 +1,5 @@
-/* Shape.java -- Interface for shape abstractions.
- Copyright (C) 1999 Free Software Foundation, Inc.
+/* Shape.java -- the classic Object-Oriented shape interface
+ Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,21 +38,166 @@ exception statement from your version. */
package java.awt;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
/**
- * This interface represents an abstract shape.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- */
+ * This interface represents an abstract shape. The shape is described by
+ * a {@link PathIterator}, and has callbacks for determining bounding box,
+ * where points and rectangles lie in relation to the shape, and tracing
+ * the trajectory.
+ *
+ * <p>A point is inside if it is completely inside, or on the boundary and
+ * adjacent points in the increasing x or y direction are completely inside.
+ * Unclosed shapes are considered as implicitly closed when performing
+ * <code>contains</code> or <code>intersects</code>.
+ *
+ * @author Aaron M. Renn <arenn@urbanophile.com>
+ * @see PathIterator
+ * @see AffineTransform
+ * @see FlatteningPathIterator
+ * @see GeneralPath
+ * @since 1.0
+ * @status updated to 1.4
+ */
public interface Shape
{
+ /**
+ * Returns a <code>Rectange</code> that bounds the shape. There is no
+ * guarantee that this is the minimum bounding box, particularly if
+ * the shape overflows the finite integer range of a bound. Generally,
+ * <code>getBounds2D</code> returns a tighter bound.
+ *
+ * @return the shape's bounding box
+ * @see #getBounds2D()
+ */
+ Rectangle getBounds();
-/**
- * Returns a <code>Rectange</code> that bounds the shape.
- *
- * @return A <code>Rectange</code> that bounds the shape.
- */
-public abstract Rectangle
-getBounds();
+ /**
+ * Returns a high precision bounding box of the shape. There is no guarantee
+ * that this is the minimum bounding box, but at least it never overflows.
+ *
+ * @return the shape's bounding box
+ * @see #getBounds()
+ * @since 1.2
+ */
+ Rectangle2D getBounds2D();
-} // interface Shape
+ /**
+ * Test if the coordinates lie in the shape.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @return true if (x,y) lies inside the shape
+ * @since 1.2
+ */
+ boolean contains(double x, double y);
+
+ /**
+ * Test if the point lie in the shape.
+ *
+ * @param p the high-precision point
+ * @return true if p lies inside the shape
+ * @throws NullPointerException if p is null
+ * @since 1.2
+ */
+ boolean contains(Point2D p);
+
+ /**
+ * Test if a high-precision rectangle intersects the shape. This is true
+ * if any point in the rectangle is in the shape, with the caveat that the
+ * operation may include high probability estimates when the actual
+ * calculation is prohibitively expensive. The {@link Area} class can
+ * be used for more precise answers.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle, undefined results if negative
+ * @param h the height of the rectangle, undefined results if negative
+ * @return true if the rectangle intersects this shape
+ * @see Area
+ * @since 1.2
+ */
+ boolean intersects(double x, double y, double w, double h);
+ /**
+ * Test if a high-precision rectangle intersects the shape. This is true
+ * if any point in the rectangle is in the shape, with the caveat that the
+ * operation may include high probability estimates when the actual
+ * calculation is prohibitively expensive. The {@link Area} class can
+ * be used for more precise answers.
+ *
+ * @param r the rectangle
+ * @return true if the rectangle intersects this shape
+ * @throws NullPointerException if r is null
+ * @see #intersects(double, double, double, double)
+ * @since 1.2
+ */
+ boolean intersects(Rectangle2D r);
+
+ /**
+ * Test if a high-precision rectangle lies completely in the shape. This is
+ * true if all points in the rectangle are in the shape, with the caveat
+ * that the operation may include high probability estimates when the actual
+ * calculation is prohibitively expensive. The {@link Area} class can
+ * be used for more precise answers.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle, undefined results if negative
+ * @param h the height of the rectangle, undefined results if negative
+ * @return true if the rectangle is contained in this shape
+ * @see Area
+ * @since 1.2
+ */
+ boolean contains(double x, double y, double w, double h);
+
+ /**
+ * Test if a high-precision rectangle lies completely in the shape. This is
+ * true if all points in the rectangle are in the shape, with the caveat
+ * that the operation may include high probability estimates when the actual
+ * calculation is prohibitively expensive. The {@link Area} class can
+ * be used for more precise answers.
+ *
+ * @param r the rectangle
+ * @return true if the rectangle is contained in this shape
+ * @throws NullPointerException if r is null
+ * @see #contains(double, double, double, double)
+ * @since 1.2
+ */
+ boolean contains(Rectangle2D r);
+
+ /**
+ * Return an iterator along the shape boundary. If the optional transform
+ * is provided, the iterator is transformed accordingly. Each call returns
+ * a new object, independent from others in use. It is recommended, but
+ * not required, that the Shape isolate iterations from future changes to
+ * the boundary, and document this fact.
+ *
+ * @param transform an optional transform to apply to the iterator
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ PathIterator getPathIterator(AffineTransform transform);
+
+ /**
+ * Return an iterator along the flattened version of the shape boundary.
+ * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE points are returned in the
+ * iterator. The flatness paramter controls how far points are allowed to
+ * differ from the real curve; although a limit on accuracy may cause this
+ * parameter to be enlarged if needed.
+ *
+ * <p>If the optional transform is provided, the iterator is transformed
+ * accordingly. Each call returns a new object, independent from others in
+ * use. It is recommended, but not required, that the Shape isolate
+ * iterations from future changes to the boundary, and document this fact.
+ *
+ * @param transform an optional transform to apply to the iterator
+ * @param double the maximum distance for deviation from the real boundary
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ PathIterator getPathIterator(AffineTransform transform, double flatness);
+} // interface Shape
diff --git a/java/awt/Stroke.java b/java/awt/Stroke.java
new file mode 100644
index 000000000..8b9b7fc77
--- /dev/null
+++ b/java/awt/Stroke.java
@@ -0,0 +1,65 @@
+/* Stroke.java -- a stroked outline of a shape
+ Copyright (C) 2002 Free Software Foundation, Inc.
+
+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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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;
+
+/**
+ * This interface allows a Graphics2D to grab the outline of a shape, as if
+ * stroked by a marking pen of appropriate size and shape. The area inked
+ * by the pen is the area of this stroke. Anything in the graphic which
+ * traces an outline will use this stroke, such as <code>drawLine</code>.
+ * Strokes must be immutable, because the graphics object does not clone
+ * them.
+ *
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @see BasicStroke
+ * @see Graphics2D#setStroke(Stroke)
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface Stroke
+{
+ /**
+ * Returns a shape which outlines the boundary of the given shape, in
+ * effect converting the infinitely thin line into a new shape.
+ *
+ * @param s the shape to stroke
+ * @return the stroked outline shape
+ */
+ Shape createStrokedShape(Shape s);
+} // interface Stroke
diff --git a/java/awt/Transparency.java b/java/awt/Transparency.java
index 6a8aeaece..fc01f5839 100644
--- a/java/awt/Transparency.java
+++ b/java/awt/Transparency.java
@@ -1,4 +1,5 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation
+/* Transparency.java -- common transparency modes in graphics
+ Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,21 +38,30 @@ exception statement from your version. */
package java.awt;
/**
+ * A common transparency mode for layering graphics.
+ *
* @author Warren Levy <warrenl@cygnus.com>
- * @date March 15, 2000.
+ * @since 1.1
+ * @status updated to 1.4
*/
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
public interface Transparency
{
- public static final int OPAQUE = 1;
- public static final int BITMASK = 2;
- public static final int TRANSLUCENT = 3;
+ /** Image data which is completely opaque, for an alpha value of 1.0. */
+ int OPAQUE = 1;
+
+ /**
+ * Image data which is either completely opaque or transparent, for an
+ * exact integer alpha value.
+ */
+ int BITMASK = 2;
+
+ /** Image data which is translucent, for a non-integer alpha value. */
+ int TRANSLUCENT = 3;
- public int getTransparency();
-}
+ /**
+ * Return the transparency type.
+ *
+ * @return One of {@see #OPAQUE}, {@see #BITMASK}, or {@see #TRANSLUCENT}.
+ */
+ int getTransparency();
+} // interface Transparency