[llvm-commits] [llvm-gcc-4.2] r43913 [35/80] - in /llvm-gcc-4.2/trunk: boehm-gc/ boehm-gc/Mac_files/ boehm-gc/cord/ boehm-gc/doc/ boehm-gc/include/ boehm-gc/include/private/ boehm-gc/tests/ libffi/ libffi/include/ libffi/src/ libffi/src/alpha/ libffi/src/arm/ libffi/src/cris/ libffi/src/frv/ libffi/src/ia64/ libffi/src/m32r/ libffi/src/m68k/ libffi/src/mips/ libffi/src/pa/ libffi/src/powerpc/ libffi/src/s390/ libffi/src/sh/ libffi/src/sh64/ libffi/src/sparc/ libffi/src/x86/ libffi/testsuite/ libffi/testsuite/config/ li...
Bill Wendling
isanbard at gmail.com
Thu Nov 8 14:57:11 PST 2007
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/dnd/peer/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/dnd/peer/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/dnd/peer/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/dnd/peer/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.dnd.peer package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.dnd.peer</title></head>
+
+<body>
+<p>Interfaces for using native interface components.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/doc-files/capjoin.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/doc-files/capjoin.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/doc-files/capjoin.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* AWTEventListener.java -- listen for all events in the AWT system
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Toolkit;
+import java.util.EventListener;
+
+/**
+ * This listener is for classes that need to listen to all events in the AWT
+ * system. In general, this should not be used except for classes like
+ * javax.accessibility or by event recorders.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see AWTEvent
+ * @see Toolkit#addAWTEventListener(AWTEventListener, long)
+ * @see Toolkit#removeAWTEventListener(AWTEventListener)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface AWTEventListener extends EventListener
+{
+ /**
+ * This method is called when any event in the AWT system is dispatched.
+ *
+ * @param event the AWTEvent that was dispatched
+ */
+ void eventDispatched(AWTEvent event);
+} // interface AWTEventListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListenerProxy.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListenerProxy.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListenerProxy.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AWTEventListenerProxy.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,95 @@
+/* AWTEventListenerProxy.java -- wrapper/filter for AWTEventListener
+ Copyright (C) 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Toolkit;
+import java.util.EventListenerProxy;
+
+/**
+ * This class allows adding an AWTEventListener which only pays attention to
+ * a specific event mask.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see Toolkit
+ * @see EventListenerProxy
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public class AWTEventListenerProxy extends EventListenerProxy
+ implements AWTEventListener
+{
+ /** The event mask. */
+ private final long mask;
+
+ /**
+ * Construct an AWT Event Listener which only listens to events in the given
+ * mask, passing the work on to the real listener.
+ *
+ * @param eventMask the mask of events to listen to
+ * @param listener the wrapped listener
+ */
+ public AWTEventListenerProxy(long eventMask, AWTEventListener listener)
+ {
+ super(listener);
+ mask = eventMask;
+ }
+
+ /**
+ * Forwards events on to the delegate.
+ *
+ * @param event the to forward to the delagate listener
+ *
+ * @throws NullPointerException if the delegate this was created with is null
+ */
+ public void eventDispatched(AWTEvent event)
+ {
+ ((AWTEventListener) getListener()).eventDispatched(event);
+ }
+
+ /**
+ * This returns the event mask associated with this listener.
+ *
+ * @return the event mask
+ */
+ public long getEventMask()
+ {
+ return mask;
+ }
+} // class AWTEventListenerProxy
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,226 @@
+/* ActionEvent.java -- an action has been triggered
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.EventQueue;
+
+/**
+ * This event is generated when an action on a component (such as a
+ * button press) occurs.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ActionListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class ActionEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -7671078796273832149L;
+
+ /** Bit mask indicating the shift key was pressed. */
+ public static final int SHIFT_MASK = InputEvent.SHIFT_MASK;
+
+ /** Bit mask indicating the control key was pressed. */
+ public static final int CTRL_MASK = InputEvent.CTRL_MASK;
+
+ /** Bit mask indicating the that meta key was pressed. */
+ public static final int META_MASK = InputEvent.META_MASK;
+
+ /** Bit mask indicating that the alt key was pressed. */
+ public static final int ALT_MASK = InputEvent.ALT_MASK;
+
+ /** The first id number in the range of action id's. */
+ public static final int ACTION_FIRST = 1001;
+
+ /** The last id number in the range of action id's. */
+ public static final int ACTION_LAST = 1001;
+
+ /** An event id indicating that an action has occurred. */
+ public static final int ACTION_PERFORMED = 1001;
+
+ /**
+ * A nonlocalized string that gives more specific details of the event cause.
+ *
+ * @see #getActionCommand()
+ * @serial the command for this event
+ */
+ private final String actionCommand;
+
+ /**
+ * The bitmask of the modifiers that were pressed during the action.
+ *
+ * @see #getModifiers()
+ * @serial modifiers for this event
+ */
+ private final int modifiers;
+
+ /**
+ * The timestamp of this event; usually the same as the underlying input
+ * event.
+ *
+ * @see #getWhen()
+ * @serial the timestamp of the event
+ * @since 1.4
+ */
+ private final long when;
+
+ /**
+ * Initializes a new instance of <code>ActionEvent</code> with the
+ * specified source, id, and command. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the event source
+ * @param id the event id
+ * @param command the command string for this action
+ * @throws IllegalArgumentException if source is null
+ */
+ public ActionEvent(Object source, int id, String command)
+ {
+ this(source, id, command, EventQueue.getMostRecentEventTime(), 0);
+ }
+
+ /**
+ * Initializes a new instance of <code>ActionEvent</code> with the
+ * specified source, id, command, and modifiers. Note that an invalid id
+ * leads to unspecified results.
+ *
+ * @param source the event source
+ * @param id the event id
+ * @param command the command string for this action
+ * @param modifiers the bitwise or of modifier keys down during the action
+ * @throws IllegalArgumentException if source is null
+ */
+ public ActionEvent(Object source, int id, String command, int modifiers)
+ {
+ this(source, id, command, EventQueue.getMostRecentEventTime(), modifiers);
+ }
+
+ /**
+ * Initializes a new instance of <code>ActionEvent</code> with the
+ * specified source, id, command, and modifiers, and timestamp. Note that
+ * an invalid id leads to unspecified results.
+ *
+ * @param source the event source
+ * @param id the event id
+ * @param command the command string for this action
+ * @param when the timestamp of the event
+ * @param modifiers the bitwise or of modifier keys down during the action
+ * @throws IllegalArgumentException if source is null
+ * @since 1.4
+ */
+ public ActionEvent(Object source, int id, String command, long when,
+ int modifiers)
+ {
+ super(source, id);
+ actionCommand = command;
+ this.when = when;
+ this.modifiers = modifiers;
+ }
+
+ /**
+ * Returns the command string associated with this action.
+ *
+ * @return the command string associated with this action
+ */
+ public String getActionCommand()
+ {
+ return actionCommand;
+ }
+
+ /**
+ * Gets the timestamp of when this action took place. Usually, this
+ * corresponds to the timestamp of the underlying InputEvent.
+ *
+ * @return the timestamp of this action
+ * @since 1.4
+ */
+ public long getWhen()
+ {
+ return when;
+ }
+
+ /**
+ * Returns the keys held down during the action. This value will be a
+ * combination of the bit mask constants defined in this class, or 0 if no
+ * modifiers were pressed.
+ *
+ * @return the modifier bits
+ */
+ public int getModifiers()
+ {
+ return modifiers;
+ }
+
+ /**
+ * Returns a string that identifies the action event. This is in the format
+ * <code>"ACTION_PERFORMED,cmd=" + getActionCommand() + ",when=" + getWhen()
+ * + ",modifiers=" + <modifier string></code>, where the modifier
+ * string is in the order "Meta", "Ctrl", "Alt", "Shift", "Alt Graph", and
+ * "Button1", separated by '+', according to the bits set in getModifiers().
+ *
+ * @return a string identifying the event
+ */
+ public String paramString()
+ {
+ StringBuffer s = new StringBuffer(id == ACTION_PERFORMED
+ ? "ACTION_PERFORMED,cmd="
+ : "unknown type,cmd=");
+ s.append(actionCommand).append(",when=").append(when).append(",modifiers");
+ int len = s.length();
+ s.setLength(len + 1);
+ if ((modifiers & META_MASK) != 0)
+ s.append("+Meta");
+ if ((modifiers & CTRL_MASK) != 0)
+ s.append("+Ctrl");
+ if ((modifiers & ALT_MASK) != 0)
+ s.append("+Alt");
+ if ((modifiers & SHIFT_MASK) != 0)
+ s.append("+Shift");
+ if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0)
+ s.append("+Alt Graph");
+ if ((modifiers & InputEvent.BUTTON1_MASK) != 0)
+ s.append("+Button1");
+ s.setCharAt(len, '=');
+ return s.toString();
+ }
+} // class ActionEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ActionListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,59 @@
+/* ActionListener.java -- listens for action events
+ Copyright (C) 1999, 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that listen for action events.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ActionEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface ActionListener extends EventListener
+{
+ /**
+ * This method is invoked when an action occurs.
+ *
+ * @param event the <code>ActionEvent</code> that occurred
+ */
+ void actionPerformed(ActionEvent event);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,222 @@
+/* AdjustmentEvent.java -- an adjustable value was changed
+ Copyright (C) 1999, 2002, 2004, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Adjustable;
+
+/**
+ * This class represents an event that is generated when an adjustable
+ * value is changed.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see Adjustable
+ * @see AdjustmentListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class AdjustmentEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 5700290645205279921L;
+
+ /** This is the first id in the range of ids used by adjustment events. */
+ public static final int ADJUSTMENT_FIRST = 601;
+
+ /** This is the last id in the range of ids used by adjustment events. */
+ public static final int ADJUSTMENT_LAST = 601;
+
+ /** This is the id indicating an adjustment value changed. */
+ public static final int ADJUSTMENT_VALUE_CHANGED = 601;
+
+ /** Adjustment type for unit increments. */
+ public static final int UNIT_INCREMENT = 1;
+
+ /** Adjustment type for unit decrements. */
+ public static final int UNIT_DECREMENT = 2;
+
+ /** Adjustment type for block decrements. */
+ public static final int BLOCK_DECREMENT = 3;
+
+ /** Adjustment type for block increments. */
+ public static final int BLOCK_INCREMENT = 4;
+
+ /** Adjustment type for tracking adjustments. */
+ public static final int TRACK = 5;
+
+ /**
+ * The adjustable object that caused the event.
+ *
+ * @see #getAdjustable()
+ * @serial the cause
+ */
+ private final Adjustable adjustable;
+
+ /**
+ * The type of adjustment, one of {@link #UNIT_INCREMENT},
+ * {@link #UNIT_DECREMENT}, {@link #BLOCK_INCREMENT},
+ * {@link #BLOCK_DECREMENT}, or {@link #TRACK}.
+ *
+ * @see #getAdjustmentType()
+ * @serial the adjustment type
+ */
+ private final int adjustmentType;
+
+ /**
+ * The new value of the adjustable; it should be in the range of the
+ * adjustable cause.
+ *
+ * @see #getValue()
+ * @serial the adjustment value
+ */
+ private final int value;
+
+ /**
+ * True if this is in a series of multiple adjustment events.
+ *
+ * @see #getValueIsAdjusting()
+ * @serial true if this is not the last adjustment
+ * @since 1.4
+ */
+ private final boolean isAdjusting;
+
+ /**
+ * Initializes an instance of <code>AdjustmentEvent</code> with the
+ * specified source, id, type, and value. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param type the event type, one of the constants of this class
+ * @param value the value of the adjustment
+ * @throws IllegalArgumentException if source is null
+ */
+ public AdjustmentEvent(Adjustable source, int id, int type, int value)
+ {
+ this(source, id, type, value, false);
+ }
+
+ /**
+ * Initializes an instance of <code>AdjustmentEvent</code> with the
+ * specified source, id, type, and value. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param type the event type, one of the constants of this class
+ * @param value the value of the adjustment
+ * @param isAdjusting if this event is in a chain of adjustments
+ * @throws IllegalArgumentException if source is null
+ * @since 1.4
+ */
+ public AdjustmentEvent(Adjustable source, int id, int type, int value,
+ boolean isAdjusting)
+ {
+ super(source, id);
+ this.adjustmentType = type;
+ this.value = value;
+ adjustable = source;
+ this.isAdjusting = isAdjusting;
+ }
+
+ /**
+ * This method returns the source of the event as an <code>Adjustable</code>.
+ *
+ * @return the <code>Adjustable</code> source of the event
+ */
+ public Adjustable getAdjustable()
+ {
+ return adjustable;
+ }
+
+ /**
+ * Returns the new value of the adjustable object.
+ *
+ * @return the value of the event
+ */
+ public int getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Returns the type of the event, which will be one of
+ * {@link #UNIT_INCREMENT}, {@link #UNIT_DECREMENT},
+ * {@link #BLOCK_INCREMENT}, {@link #BLOCK_DECREMENT}, or {@link #TRACK}.
+ *
+ * @return the type of the event
+ */
+ public int getAdjustmentType()
+ {
+ return adjustmentType;
+ }
+
+ /**
+ * Test if this event is part of a sequence of multiple adjustements.
+ *
+ * @return true if this is not the last adjustment
+ * @since 1.4
+ */
+ public boolean getValueIsAdjusting()
+ {
+ return isAdjusting;
+ }
+
+ /**
+ * Returns a string that describes the event. This is in the format
+ * <code>"ADJUSTMENT_VALUE_CHANGED,adjType=" + <type> + ",value="
+ * + getValue() + ",isAdjusting=" + getValueIsAdjusting()</code>, where
+ * type is the name of the constant returned by getAdjustmentType().
+ *
+ * @return a string that describes the event
+ */
+ public String paramString()
+ {
+ return (id == ADJUSTMENT_VALUE_CHANGED
+ ? "ADJUSTMENT_VALUE_CHANGED,adjType=" : "unknown type,adjType=")
+ + (adjustmentType == UNIT_INCREMENT ? "UNIT_INCREMENT,value="
+ : adjustmentType == UNIT_DECREMENT ? "UNIT_DECREMENT,value="
+ : adjustmentType == BLOCK_INCREMENT ? "BLOCK_INCREMENT,value="
+ : adjustmentType == BLOCK_DECREMENT ? "BLOCK_DECREMENT,value="
+ : adjustmentType == TRACK ? "TRACK,value=" : "unknown type,value=")
+ + value + ",isAdjusting=" + isAdjusting;
+ }
+} // class AdjustmentEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/AdjustmentListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,58 @@
+/* AdjustmentListener.java -- listen for adjustment events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * Interface for classes that listen for adjustment events.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface AdjustmentListener extends EventListener
+{
+ /**
+ * This method is called when an adjustable value changes.
+ *
+ * @param event the <code>AdjustmentEvent</code> that occurred
+ */
+ void adjustmentValueChanged(AdjustmentEvent event);
+} // interface AdjustmentListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,97 @@
+/* ComponentAdapter.java -- convenience class for writing component listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>ComponentListener</code> and implements
+ * all methods with empty bodies. This allows a listener interested in
+ * implementing only a subset of the <code>ComponentListener</code>
+ * interface to extend this class and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ComponentEvent
+ * @see ComponentListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class ComponentAdapter implements ComponentListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public ComponentAdapter()
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentResized(ComponentEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentMoved(ComponentEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentShown(ComponentEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentHidden(ComponentEvent event)
+ {
+ }
+} // class ComponentAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,137 @@
+/* ComponentEvent.java -- notification of events for components
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Component;
+
+/**
+ * This class is for events generated when a component is moved, resized,
+ * hidden, or shown. These events normally do not need to be handled by the
+ * application, since the AWT system automatically takes care of them. This
+ * is also the superclass for other events on components, but
+ * ComponentListeners ignore such subclasses.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ComponentAdapter
+ * @see ComponentListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class ComponentEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 8101406823902992965L;
+
+ /** This is the first id in the range of ids used by this class. */
+ public static final int COMPONENT_FIRST = 100;
+
+ /** This is the last id in the range of ids used by this class. */
+ public static final int COMPONENT_LAST = 103;
+
+ /** This id indicates that a component was moved. */
+ public static final int COMPONENT_MOVED = 100;
+
+ /** This id indicates that a component was resized. */
+ public static final int COMPONENT_RESIZED = 101;
+
+ /** This id indicates that a component was shown. */
+ public static final int COMPONENT_SHOWN = 102;
+
+ /** This id indicates that a component was hidden. */
+ public static final int COMPONENT_HIDDEN = 103;
+
+ /**
+ * Initializes a new instance of <code>ComponentEvent</code> with the
+ * specified source and id. Note that an invalid id leads to unspecified
+ * results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @throws IllegalArgumentException if source is null
+ */
+ public ComponentEvent(Component source, int id)
+ {
+ super(source, id);
+ }
+
+ /**
+ * This method returns the event source as a <code>Component</code>. If the
+ * source has subsequently been modified to a non-Component, this returns
+ * null.
+ *
+ * @return the event source as a <code>Component</code>, or null
+ */
+ public Component getComponent()
+ {
+ return source instanceof Component ? (Component) source : null;
+ }
+
+ /**
+ * This method returns a string identifying this event. This is the field
+ * name of the id type, and for COMPONENT_MOVED or COMPONENT_RESIZED, the
+ * new bounding box of the component.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ // Unlike Sun, we don't throw NullPointerException or ClassCastException
+ // when source was illegally changed.
+ switch (id)
+ {
+ case COMPONENT_MOVED:
+ return "COMPONENT_MOVED "
+ + (source instanceof Component
+ ? ((Component) source).getBounds() : (Object) "");
+ case COMPONENT_RESIZED:
+ return "COMPONENT_RESIZED "
+ + (source instanceof Component
+ ? ((Component) source).getBounds() : (Object) "");
+ case COMPONENT_SHOWN:
+ return "COMPONENT_SHOWN";
+ case COMPONENT_HIDDEN:
+ return "COMPONENT_HIDDEN";
+ default:
+ return "unknown type";
+ }
+ }
+} // class ComponentEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ComponentListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,84 @@
+/* ComponentListener.java -- receive all events for a component
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that receive all events from a component.
+ * Normally it is not necessary to process these events since the AWT
+ * handles them internally, taking all appropriate actions. To watch a subset
+ * of these events, use a ComponentAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ComponentAdapter
+ * @see ComponentEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface ComponentListener extends EventListener
+{
+ /**
+ * This method is called when the component is resized.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the resize
+ */
+ void componentResized(ComponentEvent event);
+
+ /**
+ * This method is called when the component is moved.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the move
+ */
+ void componentMoved(ComponentEvent event);
+
+ /**
+ * This method is called when the component is made visible.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ void componentShown(ComponentEvent event);
+
+ /**
+ * This method is called when the component is hidden.
+ *
+ * @param event the <code>ComponentEvent</code> indicating the visibility
+ */
+ void componentHidden(ComponentEvent event);
+} // interface ComponentListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,79 @@
+/* ContainerAdapter.java -- convenience class for writing container listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>ContainerListener</code> and implements
+ * all methods with empty bodies. This allows a listener interested in
+ * implementing only a subset of the <code>ContainerListener</code>
+ * interface to extend this class and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ContainerEvent
+ * @see ContainerListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class ContainerAdapter implements ContainerListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public ContainerAdapter()
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentAdded(ContainerEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void componentRemoved(ContainerEvent event)
+ {
+ }
+} // class ContainerAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,135 @@
+/* ContainerEvent.java -- components added/removed from a container
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.Component;
+import java.awt.Container;
+
+/**
+ * This event is generated when a component is added or removed from a
+ * container. Applications do not ordinarily need to handle these events
+ * since the AWT system handles them internally.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ContainerAdapter
+ * @see ContainerListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class ContainerEvent extends ComponentEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -4114942250539772041L;
+
+ /** This is the first id in the id range used by this class. */
+ public static final int CONTAINER_FIRST = 300;
+
+ /** This is the last id in the id range used by this class. */
+ public static final int CONTAINER_LAST = 301;
+
+ /** This id indicates a component was added to the container. */
+ public static final int COMPONENT_ADDED = 300;
+
+ /** This id indicates a component was removed from the container. */
+ public static final int COMPONENT_REMOVED = 301;
+
+ /**
+ * The non-null child component that was added or removed.
+ *
+ * @serial the child component that changed
+ */
+ private final Component child;
+
+ /**
+ * Initializes a new instance of <code>ContainerEvent</code> with the
+ * specified source and id. Additionally, the affected child component
+ * is also passed as a parameter. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source container of the event
+ * @param id the event id
+ * @param child the child component affected by this event
+ * @throws IllegalArgumentException if source is null
+ */
+ public ContainerEvent(Component source, int id, Component child)
+ {
+ super(source, id);
+ this.child = child;
+ }
+
+ /**
+ * Returns the source of this event as a <code>Container</code>.
+ *
+ * @return the source of the event
+ * @throws ClassCastException if the source is changed to a non-Container
+ */
+ public Container getContainer()
+ {
+ return (Container) source;
+ }
+
+ /**
+ * This method returns the child object that was added or removed from
+ * the container.
+ *
+ * @return the child object added or removed
+ */
+ public Component getChild()
+ {
+ return child;
+ }
+
+ /**
+ * This method returns a string identifying this event. It is formatted as:
+ * <code>(getID() == COMPONENT_ADDED ? "COMPONENT_ADDED"
+ * : "COMPONENT_REMOVED") + ",child=" + getChild().getName()</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ // Unlike Sun, we don't throw NullPointerException if child is illegally
+ // null.
+ return (id == COMPONENT_ADDED ? "COMPONENT_ADDED,child="
+ : id == COMPONENT_REMOVED ? "COMPONENT_REMOVED,child="
+ : "unknown type,child=") + (child == null ? "" : child.getName());
+ }
+} // class ContainerEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ContainerListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* ContainerListener.java -- listen for container events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to listen for all events from
+ * container objects. This is normally not necessary since the AWT system
+ * listens for and processes these events. To watch a subset of these events,
+ * use a ContainerAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ContainerAdapter
+ * @see ContainerEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface ContainerListener extends EventListener
+{
+ /**
+ * This method is called when a component is added to the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component addition
+ */
+ void componentAdded(ContainerEvent event);
+
+ /**
+ * This method is called when a component is removed from the container.
+ *
+ * @param event the <code>ContainerEvent</code> indicating component removal
+ */
+ void componentRemoved(ContainerEvent event);
+} // interface ContainerListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,79 @@
+/* FocusAdapter.java -- convenience class for writing focus listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>FocusListener</code> and implements all
+ * methods with empty bodies. This allows a listener interested in
+ * implementing only a subset of the <code>FocusListener</code> interface to
+ * extend this class and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see FocusEvent
+ * @see FocusListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class FocusAdapter implements FocusListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public FocusAdapter()
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void focusGained(FocusEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void focusLost(FocusEvent event)
+ {
+ }
+} // class FocusAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,181 @@
+/* FocusEvent.java -- generated for a focus change
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.Component;
+
+/**
+ * This class represents an event generated when a focus change occurs for a
+ * component. There are both temporary changes, such as when focus is stolen
+ * during a sroll then returned, and permanent changes, such as when the user
+ * TABs through focusable components.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see FocusAdapter
+ * @see FocusListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class FocusEvent extends ComponentEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 523753786457416396L;
+
+ /** This is the first id in the range of ids used by this class. */
+ public static final int FOCUS_FIRST = 1004;
+
+ /** This is the last id in the range of ids used by this class. */
+ public static final int FOCUS_LAST = 1005;
+
+ /** This is the event id for a focus gained event. */
+ public static final int FOCUS_GAINED = 1004;
+
+ /** This is the event id for a focus lost event. */
+ public static final int FOCUS_LOST = 1005;
+
+ /**
+ * Indicates whether or not the focus change is temporary.
+ *
+ * @see #isTemporary()
+ * @serial true if the focus change is temporary
+ */
+ private final boolean temporary;
+
+ /**
+ * The other component which is giving up or stealing focus from this
+ * component, if known.
+ *
+ * @see #getOppositeComponent()
+ * @serial the component with the opposite focus event, or null
+ * @since 1.4
+ */
+ private final Component opposite;
+
+ /**
+ * Initializes a new instance of <code>FocusEvent</code> with the
+ * specified source, id, temporary status, and opposite counterpart. Note
+ * that an invalid id leads to unspecified results.
+ *
+ * @param source the component that is gaining or losing focus
+ * @param id the event id
+ * @param temporary true if the focus change is temporary
+ * @param opposite the component receiving the opposite focus event, or null
+ * @throws IllegalArgumentException if source is null
+ */
+ public FocusEvent(Component source, int id, boolean temporary,
+ Component opposite)
+ {
+ super(source, id);
+ this.temporary = temporary;
+ this.opposite = opposite;
+ }
+
+ /**
+ * Initializes a new instance of <code>FocusEvent</code> with the
+ * specified source, id, and temporary status. Note that an invalid id
+ * leads to unspecified results.
+ *
+ * @param source the component that is gaining or losing focus
+ * @param id the event id
+ * @param temporary true if the focus change is temporary
+ * @throws IllegalArgumentException if source is null
+ */
+ public FocusEvent(Component source, int id, boolean temporary)
+ {
+ this(source, id, temporary, null);
+ }
+
+ /**
+ * Initializes a new instance of <code>FocusEvent</code> with the
+ * specified source and id. Note that an invalid id leads to unspecified
+ * results.
+ *
+ * @param source the component that is gaining or losing focus
+ * @param id the event id
+ * @throws IllegalArgumentException if source is null
+ */
+ public FocusEvent(Component source, int id)
+ {
+ this(source, id, false, null);
+ }
+
+ /**
+ * This method tests whether or not the focus change is temporary or
+ * permanent.
+ *
+ * @return true if the focus change is temporary
+ */
+ public boolean isTemporary()
+ {
+ return temporary;
+ }
+
+ /**
+ * Returns the component which received the opposite focus event. If this
+ * component gained focus, the opposite lost focus; likewise if this
+ * component is giving up focus, the opposite is gaining it. If this
+ * information is unknown, perhaps because the opposite is a native
+ * application, this returns null.
+ *
+ * @return the component with the focus opposite, or null
+ * @since 1.4
+ */
+ public Component getOppositeComponent()
+ {
+ return opposite;
+ }
+
+ /**
+ * Returns a string identifying this event. This is formatted as:
+ * <code>(getID() == FOCUS_GAINED ? "FOCUS_GAINED" : "FOCUS_LOST")
+ * + (isTemporary() ? ",temporary," : ",permanent,") + "opposite="
+ * + getOppositeComponent()</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return (id == FOCUS_GAINED ? "FOCUS_GAINED"
+ : id == FOCUS_LOST ? "FOCUS_LOST" : "unknown type")
+ + (temporary ? ",temporary,opposite=" : ",permanent,opposite=")
+ + opposite;
+ }
+} // class FocusEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/FocusListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,69 @@
+/* FocusListener.java -- listen for focus changes
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to be notified of changes of
+ * keyboard focus for a component. To watch a subset of these events, use a
+ * FocusAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see FocusAdapter
+ * @see FocusEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface FocusListener extends EventListener
+{
+ /**
+ * This method is called when a component gains the keyboard focus.
+ *
+ * @param event the <code>FocusEvent</code> indicating that focus was gained
+ */
+ void focusGained(FocusEvent event);
+
+ /**
+ * This method is invoked when a component loses the keyboard focus.
+ *
+ * @param event the <code>FocusEvent</code> indicating that focus was lost
+ */
+ void focusLost(FocusEvent event);
+} // interface FocusListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,78 @@
+/* HierarchyBoundsAdapter.java -- convenience class for writing listeners
+ Copyright (C) 2000, 2002 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.event;
+
+/**
+ * This class implements <code>HierarchyBoundsListener</code> and implements
+ * all methods with empty bodies. This allows a listener interested in
+ * implementing only a subset of the <code>HierarchyBoundsListener</code>
+ * interface to extend this class and override only the desired methods.
+ *
+ * @author Bryce McKinlay
+ * @see HierarchyBoundsListener
+ * @see HierarchyEvent
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public abstract class HierarchyBoundsAdapter implements HierarchyBoundsListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public HierarchyBoundsAdapter()
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void ancestorMoved(HierarchyEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void ancestorResized(HierarchyEvent event)
+ {
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyBoundsListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* HierarchyBoundsListener.java -- listens to bounds changes of parents
+ Copyright (C) 2000, 2002 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This listens for changes in an ancestors size or location. Normally it is
+ * not necessary to process these events since the AWT handles them
+ * internally, taking all appropriate actions. To watch a subset of these
+ * events, use a HierarchyBoundsAdapter.
+ *
+ * @author Bryce McKinlay
+ * @see HierarchyBoundsAdapter
+ * @see HierarchyEvent
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public interface HierarchyBoundsListener extends EventListener
+{
+ /**
+ * Called when an ancestor component of the source is moved.
+ *
+ * @param e the event describing the ancestor's motion
+ */
+ void ancestorMoved(HierarchyEvent e);
+
+ /**
+ * Called when an ancestor component is resized.
+ *
+ * @param e the event describing the ancestor's resizing
+ */
+ void ancestorResized(HierarchyEvent e);
+} // interface HierarchyBoundsListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,253 @@
+/* HierarchyEvent.java -- generated for a change in hierarchy
+ Copyright (C) 2000, 2002 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Component;
+import java.awt.Container;
+
+/**
+ * This class represents an event generated for an ancestor component which
+ * may affect this component. These events normally do not need to be handled
+ * by the application, since the AWT system automatically takes care of them.
+ *
+ * <p>There are two types of hierarchy events. The first type is handled by
+ * HierarchyListener, and includes addition or removal of an ancestor, or
+ * an ancestor changing its on-screen status (visible and/or displayble). The
+ * second type is handled by HierarchyBoundsListener, and includes resizing
+ * or moving of an ancestor.
+ *
+ * @author Bryce McKinlay
+ * @see HierarchyListener
+ * @see HierarchyBoundsAdapter
+ * @see HierarchyBoundsListener
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public class HierarchyEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.3+.
+ */
+ private static final long serialVersionUID = -5337576970038043990L;
+
+ /** This is the first id in the range of ids used by this class. */
+ public static final int HIERARCHY_FIRST = 1400;
+
+ /** This id indicates that the hierarchy tree changed. */
+ public static final int HIERARCHY_CHANGED = 1400;
+
+ /** This id indicates that an ancestor was moved. */
+ public static final int ANCESTOR_MOVED = 1401;
+
+ /** This id indicates that an ancestor was resized. */
+ public static final int ANCESTOR_RESIZED = 1402;
+
+ /** This is the last id in the range of ids used by this class. */
+ public static final int HIERARCHY_LAST = 1402;
+
+ /** This indicates that the HIERARCHY_CHANGED is a changed parent. */
+ public static final int PARENT_CHANGED = 1;
+
+ /**
+ * This indicates that the HIERARCHY_CHANGED is caused by a change in
+ * displayability.
+ *
+ * @see Component#isDisplayable()
+ * @see Component#addNotify()
+ * @see Component#removeNotify()
+ */
+ public static final int DISPLAYABILITY_CHANGED = 2;
+
+ /**
+ * This indicates that the HIERARCHY_CHANGED is a changed visibility.
+ *
+ * @see Component#isShowing()
+ * @see Component#addNotify()
+ * @see Component#removeNotify()
+ * @see Component#show()
+ * @see Component#hide()
+ */
+ public static final int SHOWING_CHANGED = 4;
+
+ /**
+ * The component at the top of the changed hierarchy.
+ *
+ * @serial the top component changed
+ */
+ private final Component changed;
+
+ /**
+ * The parent of this component, either before or after the change depending
+ * on the type of change.
+ *
+ * @serial the parent component changed
+ */
+ private final Container changedParent;
+
+ /**
+ * The bitmask of HIERARCHY_CHANGED event types.
+ *
+ * @serial the change flags
+ */
+ private final long changeFlags;
+
+ /**
+ * Initializes a new instance of <code>HierarchyEvent</code> with the
+ * specified parameters. Note that an invalid id leads to unspecified
+ * results.
+ *
+ * @param source the component whose hierarchy changed
+ * @param id the event id
+ * @param changed the top component in the tree of changed hierarchy
+ * @param changedParent the updated parent of this object
+ * @throws IllegalArgumentException if source is null
+ */
+ public HierarchyEvent(Component source, int id, Component changed,
+ Container changedParent)
+ {
+ this(source, id, changed, changedParent, 0);
+ }
+
+ /**
+ * Initializes a new instance of <code>HierarchyEvent</code> with the
+ * specified parameters. Note that an invalid id leads to unspecified
+ * results.
+ *
+ * @param source the component whose hierarchy changed
+ * @param id the event id
+ * @param changed the top component in the tree of changed hierarchy
+ * @param changedParent the updated parent of this object
+ * @param changeFlags the bitmask of specific HIERARCHY_CHANGED events
+ * @throws IllegalArgumentException if source is null
+ */
+ public HierarchyEvent(Component source, int id, Component changed,
+ Container changedParent, long changeFlags)
+ {
+ super(source, id);
+ this.changed = changed;
+ this.changedParent = changedParent;
+ this.changeFlags = changeFlags;
+ }
+
+ /**
+ * This method returns the event source as a <code>Component</code>. If the
+ * source has subsequently been modified to a non-Component, this returns
+ * null.
+ *
+ * @return the event source as a <code>Component</code>, or null
+ */
+ public Component getComponent()
+ {
+ return source instanceof Component ? (Component) source : null;
+ }
+
+ /**
+ * Returns the component at the top of the hierarchy which changed.
+ *
+ * @return the top changed component
+ */
+ public Component getChanged()
+ {
+ return changed;
+ }
+
+ /**
+ * Returns the parent of the component listed in <code>getChanged()</code>.
+ * If the cause of this event was <code>Container.add</code>, this is the
+ * new parent; if the cause was <code>Container.remove</code>, this is the
+ * old parent; otherwise it is the unchanged parent.
+ *
+ * @return the parent container of the changed component
+ */
+ public Container getChangedParent()
+ {
+ return changedParent;
+ }
+
+ /**
+ * If this is a HIERARCHY_CHANGED event, this returns a bitmask of the
+ * types of changes that took place.
+ *
+ * @return the bitwise or of hierarchy change types, or 0
+ * @see #PARENT_CHANGED
+ * @see #DISPLAYABILITY_CHANGED
+ * @see #SHOWING_CHANGED
+ */
+ public long getChangeFlags()
+ {
+ return changeFlags;
+ }
+
+ /**
+ * This method returns a string identifying this event. This is the field
+ * name of the id type, followed by a parenthesized listing of the changed
+ * component and its parent container. In addition, if the type is
+ * HIERARCHY_CHANGED, the flags preceed the changed component, in the
+ * order PARENT_CHANGED, DISPLAYABILITY_CHANGED, and SHOWING_CHANGED.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ StringBuffer r = new StringBuffer();
+ switch (id)
+ {
+ case HIERARCHY_CHANGED:
+ r.append("HIERARCHY_CHANGED (");
+ if ((changeFlags & PARENT_CHANGED) != 0)
+ r.append("PARENT_CHANGED,");
+ if ((changeFlags & DISPLAYABILITY_CHANGED) != 0)
+ r.append("DISPLAYABILITY_CHANGED,");
+ if ((changeFlags & SHOWING_CHANGED) != 0)
+ r.append("SHOWING_CHANGED,");
+ break;
+ case ANCESTOR_MOVED:
+ r.append("ANCESTOR_MOVED (");
+ break;
+ case ANCESTOR_RESIZED:
+ r.append("ANCESTOR_RESIZED (");
+ break;
+ default:
+ return "unknown type";
+ }
+ r.append(changed).append(',').append(changedParent).append(')');
+ return r.toString();
+ }
+} // class HierarchyEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/HierarchyListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,62 @@
+/* HierarchyListener.java -- listens to changes in the component hierarchy
+ Copyright (C) 2000, 2002 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This listens for changes in the hierarchy tree of components. Normally it is
+ * not necessary to process these events since the AWT handles them
+ * internally, taking all appropriate actions.
+ *
+ * @author Bryce McKinlay
+ * @see HierarchyEvent
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public interface HierarchyListener extends EventListener
+{
+ /**
+ * Called when the hierarchy of this component changes. Use
+ * <code>getChangeFlags()</code> on the event to see what exactly changed.
+ *
+ * @param e the event describing the change
+ */
+ void hierarchyChanged(HierarchyEvent e);
+} // interface HierarchyListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,398 @@
+/* InputEvent.java -- common superclass of component input events
+ Copyright (C) 1999, 2002, 2004, 2005 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., 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.event;
+
+import gnu.java.awt.EventModifier;
+
+import java.awt.Component;
+
+/**
+ * This is the common superclass for all component input classes. These are
+ * passed to listeners before the component, so that listeners can consume
+ * the event before it does its default behavior.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see KeyEvent
+ * @see KeyAdapter
+ * @see MouseEvent
+ * @see MouseAdapter
+ * @see MouseMotionAdapter
+ * @see MouseWheelEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class InputEvent extends ComponentEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -2482525981698309786L;
+
+ /**
+ * This is the bit mask which indicates the shift key is down. It is
+ * recommended that SHIFT_DOWN_MASK be used instead.
+ *
+ * @see #SHIFT_DOWN_MASK
+ */
+ public static final int SHIFT_MASK = 1;
+
+ /**
+ * This is the bit mask which indicates the control key is down. It is
+ * recommended that CTRL_DOWN_MASK be used instead.
+ *
+ * @see #CTRL_DOWN_MASK
+ */
+ public static final int CTRL_MASK = 2;
+
+ /**
+ * This is the bit mask which indicates the meta key is down. It is
+ * recommended that META_DOWN_MASK be used instead.
+ *
+ * @see #META_DOWN_MASK
+ */
+ public static final int META_MASK = 4;
+
+ /**
+ * This is the bit mask which indicates the alt key is down. It is
+ * recommended that ALT_DOWN_MASK be used instead.
+ *
+ * @see #ALT_DOWN_MASK
+ */
+ public static final int ALT_MASK = 8;
+
+ /**
+ * This is the bit mask which indicates the alt-graph modifier is in effect.
+ * It is recommended that ALT_GRAPH_DOWN_MASK be used instead.
+ *
+ * @see #ALT_GRAPH_DOWN_MASK
+ */
+ public static final int ALT_GRAPH_MASK = 0x20;
+
+ /**
+ * This bit mask indicates mouse button one is down. It is recommended that
+ * BUTTON1_DOWN_MASK be used instead.
+ *
+ * @see #BUTTON1_DOWN_MASK
+ */
+ public static final int BUTTON1_MASK = 0x10;
+
+ /**
+ * This bit mask indicates mouse button two is down. It is recommended that
+ * BUTTON2_DOWN_MASK be used instead.
+ *
+ * @see #BUTTON2_DOWN_MASK
+ */
+ public static final int BUTTON2_MASK = 8;
+
+ /**
+ * This bit mask indicates mouse button three is down. It is recommended
+ * that BUTTON3_DOWN_MASK be used instead.
+ *
+ * @see #BUTTON3_DOWN_MASK
+ */
+ public static final int BUTTON3_MASK = 4;
+
+ /**
+ * The SHIFT key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int SHIFT_DOWN_MASK = 0x0040;
+
+ /**
+ * The CTRL key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int CTRL_DOWN_MASK = 0x0080;
+
+ /**
+ * The META key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int META_DOWN_MASK = 0x0100;
+
+ /**
+ * The ALT key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int ALT_DOWN_MASK = 0x0200;
+
+ /**
+ * The mouse button1 key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int BUTTON1_DOWN_MASK = 0x0400;
+
+ /**
+ * The mouse button2 extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int BUTTON2_DOWN_MASK = 0x0800;
+
+ /**
+ * The mouse button3 extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int BUTTON3_DOWN_MASK = 0x1000;
+
+ /**
+ * The ALT_GRAPH key extended modifier.
+ *
+ * @since 1.4
+ */
+ public static final int ALT_GRAPH_DOWN_MASK = 0x2000;
+
+ /** The mask to convert new to old, package visible for use in subclasses. */
+ static final int CONVERT_MASK
+ = EventModifier.NEW_MASK & ~(BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK);
+
+ /**
+ * The timestamp when this event occurred.
+ *
+ * @see #getWhen()
+ * @serial the timestamp
+ */
+ private final long when;
+
+ /**
+ * The old-style modifiers in effect for this event. Package visible
+ * for use by subclasses. The old style (bitmask 0x3f) should not be
+ * mixed with the new style (bitmasks 0xffffffc0).
+ *
+ * @see #getModifiers()
+ * @see MouseEvent
+ * @serial the modifier state, stored in the old style
+ */
+ int modifiers;
+
+ /**
+ * The new-style modifiers in effect for this event. Package visible
+ * for use by subclasses. The old style (bitmask 0x3f) should not be
+ * mixed with the new style (bitmasks 0xffffffc0).
+ *
+ * @see #getModifiersEx()
+ * @see MouseEvent
+ * @serial the modifier state, stored in the new style
+ */
+ int modifiersEx;
+
+ /**
+ * Initializes a new instance of <code>InputEvent</code> with the specified
+ * source, id, timestamp, and modifiers. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param when the timestamp when the event occurred
+ * @param modifiers the modifiers in effect for this event, old or new style
+ * @throws IllegalArgumentException if source is null
+ */
+ InputEvent(Component source, int id, long when, int modifiers)
+ {
+ super(source, id);
+ this.when = when;
+ this.modifiers = modifiers & EventModifier.OLD_MASK;
+ this.modifiersEx = modifiers & EventModifier.NEW_MASK;
+ }
+
+ /**
+ * This method tests whether or not the shift key was down during the event.
+ *
+ * @return true if the shift key is down
+ */
+ public boolean isShiftDown()
+ {
+ return ((modifiers & SHIFT_MASK) != 0)
+ || ((modifiersEx & SHIFT_DOWN_MASK) != 0);
+ }
+
+ /**
+ * This method tests whether or not the control key was down during the
+ * event.
+ *
+ * @return true if the control key is down
+ */
+ public boolean isControlDown()
+ {
+ return ((modifiers & CTRL_MASK) != 0)
+ || ((modifiersEx & CTRL_DOWN_MASK) != 0);
+ }
+
+ /**
+ * This method tests whether or not the meta key was down during the event.
+ *
+ * @return true if the meta key is down
+ */
+ public boolean isMetaDown()
+ {
+ return ((modifiers & META_MASK) != 0)
+ || ((modifiersEx & META_DOWN_MASK) != 0);
+ }
+
+ /**
+ * This method tests whether or not the alt key was down during the event.
+ *
+ * @return true if the alt key is down
+ */
+ public boolean isAltDown()
+ {
+ return ((modifiers & ALT_MASK) != 0)
+ || ((modifiersEx & ALT_DOWN_MASK) != 0);
+ }
+
+ /**
+ * This method tests whether or not the alt-graph modifier was in effect
+ * during the event.
+ *
+ * @return true if the alt-graph modifier is down
+ */
+ public boolean isAltGraphDown()
+ {
+ return ((modifiers & ALT_GRAPH_MASK) != 0)
+ || ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0);
+ }
+
+ /**
+ * This method returns the timestamp when this event occurred.
+ *
+ * @return the timestamp when this event occurred
+ */
+ public long getWhen()
+ {
+ return when;
+ }
+
+ /**
+ * This method returns the old-style modifiers in effect for this event.
+ * Note that this is ambiguous between button2 and alt, and between
+ * button3 and meta. Also, code which generated these modifiers tends to
+ * only list the modifier that just changed, even if others were down at
+ * the time. Consider using getModifiersEx instead. This will be a union
+ * of the bit masks defined in this class that are applicable to the event.
+ *
+ * @return the modifiers in effect for this event
+ * @see #getModifiersEx()
+ */
+ public int getModifiers()
+ {
+ return modifiers;
+ }
+
+ /**
+ * Returns the extended modifiers (new-style) for this event. This represents
+ * the state of all modal keys and mouse buttons at the time of the event,
+ * and does not suffer from the problems mentioned in getModifiers.
+ *
+ * <p>For an example of checking multiple modifiers, this code will return
+ * true only if SHIFT and BUTTON1 were pressed and CTRL was not:
+ * <pre>
+ * int onmask = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
+ * int offmask = InputEvent.CTRL_DOWN_MASK;
+ * return (event.getModifiersEx() & (onmask | offmask)) == onmask;
+ * </pre>
+ *
+ * @return the bitwise or of all modifiers pressed during the event
+ * @since 1.4
+ */
+ public int getModifiersEx()
+ {
+ return modifiersEx;
+ }
+
+ /**
+ * Consumes this event. A consumed event is not processed further by the AWT
+ * system.
+ */
+ public void consume()
+ {
+ consumed = true;
+ }
+
+ /**
+ * This method tests whether or not this event has been consumed.
+ *
+ * @return true if this event has been consumed
+ */
+ public boolean isConsumed()
+ {
+ return consumed;
+ }
+
+ /**
+ * Convert the extended modifier bitmask into a String, such as "Shift" or
+ * "Ctrl+Button1".
+ *
+ * XXX Sun claims this can be localized via the awt.properties file - how
+ * do we implement that?
+ *
+ * @param modifiers the modifiers
+ * @return a string representation of the modifiers in this bitmask
+ * @since 1.4
+ */
+ public static String getModifiersExText(int modifiers)
+ {
+ modifiers &= EventModifier.NEW_MASK;
+ if (modifiers == 0)
+ return "";
+ StringBuffer s = new StringBuffer();
+ if ((modifiers & META_DOWN_MASK) != 0)
+ s.append("Meta+");
+ if ((modifiers & CTRL_DOWN_MASK) != 0)
+ s.append("Ctrl+");
+ if ((modifiers & ALT_DOWN_MASK) != 0)
+ s.append("Alt+");
+ if ((modifiers & SHIFT_DOWN_MASK) != 0)
+ s.append("Shift+");
+ if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0)
+ s.append("Alt Graph+");
+ if ((modifiers & BUTTON1_DOWN_MASK) != 0)
+ s.append("Button1+");
+ if ((modifiers & BUTTON2_DOWN_MASK) != 0)
+ s.append("Button2+");
+ if ((modifiers & BUTTON3_DOWN_MASK) != 0)
+ s.append("Button3+");
+ return s.substring(0, s.length() - 1);
+ }
+} // class InputEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,303 @@
+/* InputMethodEvent.java -- events from a text input method
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.font.TextHitInfo;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.text.AttributedCharacterIterator;
+
+/**
+ * This class is for event generated by change in a text input method.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see InputMethodListener
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public class InputMethodEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = 4727190874778922661L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int INPUT_METHOD_FIRST = 1100;
+
+ /** This event id indicates that the text in the input method has changed. */
+ public static final int INPUT_METHOD_TEXT_CHANGED = 1100;
+
+ /** This event id indicates that the input method curor point has changed. */
+ public static final int CARET_POSITION_CHANGED = 1101;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int INPUT_METHOD_LAST = 1101;
+
+ /**
+ * The timestamp when this event was created.
+ *
+ * @serial the timestamp
+ * @since 1.4
+ */
+ private long when;
+
+ /** The input method text. */
+ private final transient AttributedCharacterIterator text;
+
+ /** The number of committed characters in the text. */
+ private final transient int committedCharacterCount;
+
+ /** The caret. */
+ private final transient TextHitInfo caret;
+
+ /** The most important position to be visible. */
+ private final transient TextHitInfo visiblePosition;
+
+ /**
+ * Initializes a new instance of <code>InputMethodEvent</code> with the
+ * specified source, id, timestamp, text, char count, caret, and visible
+ * position.
+ *
+ * @param source the source that generated the event
+ * @param id the event id
+ * @param when the timestamp of the event
+ * @param text the input text
+ * @param committedCharacterCount the number of committed characters
+ * @param caret the caret position
+ * @param visiblePosition the position most important to make visible
+ * @throws IllegalArgumentException if source is null, id is invalid, id is
+ * CARET_POSITION_CHANGED and text is non-null, or if
+ * committedCharacterCount is out of range
+ * @since 1.4
+ */
+ public InputMethodEvent(Component source, int id, long when,
+ AttributedCharacterIterator text,
+ int committedCharacterCount, TextHitInfo caret,
+ TextHitInfo visiblePosition)
+ {
+ super(source, id);
+ this.when = when;
+ this.text = text;
+ this.committedCharacterCount = committedCharacterCount;
+ this.caret = caret;
+ this.visiblePosition = visiblePosition;
+ if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST
+ || (id == CARET_POSITION_CHANGED && text != null)
+ || committedCharacterCount < 0
+ || (committedCharacterCount
+ > (text == null ? 0 : text.getEndIndex() - text.getBeginIndex())))
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * Initializes a new instance of <code>InputMethodEvent</code> with the
+ * specified source, id, text, char count, caret, and visible position.
+ *
+ * @param source the source that generated the event
+ * @param id the event id
+ * @param text the input text
+ * @param committedCharacterCount the number of committed characters
+ * @param caret the caret position
+ * @param visiblePosition the position most important to make visible
+ * @throws IllegalArgumentException if source is null, id is invalid, id is
+ * CARET_POSITION_CHANGED and text is non-null, or if
+ * committedCharacterCount is out of range
+ * @since 1.4
+ */
+ public InputMethodEvent(Component source, int id,
+ AttributedCharacterIterator text,
+ int committedCharacterCount, TextHitInfo caret,
+ TextHitInfo visiblePosition)
+ {
+ this(source, id, EventQueue.getMostRecentEventTime(), text,
+ committedCharacterCount, caret, visiblePosition);
+ }
+
+ /**
+ * Initializes a new instance of <code>InputMethodEvent</code> with the
+ * specified source, id, caret, and visible position, and with a null
+ * text and char count.
+ *
+ * @param source the source that generated the event
+ * @param id the event id
+ * @param caret the caret position
+ * @param visiblePosition the position most important to make visible
+ * @throws IllegalArgumentException if source is null or id is invalid
+ * @since 1.4
+ */
+ public InputMethodEvent(Component source, int id, TextHitInfo caret,
+ TextHitInfo visiblePosition)
+ {
+ this(source, id, EventQueue.getMostRecentEventTime(), null, 0, caret,
+ visiblePosition);
+ }
+
+ /**
+ * This method returns the input method text. This can be <code>null</code>,
+ * and will always be null for <code>CARET_POSITION_CHANGED</code> events.
+ * Characters from 0 to <code>getCommittedCharacterCount()-1</code> have
+ * been committed, the remaining characters are composed text.
+ *
+ * @return the input method text, or null
+ */
+ public AttributedCharacterIterator getText()
+ {
+ return text;
+ }
+
+ /**
+ * Returns the number of committed characters in the input method text.
+ *
+ * @return the number of committed characters in the input method text
+ */
+ public int getCommittedCharacterCount()
+ {
+ return committedCharacterCount;
+ }
+
+ /**
+ * Returns the caret position. The caret offset is relative to the composed
+ * text of the most recent <code>INPUT_METHOD_TEXT_CHANGED</code> event.
+ *
+ * @return the caret position, or null
+ */
+ public TextHitInfo getCaret()
+ {
+ return caret;
+ }
+
+ /**
+ * Returns the position that is most important to be visible, or null if
+ * such a hint is not necessary. The caret offset is relative to the composed
+ * text of the most recent <code>INPUT_METHOD_TEXT_CHANGED</code> event.
+ *
+ * @return the position that is most important to be visible
+ */
+ public TextHitInfo getVisiblePosition()
+ {
+ return visiblePosition;
+ }
+
+ /**
+ * This method consumes the event. A consumed event is not processed
+ * in the default manner by the component that generated it.
+ */
+ public void consume()
+ {
+ consumed = true;
+ }
+
+ /**
+ * This method tests whether or not this event has been consumed.
+ *
+ * @return true if the event has been consumed
+ */
+ public boolean isConsumed()
+ {
+ return consumed;
+ }
+
+ /**
+ * Return the timestamp of this event.
+ *
+ * @return the timestamp
+ * @since 1.4
+ */
+ public long getWhen()
+ {
+ return when;
+ }
+
+ /**
+ * This method returns a string identifying the event. This contains the
+ * event ID, the committed and composed characters separated by '+', the
+ * number of committed characters, the caret, and the visible position.
+ *
+ * @return a string identifying the event
+ */
+ public String paramString()
+ {
+ StringBuffer s
+ = new StringBuffer(80 + (text == null ? 0
+ : text.getEndIndex() - text.getBeginIndex()));
+ s.append(id == INPUT_METHOD_TEXT_CHANGED ? "INPUT_METHOD_TEXT_CHANGED, "
+ : "CARET_POSITION_CHANGED, ");
+ if (text == null)
+ s.append("no text, 0 characters committed, caret: ");
+ else
+ {
+ s.append('"');
+ int i = text.getBeginIndex();
+ int j = committedCharacterCount;
+ while (--j >= 0)
+ s.append(text.setIndex(i++));
+ s.append("\" + \"");
+ j = text.getEndIndex() - i;
+ while (--j >= 0)
+ s.append(text.setIndex(i++));
+ s.append("\", ").append(committedCharacterCount)
+ .append(" characters committed, caret: ");
+ }
+ s.append(caret == null ? (Object) "no caret" : caret).append(", ")
+ .append(visiblePosition == null ? (Object) "no visible position"
+ : visiblePosition);
+ return s.toString();
+ }
+
+ /**
+ * Reads in the object from a serial stream, updating when to
+ * {@link EventQueue#getMostRecentEventTime()} if necessary.
+ *
+ * @param s the stream to read from
+ * @throws IOException if deserialization fails
+ * @throws ClassNotFoundException if deserialization fails
+ * @serialData default, except for updating when
+ */
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ if (when == 0)
+ when = EventQueue.getMostRecentEventTime();
+ }
+} // class InputMethodEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InputMethodListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,70 @@
+/* InputMethodListener.java -- listen for input method events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.im.InputMethodRequests;
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to receive events from an input
+ * method. For a text component to use input methods, it must also install
+ * an InputMethodRequests handler.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see InputMethodEvent
+ * @see InputMethodRequests
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface InputMethodListener extends EventListener
+{
+ /**
+ * This method is called when the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the text change
+ */
+ void inputMethodTextChanged(InputMethodEvent event);
+
+ /**
+ * This method is called when the cursor position within the text is changed.
+ *
+ * @param event the <code>InputMethodEvent</code> indicating the change
+ */
+ void caretPositionChanged(InputMethodEvent event);
+} // interface InputMethodListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InvocationEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InvocationEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InvocationEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/InvocationEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,258 @@
+/* InvocationEvent.java -- call a runnable when dispatched
+ Copyright (C) 1999, 2002, 2004, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.ActiveEvent;
+import java.awt.EventQueue;
+
+/**
+ * This event executes {@link Runnable#run()} of a target object when it is
+ * dispatched. This class is used by calls to <code>invokeLater</code> and
+ * <code>invokeAndWait</code>, so client code can use this fact to avoid
+ * writing special-casing AWTEventListener objects.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ActiveEvent
+ * @see EventQueue#invokeLater(Runnable)
+ * @see EventQueue#invokeAndWait(Runnable)
+ * @see AWTEventListener
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public class InvocationEvent extends AWTEvent implements ActiveEvent
+{
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = 436056344909459450L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int INVOCATION_FIRST = 1200;
+
+ /** This is the default id for this event type. */
+ public static final int INVOCATION_DEFAULT = 1200;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int INVOCATION_LAST = 1200;
+
+ /**
+ * This is the <code>Runnable</code> object to call when dispatched.
+ *
+ * @serial the runnable to execute
+ */
+ protected Runnable runnable;
+
+ /**
+ * This is the object to call <code>notifyAll()</code> on when
+ * the call to <code>run()</code> returns, or <code>null</code> if no
+ * object is to be notified.
+ *
+ * @serial the object to notify
+ */
+ protected Object notifier;
+
+ /**
+ * This variable is set to <code>true</code> if exceptions are caught
+ * and stored in a variable during the call to <code>run()</code>, otherwise
+ * exceptions are ignored and propagate up.
+ *
+ * @serial true to catch exceptions
+ */
+ protected boolean catchExceptions;
+
+ /**
+ * This is the caught exception thrown in the <code>run()</code> method. It
+ * is null if exceptions are ignored, the run method hasn't completed, or
+ * there were no exceptions.
+ *
+ * @serial the caught exception, if any
+ */
+ private Exception exception;
+
+ /**
+ * This is the caught Throwable thrown in the <code>run()</code> method.
+ * It is null if throwables are ignored, the run method hasn't completed,
+ * or there were no throwables thrown.
+ */
+ private Throwable throwable;
+
+ /**
+ * The timestamp when this event was created.
+ *
+ * @see #getWhen()
+ * @serial the timestamp
+ * @since 1.4
+ */
+ private final long when = EventQueue.getMostRecentEventTime();
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source and runnable.
+ *
+ * @param source the source of the event
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @throws IllegalArgumentException if source is null
+ */
+ public InvocationEvent(Object source, Runnable runnable)
+ {
+ this(source, INVOCATION_DEFAULT, runnable, null, false);
+ }
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source, runnable, and notifier. It will also catch exceptions
+ * if specified. If notifier is non-null, this will call notifyAll() on
+ * the object when the runnable is complete. If catchExceptions is true,
+ * this traps any exception in the runnable, otherwise it lets the exception
+ * propagate up the Event Dispatch thread.
+ *
+ * @param source the source of the event
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @param notifier the object to notify, or null
+ * @param catchExceptions true to catch exceptions from the runnable
+ */
+ public InvocationEvent(Object source, Runnable runnable, Object notifier,
+ boolean catchExceptions)
+ {
+ this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions);
+ }
+
+ /**
+ * Initializes a new instance of <code>InvocationEvent</code> with the
+ * specified source, runnable, and notifier. It will also catch exceptions
+ * if specified. If notifier is non-null, this will call notifyAll() on
+ * the object when the runnable is complete. If catchExceptions is true,
+ * this traps any exception in the runnable, otherwise it lets the exception
+ * propagate up the Event Dispatch thread. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param runnable the <code>Runnable</code> object to invoke
+ * @param notifier the object to notify, or null
+ * @param catchExceptions true to catch exceptions from the runnable
+ */
+ protected InvocationEvent(Object source, int id, Runnable runnable,
+ Object notifier, boolean catchExceptions)
+ {
+ super(source, id);
+ this.runnable = runnable;
+ this.notifier = notifier;
+ this.catchExceptions = catchExceptions;
+ }
+
+ /**
+ * This method calls the <code>run()</code> method of the runnable, traps
+ * exceptions if instructed to do so, and calls <code>notifyAll()</code>
+ * on any notifier if all worked successfully.
+ */
+ public void dispatch()
+ {
+ if (catchExceptions)
+ try
+ {
+ runnable.run();
+ }
+ catch (Throwable t)
+ {
+ throwable = t;
+ if (t instanceof Exception)
+ exception = (Exception)t;
+ }
+ else
+ runnable.run();
+
+ Object o = notifier;
+ if (o != null)
+ synchronized(o)
+ {
+ o.notifyAll();
+ }
+ }
+
+ /**
+ * This method returns the exception that occurred during the execution of
+ * the runnable, or <code>null</code> if not exception was thrown or
+ * exceptions were not caught.
+ *
+ * @return the exception thrown by the runnable
+ */
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ /**
+ * Returns a throwable caught while executing the Runnable's run() method.
+ * Null if none was thrown or if this InvocationEvent doesn't catch
+ * throwables.
+ * @return the caught Throwable
+ * @since 1.5
+ */
+ public Throwable getThrowable()
+ {
+ return throwable;
+ }
+
+ /**
+ * Gets the timestamp of when this event was created.
+ *
+ * @return the timestamp of this event
+ * @since 1.4
+ */
+ public long getWhen()
+ {
+ return when;
+ }
+
+ /**
+ * This method returns a string identifying this event. This is formatted as:
+ * <code>"INVOCATION_DEFAULT,runnable=" + runnable + ",notifier=" + notifier
+ * + ",catchExceptions=" + catchExceptions + ",when=" + getWhen()</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return (id == INVOCATION_DEFAULT ? "INVOCATION_DEFAULT,runnable="
+ : "unknown type,runnable=") + runnable + ",notifier=" + notifier
+ + ",catchExceptions=" + catchExceptions + ",when=" + when;
+ }
+} // class InvocationEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,155 @@
+/* ItemEvent.java -- event for item state changes
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.ItemSelectable;
+
+/**
+ * This event is generated when a selection item changes state. This is an
+ * abstraction that distills a large number of individual mouse or keyboard
+ * events into a simpler "item selected" and "item deselected" events.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ItemSelectable
+ * @see ItemListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class ItemEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -608708132447206933L;
+
+ /** This is the first id in the event id range used by this class. */
+ public static final int ITEM_FIRST = 701;
+
+ /** This is the last id in the event id range used by this class. */
+ public static final int ITEM_LAST = 701;
+
+ /** This event id indicates a state change occurred. */
+ public static final int ITEM_STATE_CHANGED = 701;
+
+ /** This type indicates that the item was selected. */
+ public static final int SELECTED = 1;
+
+ /** This type indicates that the item was deselected. */
+ public static final int DESELECTED = 2;
+
+ /**
+ * The item affected by this event.
+ *
+ * @serial the item of the selection
+ */
+ private final Object item;
+
+ /**
+ * The state change direction, one of {@link #SELECTED} or
+ * {@link #DESELECTED}.
+ *
+ * @serial the selection state
+ */
+ private final int stateChange;
+
+ /**
+ * Initializes a new instance of <code>ItemEvent</code> with the specified
+ * source, id, and state change constant. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param item the item affected by the state change
+ * @param stateChange one of {@link #SELECTED} or {@link #DESELECTED}
+ */
+ public ItemEvent(ItemSelectable source, int id, Object item, int stateChange)
+ {
+ super(source, id);
+ this.item = item;
+ this.stateChange = stateChange;
+ }
+
+ /**
+ * This method returns the event source as an <code>ItemSelectable</code>.
+ *
+ * @return the event source as an <code>ItemSelected</code>
+ * @throws ClassCastException if source is changed to a non-ItemSelectable
+ */
+ public ItemSelectable getItemSelectable()
+ {
+ return (ItemSelectable) source;
+ }
+
+ /**
+ * Returns the item affected by this state change.
+ *
+ * @return the item affected by this state change
+ */
+ public Object getItem()
+ {
+ return item;
+ }
+
+ /**
+ * Returns the type of state change, either {@link #SELECTED} or
+ * {@link #DESELECTED}.
+ *
+ * @return the type of state change
+ */
+ public int getStateChange()
+ {
+ return stateChange;
+ }
+
+ /**
+ * Returns a string identifying this event. This is in the format:
+ * <code>"ITEM_STATE_CHANGED,item=" + item + ",stateChange="
+ * + (getStateChange() == DESELECTED ? "DESELECTED" : "SELECTED")</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return (id == ITEM_STATE_CHANGED ? "ITEM_STATE_CHANGED,item="
+ : "unknown type,item=") + item + ",stateChange="
+ + (stateChange == SELECTED ? "SELECTED"
+ : stateChange == DESELECTED ? "DESELECTED" : "unknown type");
+ }
+} // class ItemEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/ItemListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,62 @@
+/* ItemListener.java -- listen for item events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.ItemSelectable;
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to receive events when an
+ * item's selection state changes.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ItemSelectable
+ * @see ItemEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface ItemListener extends EventListener
+{
+ /**
+ * This method is called when an item's state is changed.
+ *
+ * @param event the <code>ItemEvent</code> indicating the change
+ */
+ void itemStateChanged(ItemEvent event);
+} // interface ItemListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,88 @@
+/* KeyAdapter.java -- convenience class for writing key listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>KeyListener</code> and implements all methods
+ * with empty bodies. This allows a listener interested in implementing only
+ * a subset of the <code>KeyListener</code> interface to extend this class
+ * and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see KeyEvent
+ * @see KeyListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class KeyAdapter implements KeyListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public KeyAdapter()
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void keyTyped(KeyEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void keyPressed(KeyEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void keyReleased(KeyEvent event)
+ {
+ }
+} // class KeyAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1761 @@
+/* KeyEvent.java -- event for key presses
+ Copyright (C) 1999, 2002, 2004, 2005 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., 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.event;
+
+import gnu.java.awt.EventModifier;
+
+import java.awt.Component;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+/**
+ * This event is generated when a key is pressed or released. There are two
+ * categories of key events:
+ *
+ * <p><em>"Key typed" events</em> are higher-level, and have already
+ * compensated for modifiers and keyboard layout to generate a single Unicode
+ * character. It may take several key press events to generate one key typed.
+ * The <code>getKeyCode</code> method will return <code>VK_UNDEFINED</code>,
+ * and <code>getKeyChar</code> will return a valid Unicode character or
+ * <code>CHAR_UNDEFINED</code>.
+ *
+ * <p><em>"Key pressed" and "key released" events</em> are lower-level, and
+ * are platform and keyboard dependent. They correspond to the actaul motion
+ * on a keyboard, and return a virtual key code which labels the key that was
+ * pressed. The <code>getKeyCode</code> method will return one of the
+ * <code>VK_*</code> constants (except VK_UNDEFINED), and the
+ * <code>getKeyChar</code> method is undefined.
+ *
+ * <p>Some keys do not generate key typed events, such as the F1 or HELP keys.
+ * Not all keyboards can generate all virtual keys, and no attempt is made to
+ * simulate the ones that can't be typed. Virtual keys correspond to the
+ * keyboard layout, so for example, VK_Q in English is VK_A in French. Also,
+ * there are some additional virtual keys to ease handling of actions, such
+ * as VK_ALL_CANDIDATES in place of ALT+VK_CONVERT. Do not rely on the value
+ * of the VK_* constants, except for VK_ENTER, VK_BACK_SPACE, and VK_TAB.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see KeyAdapter
+ * @see KeyListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class KeyEvent extends InputEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -2352130953028126954L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int KEY_FIRST = 400;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int KEY_LAST = 402;
+
+ /**
+ * This event id indicates a key was typed, which is a key press followed
+ * by a key release to generate an actual Unicode character. It may take
+ * several key presses to generate one key typed event, and some action
+ * keys have no corresponding key typed.
+ */
+ public static final int KEY_TYPED = 400;
+
+ /** This event id indicates a key was pressed. */
+ public static final int KEY_PRESSED = 401;
+
+ /** This event it indicates a key was released. */
+ public static final int KEY_RELEASED = 402;
+
+ /** The virtual key Enter, which will always map to '\n'. */
+ public static final int VK_ENTER = '\n';
+
+ /** The virtual key Backspace, which will always map to '\b'. */
+ public static final int VK_BACK_SPACE = '\b';
+
+ /** The virtual key Tab, which will always map to '\t'. */
+ public static final int VK_TAB = '\t';
+
+ /** The virtual key Cancel. */
+ public static final int VK_CANCEL = 3;
+
+ /** The virtual key VK_CLEAR. */
+ public static final int VK_CLEAR = 12;
+
+ /** The virtual key VK_SHIFT. */
+ public static final int VK_SHIFT = 16;
+
+ /** The virtual key VK_CONTROL. */
+ public static final int VK_CONTROL = 17;
+
+ /** The virtual key VK_ALT. */
+ public static final int VK_ALT = 18;
+
+ /** The virtual key VK_PAUSE. */
+ public static final int VK_PAUSE = 19;
+
+ /** The virtual key VK_CAPS_LOCK. */
+ public static final int VK_CAPS_LOCK = 20;
+
+ /** The virtual key VK_ESCAPE. */
+ public static final int VK_ESCAPE = 27;
+
+ /** The virtual key VK_SPACE. */
+ public static final int VK_SPACE = ' ';
+
+ /** The virtual key VK_PAGE_UP. */
+ public static final int VK_PAGE_UP = 33;
+
+ /** The virtual key VK_PAGE_DOWN. */
+ public static final int VK_PAGE_DOWN = 34;
+
+ /** The virtual key VK_END. */
+ public static final int VK_END = 35;
+
+ /** The virtual key VK_HOME. */
+ public static final int VK_HOME = 36;
+
+ /**
+ * The virtual key for the non-numpad VK_LEFT.
+ *
+ * @see #VK_KP_LEFT
+ */
+ public static final int VK_LEFT = 37;
+
+ /**
+ * The virtual key for the non-numpad VK_UP.
+ *
+ * @see #VK_KP_UP
+ */
+ public static final int VK_UP = 38;
+
+ /**
+ * The virtual key for the non-numpad VK_RIGHT.
+ *
+ * @see #VK_KP_RIGHT
+ */
+ public static final int VK_RIGHT = 39;
+
+ /**
+ * The virtual key for the non-numpad VK_DOWN.
+ *
+ * @see #VK_KP_DOWN
+ */
+ public static final int VK_DOWN = 40;
+
+ /** The virtual key VK_COMMA. */
+ public static final int VK_COMMA = ',';
+
+ /**
+ * The virtual key VK_MINUS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_MINUS = '-';
+
+ /** The virtual key VK_PERIOD. */
+ public static final int VK_PERIOD = '.';
+
+ /** The virtual key VK_SLASH. */
+ public static final int VK_SLASH = '/';
+
+ /** The virtual key VK_0. */
+ public static final int VK_0 = '0';
+
+ /** The virtual key VK_1. */
+ public static final int VK_1 = '1';
+
+ /** The virtual key VK_2. */
+ public static final int VK_2 = '2';
+
+ /** The virtual key VK_3. */
+ public static final int VK_3 = '3';
+
+ /** The virtual key VK_4. */
+ public static final int VK_4 = '4';
+
+ /** The virtual key VK_5. */
+ public static final int VK_5 = '5';
+
+ /** The virtual key VK_6. */
+ public static final int VK_6 = '6';
+
+ /** The virtual key VK_7. */
+ public static final int VK_7 = '7';
+
+ /** The virtual key VK_8. */
+ public static final int VK_8 = '8';
+
+ /** The virtual key VK_9. */
+ public static final int VK_9 = '9';
+
+ /** The virtual key VK_SEMICOLON. */
+ public static final int VK_SEMICOLON = ';';
+
+ /** The virtual key VK_EQUALS. */
+ public static final int VK_EQUALS = '=';
+
+ /** The virtual key VK_A. */
+ public static final int VK_A = 'A';
+
+ /** The virtual key VK_B. */
+ public static final int VK_B = 'B';
+
+ /** The virtual key VK_C. */
+ public static final int VK_C = 'C';
+
+ /** The virtual key VK_D. */
+ public static final int VK_D = 'D';
+
+ /** The virtual key VK_E. */
+ public static final int VK_E = 'E';
+
+ /** The virtual key VK_F. */
+ public static final int VK_F = 'F';
+
+ /** The virtual key VK_G. */
+ public static final int VK_G = 'G';
+
+ /** The virtual key VK_H. */
+ public static final int VK_H = 'H';
+
+ /** The virtual key VK_I. */
+ public static final int VK_I = 'I';
+
+ /** The virtual key VK_J. */
+ public static final int VK_J = 'J';
+
+ /** The virtual key VK_K. */
+ public static final int VK_K = 'K';
+
+ /** The virtual key VK_L. */
+ public static final int VK_L = 'L';
+
+ /** The virtual key VK_M. */
+ public static final int VK_M = 'M';
+
+ /** The virtual key VK_N. */
+ public static final int VK_N = 'N';
+
+ /** The virtual key VK_O. */
+ public static final int VK_O = 'O';
+
+ /** The virtual key VK_P. */
+ public static final int VK_P = 'P';
+
+ /** The virtual key VK_Q. */
+ public static final int VK_Q = 'Q';
+
+ /** The virtual key VK_R. */
+ public static final int VK_R = 'R';
+
+ /** The virtual key VK_S. */
+ public static final int VK_S = 'S';
+
+ /** The virtual key VK_T. */
+ public static final int VK_T = 'T';
+
+ /** The virtual key VK_U. */
+ public static final int VK_U = 'U';
+
+ /** The virtual key VK_V. */
+ public static final int VK_V = 'V';
+
+ /** The virtual key VK_W. */
+ public static final int VK_W = 'W';
+
+ /** The virtual key VK_X. */
+ public static final int VK_X = 'X';
+
+ /** The virtual key VK_Y. */
+ public static final int VK_Y = 'Y';
+
+ /** The virtual key VK_Z. */
+ public static final int VK_Z = 'Z';
+
+ /** The virtual key VK_OPEN_BRACKET. */
+ public static final int VK_OPEN_BRACKET = '[';
+
+ /** The virtual key VK_BACK_SLASH. */
+ public static final int VK_BACK_SLASH = '\\';
+
+ /** The virtual key VK_CLOSE_BRACKET. */
+ public static final int VK_CLOSE_BRACKET = ']';
+
+ /** The virtual key VK_NUMPAD0. */
+ public static final int VK_NUMPAD0 = 96;
+
+ /** The virtual key VK_NUMPAD1. */
+ public static final int VK_NUMPAD1 = 97;
+
+ /** The virtual key VK_NUMPAD2. */
+ public static final int VK_NUMPAD2 = 98;
+
+ /** The virtual key VK_NUMPAD3. */
+ public static final int VK_NUMPAD3 = 99;
+
+ /** The virtual key VK_NUMPAD4. */
+ public static final int VK_NUMPAD4 = 100;
+
+ /** The virtual key VK_NUMPAD5. */
+ public static final int VK_NUMPAD5 = 101;
+
+ /** The virtual key VK_NUMPAD6. */
+ public static final int VK_NUMPAD6 = 102;
+
+ /** The virtual key VK_NUMPAD7. */
+ public static final int VK_NUMPAD7 = 103;
+
+ /** The virtual key VK_NUMPAD8. */
+ public static final int VK_NUMPAD8 = 104;
+
+ /** The virtual key VK_NUMPAD9. */
+ public static final int VK_NUMPAD9 = 105;
+
+ /** The virtual key VK_MULTIPLY. */
+ public static final int VK_MULTIPLY = 106;
+
+ /** The virtual key VK_ADD. */
+ public static final int VK_ADD = 107;
+
+ /**
+ * The virtual key VK_SEPARATOR, handily mispelled for those who can't
+ * figure it out.
+ *
+ * @deprecated use {@link #VK_SEPARATOR}
+ */
+ public static final int VK_SEPARATER = 108;
+
+ /**
+ * The virtual key VK_SEPARATOR.
+ *
+ * @since 1.4
+ */
+ public static final int VK_SEPARATOR = 108;
+
+ /** The virtual key VK_SUBTRACT. */
+ public static final int VK_SUBTRACT = 109;
+
+ /** The virtual key VK_DECIMAL. */
+ public static final int VK_DECIMAL = 110;
+
+ /** The virtual key VK_DIVIDE. */
+ public static final int VK_DIVIDE = 111;
+
+ /** The virtual key VK_DELETE. */
+ public static final int VK_DELETE = 127;
+
+ /** The virtual key VK_NUM_LOCK. */
+ public static final int VK_NUM_LOCK = 144;
+
+ /** The virtual key VK_SCROLL_LOCK. */
+ public static final int VK_SCROLL_LOCK = 145;
+
+ /** The virtual key VK_F1. */
+ public static final int VK_F1 = 112;
+
+ /** The virtual key VK_F2. */
+ public static final int VK_F2 = 113;
+
+ /** The virtual key VK_F3. */
+ public static final int VK_F3 = 114;
+
+ /** The virtual key VK_F4. */
+ public static final int VK_F4 = 115;
+
+ /** The virtual key VK_F5. */
+ public static final int VK_F5 = 116;
+
+ /** The virtual key VK_F6. */
+ public static final int VK_F6 = 117;
+
+ /** The virtual key VK_F7. */
+ public static final int VK_F7 = 118;
+
+ /** The virtual key VK_F8. */
+ public static final int VK_F8 = 119;
+
+ /** The virtual key VK_F9. */
+ public static final int VK_F9 = 120;
+
+ /** The virtual key VK_F10. */
+ public static final int VK_F10 = 121;
+
+ /** The virtual key VK_F11. */
+ public static final int VK_F11 = 122;
+
+ /** The virtual key VK_F12. */
+ public static final int VK_F12 = 123;
+
+ /**
+ * The virtual key VK_F13.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F13 = 61440;
+
+ /**
+ * The virtual key VK_F14.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F14 = 61441;
+
+ /**
+ * The virtual key VK_F15.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F15 = 61442;
+
+ /**
+ * The virtual key VK_F16.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F16 = 61443;
+
+ /**
+ * The virtual key VK_F17.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F17 = 61444;
+
+ /**
+ * The virtual key VK_F18.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F18 = 61445;
+
+ /**
+ * The virtual key VK_F19.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F19 = 61446;
+
+ /**
+ * The virtual key VK_F20.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F20 = 61447;
+
+ /**
+ * The virtual key VK_F21.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F21 = 61448;
+
+ /**
+ * The virtual key VK_F22.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F22 = 61449;
+
+ /**
+ * The virtual key VK_F23.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F23 = 61450;
+
+ /**
+ * The virtual key VK_F24.
+ *
+ * @since 1.2
+ */
+ public static final int VK_F24 = 61451;
+
+ /** The virtual key VK_PRINTSCREEN. */
+ public static final int VK_PRINTSCREEN = 154;
+
+ /** The virtual key VK_INSERT. */
+ public static final int VK_INSERT = 155;
+
+ /** The virtual key VK_HELP. */
+ public static final int VK_HELP = 156;
+
+ /** The virtual key VK_META. */
+ public static final int VK_META = 157;
+
+ /** The virtual key VK_BACK_QUOTE. */
+ public static final int VK_BACK_QUOTE = 192;
+
+ /** The virtual key VK_QUOTE. */
+ public static final int VK_QUOTE = 222;
+
+ /**
+ * The virtual key for the numpad VK_KP_UP.
+ *
+ * @see #VK_UP
+ * @since 1.2
+ */
+ public static final int VK_KP_UP = 224;
+
+ /**
+ * The virtual key for the numpad VK_KP_DOWN.
+ *
+ * @see #VK_DOWN
+ * @since 1.2
+ */
+ public static final int VK_KP_DOWN = 225;
+
+ /**
+ * The virtual key for the numpad VK_KP_LEFT.
+ *
+ * @see #VK_LEFT
+ * @since 1.2
+ */
+ public static final int VK_KP_LEFT = 226;
+
+ /**
+ * The virtual key for the numpad VK_KP_RIGHT.
+ *
+ * @see #VK_RIGHT
+ * @since 1.2
+ */
+ public static final int VK_KP_RIGHT = 227;
+
+ /**
+ * The virtual key VK_DEAD_GRAVE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_GRAVE = 128;
+
+ /**
+ * The virtual key VK_DEAD_ACUTE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_ACUTE = 129;
+
+ /**
+ * The virtual key VK_DEAD_CIRCUMFLEX.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_CIRCUMFLEX = 130;
+
+ /**
+ * The virtual key VK_DEAD_TILDE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_TILDE = 131;
+
+ /**
+ * The virtual key VK_DEAD_MACRON.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_MACRON = 132;
+
+ /**
+ * The virtual key VK_DEAD_BREVE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_BREVE = 133;
+
+ /**
+ * The virtual key VK_DEAD_ABOVEDOT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_ABOVEDOT = 134;
+
+ /**
+ * The virtual key VK_DEAD_DIAERESIS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_DIAERESIS = 135;
+
+ /**
+ * The virtual key VK_DEAD_ABOVERING.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_ABOVERING = 136;
+
+ /**
+ * The virtual key VK_DEAD_DOUBLEACUTE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_DOUBLEACUTE = 137;
+
+ /**
+ * The virtual key VK_DEAD_CARON.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_CARON = 138;
+
+ /**
+ * The virtual key VK_DEAD_CEDILLA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_CEDILLA = 139;
+
+ /**
+ * The virtual key VK_DEAD_OGONEK.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_OGONEK = 140;
+
+ /**
+ * The virtual key VK_DEAD_IOTA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_IOTA = 141;
+
+ /**
+ * The virtual key VK_DEAD_VOICED_SOUND.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_VOICED_SOUND = 142;
+
+ /**
+ * The virtual key VK_DEAD_SEMIVOICED_SOUND.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DEAD_SEMIVOICED_SOUND = 143;
+
+ /**
+ * The virtual key VK_AMPERSAND.
+ *
+ * @since 1.2
+ */
+ public static final int VK_AMPERSAND = 150;
+
+ /**
+ * The virtual key VK_ASTERISK.
+ *
+ * @since 1.2
+ */
+ public static final int VK_ASTERISK = 151;
+
+ /**
+ * The virtual key VK_QUOTEDBL.
+ *
+ * @since 1.2
+ */
+ public static final int VK_QUOTEDBL = 152;
+
+ /**
+ * The virtual key VK_LESS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_LESS = 153;
+
+ /**
+ * The virtual key VK_GREATER.
+ *
+ * @since 1.2
+ */
+ public static final int VK_GREATER = 160;
+
+ /**
+ * The virtual key VK_BRACELEFT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_BRACELEFT = 161;
+
+ /**
+ * The virtual key VK_BRACERIGHT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_BRACERIGHT = 162;
+
+ /**
+ * The virtual key VK_AT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_AT = 512;
+
+ /**
+ * The virtual key VK_COLON.
+ *
+ * @since 1.2
+ */
+ public static final int VK_COLON = 513;
+
+ /**
+ * The virtual key VK_CIRCUMFLEX.
+ *
+ * @since 1.2
+ */
+ public static final int VK_CIRCUMFLEX = 514;
+
+ /**
+ * The virtual key VK_DOLLAR.
+ *
+ * @since 1.2
+ */
+ public static final int VK_DOLLAR = 515;
+
+ /**
+ * The virtual key VK_EURO_SIGN.
+ *
+ * @since 1.2
+ */
+ public static final int VK_EURO_SIGN = 516;
+
+ /**
+ * The virtual key VK_EXCLAMATION_MARK.
+ *
+ * @since 1.2
+ */
+ public static final int VK_EXCLAMATION_MARK = 517;
+
+ /**
+ * The virtual key VK_INVERTED_EXCLAMATION_MARK.
+ *
+ * @since 1.2
+ */
+ public static final int VK_INVERTED_EXCLAMATION_MARK = 518;
+
+ /**
+ * The virtual key VK_LEFT_PARENTHESIS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_LEFT_PARENTHESIS = 519;
+
+ /**
+ * The virtual key VK_NUMBER_SIGN.
+ *
+ * @since 1.2
+ */
+ public static final int VK_NUMBER_SIGN = 520;
+
+ /**
+ * The virtual key VK_PLUS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_PLUS = 521;
+
+ /**
+ * The virtual key VK_RIGHT_PARENTHESIS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_RIGHT_PARENTHESIS = 522;
+
+ /**
+ * The virtual key VK_UNDERSCORE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_UNDERSCORE = 523;
+
+ /** The virtual key VK_FINAL. */
+ public static final int VK_FINAL = 24;
+
+ /** The virtual key VK_CONVERT. */
+ public static final int VK_CONVERT = 28;
+
+ /** The virtual key VK_NONCONVERT. */
+ public static final int VK_NONCONVERT = 29;
+
+ /** The virtual key VK_ACCEPT. */
+ public static final int VK_ACCEPT = 30;
+
+ /** The virtual key VK_MODECHANGE. */
+ public static final int VK_MODECHANGE = 31;
+
+ /** The virtual key VK_KANA. */
+ public static final int VK_KANA = 21;
+
+ /** The virtual key VK_KANJI. */
+ public static final int VK_KANJI = 25;
+
+ /**
+ * The virtual key VK_ALPHANUMERIC.
+ *
+ * @since 1.2
+ */
+ public static final int VK_ALPHANUMERIC = 240;
+
+ /**
+ * The virtual key VK_KATAKANA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_KATAKANA = 241;
+
+ /**
+ * The virtual key VK_HIRAGANA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_HIRAGANA = 242;
+
+ /**
+ * The virtual key VK_FULL_WIDTH.
+ *
+ * @since 1.2
+ */
+ public static final int VK_FULL_WIDTH = 243;
+
+ /**
+ * The virtual key VK_HALF_WIDTH.
+ *
+ * @since 1.2
+ */
+ public static final int VK_HALF_WIDTH = 244;
+
+ /**
+ * The virtual key VK_ROMAN_CHARACTERS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_ROMAN_CHARACTERS = 245;
+
+ /**
+ * The virtual key VK_ALL_CANDIDATES.
+ *
+ * @since 1.2
+ */
+ public static final int VK_ALL_CANDIDATES = 256;
+
+ /**
+ * The virtual key VK_PREVIOUS_CANDIDATE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_PREVIOUS_CANDIDATE = 257;
+
+ /**
+ * The virtual key VK_CODE_INPUT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_CODE_INPUT = 258;
+
+ /**
+ * The virtual key VK_JAPANESE_KATAKANA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_JAPANESE_KATAKANA = 259;
+
+ /**
+ * The virtual key VK_JAPANESE_HIRAGANA.
+ *
+ * @since 1.2
+ */
+ public static final int VK_JAPANESE_HIRAGANA = 260;
+
+ /**
+ * The virtual key VK_JAPANESE_ROMAN.
+ *
+ * @since 1.2
+ */
+ public static final int VK_JAPANESE_ROMAN = 261;
+
+ /**
+ * The virtual key VK_KANA_LOCK.
+ *
+ * @since 1.3
+ */
+ public static final int VK_KANA_LOCK = 262;
+
+ /**
+ * The virtual key VK_INPUT_METHOD_ON_OFF.
+ *
+ * @since 1.3
+ */
+ public static final int VK_INPUT_METHOD_ON_OFF = 263;
+
+ /**
+ * The virtual key VK_CUT.
+ *
+ * @since 1.2
+ */
+ public static final int VK_CUT = 65489;
+
+ /**
+ * The virtual key VK_COPY.
+ *
+ * @since 1.2
+ */
+ public static final int VK_COPY = 65485;
+
+ /**
+ * The virtual key VK_PASTE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_PASTE = 65487;
+
+ /**
+ * The virtual key VK_UNDO.
+ *
+ * @since 1.2
+ */
+ public static final int VK_UNDO = 65483;
+
+ /**
+ * The virtual key VK_AGAIN.
+ *
+ * @since 1.2
+ */
+ public static final int VK_AGAIN = 65481;
+
+ /**
+ * The virtual key VK_FIND.
+ *
+ * @since 1.2
+ */
+ public static final int VK_FIND = 65488;
+
+ /**
+ * The virtual key VK_PROPS.
+ *
+ * @since 1.2
+ */
+ public static final int VK_PROPS = 65482;
+
+ /**
+ * The virtual key VK_STOP.
+ *
+ * @since 1.2
+ */
+ public static final int VK_STOP = 65480;
+
+ /**
+ * The virtual key VK_COMPOSE.
+ *
+ * @since 1.2
+ */
+ public static final int VK_COMPOSE = 65312;
+
+ /**
+ * The virtual key VK_ALT_GRAPH.
+ *
+ * @since 1.2
+ */
+ public static final int VK_ALT_GRAPH = 65406;
+
+ /**
+ * The 'begin' key VK_BEGIN
+ *
+ * @since 1.5
+ */
+ public static final int VK_BEGIN = 65368;
+
+ /**
+ * The context-menu key VK_CONTEXT_MENU
+ *
+ * @since 1.5
+ */
+ public static final int VK_CONTEXT_MENU = 525;
+
+ /**
+ * The 'Windows' key VK_WINDOWS
+ *
+ * @since 1.5
+ */
+ public static final int VK_WINDOWS = 524;
+
+ /**
+ * The virtual key VK_UNDEFINED. This is used for key typed events, which
+ * do not have a virtual key.
+ */
+ public static final int VK_UNDEFINED = 0;
+
+ /**
+ * The only char with no valid Unicode interpretation. This is used for
+ * key pressed and key released events which do not have a valid keyChar.
+ */
+ public static final char CHAR_UNDEFINED = '\uffff';
+
+ /**
+ * Indicates unknown or irrelavent key location. This is also used for
+ * key typed events, which do not need a location.
+ *
+ * @since 1.4
+ */
+ public static final int KEY_LOCATION_UNKNOWN = 0;
+
+ /**
+ * Indicates a standard key location, with no left/right variants and not
+ * on the numeric pad.
+ *
+ * @since 1.4
+ */
+ public static final int KEY_LOCATION_STANDARD = 1;
+
+ /**
+ * Indicates the key is on the left side of the keyboard, such as the left
+ * shift.
+ *
+ * @since 1.4
+ */
+ public static final int KEY_LOCATION_LEFT = 2;
+
+ /**
+ * Indicates the key is on the right side of the keyboard, such as the right
+ * shift.
+ *
+ * @since 1.4
+ */
+ public static final int KEY_LOCATION_RIGHT = 3;
+
+ /**
+ * Indicates the key is on the numeric pad, such as the numpad 0.
+ *
+ * @since 1.4
+ */
+ public static final int KEY_LOCATION_NUMPAD = 4;
+
+ /**
+ * The code assigned to the physical keyboard location (as adjusted by the
+ * keyboard layout). Use the symbolic VK_* names instead of numbers.
+ *
+ * @see #getKeyCode()
+ * @serial the VK_ code for this key
+ */
+ private int keyCode;
+
+ /**
+ * The Unicode character produced by the key type event. This has no meaning
+ * for key pressed and key released events.
+ *
+ * @see #getKeyChar()
+ * @serial the Unicode value for this key
+ */
+ private char keyChar;
+
+ /**
+ * The keyboard location of the key. One of {@link #KEY_LOCATION_UNKNOWN},
+ * {@link #KEY_LOCATION_STANDARD}, {@link #KEY_LOCATION_LEFT},
+ * {@link #KEY_LOCATION_RIGHT}, or {@link #KEY_LOCATION_NUMPAD}.
+ *
+ * @see #getKeyLocation()
+ * @serial the key location
+ * @since 1.4
+ */
+ private final int keyLocation;
+
+ /**
+ * Stores the state of the native event dispatching system, to correctly
+ * dispatch in Component#dispatchEventImpl when a proxy is active.
+ *
+ * XXX Does this matter in Classpath?
+ *
+ * @serial whether the proxy is active
+ */
+ private boolean isProxyActive;
+
+
+ /**
+ * Initializes a new instance of <code>KeyEvent</code> with the specified
+ * information. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the component that generated this event
+ * @param id the event id
+ * @param when the timestamp when the even occurred
+ * @param modifiers the modifier keys during the event, in old or new style
+ * @param keyCode the integer constant for the virtual key type
+ * @param keyChar the Unicode value of the key
+ * @param keyLocation the location of the key
+ * @throws IllegalArgumentException if source is null, if keyLocation is
+ * invalid, or if (id == KEY_TYPED && (keyCode != VK_UNDEFINED
+ * || keyChar == CHAR_UNDEFINED))
+ */
+ public KeyEvent(Component source, int id, long when, int modifiers,
+ int keyCode, char keyChar, int keyLocation)
+ {
+ super(source, id, when, modifiers);
+ this.keyCode = keyCode;
+ this.keyChar = keyChar;
+ this.keyLocation = keyLocation;
+ if ((id == KEY_TYPED && (keyCode != VK_UNDEFINED
+ || keyChar == CHAR_UNDEFINED))
+ || keyLocation < KEY_LOCATION_UNKNOWN
+ || keyLocation > KEY_LOCATION_NUMPAD)
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * Initializes a new instance of <code>KeyEvent</code> with the specified
+ * information. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the component that generated this event
+ * @param id the event id
+ * @param when the timestamp when the even occurred
+ * @param modifiers the modifier keys during the event, in old or new style
+ * @param keyCode the integer constant for the virtual key type
+ * @param keyChar the Unicode value of the key
+ * @throws IllegalArgumentException if source is null, or if
+ * (id == KEY_TYPED && (keyCode != VK_UNDEFINED
+ * || keyChar == CHAR_UNDEFINED))
+ */
+ public KeyEvent(Component source, int id, long when, int modifiers,
+ int keyCode, char keyChar)
+ {
+ this(source, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN);
+ }
+
+ /**
+ * Initializes a new instance of <code>KeyEvent</code> with the specified
+ * information. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the component that generated this event
+ * @param id the event id
+ * @param when the timestamp when the even occurred
+ * @param modifiers the modifier keys during the event, in old or new style
+ * @param keyCode the integer constant for the virtual key type
+ * @throws IllegalArgumentException if source is null, or if
+ * id == KEY_TYPED but keyCode != VK_UNDEFINED
+ *
+ * @deprecated
+ */
+ public KeyEvent(Component source, int id, long when, int modifiers,
+ int keyCode)
+ {
+ this(source, id, when, modifiers, keyCode, '\0', KEY_LOCATION_UNKNOWN);
+ }
+
+ /**
+ * Returns the key code for the event key. This will be one of the
+ * <code>VK_*</code> constants defined in this class. If the event type is
+ * KEY_TYPED, the result will be VK_UNDEFINED.
+ *
+ * @return the key code for this event
+ */
+ public int getKeyCode()
+ {
+ return keyCode;
+ }
+
+ /**
+ * Sets the key code for this event. This must be one of the
+ * <code>VK_*</code> constants defined in this class.
+ *
+ * @param keyCode the new key code for this event
+ */
+ public void setKeyCode(int keyCode)
+ {
+ this.keyCode = keyCode;
+ }
+
+ /**
+ * Returns the Unicode value for the event key. This will be
+ * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for
+ * this key, usually when this is a KEY_PRESSED or KEY_RELEASED event.
+ *
+ * @return the Unicode character for this event
+ */
+ public char getKeyChar()
+ {
+ return keyChar;
+ }
+
+ /**
+ * Sets the Unicode character for this event to the specified value.
+ *
+ * @param keyChar the new Unicode character for this event
+ */
+ public void setKeyChar(char keyChar)
+ {
+ this.keyChar = keyChar;
+ }
+
+ /**
+ * Sets the modifier keys to the specified value. This should be a union
+ * of the bit mask constants from <code>InputEvent</code>. The use of this
+ * method is not recommended, particularly for KEY_TYPED events, which do
+ * not check if the modifiers were changed.
+ *
+ * @param modifiers the new modifier value, in either old or new style
+ * @see InputEvent
+ *
+ * @deprecated
+ */
+ public void setModifiers(int modifiers)
+ {
+ this.modifiers = EventModifier.extend(modifiers);
+ }
+
+ /**
+ * Returns the keyboard location of the key that generated this event. This
+ * provides a way to distinguish between keys like left and right shift
+ * which share a common key code. The result will be one of
+ * {@link #KEY_LOCATION_UNKNOWN}, {@link #KEY_LOCATION_STANDARD},
+ * {@link #KEY_LOCATION_LEFT}, {@link #KEY_LOCATION_RIGHT}, or
+ * {@link #KEY_LOCATION_NUMPAD}.
+ *
+ * @return the key location
+ * @since 1.4
+ */
+ public int getKeyLocation()
+ {
+ return keyLocation;
+ }
+
+ /**
+ * Returns the text name of key code, such as "HOME", "F1", or "A".
+ *
+ * XXX Sun claims this can be localized via the awt.properties file - how
+ * do we implement that?
+ *
+ * @return the text name of the key code
+ */
+ public static String getKeyText(int keyCode)
+ {
+ switch (keyCode)
+ {
+ case VK_CANCEL:
+ return "Cancel";
+ case VK_BACK_SPACE:
+ return "Backspace";
+ case VK_TAB:
+ return "Tab";
+ case VK_ENTER:
+ return "Enter";
+ case VK_CLEAR:
+ return "Clear";
+ case VK_SHIFT:
+ return "Shift";
+ case VK_CONTROL:
+ return "Ctrl";
+ case VK_ALT:
+ return "Alt";
+ case VK_PAUSE:
+ return "Pause";
+ case VK_CAPS_LOCK:
+ return "Caps Lock";
+ case VK_KANA:
+ return "Kana";
+ case VK_FINAL:
+ return "Final";
+ case VK_KANJI:
+ return "Kanji";
+ case VK_ESCAPE:
+ return "Escape";
+ case VK_CONVERT:
+ return "Convert";
+ case VK_NONCONVERT:
+ return "No Convert";
+ case VK_ACCEPT:
+ return "Accept";
+ case VK_MODECHANGE:
+ return "Mode Change";
+ case VK_SPACE:
+ return "Space";
+ case VK_PAGE_UP:
+ return "Page Up";
+ case VK_PAGE_DOWN:
+ return "Page Down";
+ case VK_END:
+ return "End";
+ case VK_HOME:
+ return "Home";
+ case VK_LEFT:
+ case VK_KP_LEFT:
+ return "Left";
+ case VK_UP:
+ case VK_KP_UP:
+ return "Up";
+ case VK_RIGHT:
+ case VK_KP_RIGHT:
+ return "Right";
+ case VK_DOWN:
+ case VK_KP_DOWN:
+ return "Down";
+ case VK_MINUS:
+ return "Minus";
+ case VK_MULTIPLY:
+ return "NumPad *";
+ case VK_ADD:
+ return "NumPad +";
+ case VK_SEPARATOR:
+ return "NumPad ,";
+ case VK_SUBTRACT:
+ return "NumPad -";
+ case VK_DECIMAL:
+ return "NumPad .";
+ case VK_DIVIDE:
+ return "NumPad /";
+ case VK_DELETE:
+ return "Delete";
+ case VK_DEAD_GRAVE:
+ return "Dead Grave";
+ case VK_DEAD_ACUTE:
+ return "Dead Acute";
+ case VK_DEAD_CIRCUMFLEX:
+ return "Dead Circumflex";
+ case VK_DEAD_TILDE:
+ return "Dead Tilde";
+ case VK_DEAD_MACRON:
+ return "Dead Macron";
+ case VK_DEAD_BREVE:
+ return "Dead Breve";
+ case VK_DEAD_ABOVEDOT:
+ return "Dead Above Dot";
+ case VK_DEAD_DIAERESIS:
+ return "Dead Diaeresis";
+ case VK_DEAD_ABOVERING:
+ return "Dead Above Ring";
+ case VK_DEAD_DOUBLEACUTE:
+ return "Dead Double Acute";
+ case VK_DEAD_CARON:
+ return "Dead Caron";
+ case VK_DEAD_CEDILLA:
+ return "Dead Cedilla";
+ case VK_DEAD_OGONEK:
+ return "Dead Ogonek";
+ case VK_DEAD_IOTA:
+ return "Dead Iota";
+ case VK_DEAD_VOICED_SOUND:
+ return "Dead Voiced Sound";
+ case VK_DEAD_SEMIVOICED_SOUND:
+ return "Dead Semivoiced Sound";
+ case VK_NUM_LOCK:
+ return "Num Lock";
+ case VK_SCROLL_LOCK:
+ return "Scroll Lock";
+ case VK_AMPERSAND:
+ return "Ampersand";
+ case VK_ASTERISK:
+ return "Asterisk";
+ case VK_QUOTEDBL:
+ return "Double Quote";
+ case VK_LESS:
+ return "Less";
+ case VK_PRINTSCREEN:
+ return "Print Screen";
+ case VK_INSERT:
+ return "Insert";
+ case VK_HELP:
+ return "Help";
+ case VK_META:
+ return "Meta";
+ case VK_GREATER:
+ return "Greater";
+ case VK_BRACELEFT:
+ return "Left Brace";
+ case VK_BRACERIGHT:
+ return "Right Brace";
+ case VK_BACK_QUOTE:
+ return "Back Quote";
+ case VK_QUOTE:
+ return "Quote";
+ case VK_ALPHANUMERIC:
+ return "Alphanumeric";
+ case VK_KATAKANA:
+ return "Katakana";
+ case VK_HIRAGANA:
+ return "Hiragana";
+ case VK_FULL_WIDTH:
+ return "Full-Width";
+ case VK_HALF_WIDTH:
+ return "Half-Width";
+ case VK_ROMAN_CHARACTERS:
+ return "Roman Characters";
+ case VK_ALL_CANDIDATES:
+ return "All Candidates";
+ case VK_PREVIOUS_CANDIDATE:
+ return "Previous Candidate";
+ case VK_CODE_INPUT:
+ return "Code Input";
+ case VK_JAPANESE_KATAKANA:
+ return "Japanese Katakana";
+ case VK_JAPANESE_HIRAGANA:
+ return "Japanese Hiragana";
+ case VK_JAPANESE_ROMAN:
+ return "Japanese Roman";
+ case VK_KANA_LOCK:
+ return "Kana Lock";
+ case VK_INPUT_METHOD_ON_OFF:
+ return "Input Method On/Off";
+ case VK_AT:
+ return "At";
+ case VK_COLON:
+ return "Colon";
+ case VK_CIRCUMFLEX:
+ return "Circumflex";
+ case VK_DOLLAR:
+ return "Dollar";
+ case VK_EURO_SIGN:
+ return "Euro";
+ case VK_EXCLAMATION_MARK:
+ return "Exclamation Mark";
+ case VK_INVERTED_EXCLAMATION_MARK:
+ return "Inverted Exclamation Mark";
+ case VK_LEFT_PARENTHESIS:
+ return "Left Parenthesis";
+ case VK_NUMBER_SIGN:
+ return "Number Sign";
+ case VK_PLUS:
+ return "Plus";
+ case VK_RIGHT_PARENTHESIS:
+ return "Right Parenthesis";
+ case VK_UNDERSCORE:
+ return "Underscore";
+ case VK_COMPOSE:
+ return "Compose";
+ case VK_ALT_GRAPH:
+ return "Alt Graph";
+ case VK_STOP:
+ return "Stop";
+ case VK_AGAIN:
+ return "Again";
+ case VK_PROPS:
+ return "Props";
+ case VK_UNDO:
+ return "Undo";
+ case VK_COPY:
+ return "Copy";
+ case VK_PASTE:
+ return "Paste";
+ case VK_FIND:
+ return "Find";
+ case VK_CUT:
+ return "Cut";
+ case VK_COMMA:
+ case VK_PERIOD:
+ case VK_SLASH:
+ case VK_0:
+ case VK_1:
+ case VK_2:
+ case VK_3:
+ case VK_4:
+ case VK_5:
+ case VK_6:
+ case VK_7:
+ case VK_8:
+ case VK_9:
+ case VK_SEMICOLON:
+ case VK_EQUALS:
+ case VK_A:
+ case VK_B:
+ case VK_C:
+ case VK_D:
+ case VK_E:
+ case VK_F:
+ case VK_G:
+ case VK_H:
+ case VK_I:
+ case VK_J:
+ case VK_K:
+ case VK_L:
+ case VK_M:
+ case VK_N:
+ case VK_O:
+ case VK_P:
+ case VK_Q:
+ case VK_R:
+ case VK_S:
+ case VK_T:
+ case VK_U:
+ case VK_V:
+ case VK_W:
+ case VK_X:
+ case VK_Y:
+ case VK_Z:
+ case VK_OPEN_BRACKET:
+ case VK_BACK_SLASH:
+ case VK_CLOSE_BRACKET:
+ return "" + (char) keyCode;
+ case VK_NUMPAD0:
+ case VK_NUMPAD1:
+ case VK_NUMPAD2:
+ case VK_NUMPAD3:
+ case VK_NUMPAD4:
+ case VK_NUMPAD5:
+ case VK_NUMPAD6:
+ case VK_NUMPAD7:
+ case VK_NUMPAD8:
+ case VK_NUMPAD9:
+ return "NumPad-" + (keyCode - VK_NUMPAD0);
+ case VK_F1:
+ case VK_F2:
+ case VK_F3:
+ case VK_F4:
+ case VK_F5:
+ case VK_F6:
+ case VK_F7:
+ case VK_F8:
+ case VK_F9:
+ case VK_F10:
+ case VK_F11:
+ case VK_F12:
+ return "F" + (keyCode - (VK_F1 - 1));
+ case VK_F13:
+ case VK_F14:
+ case VK_F15:
+ case VK_F16:
+ case VK_F17:
+ case VK_F18:
+ case VK_F19:
+ case VK_F20:
+ case VK_F21:
+ case VK_F22:
+ case VK_F23:
+ case VK_F24:
+ return "F" + (keyCode - (VK_F13 - 13));
+ default:
+ // This is funky on negative numbers, but that's Sun's fault.
+ return "Unknown keyCode: 0x" + (keyCode < 0 ? "-" : "")
+ + Integer.toHexString(Math.abs(keyCode));
+ }
+ }
+
+ /**
+ * Returns a string describing the modifiers, such as "Shift" or
+ * "Ctrl+Button1".
+ *
+ * XXX Sun claims this can be localized via the awt.properties file - how
+ * do we implement that?
+ *
+ * @param modifiers the old-style modifiers to convert to text
+ * @return a string representation of the modifiers in this bitmask
+ */
+ public static String getKeyModifiersText(int modifiers)
+ {
+ return getModifiersExText(EventModifier.extend(modifiers
+ & EventModifier.OLD_MASK));
+ }
+
+ /**
+ * Tests whether or not this key is an action key. An action key typically
+ * does not fire a KEY_TYPED event, and is not a modifier.
+ *
+ * @return true if this is an action key
+ */
+ public boolean isActionKey()
+ {
+ switch (keyCode)
+ {
+ case VK_PAUSE:
+ case VK_CAPS_LOCK:
+ case VK_KANA:
+ case VK_FINAL:
+ case VK_KANJI:
+ case VK_CONVERT:
+ case VK_NONCONVERT:
+ case VK_ACCEPT:
+ case VK_MODECHANGE:
+ case VK_PAGE_UP:
+ case VK_PAGE_DOWN:
+ case VK_END:
+ case VK_HOME:
+ case VK_LEFT:
+ case VK_UP:
+ case VK_RIGHT:
+ case VK_DOWN:
+ case VK_F1:
+ case VK_F2:
+ case VK_F3:
+ case VK_F4:
+ case VK_F5:
+ case VK_F6:
+ case VK_F7:
+ case VK_F8:
+ case VK_F9:
+ case VK_F10:
+ case VK_F11:
+ case VK_F12:
+ case VK_NUM_LOCK:
+ case VK_SCROLL_LOCK:
+ case VK_PRINTSCREEN:
+ case VK_INSERT:
+ case VK_HELP:
+ case VK_KP_UP:
+ case VK_KP_DOWN:
+ case VK_KP_LEFT:
+ case VK_KP_RIGHT:
+ case VK_ALPHANUMERIC:
+ case VK_KATAKANA:
+ case VK_HIRAGANA:
+ case VK_FULL_WIDTH:
+ case VK_HALF_WIDTH:
+ case VK_ROMAN_CHARACTERS:
+ case VK_ALL_CANDIDATES:
+ case VK_PREVIOUS_CANDIDATE:
+ case VK_CODE_INPUT:
+ case VK_JAPANESE_KATAKANA:
+ case VK_JAPANESE_HIRAGANA:
+ case VK_JAPANESE_ROMAN:
+ case VK_KANA_LOCK:
+ case VK_INPUT_METHOD_ON_OFF:
+ case VK_F13:
+ case VK_F14:
+ case VK_F15:
+ case VK_F16:
+ case VK_F17:
+ case VK_F18:
+ case VK_F19:
+ case VK_F20:
+ case VK_F21:
+ case VK_F22:
+ case VK_F23:
+ case VK_F24:
+ case VK_STOP:
+ case VK_AGAIN:
+ case VK_PROPS:
+ case VK_UNDO:
+ case VK_COPY:
+ case VK_PASTE:
+ case VK_FIND:
+ case VK_CUT:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Returns a string identifying the event. This is formatted as the
+ * field name of the id type, followed by the keyCode, then the
+ * keyChar, modifiers (if any), extModifiers (if any), and
+ * keyLocation.
+ *
+ * @return a string identifying the event
+ */
+ public String paramString()
+ {
+ StringBuffer s = new StringBuffer();
+
+ switch (id)
+ {
+ case KEY_PRESSED:
+ s.append("KEY_PRESSED");
+ break;
+ case KEY_RELEASED:
+ s.append("KEY_RELEASED");
+ break;
+ case KEY_TYPED:
+ s.append("KEY_TYPED");
+ break;
+ default:
+ s.append("unknown type");
+ }
+
+ s.append(",keyCode=").append(keyCode);
+
+ s.append(",keyText=").append(getKeyText(keyCode));
+
+ s.append(",keyChar=");
+ if (isActionKey()
+ || keyCode == VK_SHIFT
+ || keyCode == VK_CONTROL
+ || keyCode == VK_ALT)
+ s.append("Undefined keyChar");
+ else
+ {
+ /* This output string must be selected by examining keyChar
+ * rather than keyCode, because key code information is not
+ * included in KEY_TYPED events.
+ */
+ if (keyChar == VK_BACK_SPACE
+ || keyChar == VK_TAB
+ || keyChar == VK_ENTER
+ || keyChar == VK_ESCAPE
+ || keyChar == VK_DELETE)
+ s.append(getKeyText(keyChar));
+ else
+ s.append("'").append(keyChar).append("'");
+ }
+
+ if ((modifiers & CONVERT_MASK) != 0)
+ s.append(",modifiers=").append(getModifiersExText(modifiers
+ & CONVERT_MASK));
+ if (modifiers != 0)
+ s.append(",extModifiers=").append(getModifiersExText(modifiers));
+
+ s.append(",keyLocation=KEY_LOCATION_");
+ switch (keyLocation)
+ {
+ case KEY_LOCATION_UNKNOWN:
+ s.append("UNKNOWN");
+ break;
+ case KEY_LOCATION_STANDARD:
+ s.append("STANDARD");
+ break;
+ case KEY_LOCATION_LEFT:
+ s.append("LEFT");
+ break;
+ case KEY_LOCATION_RIGHT:
+ s.append("RIGHT");
+ break;
+ case KEY_LOCATION_NUMPAD:
+ s.append("NUMPAD");
+ }
+
+ return s.toString();
+ }
+
+ /**
+ * Reads in the object from a serial stream.
+ *
+ * @param s the stream to read from
+ * @throws IOException if deserialization fails
+ * @throws ClassNotFoundException if deserialization fails
+ * @serialData default, except that the modifiers are converted to new style
+ */
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK;
+ }
+} // class KeyEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/KeyListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,77 @@
+/* KeyListener.java -- listen for keyboard presses
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to receive keyboard events. To
+ * watch a subset of these events, use a KeyAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see KeyAdapter
+ * @see KeyEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface KeyListener extends EventListener
+{
+ /**
+ * This method is called when a key is typed. A key is considered typed
+ * when it and all modifiers have been pressed and released, mapping to
+ * a single virtual key.
+ *
+ * @param event the <code>KeyEvent</code> indicating that a key was typed
+ */
+ void keyTyped(KeyEvent event);
+
+ /**
+ * This method is called when a key is pressed.
+ *
+ * @param event the <code>KeyEvent</code> indicating the key press
+ */
+ void keyPressed(KeyEvent event);
+
+ /**
+ * This method is called when a key is released.
+ *
+ * @param event the <code>KeyEvent</code> indicating the key release
+ */
+ void keyReleased(KeyEvent event);
+} // interface KeyListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,106 @@
+/* MouseAdapter.java -- convenience class for writing mouse listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>MouseListener</code> and implements all methods
+ * with empty bodies. This allows a listener interested in implementing only
+ * a subset of the <code>MouseListener</code> interface to extend this class
+ * and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see MouseEvent
+ * @see MouseListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class MouseAdapter implements MouseListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public MouseAdapter()
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseClicked(MouseEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mousePressed(MouseEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseReleased(MouseEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseEntered(MouseEvent event)
+ {
+ }
+
+ /**
+ * Implements this method in the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseExited(MouseEvent event)
+ {
+ }
+} // class MouseAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,435 @@
+/* MouseEvent.java -- a mouse event
+ Copyright (C) 1999, 2002, 2004, 2005 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., 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.event;
+
+import gnu.java.awt.EventModifier;
+
+import java.awt.Component;
+import java.awt.Point;
+import java.awt.PopupMenu;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+/**
+ * This event is generated for a mouse event. There are three main categories
+ * of mouse events: Regular events include pressing, releasing, and clicking
+ * buttons, as well as moving over the boundary of the unobscured portion of
+ * a component. Motion events include movement and dragging. Wheel events are
+ * covered separately by the subclass MouseWheelEvent.
+ *
+ * <p>A mouse event is tied to the unobstructed visible component that the
+ * mouse cursor was over at the time of the action. The button that was
+ * most recently pressed is the only one that shows up in
+ * <code>getModifiers</code>, and is returned by <code>getButton</code>,
+ * while all buttons that are down show up in <code>getModifiersEx</code>.
+ *
+ * <p>Drag events may be cut short if native drag-and-drop operations steal
+ * the event. Likewise, if a mouse drag exceeds the bounds of a window or
+ * virtual device, some platforms may clip the path to fit in the bounds of
+ * the component.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see MouseAdapter
+ * @see MouseListener
+ * @see MouseMotionAdapter
+ * @see MouseMotionListener
+ * @see MouseWheelListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class MouseEvent extends InputEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -991214153494842848L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int MOUSE_FIRST = 500;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int MOUSE_LAST = 507;
+
+ /** This event id indicates that the mouse was clicked. */
+ public static final int MOUSE_CLICKED = 500;
+
+ /** This event id indicates that the mouse was pressed. */
+ public static final int MOUSE_PRESSED = 501;
+
+ /** This event id indicates that the mouse was released. */
+ public static final int MOUSE_RELEASED = 502;
+
+ /** This event id indicates that the mouse was moved. */
+ public static final int MOUSE_MOVED = 503;
+
+ /** This event id indicates that the mouse entered a component. */
+ public static final int MOUSE_ENTERED = 504;
+
+ /** This event id indicates that the mouse exited a component. */
+ public static final int MOUSE_EXITED = 505;
+
+ /**
+ * This indicates that no button changed state.
+ *
+ * @see #getButton()
+ * @since 1.4
+ */
+ public static final int NOBUTTON = 0;
+
+ /**
+ * This indicates that button 1 changed state.
+ *
+ * @see #getButton()
+ * @since 1.4
+ */
+ public static final int BUTTON1 = 1;
+
+ /**
+ * This indicates that button 2 changed state.
+ *
+ * @see #getButton()
+ * @since 1.4
+ */
+ public static final int BUTTON2 = 2;
+
+ /**
+ * This indicates that button 3 changed state.
+ *
+ * @see #getButton()
+ * @since 1.4
+ */
+ public static final int BUTTON3 = 3;
+
+ /** This event id indicates that the mouse was dragged over a component. */
+ public static final int MOUSE_DRAGGED = 506;
+
+ /**
+ * This event id indicates that the mouse wheel was rotated.
+ *
+ * @since 1.4
+ */
+ public static final int MOUSE_WHEEL = 507;
+
+ /**
+ * The X coordinate of the mouse cursor at the time of the event.
+ *
+ * @see #getX()
+ * @serial the x coordinate
+ */
+ private int x;
+
+ /**
+ * The Y coordinate of the mouse cursor at the time of the event.
+ *
+ * @see #getY()
+ * @serial the y coordinate
+ */
+ private int y;
+
+ /**
+ * The number of clicks that took place. For MOUSE_CLICKED, MOUSE_PRESSED,
+ * and MOUSE_RELEASED, this will be at least 1; otherwise it is 0.
+ *
+ * see #getClickCount()
+ * @serial the number of clicks
+ */
+ private final int clickCount;
+
+ /**
+ * Indicates which mouse button changed state. Can only be one of
+ * {@link #NOBUTTON}, {@link #BUTTON1}, {@link #BUTTON2}, or
+ * {@link #BUTTON3}.
+ *
+ * @see #getButton()
+ * @since 1.4
+ */
+ private int button;
+
+ /**
+ * Whether or not this event should trigger a popup menu.
+ *
+ * @see PopupMenu
+ * @see #isPopupTrigger()
+ * @serial true if this is a popup trigger
+ */
+ private final boolean popupTrigger;
+
+ /**
+ * Initializes a new instance of <code>MouseEvent</code> with the specified
+ * information. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param when the timestamp of when the event occurred
+ * @param modifiers the modifier keys during the event, in old or new style
+ * @param x the X coordinate of the mouse point
+ * @param y the Y coordinate of the mouse point
+ * @param clickCount the number of mouse clicks for this event
+ * @param popupTrigger true if this event triggers a popup menu
+ * @param button the most recent mouse button to change state
+ * @throws IllegalArgumentException if source is null or button is invalid
+ * @since 1.4
+ */
+ public MouseEvent(Component source, int id, long when, int modifiers,
+ int x, int y, int clickCount, boolean popupTrigger,
+ int button)
+ {
+ super(source, id, when, modifiers);
+ this.x = x;
+ this.y = y;
+ this.clickCount = clickCount;
+ this.popupTrigger = popupTrigger;
+ this.button = button;
+ if (button < NOBUTTON || button > BUTTON3)
+ throw new IllegalArgumentException();
+ if ((modifiers & EventModifier.OLD_MASK) != 0)
+ {
+ if ((modifiers & BUTTON1_MASK) != 0)
+ this.button = BUTTON1;
+ else if ((modifiers & BUTTON2_MASK) != 0)
+ this.button = BUTTON2;
+ else if ((modifiers & BUTTON3_MASK) != 0)
+ this.button = BUTTON3;
+ }
+ // clear the mouse button modifier masks if this is a button
+ // release event.
+ if (id == MOUSE_RELEASED)
+ this.modifiersEx &= ~(BUTTON1_DOWN_MASK
+ | BUTTON2_DOWN_MASK
+ | BUTTON3_DOWN_MASK);
+ }
+
+ /**
+ * Initializes a new instance of <code>MouseEvent</code> with the specified
+ * information. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param when the timestamp of when the event occurred
+ * @param modifiers the modifier keys during the event, in old or new style
+ * @param x the X coordinate of the mouse point
+ * @param y the Y coordinate of the mouse point
+ * @param clickCount the number of mouse clicks for this event
+ * @param popupTrigger true if this event triggers a popup menu
+ * @throws IllegalArgumentException if source is null
+ */
+ public MouseEvent(Component source, int id, long when, int modifiers,
+ int x, int y, int clickCount, boolean popupTrigger)
+ {
+ this(source, id, when, modifiers, x, y, clickCount, popupTrigger,
+ NOBUTTON);
+ }
+
+ /**
+ * This method returns the X coordinate of the mouse position. This is
+ * relative to the source component.
+ *
+ * @return the x coordinate
+ */
+ public int getX()
+ {
+ return x;
+ }
+
+ /**
+ * This method returns the Y coordinate of the mouse position. This is
+ * relative to the source component.
+ *
+ * @return the y coordinate
+ */
+ public int getY()
+ {
+ return y;
+ }
+
+ /**
+ * This method returns a <code>Point</code> for the x,y position of
+ * the mouse pointer. This is relative to the source component.
+ *
+ * @return a <code>Point</code> for the event position
+ */
+ public Point getPoint()
+ {
+ return new Point(x, y);
+ }
+
+ /**
+ * Translates the event coordinates by the specified x and y offsets.
+ *
+ * @param dx the value to add to the X coordinate of this event
+ * @param dy the value to add to the Y coordiante of this event
+ */
+ public void translatePoint(int dx, int dy)
+ {
+ x += dx;
+ y += dy;
+ }
+
+ /**
+ * This method returns the number of mouse clicks associated with this
+ * event.
+ *
+ * @return the number of mouse clicks for this event
+ */
+ public int getClickCount()
+ {
+ return clickCount;
+ }
+
+ /**
+ * Returns which button, if any, was the most recent to change state. This
+ * will be one of {@link #NOBUTTON}, {@link #BUTTON1}, {@link #BUTTON2}, or
+ * {@link #BUTTON3}.
+ *
+ * @return the button that changed state
+ * @since 1.4
+ */
+ public int getButton()
+ {
+ return button;
+ }
+
+ /**
+ * This method tests whether or not the event is a popup menu trigger. This
+ * should be checked in both MousePressed and MouseReleased to be
+ * cross-platform compatible, as different systems have different popup
+ * triggers.
+ *
+ * @return true if the event is a popup menu trigger
+ */
+ public boolean isPopupTrigger()
+ {
+ return popupTrigger;
+ }
+
+ /**
+ * Returns a string describing the modifiers, such as "Shift" or
+ * "Ctrl+Button1".
+ *
+ * XXX Sun claims this can be localized via the awt.properties file - how
+ * do we implement that?
+ *
+ * @param modifiers the old-style modifiers to convert to text
+ * @return a string representation of the modifiers in this bitmask
+ */
+ public static String getMouseModifiersText(int modifiers)
+ {
+ modifiers &= EventModifier.OLD_MASK;
+ if ((modifiers & BUTTON2_MASK) != 0)
+ modifiers |= BUTTON2_DOWN_MASK;
+ if ((modifiers & BUTTON3_MASK) != 0)
+ modifiers |= BUTTON3_DOWN_MASK;
+ return getModifiersExText(EventModifier.extend(modifiers));
+ }
+
+ /**
+ * Returns a string identifying this event. This is formatted as the field
+ * name of the id type, followed by the (x,y) point, the most recent button
+ * changed, modifiers (if any), extModifiers (if any), and clickCount.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ StringBuffer s = new StringBuffer();
+ switch (id)
+ {
+ case MOUSE_CLICKED:
+ s.append("MOUSE_CLICKED,(");
+ break;
+ case MOUSE_PRESSED:
+ s.append("MOUSE_PRESSED,(");
+ break;
+ case MOUSE_RELEASED:
+ s.append("MOUSE_RELEASED,(");
+ break;
+ case MOUSE_MOVED:
+ s.append("MOUSE_MOVED,(");
+ break;
+ case MOUSE_ENTERED:
+ s.append("MOUSE_ENTERED,(");
+ break;
+ case MOUSE_EXITED:
+ s.append("MOUSE_EXITED,(");
+ break;
+ case MOUSE_DRAGGED:
+ s.append("MOUSE_DRAGGED,(");
+ break;
+ case MOUSE_WHEEL:
+ s.append("MOUSE_WHEEL,(");
+ break;
+ default:
+ s.append("unknown type,(");
+ }
+ s.append(x).append(',').append(y).append("),button=").append(button);
+ // FIXME: need a mauve test for this method
+ if (modifiersEx != 0)
+ s.append(",extModifiers=").append(getModifiersExText(modifiersEx));
+
+ s.append(",clickCount=").append(clickCount);
+ s.append(",consumed=").append(consumed);
+
+ return s.toString();
+ }
+
+ /**
+ * Reads in the object from a serial stream.
+ *
+ * @param s the stream to read from
+ * @throws IOException if deserialization fails
+ * @throws ClassNotFoundException if deserialization fails
+ * @serialData default, except that the modifiers are converted to new style
+ */
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ if ((modifiers & EventModifier.OLD_MASK) != 0)
+ {
+ if ((modifiers & BUTTON1_MASK) != 0)
+ button = BUTTON1;
+ else if ((modifiers & BUTTON2_MASK) != 0)
+ button = BUTTON2;
+ else if ((modifiers & BUTTON3_MASK) != 0)
+ button = BUTTON3;
+ modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK;
+ }
+ }
+} // class MouseEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,94 @@
+/* MouseListener.java -- listen for mouse clicks and crossing component edges
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to receive mouse events other than
+ * simple motion events. This includes clicks (but not mouse wheel events),
+ * and crossing component boundaries without change in button status. To
+ * track moves and drags, use MouseMotionListener, and to track wheel events,
+ * use MouseWheelListener. To watch a subset of these events, use a
+ * MouseAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see MouseAdapter
+ * @see MouseEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface MouseListener extends EventListener
+{
+ /**
+ * This method is called when the mouse is clicked (pressed and released
+ * in short succession) on a component.
+ *
+ * @param event the <code>MouseEvent</code> indicating the click
+ */
+ void mouseClicked(MouseEvent event);
+
+ /**
+ * This method is called when the mouse is pressed over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the press
+ */
+ void mousePressed(MouseEvent event);
+
+ /**
+ * This method is called when the mouse is released over a component.
+ *
+ * @param event the <code>MouseEvent</code> for the release
+ */
+ void mouseReleased(MouseEvent event);
+
+ /**
+ * This method is called when the mouse enters a component.
+ *
+ * @param event the <code>MouseEvent</code> for the entry
+ */
+ void mouseEntered(MouseEvent event);
+
+ /**
+ * This method is called when the mouse exits a component.
+ *
+ * @param event the <code>MouseEvent</code> for the exit
+ */
+ void mouseExited(MouseEvent event);
+} // interface MouseListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,79 @@
+/* MouseMotionAdapter.java -- convenience class for mouse motion listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>MouseMotionListener</code> and implements all
+ * methods with empty bodies. This allows a listener interested in
+ * implementing only a subset of the <code>MouseMotionListener</code>
+ * interface to extend this class and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see MouseEvent
+ * @see MouseMotionListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class MouseMotionAdapter implements MouseMotionListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public MouseMotionAdapter()
+ {
+ }
+
+ /**
+ * Implement this method in the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseDragged(MouseEvent event)
+ {
+ }
+
+ /**
+ * Implement this method in the interface with an empty body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void mouseMoved(MouseEvent event)
+ {
+ }
+} // class MouseMotionAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseMotionListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,72 @@
+/* MouseMotionListener.java -- listen to mouse motion events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to be notified of mouse movements.
+ * This includes moves and drags, but not crossing component boundaries. To
+ * track other mouse events, use MouseListener or MouseWheelListener. To
+ * watch a subset of these events, use a MouseMotionAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see MouseMotionAdapter
+ * @see MouseEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface MouseMotionListener extends EventListener
+{
+ /**
+ * This method is called when the mouse is moved over a component
+ * while a button has been pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ void mouseDragged(MouseEvent event);
+
+ /**
+ * This method is called when the mouse is moved over a component
+ * while no button is pressed.
+ *
+ * @param event the <code>MouseEvent</code> indicating the motion
+ */
+ void mouseMoved(MouseEvent event);
+} // interface MouseMotionListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,232 @@
+/* MouseWheelEvent.java -- a mouse wheel event
+ Copyright (C) 2002, 2005 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., 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.event;
+
+import java.awt.Adjustable;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.ScrollPane;
+
+import javax.swing.JScrollPane;
+import javax.swing.Scrollable;
+
+/**
+ * This event is generated for a mouse wheel rotation. The wheel (the middle
+ * mouse button on most modern mice) can be rotated towards or away from the
+ * user, and is often used for scrolling.
+ *
+ * <p>Because of the special use for scrolling components, MouseWheelEvents
+ * often affect a different component than the one located at the point of
+ * the event. If the component under the mouse cursor does not accept wheel
+ * events, the event is passed to the first ancestor container which does. This
+ * is often a ScrollPane, which knows how to scroll. If an AWT component is
+ * built from a native widget that knows how to use mouse wheel events, that
+ * component will consume the event.
+ *
+ * <p>The two most common scroll types are "units" (lines at a time) or
+ * "blocks" (pages at a time). The initial setting is taken from the platform,
+ * although the user can adjust the setting at any time.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see MouseWheelListener
+ * @see ScrollPane
+ * @see ScrollPane#setWheelScrollingEnabled(boolean)
+ * @see JScrollPane
+ * @see JScrollPane#setWheelScrollingEnabled(boolean)
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public class MouseWheelEvent extends MouseEvent
+{
+ /**
+ * Compatible with JDK 1.4+.
+ */
+ private static final long serialVersionUID = 6459879390515399677L;
+
+ /**
+ * Indicates scrolling by units (lines).
+ *
+ * @see #getScrollType()
+ */
+ public static final int WHEEL_UNIT_SCROLL = 0;
+
+ /**
+ * Indicates scrolling by blocks (pages).
+ *
+ * @see #getScrollType()
+ */
+ public static final int WHEEL_BLOCK_SCROLL = 1;
+
+ /**
+ * Indicates what scroll type should take place. This should be limited
+ * to {@link #WHEEL_UNIT_SCROLL} and {@link #WHEEL_BLOCK_SCROLL}.
+ *
+ * @serial the scroll type
+ */
+ private final int scrollType;
+
+ /**
+ * Indicates the scroll amount. This is only meaningful if scrollType is
+ * WHEEL_UNIT_SCROLL.
+ *
+ * @serial the number of lines to scroll
+ */
+ private final int scrollAmount;
+
+ /**
+ * Indicates how far the mouse wheel was rotated.
+ *
+ * @serial the rotation amount
+ */
+ private final int wheelRotation;
+
+ /**
+ * Initializes a new instance of <code>MouseWheelEvent</code> with the
+ * specified information. Note that an invalid id leads to unspecified
+ * results.
+ *
+ * @param source the source of the event
+ * @param id the event id
+ * @param when the timestamp of when the event occurred
+ * @param modifiers any modifier bits for this event
+ * @param x the X coordinate of the mouse point
+ * @param y the Y coordinate of the mouse point
+ * @param clickCount the number of mouse clicks for this event
+ * @param popupTrigger true if this event triggers a popup menu
+ * @param scrollType one of {@link #WHEEL_UNIT_SCROLL},
+ * {@link #WHEEL_BLOCK_SCROLL}
+ * @param scrollAmount the number of units to scroll, ignored for block type
+ * @param wheelRotation the number of rotation "clicks"
+ * @throws IllegalArgumentException if source is null
+ * @see MouseEvent#MouseEvent(Component, int, long, int, int, int, int,
+ * boolean)
+ */
+ public MouseWheelEvent(Component source, int id, long when, int modifiers,
+ int x, int y, int clickCount, boolean popupTrigger,
+ int scrollType, int scrollAmount, int wheelRotation)
+ {
+ super(source, id, when, modifiers, x, y, clickCount, popupTrigger);
+ this.scrollType = scrollType;
+ this.scrollAmount = scrollAmount;
+ this.wheelRotation = wheelRotation;
+ }
+
+ /**
+ * This method returns the scrolling pattern this event requests. Legal
+ * values are {@link #WHEEL_UNIT_SCROLL} and {@link #WHEEL_BLOCK_SCROLL}.
+ *
+ * @return the scroll type
+ * @see Adjustable#getUnitIncrement()
+ * @see Adjustable#getBlockIncrement()
+ * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
+ * @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int)
+ */
+ public int getScrollType()
+ {
+ return scrollType;
+ }
+
+ /**
+ * Returns the number of units to scroll in response to this event. This
+ * only makes sense when the scroll type is WHEEL_UNIT_SCROLL.
+ *
+ * @return the number of scroll units, if defined
+ * @see #getScrollType()
+ */
+ public int getScrollAmount()
+ {
+ return scrollAmount;
+ }
+
+ /**
+ * Gets the number of "clicks" the wheel was rotated. Negative values move
+ * up (away) from the user, positive values move down (towards) the user.
+ *
+ * @return the number of rotation clicks
+ */
+ public int getWheelRotation()
+ {
+ return wheelRotation;
+ }
+
+ /**
+ * This is a convenience method which aids in a common listener for scrolling
+ * a scrollpane (although this is already built into ScrollPane and
+ * JScrollPane). This method only makes sense when getScrollType() returns
+ * WHEEL_UNIT_SCROLL.
+ *
+ * <p>This accounts for direction of scroll and amount of wheel movement, as
+ * interpreted by the platform settings.
+ *
+ * @return the number of units to scroll
+ * @see #getScrollType()
+ * @see #getScrollAmount()
+ * @see MouseWheelListener
+ * @see Adjustable
+ * @see Adjustable#getUnitIncrement()
+ * @see Scrollable
+ * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
+ * @see ScrollPane
+ * @see ScrollPane#setWheelScrollingEnabled(boolean)
+ * @see JScrollPane
+ * @see JScrollPane#setWheelScrollingEnabled(boolean)
+ */
+ public int getUnitsToScroll()
+ {
+ return wheelRotation * scrollAmount;
+ }
+
+ /**
+ * Returns a string identifying this event. For mouse wheel events, this
+ * is <code>super.paramString() + ",scrollType=WHEEL_" +
+ * (getScrollType() == WHEEL_UNIT_SCROLL ? "UNIT" : "BLOCK")
+ * + "_SCROLL,scrollAmount=" + getScrollAmount() + ",wheelRotation="
+ * + getWheelRotation()</code>.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return super.paramString() + ",scrollType="
+ + (scrollType == WHEEL_UNIT_SCROLL ? "WHEEL_UNIT_SCROLL"
+ : scrollType == WHEEL_BLOCK_SCROLL ? "WHEEL_BLOCK_SCROLL"
+ : "unknown scroll type")
+ + ",scrollAmount=" + scrollAmount + ",wheelRotation=" + wheelRotation;
+ }
+} // class MouseWheelEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/MouseWheelListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,60 @@
+/* MouseWheelListener.java -- listen for mouse wheel events
+ Copyright (C) 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to receive mouse wheel events. For
+ * other events, use MouseListener or MouseMotionListener.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see MouseWheelEvent
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public interface MouseWheelListener extends EventListener
+{
+ /**
+ * This method is called when the mouse wheel is rotated.
+ *
+ * @param event the <code>MouseWheelEvent</code> indicating the rotation
+ */
+ void mouseWheelMoved(MouseWheelEvent event);
+} // interface MouseWheelListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/PaintEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/PaintEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/PaintEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/PaintEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,127 @@
+/* PaintEvent.java -- an area of the screen needs to be repainted
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.Component;
+import java.awt.Rectangle;
+
+/**
+ * This event is generated when an area of the screen needs to be painted.
+ * This event is not meant for users, but exists to allow proper serialization
+ * behavior in the EventQueue with user-accessible events.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class PaintEvent extends ComponentEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 1267492026433337593L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int PAINT_FIRST = 800;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int PAINT_LAST = 801;
+
+ /** This id is for paint event types. */
+ public static final int PAINT = 800;
+
+ /** This id is for update event types. */
+ public static final int UPDATE = 801;
+
+ /**
+ * This is the rectange to be painted or updated.
+ *
+ * @see #getUpdateRect()
+ * @see #setUpdateRect(Rectangle)
+ * @serial the non-null rectangle to be painted
+ */
+ private Rectangle updateRect;
+
+ /**
+ * Initializes a new instance of <code>PaintEvent</code> with the specified
+ * source, id, and update region. Note that an invalid id leads to
+ * unspecified results.
+ *
+ * @param source the event source
+ * @param id the event id
+ * @param updateRect the rectangle to repaint
+ * @throws IllegalArgumentException if source is null
+ */
+ public PaintEvent(Component source, int id, Rectangle updateRect)
+ {
+ super(source, id);
+ this.updateRect = updateRect;
+ }
+
+ /**
+ * Returns the rectange to be updated for this event.
+ *
+ * @return the rectangle to update
+ */
+ public Rectangle getUpdateRect()
+ {
+ return updateRect;
+ }
+
+ /**
+ * Sets the rectangle to be updated for this event.
+ *
+ * @param updateRect the new update rectangle for this event
+ */
+ public void setUpdateRect(Rectangle updateRect)
+ {
+ this.updateRect = updateRect;
+ }
+
+ /**
+ * Returns a string identifying this event.
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return (id == PAINT ? "PAINT,updateRect=" : id == UPDATE
+ ? "UPDATE,updateRect=" : "unknown type,updateRect=") + updateRect;
+ }
+} // class PaintEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,93 @@
+/* TextEvent.java -- event for text changes
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.AWTEvent;
+import java.awt.TextComponent;
+
+/**
+ * This event is generated when a text box changes contents. This is an
+ * abstraction that distills a large number of individual mouse or keyboard
+ * events into a simpler "text changed" event.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see TextComponent
+ * @see TextListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class TextEvent extends AWTEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 6269902291250941179L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int TEXT_FIRST = 900;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int TEXT_LAST = 900;
+
+ /** This event id indicates that the text of an object has changed. */
+ public static final int TEXT_VALUE_CHANGED = 900;
+
+ /**
+ * Initializes a new instance of <code>TextEvent</code> with the specified
+ * source and id. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the (TextComponent) object that generated this event
+ * @param id the event id
+ * @throws IllegalArgumentException if source is null
+ */
+ public TextEvent(Object source, int id)
+ {
+ super(source, id);
+ }
+
+ /**
+ * Returns a string identifying this event. This is "TEXT_VALUE_CHANGED".
+ *
+ * @return a string identifying this event
+ */
+ public String paramString()
+ {
+ return id == TEXT_VALUE_CHANGED ? "TEXT_VALUE_CHANGED" : "unknown type";
+ }
+} // class TextEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/TextListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,60 @@
+/* TextListener.java -- listen for text changes
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to be notified when text changes
+ * in a component.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see TextEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface TextListener extends EventListener
+{
+ /**
+ * This method is called when the text being monitored changes.
+ *
+ * @param event the <code>TextEvent</code> indicating the change
+ */
+ void textValueChanged(TextEvent event);
+} // interface TextListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowAdapter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowAdapter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowAdapter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowAdapter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,156 @@
+/* WindowAdapter.java -- convenience class for writing window listeners
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+/**
+ * This class implements <code>WindowListener</code>,
+ * <code>WindowStateListener</code>, and <code>WindowFocusListener</code>, and
+ * implements all methods with empty bodies. This allows a listener
+ * interested in listening to only a subset of any <code>WindowEvent</code>
+ * actions to extend this class and override only the desired methods.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see ComponentEvent
+ * @see ComponentListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public abstract class WindowAdapter
+ implements WindowListener, WindowStateListener, WindowFocusListener
+{
+ /**
+ * Do nothing default constructor for subclasses.
+ */
+ public WindowAdapter()
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowOpened(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowClosing(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowClosed(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowIconified(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowDeiconified(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowActivated(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ */
+ public void windowDeactivated(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ * @since 1.4
+ */
+ public void windowStateChanged(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ * @since 1.4
+ */
+ public void windowGainedFocus(WindowEvent event)
+ {
+ }
+
+ /**
+ * Implements this method from the interface with an empty method body.
+ *
+ * @param event the event, ignored in this implementation
+ * @since 1.4
+ */
+ public void windowLostFocus(WindowEvent event)
+ {
+ }
+} // class WindowAdapter
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowEvent.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowEvent.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowEvent.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowEvent.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,312 @@
+/* WindowEvent.java -- window change event
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.Frame;
+import java.awt.Window;
+
+/**
+ * This event is generated when there is a change in a window. This includes
+ * creation, closing, iconification, activation, and focus changes. There
+ * are three listeners, for three types of events: WindowListeners deal with
+ * the lifecycle of a window, WindowStateListeners deal with window state
+ * like maximization, and WindowFocusListeners deal with focus switching to
+ * or from a window.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see WindowAdapter
+ * @see WindowListener
+ * @see WindowFocusListener
+ * @see WindowStateListener
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class WindowEvent extends ComponentEvent
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = -1567959133147912127L;
+
+ /** This is the first id in the range of event ids used by this class. */
+ public static final int WINDOW_FIRST = 200;
+
+ /** This is the id for a window that is opened. */
+ public static final int WINDOW_OPENED = 200;
+
+ /** This is the id for a window that is about to close. */
+ public static final int WINDOW_CLOSING = 201;
+
+ /** This is the id for a window that finished closing. */
+ public static final int WINDOW_CLOSED = 202;
+
+ /** This is the id for a window that is iconified. */
+ public static final int WINDOW_ICONIFIED = 203;
+
+ /** This is the id for a window that is de-iconified. */
+ public static final int WINDOW_DEICONIFIED = 204;
+
+ /** This is the id for a window that is activated. */
+ public static final int WINDOW_ACTIVATED = 205;
+
+ /** This is the id for a window that is de-activated. */
+ public static final int WINDOW_DEACTIVATED = 206;
+
+ /**
+ * This is the id for a window becoming the focused window.
+ *
+ * @since 1.4
+ */
+ public static final int WINDOW_GAINED_FOCUS = 207;
+
+ /**
+ * This is the id for a window losing all focus.
+ *
+ * @since 1.4
+ */
+ public static final int WINDOW_LOST_FOCUS = 208;
+
+ /**
+ * This is the id for a window state change, such as maximization.
+ *
+ * @since 1.4
+ */
+ public static final int WINDOW_STATE_CHANGED = 209;
+
+ /** This is the last id in the range of event ids used by this class. */
+ public static final int WINDOW_LAST = 209;
+
+ /**
+ * The other Window involved in a focus or activation change. For
+ * WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, this is the window that
+ * lost focus; for WINDOW_DEACTIVATED and WINDOW_LOST_FOCUS, this is the
+ * window that stole focus; and for other events (or when native
+ * implementation does not have the data available), this is null.
+ *
+ * @see #getOppositeWindow()
+ * @serial the opposite window, or null
+ * @since 1.4
+ */
+ private final Window opposite;
+
+ /**
+ * The former state of the window.
+ *
+ * @serial bitmask of the old window state
+ * @since 1.4
+ */
+ private final int oldState;
+
+ /**
+ * The present state of the window.
+ *
+ * @serial bitmask of the new window state
+ * @since 1.4
+ */
+ private final int newState;
+
+ /**
+ * Initializes a new instance of <code>WindowEvent</code> with the specified
+ * parameters. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the window that generated this event
+ * @param id the event id
+ * @param opposite the window that received the opposite event, or null
+ * @param oldState the previous state of this window
+ * @param newState the new state of this window
+ * @throws IllegalArgumentException if source is null
+ * @since 1.4
+ */
+ public WindowEvent(Window source, int id, Window opposite,
+ int oldState, int newState)
+ {
+ super(source, id);
+ this.opposite = opposite;
+ this.oldState = oldState;
+ this.newState = newState;
+ }
+
+ /**
+ * Initializes a new instance of <code>WindowEvent</code> with the specified
+ * parameters. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the window that generated this event
+ * @param id the event id
+ * @param opposite the window that received the opposite event, or null
+ * @throws IllegalArgumentException if source is null
+ * @since 1.4
+ */
+ public WindowEvent(Window source, int id, Window opposite)
+ {
+ this(source, id, opposite, 0, 0);
+ }
+
+ /**
+ * Initializes a new instance of <code>WindowEvent</code> with the specified
+ * parameters. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the window that generated this event
+ * @param id the event id
+ * @param oldState the previous state of this window
+ * @param newState the new state of this window
+ * @throws IllegalArgumentException if source is null
+ * @since 1.4
+ */
+ public WindowEvent(Window source, int id, int oldState, int newState)
+ {
+ this(source, id, null, oldState, newState);
+ }
+
+ /**
+ * Initializes a new instance of <code>WindowEvent</code> with the specified
+ * parameters. Note that an invalid id leads to unspecified results.
+ *
+ * @param source the window that generated this event
+ * @param id the event id
+ * @throws IllegalArgumentException if source is null
+ */
+ public WindowEvent(Window source, int id)
+ {
+ this(source, id, null, 0, 0);
+ }
+
+ /**
+ * Returns the event source as a <code>Window</code>. If the source has
+ * subsequently been modified to a non-Window, this returns null.
+ *
+ * @return the event source as a <code>Window</code>
+ */
+ public Window getWindow()
+ {
+ return source instanceof Window ? (Window) source : null;
+ }
+
+ /**
+ * Returns the opposite window if this window was involved in an activation
+ * or focus change. For WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events,
+ * this is the window that lost focus; for WINDOW_DEACTIVATED and
+ * WINDOW_LOST_FOCUS, this is the window that stole focus; and for other
+ * events (or when native implementation does not have the data available),
+ * this is null.
+ *
+ * @return the opposite window, or null
+ * @since 1.4
+ */
+ public Window getOppositeWindow()
+ {
+ return opposite;
+ }
+
+ /**
+ * Returns the state of this window before the event. This is the bitwise
+ * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT,
+ * and MAXIMIZED_BOTH.
+ *
+ * @return the former state
+ * @see Frame#getExtendedState()
+ * @since 1.4
+ */
+ public int getOldState()
+ {
+ return oldState;
+ }
+
+ /**
+ * Returns the state of this window after the event. This is the bitwise
+ * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT,
+ * and MAXIMIZED_BOTH.
+ *
+ * @return the updated state
+ * @see Frame#getExtendedState()
+ * @since 1.4
+ */
+ public int getNewState()
+ {
+ return newState;
+ }
+
+ /**
+ * Returns a string that identifies this event. This is formatted as the
+ * field name of the id, followed by the opposite window, old state, and
+ * new state.
+ *
+ * @return a string that identifies this event
+ */
+ public String paramString()
+ {
+ StringBuffer s = new StringBuffer();
+ switch (id)
+ {
+ case WINDOW_OPENED:
+ s.append("WINDOW_OPENED,opposite=");
+ break;
+ case WINDOW_CLOSING:
+ s.append("WINDOW_CLOSING,opposite=");
+ break;
+ case WINDOW_CLOSED:
+ s.append("WINDOW_CLOSED,opposite=");
+ break;
+ case WINDOW_ICONIFIED:
+ s.append("WINDOW_ICONIFIED,opposite=");
+ break;
+ case WINDOW_DEICONIFIED:
+ s.append("WINDOW_DEICONIFIED,opposite=");
+ break;
+ case WINDOW_ACTIVATED:
+ s.append("WINDOW_ACTIVATED,opposite=");
+ break;
+ case WINDOW_DEACTIVATED:
+ s.append("WINDOW_DEACTIVATED,opposite=");
+ break;
+ case WINDOW_GAINED_FOCUS:
+ s.append("WINDOW_GAINED_FOCUS,opposite=");
+ break;
+ case WINDOW_LOST_FOCUS:
+ s.append("WINDOW_LOST_FOCUS,opposite=");
+ break;
+ case WINDOW_STATE_CHANGED:
+ s.append("WINDOW_STATE_CHANGED,opposite=");
+ break;
+ default:
+ s.append("unknown type,opposite=");
+ }
+ return s.append(opposite).append(",oldState=").append(oldState)
+ .append(",newState=").append(newState).toString();
+ }
+} // class WindowEvent
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowFocusListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowFocusListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowFocusListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowFocusListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,68 @@
+/* WindowFocusListener.java -- listens for window focus events
+ Copyright (C) 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to monitor events for window
+ * focus changes. To watch a subset of these events, use a WindowAdapter.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see WindowAdapter
+ * @see WindowEvent
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public interface WindowFocusListener extends EventListener
+{
+ /**
+ * This method is called when a window gains focus.
+ *
+ * @param event the <code>WindowEvent</code> indicating the focus change
+ */
+ void windowGainedFocus(WindowEvent event);
+
+ /**
+ * This method is called when a window loses focus.
+ *
+ * @param event the <code>WindowEvent</code> indicating the focus change
+ */
+ void windowLostFocus(WindowEvent event);
+} // interface WindowFocusListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,109 @@
+/* WindowListener.java -- listens for window events
+ Copyright (C) 1999, 2002, 2005 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., 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.event;
+
+import java.awt.Frame;
+import java.awt.Image;
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to monitor events for window
+ * changes. To watch a subset of these events, use a WindowAdapter.
+ *
+ * @author Aaron M. Renn (arenn at urbanophile.com)
+ * @see WindowAdapter
+ * @see WindowEvent
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public interface WindowListener extends EventListener
+{
+ /**
+ * This method is called when the window is made visible.
+ *
+ * @param event the <code>WindowEvent</code> indicating the change
+ */
+ void windowOpened(WindowEvent event);
+
+ /**
+ * This method is called when the user calls the system menu close
+ * function, giving the program a chance to cancel the close.
+ *
+ * @param event the <code>WindowEvent</code> indicating the close attempt
+ */
+ void windowClosing(WindowEvent event);
+
+ /**
+ * This method is called when the window is closed.
+ *
+ * @param event the <code>WindowEvent</code> indicating the dispose
+ */
+ void windowClosed(WindowEvent event);
+
+ /**
+ * This method is called when the window is iconified.
+ *
+ * @param event the <code>WindowEvent</code> indicating the iconification
+ * @see Frame#setIconImage(Image)
+ */
+ void windowIconified(WindowEvent event);
+
+ /**
+ * This method is called when the window is deiconified.
+ *
+ * @param event the <code>WindowEvent</code> indicating the deiconification
+ */
+ void windowDeiconified(WindowEvent event);
+
+ /**
+ * This method is called when a window is activated. Only Frames and Dialogs
+ * can be active, and the active window always contains the component with
+ * focus.
+ *
+ * @param event the <code>WindowEvent</code> indicating the activation
+ */
+ void windowActivated(WindowEvent event);
+
+ /**
+ * This method is called when the window is deactivated.
+ *
+ * @param event the <code>WindowEvent</code> indicating the deactivation
+ */
+ void windowDeactivated(WindowEvent event);
+} // interface WindowListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowStateListener.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowStateListener.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowStateListener.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/WindowStateListener.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,62 @@
+/* WindowStateListener.java -- listens for window state changes
+ Copyright (C) 2002, 2005 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., 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.event;
+
+import java.util.EventListener;
+
+/**
+ * This interface is for classes that wish to monitor events for window
+ * state changes.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see WindowAdapter
+ * @see WindowEvent
+ * @since 1.4
+ * @status updated to 1.4
+ */
+public interface WindowStateListener extends EventListener
+{
+ /**
+ * This method is called when the window state is changed, because of
+ * iconification or maximization.
+ *
+ * @param event the <code>WindowEvent</code> indicating the change
+ */
+ void windowStateChanged(WindowEvent event);
+} // interface WindowStateListener
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/event/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.event package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.event</title></head>
+
+<body>
+<p>Listeners and adapters for different kinds of AWT events.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/FontRenderContext.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/FontRenderContext.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/FontRenderContext.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/FontRenderContext.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,134 @@
+/* FontRenderContext.java
+ Copyright (C) 2002, 2003 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., 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.font;
+
+import java.awt.geom.AffineTransform;
+
+/**
+ * @author Michael Koch
+ */
+public class FontRenderContext
+{
+ private AffineTransform affineTransform;
+ private boolean isAntiAliased;
+ private boolean usesFractionalMetrics;
+
+ /**
+ * Construct a new <code>FontRenderContext</code>.
+ */
+ protected FontRenderContext()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Construct a new <code>FontRenderContext</code>.
+ */
+ public FontRenderContext (AffineTransform tx, boolean isAntiAliased,
+ boolean usesFractionalMetrics)
+ {
+ if (tx != null
+ && !tx.isIdentity ())
+ {
+ this.affineTransform = new AffineTransform (tx);
+ }
+
+ this.isAntiAliased = isAntiAliased;
+ this.usesFractionalMetrics = usesFractionalMetrics;
+ }
+
+ public boolean equals (Object obj)
+ {
+ if (! (obj instanceof FontRenderContext))
+ return false;
+
+ return equals ((FontRenderContext) obj);
+ }
+
+ public boolean equals (FontRenderContext rhs)
+ {
+ if (rhs == null)
+ return false;
+
+ if (affineTransform == null && rhs.affineTransform != null
+ || affineTransform != null && rhs.affineTransform == null)
+ return false;
+
+ return ((affineTransform == rhs.affineTransform
+ || affineTransform.equals (rhs.getTransform ()))
+ && isAntiAliased == rhs.isAntiAliased ()
+ && usesFractionalMetrics == rhs.usesFractionalMetrics ());
+ }
+
+
+ /**
+ * Retrieves the affine transform for scaling typographical points
+ * to raster pixels.
+ *
+ * @return a clone of the transform object.
+ */
+ public AffineTransform getTransform ()
+ {
+ if (affineTransform == null)
+ return new AffineTransform ();
+ else
+ return new AffineTransform (affineTransform);
+ }
+
+
+ /**
+ * Returns the hash code of the font render context.
+ */
+ public int hashCode ()
+ {
+ // FIXME: check what SUN does here.
+ return affineTransform == null ? 0 : affineTransform.hashCode ();
+ }
+
+ public boolean isAntiAliased ()
+ {
+ return isAntiAliased;
+ }
+
+ public boolean usesFractionalMetrics ()
+ {
+ return usesFractionalMetrics;
+ }
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphJustificationInfo.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphJustificationInfo.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphJustificationInfo.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphJustificationInfo.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,77 @@
+/* GlyphJustificationInfo.java
+ Copyright (C) 2003 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., 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.font;
+
+/**
+ * @author Michael Koch
+ */
+public final class GlyphJustificationInfo
+{
+ public static final int PRIORITY_KASHIDA = 0;
+ public static final int PRIORITY_WHITESPACE = 1;
+ public static final int PRIORITY_INTERCHAR = 2;
+ public static final int PRIORITY_NONE = 3;
+
+ public final float weight;
+ public final int growPriority;
+ public final boolean growAbsorb;
+ public final float growLeftLimit;
+ public final float growRightLimit;
+ public final int shrinkPriority;
+ public final boolean shrinkAbsorb;
+ public final float shrinkLeftLimit;
+ public final float shrinkRightLimit;
+
+ public GlyphJustificationInfo (float weight, boolean growAbsorb,
+ int growPriority, float growLeftLimit,
+ float growRightLimit, boolean shrinkAbsorb,
+ int shrinkPriority, float shrinkLeftLimit,
+ float shrinkRightLimit)
+ {
+ this.weight = weight;
+ this.growAbsorb = growAbsorb;
+ this.growPriority = growPriority;
+ this.growLeftLimit = growLeftLimit;
+ this.growRightLimit = growRightLimit;
+ this.shrinkAbsorb = shrinkAbsorb;
+ this.shrinkPriority = shrinkPriority;
+ this.shrinkLeftLimit = shrinkLeftLimit;
+ this.shrinkRightLimit = shrinkRightLimit;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphMetrics.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphMetrics.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphMetrics.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphMetrics.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,138 @@
+/* GlyphMetrics.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.awt.geom.Rectangle2D;
+
+/**
+ * @author Michael Koch
+ */
+public final class GlyphMetrics
+{
+ public static final byte COMBINING = 2;
+ public static final byte COMPONENT = 3;
+ public static final byte LIGATURE = 1;
+ public static final byte STANDARD = 0;
+ public static final byte WHITESPACE = 4;
+
+ private boolean horizontal;
+ private float advanceX;
+ private float advanceY;
+ private Rectangle2D bounds;
+ private byte glyphType;
+
+ public GlyphMetrics (boolean horizontal, float advanceX, float advanceY,
+ Rectangle2D bounds, byte glyphType)
+ {
+ this.horizontal = horizontal;
+ this.advanceX = advanceX;
+ this.advanceY = advanceY;
+ this.bounds = bounds;
+ this.glyphType = glyphType;
+ }
+
+ public GlyphMetrics (float advance, Rectangle2D bounds, byte glyphType)
+ {
+ this (true, advance, advance, bounds, glyphType);
+ }
+
+ public float getAdvance ()
+ {
+ return horizontal ? advanceX : advanceY;
+ }
+
+ public float getAdvanceX ()
+ {
+ return advanceX;
+ }
+
+ public float getAdvanceY ()
+ {
+ return advanceY;
+ }
+
+ public Rectangle2D getBounds2D ()
+ {
+ return bounds;
+ }
+
+ public float getLSB()
+ {
+ if (horizontal)
+ return (float) bounds.getX();
+ return (float) bounds.getY();
+ }
+
+ public float getRSB()
+ {
+ if (horizontal)
+ return (float) (advanceX - (bounds.getX() + bounds.getWidth()));
+ return (float) (advanceY - (bounds.getY() + bounds.getHeight()));
+ }
+
+ public int getType ()
+ {
+ return glyphType;
+ }
+
+ public boolean isCombining ()
+ {
+ return (glyphType == COMBINING);
+ }
+
+ public boolean isComponent ()
+ {
+ return (glyphType == COMPONENT);
+ }
+
+ public boolean isLigature()
+ {
+ return (glyphType == LIGATURE);
+ }
+
+ public boolean isStandard()
+ {
+ return (glyphType == STANDARD);
+ }
+
+ public boolean isWhitespace()
+ {
+ return (glyphType == WHITESPACE);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphVector.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphVector.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphVector.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GlyphVector.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,174 @@
+/* GlyphVector.java
+ 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., 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.font;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * @author Lillian Angel (langel at redhat dot com)
+ * @author Michael Koch
+ */
+public abstract class GlyphVector implements Cloneable
+{
+ public static final int FLAG_COMPLEX_GLYPHS = 8;
+ public static final int FLAG_HAS_POSITION_ADJUSTMENTS = 2;
+ public static final int FLAG_HAS_TRANSFORMS = 1;
+ public static final int FLAG_MASK = 15;
+ public static final int FLAG_RUN_RTL = 4;
+
+ /**
+ * Constructs a <code>GlyphVector</code> object.
+ */
+ public GlyphVector ()
+ {
+ }
+
+ public abstract boolean equals (GlyphVector set);
+
+ public abstract Font getFont ();
+
+ public abstract FontRenderContext getFontRenderContext ();
+
+ public int getGlyphCharIndex (int glyphIndex)
+ {
+ return glyphIndex;
+ }
+
+ public int[] getGlyphCharIndices(int beginGlyphIndex, int numEntries,
+ int[] codeReturn)
+ {
+ if (codeReturn == null)
+ codeReturn = new int[numEntries];
+
+ int i = 0;
+ int j = beginGlyphIndex;
+ while (j < numEntries)
+ codeReturn[i++] = getGlyphCharIndex(j++);
+
+ return codeReturn;
+ }
+
+ public abstract int getGlyphCode (int glyphIndex);
+
+ public abstract int[] getGlyphCodes (int beginGlyphIndex, int numEntries,
+ int[] codeReturn);
+
+ public abstract GlyphJustificationInfo getGlyphJustificationInfo
+ (int glyphIndex);
+
+ public abstract Shape getGlyphLogicalBounds (int glyphIndex);
+
+ public abstract GlyphMetrics getGlyphMetrics (int glyphIndex);
+
+ public abstract Shape getGlyphOutline (int glyphIndex);
+
+ public Shape getGlyphOutline(int glyphIndex, float x, float y)
+ {
+ Shape s = getGlyphOutline(glyphIndex);
+
+ // This is the only way to translate the origin of a shape
+ AffineTransform at = AffineTransform.getTranslateInstance(x, y);
+ return at.createTransformedShape(s);
+ }
+
+ public Rectangle getGlyphPixelBounds(int index, FontRenderContext renderFRC,
+ float x, float y)
+ {
+ Rectangle bounds = new Rectangle();
+ Rectangle2D rect = getGlyphVisualBounds(index).getBounds2D();
+
+ bounds.x = (int) (rect.getX() + x);
+ bounds.y = (int) (rect.getY() + y);
+ bounds.width = (int) rect.getMaxX() - bounds.x;
+ bounds.height = (int) rect.getMaxY() - bounds.y;
+
+ return bounds;
+ }
+
+ public abstract Point2D getGlyphPosition (int glyphIndex);
+
+ public abstract float[] getGlyphPositions (int beginGlyphIndex,
+ int numEntries,
+ float[] positionReturn);
+
+ public abstract AffineTransform getGlyphTransform (int glyphIndex);
+
+ public abstract Shape getGlyphVisualBounds (int glyphIndex);
+
+ public int getLayoutFlags()
+ {
+ return 0;
+ }
+
+ public abstract Rectangle2D getLogicalBounds ();
+
+ public abstract int getNumGlyphs ();
+
+ public abstract Shape getOutline ();
+
+ public abstract Shape getOutline (float x, float y);
+
+ public Rectangle getPixelBounds (FontRenderContext renderFRC,
+ float x, float y)
+ {
+ Rectangle bounds = new Rectangle();
+ Rectangle2D rect = getVisualBounds();
+
+ bounds.x = (int) (rect.getX() + x);
+ bounds.y = (int) (rect.getY() + y);
+ bounds.width = (int) rect.getMaxX() - bounds.x;
+ bounds.height = (int) rect.getMaxY() - bounds.y;
+
+ return bounds;
+ }
+
+ public abstract Rectangle2D getVisualBounds ();
+
+ public abstract void performDefaultLayout ();
+
+ public abstract void setGlyphPosition (int glyphIndex, Point2D newPos);
+
+ public abstract void setGlyphTransform (int glyphIndex,
+ AffineTransform newTX);
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GraphicAttribute.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GraphicAttribute.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GraphicAttribute.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/GraphicAttribute.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,137 @@
+/* GraphicAttribute.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * This class represents a graphic embedded in text.
+ *
+ * @author Michael Koch
+ * @author Lillian Angel (langel at redhat dot com)
+ */
+public abstract class GraphicAttribute
+{
+ public static final int BOTTOM_ALIGNMENT = - 2;
+ public static final int CENTER_BASELINE = 1;
+ public static final int HANGING_BASELINE = 2;
+ public static final int ROMAN_BASELINE = 0;
+ public static final int TOP_ALIGNMENT = - 1;
+
+ private int alignment;
+
+ /**
+ * Constructor.
+ *
+ * @param alignment - the alignment to use for the graphic
+ */
+ protected GraphicAttribute(int alignment)
+ {
+ if (alignment < BOTTOM_ALIGNMENT || alignment > HANGING_BASELINE)
+ throw new IllegalArgumentException("Invalid alignment");
+ this.alignment = alignment;
+ }
+
+ /**
+ * Draws the graphic.
+ *
+ * @param graphics - the graphics configuration to use
+ * @param x - the x location
+ * @param y - the y location
+ */
+ public abstract void draw(Graphics2D graphics, float x, float y);
+
+ /**
+ * Gets the distance from the origin of its graphic to the right side of the
+ * bounds of its graphic.
+ *
+ * @return the advance
+ */
+ public abstract float getAdvance();
+
+ /**
+ * Gets the positive distance from the origin of its graphic to the top of
+ * bounds.
+ *
+ * @return the ascent
+ */
+ public abstract float getAscent();
+
+ /**
+ * Gets the distance from the origin of its graphic to the bottom of the bounds.
+ *
+ * @return the descent
+ */
+ public abstract float getDescent();
+
+ /**
+ * Gets the alignment.
+ *
+ * @return the alignment
+ */
+ public final int getAlignment()
+ {
+ return alignment;
+ }
+
+ /**
+ * Returns a Rectangle2D that encloses the rendered area.
+ * Default bounds is the rectangle (0, -ascent, advance, ascent+descent).
+ *
+ * @return the bounds of the rendered area
+ */
+ public Rectangle2D getBounds()
+ {
+ float asc = getAscent();
+ return new Rectangle2D.Float(0, - asc, getAdvance(), asc + getDescent());
+ }
+
+ /**
+ * Returns the justification information for this object.
+ *
+ * @return the justification information
+ */
+ public GlyphJustificationInfo getJustificationInfo()
+ {
+ float adv = getAdvance();
+ return new GlyphJustificationInfo(adv, false, 2, adv / 3, adv / 3, false,
+ 1, 0, 0);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ImageGraphicAttribute.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ImageGraphicAttribute.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ImageGraphicAttribute.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ImageGraphicAttribute.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,187 @@
+/* ImageGraphicAttribute.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * This is an implementation of GraphicAttribute which draws images in a
+ * TextLayout.
+ *
+ * @author Lillian Angel
+ * @author Michael Koch
+ */
+public final class ImageGraphicAttribute
+ extends GraphicAttribute
+{
+ private Image image;
+ private float originX;
+ private float originY;
+
+ /**
+ * Constucts an instance from the specified Image. The origin is at (0, 0).
+ *
+ * @param image - image to construct from.
+ * @param alignment - the alignment
+ */
+ public ImageGraphicAttribute(Image image, int alignment)
+ {
+ this(image, alignment, 0, 0);
+ }
+
+ /**
+ * Constucts an instance from the specified Image. The origin is at (originX,
+ * originY).
+ *
+ * @param image - image to construct from
+ * @param alignment - the alignment
+ * @param originX - x point of origin
+ * @param originY - y point of origin
+ */
+ public ImageGraphicAttribute(Image image, int alignment, float originX,
+ float originY)
+ {
+ super(alignment);
+ this.image = image;
+ this.originX = originX;
+ this.originY = originY;
+ }
+
+ /**
+ * Draws the image at the specified location, relative to the
+ * origin.
+ *
+ * @param g - the graphics to use to render the image
+ * @param x - the x location
+ * @param y - the y location
+ */
+ public void draw(Graphics2D g, float x, float y)
+ {
+ g.drawImage(image, (int) (x - originX), (int) (y - originY), null);
+ }
+
+ /**
+ * Compares this to the specified Object
+ *
+ * @param obj - the object to compare
+ * @return true if the obj and this are equivalent
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof ImageGraphicAttribute))
+ return false;
+
+ return equals((ImageGraphicAttribute) obj);
+ }
+
+ /**
+ * Compares this to the ImageGraphicAttribute given, by
+ * comparing all fields and values.
+ *
+ * @param rhs - the ImageGraphicAttribute to compare
+ * @return true if the object given is equivalent to this
+ */
+ public boolean equals(ImageGraphicAttribute rhs)
+ {
+ return ((this == rhs) || ((this.getAscent() == rhs.getAscent())
+ && (this.getAdvance() == rhs.getAdvance())
+ && (this.getAlignment() == rhs.getAlignment())
+ && (this.getBounds().equals(rhs.getBounds()))
+ && (this.getDescent() == rhs.getDescent())
+ && (this.hashCode() == rhs.hashCode())
+ && (this.image.equals(rhs.image))
+ && (this.originX == rhs.originX)
+ && (this.originY == rhs.originY)));
+ }
+
+ /**
+ * Returns distance from the origin to the right edge of the image of this.
+ *
+ * @return the advance
+ */
+ public float getAdvance()
+ {
+ return Math.max(0, image.getWidth(null) - originX);
+ }
+
+ /**
+ * Returns the the distance from the top of the image to the origin of this.
+ *
+ * @return the ascent.
+ */
+ public float getAscent()
+ {
+ return Math.max(0, originY);
+ }
+
+ /**
+ * Gets the bounds of the object rendered, relative to the position.
+ *
+ * @return the bounds of the object rendered, relative to the position.
+ */
+ public Rectangle2D getBounds()
+ {
+ // This is equivalent to what Sun's JDK returns.
+ // I am not entirely sure why the origin is negative.
+ return new Rectangle2D.Float(- originX, - originY, image.getWidth(null),
+ image.getHeight(null));
+ }
+
+ /**
+ * Returns the distance from the origin to the bottom of the image.
+ *
+ * @return the descent
+ */
+ public float getDescent()
+ {
+ return Math.max(0, image.getHeight(null) - originY);
+ }
+
+ /**
+ * Gets the hash code for this image.
+ *
+ * @return the hash code
+ */
+ public int hashCode()
+ {
+ return image.hashCode();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineBreakMeasurer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineBreakMeasurer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineBreakMeasurer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineBreakMeasurer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,151 @@
+/* LineBreakMeasurer.java
+ Copyright (C) 2006 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., 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.font;
+
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.text.BreakIterator;
+import java.awt.Shape;
+
+public final class LineBreakMeasurer
+{
+ private AttributedCharacterIterator text;
+ private int position;
+ private TextMeasurer tm;
+ private int numChars;
+
+ public LineBreakMeasurer(AttributedCharacterIterator text,
+ BreakIterator breakIter, FontRenderContext frc)
+ {
+ this( text, frc );
+ }
+
+ public LineBreakMeasurer(AttributedCharacterIterator text,
+ FontRenderContext frc)
+ {
+ this.text = text;
+ position = 0;
+ numChars = text.getEndIndex();
+ tm = new TextMeasurer( text, frc );
+ }
+
+ public void deleteChar(AttributedCharacterIterator newParagraph,
+ int deletePos)
+ {
+ tm.deleteChar( newParagraph, deletePos );
+ position = 0;
+ }
+
+ public void insertChar(AttributedCharacterIterator newParagraph,
+ int insertPos)
+ {
+ tm.insertChar( newParagraph, insertPos );
+ position = 0;
+ }
+
+ public TextLayout nextLayout(float wrappingWidth)
+ {
+ return nextLayout( wrappingWidth, numChars, false );
+ }
+
+ public TextLayout nextLayout(float wrappingWidth, int offsetLimit,
+ boolean requireNextWord)
+ {
+ int next = nextOffset( wrappingWidth, offsetLimit, requireNextWord );
+ TextLayout tl = tm.getLayout( position, next );
+ position = next;
+ return tl;
+ }
+
+ public int nextOffset(float wrappingWidth)
+ {
+ return nextOffset( wrappingWidth, numChars, false );
+ }
+
+ public int nextOffset(float wrappingWidth, int offsetLimit,
+ boolean requireNextWord)
+ {
+ int guessOffset = tm.getLineBreakIndex(position, wrappingWidth);
+ if( offsetLimit > numChars )
+ offsetLimit = numChars;
+
+ if( guessOffset > offsetLimit )
+ {
+ text.setIndex( offsetLimit );
+ return offsetLimit;
+ }
+
+ text.setIndex( guessOffset );
+
+ // If we're on a breaking character, return directly
+ if( Character.isWhitespace( text.current() ) )
+ return guessOffset;
+
+ // Otherwise jump forward or backward to the last such char.
+ if( !requireNextWord )
+ while( !Character.isWhitespace( text.previous() ) &&
+ guessOffset > position )
+ guessOffset--;
+ else
+ while( !Character.isWhitespace( text.next() ) &&
+ guessOffset < offsetLimit )
+ guessOffset++;
+
+ if( guessOffset > offsetLimit )
+ {
+ text.setIndex( offsetLimit );
+ return offsetLimit;
+ }
+
+ text.setIndex( guessOffset );
+
+ return guessOffset;
+ }
+
+ public void setPosition(int newPosition)
+ {
+ position = newPosition;
+ }
+
+ public int getPosition()
+ {
+ return position;
+ }
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineMetrics.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineMetrics.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineMetrics.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/LineMetrics.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,67 @@
+/* LineMetrics.java -- Information about about a line display characteristics
+ 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., 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.font;
+
+/**
+ * @author Michael Koch
+ */
+public abstract class LineMetrics
+{
+ public abstract float getAscent();
+
+ public abstract int getBaselineIndex();
+
+ public abstract float[] getBaselineOffsets();
+
+ public abstract float getDescent();
+
+ public abstract float getHeight();
+
+ public abstract float getLeading();
+
+ public abstract int getNumChars();
+
+ public abstract float getStrikethroughOffset();
+
+ public abstract float getStrikethroughThickness();
+
+ public abstract float getUnderlineOffset();
+
+ public abstract float getUnderlineThickness();
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/MultipleMaster.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/MultipleMaster.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/MultipleMaster.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/MultipleMaster.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,61 @@
+/* MultipleMaster.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.awt.Font;
+
+/**
+ * @author Michael Koch
+ */
+public interface MultipleMaster
+{
+ Font deriveMMFont (float[] axes);
+
+ Font deriveMMFont (float[] glyphWidths, float avgStemWidth,
+ float typicalCapHeight, float typicalXHeight,
+ float italicAngle);
+
+ float[] getDesignAxisDefaults();
+
+ String[] getDesignAxisNames();
+
+ float[] getDesignAxisRanges();
+
+ int getNumDesignAxes();
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/NumericShaper.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/NumericShaper.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/NumericShaper.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/NumericShaper.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,425 @@
+/* NumericShaper.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.io.Serializable;
+import java.lang.Character.UnicodeBlock;
+
+/**
+ * This class handles numeric shaping. A shaper can either be contextual
+ * or not. A non-contextual shaper will always translate ASCII digits
+ * in its input into the target Unicode range. A contextual shaper will
+ * change the target Unicode range depending on the characters it has
+ * previously processed.
+ *
+ * @author Michael Koch
+ * @author Tom Tromey
+ *
+ * @since 1.4
+ * @specnote This class does not handle LIMBU or OSMANYA.
+ * @specnote The JDK does not seem to properly handle ranges without a
+ * digit zero, such as TAMIL. This implementation does.
+ */
+public final class NumericShaper implements Serializable
+{
+ private static final long serialVersionUID = -8022764705923730308L;
+
+ /** Convenience constant representing all the valid Unicode ranges. */
+ public static final int ALL_RANGES = 524287;
+
+ /**
+ * Constant representing the Unicode ARABIC range. Shaping done
+ * using this range will translate to the arabic decimal characters.
+ * Use EASTERN_ARABIC if you want to shape to the eastern arabic
+ * (also known as the extended arabic) decimal characters.
+ */
+ public static final int ARABIC = 2;
+
+ /** Constant representing the Unicode BENGALI range. */
+ public static final int BENGALI = 16;
+
+ /** Constant representing the Unicode DEVANAGARI range. */
+ public static final int DEVANAGARI = 8;
+
+ /**
+ * Constant representing the Unicode extended arabic range.
+ * In Unicode there are two different sets of arabic digits;
+ * this selects the extended or eastern set.
+ */
+ public static final int EASTERN_ARABIC = 4;
+
+ /**
+ * Constant representing the Unicode ETHIOPIC range. Note that
+ * there is no digit zero in this range; an ASCII digit zero
+ * is left unchanged when shaping to this range.
+ */
+ public static final int ETHIOPIC = 65536;
+
+ /**
+ * Constant representing the Unicode EUROPEAN range. For
+ * contextual shaping purposes, characters in the various
+ * extended Latin character blocks are recognized as EUROPEAN.
+ */
+ public static final int EUROPEAN = 1;
+
+ /** Constant representing the Unicode GUJARATI range. */
+ public static final int GUJARATI = 64;
+
+ /** Constant representing the Unicode GURMUKHI range. */
+ public static final int GURMUKHI = 32;
+
+ /** Constant representing the Unicode KANNADA range. */
+ public static final int KANNADA = 1024;
+
+ /** Constant representing the Unicode KHMER range. */
+ public static final int KHMER = 131072;
+
+ /** Constant representing the Unicode LAO range. */
+ public static final int LAO = 8192;
+
+ /** Constant representing the Unicode MALAYALAM range. */
+ public static final int MALAYALAM = 2048;
+
+ /** Constant representing the Unicode MONGOLIAN range. */
+ public static final int MONGOLIAN = 262144;
+
+ /** Constant representing the Unicode MYANMAR range. */
+ public static final int MYANMAR = 32768;
+
+ /** Constant representing the Unicode ORIYA range. */
+ public static final int ORIYA = 128;
+
+ /**
+ * Constant representing the Unicode TAMIL range. Note that
+ * there is no digit zero in this range; an ASCII digit zero
+ * is left unchanged when shaping to this range.
+ */
+ public static final int TAMIL = 256;
+
+ /** Constant representing the Unicode TELUGU range. */
+ public static final int TELUGU = 512;
+
+ /** Constant representing the Unicode THAI range. */
+ public static final int THAI = 4096;
+
+ /** Constant representing the Unicode TIBETAN range. */
+ public static final int TIBETAN = 16384;
+
+ /**
+ * This table holds the zero digits for each language. This is hard-coded
+ * because the values will not change and the table layout is tied to the
+ * other constants in this class in any case. In the two places where a
+ * language does not have a zero digit, the character immediately preceeding
+ * the one digit is used instead. These languages are special-cased in
+ * the shaping code.
+ */
+ private static final char[] zeroDigits =
+ {
+ '0', // EUROPEAN
+ '\u0660', // ARABIC
+ '\u06f0', // EASTERN_ARABIC
+ '\u0966', // DEVANAGARI
+ '\u09e6', // BENGALI
+ '\u0a66', // GURMUKHI
+ '\u0ae6', // GUJARATI
+ '\u0b66', // ORIYA
+ '\u0be6', // TAMIL - special case as there is no digit zero
+ '\u0c66', // TELUGU
+ '\u0ce6', // KANNADA
+ '\u0d66', // MALAYALAM
+ '\u0e50', // THAI
+ '\u0ed0', // LAO
+ '\u0f20', // TIBETAN
+ '\u1040', // MYANMAR
+ '\u1368', // ETHIOPIC - special case as there is no digit zero
+ '\u17e0', // KHMER
+ '\u1810' // MONGOLIAN
+ };
+
+ /**
+ * The default initial context for this shaper, specified as
+ * an integer from 0 to 18.
+ */
+ private int key;
+
+ /**
+ * The target ranges handled by this shaper. If the shaper
+ * is not contextual, the high bit of this field will be set.
+ * @specnote This was discovered by reading the serialization spec
+ */
+ private int mask;
+
+ /**
+ * Create a new numeric shaper. The key given is a constant from
+ * this class, the constructor turns it into its internal form.
+ * @param key the key to use, as one of the manifest constants
+ * @param mask a mask of languages to shape for
+ */
+ private NumericShaper (int key, int mask)
+ {
+ // This internal form is a bit goofy, but it is specified by
+ // the serialization spec.
+ this.key = Integer.numberOfTrailingZeros(key);
+ this.mask = mask;
+ }
+
+ /**
+ * Return an integer representing all the languages for which this
+ * shaper will shape. The result is taken by "or"ing together
+ * the constants representing the various languages.
+ */
+ public int getRanges ()
+ {
+ return mask & ALL_RANGES;
+ }
+
+ /**
+ * Return true if this shaper is contextual, false if it is not.
+ */
+ public boolean isContextual ()
+ {
+ return mask > 0;
+ }
+
+ /**
+ * Shape the text in the given array. The starting context will
+ * be the context passed to the shaper at creation time.
+ * @param text the text to shape
+ * @param start the index of the starting character of the array
+ * @param count the number of characters in the array
+ */
+ public void shape (char[] text, int start, int count)
+ {
+ shape (text, start, count, 1 << key);
+ }
+
+ /**
+ * Given a unicode block object, return corresponding language constant.
+ * If the block is not recognized, returns zero. Note that as there
+ * is no separate ARABIC block in Character, this case must
+ * be specially handled by the caller; EASTERN_ARABIC is preferred when
+ * both are specified.
+ * @param b the unicode block to classify
+ * @return the language constant, or zero if not recognized
+ */
+ private int classify(UnicodeBlock b)
+ {
+ if (b == null)
+ return 0;
+ // ARABIC is handled by the caller; from testing we know
+ // that EASTERN_ARABIC takes precedence.
+ if (b == UnicodeBlock.ARABIC)
+ return EASTERN_ARABIC;
+ if (b == UnicodeBlock.BENGALI)
+ return BENGALI;
+ if (b == UnicodeBlock.DEVANAGARI)
+ return DEVANAGARI;
+ if (b == UnicodeBlock.ETHIOPIC)
+ return ETHIOPIC;
+ if (b == UnicodeBlock.BASIC_LATIN
+ || b == UnicodeBlock.LATIN_1_SUPPLEMENT
+ || b == UnicodeBlock.LATIN_EXTENDED_A
+ || b == UnicodeBlock.LATIN_EXTENDED_ADDITIONAL
+ || b == UnicodeBlock.LATIN_EXTENDED_B)
+ return EUROPEAN;
+ if (b == UnicodeBlock.GUJARATI)
+ return GUJARATI;
+ if (b == UnicodeBlock.GURMUKHI)
+ return GURMUKHI;
+ if (b == UnicodeBlock.KANNADA)
+ return KANNADA;
+ if (b == UnicodeBlock.KHMER)
+ return KHMER;
+ if (b == UnicodeBlock.LAO)
+ return LAO;
+ if (b == UnicodeBlock.MALAYALAM)
+ return MALAYALAM;
+ if (b == UnicodeBlock.MONGOLIAN)
+ return MONGOLIAN;
+ if (b == UnicodeBlock.MYANMAR)
+ return MYANMAR;
+ if (b == UnicodeBlock.ORIYA)
+ return ORIYA;
+ if (b == UnicodeBlock.TAMIL)
+ return TAMIL;
+ if (b == UnicodeBlock.TELUGU)
+ return TELUGU;
+ if (b == UnicodeBlock.THAI)
+ return THAI;
+ if (b == UnicodeBlock.TIBETAN)
+ return TIBETAN;
+ return 0;
+ }
+
+ /**
+ * Shape the given text, using the indicated initial context.
+ * If this shaper is not a contextual shaper, then the given context
+ * will be ignored.
+ * @param text the text to shape
+ * @param start the index of the first character of the text to shape
+ * @param count the number of characters to shape in the text
+ * @param context the initial context
+ * @throws IllegalArgumentException if the initial context is invalid
+ */
+ public void shape (char[] text, int start, int count, int context)
+ {
+ int currentContext;
+ if (isContextual())
+ {
+ if (Integer.bitCount(context) != 1 || (context & ~ALL_RANGES) != 0)
+ throw new IllegalArgumentException("invalid context argument");
+ // If the indicated context is not one we are handling, reset it.
+ if ((context & mask) == 0)
+ currentContext = -1;
+ else
+ currentContext = Integer.numberOfTrailingZeros(context);
+ }
+ else
+ currentContext = key;
+
+ for (int i = 0; i < count; ++i)
+ {
+ char c = text[start + i];
+ if (c >= '0' && c <= '9')
+ {
+ if (currentContext >= 0)
+ {
+ // Shape into the current context.
+ if (c == '0'
+ && ((1 << currentContext) == TAMIL
+ || (1 << currentContext) == ETHIOPIC))
+ {
+ // No digit 0 in this context; do nothing.
+ }
+ else
+ text[start + i]
+ = (char) (zeroDigits[currentContext] + c - '0');
+ }
+ }
+ else if (isContextual())
+ {
+ // if c is in a group, set currentContext; else reset it.
+ int group = classify(UnicodeBlock.of(c));
+ // Specially handle ARABIC.
+ if (group == EASTERN_ARABIC && (mask & EASTERN_ARABIC) == 0
+ && (mask & ARABIC) != 0)
+ group = ARABIC;
+ if ((mask & group) != 0)
+ {
+ // The character was classified as being in a group
+ // we recognize, and it was selected by the shaper.
+ // So, change the context.
+ currentContext = Integer.numberOfTrailingZeros(group);
+ }
+ }
+ }
+ }
+
+ public boolean equals (Object obj)
+ {
+ if (! (obj instanceof NumericShaper))
+ return false;
+ NumericShaper tmp = (NumericShaper) obj;
+ return key == tmp.key && mask == tmp.mask;
+ }
+
+ public int hashCode ()
+ {
+ return key ^ mask;
+ }
+
+ public String toString ()
+ {
+ // For debugging only.
+ return "key=" + key + "; mask=" + mask;
+ }
+
+ /**
+ * Return a non-contextual shaper which can shape to a single range.
+ * All ASCII digits in the input text are translated to this language.
+ * @param singleRange the target language
+ * @return a non-contextual shaper for this language
+ * @throws IllegalArgumentException if the argument does not name a
+ * single language, as specified by the constants declared in this class
+ */
+ public static NumericShaper getShaper (int singleRange)
+ {
+ if (Integer.bitCount(singleRange) != 1)
+ throw new IllegalArgumentException("more than one bit set in argument");
+ if ((singleRange & ~ALL_RANGES) != 0)
+ throw new IllegalArgumentException("argument out of range");
+ return new NumericShaper(singleRange, Integer.MIN_VALUE | singleRange);
+ }
+
+ /**
+ * Return a contextual shaper which can shape to any of the indicated
+ * languages. The default initial context for this shaper is EUROPEAN.
+ * @param ranges the ranges to shape to
+ * @return a contextual shaper which will target any of these ranges
+ * @throws IllegalArgumentException if the argument specifies an
+ * unrecognized range
+ */
+ public static NumericShaper getContextualShaper (int ranges)
+ {
+ if ((ranges & ~ALL_RANGES) != 0)
+ throw new IllegalArgumentException("argument out of range");
+ return new NumericShaper(EUROPEAN, ranges);
+ }
+
+ /**
+ * Return a contextual shaper which can shape to any of the indicated
+ * languages. The default initial context for this shaper is given as
+ * an argument.
+ * @param ranges the ranges to shape to
+ * @param defaultContext the default initial context
+ * @return a contextual shaper which will target any of these ranges
+ * @throws IllegalArgumentException if the ranges argument specifies an
+ * unrecognized range, or if the defaultContext argument does not specify
+ * a single valid range
+ */
+ public static NumericShaper getContextualShaper (int ranges,
+ int defaultContext)
+ {
+ if (Integer.bitCount(defaultContext) != 1)
+ throw new IllegalArgumentException("more than one bit set in context");
+ if ((ranges & ~ALL_RANGES) != 0 || (defaultContext & ~ALL_RANGES) != 0)
+ throw new IllegalArgumentException("argument out of range");
+ return new NumericShaper(defaultContext, ranges);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/OpenType.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/OpenType.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/OpenType.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/OpenType.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,111 @@
+/* OpenType.java
+ Copyright (C) 2003 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., 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.font;
+
+/**
+ * @author Michael Koch
+ */
+public interface OpenType
+{
+ int TAG_ACNT = 1633906292;
+ int TAG_AVAR = 1635148146;
+ int TAG_BASE = 1111577413;
+ int TAG_BDAT = 1650745716;
+ int TAG_BLOC = 1651273571;
+ int TAG_BSLN = 1651731566;
+ int TAG_CFF = 1128678944;
+ int TAG_CMAP = 1668112752;
+ int TAG_CVAR = 1668702578;
+ int TAG_CVT = 1668707360;
+ int TAG_DSIG = 1146308935;
+ int TAG_EBDT = 1161970772;
+ int TAG_EBLC = 1161972803;
+ int TAG_EBSC = 1161974595;
+ int TAG_FDSC = 1717859171;
+ int TAG_FEAT = 1717920116;
+ int TAG_FMTX = 1718449272;
+ int TAG_FPGM = 1718642541;
+ int TAG_FVAR = 1719034226;
+ int TAG_GASP = 1734439792;
+ int TAG_GDEF = 1195656518;
+ int TAG_GLYF = 1735162214;
+ int TAG_GPOS = 1196445523;
+ int TAG_GSUB = 1196643650;
+ int TAG_GVAR = 1735811442;
+ int TAG_HDMX = 1751412088;
+ int TAG_HEAD = 1751474532;
+ int TAG_HHEA = 1751672161;
+ int TAG_HMTX = 1752003704;
+ int TAG_JSTF = 1246975046;
+ int TAG_JUST = 1786082164;
+ int TAG_KERN = 1801810542;
+ int TAG_LCAR = 1818452338;
+ int TAG_LOCA = 1819239265;
+ int TAG_LTSH = 1280594760;
+ int TAG_MAXP = 1835104368;
+ int TAG_MMFX = 1296909912;
+ int TAG_MMSD = 1296913220;
+ int TAG_MORT = 1836020340;
+ int TAG_NAME = 1851878757;
+ int TAG_OPBD = 1836020340;
+ int TAG_OS2 = 1330851634;
+ int TAG_PCLT = 1346587732;
+ int TAG_POST = 1886352244;
+ int TAG_PREP = 1886545264;
+ int TAG_PROP = 1886547824;
+ int TAG_TRAK = 1953653099;
+ int TAG_TYP1 = 1954115633;
+ int TAG_VDMX = 1447316824;
+ int TAG_VHEA = 1986553185;
+ int TAG_VMTX = 1986884728;
+
+ byte[] getFontTable (int sfntTag);
+
+ byte[] getFontTable (int sfntTag, int offset, int count);
+
+ byte[] getFontTable (String strSfntTag);
+
+ byte[] getFontTable (String strSfntTag, int offset, int count);
+
+ int getFontTableSize (int sfntTag);
+
+ int getFontTableSize (String strSfntTag);
+
+ int getVersion ();
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ShapeGraphicAttribute.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ShapeGraphicAttribute.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ShapeGraphicAttribute.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/ShapeGraphicAttribute.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,185 @@
+/* ShapeGraphicAttribute.java
+ Copyright (C) 2003 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., 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.font;
+
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * This is an implementation of GraphicAttribute that draws shapes in a TextLayout.
+ *
+ * @author Lillian Angel (langel at redhat dot com)
+ */
+public final class ShapeGraphicAttribute extends GraphicAttribute
+{
+ /** True if the shape should be filled. */
+ public static final boolean FILL = false;
+
+ /** True if the shape should be stroked with a 1-pixel wide stroke. */
+ public static final boolean STROKE = true;
+
+ private Shape shape;
+ private boolean stroke;
+ private Rectangle2D bounds;
+
+ /**
+ * Constructor.
+ *
+ * @param shape - the Shape to render. The Shape is rendered with its origin.
+ * @param alignment - the alignment
+ * @param stroke - true if the Shape should be stroked; false if the Shape
+ * should be filled.
+ */
+ public ShapeGraphicAttribute(Shape shape, int alignment, boolean stroke)
+ {
+ super(alignment);
+ this.shape = shape;
+ this.stroke = stroke;
+ this.bounds = shape.getBounds2D();
+ }
+
+ /**
+ * Draws the graphic at the given location.
+ *
+ * @param graphics - the graphics to use.
+ * @param x - the x location to draw at.
+ * @param y - the y location to draw at.
+ */
+ public void draw(Graphics2D graphics, float x, float y)
+ {
+ graphics.translate(x, y);
+ if (stroke == STROKE)
+ graphics.draw(shape);
+ else
+ graphics.fill(shape);
+ graphics.translate(- x, - y);
+ }
+
+ /**
+ * Compares this ShapeGraphicAttribute to obj.
+ *
+ * @param obj - the object to compare.
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof ShapeGraphicAttribute))
+ return false;
+
+ return equals((ShapeGraphicAttribute) obj);
+ }
+
+ /**
+ * Compares this ShapeGraphicAttribute to rhs.
+ *
+ * @param rhs - the ShapeGraphicAttribute to compare.
+ */
+ public boolean equals(ShapeGraphicAttribute rhs)
+ {
+ return (this == rhs || (this.shape.equals(rhs.shape)
+ && getAlignment() == rhs.getAlignment()
+ && stroke == rhs.stroke
+ && getAdvance() == rhs.getAdvance()
+ && getAscent() == rhs.getAscent()
+ && getBounds().equals(rhs.getBounds())
+ && getDescent() == rhs.getDescent()
+ && hashCode() == rhs.hashCode()));
+ }
+
+ /**
+ * Gets the distance from the origin of its Shape to the right side of the
+ * bounds of its Shape.
+ *
+ * @return the advance
+ */
+ public float getAdvance()
+ {
+ return Math.max(0, (float) bounds.getMaxX());
+ }
+
+ /**
+ * Gets the positive distance from the origin of its Shape to the top of
+ * bounds.
+ *
+ * @return the ascent
+ */
+ public float getAscent()
+ {
+ return Math.max(0, -(float) bounds.getMinY());
+ }
+
+ /**
+ * Gets the distance from the origin of its Shape to the bottom of the bounds.
+ *
+ * @return the descent
+ */
+ public float getDescent()
+ {
+ return Math.max(0, (float) bounds.getMaxY());
+ }
+
+ /**
+ * Returns a Rectangle2D that encloses all of the bits drawn by this shape.
+ *
+ * @return the bounds of the shape.
+ */
+ public Rectangle2D getBounds()
+ {
+ Rectangle2D.Float bounds = new Rectangle2D.Float();
+ bounds.setRect(this.bounds);
+
+ if (stroke == STROKE)
+ {
+ bounds.width++;
+ bounds.height++;
+ }
+
+ return bounds;
+ }
+
+ /**
+ * Gets the hash code.
+ *
+ * @return the hash code.
+ */
+ public int hashCode()
+ {
+ return shape.hashCode();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextAttribute.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextAttribute.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextAttribute.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextAttribute.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,309 @@
+/* TextAttribute.java --
+ Copyright (C) 2003, 2004, 2005 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., 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.font;
+
+import java.io.InvalidObjectException;
+import java.text.AttributedCharacterIterator;
+
+/**
+ * Attributes (and associated values) that can be used to define an
+ * {@link java.text.AttributedString}.
+ */
+public final class TextAttribute extends AttributedCharacterIterator.Attribute
+{
+ private static final long serialVersionUID = 7744112784117861702L;
+
+ /** A key for the background paint attribute. */
+ public static final TextAttribute BACKGROUND =
+ new TextAttribute("background");
+
+ /** A key for the BIDI_EMBEDDING attribute. */
+ public static final TextAttribute BIDI_EMBEDDING =
+ new TextAttribute("bidi_embedding");
+
+ /** A key for the CHAR_REPLACEMENT attribute. */
+ public static final TextAttribute CHAR_REPLACEMENT =
+ new TextAttribute("char_replacement");
+
+ /** A key for the FAMILY attribute. */
+ public static final TextAttribute FAMILY = new TextAttribute("family");
+
+ /** A key for the font attribute. */
+ public static final TextAttribute FONT = new TextAttribute("font");
+
+ /** A key for the foreground paint attribute. */
+ public static final TextAttribute FOREGROUND =
+ new TextAttribute("foreground");
+
+ /** A key for the INPUT_METHOD_HIGHLIGHT attribute. */
+ public static final TextAttribute INPUT_METHOD_HIGHLIGHT =
+ new TextAttribute("input method highlight");
+
+ /** A key for the INPUT_METHOD_UNDERLINE attribute. */
+ public static final TextAttribute INPUT_METHOD_UNDERLINE =
+ new TextAttribute("input method underline");
+
+ /** A key for the text justification attribute. */
+ public static final TextAttribute JUSTIFICATION =
+ new TextAttribute("justification");
+
+ /**
+ * A value that can be used with the {@link #JUSTIFICATION} attribute to
+ * indicate full justification of the text.
+ */
+ public static final Float JUSTIFICATION_FULL = new Float(1.0);
+
+ /**
+ * A value that can be used with the {@link #JUSTIFICATION} attribute to
+ * indicate no justification of the text.
+ */
+ public static final Float JUSTIFICATION_NONE = new Float(0.0);
+
+ /** A key for the NUMERIC_SHAPING attribute. */
+ public static final TextAttribute NUMERIC_SHAPING =
+ new TextAttribute("numeric_shaping");
+
+ /** A key for the POSTURE attribute. */
+ public static final TextAttribute POSTURE = new TextAttribute("posture");
+
+ /** A value that can be used with the {@link #POSTURE} attribute. */
+ public static final Float POSTURE_OBLIQUE = new Float(0.2);
+
+ /** A value that can be used with the {@link #POSTURE} attribute. */
+ public static final Float POSTURE_REGULAR = new Float(0.0);
+
+ /** A key for the RUN_DIRECTION attribute. */
+ public static final TextAttribute RUN_DIRECTION =
+ new TextAttribute("run_direction");
+
+ /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
+ public static final Boolean RUN_DIRECTION_LTR = Boolean.FALSE;
+
+ /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
+ public static final Boolean RUN_DIRECTION_RTL = Boolean.TRUE;
+
+ /** A key for the text size attribute. */
+ public static final TextAttribute SIZE = new TextAttribute("size");
+
+ /** A key for the STRIKETHROUGH attribute. */
+ public static final TextAttribute STRIKETHROUGH =
+ new TextAttribute("strikethrough");
+
+ /** A value that can be used with the {@link #STRIKETHROUGH} attribute. */
+ public static final Boolean STRIKETHROUGH_ON = Boolean.TRUE;
+
+ /** A key for the SUPERSCRIPT attribute. */
+ public static final TextAttribute SUPERSCRIPT =
+ new TextAttribute("superscript");
+
+ /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
+ public static final Integer SUPERSCRIPT_SUB = new Integer(-1);
+
+ /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
+ public static final Integer SUPERSCRIPT_SUPER = new Integer(1);
+
+ /** A key for the SWAP_COLORS attribute. */
+ public static final TextAttribute SWAP_COLORS =
+ new TextAttribute("swap_colors");
+
+ /** A value that can be used with the {@link #SWAP_COLORS} attribute. */
+ public static final Boolean SWAP_COLORS_ON = Boolean.TRUE;
+
+ /** A key for the TRANFORM attribute. */
+ public static final TextAttribute TRANSFORM = new TextAttribute("transform");
+
+ /** A key for the UNDERLINE attribute. */
+ public static final TextAttribute UNDERLINE = new TextAttribute("underline");
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_LOW_DASHED = new Integer(5);
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_LOW_DOTTED = new Integer(3);
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_LOW_GRAY = new Integer(4);
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_LOW_ONE_PIXEL = new Integer(1);
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_LOW_TWO_PIXEL = new Integer(2);
+
+ /** A value that can be used with the {@link #UNDERLINE} attribute. */
+ public static final Integer UNDERLINE_ON = new Integer(0);
+
+ /** A key for the WEIGHT attribute. */
+ public static final TextAttribute WEIGHT = new TextAttribute("weight");
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_BOLD = new Float(2.0);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_DEMIBOLD = new Float(1.75);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_DEMILIGHT = new Float(0.875);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_EXTRA_LIGHT = new Float(0.5);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_EXTRABOLD = new Float(2.5);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_HEAVY = new Float(2.25);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_LIGHT = new Float(0.75);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_MEDIUM = new Float(1.5);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_REGULAR = new Float(1.0);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_SEMIBOLD = new Float(1.25);
+
+ /** A value that can be used with the {@link #WEIGHT} attribute. */
+ public static final Float WEIGHT_ULTRABOLD = new Float(2.75);
+
+ /** A key for the WIDTH attribute. */
+ public static final TextAttribute WIDTH = new TextAttribute("width");
+
+ /** A value that can be used with the {@link #WIDTH} attribute. */
+ public static final Float WIDTH_CONDENSED = new Float(0.75);
+
+ /** A value that can be used with the {@link #WIDTH} attribute. */
+ public static final Float WIDTH_EXTENDED = new Float(1.5);
+
+ /** A value that can be used with the {@link #WIDTH} attribute. */
+ public static final Float WIDTH_REGULAR = new Float(1.0);
+
+ /** A value that can be used with the {@link #WIDTH} attribute. */
+ public static final Float WIDTH_SEMI_CONDENSED = new Float(0.875);
+
+ /** A value that can be used with the {@link #WIDTH} attribute. */
+ public static final Float WIDTH_SEMI_EXTENDED = new Float(1.25);
+
+ /**
+ * Creates a new attribute.
+ *
+ * @param name the name.
+ */
+ protected TextAttribute(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * After deserialization, this method ensures that only one instance of
+ * each attribute is used.
+ *
+ * @return The (single) attribute instance.
+ *
+ * @throws InvalidObjectException if the attribute is not recognised.
+ */
+ protected Object readResolve()
+ throws InvalidObjectException
+ {
+ if (this.getName().equals("background"))
+ return BACKGROUND;
+
+ if (this.getName().equals("bidi_embedding"))
+ return BIDI_EMBEDDING;
+
+ if (this.getName().equals("char_replacement"))
+ return CHAR_REPLACEMENT;
+
+ if (this.getName().equals("family"))
+ return FAMILY;
+
+ if (this.getName().equals("font"))
+ return FONT;
+
+ if (this.getName().equals("foreground"))
+ return FOREGROUND;
+
+ if (this.getName().equals("input method highlight"))
+ return INPUT_METHOD_HIGHLIGHT;
+
+ if (this.getName().equals("input method underline"))
+ return INPUT_METHOD_UNDERLINE;
+
+ if (this.getName().equals("justification"))
+ return JUSTIFICATION;
+
+ if (this.getName().equals("numeric_shaping"))
+ return NUMERIC_SHAPING;
+
+ if (this.getName().equals("posture"))
+ return POSTURE;
+
+ if (this.getName().equals("run_direction"))
+ return RUN_DIRECTION;
+
+ if (this.getName().equals("size"))
+ return SIZE;
+
+ if (this.getName().equals("strikethrough"))
+ return STRIKETHROUGH;
+
+ if (this.getName().equals("superscript"))
+ return SUPERSCRIPT;
+
+ if (this.getName().equals("swap_colors"))
+ return SWAP_COLORS;
+
+ if (this.getName().equals("transform"))
+ return TRANSFORM;
+
+ if (this.getName().equals("underline"))
+ return UNDERLINE;
+
+ if (this.getName().equals("weight"))
+ return WEIGHT;
+
+ if (this.getName().equals("width"))
+ return WIDTH;
+
+ throw new InvalidObjectException("Can't resolve Attribute: " + getName());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextHitInfo.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextHitInfo.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextHitInfo.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextHitInfo.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,125 @@
+/* TextHitInfo.java --
+ Copyright (C) 2002, 2005 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., 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.font;
+
+/**
+ * @author John Leuner (jewel at debian.org)
+ */
+public final class TextHitInfo
+{
+ private int charIndex;
+ private boolean leadingEdge;
+
+ TextHitInfo (int charIndex, boolean leadingEdge)
+ {
+ this.charIndex = charIndex;
+ this.leadingEdge = leadingEdge;
+ }
+
+ public int getCharIndex()
+ {
+ return charIndex;
+ }
+
+ public boolean isLeadingEdge()
+ {
+ return leadingEdge;
+ }
+
+ public int getInsertionIndex()
+ {
+ return (leadingEdge ? charIndex : charIndex + 1);
+ }
+
+ public int hashCode()
+ {
+ return charIndex;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if(obj instanceof TextHitInfo)
+ return this.equals((TextHitInfo) obj);
+
+ return false;
+ }
+
+ public boolean equals(TextHitInfo hitInfo)
+ {
+ return (charIndex == hitInfo.getCharIndex ())
+ && (leadingEdge == hitInfo.isLeadingEdge ());
+ }
+
+ public static TextHitInfo leading(int charIndex)
+ {
+ return new TextHitInfo (charIndex, true);
+ }
+
+ public static TextHitInfo trailing(int charIndex)
+ {
+ return new TextHitInfo (charIndex, false);
+ }
+
+ public static TextHitInfo beforeOffset(int offset)
+ {
+ return new TextHitInfo (offset, false);
+ }
+
+ public static TextHitInfo afterOffset(int offset)
+ {
+ return new TextHitInfo (offset, true);
+ }
+
+ public TextHitInfo getOtherHit()
+ {
+ return (leadingEdge ? trailing (charIndex - 1) : leading (charIndex + 1));
+ }
+
+ public TextHitInfo getOffsetHit(int offset)
+ {
+ return new TextHitInfo (charIndex + offset, leadingEdge);
+ }
+
+ public String toString()
+ {
+ return "TextHitInfo["
+ + charIndex
+ + (leadingEdge ? "L" : "T" )
+ + "]";
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextLayout.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextLayout.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextLayout.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextLayout.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,713 @@
+/* TextLayout.java --
+ Copyright (C) 2006 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., 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.font;
+
+import gnu.classpath.NotImplementedException;
+
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
+import java.text.CharacterIterator;
+import java.text.AttributedCharacterIterator;
+import java.text.Bidi;
+import java.util.Map;
+
+/**
+ * @author Sven de Marothy
+ */
+public final class TextLayout implements Cloneable
+{
+ private GlyphVector[] runs;
+ private Font font;
+ private FontRenderContext frc;
+ private String string;
+ private Rectangle2D boundsCache;
+ private LineMetrics lm;
+
+ /**
+ * Start and end character indices of the runs.
+ * First index is the run number, second is 0 or 1 for the starting
+ * and ending character index of the run, respectively.
+ */
+ private int[][] runIndices;
+
+ /**
+ * Character indices.
+ * Fixt index is the glyphvector, second index is the (first) glyph.
+ */
+ private int[][] charIndices;
+
+ /**
+ * Base directionality, determined from the first char.
+ */
+ private boolean leftToRight;
+
+ /**
+ * Whether this layout contains whitespace or not.
+ */
+ private boolean hasWhitespace = false;
+
+ /**
+ * The default caret policy.
+ */
+ public static final TextLayout.CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy();
+
+ /**
+ * Constructs a TextLayout.
+ */
+ public TextLayout (String string, Font font, FontRenderContext frc)
+ {
+ this.font = font;
+ this.frc = frc;
+ this.string = string;
+ lm = font.getLineMetrics(string, frc);
+
+ // Get base direction and whitespace info
+ getStringProperties();
+
+ if( Bidi.requiresBidi( string.toCharArray(), 0, string.length() ) )
+ {
+ Bidi bidi = new Bidi( string, leftToRight ?
+ Bidi.DIRECTION_LEFT_TO_RIGHT :
+ Bidi.DIRECTION_RIGHT_TO_LEFT );
+ int rc = bidi.getRunCount();
+ byte[] table = new byte[ rc ];
+ for(int i = 0; i < table.length; i++)
+ table[i] = (byte)bidi.getRunLevel(i);
+
+ runs = new GlyphVector[ rc ];
+ runIndices = new int[rc][2];
+ for(int i = 0; i < runs.length; i++)
+ {
+ runIndices[i][0] = bidi.getRunStart( i );
+ runIndices[i][1] = bidi.getRunLimit( i );
+ if( runIndices[i][0] != runIndices[i][1] ) // no empty runs.
+ {
+ runs[i] = font.layoutGlyphVector
+ ( frc, string.toCharArray(),
+ runIndices[i][0], runIndices[i][1],
+ ((table[i] & 1) == 0) ? Font.LAYOUT_LEFT_TO_RIGHT :
+ Font.LAYOUT_RIGHT_TO_LEFT );
+ }
+ }
+ Bidi.reorderVisually( table, 0, runs, 0, runs.length );
+ }
+ else
+ {
+ runs = new GlyphVector[ 1 ];
+ runIndices = new int[1][2];
+ runIndices[0][0] = 0;
+ runIndices[0][1] = string.length();
+ runs[ 0 ] = font.layoutGlyphVector( frc, string.toCharArray(),
+ 0, string.length(),
+ leftToRight ?
+ Font.LAYOUT_LEFT_TO_RIGHT :
+ Font.LAYOUT_RIGHT_TO_LEFT );
+ }
+ setCharIndices();
+ }
+
+ public TextLayout (String string, Map attributes, FontRenderContext frc)
+ {
+ this( string, new Font( attributes ), frc );
+ }
+
+ public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
+ {
+ // FIXME: Very rudimentary.
+ this(getText(text), getFont(text), frc);
+ }
+
+ /**
+ * Package-private constructor to make a textlayout from an existing one.
+ * This is used by TextMeasurer for returning sub-layouts, and it
+ * saves a lot of time in not having to relayout the text.
+ */
+ TextLayout(TextLayout t, int startIndex, int endIndex)
+ {
+ font = t.font;
+ frc = t.frc;
+ boundsCache = null;
+ lm = t.lm;
+ leftToRight = t.leftToRight;
+
+ if( endIndex > t.getCharacterCount() )
+ endIndex = t.getCharacterCount();
+ string = t.string.substring( startIndex, endIndex );
+
+ int startingRun = t.charIndices[startIndex][0];
+ int nRuns = 1 + t.charIndices[endIndex - 1][0] - startingRun;
+ runIndices = new int[ nRuns ][2];
+
+ runs = new GlyphVector[ nRuns ];
+ for( int i = 0; i < nRuns; i++ )
+ {
+ GlyphVector run = t.runs[ i + startingRun ];
+ // Copy only the relevant parts of the first and last runs.
+ int beginGlyphIndex = (i > 0) ? 0 : t.charIndices[startIndex][1];
+ int numEntries = ( i < nRuns - 1) ? run.getNumGlyphs() :
+ 1 + t.charIndices[endIndex - 1][1] - beginGlyphIndex;
+
+ int[] codes = run.getGlyphCodes(beginGlyphIndex, numEntries, null);
+ runs[ i ] = font.createGlyphVector( frc, codes );
+ runIndices[ i ][0] = t.runIndices[i + startingRun][0] - startIndex;
+ runIndices[ i ][1] = t.runIndices[i + startingRun][1] - startIndex;
+ }
+ runIndices[ nRuns - 1 ][1] = endIndex - 1;
+
+ setCharIndices();
+ determineWhiteSpace();
+ }
+
+ private void setCharIndices()
+ {
+ charIndices = new int[ getCharacterCount() ][2];
+ int i = 0;
+ int currentChar = 0;
+ for(int run = 0; run < runs.length; run++)
+ {
+ currentChar = -1;
+ for( int gi = 0; gi < runs[ run ].getNumGlyphs(); gi++)
+ {
+ if( runs[ run ].getGlyphCharIndex( gi ) != currentChar )
+ {
+ charIndices[ i ][0] = run;
+ charIndices[ i ][1] = gi;
+ currentChar = runs[ run ].getGlyphCharIndex( gi );
+ i++;
+ }
+ }
+ }
+ }
+
+ private static String getText(AttributedCharacterIterator iter)
+ {
+ StringBuffer sb = new StringBuffer();
+ int idx = iter.getIndex();
+ for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
+ sb.append(c);
+ iter.setIndex( idx );
+ return sb.toString();
+ }
+
+ private static Font getFont(AttributedCharacterIterator iter)
+ {
+ Font f = (Font)iter.getAttribute(TextAttribute.FONT);
+ if( f == null )
+ {
+ int size;
+ Float i = (Float)iter.getAttribute(TextAttribute.SIZE);
+ if( i != null )
+ size = (int)i.floatValue();
+ else
+ size = 14;
+ f = new Font("Dialog", Font.PLAIN, size );
+ }
+ return f;
+ }
+
+ /**
+ * Scan the character run for the first strongly directional character,
+ * which in turn defines the base directionality of the whole layout.
+ */
+ private void getStringProperties()
+ {
+ boolean gotDirection = false;
+ int i = 0;
+
+ leftToRight = true;
+ while( i < string.length() && !gotDirection )
+ switch( Character.getDirectionality( string.charAt( i++ ) ) )
+ {
+ case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
+ case Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING:
+ case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
+ gotDirection = true;
+ break;
+
+ case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
+ case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
+ case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
+ case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
+ leftToRight = false;
+ gotDirection = true;
+ break;
+ }
+ determineWhiteSpace();
+ }
+
+ private void determineWhiteSpace()
+ {
+ // Determine if there's whitespace in the thing.
+ // Ignore trailing chars.
+ int i = string.length() - 1;
+ hasWhitespace = false;
+ while( i >= 0 && Character.isWhitespace( string.charAt(i) ) )
+ i--;
+ // Check the remaining chars
+ while( i >= 0 )
+ if( Character.isWhitespace( string.charAt(i--) ) )
+ hasWhitespace = true;
+ }
+
+ protected Object clone ()
+ {
+ return new TextLayout( string, font, frc );
+ }
+
+ public void draw (Graphics2D g2, float x, float y)
+ {
+ for(int i = 0; i < runs.length; i++)
+ {
+ g2.drawGlyphVector(runs[i], x, y);
+ Rectangle2D r = runs[i].getLogicalBounds();
+ x += r.getWidth();
+ }
+ }
+
+ public boolean equals (Object obj)
+ {
+ if( !( obj instanceof TextLayout) )
+ return false;
+
+ return equals( (TextLayout) obj );
+ }
+
+ public boolean equals (TextLayout tl)
+ {
+ if( runs.length != tl.runs.length )
+ return false;
+ // Compare all glyph vectors.
+ for( int i = 0; i < runs.length; i++ )
+ if( !runs[i].equals( tl.runs[i] ) )
+ return false;
+ return true;
+ }
+
+ public float getAdvance ()
+ {
+ float totalAdvance = 0f;
+ for(int i = 0; i < runs.length; i++)
+ totalAdvance += runs[i].getLogicalBounds().getWidth();
+ return totalAdvance;
+ }
+
+ public float getAscent ()
+ {
+ return lm.getAscent();
+ }
+
+ public byte getBaseline ()
+ {
+ return (byte)lm.getBaselineIndex();
+ }
+
+ public float[] getBaselineOffsets ()
+ {
+ return lm.getBaselineOffsets();
+ }
+
+ public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
+ {
+ if( secondEndpoint - firstEndpoint <= 0 )
+ return new Rectangle2D.Float(); // Hmm?
+
+ if( firstEndpoint < 0 || secondEndpoint > getCharacterCount())
+ return new Rectangle2D.Float();
+
+ GeneralPath gp = new GeneralPath();
+
+ int ri = charIndices[ firstEndpoint ][0];
+ int gi = charIndices[ firstEndpoint ][1];
+
+ double advance = 0;
+
+ for( int i = 0; i < ri; i++ )
+ advance += runs[i].getLogicalBounds().getWidth();
+
+ for( int i = ri; i <= charIndices[ secondEndpoint - 1 ][0]; i++ )
+ {
+ int dg;
+ if( i == charIndices[ secondEndpoint - 1 ][0] )
+ dg = charIndices[ secondEndpoint - 1][1];
+ else
+ dg = runs[i].getNumGlyphs() - 1;
+
+ for( int j = 0; j <= dg; j++ )
+ {
+ Rectangle2D r2 = (runs[i].getGlyphVisualBounds( j )).
+ getBounds2D();
+ Point2D p = runs[i].getGlyphPosition( j );
+ r2.setRect( advance + r2.getX(), r2.getY(),
+ r2.getWidth(), r2.getHeight() );
+ gp.append(r2, false);
+ }
+
+ advance += runs[i].getLogicalBounds().getWidth();
+ }
+ return gp;
+ }
+
+ public Rectangle2D getBounds()
+ {
+ if( boundsCache == null )
+ boundsCache = getOutline(new AffineTransform()).getBounds();
+ return boundsCache;
+ }
+
+ public float[] getCaretInfo (TextHitInfo hit)
+ {
+ return getCaretInfo(hit, getBounds());
+ }
+
+ public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public Shape getCaretShape (TextHitInfo hit)
+ {
+ return getCaretShape( hit, getBounds() );
+ }
+
+ public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public Shape[] getCaretShapes (int offset)
+ {
+ return getCaretShapes( offset, getBounds() );
+ }
+
+ public Shape[] getCaretShapes (int offset, Rectangle2D bounds)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public int getCharacterCount ()
+ {
+ return string.length();
+ }
+
+ public byte getCharacterLevel (int index)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public float getDescent ()
+ {
+ return lm.getDescent();
+ }
+
+ public TextLayout getJustifiedLayout (float justificationWidth)
+ {
+ TextLayout newLayout = (TextLayout)clone();
+
+ if( hasWhitespace )
+ newLayout.handleJustify( justificationWidth );
+
+ return newLayout;
+ }
+
+ public float getLeading ()
+ {
+ return lm.getLeading();
+ }
+
+ public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)
+ {
+ return getLogicalHighlightShape( firstEndpoint, secondEndpoint,
+ getBounds() );
+ }
+
+ public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
+ Rectangle2D bounds)
+ {
+ if( secondEndpoint - firstEndpoint <= 0 )
+ return new Rectangle2D.Float(); // Hmm?
+
+ if( firstEndpoint < 0 || secondEndpoint > getCharacterCount())
+ return new Rectangle2D.Float();
+
+ Rectangle2D r = null;
+ int ri = charIndices[ firstEndpoint ][0];
+ int gi = charIndices[ firstEndpoint ][1];
+
+ double advance = 0;
+
+ for( int i = 0; i < ri; i++ )
+ advance += runs[i].getLogicalBounds().getWidth();
+
+ for( int i = ri; i <= charIndices[ secondEndpoint - 1 ][0]; i++ )
+ {
+ int dg; // last index in this run to use.
+ if( i == charIndices[ secondEndpoint - 1 ][0] )
+ dg = charIndices[ secondEndpoint - 1][1];
+ else
+ dg = runs[i].getNumGlyphs() - 1;
+
+ for(; gi <= dg; gi++ )
+ {
+ Rectangle2D r2 = (runs[i].getGlyphLogicalBounds( gi )).
+ getBounds2D();
+ if( r == null )
+ r = r2;
+ else
+ r = r.createUnion(r2);
+ }
+ gi = 0; // reset glyph index into run for next run.
+
+ advance += runs[i].getLogicalBounds().getWidth();
+ }
+
+ return r;
+ }
+
+ public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
+ TextHitInfo secondEndpoint)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public TextHitInfo getNextLeftHit (int offset)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public TextHitInfo getNextLeftHit (TextHitInfo hit)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public TextHitInfo getNextRightHit (int offset)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public TextHitInfo getNextRightHit (TextHitInfo hit)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public Shape getOutline (AffineTransform tx)
+ {
+ float x = 0f;
+ GeneralPath gp = new GeneralPath();
+ for(int i = 0; i < runs.length; i++)
+ {
+ gp.append( runs[i].getOutline( x, 0f ), false );
+ Rectangle2D r = runs[i].getLogicalBounds();
+ x += r.getWidth();
+ }
+ if( tx != null )
+ gp.transform( tx );
+ return gp;
+ }
+
+ public float getVisibleAdvance ()
+ {
+ float totalAdvance = 0f;
+
+ if( runs.length <= 0 )
+ return 0f;
+
+ // No trailing whitespace
+ if( !Character.isWhitespace( string.charAt( string.length() -1 ) ) )
+ return getAdvance();
+
+ // Get length of all runs up to the last
+ for(int i = 0; i < runs.length - 1; i++)
+ totalAdvance += runs[i].getLogicalBounds().getWidth();
+
+ int lastRun = runIndices[ runs.length - 1 ][0];
+ int j = string.length() - 1;
+ while( j >= lastRun && Character.isWhitespace( string.charAt( j ) ) ) j--;
+
+ if( j < lastRun )
+ return totalAdvance; // entire last run is whitespace
+
+ int lastNonWSChar = j - lastRun;
+ j = 0;
+ while( runs[ runs.length - 1 ].getGlyphCharIndex( j )
+ <= lastNonWSChar )
+ {
+ totalAdvance += runs[ runs.length - 1 ].getGlyphLogicalBounds( j ).
+ getBounds2D().getWidth();
+ j ++;
+ }
+
+ return totalAdvance;
+ }
+
+ public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
+ TextHitInfo secondEndpoint)
+ {
+ return getVisualHighlightShape( firstEndpoint, secondEndpoint,
+ getBounds() );
+ }
+
+ public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
+ TextHitInfo secondEndpoint,
+ Rectangle2D bounds)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public TextHitInfo getVisualOtherHit (TextHitInfo hit)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ /**
+ * This is a protected method of a <code>final</code> class, meaning
+ * it exists only to taunt you.
+ */
+ protected void handleJustify (float justificationWidth)
+ {
+ // We assume that the text has non-trailing whitespace.
+ // First get the change in width to insert into the whitespaces.
+ double deltaW = justificationWidth - getVisibleAdvance();
+ int nglyphs = 0; // # of whitespace chars
+
+ // determine last non-whitespace char.
+ int lastNWS = string.length() - 1;
+ while( Character.isWhitespace( string.charAt( lastNWS ) ) ) lastNWS--;
+
+ // locations of the glyphs.
+ int[] wsglyphs = new int[string.length() * 10];
+ for(int run = 0; run < runs.length; run++ )
+ for(int i = 0; i < runs[run].getNumGlyphs(); i++ )
+ {
+ int cindex = runIndices[run][0] + runs[run].getGlyphCharIndex( i );
+ if( Character.isWhitespace( string.charAt( cindex ) ) )
+ // && cindex < lastNWS )
+ {
+ wsglyphs[ nglyphs * 2 ] = run;
+ wsglyphs[ nglyphs * 2 + 1] = i;
+ nglyphs++;
+ }
+ }
+
+ deltaW = deltaW / nglyphs; // Change in width per whitespace glyph
+ double w = 0;
+ int cws = 0;
+ // Shift all characters
+ for(int run = 0; run < runs.length; run++ )
+ for(int i = 0; i < runs[ run ].getNumGlyphs(); i++ )
+ {
+ if( wsglyphs[ cws * 2 ] == run && wsglyphs[ cws * 2 + 1 ] == i )
+ {
+ cws++; // update 'current whitespace'
+ w += deltaW; // increment the shift
+ }
+ Point2D p = runs[ run ].getGlyphPosition( i );
+ p.setLocation( p.getX() + w, p.getY() );
+ runs[ run ].setGlyphPosition( i, p );
+ }
+ }
+
+ public TextHitInfo hitTestChar (float x, float y)
+ {
+ return hitTestChar(x, y, getBounds());
+ }
+
+ public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public boolean isLeftToRight ()
+ {
+ return leftToRight;
+ }
+
+ public boolean isVertical ()
+ {
+ return false; // FIXME: How do you create a vertical layout?
+ }
+
+ public int hashCode ()
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+
+ public String toString ()
+ {
+ return "TextLayout [string:"+string+", Font:"+font+" Rendercontext:"+
+ frc+"]";
+ }
+
+ /**
+ * Inner class describing a caret policy
+ */
+ public static class CaretPolicy
+ {
+ public CaretPolicy()
+ {
+ }
+
+ public TextHitInfo getStrongCaret(TextHitInfo hit1,
+ TextHitInfo hit2,
+ TextLayout layout)
+ throws NotImplementedException
+ {
+ throw new Error ("not implemented");
+ }
+ }
+}
+
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextMeasurer.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextMeasurer.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextMeasurer.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TextMeasurer.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,191 @@
+/* TextMeasurer.java
+ Copyright (C) 2006 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., 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.font;
+
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.awt.Shape;
+
+/**
+ * TextMeasurer is a small utility class for measuring the length of laid-out
+ * text objects.
+ *
+ * @author Sven de Marothy
+ * @since 1.3
+ */
+public final class TextMeasurer implements Cloneable
+{
+ private AttributedCharacterIterator text;
+ private FontRenderContext frc;
+ private TextLayout totalLayout;
+ private int numChars;
+
+ /**
+ * Creates a TextMeasurer from a given text in the form of an
+ * <code>AttributedCharacterIterator</code> and a
+ * <code>FontRenderContext</code>.
+ */
+ public TextMeasurer (AttributedCharacterIterator text, FontRenderContext frc)
+ {
+ this.text = text;
+ this.frc = frc;
+ totalLayout = new TextLayout( text, frc );
+ numChars = totalLayout.getCharacterCount();
+ }
+
+ /**
+ * Clones the TextMeasurer object
+ */
+ protected Object clone ()
+ {
+ return new TextMeasurer( text, frc );
+ }
+
+ /**
+ * Update the text if a character is deleted at the position deletePos
+ * @param newParagraph - the updated paragraph.
+ * @param deletePos - the deletion position
+ */
+ public void deleteChar (AttributedCharacterIterator newParagraph,
+ int deletePos)
+ {
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( deletePos < 0 || deletePos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid deletePos:"+deletePos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
+ }
+
+ /**
+ * Update the text if a character is inserted at the position insertPos
+ * @param newParagraph - the updated paragraph.
+ * @param insertPos - the insertion position
+ */
+ public void insertChar (AttributedCharacterIterator newParagraph,
+ int insertPos)
+ {
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( insertPos < 0 || insertPos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid insertPos:"+insertPos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
+ }
+
+ /***
+ * Returns the total advance between two positions in the paragraph.
+ * Characters from start to limit-1 (inclusive) are included in this count.
+ *
+ * @param start - the starting character index.
+ * @param limit - the limiting index.
+ */
+ public float getAdvanceBetween (int start, int limit)
+ {
+ Shape s = totalLayout.getLogicalHighlightShape( start, limit );
+ return (float)s.getBounds2D().getWidth();
+ }
+
+ /**
+ * Returns a <code>TextLayout</code> object corresponding to the characters
+ * from text to limit.
+ * @param start - the starting character index.
+ * @param limit - the limiting index.
+ */
+ public TextLayout getLayout (int start, int limit)
+ {
+ if( start >= limit )
+ throw new IllegalArgumentException("Start position must be < limit.");
+ return new TextLayout( totalLayout, start, limit );
+ }
+
+ /**
+ * Returns the line-break index from a given starting index and a maximum
+ * advance. The index returned is the first character outside the given
+ * advance (or the limit of the string, if all remaining characters fit.)
+ *
+ * @param start - the starting index.
+ * @param maxAdvance - the maximum advance allowed.
+ * @return the index of the first character beyond maxAdvance, or the
+ * index of the last character + 1.
+ */
+ public int getLineBreakIndex (int start, float maxAdvance)
+ {
+ if( start < 0 )
+ throw new IllegalArgumentException("Start parameter must be > 0.");
+
+ double remainingLength = getAdvanceBetween( start, numChars );
+
+ int guessOffset = (int)( ( (double)maxAdvance / (double)remainingLength)
+ * ( (double)numChars - (double)start ) );
+ guessOffset += start;
+ if( guessOffset > numChars )
+ guessOffset = numChars;
+
+ double guessLength = getAdvanceBetween( start, guessOffset );
+ boolean makeSmaller = ( guessLength > maxAdvance );
+ int inc = makeSmaller ? -1 : 1;
+ boolean keepGoing = true;
+
+ do
+ {
+ guessOffset = guessOffset + inc;
+ if( guessOffset <= start || guessOffset > numChars )
+ {
+ keepGoing = false;
+ }
+ else
+ {
+ guessLength = getAdvanceBetween( start, guessOffset );
+ if( makeSmaller && ( guessLength <= maxAdvance) )
+ keepGoing = false;
+ if( !makeSmaller && ( guessLength >= maxAdvance) )
+ keepGoing = false;
+ }
+ }
+ while( keepGoing );
+
+ // Return first index that doesn't fit.
+ if( !makeSmaller )
+ guessOffset--;
+
+ if( guessOffset > numChars )
+ return numChars;
+
+ return guessOffset;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TransformAttribute.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TransformAttribute.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TransformAttribute.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/TransformAttribute.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,100 @@
+/* TransformAttribute.java --
+ Copyright (C) 2003, 2005 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., 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.font;
+
+import java.awt.geom.AffineTransform;
+import java.io.Serializable;
+
+/**
+ * This class provides a mechanism for using an {@link AffineTransform} as
+ * an <i>immutable</i> attribute (for example, in the
+ * {@link java.text.AttributedString} class). Any transform passed to
+ * this class is copied before being stored, and any transform handed out
+ * by this class is a copy of the stored transform. In this way, it is
+ * not possible to modify the stored transform.
+ *
+ * @author Michael Koch
+ */
+public final class TransformAttribute implements Serializable
+{
+ private static final long serialVersionUID = 3356247357827709530L;
+
+ private AffineTransform affineTransform;
+
+ /**
+ * Creates a new attribute that contains a copy of the given transform.
+ *
+ * @param transform the transform (<code>null</code> not permitted).
+ *
+ * @throws IllegalArgumentException if <code>transform</code> is
+ * <code>null</code>.
+ */
+ public TransformAttribute (AffineTransform transform)
+ {
+ if (transform == null)
+ {
+ throw new IllegalArgumentException("Null 'transform' not permitted.");
+ }
+ this.affineTransform = new AffineTransform (transform);
+ }
+
+ /**
+ * Returns a copy of the transform contained by this attribute.
+ *
+ * @return A copy of the transform.
+ */
+ public AffineTransform getTransform ()
+ {
+ return (AffineTransform) affineTransform.clone();
+ }
+
+ /**
+ * Returns <code>true</code> if the transform contained by this attribute is
+ * an identity transform, and <code>false</code> otherwise.
+ *
+ * @return <code>true</code> if the transform contained by this attribute is
+ * an identity transform, and <code>false</code> otherwise.
+ *
+ * @since 1.4
+ */
+ public boolean isIdentity ()
+ {
+ return (affineTransform == null ? false : affineTransform.isIdentity ());
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/font/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.font package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.font</title></head>
+
+<body>
+<p>Representations of different kind of characters and fonts.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/AffineTransform.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/AffineTransform.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/AffineTransform.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/AffineTransform.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1489 @@
+/* AffineTransform.java -- transform coordinates between two 2-D spaces
+ Copyright (C) 2000, 2001, 2002, 2004 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.geom;
+
+import java.awt.Shape;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * This class represents an affine transformation between two coordinate
+ * spaces in 2 dimensions. Such a transform preserves the "straightness"
+ * and "parallelness" of lines. The transform is built from a sequence of
+ * translations, scales, flips, rotations, and shears.
+ *
+ * <p>The transformation can be represented using matrix math on a 3x3 array.
+ * Given (x,y), the transformation (x',y') can be found by:
+ * <pre>
+ * [ x'] [ m00 m01 m02 ] [ x ] [ m00*x + m01*y + m02 ]
+ * [ y'] = [ m10 m11 m12 ] [ y ] = [ m10*x + m11*y + m12 ]
+ * [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
+ * </pre>
+ * The bottom row of the matrix is constant, so a transform can be uniquely
+ * represented (as in {@link #toString()}) by
+ * "[[m00, m01, m02], [m10, m11, m12]]".
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status partially updated to 1.4, still has some problems
+ */
+public class AffineTransform implements Cloneable, Serializable
+{
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = 1330973210523860834L;
+
+ /**
+ * The transformation is the identity (x' = x, y' = y). All other transforms
+ * have either a combination of the appropriate transform flag bits for
+ * their type, or the type GENERAL_TRANSFORM.
+ *
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #getType()
+ */
+ public static final int TYPE_IDENTITY = 0;
+
+ /**
+ * The transformation includes a translation - shifting in the x or y
+ * direction without changing length or angles.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #getType()
+ */
+ public static final int TYPE_TRANSLATION = 1;
+
+ /**
+ * The transformation includes a uniform scale - length is scaled in both
+ * the x and y directions by the same amount, without affecting angles.
+ * This is mutually exclusive with TYPE_GENERAL_SCALE.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #TYPE_MASK_SCALE
+ * @see #getType()
+ */
+ public static final int TYPE_UNIFORM_SCALE = 2;
+
+ /**
+ * The transformation includes a general scale - length is scaled in either
+ * or both the x and y directions, but by different amounts; without
+ * affecting angles. This is mutually exclusive with TYPE_UNIFORM_SCALE.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #TYPE_MASK_SCALE
+ * @see #getType()
+ */
+ public static final int TYPE_GENERAL_SCALE = 4;
+
+ /**
+ * This constant checks if either variety of scale transform is performed.
+ *
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ */
+ public static final int TYPE_MASK_SCALE = 6;
+
+ /**
+ * The transformation includes a flip about an axis, swapping between
+ * right-handed and left-handed coordinate systems. In a right-handed
+ * system, the positive x-axis rotates counter-clockwise to the positive
+ * y-axis; in a left-handed system it rotates clockwise.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #getType()
+ */
+ public static final int TYPE_FLIP = 64;
+
+ /**
+ * The transformation includes a rotation of a multiple of 90 degrees (PI/2
+ * radians). Angles are rotated, but length is preserved. This is mutually
+ * exclusive with TYPE_GENERAL_ROTATION.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #TYPE_MASK_ROTATION
+ * @see #getType()
+ */
+ public static final int TYPE_QUADRANT_ROTATION = 8;
+
+ /**
+ * The transformation includes a rotation by an arbitrary angle. Angles are
+ * rotated, but length is preserved. This is mutually exclusive with
+ * TYPE_QUADRANT_ROTATION.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ * @see #TYPE_MASK_ROTATION
+ * @see #getType()
+ */
+ public static final int TYPE_GENERAL_ROTATION = 16;
+
+ /**
+ * This constant checks if either variety of rotation is performed.
+ *
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ */
+ public static final int TYPE_MASK_ROTATION = 24;
+
+ /**
+ * The transformation is an arbitrary conversion of coordinates which
+ * could not be decomposed into the other TYPEs.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_FLIP
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #getType()
+ */
+ public static final int TYPE_GENERAL_TRANSFORM = 32;
+
+ /**
+ * The X coordinate scaling element of the transform matrix.
+ *
+ * @serial matrix[0,0]
+ */
+ private double m00;
+
+ /**
+ * The Y coordinate shearing element of the transform matrix.
+ *
+ * @serial matrix[1,0]
+ */
+ private double m10;
+
+ /**
+ * The X coordinate shearing element of the transform matrix.
+ *
+ * @serial matrix[0,1]
+ */
+ private double m01;
+
+ /**
+ * The Y coordinate scaling element of the transform matrix.
+ *
+ * @serial matrix[1,1]
+ */
+ private double m11;
+
+ /**
+ * The X coordinate translation element of the transform matrix.
+ *
+ * @serial matrix[0,2]
+ */
+ private double m02;
+
+ /**
+ * The Y coordinate translation element of the transform matrix.
+ *
+ * @serial matrix[1,2]
+ */
+ private double m12;
+
+ /** The type of this transform. */
+ private transient int type;
+
+ /**
+ * Construct a new identity transform:
+ * <pre>
+ * [ 1 0 0 ]
+ * [ 0 1 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ */
+ public AffineTransform()
+ {
+ m00 = m11 = 1;
+ }
+
+ /**
+ * Create a new transform which copies the given one.
+ *
+ * @param tx the transform to copy
+ * @throws NullPointerException if tx is null
+ */
+ public AffineTransform(AffineTransform tx)
+ {
+ setTransform(tx);
+ }
+
+ /**
+ * Construct a transform with the given matrix entries:
+ * <pre>
+ * [ m00 m01 m02 ]
+ * [ m10 m11 m12 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param m00 the x scaling component
+ * @param m10 the y shearing component
+ * @param m01 the x shearing component
+ * @param m11 the y scaling component
+ * @param m02 the x translation component
+ * @param m12 the y translation component
+ */
+ public AffineTransform(float m00, float m10,
+ float m01, float m11,
+ float m02, float m12)
+ {
+ this.m00 = m00;
+ this.m10 = m10;
+ this.m01 = m01;
+ this.m11 = m11;
+ this.m02 = m02;
+ this.m12 = m12;
+ updateType();
+ }
+
+ /**
+ * Construct a transform from a sequence of float entries. The array must
+ * have at least 4 entries, which has a translation factor of 0; or 6
+ * entries, for specifying all parameters:
+ * <pre>
+ * [ f[0] f[2] (f[4]) ]
+ * [ f[1] f[3] (f[5]) ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param f the matrix to copy from, with at least 4 (6) entries
+ * @throws NullPointerException if f is null
+ * @throws ArrayIndexOutOfBoundsException if f is too small
+ */
+ public AffineTransform(float[] f)
+ {
+ m00 = f[0];
+ m10 = f[1];
+ m01 = f[2];
+ m11 = f[3];
+ if (f.length >= 6)
+ {
+ m02 = f[4];
+ m12 = f[5];
+ }
+ updateType();
+ }
+
+ /**
+ * Construct a transform with the given matrix entries:
+ * <pre>
+ * [ m00 m01 m02 ]
+ * [ m10 m11 m12 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param m00 the x scaling component
+ * @param m10 the y shearing component
+ * @param m01 the x shearing component
+ * @param m11 the y scaling component
+ * @param m02 the x translation component
+ * @param m12 the y translation component
+ */
+ public AffineTransform(double m00, double m10, double m01,
+ double m11, double m02, double m12)
+ {
+ this.m00 = m00;
+ this.m10 = m10;
+ this.m01 = m01;
+ this.m11 = m11;
+ this.m02 = m02;
+ this.m12 = m12;
+ updateType();
+ }
+
+ /**
+ * Construct a transform from a sequence of double entries. The array must
+ * have at least 4 entries, which has a translation factor of 0; or 6
+ * entries, for specifying all parameters:
+ * <pre>
+ * [ d[0] d[2] (d[4]) ]
+ * [ d[1] d[3] (d[5]) ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param d the matrix to copy from, with at least 4 (6) entries
+ * @throws NullPointerException if d is null
+ * @throws ArrayIndexOutOfBoundsException if d is too small
+ */
+ public AffineTransform(double[] d)
+ {
+ m00 = d[0];
+ m10 = d[1];
+ m01 = d[2];
+ m11 = d[3];
+ if (d.length >= 6)
+ {
+ m02 = d[4];
+ m12 = d[5];
+ }
+ updateType();
+ }
+
+ /**
+ * Returns a translation transform:
+ * <pre>
+ * [ 1 0 tx ]
+ * [ 0 1 ty ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param tx the x translation distance
+ * @param ty the y translation distance
+ * @return the translating transform
+ */
+ public static AffineTransform getTranslateInstance(double tx, double ty)
+ {
+ AffineTransform t = new AffineTransform();
+ t.m02 = tx;
+ t.m12 = ty;
+ t.type = (tx == 0 && ty == 0) ? TYPE_UNIFORM_SCALE : TYPE_TRANSLATION;
+ return t;
+ }
+
+ /**
+ * Returns a rotation transform. A positive angle (in radians) rotates
+ * the positive x-axis to the positive y-axis:
+ * <pre>
+ * [ cos(theta) -sin(theta) 0 ]
+ * [ sin(theta) cos(theta) 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param theta the rotation angle
+ * @return the rotating transform
+ */
+ public static AffineTransform getRotateInstance(double theta)
+ {
+ AffineTransform t = new AffineTransform();
+ t.setToRotation(theta);
+ return t;
+ }
+
+ /**
+ * Returns a rotation transform about a point. A positive angle (in radians)
+ * rotates the positive x-axis to the positive y-axis. This is the same
+ * as calling:
+ * <pre>
+ * AffineTransform tx = new AffineTransform();
+ * tx.setToTranslation(x, y);
+ * tx.rotate(theta);
+ * tx.translate(-x, -y);
+ * </pre>
+ *
+ * <p>The resulting matrix is:
+ * <pre>
+ * [ cos(theta) -sin(theta) x-x*cos+y*sin ]
+ * [ sin(theta) cos(theta) y-x*sin-y*cos ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param theta the rotation angle
+ * @param x the x coordinate of the pivot point
+ * @param y the y coordinate of the pivot point
+ * @return the rotating transform
+ */
+ public static AffineTransform getRotateInstance(double theta,
+ double x, double y)
+ {
+ AffineTransform t = new AffineTransform();
+ t.setToTranslation(x, y);
+ t.rotate(theta);
+ t.translate(-x, -y);
+ return t;
+ }
+
+ /**
+ * Returns a scaling transform:
+ * <pre>
+ * [ sx 0 0 ]
+ * [ 0 sy 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param sx the x scaling factor
+ * @param sy the y scaling factor
+ * @return the scaling transform
+ */
+ public static AffineTransform getScaleInstance(double sx, double sy)
+ {
+ AffineTransform t = new AffineTransform();
+ t.setToScale(sx, sy);
+ return t;
+ }
+
+ /**
+ * Returns a shearing transform (points are shifted in the x direction based
+ * on a factor of their y coordinate, and in the y direction as a factor of
+ * their x coordinate):
+ * <pre>
+ * [ 1 shx 0 ]
+ * [ shy 1 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param shx the x shearing factor
+ * @param shy the y shearing factor
+ * @return the shearing transform
+ */
+ public static AffineTransform getShearInstance(double shx, double shy)
+ {
+ AffineTransform t = new AffineTransform();
+ t.setToShear(shx, shy);
+ return t;
+ }
+
+ /**
+ * Returns the type of this transform. The result is always valid, although
+ * it may not be the simplest interpretation (in other words, there are
+ * sequences of transforms which reduce to something simpler, which this
+ * does not always detect). The result is either TYPE_GENERAL_TRANSFORM,
+ * or a bit-wise combination of TYPE_TRANSLATION, the mutually exclusive
+ * TYPE_*_ROTATIONs, and the mutually exclusive TYPE_*_SCALEs.
+ *
+ * @return The type.
+ *
+ * @see #TYPE_IDENTITY
+ * @see #TYPE_TRANSLATION
+ * @see #TYPE_UNIFORM_SCALE
+ * @see #TYPE_GENERAL_SCALE
+ * @see #TYPE_QUADRANT_ROTATION
+ * @see #TYPE_GENERAL_ROTATION
+ * @see #TYPE_GENERAL_TRANSFORM
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ /**
+ * Return the determinant of this transform matrix. If the determinant is
+ * non-zero, the transform is invertible; otherwise operations which require
+ * an inverse throw a NoninvertibleTransformException. A result very near
+ * zero, due to rounding errors, may indicate that inversion results do not
+ * carry enough precision to be meaningful.
+ *
+ * <p>If this is a uniform scale transformation, the determinant also
+ * represents the squared value of the scale. Otherwise, it carries little
+ * additional meaning. The determinant is calculated as:
+ * <pre>
+ * | m00 m01 m02 |
+ * | m10 m11 m12 | = m00 * m11 - m01 * m10
+ * | 0 0 1 |
+ * </pre>
+ *
+ * @return the determinant
+ * @see #createInverse()
+ */
+ public double getDeterminant()
+ {
+ return m00 * m11 - m01 * m10;
+ }
+
+ /**
+ * Return the matrix of values used in this transform. If the matrix has
+ * fewer than 6 entries, only the scale and shear factors are returned;
+ * otherwise the translation factors are copied as well. The resulting
+ * values are:
+ * <pre>
+ * [ d[0] d[2] (d[4]) ]
+ * [ d[1] d[3] (d[5]) ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param d the matrix to store the results into; with 4 (6) entries
+ * @throws NullPointerException if d is null
+ * @throws ArrayIndexOutOfBoundsException if d is too small
+ */
+ public void getMatrix(double[] d)
+ {
+ d[0] = m00;
+ d[1] = m10;
+ d[2] = m01;
+ d[3] = m11;
+ if (d.length >= 6)
+ {
+ d[4] = m02;
+ d[5] = m12;
+ }
+ }
+
+ /**
+ * Returns the X coordinate scaling factor of the matrix.
+ *
+ * @return m00
+ * @see #getMatrix(double[])
+ */
+ public double getScaleX()
+ {
+ return m00;
+ }
+
+ /**
+ * Returns the Y coordinate scaling factor of the matrix.
+ *
+ * @return m11
+ * @see #getMatrix(double[])
+ */
+ public double getScaleY()
+ {
+ return m11;
+ }
+
+ /**
+ * Returns the X coordinate shearing factor of the matrix.
+ *
+ * @return m01
+ * @see #getMatrix(double[])
+ */
+ public double getShearX()
+ {
+ return m01;
+ }
+
+ /**
+ * Returns the Y coordinate shearing factor of the matrix.
+ *
+ * @return m10
+ * @see #getMatrix(double[])
+ */
+ public double getShearY()
+ {
+ return m10;
+ }
+
+ /**
+ * Returns the X coordinate translation factor of the matrix.
+ *
+ * @return m02
+ * @see #getMatrix(double[])
+ */
+ public double getTranslateX()
+ {
+ return m02;
+ }
+
+ /**
+ * Returns the Y coordinate translation factor of the matrix.
+ *
+ * @return m12
+ * @see #getMatrix(double[])
+ */
+ public double getTranslateY()
+ {
+ return m12;
+ }
+
+ /**
+ * Concatenate a translation onto this transform. This is equivalent, but
+ * more efficient than
+ * <code>concatenate(AffineTransform.getTranslateInstance(tx, ty))</code>.
+ *
+ * @param tx the x translation distance
+ * @param ty the y translation distance
+ * @see #getTranslateInstance(double, double)
+ * @see #concatenate(AffineTransform)
+ */
+ public void translate(double tx, double ty)
+ {
+ m02 += tx * m00 + ty * m01;
+ m12 += tx * m10 + ty * m11;
+ updateType();
+ }
+
+ /**
+ * Concatenate a rotation onto this transform. This is equivalent, but
+ * more efficient than
+ * <code>concatenate(AffineTransform.getRotateInstance(theta))</code>.
+ *
+ * @param theta the rotation angle
+ * @see #getRotateInstance(double)
+ * @see #concatenate(AffineTransform)
+ */
+ public void rotate(double theta)
+ {
+ double c = Math.cos(theta);
+ double s = Math.sin(theta);
+ double n00 = m00 * c + m01 * s;
+ double n01 = m00 * -s + m01 * c;
+ double n10 = m10 * c + m11 * s;
+ double n11 = m10 * -s + m11 * c;
+ m00 = n00;
+ m01 = n01;
+ m10 = n10;
+ m11 = n11;
+ updateType();
+ }
+
+ /**
+ * Concatenate a rotation about a point onto this transform. This is
+ * equivalent, but more efficient than
+ * <code>concatenate(AffineTransform.getRotateInstance(theta, x, y))</code>.
+ *
+ * @param theta the rotation angle
+ * @param x the x coordinate of the pivot point
+ * @param y the y coordinate of the pivot point
+ * @see #getRotateInstance(double, double, double)
+ * @see #concatenate(AffineTransform)
+ */
+ public void rotate(double theta, double x, double y)
+ {
+ translate(x, y);
+ rotate(theta);
+ translate(-x, -y);
+ }
+
+ /**
+ * Concatenate a scale onto this transform. This is equivalent, but more
+ * efficient than
+ * <code>concatenate(AffineTransform.getScaleInstance(sx, sy))</code>.
+ *
+ * @param sx the x scaling factor
+ * @param sy the y scaling factor
+ * @see #getScaleInstance(double, double)
+ * @see #concatenate(AffineTransform)
+ */
+ public void scale(double sx, double sy)
+ {
+ m00 *= sx;
+ m01 *= sy;
+ m10 *= sx;
+ m11 *= sy;
+ updateType();
+ }
+
+ /**
+ * Concatenate a shearing onto this transform. This is equivalent, but more
+ * efficient than
+ * <code>concatenate(AffineTransform.getShearInstance(sx, sy))</code>.
+ *
+ * @param shx the x shearing factor
+ * @param shy the y shearing factor
+ * @see #getShearInstance(double, double)
+ * @see #concatenate(AffineTransform)
+ */
+ public void shear(double shx, double shy)
+ {
+ double n00 = m00 + (shy * m01);
+ double n01 = m01 + (shx * m00);
+ double n10 = m10 + (shy * m11);
+ double n11 = m11 + (shx * m10);
+ m00 = n00;
+ m01 = n01;
+ m10 = n10;
+ m11 = n11;
+ updateType();
+ }
+
+ /**
+ * Reset this transform to the identity (no transformation):
+ * <pre>
+ * [ 1 0 0 ]
+ * [ 0 1 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ */
+ public void setToIdentity()
+ {
+ m00 = m11 = 1;
+ m01 = m02 = m10 = m12 = 0;
+ type = TYPE_IDENTITY;
+ }
+
+ /**
+ * Set this transform to a translation:
+ * <pre>
+ * [ 1 0 tx ]
+ * [ 0 1 ty ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param tx the x translation distance
+ * @param ty the y translation distance
+ */
+ public void setToTranslation(double tx, double ty)
+ {
+ m00 = m11 = 1;
+ m01 = m10 = 0;
+ m02 = tx;
+ m12 = ty;
+ type = (tx == 0 && ty == 0) ? TYPE_UNIFORM_SCALE : TYPE_TRANSLATION;
+ }
+
+ /**
+ * Set this transform to a rotation. A positive angle (in radians) rotates
+ * the positive x-axis to the positive y-axis:
+ * <pre>
+ * [ cos(theta) -sin(theta) 0 ]
+ * [ sin(theta) cos(theta) 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param theta the rotation angle
+ */
+ public void setToRotation(double theta)
+ {
+ double c = Math.cos(theta);
+ double s = Math.sin(theta);
+ m00 = c;
+ m01 = -s;
+ m02 = 0;
+ m10 = s;
+ m11 = c;
+ m12 = 0;
+ type = (c == 1 ? TYPE_IDENTITY
+ : c == 0 || c == -1 ? TYPE_QUADRANT_ROTATION
+ : TYPE_GENERAL_ROTATION);
+ }
+
+ /**
+ * Set this transform to a rotation about a point. A positive angle (in
+ * radians) rotates the positive x-axis to the positive y-axis. This is the
+ * same as calling:
+ * <pre>
+ * tx.setToTranslation(x, y);
+ * tx.rotate(theta);
+ * tx.translate(-x, -y);
+ * </pre>
+ *
+ * <p>The resulting matrix is:
+ * <pre>
+ * [ cos(theta) -sin(theta) x-x*cos+y*sin ]
+ * [ sin(theta) cos(theta) y-x*sin-y*cos ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param theta the rotation angle
+ * @param x the x coordinate of the pivot point
+ * @param y the y coordinate of the pivot point
+ */
+ public void setToRotation(double theta, double x, double y)
+ {
+ double c = Math.cos(theta);
+ double s = Math.sin(theta);
+ m00 = c;
+ m01 = -s;
+ m02 = x - x * c + y * s;
+ m10 = s;
+ m11 = c;
+ m12 = y - x * s - y * c;
+ updateType();
+ }
+
+ /**
+ * Set this transform to a scale:
+ * <pre>
+ * [ sx 0 0 ]
+ * [ 0 sy 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param sx the x scaling factor
+ * @param sy the y scaling factor
+ */
+ public void setToScale(double sx, double sy)
+ {
+ m00 = sx;
+ m01 = m02 = m10 = m12 = 0;
+ m11 = sy;
+ type = (sx != sy ? TYPE_GENERAL_SCALE
+ : sx == 1 ? TYPE_IDENTITY : TYPE_UNIFORM_SCALE);
+ }
+
+ /**
+ * Set this transform to a shear (points are shifted in the x direction based
+ * on a factor of their y coordinate, and in the y direction as a factor of
+ * their x coordinate):
+ * <pre>
+ * [ 1 shx 0 ]
+ * [ shy 1 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param shx the x shearing factor
+ * @param shy the y shearing factor
+ */
+ public void setToShear(double shx, double shy)
+ {
+ m00 = m11 = 1;
+ m01 = shx;
+ m10 = shy;
+ m02 = m12 = 0;
+ updateType();
+ }
+
+ /**
+ * Set this transform to a copy of the given one.
+ *
+ * @param tx the transform to copy
+ * @throws NullPointerException if tx is null
+ */
+ public void setTransform(AffineTransform tx)
+ {
+ m00 = tx.m00;
+ m01 = tx.m01;
+ m02 = tx.m02;
+ m10 = tx.m10;
+ m11 = tx.m11;
+ m12 = tx.m12;
+ type = tx.type;
+ }
+
+ /**
+ * Set this transform to the given values:
+ * <pre>
+ * [ m00 m01 m02 ]
+ * [ m10 m11 m12 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @param m00 the x scaling component
+ * @param m10 the y shearing component
+ * @param m01 the x shearing component
+ * @param m11 the y scaling component
+ * @param m02 the x translation component
+ * @param m12 the y translation component
+ */
+ public void setTransform(double m00, double m10, double m01,
+ double m11, double m02, double m12)
+ {
+ this.m00 = m00;
+ this.m10 = m10;
+ this.m01 = m01;
+ this.m11 = m11;
+ this.m02 = m02;
+ this.m12 = m12;
+ updateType();
+ }
+
+ /**
+ * Set this transform to the result of performing the original version of
+ * this followed by tx. This is commonly used when chaining transformations
+ * from one space to another. In matrix form:
+ * <pre>
+ * [ this ] = [ this ] x [ tx ]
+ * </pre>
+ *
+ * @param tx the transform to concatenate
+ * @throws NullPointerException if tx is null
+ * @see #preConcatenate(AffineTransform)
+ */
+ public void concatenate(AffineTransform tx)
+ {
+ double n00 = m00 * tx.m00 + m01 * tx.m10;
+ double n01 = m00 * tx.m01 + m01 * tx.m11;
+ double n02 = m00 * tx.m02 + m01 * tx.m12 + m02;
+ double n10 = m10 * tx.m00 + m11 * tx.m10;
+ double n11 = m10 * tx.m01 + m11 * tx.m11;
+ double n12 = m10 * tx.m02 + m11 * tx.m12 + m12;
+ m00 = n00;
+ m01 = n01;
+ m02 = n02;
+ m10 = n10;
+ m11 = n11;
+ m12 = n12;
+ updateType();
+ }
+
+ /**
+ * Set this transform to the result of performing tx followed by the
+ * original version of this. This is less common than normal concatenation,
+ * but can still be used to chain transformations from one space to another.
+ * In matrix form:
+ * <pre>
+ * [ this ] = [ tx ] x [ this ]
+ * </pre>
+ *
+ * @param tx the transform to concatenate
+ * @throws NullPointerException if tx is null
+ * @see #concatenate(AffineTransform)
+ */
+ public void preConcatenate(AffineTransform tx)
+ {
+ double n00 = tx.m00 * m00 + tx.m01 * m10;
+ double n01 = tx.m00 * m01 + tx.m01 * m11;
+ double n02 = tx.m00 * m02 + tx.m01 * m12 + tx.m02;
+ double n10 = tx.m10 * m00 + tx.m11 * m10;
+ double n11 = tx.m10 * m01 + tx.m11 * m11;
+ double n12 = tx.m10 * m02 + tx.m11 * m12 + tx.m12;
+ m00 = n00;
+ m01 = n01;
+ m02 = n02;
+ m10 = n10;
+ m11 = n11;
+ m12 = n12;
+ updateType();
+ }
+
+ /**
+ * Returns a transform, which if concatenated to this one, will result in
+ * the identity transform. This is useful for undoing transformations, but
+ * is only possible if the original transform has an inverse (ie. does not
+ * map multiple points to the same line or point). A transform exists only
+ * if getDeterminant() has a non-zero value.
+ *
+ * The inverse is calculated as:
+ *
+ * <pre>
+ *
+ * Let A be the matrix for which we want to find the inverse:
+ *
+ * A = [ m00 m01 m02 ]
+ * [ m10 m11 m12 ]
+ * [ 0 0 1 ]
+ *
+ *
+ * 1
+ * inverse (A) = --- x adjoint(A)
+ * det
+ *
+ *
+ *
+ * = 1 [ m11 -m01 m01*m12-m02*m11 ]
+ * --- x [ -m10 m00 -m00*m12+m10*m02 ]
+ * det [ 0 0 m00*m11-m10*m01 ]
+ *
+ *
+ *
+ * = [ m11/det -m01/det m01*m12-m02*m11/det ]
+ * [ -m10/det m00/det -m00*m12+m10*m02/det ]
+ * [ 0 0 1 ]
+ *
+ *
+ * </pre>
+ *
+ *
+ *
+ * @return a new inverse transform
+ * @throws NoninvertibleTransformException if inversion is not possible
+ * @see #getDeterminant()
+ */
+ public AffineTransform createInverse()
+ throws NoninvertibleTransformException
+ {
+ double det = getDeterminant();
+ if (det == 0)
+ throw new NoninvertibleTransformException("can't invert transform");
+
+ double im00 = m11 / det;
+ double im10 = -m10 / det;
+ double im01 = -m01 / det;
+ double im11 = m00 / det;
+ double im02 = (m01 * m12 - m02 * m11) / det;
+ double im12 = (-m00 * m12 + m10 * m02) / det;
+
+ return new AffineTransform (im00, im10, im01, im11, im02, im12);
+ }
+
+ /**
+ * Perform this transformation on the given source point, and store the
+ * result in the destination (creating it if necessary). It is safe for
+ * src and dst to be the same.
+ *
+ * @param src the source point
+ * @param dst the destination, or null
+ * @return the transformation of src, in dst if it was non-null
+ * @throws NullPointerException if src is null
+ */
+ public Point2D transform(Point2D src, Point2D dst)
+ {
+ if (dst == null)
+ dst = new Point2D.Double();
+ double x = src.getX();
+ double y = src.getY();
+ double nx = m00 * x + m01 * y + m02;
+ double ny = m10 * x + m11 * y + m12;
+ dst.setLocation(nx, ny);
+ return dst;
+ }
+
+ /**
+ * Perform this transformation on an array of points, storing the results
+ * in another (possibly same) array. This will not create a destination
+ * array, but will create points for the null entries of the destination.
+ * The transformation is done sequentially. While having a single source
+ * and destination point be the same is safe, you should be aware that
+ * duplicate references to the same point in the source, and having the
+ * source overlap the destination, may result in your source points changing
+ * from a previous transform before it is their turn to be evaluated.
+ *
+ * @param src the array of source points
+ * @param srcOff the starting offset into src
+ * @param dst the array of destination points (may have null entries)
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null, or src has null
+ * entries
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ * @throws ArrayStoreException if new points are incompatible with dst
+ */
+ public void transform(Point2D[] src, int srcOff,
+ Point2D[] dst, int dstOff, int num)
+ {
+ while (--num >= 0)
+ dst[dstOff] = transform(src[srcOff++], dst[dstOff++]);
+ }
+
+ /**
+ * Perform this transformation on an array of points, in (x,y) pairs,
+ * storing the results in another (possibly same) array. This will not
+ * create a destination array. All sources are copied before the
+ * transformation, so that no result will overwrite a point that has not yet
+ * been evaluated.
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ */
+ public void transform(float[] srcPts, int srcOff,
+ float[] dstPts, int dstOff, int num)
+ {
+ if (srcPts == dstPts && dstOff > srcOff
+ && num > 1 && srcOff + 2 * num > dstOff)
+ {
+ float[] f = new float[2 * num];
+ System.arraycopy(srcPts, srcOff, f, 0, 2 * num);
+ srcPts = f;
+ }
+ while (--num >= 0)
+ {
+ float x = srcPts[srcOff++];
+ float y = srcPts[srcOff++];
+ dstPts[dstOff++] = (float) (m00 * x + m01 * y + m02);
+ dstPts[dstOff++] = (float) (m10 * x + m11 * y + m12);
+ }
+ }
+
+ /**
+ * Perform this transformation on an array of points, in (x,y) pairs,
+ * storing the results in another (possibly same) array. This will not
+ * create a destination array. All sources are copied before the
+ * transformation, so that no result will overwrite a point that has not yet
+ * been evaluated.
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ */
+ public void transform(double[] srcPts, int srcOff,
+ double[] dstPts, int dstOff, int num)
+ {
+ if (srcPts == dstPts && dstOff > srcOff
+ && num > 1 && srcOff + 2 * num > dstOff)
+ {
+ double[] d = new double[2 * num];
+ System.arraycopy(srcPts, srcOff, d, 0, 2 * num);
+ srcPts = d;
+ }
+ while (--num >= 0)
+ {
+ double x = srcPts[srcOff++];
+ double y = srcPts[srcOff++];
+ dstPts[dstOff++] = m00 * x + m01 * y + m02;
+ dstPts[dstOff++] = m10 * x + m11 * y + m12;
+ }
+ }
+
+ /**
+ * Perform this transformation on an array of points, in (x,y) pairs,
+ * storing the results in another array. This will not create a destination
+ * array.
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ */
+ public void transform(float[] srcPts, int srcOff,
+ double[] dstPts, int dstOff, int num)
+ {
+ while (--num >= 0)
+ {
+ float x = srcPts[srcOff++];
+ float y = srcPts[srcOff++];
+ dstPts[dstOff++] = m00 * x + m01 * y + m02;
+ dstPts[dstOff++] = m10 * x + m11 * y + m12;
+ }
+ }
+
+ /**
+ * Perform this transformation on an array of points, in (x,y) pairs,
+ * storing the results in another array. This will not create a destination
+ * array.
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ */
+ public void transform(double[] srcPts, int srcOff,
+ float[] dstPts, int dstOff, int num)
+ {
+ while (--num >= 0)
+ {
+ double x = srcPts[srcOff++];
+ double y = srcPts[srcOff++];
+ dstPts[dstOff++] = (float) (m00 * x + m01 * y + m02);
+ dstPts[dstOff++] = (float) (m10 * x + m11 * y + m12);
+ }
+ }
+
+ /**
+ * Perform the inverse of this transformation on the given source point,
+ * and store the result in the destination (creating it if necessary). It
+ * is safe for src and dst to be the same.
+ *
+ * @param src the source point
+ * @param dst the destination, or null
+ * @return the inverse transformation of src, in dst if it was non-null
+ * @throws NullPointerException if src is null
+ * @throws NoninvertibleTransformException if the inverse does not exist
+ * @see #getDeterminant()
+ */
+ public Point2D inverseTransform(Point2D src, Point2D dst)
+ throws NoninvertibleTransformException
+ {
+ return createInverse().transform(src, dst);
+ }
+
+ /**
+ * Perform the inverse of this transformation on an array of points, in
+ * (x,y) pairs, storing the results in another (possibly same) array. This
+ * will not create a destination array. All sources are copied before the
+ * transformation, so that no result will overwrite a point that has not yet
+ * been evaluated.
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ * @throws NoninvertibleTransformException if the inverse does not exist
+ * @see #getDeterminant()
+ */
+ public void inverseTransform(double[] srcPts, int srcOff,
+ double[] dstPts, int dstOff, int num)
+ throws NoninvertibleTransformException
+ {
+ createInverse().transform(srcPts, srcOff, dstPts, dstOff, num);
+ }
+
+ /**
+ * Perform this transformation, less any translation, on the given source
+ * point, and store the result in the destination (creating it if
+ * necessary). It is safe for src and dst to be the same. The reduced
+ * transform is equivalent to:
+ * <pre>
+ * [ x' ] = [ m00 m01 ] [ x ] = [ m00 * x + m01 * y ]
+ * [ y' ] [ m10 m11 ] [ y ] = [ m10 * x + m11 * y ]
+ * </pre>
+ *
+ * @param src the source point
+ * @param dst the destination, or null
+ * @return the delta transformation of src, in dst if it was non-null
+ * @throws NullPointerException if src is null
+ */
+ public Point2D deltaTransform(Point2D src, Point2D dst)
+ {
+ if (dst == null)
+ dst = new Point2D.Double();
+ double x = src.getX();
+ double y = src.getY();
+ double nx = m00 * x + m01 * y;
+ double ny = m10 * x + m11 * y;
+ dst.setLocation(nx, ny);
+ return dst;
+ }
+
+ /**
+ * Perform this transformation, less any translation, on an array of points,
+ * in (x,y) pairs, storing the results in another (possibly same) array.
+ * This will not create a destination array. All sources are copied before
+ * the transformation, so that no result will overwrite a point that has
+ * not yet been evaluated. The reduced transform is equivalent to:
+ * <pre>
+ * [ x' ] = [ m00 m01 ] [ x ] = [ m00 * x + m01 * y ]
+ * [ y' ] [ m10 m11 ] [ y ] = [ m10 * x + m11 * y ]
+ * </pre>
+ *
+ * @param srcPts the array of source points
+ * @param srcOff the starting offset into src
+ * @param dstPts the array of destination points
+ * @param dstOff the starting offset into dst
+ * @param num the number of points to transform
+ * @throws NullPointerException if src or dst is null
+ * @throws ArrayIndexOutOfBoundsException if array bounds are exceeded
+ */
+ public void deltaTransform(double[] srcPts, int srcOff,
+ double[] dstPts, int dstOff,
+ int num)
+ {
+ if (srcPts == dstPts && dstOff > srcOff
+ && num > 1 && srcOff + 2 * num > dstOff)
+ {
+ double[] d = new double[2 * num];
+ System.arraycopy(srcPts, srcOff, d, 0, 2 * num);
+ srcPts = d;
+ }
+ while (--num >= 0)
+ {
+ double x = srcPts[srcOff++];
+ double y = srcPts[srcOff++];
+ dstPts[dstOff++] = m00 * x + m01 * y;
+ dstPts[dstOff++] = m10 * x + m11 * y;
+ }
+ }
+
+ /**
+ * Return a new Shape, based on the given one, where the path of the shape
+ * has been transformed by this transform. Notice that this uses GeneralPath,
+ * which only stores points in float precision.
+ *
+ * @param src the shape source to transform
+ * @return the shape, transformed by this, <code>null</code> if src is
+ * <code>null</code>.
+ * @see GeneralPath#transform(AffineTransform)
+ */
+ public Shape createTransformedShape(Shape src)
+ {
+ if(src == null)
+ return null;
+ GeneralPath p = new GeneralPath(src);
+ p.transform(this);
+ return p;
+ }
+
+ /**
+ * Returns a string representation of the transform, in the format:
+ * <code>"AffineTransform[[" + m00 + ", " + m01 + ", " + m02 + "], ["
+ * + m10 + ", " + m11 + ", " + m12 + "]]"</code>.
+ *
+ * @return the string representation
+ */
+ public String toString()
+ {
+ return "AffineTransform[[" + m00 + ", " + m01 + ", " + m02 + "], ["
+ + m10 + ", " + m11 + ", " + m12 + "]]";
+ }
+
+ /**
+ * Tests if this transformation is the identity:
+ * <pre>
+ * [ 1 0 0 ]
+ * [ 0 1 0 ]
+ * [ 0 0 1 ]
+ * </pre>
+ *
+ * @return true if this is the identity transform
+ */
+ public boolean isIdentity()
+ {
+ // Rather than rely on type, check explicitly.
+ return (m00 == 1 && m01 == 0 && m02 == 0
+ && m10 == 0 && m11 == 1 && m12 == 0);
+ }
+
+ /**
+ * Create a new transform of the same run-time type, with the same
+ * transforming properties as this one.
+ *
+ * @return the clone
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * Return the hashcode for this transformation. The formula is not
+ * documented, but appears to be the same as:
+ * <pre>
+ * long l = Double.doubleToLongBits(getScaleX());
+ * l = l * 31 + Double.doubleToLongBits(getShearY());
+ * l = l * 31 + Double.doubleToLongBits(getShearX());
+ * l = l * 31 + Double.doubleToLongBits(getScaleY());
+ * l = l * 31 + Double.doubleToLongBits(getTranslateX());
+ * l = l * 31 + Double.doubleToLongBits(getTranslateY());
+ * return (int) ((l >> 32) ^ l);
+ * </pre>
+ *
+ * @return the hashcode
+ */
+ public int hashCode()
+ {
+ long l = Double.doubleToLongBits(m00);
+ l = l * 31 + Double.doubleToLongBits(m10);
+ l = l * 31 + Double.doubleToLongBits(m01);
+ l = l * 31 + Double.doubleToLongBits(m11);
+ l = l * 31 + Double.doubleToLongBits(m02);
+ l = l * 31 + Double.doubleToLongBits(m12);
+ return (int) ((l >> 32) ^ l);
+ }
+
+ /**
+ * Compares two transforms for equality. This returns true if they have the
+ * same matrix values.
+ *
+ * @param obj the transform to compare
+ * @return true if it is equal
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof AffineTransform))
+ return false;
+ AffineTransform t = (AffineTransform) obj;
+ return (m00 == t.m00 && m01 == t.m01 && m02 == t.m02
+ && m10 == t.m10 && m11 == t.m11 && m12 == t.m12);
+ }
+
+ /**
+ * Helper to decode the type from the matrix. This is not guaranteed
+ * to find the optimal type, but at least it will be valid.
+ */
+ private void updateType()
+ {
+ double det = getDeterminant();
+ if (det == 0)
+ {
+ type = TYPE_GENERAL_TRANSFORM;
+ return;
+ }
+ // Scale (includes rotation by PI) or translation.
+ if (m01 == 0 && m10 == 0)
+ {
+ if (m00 == m11)
+ type = m00 == 1 ? TYPE_IDENTITY : TYPE_UNIFORM_SCALE;
+ else
+ type = TYPE_GENERAL_SCALE;
+ if (m02 != 0 || m12 != 0)
+ type |= TYPE_TRANSLATION;
+ }
+ // Rotation.
+ else if (m00 == m11 && m01 == -m10)
+ {
+ type = m00 == 0 ? TYPE_QUADRANT_ROTATION : TYPE_GENERAL_ROTATION;
+ if (det != 1)
+ type |= TYPE_UNIFORM_SCALE;
+ if (m02 != 0 || m12 != 0)
+ type |= TYPE_TRANSLATION;
+ }
+ else
+ type = TYPE_GENERAL_TRANSFORM;
+ }
+
+ /**
+ * Reads a transform from an object stream.
+ *
+ * @param s the stream to read from
+ * @throws ClassNotFoundException if there is a problem deserializing
+ * @throws IOException if there is a problem deserializing
+ */
+ private void readObject(ObjectInputStream s)
+ throws ClassNotFoundException, IOException
+ {
+ s.defaultReadObject();
+ updateType();
+ }
+} // class AffineTransform
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Arc2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Arc2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Arc2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Arc2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1399 @@
+/* Arc2D.java -- represents an arc in 2-D space
+ Copyright (C) 2002, 2003, 2004 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.geom;
+
+import java.util.NoSuchElementException;
+
+
+/**
+ * This class represents all arcs (segments of an ellipse in 2-D space). The
+ * arcs are defined by starting angle and extent (arc length) in degrees, as
+ * opposed to radians (like the rest of Java), and can be open, chorded, or
+ * wedge shaped. The angles are skewed according to the ellipse, so that 45
+ * degrees always points to the upper right corner (positive x, negative y)
+ * of the bounding rectangle. A positive extent draws a counterclockwise arc,
+ * and while the angle can be any value, the path iterator only traverses the
+ * first 360 degrees. Storage is up to the subclasses.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Sven de Marothy (sven at physto.se)
+ * @since 1.2
+ */
+public abstract class Arc2D extends RectangularShape
+{
+ /**
+ * An open arc, with no segment connecting the endpoints. This type of
+ * arc still contains the same points as a chorded version.
+ */
+ public static final int OPEN = 0;
+
+ /**
+ * A closed arc with a single segment connecting the endpoints (a chord).
+ */
+ public static final int CHORD = 1;
+
+ /**
+ * A closed arc with two segments, one from each endpoint, meeting at the
+ * center of the ellipse.
+ */
+ public static final int PIE = 2;
+
+ /** The closure type of this arc. This is package-private to avoid an
+ * accessor method. */
+ int type;
+
+ /**
+ * Create a new arc, with the specified closure type.
+ *
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
+ * @throws IllegalArgumentException if type is invalid
+ */
+ protected Arc2D(int type)
+ {
+ if (type < OPEN || type > PIE)
+ throw new IllegalArgumentException();
+ this.type = type;
+ }
+
+ /**
+ * Get the starting angle of the arc in degrees.
+ *
+ * @return the starting angle
+ * @see #setAngleStart(double)
+ */
+ public abstract double getAngleStart();
+
+ /**
+ * Get the extent angle of the arc in degrees.
+ *
+ * @return the extent angle
+ * @see #setAngleExtent(double)
+ */
+ public abstract double getAngleExtent();
+
+ /**
+ * Return the closure type of the arc.
+ *
+ * @return the closure type
+ * @see #OPEN
+ * @see #CHORD
+ * @see #PIE
+ * @see #setArcType(int)
+ */
+ public int getArcType()
+ {
+ return type;
+ }
+
+ /**
+ * Returns the starting point of the arc.
+ *
+ * @return the start point
+ */
+ public Point2D getStartPoint()
+ {
+ double angle = Math.toRadians(getAngleStart());
+ double rx = getWidth() / 2;
+ double ry = getHeight() / 2;
+ double x = getX() + rx + rx * Math.cos(angle);
+ double y = getY() + ry - ry * Math.sin(angle);
+ return new Point2D.Double(x, y);
+ }
+
+ /**
+ * Returns the ending point of the arc.
+ *
+ * @return the end point
+ */
+ public Point2D getEndPoint()
+ {
+ double angle = Math.toRadians(getAngleStart() + getAngleExtent());
+ double rx = getWidth() / 2;
+ double ry = getHeight() / 2;
+ double x = getX() + rx + rx * Math.cos(angle);
+ double y = getY() + ry - ry * Math.sin(angle);
+ return new Point2D.Double(x, y);
+ }
+
+ /**
+ * Set the parameters of the arc. The angles are in degrees, and a positive
+ * extent sweeps counterclockwise (from the positive x-axis to the negative
+ * y-axis).
+ *
+ * @param x the new x coordinate of the upper left of the bounding box
+ * @param y the new y coordinate of the upper left of the bounding box
+ * @param w the new width of the bounding box
+ * @param h the new height of the bounding box
+ * @param start the start angle, in degrees
+ * @param extent the arc extent, in degrees
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public abstract void setArc(double x, double y, double w, double h,
+ double start, double extent, int type);
+
+ /**
+ * Set the parameters of the arc. The angles are in degrees, and a positive
+ * extent sweeps counterclockwise (from the positive x-axis to the negative
+ * y-axis).
+ *
+ * @param p the upper left point of the bounding box
+ * @param d the dimensions of the bounding box
+ * @param start the start angle, in degrees
+ * @param extent the arc extent, in degrees
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ * @throws NullPointerException if p or d is null
+ */
+ public void setArc(Point2D p, Dimension2D d, double start, double extent,
+ int type)
+ {
+ setArc(p.getX(), p.getY(), d.getWidth(), d.getHeight(), start, extent, type);
+ }
+
+ /**
+ * Set the parameters of the arc. The angles are in degrees, and a positive
+ * extent sweeps counterclockwise (from the positive x-axis to the negative
+ * y-axis).
+ *
+ * @param r the new bounding box
+ * @param start the start angle, in degrees
+ * @param extent the arc extent, in degrees
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ * @throws NullPointerException if r is null
+ */
+ public void setArc(Rectangle2D r, double start, double extent, int type)
+ {
+ setArc(r.getX(), r.getY(), r.getWidth(), r.getHeight(), start, extent, type);
+ }
+
+ /**
+ * Set the parameters of the arc from the given one.
+ *
+ * @param a the arc to copy
+ * @throws NullPointerException if a is null
+ */
+ public void setArc(Arc2D a)
+ {
+ setArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), a.getAngleStart(),
+ a.getAngleExtent(), a.getArcType());
+ }
+
+ /**
+ * Set the parameters of the arc. The angles are in degrees, and a positive
+ * extent sweeps counterclockwise (from the positive x-axis to the negative
+ * y-axis). This controls the center point and radius, so the arc will be
+ * circular.
+ *
+ * @param x the x coordinate of the center of the circle
+ * @param y the y coordinate of the center of the circle
+ * @param r the radius of the circle
+ * @param start the start angle, in degrees
+ * @param extent the arc extent, in degrees
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public void setArcByCenter(double x, double y, double r, double start,
+ double extent, int type)
+ {
+ setArc(x - r, y - r, r + r, r + r, start, extent, type);
+ }
+
+ /**
+ * Sets the parameters of the arc by finding the tangents of two lines, and
+ * using the specified radius. The arc will be circular, will begin on the
+ * tangent point of the line extending from p1 to p2, and will end on the
+ * tangent point of the line extending from p2 to p3.
+ *
+ * XXX What happens if the points are colinear, or the radius negative?
+ *
+ * @param p1 the first point
+ * @param p2 the tangent line intersection point
+ * @param p3 the third point
+ * @param r the radius of the arc
+ * @throws NullPointerException if any point is null
+ */
+ public void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double r)
+ {
+ if ((p2.getX() - p1.getX()) * (p3.getY() - p1.getY())
+ - (p3.getX() - p1.getX()) * (p2.getY() - p1.getY()) > 0)
+ {
+ Point2D p = p3;
+ p3 = p1;
+ p1 = p;
+ }
+
+ // normalized tangent vectors
+ double dx1 = (p1.getX() - p2.getX()) / p1.distance(p2);
+ double dy1 = (p1.getY() - p2.getY()) / p1.distance(p2);
+ double dx2 = (p2.getX() - p3.getX()) / p3.distance(p2);
+ double dy2 = (p2.getY() - p3.getY()) / p3.distance(p2);
+ double theta1 = Math.atan2(dx1, dy1);
+ double theta2 = Math.atan2(dx2, dy2);
+
+ double dx = r * Math.cos(theta2) - r * Math.cos(theta1);
+ double dy = -r * Math.sin(theta2) + r * Math.sin(theta1);
+
+ if (theta1 < 0)
+ theta1 += 2 * Math.PI;
+ if (theta2 < 0)
+ theta2 += 2 * Math.PI;
+ if (theta2 < theta1)
+ theta2 += 2 * Math.PI;
+
+ // Vectors of the lines, not normalized, note we change
+ // the direction of line 2.
+ dx1 = p1.getX() - p2.getX();
+ dy1 = p1.getY() - p2.getY();
+ dx2 = p3.getX() - p2.getX();
+ dy2 = p3.getY() - p2.getY();
+
+ // Calculate the tangent point to the second line
+ double t2 = -(dx1 * dy - dy1 * dx) / (dx2 * dy1 - dx1 * dy2);
+ double x2 = t2 * (p3.getX() - p2.getX()) + p2.getX();
+ double y2 = t2 * (p3.getY() - p2.getY()) + p2.getY();
+
+ // calculate the center point
+ double x = x2 - r * Math.cos(theta2);
+ double y = y2 + r * Math.sin(theta2);
+
+ setArc(x - r, y - r, 2 * r, 2 * r, Math.toDegrees(theta1),
+ Math.toDegrees(theta2 - theta1), getArcType());
+ }
+
+ /**
+ * Set the start, in degrees.
+ *
+ * @param start the new start angle
+ * @see #getAngleStart()
+ */
+ public abstract void setAngleStart(double start);
+
+ /**
+ * Set the extent, in degrees.
+ *
+ * @param extent the new extent angle
+ * @see #getAngleExtent()
+ */
+ public abstract void setAngleExtent(double extent);
+
+ /**
+ * Sets the starting angle to the angle of the given point relative to
+ * the center of the arc. The extent remains constant; in other words,
+ * this rotates the arc.
+ *
+ * @param p the new start point
+ * @throws NullPointerException if p is null
+ * @see #getStartPoint()
+ * @see #getAngleStart()
+ */
+ public void setAngleStart(Point2D p)
+ {
+ // Normalize.
+ double x = p.getX() - (getX() + getWidth() / 2);
+ double y = p.getY() - (getY() + getHeight() / 2);
+ setAngleStart(Math.toDegrees(Math.atan2(-y, x)));
+ }
+
+ /**
+ * Sets the starting and extent angles to those of the given points
+ * relative to the center of the arc. The arc will be non-empty, and will
+ * extend counterclockwise.
+ *
+ * @param x1 the first x coordinate
+ * @param y1 the first y coordinate
+ * @param x2 the second x coordinate
+ * @param y2 the second y coordinate
+ * @see #setAngleStart(Point2D)
+ */
+ public void setAngles(double x1, double y1, double x2, double y2)
+ {
+ // Normalize the points.
+ double mx = getX();
+ double my = getY();
+ double mw = getWidth();
+ double mh = getHeight();
+ x1 = x1 - (mx + mw / 2);
+ y1 = y1 - (my + mh / 2);
+ x2 = x2 - (mx + mw / 2);
+ y2 = y2 - (my + mh / 2);
+ double start = Math.toDegrees(Math.atan2(-y1, x1));
+ double extent = Math.toDegrees(Math.atan2(-y2, x2)) - start;
+ if (extent < 0)
+ extent += 360;
+ setAngleStart(start);
+ setAngleExtent(extent);
+ }
+
+ /**
+ * Sets the starting and extent angles to those of the given points
+ * relative to the center of the arc. The arc will be non-empty, and will
+ * extend counterclockwise.
+ *
+ * @param p1 the first point
+ * @param p2 the second point
+ * @throws NullPointerException if either point is null
+ * @see #setAngleStart(Point2D)
+ */
+ public void setAngles(Point2D p1, Point2D p2)
+ {
+ setAngles(p1.getX(), p1.getY(), p2.getX(), p2.getY());
+ }
+
+ /**
+ * Set the closure type of this arc.
+ *
+ * @param type one of {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ * @see #getArcType()
+ */
+ public void setArcType(int type)
+ {
+ if (type < OPEN || type > PIE)
+ throw new IllegalArgumentException();
+ this.type = type;
+ }
+
+ /**
+ * Sets the location and bounds of the ellipse of which this arc is a part.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ * @param w the new width
+ * @param h the new height
+ * @see #getFrame()
+ */
+ public void setFrame(double x, double y, double w, double h)
+ {
+ setArc(x, y, w, h, getAngleStart(), getAngleExtent(), type);
+ }
+
+ /**
+ * Gets the bounds of the arc. This is much tighter than
+ * <code>getBounds</code>, as it takes into consideration the start and
+ * end angles, and the center point of a pie wedge, rather than just the
+ * overall ellipse.
+ *
+ * @return the bounds of the arc
+ * @see #getBounds()
+ */
+ public Rectangle2D getBounds2D()
+ {
+ double extent = getAngleExtent();
+ if (Math.abs(extent) >= 360)
+ return makeBounds(getX(), getY(), getWidth(), getHeight());
+
+ // Find the minimal bounding box. This determined by its extrema,
+ // which are the center, the endpoints of the arc, and any local
+ // maximum contained by the arc.
+ double rX = getWidth() / 2;
+ double rY = getHeight() / 2;
+ double centerX = getX() + rX;
+ double centerY = getY() + rY;
+
+ Point2D p1 = getStartPoint();
+ Rectangle2D result = makeBounds(p1.getX(), p1.getY(), 0, 0);
+ result.add(getEndPoint());
+
+ if (type == PIE)
+ result.add(centerX, centerY);
+ if (containsAngle(0))
+ result.add(centerX + rX, centerY);
+ if (containsAngle(90))
+ result.add(centerX, centerY - rY);
+ if (containsAngle(180))
+ result.add(centerX - rX, centerY);
+ if (containsAngle(270))
+ result.add(centerX, centerY + rY);
+
+ return result;
+ }
+
+ /**
+ * Construct a bounding box in a precision appropriate for the subclass.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ * @return the rectangle for use in getBounds2D
+ */
+ protected abstract Rectangle2D makeBounds(double x, double y, double w,
+ double h);
+
+ /**
+ * Tests if the given angle, in degrees, is included in the arc.
+ * All angles are normalized to be between 0 and 360 degrees.
+ *
+ * @param a the angle to test
+ * @return true if it is contained
+ */
+ public boolean containsAngle(double a)
+ {
+ double start = getAngleStart();
+ double extent = getAngleExtent();
+ double end = start + extent;
+
+ if (extent == 0)
+ return false;
+
+ if (extent >= 360 || extent <= -360)
+ return true;
+
+ if (extent < 0)
+ {
+ end = start;
+ start += extent;
+ }
+
+ start %= 360;
+ while (start < 0)
+ start += 360;
+
+ end %= 360;
+ while (end < start)
+ end += 360;
+
+ a %= 360;
+ while (a < start)
+ a += 360;
+
+ return a >= start && a < end; // starting angle included, ending angle not
+ }
+
+ /**
+ * Determines if the arc contains the given point. If the bounding box
+ * is empty, then this will return false.
+ *
+ * The area considered 'inside' an arc of type OPEN is the same as the
+ * area inside an equivalent filled CHORD-type arc. The area considered
+ * 'inside' a CHORD-type arc is the same as the filled area.
+ *
+ * @param x the x coordinate to test
+ * @param y the y coordinate to test
+ * @return true if the point is inside the arc
+ */
+ public boolean contains(double x, double y)
+ {
+ double w = getWidth();
+ double h = getHeight();
+ double extent = getAngleExtent();
+ if (w <= 0 || h <= 0 || extent == 0)
+ return false;
+
+ double mx = getX() + w / 2;
+ double my = getY() + h / 2;
+ double dx = (x - mx) * 2 / w;
+ double dy = (y - my) * 2 / h;
+ if ((dx * dx + dy * dy) >= 1.0)
+ return false;
+
+ double angle = Math.toDegrees(Math.atan2(-dy, dx));
+ if (getArcType() == PIE)
+ return containsAngle(angle);
+
+ double a1 = Math.toRadians(getAngleStart());
+ double a2 = Math.toRadians(getAngleStart() + extent);
+ double x1 = mx + getWidth() * Math.cos(a1) / 2;
+ double y1 = my - getHeight() * Math.sin(a1) / 2;
+ double x2 = mx + getWidth() * Math.cos(a2) / 2;
+ double y2 = my - getHeight() * Math.sin(a2) / 2;
+ double sgn = ((x2 - x1) * (my - y1) - (mx - x1) * (y2 - y1)) * ((x2 - x1) * (y
+ - y1) - (x - x1) * (y2 - y1));
+
+ if (Math.abs(extent) > 180)
+ {
+ if (containsAngle(angle))
+ return true;
+ return sgn > 0;
+ }
+ else
+ {
+ if (! containsAngle(angle))
+ return false;
+ return sgn < 0;
+ }
+ }
+
+ /**
+ * Tests if a given rectangle intersects the area of the arc.
+ *
+ * For a definition of the 'inside' area, see the contains() method.
+ * @see #contains(double, double)
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @return true if the two shapes share common points
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ double extent = getAngleExtent();
+ if (extent == 0)
+ return false;
+
+ if (contains(x, y) || contains(x, y + h) || contains(x + w, y)
+ || contains(x + w, y + h))
+ return true;
+
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
+
+ if (getArcType() != CHORD)
+ {
+ // check intersections against the pie radii
+ if (rect.intersectsLine(mx, my, x1, y1))
+ return true;
+ if (rect.intersectsLine(mx, my, x2, y2))
+ return true;
+ }
+ else// check the chord
+ if (rect.intersectsLine(x1, y1, x2, y2))
+ return true;
+
+ // Check the Arc segment against the four edges
+ double dx;
+
+ // Check the Arc segment against the four edges
+ double dy;
+ dy = y - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dy = (y + h) - my;
+ dx = a * Math.sqrt(1 - ((dy * dy) / (b * b)));
+ if (! java.lang.Double.isNaN(dx))
+ {
+ if (mx + dx >= x && mx + dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (mx - dx >= x && mx - dx <= x + w
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, -dx))))
+ return true;
+ }
+ dx = x - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ dx = (x + w) - mx;
+ dy = b * Math.sqrt(1 - ((dx * dx) / (a * a)));
+ if (! java.lang.Double.isNaN(dy))
+ {
+ if (my + dy >= y && my + dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(-dy, dx))))
+ return true;
+ if (my - dy >= y && my - dy <= y + h
+ && containsAngle(Math.toDegrees(Math.atan2(dy, dx))))
+ return true;
+ }
+
+ // Check whether the arc is contained within the box
+ if (rect.contains(mx, my))
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Tests if a given rectangle is contained in the area of the arc.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @return true if the arc contains the rectangle
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ double extent = getAngleExtent();
+ if (extent == 0)
+ return false;
+
+ if (! (contains(x, y) && contains(x, y + h) && contains(x + w, y)
+ && contains(x + w, y + h)))
+ return false;
+
+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
+
+ double a = getWidth() / 2.0;
+ double b = getHeight() / 2.0;
+
+ double mx = getX() + a;
+ double my = getY() + b;
+ double x1 = mx + a * Math.cos(Math.toRadians(getAngleStart()));
+ double y1 = my - b * Math.sin(Math.toRadians(getAngleStart()));
+ double x2 = mx + a * Math.cos(Math.toRadians(getAngleStart() + extent));
+ double y2 = my - b * Math.sin(Math.toRadians(getAngleStart() + extent));
+ if (getArcType() != CHORD)
+ {
+ // check intersections against the pie radii
+ if (rect.intersectsLine(mx, my, x1, y1))
+ return false;
+
+ if (rect.intersectsLine(mx, my, x2, y2))
+ return false;
+ }
+ else if (rect.intersectsLine(x1, y1, x2, y2))
+ return false;
+ return true;
+ }
+
+ /**
+ * Tests if a given rectangle is contained in the area of the arc.
+ *
+ * @param r the rectangle
+ * @return true if the arc contains the rectangle
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Returns an iterator over this arc, with an optional transformation.
+ * This iterator is threadsafe, so future modifications to the arc do not
+ * affect the iteration.
+ *
+ * @param at the transformation, or null
+ * @return a path iterator
+ */
+ public PathIterator getPathIterator(AffineTransform at)
+ {
+ return new ArcIterator(this, at);
+ }
+
+ /**
+ * This class is used to iterate over an arc. Since ellipses are a subclass
+ * of arcs, this is used by Ellipse2D as well.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ */
+ static final class ArcIterator implements PathIterator
+ {
+ /** The current iteration. */
+ private int current;
+
+ /** The last iteration. */
+ private final int limit;
+
+ /** The optional transformation. */
+ private final AffineTransform xform;
+
+ /** The x coordinate of the bounding box. */
+ private final double x;
+
+ /** The y coordinate of the bounding box. */
+ private final double y;
+
+ /** The width of the bounding box. */
+ private final double w;
+
+ /** The height of the bounding box. */
+ private final double h;
+
+ /** The start angle, in radians (not degrees). */
+ private final double start;
+
+ /** The extent angle, in radians (not degrees). */
+ private final double extent;
+
+ /** The arc closure type. */
+ private final int type;
+
+ /**
+ * Construct a new iterator over an arc.
+ *
+ * @param a the arc
+ * @param xform the transform
+ */
+ public ArcIterator(Arc2D a, AffineTransform xform)
+ {
+ this.xform = xform;
+ x = a.getX();
+ y = a.getY();
+ w = a.getWidth();
+ h = a.getHeight();
+ double start = a.getAngleStart() * (Math.PI / 180);
+ double extent = a.getAngleExtent() * (Math.PI / 180);
+
+ if (extent < 0)
+ {
+ extent = -extent;
+ start = 2 * Math.PI - extent + start;
+ }
+ this.start = start;
+ this.extent = extent;
+
+ type = a.type;
+ if (w < 0 || h < 0)
+ limit = -1;
+ else if (extent == 0)
+ limit = type;
+ else if (extent <= Math.PI / 2.0)
+ limit = type + 1;
+ else if (extent <= Math.PI)
+ limit = type + 2;
+ else if (extent <= 3.0 * (Math.PI / 2.0))
+ limit = type + 3;
+ else
+ limit = type + 4;
+ }
+
+ /**
+ * Construct a new iterator over an ellipse.
+ *
+ * @param e the ellipse
+ * @param xform the transform
+ */
+ public ArcIterator(Ellipse2D e, AffineTransform xform)
+ {
+ this.xform = xform;
+ x = e.getX();
+ y = e.getY();
+ w = e.getWidth();
+ h = e.getHeight();
+ start = 0;
+ extent = 2 * Math.PI;
+ type = CHORD;
+ limit = (w < 0 || h < 0) ? -1 : 5;
+ }
+
+ /**
+ * Return the winding rule.
+ *
+ * @return {@link PathIterator#WIND_NON_ZERO}
+ */
+ public int getWindingRule()
+ {
+ return WIND_NON_ZERO;
+ }
+
+ /**
+ * Test if the iteration is complete.
+ *
+ * @return true if more segments exist
+ */
+ public boolean isDone()
+ {
+ return current > limit;
+ }
+
+ /**
+ * Advance the iterator.
+ */
+ public void next()
+ {
+ current++;
+ }
+
+ /**
+ * Put the current segment into the array, and return the segment type.
+ *
+ * @param coords an array of 6 elements
+ * @return the segment type
+ * @throws NullPointerException if coords is null
+ * @throws ArrayIndexOutOfBoundsException if coords is too small
+ */
+ public int currentSegment(float[] coords)
+ {
+ double[] double_coords = new double[6];
+ int code = currentSegment(double_coords);
+ for (int i = 0; i < 6; ++i)
+ coords[i] = (float) double_coords[i];
+ return code;
+ }
+
+ /**
+ * Put the current segment into the array, and return the segment type.
+ *
+ * @param coords an array of 6 elements
+ * @return the segment type
+ * @throws NullPointerException if coords is null
+ * @throws ArrayIndexOutOfBoundsException if coords is too small
+ */
+ public int currentSegment(double[] coords)
+ {
+ double rx = w / 2;
+ double ry = h / 2;
+ double xmid = x + rx;
+ double ymid = y + ry;
+
+ if (current > limit)
+ throw new NoSuchElementException("arc iterator out of bounds");
+
+ if (current == 0)
+ {
+ coords[0] = xmid + rx * Math.cos(start);
+ coords[1] = ymid - ry * Math.sin(start);
+ if (xform != null)
+ xform.transform(coords, 0, coords, 0, 1);
+ return SEG_MOVETO;
+ }
+
+ if (type != OPEN && current == limit)
+ return SEG_CLOSE;
+
+ if ((current == limit - 1) && (type == PIE))
+ {
+ coords[0] = xmid;
+ coords[1] = ymid;
+ if (xform != null)
+ xform.transform(coords, 0, coords, 0, 1);
+ return SEG_LINETO;
+ }
+
+ // note that this produces a cubic approximation of the arc segment,
+ // not a true ellipsoid. there's no ellipsoid path segment code,
+ // unfortunately. the cubic approximation looks about right, though.
+ double kappa = (Math.sqrt(2.0) - 1.0) * (4.0 / 3.0);
+ double quad = (Math.PI / 2.0);
+
+ double curr_begin = start + (current - 1) * quad;
+ double curr_extent = Math.min((start + extent) - curr_begin, quad);
+ double portion_of_a_quadrant = curr_extent / quad;
+
+ double x0 = xmid + rx * Math.cos(curr_begin);
+ double y0 = ymid - ry * Math.sin(curr_begin);
+
+ double x1 = xmid + rx * Math.cos(curr_begin + curr_extent);
+ double y1 = ymid - ry * Math.sin(curr_begin + curr_extent);
+
+ AffineTransform trans = new AffineTransform();
+ double[] cvec = new double[2];
+ double len = kappa * portion_of_a_quadrant;
+ double angle = curr_begin;
+
+ // in a hypothetical "first quadrant" setting, our first control
+ // vector would be sticking up, from [1,0] to [1,kappa].
+ //
+ // let us recall however that in java2d, y coords are upside down
+ // from what one would consider "normal" first quadrant rules, so we
+ // will *subtract* the y value of this control vector from our first
+ // point.
+ cvec[0] = 0;
+ cvec[1] = len;
+ trans.scale(rx, ry);
+ trans.rotate(angle);
+ trans.transform(cvec, 0, cvec, 0, 1);
+ coords[0] = x0 + cvec[0];
+ coords[1] = y0 - cvec[1];
+
+ // control vector #2 would, ideally, be sticking out and to the
+ // right, in a first quadrant arc segment. again, subtraction of y.
+ cvec[0] = 0;
+ cvec[1] = -len;
+ trans.rotate(curr_extent);
+ trans.transform(cvec, 0, cvec, 0, 1);
+ coords[2] = x1 + cvec[0];
+ coords[3] = y1 - cvec[1];
+
+ // end point
+ coords[4] = x1;
+ coords[5] = y1;
+
+ if (xform != null)
+ xform.transform(coords, 0, coords, 0, 3);
+
+ return SEG_CUBICTO;
+ }
+ } // class ArcIterator
+
+ /**
+ * This class implements an arc in double precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ */
+ public static class Double extends Arc2D
+ {
+ /** The x coordinate of the box bounding the ellipse of this arc. */
+ public double x;
+
+ /** The y coordinate of the box bounding the ellipse of this arc. */
+ public double y;
+
+ /** The width of the box bounding the ellipse of this arc. */
+ public double width;
+
+ /** The height of the box bounding the ellipse of this arc. */
+ public double height;
+
+ /** The start angle of this arc, in degrees. */
+ public double start;
+
+ /** The extent angle of this arc, in degrees. */
+ public double extent;
+
+ /**
+ * Create a new, open arc at (0,0) with 0 extent.
+ */
+ public Double()
+ {
+ super(OPEN);
+ }
+
+ /**
+ * Create a new arc of the given type at (0,0) with 0 extent.
+ *
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public Double(int type)
+ {
+ super(type);
+ }
+
+ /**
+ * Create a new arc with the given dimensions.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public Double(double x, double y, double w, double h, double start,
+ double extent, int type)
+ {
+ super(type);
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ this.start = start;
+ this.extent = extent;
+ }
+
+ /**
+ * Create a new arc with the given dimensions.
+ *
+ * @param r the bounding box
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ * @throws NullPointerException if r is null
+ */
+ public Double(Rectangle2D r, double start, double extent, int type)
+ {
+ super(type);
+ x = r.getX();
+ y = r.getY();
+ width = r.getWidth();
+ height = r.getHeight();
+ this.start = start;
+ this.extent = extent;
+ }
+
+ /**
+ * Return the x coordinate of the bounding box.
+ *
+ * @return the value of x
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the y coordinate of the bounding box.
+ *
+ * @return the value of y
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Return the width of the bounding box.
+ *
+ * @return the value of width
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Return the height of the bounding box.
+ *
+ * @return the value of height
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Return the start angle of the arc, in degrees.
+ *
+ * @return the value of start
+ */
+ public double getAngleStart()
+ {
+ return start;
+ }
+
+ /**
+ * Return the extent of the arc, in degrees.
+ *
+ * @return the value of extent
+ */
+ public double getAngleExtent()
+ {
+ return extent;
+ }
+
+ /**
+ * Tests if the arc contains points.
+ *
+ * @return true if the arc has no interior
+ */
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ /**
+ * Sets the arc to the given dimensions.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public void setArc(double x, double y, double w, double h, double start,
+ double extent, int type)
+ {
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ this.start = start;
+ this.extent = extent;
+ setArcType(type);
+ }
+
+ /**
+ * Sets the start angle of the arc.
+ *
+ * @param start the new start angle
+ */
+ public void setAngleStart(double start)
+ {
+ this.start = start;
+ }
+
+ /**
+ * Sets the extent angle of the arc.
+ *
+ * @param extent the new extent angle
+ */
+ public void setAngleExtent(double extent)
+ {
+ this.extent = extent;
+ }
+
+ /**
+ * Creates a tight bounding box given dimensions that more precise than
+ * the bounding box of the ellipse.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ protected Rectangle2D makeBounds(double x, double y, double w, double h)
+ {
+ return new Rectangle2D.Double(x, y, w, h);
+ }
+ } // class Double
+
+ /**
+ * This class implements an arc in float precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ */
+ public static class Float extends Arc2D
+ {
+ /** The x coordinate of the box bounding the ellipse of this arc. */
+ public float x;
+
+ /** The y coordinate of the box bounding the ellipse of this arc. */
+ public float y;
+
+ /** The width of the box bounding the ellipse of this arc. */
+ public float width;
+
+ /** The height of the box bounding the ellipse of this arc. */
+ public float height;
+
+ /** The start angle of this arc, in degrees. */
+ public float start;
+
+ /** The extent angle of this arc, in degrees. */
+ public float extent;
+
+ /**
+ * Create a new, open arc at (0,0) with 0 extent.
+ */
+ public Float()
+ {
+ super(OPEN);
+ }
+
+ /**
+ * Create a new arc of the given type at (0,0) with 0 extent.
+ *
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public Float(int type)
+ {
+ super(type);
+ }
+
+ /**
+ * Create a new arc with the given dimensions.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public Float(float x, float y, float w, float h, float start,
+ float extent, int type)
+ {
+ super(type);
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ this.start = start;
+ this.extent = extent;
+ }
+
+ /**
+ * Create a new arc with the given dimensions.
+ *
+ * @param r the bounding box
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ * @throws NullPointerException if r is null
+ */
+ public Float(Rectangle2D r, float start, float extent, int type)
+ {
+ super(type);
+ x = (float) r.getX();
+ y = (float) r.getY();
+ width = (float) r.getWidth();
+ height = (float) r.getHeight();
+ this.start = start;
+ this.extent = (float) extent;
+ }
+
+ /**
+ * Return the x coordinate of the bounding box.
+ *
+ * @return the value of x
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the y coordinate of the bounding box.
+ *
+ * @return the value of y
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Return the width of the bounding box.
+ *
+ * @return the value of width
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Return the height of the bounding box.
+ *
+ * @return the value of height
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Return the start angle of the arc, in degrees.
+ *
+ * @return the value of start
+ */
+ public double getAngleStart()
+ {
+ return start;
+ }
+
+ /**
+ * Return the extent of the arc, in degrees.
+ *
+ * @return the value of extent
+ */
+ public double getAngleExtent()
+ {
+ return extent;
+ }
+
+ /**
+ * Tests if the arc contains points.
+ *
+ * @return true if the arc has no interior
+ */
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ /**
+ * Sets the arc to the given dimensions.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ * @param start the start angle, in degrees
+ * @param extent the extent, in degrees
+ * @param type the arc type: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}
+ * @throws IllegalArgumentException if type is invalid
+ */
+ public void setArc(double x, double y, double w, double h, double start,
+ double extent, int type)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ width = (float) w;
+ height = (float) h;
+ this.start = (float) start;
+ this.extent = (float) extent;
+ setArcType(type);
+ }
+
+ /**
+ * Sets the start angle of the arc.
+ *
+ * @param start the new start angle
+ */
+ public void setAngleStart(double start)
+ {
+ this.start = (float) start;
+ }
+
+ /**
+ * Sets the extent angle of the arc.
+ *
+ * @param extent the new extent angle
+ */
+ public void setAngleExtent(double extent)
+ {
+ this.extent = (float) extent;
+ }
+
+ /**
+ * Creates a tight bounding box given dimensions that more precise than
+ * the bounding box of the ellipse.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ protected Rectangle2D makeBounds(double x, double y, double w, double h)
+ {
+ return new Rectangle2D.Float((float) x, (float) y, (float) w, (float) h);
+ }
+ } // class Float
+} // class Arc2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Area.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Area.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Area.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Area.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,3312 @@
+/* Area.java -- represents a shape built by constructive area geometry
+ Copyright (C) 2002, 2004 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.util.Vector;
+
+
+/**
+ * The Area class represents any area for the purpose of
+ * Constructive Area Geometry (CAG) manipulations. CAG manipulations
+ * work as an area-wise form of boolean logic, where the basic operations are:
+ * <P><li>Add (in boolean algebra: A <B>or</B> B)<BR>
+ * <li>Subtract (in boolean algebra: A <B>and</B> (<B>not</B> B) )<BR>
+ * <li>Intersect (in boolean algebra: A <B>and</B> B)<BR>
+ * <li>Exclusive Or <BR>
+ * <img src="doc-files/Area-1.png" width="342" height="302"
+ * alt="Illustration of CAG operations" /><BR>
+ * Above is an illustration of the CAG operations on two ring shapes.<P>
+ *
+ * The contains and intersects() methods are also more accurate than the
+ * specification of #Shape requires.<P>
+ *
+ * Please note that constructing an Area can be slow
+ * (Self-intersection resolving is proportional to the square of
+ * the number of segments).<P>
+ * @see #add(Area)
+ * @see #subtract(Area)
+ * @see #intersect(Area)
+ * @see #exclusiveOr(Area)
+ *
+ * @author Sven de Marothy (sven at physto.se)
+ *
+ * @since 1.2
+ * @status Works, but could be faster and more reliable.
+ */
+public class Area implements Shape, Cloneable
+{
+ /**
+ * General numerical precision
+ */
+ private static final double EPSILON = 1E-11;
+
+ /**
+ * recursive subdivision epsilon - (see getRecursionDepth)
+ */
+ private static final double RS_EPSILON = 1E-13;
+
+ /**
+ * Snap distance - points within this distance are considered equal
+ */
+ private static final double PE_EPSILON = 1E-11;
+
+ /**
+ * Segment vectors containing solid areas and holes
+ * This is package-private to avoid an accessor method.
+ */
+ Vector solids;
+
+ /**
+ * Segment vectors containing solid areas and holes
+ * This is package-private to avoid an accessor method.
+ */
+ Vector holes;
+
+ /**
+ * Vector (temporary) storing curve-curve intersections
+ */
+ private Vector cc_intersections;
+
+ /**
+ * Winding rule WIND_NON_ZERO used, after construction,
+ * this is irrelevant.
+ */
+ private int windingRule;
+
+ /**
+ * Constructs an empty Area
+ */
+ public Area()
+ {
+ solids = new Vector();
+ holes = new Vector();
+ }
+
+ /**
+ * Constructs an Area from any given Shape. <P>
+ *
+ * If the Shape is self-intersecting, the created Area will consist
+ * of non-self-intersecting subpaths, and any inner paths which
+ * are found redundant in accordance with the Shape's winding rule
+ * will not be included.
+ *
+ * @param s the shape (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>s</code> is <code>null</code>.
+ */
+ public Area(Shape s)
+ {
+ this();
+
+ Vector p = makeSegment(s);
+
+ // empty path
+ if (p == null)
+ return;
+
+ // delete empty paths
+ for (int i = 0; i < p.size(); i++)
+ if (((Segment) p.elementAt(i)).getSignedArea() == 0.0)
+ p.remove(i--);
+
+ /*
+ * Resolve self intersecting paths into non-intersecting
+ * solids and holes.
+ * Algorithm is as follows:
+ * 1: Create nodes at all self intersections
+ * 2: Put all segments into a list
+ * 3: Grab a segment, follow it, change direction at each node,
+ * removing segments from the list in the process
+ * 4: Repeat (3) until no segments remain in the list
+ * 5: Remove redundant paths and sort into solids and holes
+ */
+ Vector paths = new Vector();
+ Segment v;
+
+ for (int i = 0; i < p.size(); i++)
+ {
+ Segment path = (Segment) p.elementAt(i);
+ createNodesSelf(path);
+ }
+
+ if (p.size() > 1)
+ {
+ for (int i = 0; i < p.size() - 1; i++)
+ for (int j = i + 1; j < p.size(); j++)
+ {
+ Segment path1 = (Segment) p.elementAt(i);
+ Segment path2 = (Segment) p.elementAt(j);
+ createNodes(path1, path2);
+ }
+ }
+
+ // we have intersecting points.
+ Vector segments = new Vector();
+
+ for (int i = 0; i < p.size(); i++)
+ {
+ Segment path = v = (Segment) p.elementAt(i);
+ do
+ {
+ segments.add(v);
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ paths = weilerAtherton(segments);
+ deleteRedundantPaths(paths);
+ }
+
+ /**
+ * Performs an add (union) operation on this area with another Area.<BR>
+ * @param area - the area to be unioned with this one
+ */
+ public void add(Area area)
+ {
+ if (equals(area))
+ return;
+ if (area.isEmpty())
+ return;
+
+ Area B = (Area) area.clone();
+
+ Vector pathA = new Vector();
+ Vector pathB = new Vector();
+ pathA.addAll(solids);
+ pathA.addAll(holes);
+ pathB.addAll(B.solids);
+ pathB.addAll(B.holes);
+
+ int nNodes = 0;
+
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment a = (Segment) pathA.elementAt(i);
+ for (int j = 0; j < pathB.size(); j++)
+ {
+ Segment b = (Segment) pathB.elementAt(j);
+ nNodes += createNodes(a, b);
+ }
+ }
+
+ Vector paths = new Vector();
+ Segment v;
+
+ // we have intersecting points.
+ Vector segments = new Vector();
+
+ // In a union operation, we keep all
+ // segments of A oustide B and all B outside A
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ v = (Segment) pathA.elementAt(i);
+ Segment path = v;
+ do
+ {
+ if (v.isSegmentOutside(area))
+ segments.add(v);
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ for (int i = 0; i < pathB.size(); i++)
+ {
+ v = (Segment) pathB.elementAt(i);
+ Segment path = v;
+ do
+ {
+ if (v.isSegmentOutside(this))
+ segments.add(v);
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ paths = weilerAtherton(segments);
+ deleteRedundantPaths(paths);
+ }
+
+ /**
+ * Performs a subtraction operation on this Area.<BR>
+ * @param area the area to be subtracted from this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
+ */
+ public void subtract(Area area)
+ {
+ if (isEmpty() || area.isEmpty())
+ return;
+
+ if (equals(area))
+ {
+ reset();
+ return;
+ }
+
+ Vector pathA = new Vector();
+ Area B = (Area) area.clone();
+ pathA.addAll(solids);
+ pathA.addAll(holes);
+
+ // reverse the directions of B paths.
+ setDirection(B.holes, true);
+ setDirection(B.solids, false);
+
+ Vector pathB = new Vector();
+ pathB.addAll(B.solids);
+ pathB.addAll(B.holes);
+
+ int nNodes = 0;
+
+ // create nodes
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment a = (Segment) pathA.elementAt(i);
+ for (int j = 0; j < pathB.size(); j++)
+ {
+ Segment b = (Segment) pathB.elementAt(j);
+ nNodes += createNodes(a, b);
+ }
+ }
+
+ Vector paths = new Vector();
+
+ // we have intersecting points.
+ Vector segments = new Vector();
+
+ // In a subtraction operation, we keep all
+ // segments of A oustide B and all B within A
+ // We outsideness-test only one segment in each path
+ // and the segments before and after any node
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment v = (Segment) pathA.elementAt(i);
+ Segment path = v;
+ if (v.isSegmentOutside(area) && v.node == null)
+ segments.add(v);
+ boolean node = false;
+ do
+ {
+ if ((v.node != null || node))
+ {
+ node = (v.node != null);
+ if (v.isSegmentOutside(area))
+ segments.add(v);
+ }
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ for (int i = 0; i < pathB.size(); i++)
+ {
+ Segment v = (Segment) pathB.elementAt(i);
+ Segment path = v;
+ if (! v.isSegmentOutside(this) && v.node == null)
+ segments.add(v);
+ v = v.next;
+ boolean node = false;
+ do
+ {
+ if ((v.node != null || node))
+ {
+ node = (v.node != null);
+ if (! v.isSegmentOutside(this))
+ segments.add(v);
+ }
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ paths = weilerAtherton(segments);
+ deleteRedundantPaths(paths);
+ }
+
+ /**
+ * Performs an intersection operation on this Area.<BR>
+ * @param area - the area to be intersected with this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
+ */
+ public void intersect(Area area)
+ {
+ if (isEmpty() || area.isEmpty())
+ {
+ reset();
+ return;
+ }
+ if (equals(area))
+ return;
+
+ Vector pathA = new Vector();
+ Area B = (Area) area.clone();
+ pathA.addAll(solids);
+ pathA.addAll(holes);
+
+ Vector pathB = new Vector();
+ pathB.addAll(B.solids);
+ pathB.addAll(B.holes);
+
+ int nNodes = 0;
+
+ // create nodes
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment a = (Segment) pathA.elementAt(i);
+ for (int j = 0; j < pathB.size(); j++)
+ {
+ Segment b = (Segment) pathB.elementAt(j);
+ nNodes += createNodes(a, b);
+ }
+ }
+
+ Vector paths = new Vector();
+
+ // we have intersecting points.
+ Vector segments = new Vector();
+
+ // In an intersection operation, we keep all
+ // segments of A within B and all B within A
+ // (The rest must be redundant)
+ // We outsideness-test only one segment in each path
+ // and the segments before and after any node
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment v = (Segment) pathA.elementAt(i);
+ Segment path = v;
+ if (! v.isSegmentOutside(area) && v.node == null)
+ segments.add(v);
+ boolean node = false;
+ do
+ {
+ if ((v.node != null || node))
+ {
+ node = (v.node != null);
+ if (! v.isSegmentOutside(area))
+ segments.add(v);
+ }
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ for (int i = 0; i < pathB.size(); i++)
+ {
+ Segment v = (Segment) pathB.elementAt(i);
+ Segment path = v;
+ if (! v.isSegmentOutside(this) && v.node == null)
+ segments.add(v);
+ v = v.next;
+ boolean node = false;
+ do
+ {
+ if ((v.node != null || node))
+ {
+ node = (v.node != null);
+ if (! v.isSegmentOutside(this))
+ segments.add(v);
+ }
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ paths = weilerAtherton(segments);
+ deleteRedundantPaths(paths);
+ }
+
+ /**
+ * Performs an exclusive-or operation on this Area.<BR>
+ * @param area - the area to be XORed with this area.
+ * @throws NullPointerException if <code>area</code> is <code>null</code>.
+ */
+ public void exclusiveOr(Area area)
+ {
+ if (area.isEmpty())
+ return;
+
+ if (isEmpty())
+ {
+ Area B = (Area) area.clone();
+ solids = B.solids;
+ holes = B.holes;
+ return;
+ }
+ if (equals(area))
+ {
+ reset();
+ return;
+ }
+
+ Vector pathA = new Vector();
+
+ Area B = (Area) area.clone();
+ Vector pathB = new Vector();
+ pathA.addAll(solids);
+ pathA.addAll(holes);
+
+ // reverse the directions of B paths.
+ setDirection(B.holes, true);
+ setDirection(B.solids, false);
+ pathB.addAll(B.solids);
+ pathB.addAll(B.holes);
+
+ int nNodes = 0;
+
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ Segment a = (Segment) pathA.elementAt(i);
+ for (int j = 0; j < pathB.size(); j++)
+ {
+ Segment b = (Segment) pathB.elementAt(j);
+ nNodes += createNodes(a, b);
+ }
+ }
+
+ Vector paths = new Vector();
+ Segment v;
+
+ // we have intersecting points.
+ Vector segments = new Vector();
+
+ // In an XOR operation, we operate on all segments
+ for (int i = 0; i < pathA.size(); i++)
+ {
+ v = (Segment) pathA.elementAt(i);
+ Segment path = v;
+ do
+ {
+ segments.add(v);
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ for (int i = 0; i < pathB.size(); i++)
+ {
+ v = (Segment) pathB.elementAt(i);
+ Segment path = v;
+ do
+ {
+ segments.add(v);
+ v = v.next;
+ }
+ while (v != path);
+ }
+
+ paths = weilerAtherton(segments);
+ deleteRedundantPaths(paths);
+ }
+
+ /**
+ * Clears the Area object, creating an empty area.
+ */
+ public void reset()
+ {
+ solids = new Vector();
+ holes = new Vector();
+ }
+
+ /**
+ * Returns whether this area encloses any area.
+ * @return true if the object encloses any area.
+ */
+ public boolean isEmpty()
+ {
+ if (solids.size() == 0)
+ return true;
+
+ double totalArea = 0;
+ for (int i = 0; i < solids.size(); i++)
+ totalArea += Math.abs(((Segment) solids.elementAt(i)).getSignedArea());
+ for (int i = 0; i < holes.size(); i++)
+ totalArea -= Math.abs(((Segment) holes.elementAt(i)).getSignedArea());
+ if (totalArea <= EPSILON)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Determines whether the Area consists entirely of line segments
+ * @return true if the Area lines-only, false otherwise
+ */
+ public boolean isPolygonal()
+ {
+ for (int i = 0; i < holes.size(); i++)
+ if (! ((Segment) holes.elementAt(i)).isPolygonal())
+ return false;
+ for (int i = 0; i < solids.size(); i++)
+ if (! ((Segment) solids.elementAt(i)).isPolygonal())
+ return false;
+ return true;
+ }
+
+ /**
+ * Determines if the Area is rectangular.<P>
+ *
+ * This is strictly qualified. An area is considered rectangular if:<BR>
+ * <li>It consists of a single polygonal path.<BR>
+ * <li>It is oriented parallel/perpendicular to the xy axis<BR>
+ * <li>It must be exactly rectangular, i.e. small errors induced by
+ * transformations may cause a false result, although the area is
+ * visibly rectangular.<P>
+ * @return true if the above criteria are met, false otherwise
+ */
+ public boolean isRectangular()
+ {
+ if (isEmpty())
+ return true;
+
+ if (holes.size() != 0 || solids.size() != 1)
+ return false;
+
+ Segment path = (Segment) solids.elementAt(0);
+ if (! path.isPolygonal())
+ return false;
+
+ int nCorners = 0;
+ Segment s = path;
+ do
+ {
+ Segment s2 = s.next;
+ double d1 = (s.P2.getX() - s.P1.getX())*(s2.P2.getX() - s2.P1.getX())/
+ ((s.P1.distance(s.P2)) * (s2.P1.distance(s2.P2)));
+ double d2 = (s.P2.getY() - s.P1.getY())*(s2.P2.getY() - s2.P1.getY())/
+ ((s.P1.distance(s.P2)) * (s2.P1.distance(s2.P2)));
+ double dotproduct = d1 + d2;
+
+ // For some reason, only rectangles on the XY axis count.
+ if (d1 != 0 && d2 != 0)
+ return false;
+
+ if (Math.abs(dotproduct) == 0) // 90 degree angle
+ nCorners++;
+ else if ((Math.abs(1.0 - dotproduct) > 0)) // 0 degree angle?
+ return false; // if not, return false
+
+ s = s.next;
+ }
+ while (s != path);
+
+ return nCorners == 4;
+ }
+
+ /**
+ * Returns whether the Area consists of more than one simple
+ * (non self-intersecting) subpath.
+ *
+ * @return true if the Area consists of none or one simple subpath,
+ * false otherwise.
+ */
+ public boolean isSingular()
+ {
+ return (holes.size() == 0 && solids.size() <= 1);
+ }
+
+ /**
+ * Returns the bounding box of the Area.<P> Unlike the CubicCurve2D and
+ * QuadraticCurve2D classes, this method will return the tightest possible
+ * bounding box, evaluating the extreme points of each curved segment.<P>
+ * @return the bounding box
+ */
+ public Rectangle2D getBounds2D()
+ {
+ if (solids.size() == 0)
+ return new Rectangle2D.Double(0.0, 0.0, 0.0, 0.0);
+
+ double xmin;
+ double xmax;
+ double ymin;
+ double ymax;
+ xmin = xmax = ((Segment) solids.elementAt(0)).P1.getX();
+ ymin = ymax = ((Segment) solids.elementAt(0)).P1.getY();
+
+ for (int path = 0; path < solids.size(); path++)
+ {
+ Rectangle2D r = ((Segment) solids.elementAt(path)).getPathBounds();
+ xmin = Math.min(r.getMinX(), xmin);
+ ymin = Math.min(r.getMinY(), ymin);
+ xmax = Math.max(r.getMaxX(), xmax);
+ ymax = Math.max(r.getMaxY(), ymax);
+ }
+
+ return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin)));
+ }
+
+ /**
+ * Returns the bounds of this object in Rectangle format.
+ * Please note that this may lead to loss of precision.
+ *
+ * @return The bounds.
+ * @see #getBounds2D()
+ */
+ public Rectangle getBounds()
+ {
+ return getBounds2D().getBounds();
+ }
+
+ /**
+ * Create a new area of the same run-time type with the same contents as
+ * this one.
+ *
+ * @return the clone
+ */
+ public Object clone()
+ {
+ try
+ {
+ Area clone = new Area();
+ for (int i = 0; i < solids.size(); i++)
+ clone.solids.add(((Segment) solids.elementAt(i)).cloneSegmentList());
+ for (int i = 0; i < holes.size(); i++)
+ clone.holes.add(((Segment) holes.elementAt(i)).cloneSegmentList());
+ return clone;
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * Compares two Areas.
+ *
+ * @param area the area to compare against this area (<code>null</code>
+ * permitted).
+ * @return <code>true</code> if the areas are equal, and <code>false</code>
+ * otherwise.
+ */
+ public boolean equals(Area area)
+ {
+ if (area == null)
+ return false;
+
+ if (! getBounds2D().equals(area.getBounds2D()))
+ return false;
+
+ if (solids.size() != area.solids.size()
+ || holes.size() != area.holes.size())
+ return false;
+
+ Vector pathA = new Vector();
+ pathA.addAll(solids);
+ pathA.addAll(holes);
+ Vector pathB = new Vector();
+ pathB.addAll(area.solids);
+ pathB.addAll(area.holes);
+
+ int nPaths = pathA.size();
+ boolean[][] match = new boolean[2][nPaths];
+
+ for (int i = 0; i < nPaths; i++)
+ {
+ for (int j = 0; j < nPaths; j++)
+ {
+ Segment p1 = (Segment) pathA.elementAt(i);
+ Segment p2 = (Segment) pathB.elementAt(j);
+ if (! match[0][i] && ! match[1][j])
+ if (p1.pathEquals(p2))
+ match[0][i] = match[1][j] = true;
+ }
+ }
+
+ boolean result = true;
+ for (int i = 0; i < nPaths; i++)
+ result = result && match[0][i] && match[1][i];
+ return result;
+ }
+
+ /**
+ * Transforms this area by the AffineTransform at.
+ *
+ * @param at the transform.
+ */
+ public void transform(AffineTransform at)
+ {
+ for (int i = 0; i < solids.size(); i++)
+ ((Segment) solids.elementAt(i)).transformSegmentList(at);
+ for (int i = 0; i < holes.size(); i++)
+ ((Segment) holes.elementAt(i)).transformSegmentList(at);
+
+ // Note that the orientation is not invariant under inversion
+ if ((at.getType() & AffineTransform.TYPE_FLIP) != 0)
+ {
+ setDirection(holes, false);
+ setDirection(solids, true);
+ }
+ }
+
+ /**
+ * Returns a new Area equal to this one, transformed
+ * by the AffineTransform at.
+ * @param at the transform.
+ * @return the transformed area
+ * @throws NullPointerException if <code>at</code> is <code>null</code>.
+ */
+ public Area createTransformedArea(AffineTransform at)
+ {
+ Area a = (Area) clone();
+ a.transform(at);
+ return a;
+ }
+
+ /**
+ * Determines if the point (x,y) is contained within this Area.
+ *
+ * @param x the x-coordinate of the point.
+ * @param y the y-coordinate of the point.
+ * @return true if the point is contained, false otherwise.
+ */
+ public boolean contains(double x, double y)
+ {
+ int n = 0;
+ for (int i = 0; i < solids.size(); i++)
+ if (((Segment) solids.elementAt(i)).contains(x, y))
+ n++;
+
+ for (int i = 0; i < holes.size(); i++)
+ if (((Segment) holes.elementAt(i)).contains(x, y))
+ n--;
+
+ return (n != 0);
+ }
+
+ /**
+ * Determines if the Point2D p is contained within this Area.
+ *
+ * @param p the point.
+ * @return <code>true</code> if the point is contained, <code>false</code>
+ * otherwise.
+ * @throws NullPointerException if <code>p</code> is <code>null</code>.
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Determines if the rectangle specified by (x,y) as the upper-left
+ * and with width w and height h is completely contained within this Area,
+ * returns false otherwise.<P>
+ *
+ * This method should always produce the correct results, unlike for other
+ * classes in geom.
+ *
+ * @param x the x-coordinate of the rectangle.
+ * @param y the y-coordinate of the rectangle.
+ * @param w the width of the the rectangle.
+ * @param h the height of the rectangle.
+ * @return <code>true</code> if the rectangle is considered contained
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ LineSegment[] l = new LineSegment[4];
+ l[0] = new LineSegment(x, y, x + w, y);
+ l[1] = new LineSegment(x, y + h, x + w, y + h);
+ l[2] = new LineSegment(x, y, x, y + h);
+ l[3] = new LineSegment(x + w, y, x + w, y + h);
+
+ // Since every segment in the area must a contour
+ // between inside/outside segments, ANY intersection
+ // will mean the rectangle is not entirely contained.
+ for (int i = 0; i < 4; i++)
+ {
+ for (int path = 0; path < solids.size(); path++)
+ {
+ Segment v;
+ Segment start;
+ start = v = (Segment) solids.elementAt(path);
+ do
+ {
+ if (l[i].hasIntersections(v))
+ return false;
+ v = v.next;
+ }
+ while (v != start);
+ }
+ for (int path = 0; path < holes.size(); path++)
+ {
+ Segment v;
+ Segment start;
+ start = v = (Segment) holes.elementAt(path);
+ do
+ {
+ if (l[i].hasIntersections(v))
+ return false;
+ v = v.next;
+ }
+ while (v != start);
+ }
+ }
+
+ // Is any point inside?
+ if (! contains(x, y))
+ return false;
+
+ // Final hoop: Is the rectangle non-intersecting and inside,
+ // but encloses a hole?
+ Rectangle2D r = new Rectangle2D.Double(x, y, w, h);
+ for (int path = 0; path < holes.size(); path++)
+ if (! ((Segment) holes.elementAt(path)).isSegmentOutside(r))
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Determines if the Rectangle2D specified by r is completely contained
+ * within this Area, returns false otherwise.<P>
+ *
+ * This method should always produce the correct results, unlike for other
+ * classes in geom.
+ *
+ * @param r the rectangle.
+ * @return <code>true</code> if the rectangle is considered contained
+ *
+ * @throws NullPointerException if <code>r</code> is <code>null</code>.
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Determines if the rectangle specified by (x,y) as the upper-left
+ * and with width w and height h intersects any part of this Area.
+ *
+ * @param x the x-coordinate for the rectangle.
+ * @param y the y-coordinate for the rectangle.
+ * @param w the width of the rectangle.
+ * @param h the height of the rectangle.
+ * @return <code>true</code> if the rectangle intersects the area,
+ * <code>false</code> otherwise.
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ if (solids.size() == 0)
+ return false;
+
+ LineSegment[] l = new LineSegment[4];
+ l[0] = new LineSegment(x, y, x + w, y);
+ l[1] = new LineSegment(x, y + h, x + w, y + h);
+ l[2] = new LineSegment(x, y, x, y + h);
+ l[3] = new LineSegment(x + w, y, x + w, y + h);
+
+ // Return true on any intersection
+ for (int i = 0; i < 4; i++)
+ {
+ for (int path = 0; path < solids.size(); path++)
+ {
+ Segment v;
+ Segment start;
+ start = v = (Segment) solids.elementAt(path);
+ do
+ {
+ if (l[i].hasIntersections(v))
+ return true;
+ v = v.next;
+ }
+ while (v != start);
+ }
+ for (int path = 0; path < holes.size(); path++)
+ {
+ Segment v;
+ Segment start;
+ start = v = (Segment) holes.elementAt(path);
+ do
+ {
+ if (l[i].hasIntersections(v))
+ return true;
+ v = v.next;
+ }
+ while (v != start);
+ }
+ }
+
+ // Non-intersecting, Is any point inside?
+ if (contains(x + w * 0.5, y + h * 0.5))
+ return true;
+
+ // What if the rectangle encloses the whole shape?
+ Point2D p = ((Segment) solids.elementAt(0)).getMidPoint();
+ if ((new Rectangle2D.Double(x, y, w, h)).contains(p))
+ return true;
+ return false;
+ }
+
+ /**
+ * Determines if the Rectangle2D specified by r intersects any
+ * part of this Area.
+ * @param r the rectangle to test intersection with (<code>null</code>
+ * not permitted).
+ * @return <code>true</code> if the rectangle intersects the area,
+ * <code>false</code> otherwise.
+ * @throws NullPointerException if <code>r</code> is <code>null</code>.
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Returns a PathIterator object defining the contour of this Area,
+ * transformed by at.
+ *
+ * @param at the transform.
+ * @return A path iterator.
+ */
+ public PathIterator getPathIterator(AffineTransform at)
+ {
+ return (new AreaIterator(at));
+ }
+
+ /**
+ * Returns a flattened PathIterator object defining the contour of this
+ * Area, transformed by at and with a defined flatness.
+ *
+ * @param at the transform.
+ * @param flatness the flatness.
+ * @return A path iterator.
+ */
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return new FlatteningPathIterator(getPathIterator(at), flatness);
+ }
+
+ //---------------------------------------------------------------------
+ // Non-public methods and classes
+
+ /**
+ * Private pathiterator object.
+ */
+ private class AreaIterator implements PathIterator
+ {
+ private Vector segments;
+ private int index;
+ private AffineTransform at;
+
+ // Simple compound type for segments
+ class IteratorSegment
+ {
+ int type;
+ double[] coords;
+
+ IteratorSegment()
+ {
+ coords = new double[6];
+ }
+ }
+
+ /**
+ * The contructor here does most of the work,
+ * creates a vector of IteratorSegments, which can
+ * readily be returned
+ */
+ public AreaIterator(AffineTransform at)
+ {
+ this.at = at;
+ index = 0;
+ segments = new Vector();
+ Vector allpaths = new Vector();
+ allpaths.addAll(solids);
+ allpaths.addAll(holes);
+
+ for (int i = 0; i < allpaths.size(); i++)
+ {
+ Segment v = (Segment) allpaths.elementAt(i);
+ Segment start = v;
+
+ IteratorSegment is = new IteratorSegment();
+ is.type = SEG_MOVETO;
+ is.coords[0] = start.P1.getX();
+ is.coords[1] = start.P1.getY();
+ segments.add(is);
+
+ do
+ {
+ is = new IteratorSegment();
+ is.type = v.pathIteratorFormat(is.coords);
+ segments.add(is);
+ v = v.next;
+ }
+ while (v != start);
+
+ is = new IteratorSegment();
+ is.type = SEG_CLOSE;
+ segments.add(is);
+ }
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ IteratorSegment s = (IteratorSegment) segments.elementAt(index);
+ if (at != null)
+ at.transform(s.coords, 0, coords, 0, 3);
+ else
+ for (int i = 0; i < 6; i++)
+ coords[i] = s.coords[i];
+ return (s.type);
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ IteratorSegment s = (IteratorSegment) segments.elementAt(index);
+ double[] d = new double[6];
+ if (at != null)
+ {
+ at.transform(s.coords, 0, d, 0, 3);
+ for (int i = 0; i < 6; i++)
+ coords[i] = (float) d[i];
+ }
+ else
+ for (int i = 0; i < 6; i++)
+ coords[i] = (float) s.coords[i];
+ return (s.type);
+ }
+
+ // Note that the winding rule should not matter here,
+ // EVEN_ODD is chosen because it renders faster.
+ public int getWindingRule()
+ {
+ return (PathIterator.WIND_EVEN_ODD);
+ }
+
+ public boolean isDone()
+ {
+ return (index >= segments.size());
+ }
+
+ public void next()
+ {
+ index++;
+ }
+ }
+
+ /**
+ * Performs the fundamental task of the Weiler-Atherton algorithm,
+ * traverse a list of segments, for each segment:
+ * Follow it, removing segments from the list and switching paths
+ * at each node. Do so until the starting segment is reached.
+ *
+ * Returns a Vector of the resulting paths.
+ */
+ private Vector weilerAtherton(Vector segments)
+ {
+ Vector paths = new Vector();
+ while (segments.size() > 0)
+ {
+ // Iterate over the path
+ Segment start = (Segment) segments.elementAt(0);
+ Segment s = start;
+ do
+ {
+ segments.remove(s);
+ if (s.node != null)
+ { // switch over
+ s.next = s.node;
+ s.node = null;
+ }
+ s = s.next; // continue
+ }
+ while (s != start);
+
+ paths.add(start);
+ }
+ return paths;
+ }
+
+ /**
+ * A small wrapper class to store intersection points
+ */
+ private class Intersection
+ {
+ Point2D p; // the 2D point of intersection
+ double ta; // the parametric value on a
+ double tb; // the parametric value on b
+ Segment seg; // segment placeholder for node setting
+
+ public Intersection(Point2D p, double ta, double tb)
+ {
+ this.p = p;
+ this.ta = ta;
+ this.tb = tb;
+ }
+ }
+
+ /**
+ * Returns the recursion depth necessary to approximate the
+ * curve by line segments within the error RS_EPSILON.
+ *
+ * This is done with Wang's formula:
+ * L0 = max{0<=i<=N-2}(|xi - 2xi+1 + xi+2|,|yi - 2yi+1 + yi+2|)
+ * r0 = log4(sqrt(2)*N*(N-1)*L0/8e)
+ * Where e is the maximum distance error (RS_EPSILON)
+ */
+ private int getRecursionDepth(CubicSegment curve)
+ {
+ double x0 = curve.P1.getX();
+ double y0 = curve.P1.getY();
+
+ double x1 = curve.cp1.getX();
+ double y1 = curve.cp1.getY();
+
+ double x2 = curve.cp2.getX();
+ double y2 = curve.cp2.getY();
+
+ double x3 = curve.P2.getX();
+ double y3 = curve.P2.getY();
+
+ double L0 = Math.max(Math.max(Math.abs(x0 - 2 * x1 + x2),
+ Math.abs(x1 - 2 * x2 + x3)),
+ Math.max(Math.abs(y0 - 2 * y1 + y2),
+ Math.abs(y1 - 2 * y2 + y3)));
+
+ double f = Math.sqrt(2) * 6.0 * L0 / (8.0 * RS_EPSILON);
+
+ int r0 = (int) Math.ceil(Math.log(f) / Math.log(4.0));
+ return (r0);
+ }
+
+ /**
+ * Performs recursive subdivision:
+ * @param c1 - curve 1
+ * @param c2 - curve 2
+ * @param depth1 - recursion depth of curve 1
+ * @param depth2 - recursion depth of curve 2
+ * @param t1 - global parametric value of the first curve's starting point
+ * @param t2 - global parametric value of the second curve's starting point
+ * @param w1 - global parametric length of curve 1
+ * @param w2 - global parametric length of curve 2
+ *
+ * The final four parameters are for keeping track of the parametric
+ * value of the curve. For a full curve t = 0, w = 1, w is halved with
+ * each subdivision.
+ */
+ private void recursiveSubdivide(CubicCurve2D c1, CubicCurve2D c2,
+ int depth1, int depth2, double t1,
+ double t2, double w1, double w2)
+ {
+ boolean flat1 = depth1 <= 0;
+ boolean flat2 = depth2 <= 0;
+
+ if (flat1 && flat2)
+ {
+ double xlk = c1.getP2().getX() - c1.getP1().getX();
+ double ylk = c1.getP2().getY() - c1.getP1().getY();
+
+ double xnm = c2.getP2().getX() - c2.getP1().getX();
+ double ynm = c2.getP2().getY() - c2.getP1().getY();
+
+ double xmk = c2.getP1().getX() - c1.getP1().getX();
+ double ymk = c2.getP1().getY() - c1.getP1().getY();
+ double det = xnm * ylk - ynm * xlk;
+
+ if (det + 1.0 == 1.0)
+ return;
+
+ double detinv = 1.0 / det;
+ double s = (xnm * ymk - ynm * xmk) * detinv;
+ double t = (xlk * ymk - ylk * xmk) * detinv;
+ if ((s < 0.0) || (s > 1.0) || (t < 0.0) || (t > 1.0))
+ return;
+
+ double[] temp = new double[2];
+ temp[0] = t1 + s * w1;
+ temp[1] = t2 + t * w1;
+ cc_intersections.add(temp);
+ return;
+ }
+
+ CubicCurve2D.Double c11 = new CubicCurve2D.Double();
+ CubicCurve2D.Double c12 = new CubicCurve2D.Double();
+ CubicCurve2D.Double c21 = new CubicCurve2D.Double();
+ CubicCurve2D.Double c22 = new CubicCurve2D.Double();
+
+ if (! flat1 && ! flat2)
+ {
+ depth1--;
+ depth2--;
+ w1 = w1 * 0.5;
+ w2 = w2 * 0.5;
+ c1.subdivide(c11, c12);
+ c2.subdivide(c21, c22);
+ if (c11.getBounds2D().intersects(c21.getBounds2D()))
+ recursiveSubdivide(c11, c21, depth1, depth2, t1, t2, w1, w2);
+ if (c11.getBounds2D().intersects(c22.getBounds2D()))
+ recursiveSubdivide(c11, c22, depth1, depth2, t1, t2 + w2, w1, w2);
+ if (c12.getBounds2D().intersects(c21.getBounds2D()))
+ recursiveSubdivide(c12, c21, depth1, depth2, t1 + w1, t2, w1, w2);
+ if (c12.getBounds2D().intersects(c22.getBounds2D()))
+ recursiveSubdivide(c12, c22, depth1, depth2, t1 + w1, t2 + w2, w1, w2);
+ return;
+ }
+
+ if (! flat1)
+ {
+ depth1--;
+ c1.subdivide(c11, c12);
+ w1 = w1 * 0.5;
+ if (c11.getBounds2D().intersects(c2.getBounds2D()))
+ recursiveSubdivide(c11, c2, depth1, depth2, t1, t2, w1, w2);
+ if (c12.getBounds2D().intersects(c2.getBounds2D()))
+ recursiveSubdivide(c12, c2, depth1, depth2, t1 + w1, t2, w1, w2);
+ return;
+ }
+
+ depth2--;
+ c2.subdivide(c21, c22);
+ w2 = w2 * 0.5;
+ if (c1.getBounds2D().intersects(c21.getBounds2D()))
+ recursiveSubdivide(c1, c21, depth1, depth2, t1, t2, w1, w2);
+ if (c1.getBounds2D().intersects(c22.getBounds2D()))
+ recursiveSubdivide(c1, c22, depth1, depth2, t1, t2 + w2, w1, w2);
+ }
+
+ /**
+ * Returns a set of interesections between two Cubic segments
+ * Or null if no intersections were found.
+ *
+ * The method used to find the intersection is recursive midpoint
+ * subdivision. Outline description:
+ *
+ * 1) Check if the bounding boxes of the curves intersect,
+ * 2) If so, divide the curves in the middle and test the bounding
+ * boxes again,
+ * 3) Repeat until a maximum recursion depth has been reached, where
+ * the intersecting curves can be approximated by line segments.
+ *
+ * This is a reasonably accurate method, although the recursion depth
+ * is typically around 20, the bounding-box tests allow for significant
+ * pruning of the subdivision tree.
+ *
+ * This is package-private to avoid an accessor method.
+ */
+ Intersection[] cubicCubicIntersect(CubicSegment curve1, CubicSegment curve2)
+ {
+ Rectangle2D r1 = curve1.getBounds();
+ Rectangle2D r2 = curve2.getBounds();
+
+ if (! r1.intersects(r2))
+ return null;
+
+ cc_intersections = new Vector();
+ recursiveSubdivide(curve1.getCubicCurve2D(), curve2.getCubicCurve2D(),
+ getRecursionDepth(curve1), getRecursionDepth(curve2),
+ 0.0, 0.0, 1.0, 1.0);
+
+ if (cc_intersections.size() == 0)
+ return null;
+
+ Intersection[] results = new Intersection[cc_intersections.size()];
+ for (int i = 0; i < cc_intersections.size(); i++)
+ {
+ double[] temp = (double[]) cc_intersections.elementAt(i);
+ results[i] = new Intersection(curve1.evaluatePoint(temp[0]), temp[0],
+ temp[1]);
+ }
+ cc_intersections = null;
+ return (results);
+ }
+
+ /**
+ * Returns the intersections between a line and a quadratic bezier
+ * Or null if no intersections are found1
+ * This is done through combining the line's equation with the
+ * parametric form of the Bezier and solving the resulting quadratic.
+ * This is package-private to avoid an accessor method.
+ */
+ Intersection[] lineQuadIntersect(LineSegment l, QuadSegment c)
+ {
+ double[] y = new double[3];
+ double[] x = new double[3];
+ double[] r = new double[3];
+ int nRoots;
+ double x0 = c.P1.getX();
+ double y0 = c.P1.getY();
+ double x1 = c.cp.getX();
+ double y1 = c.cp.getY();
+ double x2 = c.P2.getX();
+ double y2 = c.P2.getY();
+
+ double lx0 = l.P1.getX();
+ double ly0 = l.P1.getY();
+ double lx1 = l.P2.getX();
+ double ly1 = l.P2.getY();
+ double dx = lx1 - lx0;
+ double dy = ly1 - ly0;
+
+ // form r(t) = y(t) - x(t) for the bezier
+ y[0] = y0;
+ y[1] = 2 * (y1 - y0);
+ y[2] = (y2 - 2 * y1 + y0);
+
+ x[0] = x0;
+ x[1] = 2 * (x1 - x0);
+ x[2] = (x2 - 2 * x1 + x0);
+
+ // a point, not a line
+ if (dy == 0 && dx == 0)
+ return null;
+
+ // line on y axis
+ if (dx == 0 || (dy / dx) > 1.0)
+ {
+ double k = dx / dy;
+ x[0] -= lx0;
+ y[0] -= ly0;
+ y[0] *= k;
+ y[1] *= k;
+ y[2] *= k;
+ }
+ else
+ {
+ double k = dy / dx;
+ x[0] -= lx0;
+ y[0] -= ly0;
+ x[0] *= k;
+ x[1] *= k;
+ x[2] *= k;
+ }
+
+ for (int i = 0; i < 3; i++)
+ r[i] = y[i] - x[i];
+
+ if ((nRoots = QuadCurve2D.solveQuadratic(r)) > 0)
+ {
+ Intersection[] temp = new Intersection[nRoots];
+ int intersections = 0;
+ for (int i = 0; i < nRoots; i++)
+ {
+ double t = r[i];
+ if (t >= 0.0 && t <= 1.0)
+ {
+ Point2D p = c.evaluatePoint(t);
+
+ // if the line is on an axis, snap the point to that axis.
+ if (dx == 0)
+ p.setLocation(lx0, p.getY());
+ if (dy == 0)
+ p.setLocation(p.getX(), ly0);
+
+ if (p.getX() <= Math.max(lx0, lx1)
+ && p.getX() >= Math.min(lx0, lx1)
+ && p.getY() <= Math.max(ly0, ly1)
+ && p.getY() >= Math.min(ly0, ly1))
+ {
+ double lineparameter = p.distance(l.P1) / l.P2.distance(l.P1);
+ temp[i] = new Intersection(p, lineparameter, t);
+ intersections++;
+ }
+ }
+ else
+ temp[i] = null;
+ }
+ if (intersections == 0)
+ return null;
+
+ Intersection[] rValues = new Intersection[intersections];
+
+ for (int i = 0; i < nRoots; i++)
+ if (temp[i] != null)
+ rValues[--intersections] = temp[i];
+ return (rValues);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the intersections between a line and a cubic segment
+ * This is done through combining the line's equation with the
+ * parametric form of the Bezier and solving the resulting quadratic.
+ * This is package-private to avoid an accessor method.
+ */
+ Intersection[] lineCubicIntersect(LineSegment l, CubicSegment c)
+ {
+ double[] y = new double[4];
+ double[] x = new double[4];
+ double[] r = new double[4];
+ int nRoots;
+ double x0 = c.P1.getX();
+ double y0 = c.P1.getY();
+ double x1 = c.cp1.getX();
+ double y1 = c.cp1.getY();
+ double x2 = c.cp2.getX();
+ double y2 = c.cp2.getY();
+ double x3 = c.P2.getX();
+ double y3 = c.P2.getY();
+
+ double lx0 = l.P1.getX();
+ double ly0 = l.P1.getY();
+ double lx1 = l.P2.getX();
+ double ly1 = l.P2.getY();
+ double dx = lx1 - lx0;
+ double dy = ly1 - ly0;
+
+ // form r(t) = y(t) - x(t) for the bezier
+ y[0] = y0;
+ y[1] = 3 * (y1 - y0);
+ y[2] = 3 * (y2 + y0 - 2 * y1);
+ y[3] = y3 - 3 * y2 + 3 * y1 - y0;
+
+ x[0] = x0;
+ x[1] = 3 * (x1 - x0);
+ x[2] = 3 * (x2 + x0 - 2 * x1);
+ x[3] = x3 - 3 * x2 + 3 * x1 - x0;
+
+ // a point, not a line
+ if (dy == 0 && dx == 0)
+ return null;
+
+ // line on y axis
+ if (dx == 0 || (dy / dx) > 1.0)
+ {
+ double k = dx / dy;
+ x[0] -= lx0;
+ y[0] -= ly0;
+ y[0] *= k;
+ y[1] *= k;
+ y[2] *= k;
+ y[3] *= k;
+ }
+ else
+ {
+ double k = dy / dx;
+ x[0] -= lx0;
+ y[0] -= ly0;
+ x[0] *= k;
+ x[1] *= k;
+ x[2] *= k;
+ x[3] *= k;
+ }
+ for (int i = 0; i < 4; i++)
+ r[i] = y[i] - x[i];
+
+ if ((nRoots = CubicCurve2D.solveCubic(r)) > 0)
+ {
+ Intersection[] temp = new Intersection[nRoots];
+ int intersections = 0;
+ for (int i = 0; i < nRoots; i++)
+ {
+ double t = r[i];
+ if (t >= 0.0 && t <= 1.0)
+ {
+ // if the line is on an axis, snap the point to that axis.
+ Point2D p = c.evaluatePoint(t);
+ if (dx == 0)
+ p.setLocation(lx0, p.getY());
+ if (dy == 0)
+ p.setLocation(p.getX(), ly0);
+
+ if (p.getX() <= Math.max(lx0, lx1)
+ && p.getX() >= Math.min(lx0, lx1)
+ && p.getY() <= Math.max(ly0, ly1)
+ && p.getY() >= Math.min(ly0, ly1))
+ {
+ double lineparameter = p.distance(l.P1) / l.P2.distance(l.P1);
+ temp[i] = new Intersection(p, lineparameter, t);
+ intersections++;
+ }
+ }
+ else
+ temp[i] = null;
+ }
+
+ if (intersections == 0)
+ return null;
+
+ Intersection[] rValues = new Intersection[intersections];
+ for (int i = 0; i < nRoots; i++)
+ if (temp[i] != null)
+ rValues[--intersections] = temp[i];
+ return (rValues);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the intersection between two lines, or null if there is no
+ * intersection.
+ * This is package-private to avoid an accessor method.
+ */
+ Intersection linesIntersect(LineSegment a, LineSegment b)
+ {
+ Point2D P1 = a.P1;
+ Point2D P2 = a.P2;
+ Point2D P3 = b.P1;
+ Point2D P4 = b.P2;
+
+ if (! Line2D.linesIntersect(P1.getX(), P1.getY(), P2.getX(), P2.getY(),
+ P3.getX(), P3.getY(), P4.getX(), P4.getY()))
+ return null;
+
+ double x1 = P1.getX();
+ double y1 = P1.getY();
+ double rx = P2.getX() - x1;
+ double ry = P2.getY() - y1;
+
+ double x2 = P3.getX();
+ double y2 = P3.getY();
+ double sx = P4.getX() - x2;
+ double sy = P4.getY() - y2;
+
+ double determinant = sx * ry - sy * rx;
+ double nom = (sx * (y2 - y1) + sy * (x1 - x2));
+
+ // Parallel lines don't intersect. At least we pretend they don't.
+ if (Math.abs(determinant) < EPSILON)
+ return null;
+
+ nom = nom / determinant;
+
+ if (nom == 0.0)
+ return null;
+ if (nom == 1.0)
+ return null;
+
+ Point2D p = new Point2D.Double(x1 + nom * rx, y1 + nom * ry);
+
+ return new Intersection(p, p.distance(P1) / P1.distance(P2),
+ p.distance(P3) / P3.distance(P4));
+ }
+
+ /**
+ * Determines if two points are equal, within an error margin
+ * 'snap distance'
+ * This is package-private to avoid an accessor method.
+ */
+ boolean pointEquals(Point2D a, Point2D b)
+ {
+ return (a.equals(b) || a.distance(b) < PE_EPSILON);
+ }
+
+ /**
+ * Helper method
+ * Turns a shape into a Vector of Segments
+ */
+ private Vector makeSegment(Shape s)
+ {
+ Vector paths = new Vector();
+ PathIterator pi = s.getPathIterator(null);
+ double[] coords = new double[6];
+ Segment subpath = null;
+ Segment current = null;
+ double cx;
+ double cy;
+ double subpathx;
+ double subpathy;
+ cx = cy = subpathx = subpathy = 0.0;
+
+ this.windingRule = pi.getWindingRule();
+
+ while (! pi.isDone())
+ {
+ Segment v;
+ switch (pi.currentSegment(coords))
+ {
+ case PathIterator.SEG_MOVETO:
+ if (subpath != null)
+ { // close existing open path
+ current.next = new LineSegment(cx, cy, subpathx, subpathy);
+ current = current.next;
+ current.next = subpath;
+ }
+ subpath = null;
+ subpathx = cx = coords[0];
+ subpathy = cy = coords[1];
+ break;
+
+ // replace 'close' with a line-to.
+ case PathIterator.SEG_CLOSE:
+ if (subpath != null && (subpathx != cx || subpathy != cy))
+ {
+ current.next = new LineSegment(cx, cy, subpathx, subpathy);
+ current = current.next;
+ current.next = subpath;
+ cx = subpathx;
+ cy = subpathy;
+ subpath = null;
+ }
+ else if (subpath != null)
+ {
+ current.next = subpath;
+ subpath = null;
+ }
+ break;
+ case PathIterator.SEG_LINETO:
+ if (cx != coords[0] || cy != coords[1])
+ {
+ v = new LineSegment(cx, cy, coords[0], coords[1]);
+ if (subpath == null)
+ {
+ subpath = current = v;
+ paths.add(subpath);
+ }
+ else
+ {
+ current.next = v;
+ current = current.next;
+ }
+ cx = coords[0];
+ cy = coords[1];
+ }
+ break;
+ case PathIterator.SEG_QUADTO:
+ v = new QuadSegment(cx, cy, coords[0], coords[1], coords[2],
+ coords[3]);
+ if (subpath == null)
+ {
+ subpath = current = v;
+ paths.add(subpath);
+ }
+ else
+ {
+ current.next = v;
+ current = current.next;
+ }
+ cx = coords[2];
+ cy = coords[3];
+ break;
+ case PathIterator.SEG_CUBICTO:
+ v = new CubicSegment(cx, cy, coords[0], coords[1], coords[2],
+ coords[3], coords[4], coords[5]);
+ if (subpath == null)
+ {
+ subpath = current = v;
+ paths.add(subpath);
+ }
+ else
+ {
+ current.next = v;
+ current = current.next;
+ }
+
+ // check if the cubic is self-intersecting
+ double[] lpts = ((CubicSegment) v).getLoop();
+ if (lpts != null)
+ {
+ // if it is, break off the loop into its own path.
+ v.subdivideInsert(lpts[0]);
+ v.next.subdivideInsert((lpts[1] - lpts[0]) / (1.0 - lpts[0]));
+
+ CubicSegment loop = (CubicSegment) v.next;
+ v.next = loop.next;
+ loop.next = loop;
+
+ v.P2 = v.next.P1 = loop.P2 = loop.P1; // snap points
+ paths.add(loop);
+ current = v.next;
+ }
+
+ cx = coords[4];
+ cy = coords[5];
+ break;
+ }
+ pi.next();
+ }
+
+ if (subpath != null)
+ { // close any open path
+ if (subpathx != cx || subpathy != cy)
+ {
+ current.next = new LineSegment(cx, cy, subpathx, subpathy);
+ current = current.next;
+ current.next = subpath;
+ }
+ else
+ current.next = subpath;
+ }
+
+ if (paths.size() == 0)
+ return (null);
+
+ return (paths);
+ }
+
+ /**
+ * Find the intersections of two separate closed paths,
+ * A and B, split the segments at the intersection points,
+ * and create nodes pointing from one to the other
+ */
+ private int createNodes(Segment A, Segment B)
+ {
+ int nNodes = 0;
+
+ Segment a = A;
+ Segment b = B;
+
+ do
+ {
+ do
+ {
+ nNodes += a.splitIntersections(b);
+ b = b.next;
+ }
+ while (b != B);
+
+ a = a.next; // move to the next segment
+ }
+ while (a != A); // until one wrap.
+
+ return (nNodes);
+ }
+
+ /**
+ * Find the intersections of a path with itself.
+ * Splits the segments at the intersection points,
+ * and create nodes pointing from one to the other.
+ */
+ private int createNodesSelf(Segment A)
+ {
+ int nNodes = 0;
+ Segment a = A;
+
+ if (A.next == A)
+ return 0;
+
+ do
+ {
+ Segment b = a.next;
+ do
+ {
+ if (b != a) // necessary
+ nNodes += a.splitIntersections(b);
+ b = b.next;
+ }
+ while (b != A);
+ a = a.next; // move to the next segment
+ }
+ while (a != A); // until one wrap.
+
+ return (nNodes);
+ }
+
+ /**
+ * Deletes paths which are redundant from a list, (i.e. solid areas within
+ * solid areas) Clears any nodes. Sorts the remaining paths into solids
+ * and holes, sets their orientation and sets the solids and holes lists.
+ */
+ private void deleteRedundantPaths(Vector paths)
+ {
+ int npaths = paths.size();
+
+ int[][] contains = new int[npaths][npaths];
+ int[][] windingNumbers = new int[npaths][2];
+ int neg;
+ Rectangle2D[] bb = new Rectangle2D[npaths]; // path bounding boxes
+
+ neg = ((windingRule == PathIterator.WIND_NON_ZERO) ? -1 : 1);
+
+ for (int i = 0; i < npaths; i++)
+ bb[i] = ((Segment) paths.elementAt(i)).getPathBounds();
+
+ // Find which path contains which, assign winding numbers
+ for (int i = 0; i < npaths; i++)
+ {
+ Segment pathA = (Segment) paths.elementAt(i);
+ pathA.nullNodes(); // remove any now-redundant nodes, in case.
+ int windingA = pathA.hasClockwiseOrientation() ? 1 : neg;
+
+ for (int j = 0; j < npaths; j++)
+ if (i != j)
+ {
+ Segment pathB = (Segment) paths.elementAt(j);
+
+ // A contains B
+ if (bb[i].intersects(bb[j]))
+ {
+ Segment s = pathB.next;
+ while (s.P1.getY() == s.P2.getY() && s != pathB)
+ s = s.next;
+ Point2D p = s.getMidPoint();
+ if (pathA.contains(p.getX(), p.getY()))
+ contains[i][j] = windingA;
+ }
+ else
+ // A does not contain B
+ contains[i][j] = 0;
+ }
+ else
+ contains[i][j] = windingA; // i == j
+ }
+
+ for (int i = 0; i < npaths; i++)
+ {
+ windingNumbers[i][0] = 0;
+ for (int j = 0; j < npaths; j++)
+ windingNumbers[i][0] += contains[j][i];
+ windingNumbers[i][1] = contains[i][i];
+ }
+
+ Vector solids = new Vector();
+ Vector holes = new Vector();
+
+ if (windingRule == PathIterator.WIND_NON_ZERO)
+ {
+ for (int i = 0; i < npaths; i++)
+ {
+ if (windingNumbers[i][0] == 0)
+ holes.add(paths.elementAt(i));
+ else if (windingNumbers[i][0] - windingNumbers[i][1] == 0
+ && Math.abs(windingNumbers[i][0]) == 1)
+ solids.add(paths.elementAt(i));
+ }
+ }
+ else
+ {
+ windingRule = PathIterator.WIND_NON_ZERO;
+ for (int i = 0; i < npaths; i++)
+ {
+ if ((windingNumbers[i][0] & 1) == 0)
+ holes.add(paths.elementAt(i));
+ else if ((windingNumbers[i][0] & 1) == 1)
+ solids.add(paths.elementAt(i));
+ }
+ }
+
+ setDirection(holes, false);
+ setDirection(solids, true);
+ this.holes = holes;
+ this.solids = solids;
+ }
+
+ /**
+ * Sets the winding direction of a Vector of paths
+ * @param clockwise gives the direction,
+ * true = clockwise, false = counter-clockwise
+ */
+ private void setDirection(Vector paths, boolean clockwise)
+ {
+ Segment v;
+ for (int i = 0; i < paths.size(); i++)
+ {
+ v = (Segment) paths.elementAt(i);
+ if (clockwise != v.hasClockwiseOrientation())
+ v.reverseAll();
+ }
+ }
+
+ /**
+ * Class representing a linked-list of vertices forming a closed polygon,
+ * convex or concave, without holes.
+ */
+ private abstract class Segment implements Cloneable
+ {
+ // segment type, PathIterator segment types are used.
+ Point2D P1;
+ Point2D P2;
+ Segment next;
+ Segment node;
+
+ Segment()
+ {
+ P1 = P2 = null;
+ node = next = null;
+ }
+
+ /**
+ * Reverses the direction of a single segment
+ */
+ abstract void reverseCoords();
+
+ /**
+ * Returns the segment's midpoint
+ */
+ abstract Point2D getMidPoint();
+
+ /**
+ * Returns the bounding box of this segment
+ */
+ abstract Rectangle2D getBounds();
+
+ /**
+ * Transforms a single segment
+ */
+ abstract void transform(AffineTransform at);
+
+ /**
+ * Returns the PathIterator type of a segment
+ */
+ abstract int getType();
+
+ /**
+ */
+ abstract int splitIntersections(Segment b);
+
+ /**
+ * Returns the PathIterator coords of a segment
+ */
+ abstract int pathIteratorFormat(double[] coords);
+
+ /**
+ * Returns the number of intersections on the positive X axis,
+ * with the origin at (x,y), used for contains()-testing
+ *
+ * (Although that could be done by the line-intersect methods,
+ * a dedicated method is better to guarantee consitent handling
+ * of endpoint-special-cases)
+ */
+ abstract int rayCrossing(double x, double y);
+
+ /**
+ * Subdivides the segment at parametric value t, inserting
+ * the new segment into the linked list after this,
+ * such that this becomes [0,t] and this.next becomes [t,1]
+ */
+ abstract void subdivideInsert(double t);
+
+ /**
+ * Returns twice the area of a curve, relative the P1-P2 line
+ * Used for area calculations.
+ */
+ abstract double curveArea();
+
+ /**
+ * Compare two segments.
+ */
+ abstract boolean equals(Segment b);
+
+ /**
+ * Determines if this path of segments contains the point (x,y)
+ */
+ boolean contains(double x, double y)
+ {
+ Segment v = this;
+ int crossings = 0;
+ do
+ {
+ int n = v.rayCrossing(x, y);
+ crossings += n;
+ v = v.next;
+ }
+ while (v != this);
+ return ((crossings & 1) == 1);
+ }
+
+ /**
+ * Nulls all nodes of the path. Clean up any 'hairs'.
+ */
+ void nullNodes()
+ {
+ Segment v = this;
+ do
+ {
+ v.node = null;
+ v = v.next;
+ }
+ while (v != this);
+ }
+
+ /**
+ * Transforms each segment in the closed path
+ */
+ void transformSegmentList(AffineTransform at)
+ {
+ Segment v = this;
+ do
+ {
+ v.transform(at);
+ v = v.next;
+ }
+ while (v != this);
+ }
+
+ /**
+ * Determines the winding direction of the path
+ * By the sign of the area.
+ */
+ boolean hasClockwiseOrientation()
+ {
+ return (getSignedArea() > 0.0);
+ }
+
+ /**
+ * Returns the bounds of this path
+ */
+ public Rectangle2D getPathBounds()
+ {
+ double xmin;
+ double xmax;
+ double ymin;
+ double ymax;
+ xmin = xmax = P1.getX();
+ ymin = ymax = P1.getY();
+
+ Segment v = this;
+ do
+ {
+ Rectangle2D r = v.getBounds();
+ xmin = Math.min(r.getMinX(), xmin);
+ ymin = Math.min(r.getMinY(), ymin);
+ xmax = Math.max(r.getMaxX(), xmax);
+ ymax = Math.max(r.getMaxY(), ymax);
+ v = v.next;
+ }
+ while (v != this);
+
+ return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin)));
+ }
+
+ /**
+ * Calculates twice the signed area of the path;
+ */
+ double getSignedArea()
+ {
+ Segment s;
+ double area = 0.0;
+
+ s = this;
+ do
+ {
+ area += s.curveArea();
+
+ area += s.P1.getX() * s.next.P1.getY()
+ - s.P1.getY() * s.next.P1.getX();
+ s = s.next;
+ }
+ while (s != this);
+
+ return area;
+ }
+
+ /**
+ * Reverses the orientation of the whole polygon
+ */
+ void reverseAll()
+ {
+ reverseCoords();
+ Segment v = next;
+ Segment former = this;
+ while (v != this)
+ {
+ v.reverseCoords();
+ Segment vnext = v.next;
+ v.next = former;
+ former = v;
+ v = vnext;
+ }
+ next = former;
+ }
+
+ /**
+ * Inserts a Segment after this one
+ */
+ void insert(Segment v)
+ {
+ Segment n = next;
+ next = v;
+ v.next = n;
+ }
+
+ /**
+ * Returns if this segment path is polygonal
+ */
+ boolean isPolygonal()
+ {
+ Segment v = this;
+ do
+ {
+ if (! (v instanceof LineSegment))
+ return false;
+ v = v.next;
+ }
+ while (v != this);
+ return true;
+ }
+
+ /**
+ * Clones this path
+ */
+ Segment cloneSegmentList() throws CloneNotSupportedException
+ {
+ Vector list = new Vector();
+ Segment v = next;
+
+ while (v != this)
+ {
+ list.add(v);
+ v = v.next;
+ }
+
+ Segment clone = (Segment) this.clone();
+ v = clone;
+ for (int i = 0; i < list.size(); i++)
+ {
+ clone.next = (Segment) ((Segment) list.elementAt(i)).clone();
+ clone = clone.next;
+ }
+ clone.next = v;
+ return v;
+ }
+
+ /**
+ * Creates a node between this segment and segment b
+ * at the given intersection
+ * @return the number of nodes created (0 or 1)
+ */
+ int createNode(Segment b, Intersection i)
+ {
+ Point2D p = i.p;
+ if ((pointEquals(P1, p) || pointEquals(P2, p))
+ && (pointEquals(b.P1, p) || pointEquals(b.P2, p)))
+ return 0;
+
+ subdivideInsert(i.ta);
+ b.subdivideInsert(i.tb);
+
+ // snap points
+ b.P2 = b.next.P1 = P2 = next.P1 = i.p;
+
+ node = b.next;
+ b.node = next;
+ return 1;
+ }
+
+ /**
+ * Creates multiple nodes from a list of intersections,
+ * This must be done in the order of ascending parameters,
+ * and the parameters must be recalculated in accordance
+ * with each split.
+ * @return the number of nodes created
+ */
+ protected int createNodes(Segment b, Intersection[] x)
+ {
+ Vector v = new Vector();
+ for (int i = 0; i < x.length; i++)
+ {
+ Point2D p = x[i].p;
+ if (! ((pointEquals(P1, p) || pointEquals(P2, p))
+ && (pointEquals(b.P1, p) || pointEquals(b.P2, p))))
+ v.add(x[i]);
+ }
+
+ int nNodes = v.size();
+ Intersection[] A = new Intersection[nNodes];
+ Intersection[] B = new Intersection[nNodes];
+ for (int i = 0; i < nNodes; i++)
+ A[i] = B[i] = (Intersection) v.elementAt(i);
+
+ // Create two lists sorted by the parameter
+ // Bubble sort, OK I suppose, since the number of intersections
+ // cannot be larger than 9 (cubic-cubic worst case) anyway
+ for (int i = 0; i < nNodes - 1; i++)
+ {
+ for (int j = i + 1; j < nNodes; j++)
+ {
+ if (A[i].ta > A[j].ta)
+ {
+ Intersection swap = A[i];
+ A[i] = A[j];
+ A[j] = swap;
+ }
+ if (B[i].tb > B[j].tb)
+ {
+ Intersection swap = B[i];
+ B[i] = B[j];
+ B[j] = swap;
+ }
+ }
+ }
+ // subdivide a
+ Segment s = this;
+ for (int i = 0; i < nNodes; i++)
+ {
+ s.subdivideInsert(A[i].ta);
+
+ // renormalize the parameters
+ for (int j = i + 1; j < nNodes; j++)
+ A[j].ta = (A[j].ta - A[i].ta) / (1.0 - A[i].ta);
+
+ A[i].seg = s;
+ s = s.next;
+ }
+
+ // subdivide b, set nodes
+ s = b;
+ for (int i = 0; i < nNodes; i++)
+ {
+ s.subdivideInsert(B[i].tb);
+
+ for (int j = i + 1; j < nNodes; j++)
+ B[j].tb = (B[j].tb - B[i].tb) / (1.0 - B[i].tb);
+
+ // set nodes
+ B[i].seg.node = s.next; // node a -> b
+ s.node = B[i].seg.next; // node b -> a
+
+ // snap points
+ B[i].seg.P2 = B[i].seg.next.P1 = s.P2 = s.next.P1 = B[i].p;
+ s = s.next;
+ }
+ return nNodes;
+ }
+
+ /**
+ * Determines if two paths are equal.
+ * Colinear line segments are ignored in the comparison.
+ */
+ boolean pathEquals(Segment B)
+ {
+ if (! getPathBounds().equals(B.getPathBounds()))
+ return false;
+
+ Segment startA = getTopLeft();
+ Segment startB = B.getTopLeft();
+ Segment a = startA;
+ Segment b = startB;
+ do
+ {
+ if (! a.equals(b))
+ return false;
+
+ if (a instanceof LineSegment)
+ a = ((LineSegment) a).lastCoLinear();
+ if (b instanceof LineSegment)
+ b = ((LineSegment) b).lastCoLinear();
+
+ a = a.next;
+ b = b.next;
+ }
+ while (a != startA && b != startB);
+ return true;
+ }
+
+ /**
+ * Return the segment with the top-leftmost first point
+ */
+ Segment getTopLeft()
+ {
+ Segment v = this;
+ Segment tl = this;
+ do
+ {
+ if (v.P1.getY() < tl.P1.getY())
+ tl = v;
+ else if (v.P1.getY() == tl.P1.getY())
+ {
+ if (v.P1.getX() < tl.P1.getX())
+ tl = v;
+ }
+ v = v.next;
+ }
+ while (v != this);
+ return tl;
+ }
+
+ /**
+ * Returns if the path has a segment outside a shape
+ */
+ boolean isSegmentOutside(Shape shape)
+ {
+ return ! shape.contains(getMidPoint());
+ }
+ } // class Segment
+
+ private class LineSegment extends Segment
+ {
+ public LineSegment(double x1, double y1, double x2, double y2)
+ {
+ super();
+ P1 = new Point2D.Double(x1, y1);
+ P2 = new Point2D.Double(x2, y2);
+ }
+
+ public LineSegment(Point2D p1, Point2D p2)
+ {
+ super();
+ P1 = (Point2D) p1.clone();
+ P2 = (Point2D) p2.clone();
+ }
+
+ /**
+ * Clones this segment
+ */
+ public Object clone()
+ {
+ return new LineSegment(P1, P2);
+ }
+
+ /**
+ * Transforms the segment
+ */
+ void transform(AffineTransform at)
+ {
+ P1 = at.transform(P1, null);
+ P2 = at.transform(P2, null);
+ }
+
+ /**
+ * Swap start and end points
+ */
+ void reverseCoords()
+ {
+ Point2D p = P1;
+ P1 = P2;
+ P2 = p;
+ }
+
+ /**
+ * Returns the segment's midpoint
+ */
+ Point2D getMidPoint()
+ {
+ return (new Point2D.Double(0.5 * (P1.getX() + P2.getX()),
+ 0.5 * (P1.getY() + P2.getY())));
+ }
+
+ /**
+ * Returns twice the area of a curve, relative the P1-P2 line
+ * Obviously, a line does not enclose any area besides the line
+ */
+ double curveArea()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns the PathIterator type of a segment
+ */
+ int getType()
+ {
+ return (PathIterator.SEG_LINETO);
+ }
+
+ /**
+ * Subdivides the segment at parametric value t, inserting
+ * the new segment into the linked list after this,
+ * such that this becomes [0,t] and this.next becomes [t,1]
+ */
+ void subdivideInsert(double t)
+ {
+ Point2D p = new Point2D.Double((P2.getX() - P1.getX()) * t + P1.getX(),
+ (P2.getY() - P1.getY()) * t + P1.getY());
+ insert(new LineSegment(p, P2));
+ P2 = p;
+ next.node = node;
+ node = null;
+ }
+
+ /**
+ * Determines if two line segments are strictly colinear
+ */
+ boolean isCoLinear(LineSegment b)
+ {
+ double x1 = P1.getX();
+ double y1 = P1.getY();
+ double x2 = P2.getX();
+ double y2 = P2.getY();
+ double x3 = b.P1.getX();
+ double y3 = b.P1.getY();
+ double x4 = b.P2.getX();
+ double y4 = b.P2.getY();
+
+ if ((y1 - y3) * (x4 - x3) - (x1 - x3) * (y4 - y3) != 0.0)
+ return false;
+
+ return ((x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3) == 0.0);
+ }
+
+ /**
+ * Return the last segment colinear with this one.
+ * Used in comparing paths.
+ */
+ Segment lastCoLinear()
+ {
+ Segment prev = this;
+ Segment v = next;
+
+ while (v instanceof LineSegment)
+ {
+ if (isCoLinear((LineSegment) v))
+ {
+ prev = v;
+ v = v.next;
+ }
+ else
+ return prev;
+ }
+ return prev;
+ }
+
+ /**
+ * Compare two segments.
+ * We must take into account that the lines may be broken into colinear
+ * subsegments and ignore them.
+ */
+ boolean equals(Segment b)
+ {
+ if (! (b instanceof LineSegment))
+ return false;
+ Point2D p1 = P1;
+ Point2D p3 = b.P1;
+
+ if (! p1.equals(p3))
+ return false;
+
+ Point2D p2 = lastCoLinear().P2;
+ Point2D p4 = ((LineSegment) b).lastCoLinear().P2;
+ return (p2.equals(p4));
+ }
+
+ /**
+ * Returns a line segment
+ */
+ int pathIteratorFormat(double[] coords)
+ {
+ coords[0] = P2.getX();
+ coords[1] = P2.getY();
+ return (PathIterator.SEG_LINETO);
+ }
+
+ /**
+ * Returns if the line has intersections.
+ */
+ boolean hasIntersections(Segment b)
+ {
+ if (b instanceof LineSegment)
+ return (linesIntersect(this, (LineSegment) b) != null);
+
+ if (b instanceof QuadSegment)
+ return (lineQuadIntersect(this, (QuadSegment) b) != null);
+
+ if (b instanceof CubicSegment)
+ return (lineCubicIntersect(this, (CubicSegment) b) != null);
+
+ return false;
+ }
+
+ /**
+ * Splits intersections into nodes,
+ * This one handles line-line, line-quadratic, line-cubic
+ */
+ int splitIntersections(Segment b)
+ {
+ if (b instanceof LineSegment)
+ {
+ Intersection i = linesIntersect(this, (LineSegment) b);
+
+ if (i == null)
+ return 0;
+
+ return createNode(b, i);
+ }
+
+ Intersection[] x = null;
+
+ if (b instanceof QuadSegment)
+ x = lineQuadIntersect(this, (QuadSegment) b);
+
+ if (b instanceof CubicSegment)
+ x = lineCubicIntersect(this, (CubicSegment) b);
+
+ if (x == null)
+ return 0;
+
+ if (x.length == 1)
+ return createNode(b, (Intersection) x[0]);
+
+ return createNodes(b, x);
+ }
+
+ /**
+ * Returns the bounding box of this segment
+ */
+ Rectangle2D getBounds()
+ {
+ return (new Rectangle2D.Double(Math.min(P1.getX(), P2.getX()),
+ Math.min(P1.getY(), P2.getY()),
+ Math.abs(P1.getX() - P2.getX()),
+ Math.abs(P1.getY() - P2.getY())));
+ }
+
+ /**
+ * Returns the number of intersections on the positive X axis,
+ * with the origin at (x,y), used for contains()-testing
+ */
+ int rayCrossing(double x, double y)
+ {
+ double x0 = P1.getX() - x;
+ double y0 = P1.getY() - y;
+ double x1 = P2.getX() - x;
+ double y1 = P2.getY() - y;
+
+ if (y0 * y1 > 0)
+ return 0;
+
+ if (x0 < 0 && x1 < 0)
+ return 0;
+
+ if (y0 == 0.0)
+ y0 -= EPSILON;
+
+ if (y1 == 0.0)
+ y1 -= EPSILON;
+
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ EPSILON, 0.0, Double.MAX_VALUE, 0.0))
+ return 1;
+ return 0;
+ }
+ } // class LineSegment
+
+ /**
+ * Quadratic Bezier curve segment
+ *
+ * Note: Most peers don't support quadratics directly, so it might make
+ * sense to represent them as cubics internally and just be done with it.
+ * I think we should be peer-agnostic, however, and stay faithful to the
+ * input geometry types as far as possible.
+ */
+ private class QuadSegment extends Segment
+ {
+ Point2D cp; // control point
+
+ /**
+ * Constructor, takes the coordinates of the start, control,
+ * and end point, respectively.
+ */
+ QuadSegment(double x1, double y1, double cx, double cy, double x2,
+ double y2)
+ {
+ super();
+ P1 = new Point2D.Double(x1, y1);
+ P2 = new Point2D.Double(x2, y2);
+ cp = new Point2D.Double(cx, cy);
+ }
+
+ /**
+ * Clones this segment
+ */
+ public Object clone()
+ {
+ return new QuadSegment(P1.getX(), P1.getY(), cp.getX(), cp.getY(),
+ P2.getX(), P2.getY());
+ }
+
+ /**
+ * Returns twice the area of a curve, relative the P1-P2 line
+ *
+ * The area formula can be derived by using Green's formula in the
+ * plane on the parametric form of the bezier.
+ */
+ double curveArea()
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp.getX();
+ double y1 = cp.getY();
+ double x2 = P2.getX();
+ double y2 = P2.getY();
+
+ double P = (y2 - 2 * y1 + y0);
+ double Q = 2 * (y1 - y0);
+
+ double A = (x2 - 2 * x1 + x0);
+ double B = 2 * (x1 - x0);
+
+ double area = (B * P - A * Q) / 3.0;
+ return (area);
+ }
+
+ /**
+ * Compare two segments.
+ */
+ boolean equals(Segment b)
+ {
+ if (! (b instanceof QuadSegment))
+ return false;
+
+ return (P1.equals(b.P1) && cp.equals(((QuadSegment) b).cp)
+ && P2.equals(b.P2));
+ }
+
+ /**
+ * Returns a Point2D corresponding to the parametric value t
+ * of the curve
+ */
+ Point2D evaluatePoint(double t)
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp.getX();
+ double y1 = cp.getY();
+ double x2 = P2.getX();
+ double y2 = P2.getY();
+
+ return new Point2D.Double(t * t * (x2 - 2 * x1 + x0) + 2 * t * (x1 - x0)
+ + x0,
+ t * t * (y2 - 2 * y1 + y0) + 2 * t * (y1 - y0)
+ + y0);
+ }
+
+ /**
+ * Returns the bounding box of this segment
+ */
+ Rectangle2D getBounds()
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp.getX();
+ double y1 = cp.getY();
+ double x2 = P2.getX();
+ double y2 = P2.getY();
+ double r0;
+ double r1;
+
+ double xmax = Math.max(x0, x2);
+ double ymax = Math.max(y0, y2);
+ double xmin = Math.min(x0, x2);
+ double ymin = Math.min(y0, y2);
+
+ r0 = 2 * (y1 - y0);
+ r1 = 2 * (y2 - 2 * y1 + y0);
+ if (r1 != 0.0)
+ {
+ double t = -r0 / r1;
+ if (t > 0.0 && t < 1.0)
+ {
+ double y = evaluatePoint(t).getY();
+ ymax = Math.max(y, ymax);
+ ymin = Math.min(y, ymin);
+ }
+ }
+ r0 = 2 * (x1 - x0);
+ r1 = 2 * (x2 - 2 * x1 + x0);
+ if (r1 != 0.0)
+ {
+ double t = -r0 / r1;
+ if (t > 0.0 && t < 1.0)
+ {
+ double x = evaluatePoint(t).getY();
+ xmax = Math.max(x, xmax);
+ xmin = Math.min(x, xmin);
+ }
+ }
+
+ return (new Rectangle2D.Double(xmin, ymin, xmax - xmin, ymax - ymin));
+ }
+
+ /**
+ * Returns a cubic segment corresponding to this curve
+ */
+ CubicSegment getCubicSegment()
+ {
+ double x1 = P1.getX() + 2.0 * (cp.getX() - P1.getX()) / 3.0;
+ double y1 = P1.getY() + 2.0 * (cp.getY() - P1.getY()) / 3.0;
+ double x2 = cp.getX() + (P2.getX() - cp.getX()) / 3.0;
+ double y2 = cp.getY() + (P2.getY() - cp.getY()) / 3.0;
+
+ return new CubicSegment(P1.getX(), P1.getY(), x1, y1, x2, y2, P2.getX(),
+ P2.getY());
+ }
+
+ /**
+ * Returns the segment's midpoint
+ */
+ Point2D getMidPoint()
+ {
+ return evaluatePoint(0.5);
+ }
+
+ /**
+ * Returns the PathIterator type of a segment
+ */
+ int getType()
+ {
+ return (PathIterator.SEG_QUADTO);
+ }
+
+ /**
+ * Returns the PathIterator coords of a segment
+ */
+ int pathIteratorFormat(double[] coords)
+ {
+ coords[0] = cp.getX();
+ coords[1] = cp.getY();
+ coords[2] = P2.getX();
+ coords[3] = P2.getY();
+ return (PathIterator.SEG_QUADTO);
+ }
+
+ /**
+ * Returns the number of intersections on the positive X axis,
+ * with the origin at (x,y), used for contains()-testing
+ */
+ int rayCrossing(double x, double y)
+ {
+ double x0 = P1.getX() - x;
+ double y0 = P1.getY() - y;
+ double x1 = cp.getX() - x;
+ double y1 = cp.getY() - y;
+ double x2 = P2.getX() - x;
+ double y2 = P2.getY() - y;
+ double[] r = new double[3];
+ int nRoots;
+ int nCrossings = 0;
+
+ /* check if curve may intersect X+ axis. */
+ if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0) && (y0 * y1 <= 0 || y1 * y2 <= 0))
+ {
+ if (y0 == 0.0)
+ y0 -= EPSILON;
+ if (y2 == 0.0)
+ y2 -= EPSILON;
+
+ r[0] = y0;
+ r[1] = 2 * (y1 - y0);
+ r[2] = (y2 - 2 * y1 + y0);
+
+ nRoots = QuadCurve2D.solveQuadratic(r);
+ for (int i = 0; i < nRoots; i++)
+ if (r[i] > 0.0f && r[i] < 1.0f)
+ {
+ double t = r[i];
+ if (t * t * (x2 - 2 * x1 + x0) + 2 * t * (x1 - x0) + x0 > 0.0)
+ nCrossings++;
+ }
+ }
+ return nCrossings;
+ }
+
+ /**
+ * Swap start and end points
+ */
+ void reverseCoords()
+ {
+ Point2D temp = P1;
+ P1 = P2;
+ P2 = temp;
+ }
+
+ /**
+ * Splits intersections into nodes,
+ * This one handles quadratic-quadratic only,
+ * Quadratic-line is passed on to the LineSegment class,
+ * Quadratic-cubic is passed on to the CubicSegment class
+ */
+ int splitIntersections(Segment b)
+ {
+ if (b instanceof LineSegment)
+ return (b.splitIntersections(this));
+
+ if (b instanceof CubicSegment)
+ return (b.splitIntersections(this));
+
+ if (b instanceof QuadSegment)
+ {
+ // Use the cubic-cubic intersection routine for quads as well,
+ // Since a quadratic can be exactly described as a cubic, this
+ // should not be a problem;
+ // The recursion depth will be the same in any case.
+ Intersection[] x = cubicCubicIntersect(getCubicSegment(),
+ ((QuadSegment) b)
+ .getCubicSegment());
+ if (x == null)
+ return 0;
+
+ if (x.length == 1)
+ return createNode(b, (Intersection) x[0]);
+
+ return createNodes(b, x);
+ }
+ return 0;
+ }
+
+ /**
+ * Subdivides the segment at parametric value t, inserting
+ * the new segment into the linked list after this,
+ * such that this becomes [0,t] and this.next becomes [t,1]
+ */
+ void subdivideInsert(double t)
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp.getX();
+ double y1 = cp.getY();
+ double x2 = P2.getX();
+ double y2 = P2.getY();
+
+ double p10x = x0 + t * (x1 - x0);
+ double p10y = y0 + t * (y1 - y0);
+ double p11x = x1 + t * (x2 - x1);
+ double p11y = y1 + t * (y2 - y1);
+ double p20x = p10x + t * (p11x - p10x);
+ double p20y = p10y + t * (p11y - p10y);
+
+ insert(new QuadSegment(p20x, p20y, p11x, p11y, x2, y2));
+ P2 = next.P1;
+ cp.setLocation(p10x, p10y);
+
+ next.node = node;
+ node = null;
+ }
+
+ /**
+ * Transforms the segment
+ */
+ void transform(AffineTransform at)
+ {
+ P1 = at.transform(P1, null);
+ P2 = at.transform(P2, null);
+ cp = at.transform(cp, null);
+ }
+ } // class QuadSegment
+
+ /**
+ * Cubic Bezier curve segment
+ */
+ private class CubicSegment extends Segment
+ {
+ Point2D cp1; // control points
+ Point2D cp2; // control points
+
+ /**
+ * Constructor - takes coordinates of the starting point,
+ * first control point, second control point and end point,
+ * respecively.
+ */
+ public CubicSegment(double x1, double y1, double c1x, double c1y,
+ double c2x, double c2y, double x2, double y2)
+ {
+ super();
+ P1 = new Point2D.Double(x1, y1);
+ P2 = new Point2D.Double(x2, y2);
+ cp1 = new Point2D.Double(c1x, c1y);
+ cp2 = new Point2D.Double(c2x, c2y);
+ }
+
+ /**
+ * Clones this segment
+ */
+ public Object clone()
+ {
+ return new CubicSegment(P1.getX(), P1.getY(), cp1.getX(), cp1.getY(),
+ cp2.getX(), cp2.getY(), P2.getX(), P2.getY());
+ }
+
+ /**
+ * Returns twice the area of a curve, relative the P1-P2 line
+ *
+ * The area formula can be derived by using Green's formula in the
+ * plane on the parametric form of the bezier.
+ */
+ double curveArea()
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp1.getX();
+ double y1 = cp1.getY();
+ double x2 = cp2.getX();
+ double y2 = cp2.getY();
+ double x3 = P2.getX();
+ double y3 = P2.getY();
+
+ double P = y3 - 3 * y2 + 3 * y1 - y0;
+ double Q = 3 * (y2 + y0 - 2 * y1);
+ double R = 3 * (y1 - y0);
+
+ double A = x3 - 3 * x2 + 3 * x1 - x0;
+ double B = 3 * (x2 + x0 - 2 * x1);
+ double C = 3 * (x1 - x0);
+
+ double area = (B * P - A * Q) / 5.0 + (C * P - A * R) / 2.0
+ + (C * Q - B * R) / 3.0;
+
+ return (area);
+ }
+
+ /**
+ * Compare two segments.
+ */
+ boolean equals(Segment b)
+ {
+ if (! (b instanceof CubicSegment))
+ return false;
+
+ return (P1.equals(b.P1) && cp1.equals(((CubicSegment) b).cp1)
+ && cp2.equals(((CubicSegment) b).cp2) && P2.equals(b.P2));
+ }
+
+ /**
+ * Returns a Point2D corresponding to the parametric value t
+ * of the curve
+ */
+ Point2D evaluatePoint(double t)
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp1.getX();
+ double y1 = cp1.getY();
+ double x2 = cp2.getX();
+ double y2 = cp2.getY();
+ double x3 = P2.getX();
+ double y3 = P2.getY();
+
+ return new Point2D.Double(-(t * t * t) * (x0 - 3 * x1 + 3 * x2 - x3)
+ + 3 * t * t * (x0 - 2 * x1 + x2)
+ + 3 * t * (x1 - x0) + x0,
+ -(t * t * t) * (y0 - 3 * y1 + 3 * y2 - y3)
+ + 3 * t * t * (y0 - 2 * y1 + y2)
+ + 3 * t * (y1 - y0) + y0);
+ }
+
+ /**
+ * Returns the bounding box of this segment
+ */
+ Rectangle2D getBounds()
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp1.getX();
+ double y1 = cp1.getY();
+ double x2 = cp2.getX();
+ double y2 = cp2.getY();
+ double x3 = P2.getX();
+ double y3 = P2.getY();
+ double[] r = new double[3];
+
+ double xmax = Math.max(x0, x3);
+ double ymax = Math.max(y0, y3);
+ double xmin = Math.min(x0, x3);
+ double ymin = Math.min(y0, y3);
+
+ r[0] = 3 * (y1 - y0);
+ r[1] = 6.0 * (y2 + y0 - 2 * y1);
+ r[2] = 3.0 * (y3 - 3 * y2 + 3 * y1 - y0);
+
+ int n = QuadCurve2D.solveQuadratic(r);
+ for (int i = 0; i < n; i++)
+ {
+ double t = r[i];
+ if (t > 0 && t < 1.0)
+ {
+ double y = evaluatePoint(t).getY();
+ ymax = Math.max(y, ymax);
+ ymin = Math.min(y, ymin);
+ }
+ }
+
+ r[0] = 3 * (x1 - x0);
+ r[1] = 6.0 * (x2 + x0 - 2 * x1);
+ r[2] = 3.0 * (x3 - 3 * x2 + 3 * x1 - x0);
+ n = QuadCurve2D.solveQuadratic(r);
+ for (int i = 0; i < n; i++)
+ {
+ double t = r[i];
+ if (t > 0 && t < 1.0)
+ {
+ double x = evaluatePoint(t).getX();
+ xmax = Math.max(x, xmax);
+ xmin = Math.min(x, xmin);
+ }
+ }
+ return (new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin)));
+ }
+
+ /**
+ * Returns a CubicCurve2D object corresponding to this segment.
+ */
+ CubicCurve2D getCubicCurve2D()
+ {
+ return new CubicCurve2D.Double(P1.getX(), P1.getY(), cp1.getX(),
+ cp1.getY(), cp2.getX(), cp2.getY(),
+ P2.getX(), P2.getY());
+ }
+
+ /**
+ * Returns the parametric points of self-intersection if the cubic
+ * is self-intersecting, null otherwise.
+ */
+ double[] getLoop()
+ {
+ double x0 = P1.getX();
+ double y0 = P1.getY();
+ double x1 = cp1.getX();
+ double y1 = cp1.getY();
+ double x2 = cp2.getX();
+ double y2 = cp2.getY();
+ double x3 = P2.getX();
+ double y3 = P2.getY();
+ double[] r = new double[4];
+ double k;
+ double R;
+ double T;
+ double A;
+ double B;
+ double[] results = new double[2];
+
+ R = x3 - 3 * x2 + 3 * x1 - x0;
+ T = y3 - 3 * y2 + 3 * y1 - y0;
+
+ // A qudratic
+ if (R == 0.0 && T == 0.0)
+ return null;
+
+ // true cubic
+ if (R != 0.0 && T != 0.0)
+ {
+ A = 3 * (x2 + x0 - 2 * x1) / R;
+ B = 3 * (x1 - x0) / R;
+
+ double P = 3 * (y2 + y0 - 2 * y1) / T;
+ double Q = 3 * (y1 - y0) / T;
+
+ if (A == P || Q == B)
+ return null;
+
+ k = (Q - B) / (A - P);
+ }
+ else
+ {
+ if (R == 0.0)
+ {
+ // quadratic in x
+ k = -(3 * (x1 - x0)) / (3 * (x2 + x0 - 2 * x1));
+ A = 3 * (y2 + y0 - 2 * y1) / T;
+ B = 3 * (y1 - y0) / T;
+ }
+ else
+ {
+ // quadratic in y
+ k = -(3 * (y1 - y0)) / (3 * (y2 + y0 - 2 * y1));
+ A = 3 * (x2 + x0 - 2 * x1) / R;
+ B = 3 * (x1 - x0) / R;
+ }
+ }
+
+ r[0] = -k * k * k - A * k * k - B * k;
+ r[1] = 3 * k * k + 2 * k * A + 2 * B;
+ r[2] = -3 * k;
+ r[3] = 2;
+
+ int n = CubicCurve2D.solveCubic(r);
+ if (n != 3)
+ return null;
+
+ // sort r
+ double t;
+ for (int i = 0; i < 2; i++)
+ for (int j = i + 1; j < 3; j++)
+ if (r[j] < r[i])
+ {
+ t = r[i];
+ r[i] = r[j];
+ r[j] = t;
+ }
+
+ if (Math.abs(r[0] + r[2] - k) < 1E-13)
+ if (r[0] >= 0.0 && r[0] <= 1.0 && r[2] >= 0.0 && r[2] <= 1.0)
+ if (evaluatePoint(r[0]).distance(evaluatePoint(r[2])) < PE_EPSILON * 10)
+ { // we snap the points anyway
+ results[0] = r[0];
+ results[1] = r[2];
+ return (results);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the segment's midpoint
+ */
+ Point2D getMidPoint()
+ {
+ return evaluatePoint(0.5);
+ }
+
+ /**
+ * Returns the PathIterator type of a segment
+ */
+ int getType()
+ {
+ return (PathIterator.SEG_CUBICTO);
+ }
+
+ /**
+ * Returns the PathIterator coords of a segment
+ */
+ int pathIteratorFormat(double[] coords)
+ {
+ coords[0] = cp1.getX();
+ coords[1] = cp1.getY();
+ coords[2] = cp2.getX();
+ coords[3] = cp2.getY();
+ coords[4] = P2.getX();
+ coords[5] = P2.getY();
+ return (PathIterator.SEG_CUBICTO);
+ }
+
+ /**
+ * Returns the number of intersections on the positive X axis,
+ * with the origin at (x,y), used for contains()-testing
+ */
+ int rayCrossing(double x, double y)
+ {
+ double x0 = P1.getX() - x;
+ double y0 = P1.getY() - y;
+ double x1 = cp1.getX() - x;
+ double y1 = cp1.getY() - y;
+ double x2 = cp2.getX() - x;
+ double y2 = cp2.getY() - y;
+ double x3 = P2.getX() - x;
+ double y3 = P2.getY() - y;
+ double[] r = new double[4];
+ int nRoots;
+ int nCrossings = 0;
+
+ /* check if curve may intersect X+ axis. */
+ if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0 || x3 > 0.0)
+ && (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0))
+ {
+ if (y0 == 0.0)
+ y0 -= EPSILON;
+ if (y3 == 0.0)
+ y3 -= EPSILON;
+
+ r[0] = y0;
+ r[1] = 3 * (y1 - y0);
+ r[2] = 3 * (y2 + y0 - 2 * y1);
+ r[3] = y3 - 3 * y2 + 3 * y1 - y0;
+
+ if ((nRoots = CubicCurve2D.solveCubic(r)) > 0)
+ for (int i = 0; i < nRoots; i++)
+ {
+ if (r[i] > 0.0 && r[i] < 1.0)
+ {
+ double t = r[i];
+ if (-(t * t * t) * (x0 - 3 * x1 + 3 * x2 - x3)
+ + 3 * t * t * (x0 - 2 * x1 + x2) + 3 * t * (x1 - x0)
+ + x0 > 0.0)
+ nCrossings++;
+ }
+ }
+ }
+ return nCrossings;
+ }
+
+ /**
+ * Swap start and end points
+ */
+ void reverseCoords()
+ {
+ Point2D p = P1;
+ P1 = P2;
+ P2 = p;
+ p = cp1; // swap control points
+ cp1 = cp2;
+ cp2 = p;
+ }
+
+ /**
+ * Splits intersections into nodes,
+ * This one handles cubic-cubic and cubic-quadratic intersections
+ */
+ int splitIntersections(Segment b)
+ {
+ if (b instanceof LineSegment)
+ return (b.splitIntersections(this));
+
+ Intersection[] x = null;
+
+ if (b instanceof QuadSegment)
+ x = cubicCubicIntersect(this, ((QuadSegment) b).getCubicSegment());
+
+ if (b instanceof CubicSegment)
+ x = cubicCubicIntersect(this, (CubicSegment) b);
+
+ if (x == null)
+ return 0;
+
+ if (x.length == 1)
+ return createNode(b, x[0]);
+
+ return createNodes(b, x);
+ }
+
+ /**
+ * Subdivides the segment at parametric value t, inserting
+ * the new segment into the linked list after this,
+ * such that this becomes [0,t] and this.next becomes [t,1]
+ */
+ void subdivideInsert(double t)
+ {
+ CubicSegment s = (CubicSegment) clone();
+ double p1x = (s.cp1.getX() - s.P1.getX()) * t + s.P1.getX();
+ double p1y = (s.cp1.getY() - s.P1.getY()) * t + s.P1.getY();
+
+ double px = (s.cp2.getX() - s.cp1.getX()) * t + s.cp1.getX();
+ double py = (s.cp2.getY() - s.cp1.getY()) * t + s.cp1.getY();
+
+ s.cp2.setLocation((s.P2.getX() - s.cp2.getX()) * t + s.cp2.getX(),
+ (s.P2.getY() - s.cp2.getY()) * t + s.cp2.getY());
+
+ s.cp1.setLocation((s.cp2.getX() - px) * t + px,
+ (s.cp2.getY() - py) * t + py);
+
+ double p2x = (px - p1x) * t + p1x;
+ double p2y = (py - p1y) * t + p1y;
+
+ double p3x = (s.cp1.getX() - p2x) * t + p2x;
+ double p3y = (s.cp1.getY() - p2y) * t + p2y;
+ s.P1.setLocation(p3x, p3y);
+
+ // insert new curve
+ insert(s);
+
+ // set this curve
+ cp1.setLocation(p1x, p1y);
+ cp2.setLocation(p2x, p2y);
+ P2 = s.P1;
+ next.node = node;
+ node = null;
+ }
+
+ /**
+ * Transforms the segment
+ */
+ void transform(AffineTransform at)
+ {
+ P1 = at.transform(P1, null);
+ P2 = at.transform(P2, null);
+ cp1 = at.transform(cp1, null);
+ cp2 = at.transform(cp2, null);
+ }
+ } // class CubicSegment
+} // class Area
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/CubicCurve2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/CubicCurve2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/CubicCurve2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/CubicCurve2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1724 @@
+/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space
+ Copyright (C) 2002, 2003, 2004 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.util.NoSuchElementException;
+
+
+/**
+ * A two-dimensional curve that is parameterized with a cubic
+ * function.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Graydon Hoare (graydon at redhat.com)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * @author Sven de Marothy (sven at physto.se)
+ *
+ * @since 1.2
+ */
+public abstract class CubicCurve2D implements Shape, Cloneable
+{
+ private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
+
+ /**
+ * Constructs a new CubicCurve2D. Typical users will want to
+ * construct instances of a subclass, such as {@link
+ * CubicCurve2D.Float} or {@link CubicCurve2D.Double}.
+ */
+ protected CubicCurve2D()
+ {
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public abstract double getX1();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public abstract double getY1();
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public abstract Point2D getP1();
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s first
+ * control point.
+ */
+ public abstract double getCtrlX1();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s first
+ * control point.
+ */
+ public abstract double getCtrlY1();
+
+ /**
+ * Returns the curve’s first control point.
+ */
+ public abstract Point2D getCtrlP1();
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s second
+ * control point.
+ */
+ public abstract double getCtrlX2();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s second
+ * control point.
+ */
+ public abstract double getCtrlY2();
+
+ /**
+ * Returns the curve’s second control point.
+ */
+ public abstract Point2D getCtrlP2();
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public abstract double getX2();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public abstract double getY2();
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public abstract Point2D getP2();
+
+ /**
+ * Changes the curve geometry, separately specifying each coordinate
+ * value.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new end
+ * point.
+ */
+ public abstract void setCurve(double x1, double y1, double cx1, double cy1,
+ double cx2, double cy2, double x2, double y2);
+
+ /**
+ * Changes the curve geometry, specifying coordinate values in an
+ * array.
+ *
+ * @param coords an array containing the new coordinate values. The
+ * <i>x</i> coordinate of the new start point is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * new first control point is located at <code>coords[offset +
+ * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 3]</code>. The <i>x</i> coordinate of the new second control
+ * point is located at <code>coords[offset + 4]</code>, its <i>y</i>
+ * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>
+ * coordinate of the new end point is located at <code>coords[offset
+ * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 7]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public void setCurve(double[] coords, int offset)
+ {
+ setCurve(coords[offset++], coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++]);
+ }
+
+ /**
+ * Changes the curve geometry, specifying coordinate values in
+ * separate Point objects.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * <p>The curve does not keep any reference to the passed point
+ * objects. Therefore, a later change to <code>p1</code>,
+ * <code>c1</code>, <code>c2</code> or <code>p2</code> will not
+ * affect the curve geometry.
+ *
+ * @param p1 the new start point.
+ * @param c1 the new first control point.
+ * @param c2 the new second control point.
+ * @param p2 the new end point.
+ */
+ public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2)
+ {
+ setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(), c2.getX(), c2.getY(),
+ p2.getX(), p2.getY());
+ }
+
+ /**
+ * Changes the curve geometry, specifying coordinate values in an
+ * array of Point objects.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * <p>The curve does not keep references to the passed point
+ * objects. Therefore, a later change to the <code>pts</code> array
+ * or any of its elements will not affect the curve geometry.
+ *
+ * @param pts an array containing the points. The new start point
+ * is located at <code>pts[offset]</code>, the new first control
+ * point at <code>pts[offset + 1]</code>, the new second control
+ * point at <code>pts[offset + 2]</code>, and the new end point
+ * at <code>pts[offset + 3]</code>.
+ *
+ * @param offset the offset of the start point in <code>pts</code>.
+ */
+ public void setCurve(Point2D[] pts, int offset)
+ {
+ setCurve(pts[offset].getX(), pts[offset++].getY(), pts[offset].getX(),
+ pts[offset++].getY(), pts[offset].getX(), pts[offset++].getY(),
+ pts[offset].getX(), pts[offset++].getY());
+ }
+
+ /**
+ * Changes the curve geometry to that of another curve.
+ *
+ * @param c the curve whose coordinates will be copied.
+ */
+ public void setCurve(CubicCurve2D c)
+ {
+ setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(),
+ c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2());
+ }
+
+ /**
+ * Calculates the squared flatness of a cubic curve, directly
+ * specifying each coordinate value. The flatness is the maximal
+ * distance of a control point to the line between start and end
+ * point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the square of the distance between C2 and the
+ * gray line, i.e. the squared length of the red line.
+ *
+ * @param x1 the <i>x</i> coordinate of the start point P1.
+ * @param y1 the <i>y</i> coordinate of the start point P1.
+ * @param cx1 the <i>x</i> coordinate of the first control point C1.
+ * @param cy1 the <i>y</i> coordinate of the first control point C1.
+ * @param cx2 the <i>x</i> coordinate of the second control point C2.
+ * @param cy2 the <i>y</i> coordinate of the second control point C2.
+ * @param x2 the <i>x</i> coordinate of the end point P2.
+ * @param y2 the <i>y</i> coordinate of the end point P2.
+ */
+ public static double getFlatnessSq(double x1, double y1, double cx1,
+ double cy1, double cx2, double cy2,
+ double x2, double y2)
+ {
+ return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1),
+ Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2));
+ }
+
+ /**
+ * Calculates the flatness of a cubic curve, directly specifying
+ * each coordinate value. The flatness is the maximal distance of a
+ * control point to the line between start and end point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the distance between C2 and the gray line,
+ * i.e. the length of the red line.
+ *
+ * @param x1 the <i>x</i> coordinate of the start point P1.
+ * @param y1 the <i>y</i> coordinate of the start point P1.
+ * @param cx1 the <i>x</i> coordinate of the first control point C1.
+ * @param cy1 the <i>y</i> coordinate of the first control point C1.
+ * @param cx2 the <i>x</i> coordinate of the second control point C2.
+ * @param cy2 the <i>y</i> coordinate of the second control point C2.
+ * @param x2 the <i>x</i> coordinate of the end point P2.
+ * @param y2 the <i>y</i> coordinate of the end point P2.
+ */
+ public static double getFlatness(double x1, double y1, double cx1,
+ double cy1, double cx2, double cy2,
+ double x2, double y2)
+ {
+ return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2));
+ }
+
+ /**
+ * Calculates the squared flatness of a cubic curve, specifying the
+ * coordinate values in an array. The flatness is the maximal
+ * distance of a control point to the line between start and end
+ * point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the square of the distance between C2 and the
+ * gray line, i.e. the squared length of the red line.
+ *
+ * @param coords an array containing the coordinate values. The
+ * <i>x</i> coordinate of the start point P1 is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * first control point C1 is located at <code>coords[offset +
+ * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 3]</code>. The <i>x</i> coordinate of the second control point C2
+ * is located at <code>coords[offset + 4]</code>, its <i>y</i>
+ * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>
+ * coordinate of the end point P2 is located at <code>coords[offset
+ * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 7]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public static double getFlatnessSq(double[] coords, int offset)
+ {
+ return getFlatnessSq(coords[offset++], coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++]);
+ }
+
+ /**
+ * Calculates the flatness of a cubic curve, specifying the
+ * coordinate values in an array. The flatness is the maximal
+ * distance of a control point to the line between start and end
+ * point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the distance between C2 and the gray line,
+ * i.e. the length of the red line.
+ *
+ * @param coords an array containing the coordinate values. The
+ * <i>x</i> coordinate of the start point P1 is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * first control point C1 is located at <code>coords[offset +
+ * 2]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 3]</code>. The <i>x</i> coordinate of the second control point C2
+ * is located at <code>coords[offset + 4]</code>, its <i>y</i>
+ * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>
+ * coordinate of the end point P2 is located at <code>coords[offset
+ * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +
+ * 7]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public static double getFlatness(double[] coords, int offset)
+ {
+ return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++]));
+ }
+
+ /**
+ * Calculates the squared flatness of this curve. The flatness is
+ * the maximal distance of a control point to the line between start
+ * and end point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the square of the distance between C2 and the
+ * gray line, i.e. the squared length of the red line.
+ */
+ public double getFlatnessSq()
+ {
+ return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),
+ getCtrlX2(), getCtrlY2(), getX2(), getY2());
+ }
+
+ /**
+ * Calculates the flatness of this curve. The flatness is the
+ * maximal distance of a control point to the line between start and
+ * end point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. In comparison to C1,
+ * control point C2 is father away from the gray line. Therefore,
+ * the result will be the distance between C2 and the gray line,
+ * i.e. the length of the red line.
+ */
+ public double getFlatness()
+ {
+ return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),
+ getCtrlX2(), getCtrlY2(), getX2(), getY2()));
+ }
+
+ /**
+ * Subdivides this curve into two halves.
+ *
+ * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a CubicCurve2D" />
+ *
+ * @param left a curve whose geometry will be set to the left half
+ * of this curve, or <code>null</code> if the caller is not
+ * interested in the left half.
+ *
+ * @param right a curve whose geometry will be set to the right half
+ * of this curve, or <code>null</code> if the caller is not
+ * interested in the right half.
+ */
+ public void subdivide(CubicCurve2D left, CubicCurve2D right)
+ {
+ // Use empty slots at end to share single array.
+ double[] d = new double[]
+ {
+ getX1(), getY1(), getCtrlX1(), getCtrlY1(), getCtrlX2(),
+ getCtrlY2(), getX2(), getY2(), 0, 0, 0, 0, 0, 0
+ };
+ subdivide(d, 0, d, 0, d, 6);
+ if (left != null)
+ left.setCurve(d, 0);
+ if (right != null)
+ right.setCurve(d, 6);
+ }
+
+ /**
+ * Subdivides a cubic curve into two halves.
+ *
+ * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a CubicCurve2D" />
+ *
+ * @param src the curve to be subdivided.
+ *
+ * @param left a curve whose geometry will be set to the left half
+ * of <code>src</code>, or <code>null</code> if the caller is not
+ * interested in the left half.
+ *
+ * @param right a curve whose geometry will be set to the right half
+ * of <code>src</code>, or <code>null</code> if the caller is not
+ * interested in the right half.
+ */
+ public static void subdivide(CubicCurve2D src, CubicCurve2D left,
+ CubicCurve2D right)
+ {
+ src.subdivide(left, right);
+ }
+
+ /**
+ * Subdivides a cubic curve into two halves, passing all coordinates
+ * in an array.
+ *
+ * <p><img src="doc-files/CubicCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a CubicCurve2D" />
+ *
+ * <p>The left end point and the right start point will always be
+ * identical. Memory-concious programmers thus may want to pass the
+ * same array for both <code>left</code> and <code>right</code>, and
+ * set <code>rightOff</code> to <code>leftOff + 6</code>.
+ *
+ * @param src an array containing the coordinates of the curve to be
+ * subdivided. The <i>x</i> coordinate of the start point P1 is
+ * located at <code>src[srcOff]</code>, its <i>y</i> at
+ * <code>src[srcOff + 1]</code>. The <i>x</i> coordinate of the
+ * first control point C1 is located at <code>src[srcOff +
+ * 2]</code>, its <i>y</i> at <code>src[srcOff + 3]</code>. The
+ * <i>x</i> coordinate of the second control point C2 is located at
+ * <code>src[srcOff + 4]</code>, its <i>y</i> at <code>src[srcOff +
+ * 5]</code>. The <i>x</i> coordinate of the end point is located at
+ * <code>src[srcOff + 6]</code>, its <i>y</i> at <code>src[srcOff +
+ * 7]</code>.
+ *
+ * @param srcOff an offset into <code>src</code>, specifying
+ * the index of the start point’s <i>x</i> coordinate.
+ *
+ * @param left an array that will receive the coordinates of the
+ * left half of <code>src</code>. It is acceptable to pass
+ * <code>src</code>. A caller who is not interested in the left half
+ * can pass <code>null</code>.
+ *
+ * @param leftOff an offset into <code>left</code>, specifying the
+ * index where the start point’s <i>x</i> coordinate will be
+ * stored.
+ *
+ * @param right an array that will receive the coordinates of the
+ * right half of <code>src</code>. It is acceptable to pass
+ * <code>src</code> or <code>left</code>. A caller who is not
+ * interested in the right half can pass <code>null</code>.
+ *
+ * @param rightOff an offset into <code>right</code>, specifying the
+ * index where the start point’s <i>x</i> coordinate will be
+ * stored.
+ */
+ public static void subdivide(double[] src, int srcOff, double[] left,
+ int leftOff, double[] right, int rightOff)
+ {
+ // To understand this code, please have a look at the image
+ // "CubicCurve2D-3.png" in the sub-directory "doc-files".
+ double src_C1_x;
+ double src_C1_y;
+ double src_C2_x;
+ double src_C2_y;
+ double left_P1_x;
+ double left_P1_y;
+ double left_C1_x;
+ double left_C1_y;
+ double left_C2_x;
+ double left_C2_y;
+ double right_C1_x;
+ double right_C1_y;
+ double right_C2_x;
+ double right_C2_y;
+ double right_P2_x;
+ double right_P2_y;
+ double Mid_x; // Mid = left.P2 = right.P1
+ double Mid_y; // Mid = left.P2 = right.P1
+
+ left_P1_x = src[srcOff];
+ left_P1_y = src[srcOff + 1];
+ src_C1_x = src[srcOff + 2];
+ src_C1_y = src[srcOff + 3];
+ src_C2_x = src[srcOff + 4];
+ src_C2_y = src[srcOff + 5];
+ right_P2_x = src[srcOff + 6];
+ right_P2_y = src[srcOff + 7];
+
+ left_C1_x = (left_P1_x + src_C1_x) / 2;
+ left_C1_y = (left_P1_y + src_C1_y) / 2;
+ right_C2_x = (right_P2_x + src_C2_x) / 2;
+ right_C2_y = (right_P2_y + src_C2_y) / 2;
+ Mid_x = (src_C1_x + src_C2_x) / 2;
+ Mid_y = (src_C1_y + src_C2_y) / 2;
+ left_C2_x = (left_C1_x + Mid_x) / 2;
+ left_C2_y = (left_C1_y + Mid_y) / 2;
+ right_C1_x = (Mid_x + right_C2_x) / 2;
+ right_C1_y = (Mid_y + right_C2_y) / 2;
+ Mid_x = (left_C2_x + right_C1_x) / 2;
+ Mid_y = (left_C2_y + right_C1_y) / 2;
+
+ if (left != null)
+ {
+ left[leftOff] = left_P1_x;
+ left[leftOff + 1] = left_P1_y;
+ left[leftOff + 2] = left_C1_x;
+ left[leftOff + 3] = left_C1_y;
+ left[leftOff + 4] = left_C2_x;
+ left[leftOff + 5] = left_C2_y;
+ left[leftOff + 6] = Mid_x;
+ left[leftOff + 7] = Mid_y;
+ }
+
+ if (right != null)
+ {
+ right[rightOff] = Mid_x;
+ right[rightOff + 1] = Mid_y;
+ right[rightOff + 2] = right_C1_x;
+ right[rightOff + 3] = right_C1_y;
+ right[rightOff + 4] = right_C2_x;
+ right[rightOff + 5] = right_C2_y;
+ right[rightOff + 6] = right_P2_x;
+ right[rightOff + 7] = right_P2_y;
+ }
+ }
+
+ /**
+ * Finds the non-complex roots of a cubic equation, placing the
+ * results into the same array as the equation coefficients. The
+ * following equation is being solved:
+ *
+ * <blockquote><code>eqn[3]</code> · <i>x</i><sup>3</sup>
+ * + <code>eqn[2]</code> · <i>x</i><sup>2</sup>
+ * + <code>eqn[1]</code> · <i>x</i>
+ * + <code>eqn[0]</code>
+ * = 0
+ * </blockquote>
+ *
+ * <p>For some background about solving cubic equations, see the
+ * article <a
+ * href="http://planetmath.org/encyclopedia/CubicFormula.html"
+ * >“Cubic Formula”</a> in <a
+ * href="http://planetmath.org/" >PlanetMath</a>. For an extensive
+ * library of numerical algorithms written in the C programming
+ * language, see the <a href= "http://www.gnu.org/software/gsl/">GNU
+ * Scientific Library</a>, from which this implementation was
+ * adapted.
+ *
+ * @param eqn an array with the coefficients of the equation. When
+ * this procedure has returned, <code>eqn</code> will contain the
+ * non-complex solutions of the equation, in no particular order.
+ *
+ * @return the number of non-complex solutions. A result of 0
+ * indicates that the equation has no non-complex solutions. A
+ * result of -1 indicates that the equation is constant (i.e.,
+ * always or never zero).
+ *
+ * @see #solveCubic(double[], double[])
+ * @see QuadCurve2D#solveQuadratic(double[],double[])
+ *
+ * @author Brian Gough (bjg at network-theory.com)
+ * (original C implementation in the <a href=
+ * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>)
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * (adaptation to Java)
+ */
+ public static int solveCubic(double[] eqn)
+ {
+ return solveCubic(eqn, eqn);
+ }
+
+ /**
+ * Finds the non-complex roots of a cubic equation. The following
+ * equation is being solved:
+ *
+ * <blockquote><code>eqn[3]</code> · <i>x</i><sup>3</sup>
+ * + <code>eqn[2]</code> · <i>x</i><sup>2</sup>
+ * + <code>eqn[1]</code> · <i>x</i>
+ * + <code>eqn[0]</code>
+ * = 0
+ * </blockquote>
+ *
+ * <p>For some background about solving cubic equations, see the
+ * article <a
+ * href="http://planetmath.org/encyclopedia/CubicFormula.html"
+ * >“Cubic Formula”</a> in <a
+ * href="http://planetmath.org/" >PlanetMath</a>. For an extensive
+ * library of numerical algorithms written in the C programming
+ * language, see the <a href= "http://www.gnu.org/software/gsl/">GNU
+ * Scientific Library</a>, from which this implementation was
+ * adapted.
+ *
+ * @see QuadCurve2D#solveQuadratic(double[],double[])
+ *
+ * @param eqn an array with the coefficients of the equation.
+ *
+ * @param res an array into which the non-complex roots will be
+ * stored. The results may be in an arbitrary order. It is safe to
+ * pass the same array object reference for both <code>eqn</code>
+ * and <code>res</code>.
+ *
+ * @return the number of non-complex solutions. A result of 0
+ * indicates that the equation has no non-complex solutions. A
+ * result of -1 indicates that the equation is constant (i.e.,
+ * always or never zero).
+ *
+ * @author Brian Gough (bjg at network-theory.com)
+ * (original C implementation in the <a href=
+ * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>)
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * (adaptation to Java)
+ */
+ public static int solveCubic(double[] eqn, double[] res)
+ {
+ // Adapted from poly/solve_cubic.c in the GNU Scientific Library
+ // (GSL), revision 1.7 of 2003-07-26. For the original source, see
+ // http://www.gnu.org/software/gsl/
+ //
+ // Brian Gough, the author of that code, has granted the
+ // permission to use it in GNU Classpath under the GNU Classpath
+ // license, and has assigned the copyright to the Free Software
+ // Foundation.
+ //
+ // The Java implementation is very similar to the GSL code, but
+ // not a strict one-to-one copy. For example, GSL would sort the
+ // result.
+
+ double a;
+ double b;
+ double c;
+ double q;
+ double r;
+ double Q;
+ double R;
+ double c3;
+ double Q3;
+ double R2;
+ double CR2;
+ double CQ3;
+
+ // If the cubic coefficient is zero, we have a quadratic equation.
+ c3 = eqn[3];
+ if (c3 == 0)
+ return QuadCurve2D.solveQuadratic(eqn, res);
+
+ // Divide the equation by the cubic coefficient.
+ c = eqn[0] / c3;
+ b = eqn[1] / c3;
+ a = eqn[2] / c3;
+
+ // We now need to solve x^3 + ax^2 + bx + c = 0.
+ q = a * a - 3 * b;
+ r = 2 * a * a * a - 9 * a * b + 27 * c;
+
+ Q = q / 9;
+ R = r / 54;
+
+ Q3 = Q * Q * Q;
+ R2 = R * R;
+
+ CR2 = 729 * r * r;
+ CQ3 = 2916 * q * q * q;
+
+ if (R == 0 && Q == 0)
+ {
+ // The GNU Scientific Library would return three identical
+ // solutions in this case.
+ res[0] = -a / 3;
+ return 1;
+ }
+
+ if (CR2 == CQ3)
+ {
+ /* this test is actually R2 == Q3, written in a form suitable
+ for exact computation with integers */
+ /* Due to finite precision some double roots may be missed, and
+ considered to be a pair of complex roots z = x +/- epsilon i
+ close to the real axis. */
+ double sqrtQ = Math.sqrt(Q);
+
+ if (R > 0)
+ {
+ res[0] = -2 * sqrtQ - a / 3;
+ res[1] = sqrtQ - a / 3;
+ }
+ else
+ {
+ res[0] = -sqrtQ - a / 3;
+ res[1] = 2 * sqrtQ - a / 3;
+ }
+ return 2;
+ }
+
+ if (CR2 < CQ3) /* equivalent to R2 < Q3 */
+ {
+ double sqrtQ = Math.sqrt(Q);
+ double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ;
+ double theta = Math.acos(R / sqrtQ3);
+ double norm = -2 * sqrtQ;
+ res[0] = norm * Math.cos(theta / 3) - a / 3;
+ res[1] = norm * Math.cos((theta + 2.0 * Math.PI) / 3) - a / 3;
+ res[2] = norm * Math.cos((theta - 2.0 * Math.PI) / 3) - a / 3;
+
+ // The GNU Scientific Library sorts the results. We don't.
+ return 3;
+ }
+
+ double sgnR = (R >= 0 ? 1 : -1);
+ double A = -sgnR * Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0);
+ double B = Q / A;
+ res[0] = A + B - a / 3;
+ return 1;
+ }
+
+ /**
+ * Determines whether a position lies inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a CubicCurve2D.
+ */
+ public boolean contains(double x, double y)
+ {
+ if (! getBounds2D().contains(x, y))
+ return false;
+
+ return ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0);
+ }
+
+ /**
+ * Determines whether a point lies inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a CubicCurve2D.
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Determines whether any part of a rectangle is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” in a CubicCurve2D.
+ * @see #contains(double, double)
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ if (! getBounds2D().contains(x, y, w, h))
+ return false;
+
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, true, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, false, h) != 0 /* right */
+ || getAxisIntersections(x, y, false, h) != 0) /* left */
+ return true;
+
+ /* No intersections, is any point inside? */
+ if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Determines whether any part of a Rectangle2D is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ * @see #intersects(double, double, double, double)
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Determine whether a rectangle is entirely inside the area that is bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a CubicCurve2D.
+ * @see #contains(double, double)
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ if (! getBounds2D().intersects(x, y, w, h))
+ return false;
+
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, true, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, false, h) != 0 /* right */
+ || getAxisIntersections(x, y, false, h) != 0) /* left */
+ return false;
+
+ /* No intersections, is any point inside? */
+ if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Determine whether a Rectangle2D is entirely inside the area that is
+ * bounded by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/CubicCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a CubicCurve2D.
+ * @see #contains(double, double)
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control points.
+ */
+ public Rectangle getBounds()
+ {
+ return getBounds2D().getBounds();
+ }
+
+ public PathIterator getPathIterator(final AffineTransform at)
+ {
+ return new PathIterator()
+ {
+ /** Current coordinate. */
+ private int current = 0;
+
+ public int getWindingRule()
+ {
+ return WIND_NON_ZERO;
+ }
+
+ public boolean isDone()
+ {
+ return current >= 2;
+ }
+
+ public void next()
+ {
+ current++;
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = (float) getX1();
+ coords[1] = (float) getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = (float) getCtrlX1();
+ coords[1] = (float) getCtrlY1();
+ coords[2] = (float) getCtrlX2();
+ coords[3] = (float) getCtrlY2();
+ coords[4] = (float) getX2();
+ coords[5] = (float) getY2();
+ result = SEG_CUBICTO;
+ break;
+ default:
+ throw new NoSuchElementException("cubic iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 3);
+ return result;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = getX1();
+ coords[1] = getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = getCtrlX1();
+ coords[1] = getCtrlY1();
+ coords[2] = getCtrlX2();
+ coords[3] = getCtrlY2();
+ coords[4] = getX2();
+ coords[5] = getY2();
+ result = SEG_CUBICTO;
+ break;
+ default:
+ throw new NoSuchElementException("cubic iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 3);
+ return result;
+ }
+ };
+ }
+
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return new FlatteningPathIterator(getPathIterator(at), flatness);
+ }
+
+ /**
+ * Create a new curve with the same contents as this one.
+ *
+ * @return the clone.
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * Helper method used by contains() and intersects() methods, that
+ * returns the number of curve/line intersections on a given axis
+ * extending from a certain point.
+ *
+ * @param x x coordinate of the origin point
+ * @param y y coordinate of the origin point
+ * @param useYaxis axis used, if true the positive Y axis is used,
+ * false uses the positive X axis.
+ *
+ * This is an implementation of the line-crossings algorithm,
+ * Detailed in an article on Eric Haines' page:
+ * http://www.acm.org/tog/editors/erich/ptinpoly/
+ *
+ * A special-case not adressed in this code is self-intersections
+ * of the curve, e.g. if the axis intersects the self-itersection,
+ * the degenerate roots of the polynomial will erroneously count as
+ * a single intersection of the curve, and not two.
+ */
+ private int getAxisIntersections(double x, double y, boolean useYaxis,
+ double distance)
+ {
+ int nCrossings = 0;
+ double a0;
+ double a1;
+ double a2;
+ double a3;
+ double b0;
+ double b1;
+ double b2;
+ double b3;
+ double[] r = new double[4];
+ int nRoots;
+
+ a0 = a3 = 0.0;
+
+ if (useYaxis)
+ {
+ a0 = getY1() - y;
+ a1 = getCtrlY1() - y;
+ a2 = getCtrlY2() - y;
+ a3 = getY2() - y;
+ b0 = getX1() - x;
+ b1 = getCtrlX1() - x;
+ b2 = getCtrlX2() - x;
+ b3 = getX2() - x;
+ }
+ else
+ {
+ a0 = getX1() - x;
+ a1 = getCtrlX1() - x;
+ a2 = getCtrlX2() - x;
+ a3 = getX2() - x;
+ b0 = getY1() - y;
+ b1 = getCtrlY1() - y;
+ b2 = getCtrlY2() - y;
+ b3 = getY2() - y;
+ }
+
+ /* If the axis intersects a start/endpoint, shift it up by some small
+ amount to guarantee the line is 'inside'
+ If this is not done, bad behaviour may result for points on that axis.*/
+ if (a0 == 0.0 || a3 == 0.0)
+ {
+ double small = getFlatness() * EPSILON;
+ if (a0 == 0.0)
+ a0 -= small;
+ if (a3 == 0.0)
+ a3 -= small;
+ }
+
+ if (useYaxis)
+ {
+ if (Line2D.linesIntersect(b0, a0, b3, a3, EPSILON, 0.0, distance, 0.0))
+ nCrossings++;
+ }
+ else
+ {
+ if (Line2D.linesIntersect(a0, b0, a3, b3, 0.0, EPSILON, 0.0, distance))
+ nCrossings++;
+ }
+
+ r[0] = a0;
+ r[1] = 3 * (a1 - a0);
+ r[2] = 3 * (a2 + a0 - 2 * a1);
+ r[3] = a3 - 3 * a2 + 3 * a1 - a0;
+
+ if ((nRoots = solveCubic(r)) != 0)
+ for (int i = 0; i < nRoots; i++)
+ {
+ double t = r[i];
+ if (t >= 0.0 && t <= 1.0)
+ {
+ double crossing = -(t * t * t) * (b0 - 3 * b1 + 3 * b2 - b3)
+ + 3 * t * t * (b0 - 2 * b1 + b2)
+ + 3 * t * (b1 - b0) + b0;
+ if (crossing > 0.0 && crossing <= distance)
+ nCrossings++;
+ }
+ }
+
+ return (nCrossings);
+ }
+
+ /**
+ * A two-dimensional curve that is parameterized with a cubic
+ * function and stores coordinate values in double-precision
+ * floating-point format.
+ *
+ * @see CubicCurve2D.Float
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ public static class Double extends CubicCurve2D
+ {
+ /**
+ * The <i>x</i> coordinate of the curve’s start point.
+ */
+ public double x1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s start point.
+ */
+ public double y1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s first control point.
+ */
+ public double ctrlx1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s first control point.
+ */
+ public double ctrly1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s second control point.
+ */
+ public double ctrlx2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s second control point.
+ */
+ public double ctrly2;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s end point.
+ */
+ public double x2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s end point.
+ */
+ public double y2;
+
+ /**
+ * Constructs a new CubicCurve2D that stores its coordinate values
+ * in double-precision floating-point format. All points are
+ * initially at position (0, 0).
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Constructs a new CubicCurve2D that stores its coordinate values
+ * in double-precision floating-point format, specifying the
+ * initial position of each point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s first
+ * control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s first
+ * control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s second
+ * control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s second
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public Double(double x1, double y1, double cx1, double cy1, double cx2,
+ double cy2, double x2, double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx1 = cx1;
+ ctrly1 = cy1;
+ ctrlx2 = cx2;
+ ctrly2 = cy2;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Double(x1, y1);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s first
+ * control point.
+ */
+ public double getCtrlX1()
+ {
+ return ctrlx1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s first
+ * control point.
+ */
+ public double getCtrlY1()
+ {
+ return ctrly1;
+ }
+
+ /**
+ * Returns the curve’s first control point.
+ */
+ public Point2D getCtrlP1()
+ {
+ return new Point2D.Double(ctrlx1, ctrly1);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s second
+ * control point.
+ */
+ public double getCtrlX2()
+ {
+ return ctrlx2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s second
+ * control point.
+ */
+ public double getCtrlY2()
+ {
+ return ctrly2;
+ }
+
+ /**
+ * Returns the curve’s second control point.
+ */
+ public Point2D getCtrlP2()
+ {
+ return new Point2D.Double(ctrlx2, ctrly2);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Double(x2, y2);
+ }
+
+ /**
+ * Changes the curve geometry, separately specifying each coordinate
+ * value.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new end
+ * point.
+ */
+ public void setCurve(double x1, double y1, double cx1, double cy1,
+ double cx2, double cy2, double x2, double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx1 = cx1;
+ ctrly1 = cy1;
+ ctrlx2 = cx2;
+ ctrly2 = cy2;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control points. As the
+ * illustration below shows, the invisible control points may cause
+ * the bounds to be much larger than the area that is actually
+ * covered by the curve.
+ *
+ * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180"
+ * alt="An illustration of the bounds of a CubicCurve2D" />
+ */
+ public Rectangle2D getBounds2D()
+ {
+ double nx1 = Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2));
+ double ny1 = Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2));
+ double nx2 = Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2));
+ double ny2 = Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2));
+ return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1);
+ }
+ }
+
+ /**
+ * A two-dimensional curve that is parameterized with a cubic
+ * function and stores coordinate values in single-precision
+ * floating-point format.
+ *
+ * @see CubicCurve2D.Float
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ public static class Float extends CubicCurve2D
+ {
+ /**
+ * The <i>x</i> coordinate of the curve’s start point.
+ */
+ public float x1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s start point.
+ */
+ public float y1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s first control point.
+ */
+ public float ctrlx1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s first control point.
+ */
+ public float ctrly1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s second control point.
+ */
+ public float ctrlx2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s second control point.
+ */
+ public float ctrly2;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s end point.
+ */
+ public float x2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s end point.
+ */
+ public float y2;
+
+ /**
+ * Constructs a new CubicCurve2D that stores its coordinate values
+ * in single-precision floating-point format. All points are
+ * initially at position (0, 0).
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Constructs a new CubicCurve2D that stores its coordinate values
+ * in single-precision floating-point format, specifying the
+ * initial position of each point.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s first
+ * control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s first
+ * control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s second
+ * control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s second
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public Float(float x1, float y1, float cx1, float cy1, float cx2,
+ float cy2, float x2, float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx1 = cx1;
+ ctrly1 = cy1;
+ ctrlx2 = cx2;
+ ctrly2 = cy2;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Float(x1, y1);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s first
+ * control point.
+ */
+ public double getCtrlX1()
+ {
+ return ctrlx1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s first
+ * control point.
+ */
+ public double getCtrlY1()
+ {
+ return ctrly1;
+ }
+
+ /**
+ * Returns the curve’s first control point.
+ */
+ public Point2D getCtrlP1()
+ {
+ return new Point2D.Float(ctrlx1, ctrly1);
+ }
+
+ /**
+ * Returns the <i>s</i> coordinate of the curve’s second
+ * control point.
+ */
+ public double getCtrlX2()
+ {
+ return ctrlx2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s second
+ * control point.
+ */
+ public double getCtrlY2()
+ {
+ return ctrly2;
+ }
+
+ /**
+ * Returns the curve’s second control point.
+ */
+ public Point2D getCtrlP2()
+ {
+ return new Point2D.Float(ctrlx2, ctrly2);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Float(x2, y2);
+ }
+
+ /**
+ * Changes the curve geometry, separately specifying each coordinate
+ * value as a double-precision floating-point number.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new end
+ * point.
+ */
+ public void setCurve(double x1, double y1, double cx1, double cy1,
+ double cx2, double cy2, double x2, double y2)
+ {
+ this.x1 = (float) x1;
+ this.y1 = (float) y1;
+ ctrlx1 = (float) cx1;
+ ctrly1 = (float) cy1;
+ ctrlx2 = (float) cx2;
+ ctrly2 = (float) cy2;
+ this.x2 = (float) x2;
+ this.y2 = (float) y2;
+ }
+
+ /**
+ * Changes the curve geometry, separately specifying each coordinate
+ * value as a single-precision floating-point number.
+ *
+ * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a CubicCurve2D" />
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param cx1 the <i>x</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cy1 the <i>y</i> coordinate of the curve’s new
+ * first control point.
+ *
+ * @param cx2 the <i>x</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param cy2 the <i>y</i> coordinate of the curve’s new
+ * second control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new end
+ * point.
+ */
+ public void setCurve(float x1, float y1, float cx1, float cy1, float cx2,
+ float cy2, float x2, float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx1 = cx1;
+ ctrly1 = cy1;
+ ctrlx2 = cx2;
+ ctrly2 = cy2;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control points. As the
+ * illustration below shows, the invisible control points may cause
+ * the bounds to be much larger than the area that is actually
+ * covered by the curve.
+ *
+ * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180"
+ * alt="An illustration of the bounds of a CubicCurve2D" />
+ */
+ public Rectangle2D getBounds2D()
+ {
+ float nx1 = (float) Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2));
+ float ny1 = (float) Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2));
+ float nx2 = (float) Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2));
+ float ny2 = (float) Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2));
+ return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Dimension2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Dimension2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Dimension2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Dimension2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,118 @@
+/* Dimension2D.java -- abstraction of a dimension
+ Copyright (C) 1999, 2000, 2002 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.geom;
+
+/**
+ * This stores a dimension in 2-dimensional space - a width (along the x-axis)
+ * and height (along the y-axis). The storage is left to subclasses.
+ *
+ * @author Per Bothner (bothner at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class Dimension2D implements Cloneable
+{
+ /**
+ * The default constructor.
+ */
+ protected Dimension2D()
+ {
+ }
+
+ /**
+ * Get the width of this dimension. A negative result, while legal, is
+ * undefined in meaning.
+ *
+ * @return the width
+ */
+ public abstract double getWidth();
+
+ /**
+ * Get the height of this dimension. A negative result, while legal, is
+ * undefined in meaning.
+ *
+ * @return the height
+ */
+ public abstract double getHeight();
+
+ /**
+ * Set the size of this dimension to the requested values. Loss of precision
+ * may occur.
+ *
+ * @param w the new width
+ * @param h the new height
+ */
+ public abstract void setSize(double w, double h);
+
+ /**
+ * Set the size of this dimension to the requested value. Loss of precision
+ * may occur.
+ *
+ * @param d the dimension containing the new values
+ *
+ * @throws NullPointerException if d is null
+ */
+ public void setSize(Dimension2D d)
+ {
+ setSize(d.getWidth(), d.getHeight());
+ }
+
+ /**
+ * Create a new dimension of the same run-time type with the same contents
+ * as this one.
+ *
+ * @return the clone
+ *
+ * @exception OutOfMemoryError If there is not enough memory available.
+ *
+ * @since 1.2
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+} // class Dimension2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Ellipse2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Ellipse2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Ellipse2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Ellipse2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,413 @@
+/* Ellipse2D.java -- represents an ellipse in 2-D space
+ Copyright (C) 2000, 2002, 2004 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.geom;
+
+
+/**
+ * Ellipse2D is the shape of an ellipse.
+ * <BR>
+ * <img src="doc-files/Ellipse-1.png" width="347" height="221"
+ * alt="A drawing of an ellipse" /><BR>
+ * The ellipse is defined by it's bounding box (shown in red),
+ * and is defined by the implicit curve:<BR>
+ * <blockquote>(<i>x</i>/<i>a</i>)<sup>2</sup> +
+ * (<i>y</i>/<i>b</i>)<sup>2</sup> = 1<BR><BR></blockquote>
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ *
+ * @since 1.2
+ */
+public abstract class Ellipse2D extends RectangularShape
+{
+ /**
+ * Ellipse2D is defined as abstract.
+ * Implementing classes are Ellipse2D.Float and Ellipse2D.Double.
+ */
+ protected Ellipse2D()
+ {
+ }
+
+ /**
+ * Determines if a point is contained within the ellipse. <P>
+ * @param x - x coordinate of the point.
+ * @param y - y coordinate of the point.
+ * @return true if the point is within the ellipse, false otherwise.
+ */
+ public boolean contains(double x, double y)
+ {
+ double rx = getWidth() / 2;
+ double ry = getHeight() / 2;
+ double tx = (x - (getX() + rx)) / rx;
+ double ty = (y - (getY() + ry)) / ry;
+ return tx * tx + ty * ty < 1.0;
+ }
+
+ /**
+ * Determines if a rectangle is completely contained within the
+ * ellipse. <P>
+ * @param x - x coordinate of the upper-left corner of the rectangle
+ * @param y - y coordinate of the upper-left corner of the rectangle
+ * @param w - width of the rectangle
+ * @param h - height of the rectangle
+ * @return true if the rectangle is completely contained, false otherwise.
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ double x2 = x + w;
+ double y2 = y + h;
+ return (contains(x, y) && contains(x, y2) && contains(x2, y)
+ && contains(x2, y2));
+ }
+
+ /**
+ * Returns a PathIterator object corresponding to the ellipse.<P>
+ *
+ * Note: An ellipse cannot be represented exactly in PathIterator
+ * segments, the outline is thefore approximated with cubic
+ * Bezier segments.
+ *
+ * @param at an optional transform.
+ * @return A path iterator.
+ */
+ public PathIterator getPathIterator(AffineTransform at)
+ {
+ // An ellipse is just a complete arc.
+ return new Arc2D.ArcIterator(this, at);
+ }
+
+ /**
+ * Determines if a rectangle intersects any part of the ellipse.<P>
+ * @param x - x coordinate of the upper-left corner of the rectangle
+ * @param y - y coordinate of the upper-left corner of the rectangle
+ * @param w - width of the rectangle
+ * @param h - height of the rectangle
+ * @return true if the rectangle intersects the ellipse, false otherwise.
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ Rectangle2D r = new Rectangle2D.Double(x, y, w, h);
+ if (! r.intersects(getX(), getY(), getWidth(), getHeight()))
+ return false;
+
+ if (contains(x, y) || contains(x, y + h) || contains(x + w, y)
+ || contains(x + w, y + h))
+ return true;
+
+ Line2D l1 = new Line2D.Double(getX(), getY() + (getHeight() / 2),
+ getX() + getWidth(),
+ getY() + (getHeight() / 2));
+ Line2D l2 = new Line2D.Double(getX() + (getWidth() / 2), getY(),
+ getX() + (getWidth() / 2),
+ getY() + getHeight());
+
+ if (l1.intersects(r) || l2.intersects(r))
+ return true;
+
+ return false;
+ }
+
+ /**
+ * An {@link Ellipse2D} that stores its coordinates using <code>double</code>
+ * primitives.
+ */
+ public static class Double extends Ellipse2D
+ {
+ /**
+ * The height of the ellipse.
+ */
+ public double height;
+
+ /**
+ * The width of the ellipse.
+ */
+ public double width;
+
+ /**
+ * The upper-left x coordinate of the bounding-box
+ */
+ public double x;
+
+ /**
+ * The upper-left y coordinate of the bounding-box
+ */
+ public double y;
+
+ /**
+ * Creates a new Ellipse2D with an upper-left coordinate of (0,0)
+ * and a zero size.
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Creates a new Ellipse2D within a given rectangle
+ * using double-precision coordinates.<P>
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
+ * @param w - width of the ellipse
+ * @param h - height of the ellipse
+ */
+ public Double(double x, double y, double w, double h)
+ {
+ this.x = x;
+ this.y = y;
+ height = h;
+ width = w;
+ }
+
+ /**
+ * Returns the bounding-box of the ellipse.
+ * @return The bounding box.
+ */
+ public Rectangle2D getBounds2D()
+ {
+ return new Rectangle2D.Double(x, y, width, height);
+ }
+
+ /**
+ * Returns the height of the ellipse.
+ * @return The height of the ellipse.
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Returns the width of the ellipse.
+ * @return The width of the ellipse.
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Returns x coordinate of the upper-left corner of
+ * the ellipse's bounding-box.
+ * @return The x coordinate.
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Returns y coordinate of the upper-left corner of
+ * the ellipse's bounding-box.
+ * @return The y coordinate.
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Returns <code>true</code> if the ellipse encloses no area, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
+ */
+ public boolean isEmpty()
+ {
+ return height <= 0 || width <= 0;
+ }
+
+ /**
+ * Sets the geometry of the ellipse's bounding box.<P>
+ *
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
+ * @param w - width of the ellipse
+ * @param h - height of the ellipse
+ */
+ public void setFrame(double x, double y, double w, double h)
+ {
+ this.x = x;
+ this.y = y;
+ height = h;
+ width = w;
+ }
+ } // class Double
+
+ /**
+ * An {@link Ellipse2D} that stores its coordinates using <code>float</code>
+ * primitives.
+ */
+ public static class Float extends Ellipse2D
+ {
+ /**
+ * The height of the ellipse.
+ */
+ public float height;
+
+ /**
+ * The width of the ellipse.
+ */
+ public float width;
+
+ /**
+ * The upper-left x coordinate of the bounding-box
+ */
+ public float x;
+
+ /**
+ * The upper-left y coordinate of the bounding-box
+ */
+ public float y;
+
+ /**
+ * Creates a new Ellipse2D with an upper-left coordinate of (0,0)
+ * and a zero size.
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Creates a new Ellipse2D within a given rectangle
+ * using floating-point precision.<P>
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
+ * @param w - width of the ellipse
+ * @param h - height of the ellipse
+ *
+ */
+ public Float(float x, float y, float w, float h)
+ {
+ this.x = x;
+ this.y = y;
+ this.height = h;
+ this.width = w;
+ }
+
+ /**
+ * Returns the bounding-box of the ellipse.
+ * @return The bounding box.
+ */
+ public Rectangle2D getBounds2D()
+ {
+ return new Rectangle2D.Float(x, y, width, height);
+ }
+
+ /**
+ * Returns the height of the ellipse.
+ * @return The height of the ellipse.
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Returns the width of the ellipse.
+ * @return The width of the ellipse.
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Returns x coordinate of the upper-left corner of
+ * the ellipse's bounding-box.
+ * @return The x coordinate.
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Returns y coordinate of the upper-left corner of
+ * the ellipse's bounding-box.
+ * @return The y coordinate.
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Returns <code>true</code> if the ellipse encloses no area, and
+ * <code>false</code> otherwise.
+ *
+ * @return A boolean.
+ */
+ public boolean isEmpty()
+ {
+ return height <= 0 || width <= 0;
+ }
+
+ /**
+ * Sets the geometry of the ellipse's bounding box.<P>
+ *
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
+ * @param w - width of the ellipse
+ * @param h - height of the ellipse
+ */
+ public void setFrame(float x, float y, float w, float h)
+ {
+ this.x = x;
+ this.y = y;
+ height = h;
+ width = w;
+ }
+
+ /**
+ * Sets the geometry of the ellipse's bounding box.
+ *
+ * Note: This leads to a loss of precision.<P>
+ *
+ * @param x - x coordinate of the upper-left of the bounding rectangle
+ * @param y - y coordinate of the upper-left of the bounding rectangle
+ * @param w - width of the ellipse
+ * @param h - height of the ellipse
+ */
+ public void setFrame(double x, double y, double w, double h)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ height = (float) h;
+ width = (float) w;
+ }
+ } // class Float
+} // class Ellipse2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/FlatteningPathIterator.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/FlatteningPathIterator.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/FlatteningPathIterator.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/FlatteningPathIterator.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,579 @@
+/* FlatteningPathIterator.java -- Approximates curves by straight lines
+ Copyright (C) 2003 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.geom;
+
+import java.util.NoSuchElementException;
+
+
+/**
+ * A PathIterator for approximating curved path segments by sequences
+ * of straight lines. Instances of this class will only return
+ * segments of type {@link PathIterator#SEG_MOVETO}, {@link
+ * PathIterator#SEG_LINETO}, and {@link PathIterator#SEG_CLOSE}.
+ *
+ * <p>The accuracy of the approximation is determined by two
+ * parameters:
+ *
+ * <ul><li>The <i>flatness</i> is a threshold value for deciding when
+ * a curved segment is consided flat enough for being approximated by
+ * a single straight line. Flatness is defined as the maximal distance
+ * of a curve control point to the straight line that connects the
+ * curve start and end. A lower flatness threshold means a closer
+ * approximation. See {@link QuadCurve2D#getFlatness()} and {@link
+ * CubicCurve2D#getFlatness()} for drawings which illustrate the
+ * meaning of flatness.</li>
+ *
+ * <li>The <i>recursion limit</i> imposes an upper bound for how often
+ * a curved segment gets subdivided. A limit of <i>n</i> means that
+ * for each individual quadratic and cubic Bézier spline
+ * segment, at most 2<sup><small><i>n</i></small></sup> {@link
+ * PathIterator#SEG_LINETO} segments will be created.</li></ul>
+ *
+ * <p><b>Memory Efficiency:</b> The memory consumption grows linearly
+ * with the recursion limit. Neither the <i>flatness</i> parameter nor
+ * the number of segments in the flattened path will affect the memory
+ * consumption.
+ *
+ * <p><b>Thread Safety:</b> Multiple threads can safely work on
+ * separate instances of this class. However, multiple threads should
+ * not concurrently access the same instance, as no synchronization is
+ * performed.
+ *
+ * @see <a href="doc-files/FlatteningPathIterator-1.html"
+ * >Implementation Note</a>
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ *
+ * @since 1.2
+ */
+public class FlatteningPathIterator
+ implements PathIterator
+{
+ /**
+ * The PathIterator whose curved segments are being approximated.
+ */
+ private final PathIterator srcIter;
+
+
+ /**
+ * The square of the flatness threshold value, which determines when
+ * a curve segment is considered flat enough that no further
+ * subdivision is needed.
+ *
+ * <p>Calculating flatness actually produces the squared flatness
+ * value. To avoid the relatively expensive calculation of a square
+ * root for each curve segment, we perform all flatness comparisons
+ * on squared values.
+ *
+ * @see QuadCurve2D#getFlatnessSq()
+ * @see CubicCurve2D#getFlatnessSq()
+ */
+ private final double flatnessSq;
+
+
+ /**
+ * The maximal number of subdivions that are performed to
+ * approximate a quadratic or cubic curve segment.
+ */
+ private final int recursionLimit;
+
+
+ /**
+ * A stack for holding the coordinates of subdivided segments.
+ *
+ * @see <a href="doc-files/FlatteningPathIterator-1.html"
+ * >Implementation Note</a>
+ */
+ private double[] stack;
+
+
+ /**
+ * The current stack size.
+ *
+ * @see <a href="doc-files/FlatteningPathIterator-1.html"
+ * >Implementation Note</a>
+ */
+ private int stackSize;
+
+
+ /**
+ * The number of recursions that were performed to arrive at
+ * a segment on the stack.
+ *
+ * @see <a href="doc-files/FlatteningPathIterator-1.html"
+ * >Implementation Note</a>
+ */
+ private int[] recLevel;
+
+
+
+ private final double[] scratch = new double[6];
+
+
+ /**
+ * The segment type of the last segment that was returned by
+ * the source iterator.
+ */
+ private int srcSegType;
+
+
+ /**
+ * The current <i>x</i> position of the source iterator.
+ */
+ private double srcPosX;
+
+
+ /**
+ * The current <i>y</i> position of the source iterator.
+ */
+ private double srcPosY;
+
+
+ /**
+ * A flag that indicates when this path iterator has finished its
+ * iteration over path segments.
+ */
+ private boolean done;
+
+
+ /**
+ * Constructs a new PathIterator for approximating an input
+ * PathIterator with straight lines. The approximation works by
+ * recursive subdivisons, until the specified flatness threshold is
+ * not exceeded.
+ *
+ * <p>There will not be more than 10 nested recursion steps, which
+ * means that a single <code>SEG_QUADTO</code> or
+ * <code>SEG_CUBICTO</code> segment is approximated by at most
+ * 2<sup><small>10</small></sup> = 1024 straight lines.
+ */
+ public FlatteningPathIterator(PathIterator src, double flatness)
+ {
+ this(src, flatness, 10);
+ }
+
+
+ /**
+ * Constructs a new PathIterator for approximating an input
+ * PathIterator with straight lines. The approximation works by
+ * recursive subdivisons, until the specified flatness threshold is
+ * not exceeded. Additionally, the number of recursions is also
+ * bound by the specified recursion limit.
+ */
+ public FlatteningPathIterator(PathIterator src, double flatness,
+ int limit)
+ {
+ if (flatness < 0 || limit < 0)
+ throw new IllegalArgumentException();
+
+ srcIter = src;
+ flatnessSq = flatness * flatness;
+ recursionLimit = limit;
+ fetchSegment();
+ }
+
+
+ /**
+ * Returns the maximally acceptable flatness.
+ *
+ * @see QuadCurve2D#getFlatness()
+ * @see CubicCurve2D#getFlatness()
+ */
+ public double getFlatness()
+ {
+ return Math.sqrt(flatnessSq);
+ }
+
+
+ /**
+ * Returns the maximum number of recursive curve subdivisions.
+ */
+ public int getRecursionLimit()
+ {
+ return recursionLimit;
+ }
+
+
+ // Documentation will be copied from PathIterator.
+ public int getWindingRule()
+ {
+ return srcIter.getWindingRule();
+ }
+
+
+ // Documentation will be copied from PathIterator.
+ public boolean isDone()
+ {
+ return done;
+ }
+
+
+ // Documentation will be copied from PathIterator.
+ public void next()
+ {
+ if (stackSize > 0)
+ {
+ --stackSize;
+ if (stackSize > 0)
+ {
+ switch (srcSegType)
+ {
+ case PathIterator.SEG_QUADTO:
+ subdivideQuadratic();
+ return;
+
+ case PathIterator.SEG_CUBICTO:
+ subdivideCubic();
+ return;
+
+ default:
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+ srcIter.next();
+ fetchSegment();
+ }
+
+
+ // Documentation will be copied from PathIterator.
+ public int currentSegment(double[] coords)
+ {
+ if (done)
+ throw new NoSuchElementException();
+
+ switch (srcSegType)
+ {
+ case PathIterator.SEG_CLOSE:
+ return srcSegType;
+
+ case PathIterator.SEG_MOVETO:
+ case PathIterator.SEG_LINETO:
+ coords[0] = srcPosX;
+ coords[1] = srcPosY;
+ return srcSegType;
+
+ case PathIterator.SEG_QUADTO:
+ if (stackSize == 0)
+ {
+ coords[0] = srcPosX;
+ coords[1] = srcPosY;
+ }
+ else
+ {
+ int sp = stack.length - 4 * stackSize;
+ coords[0] = stack[sp + 2];
+ coords[1] = stack[sp + 3];
+ }
+ return PathIterator.SEG_LINETO;
+
+ case PathIterator.SEG_CUBICTO:
+ if (stackSize == 0)
+ {
+ coords[0] = srcPosX;
+ coords[1] = srcPosY;
+ }
+ else
+ {
+ int sp = stack.length - 6 * stackSize;
+ coords[0] = stack[sp + 4];
+ coords[1] = stack[sp + 5];
+ }
+ return PathIterator.SEG_LINETO;
+ }
+
+ throw new IllegalStateException();
+ }
+
+
+ // Documentation will be copied from PathIterator.
+ public int currentSegment(float[] coords)
+ {
+ if (done)
+ throw new NoSuchElementException();
+
+ switch (srcSegType)
+ {
+ case PathIterator.SEG_CLOSE:
+ return srcSegType;
+
+ case PathIterator.SEG_MOVETO:
+ case PathIterator.SEG_LINETO:
+ coords[0] = (float) srcPosX;
+ coords[1] = (float) srcPosY;
+ return srcSegType;
+
+ case PathIterator.SEG_QUADTO:
+ if (stackSize == 0)
+ {
+ coords[0] = (float) srcPosX;
+ coords[1] = (float) srcPosY;
+ }
+ else
+ {
+ int sp = stack.length - 4 * stackSize;
+ coords[0] = (float) stack[sp + 2];
+ coords[1] = (float) stack[sp + 3];
+ }
+ return PathIterator.SEG_LINETO;
+
+ case PathIterator.SEG_CUBICTO:
+ if (stackSize == 0)
+ {
+ coords[0] = (float) srcPosX;
+ coords[1] = (float) srcPosY;
+ }
+ else
+ {
+ int sp = stack.length - 6 * stackSize;
+ coords[0] = (float) stack[sp + 4];
+ coords[1] = (float) stack[sp + 5];
+ }
+ return PathIterator.SEG_LINETO;
+ }
+
+ throw new IllegalStateException();
+ }
+
+
+ /**
+ * Fetches the next segment from the source iterator.
+ */
+ private void fetchSegment()
+ {
+ int sp;
+
+ if (srcIter.isDone())
+ {
+ done = true;
+ return;
+ }
+
+ srcSegType = srcIter.currentSegment(scratch);
+
+ switch (srcSegType)
+ {
+ case PathIterator.SEG_CLOSE:
+ return;
+
+ case PathIterator.SEG_MOVETO:
+ case PathIterator.SEG_LINETO:
+ srcPosX = scratch[0];
+ srcPosY = scratch[1];
+ return;
+
+ case PathIterator.SEG_QUADTO:
+ if (recursionLimit == 0)
+ {
+ srcPosX = scratch[2];
+ srcPosY = scratch[3];
+ stackSize = 0;
+ return;
+ }
+ sp = 4 * recursionLimit;
+ stackSize = 1;
+ if (stack == null)
+ {
+ stack = new double[sp + /* 4 + 2 */ 6];
+ recLevel = new int[recursionLimit + 1];
+ }
+ recLevel[0] = 0;
+ stack[sp] = srcPosX; // P1.x
+ stack[sp + 1] = srcPosY; // P1.y
+ stack[sp + 2] = scratch[0]; // C.x
+ stack[sp + 3] = scratch[1]; // C.y
+ srcPosX = stack[sp + 4] = scratch[2]; // P2.x
+ srcPosY = stack[sp + 5] = scratch[3]; // P2.y
+ subdivideQuadratic();
+ break;
+
+ case PathIterator.SEG_CUBICTO:
+ if (recursionLimit == 0)
+ {
+ srcPosX = scratch[4];
+ srcPosY = scratch[5];
+ stackSize = 0;
+ return;
+ }
+ sp = 6 * recursionLimit;
+ stackSize = 1;
+ if ((stack == null) || (stack.length < sp + 8))
+ {
+ stack = new double[sp + /* 6 + 2 */ 8];
+ recLevel = new int[recursionLimit + 1];
+ }
+ recLevel[0] = 0;
+ stack[sp] = srcPosX; // P1.x
+ stack[sp + 1] = srcPosY; // P1.y
+ stack[sp + 2] = scratch[0]; // C1.x
+ stack[sp + 3] = scratch[1]; // C1.y
+ stack[sp + 4] = scratch[2]; // C2.x
+ stack[sp + 5] = scratch[3]; // C2.y
+ srcPosX = stack[sp + 6] = scratch[4]; // P2.x
+ srcPosY = stack[sp + 7] = scratch[5]; // P2.y
+ subdivideCubic();
+ return;
+ }
+ }
+
+
+ /**
+ * Repeatedly subdivides the quadratic curve segment that is on top
+ * of the stack. The iteration terminates when the recursion limit
+ * has been reached, or when the resulting segment is flat enough.
+ */
+ private void subdivideQuadratic()
+ {
+ int sp;
+ int level;
+
+ sp = stack.length - 4 * stackSize - 2;
+ level = recLevel[stackSize - 1];
+ while ((level < recursionLimit)
+ && (QuadCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
+ {
+ recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
+ QuadCurve2D.subdivide(stack, sp, stack, sp - 4, stack, sp);
+ ++stackSize;
+ sp -= 4;
+ }
+ }
+
+
+ /**
+ * Repeatedly subdivides the cubic curve segment that is on top
+ * of the stack. The iteration terminates when the recursion limit
+ * has been reached, or when the resulting segment is flat enough.
+ */
+ private void subdivideCubic()
+ {
+ int sp;
+ int level;
+
+ sp = stack.length - 6 * stackSize - 2;
+ level = recLevel[stackSize - 1];
+ while ((level < recursionLimit)
+ && (CubicCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
+ {
+ recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
+
+ CubicCurve2D.subdivide(stack, sp, stack, sp - 6, stack, sp);
+ ++stackSize;
+ sp -= 6;
+ }
+ }
+
+
+ /* These routines were useful for debugging. Since they would
+ * just bloat the implementation, they are commented out.
+ *
+ *
+
+ private static String segToString(int segType, double[] d, int offset)
+ {
+ String s;
+
+ switch (segType)
+ {
+ case PathIterator.SEG_CLOSE:
+ return "SEG_CLOSE";
+
+ case PathIterator.SEG_MOVETO:
+ return "SEG_MOVETO (" + d[offset] + ", " + d[offset + 1] + ")";
+
+ case PathIterator.SEG_LINETO:
+ return "SEG_LINETO (" + d[offset] + ", " + d[offset + 1] + ")";
+
+ case PathIterator.SEG_QUADTO:
+ return "SEG_QUADTO (" + d[offset] + ", " + d[offset + 1]
+ + ") (" + d[offset + 2] + ", " + d[offset + 3] + ")";
+
+ case PathIterator.SEG_CUBICTO:
+ return "SEG_CUBICTO (" + d[offset] + ", " + d[offset + 1]
+ + ") (" + d[offset + 2] + ", " + d[offset + 3]
+ + ") (" + d[offset + 4] + ", " + d[offset + 5] + ")";
+ }
+
+ throw new IllegalStateException();
+ }
+
+
+ private void dumpQuadraticStack(String msg)
+ {
+ int sp = stack.length - 4 * stackSize - 2;
+ int i = 0;
+ System.err.print(" " + msg + ":");
+ while (sp < stack.length)
+ {
+ System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
+ if (i < recLevel.length)
+ System.out.print("/" + recLevel[i++]);
+ if (sp + 3 < stack.length)
+ System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
+ sp += 4;
+ }
+ System.err.println();
+ }
+
+
+ private void dumpCubicStack(String msg)
+ {
+ int sp = stack.length - 6 * stackSize - 2;
+ int i = 0;
+ System.err.print(" " + msg + ":");
+ while (sp < stack.length)
+ {
+ System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
+ if (i < recLevel.length)
+ System.out.print("/" + recLevel[i++]);
+ if (sp + 3 < stack.length)
+ {
+ System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
+ System.err.print(" [" + stack[sp+4] + ", " + stack[sp+5] + "]");
+ }
+ sp += 6;
+ }
+ System.err.println();
+ }
+
+ *
+ *
+ */
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/GeneralPath.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/GeneralPath.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/GeneralPath.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/GeneralPath.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,969 @@
+/* GeneralPath.java -- represents a shape built from subpaths
+ Copyright (C) 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+
+/**
+ * A general geometric path, consisting of any number of subpaths
+ * constructed out of straight lines and cubic or quadratic Bezier
+ * curves.
+ *
+ * <p>The inside of the curve is defined for drawing purposes by a winding
+ * rule. Either the WIND_EVEN_ODD or WIND_NON_ZERO winding rule can be chosen.
+ *
+ * <p><img src="doc-files/GeneralPath-1.png" width="300" height="210"
+ * alt="A drawing of a GeneralPath" />
+ * <p>The EVEN_ODD winding rule defines a point as inside a path if:
+ * A ray from the point towards infinity in an arbitrary direction
+ * intersects the path an odd number of times. Points <b>A</b> and
+ * <b>C</b> in the image are considered to be outside the path.
+ * (both intersect twice)
+ * Point <b>B</b> intersects once, and is inside.
+ *
+ * <p>The NON_ZERO winding rule defines a point as inside a path if:
+ * The path intersects the ray in an equal number of opposite directions.
+ * Point <b>A</b> in the image is outside (one intersection in the
+ * ’up’
+ * direction, one in the ’down’ direction) Point <b>B</b> in
+ * the image is inside (one intersection ’down’)
+ * Point <b>C</b> in the image is inside (two intersections in the
+ * ’down’ direction)
+ *
+ * @see Line2D
+ * @see CubicCurve2D
+ * @see QuadCurve2D
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * @author Sven de Marothy (sven at physto.se)
+ *
+ * @since 1.2
+ */
+public final class GeneralPath implements Shape, Cloneable
+{
+ // WORKAROUND for gcj 4.0.x (x < 3)
+ // fully qualify PathIterator constants.
+
+ /** Same constant as {@link PathIterator#WIND_EVEN_ODD}. */
+ public static final int WIND_EVEN_ODD
+ = java.awt.geom.PathIterator.WIND_EVEN_ODD;
+
+ /** Same constant as {@link PathIterator.WIND_NON_ZERO}. */
+ public static final int WIND_NON_ZERO
+ = java.awt.geom.PathIterator.WIND_NON_ZERO;
+
+ /** Initial size if not specified. */
+ private static final int INIT_SIZE = 10;
+
+ /** A big number, but not so big it can't survive a few float operations */
+ private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+
+ /** The winding rule.
+ * This is package-private to avoid an accessor method.
+ */
+ int rule;
+
+ /**
+ * The path type in points. Note that xpoints[index] and ypoints[index] maps
+ * to types[index]; the control points of quad and cubic paths map as
+ * well but are ignored.
+ * This is package-private to avoid an accessor method.
+ */
+ byte[] types;
+
+ /**
+ * The list of all points seen. Since you can only append floats, it makes
+ * sense for these to be float[]. I have no idea why Sun didn't choose to
+ * allow a general path of double precision points.
+ * Note: Storing x and y coords seperately makes for a slower transforms,
+ * But it speeds up and simplifies box-intersection checking a lot.
+ * These are package-private to avoid accessor methods.
+ */
+ float[] xpoints;
+ float[] ypoints;
+
+ /** The index of the most recent moveto point, or null. */
+ private int subpath = -1;
+
+ /** The next available index into points.
+ * This is package-private to avoid an accessor method.
+ */
+ int index;
+
+ /**
+ * Constructs a GeneralPath with the default (NON_ZERO)
+ * winding rule and initial capacity (20).
+ */
+ public GeneralPath()
+ {
+ this(WIND_NON_ZERO, INIT_SIZE);
+ }
+
+ /**
+ * Constructs a GeneralPath with a specific winding rule
+ * and the default initial capacity (20).
+ * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD)
+ */
+ public GeneralPath(int rule)
+ {
+ this(rule, INIT_SIZE);
+ }
+
+ /**
+ * Constructs a GeneralPath with a specific winding rule
+ * and the initial capacity. The initial capacity should be
+ * the approximate number of path segments to be used.
+ * @param rule the winding rule (WIND_NON_ZERO or WIND_EVEN_ODD)
+ * @param capacity the inital capacity, in path segments
+ */
+ public GeneralPath(int rule, int capacity)
+ {
+ if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO)
+ throw new IllegalArgumentException();
+ this.rule = rule;
+ if (capacity < INIT_SIZE)
+ capacity = INIT_SIZE;
+ types = new byte[capacity];
+ xpoints = new float[capacity];
+ ypoints = new float[capacity];
+ }
+
+ /**
+ * Constructs a GeneralPath from an arbitrary shape object.
+ * The Shapes PathIterator path and winding rule will be used.
+ * @param s the shape
+ */
+ public GeneralPath(Shape s)
+ {
+ types = new byte[INIT_SIZE];
+ xpoints = new float[INIT_SIZE];
+ ypoints = new float[INIT_SIZE];
+ PathIterator pi = s.getPathIterator(null);
+ setWindingRule(pi.getWindingRule());
+ append(pi, false);
+ }
+
+ /**
+ * Adds a new point to a path.
+ */
+ public void moveTo(float x, float y)
+ {
+ subpath = index;
+ ensureSize(index + 1);
+ types[index] = PathIterator.SEG_MOVETO;
+ xpoints[index] = x;
+ ypoints[index++] = y;
+ }
+
+ /**
+ * Appends a straight line to the current path.
+ * @param x x coordinate of the line endpoint.
+ * @param y y coordinate of the line endpoint.
+ */
+ public void lineTo(float x, float y)
+ {
+ ensureSize(index + 1);
+ types[index] = PathIterator.SEG_LINETO;
+ xpoints[index] = x;
+ ypoints[index++] = y;
+ }
+
+ /**
+ * Appends a quadratic Bezier curve to the current path.
+ * @param x1 x coordinate of the control point
+ * @param y1 y coordinate of the control point
+ * @param x2 x coordinate of the curve endpoint.
+ * @param y2 y coordinate of the curve endpoint.
+ */
+ public void quadTo(float x1, float y1, float x2, float y2)
+ {
+ ensureSize(index + 2);
+ types[index] = PathIterator.SEG_QUADTO;
+ xpoints[index] = x1;
+ ypoints[index++] = y1;
+ xpoints[index] = x2;
+ ypoints[index++] = y2;
+ }
+
+ /**
+ * Appends a cubic Bezier curve to the current path.
+ * @param x1 x coordinate of the first control point
+ * @param y1 y coordinate of the first control point
+ * @param x2 x coordinate of the second control point
+ * @param y2 y coordinate of the second control point
+ * @param x3 x coordinate of the curve endpoint.
+ * @param y3 y coordinate of the curve endpoint.
+ */
+ public void curveTo(float x1, float y1, float x2, float y2, float x3,
+ float y3)
+ {
+ ensureSize(index + 3);
+ types[index] = PathIterator.SEG_CUBICTO;
+ xpoints[index] = x1;
+ ypoints[index++] = y1;
+ xpoints[index] = x2;
+ ypoints[index++] = y2;
+ xpoints[index] = x3;
+ ypoints[index++] = y3;
+ }
+
+ /**
+ * Closes the current subpath by drawing a line
+ * back to the point of the last moveTo, unless the path is already closed.
+ */
+ public void closePath()
+ {
+ if (index >= 1 && types[index - 1] == PathIterator.SEG_CLOSE)
+ return;
+ ensureSize(index + 1);
+ types[index] = PathIterator.SEG_CLOSE;
+ xpoints[index] = xpoints[subpath];
+ ypoints[index++] = ypoints[subpath];
+ }
+
+ /**
+ * Appends the segments of a Shape to the path. If <code>connect</code> is
+ * true, the new path segments are connected to the existing one with a line.
+ * The winding rule of the Shape is ignored.
+ */
+ public void append(Shape s, boolean connect)
+ {
+ append(s.getPathIterator(null), connect);
+ }
+
+ /**
+ * Appends the segments of a PathIterator to this GeneralPath.
+ * Optionally, the initial {@link PathIterator#SEG_MOVETO} segment
+ * of the appended path is changed into a {@link
+ * PathIterator#SEG_LINETO} segment.
+ *
+ * @param iter the PathIterator specifying which segments shall be
+ * appended.
+ *
+ * @param connect <code>true</code> for substituting the initial
+ * {@link PathIterator#SEG_MOVETO} segment by a {@link
+ * PathIterator#SEG_LINETO}, or <code>false</code> for not
+ * performing any substitution. If this GeneralPath is currently
+ * empty, <code>connect</code> is assumed to be <code>false</code>,
+ * thus leaving the initial {@link PathIterator#SEG_MOVETO}
+ * unchanged.
+ */
+ public void append(PathIterator iter, boolean connect)
+ {
+ // A bad implementation of this method had caused Classpath bug #6076.
+ float[] f = new float[6];
+ while (! iter.isDone())
+ {
+ switch (iter.currentSegment(f))
+ {
+ case PathIterator.SEG_MOVETO:
+ if (! connect || (index == 0))
+ {
+ moveTo(f[0], f[1]);
+ break;
+ }
+ if ((index >= 1) && (types[index - 1] == PathIterator.SEG_CLOSE)
+ && (f[0] == xpoints[index - 1])
+ && (f[1] == ypoints[index - 1]))
+ break;
+
+ // Fall through.
+ case PathIterator.SEG_LINETO:
+ lineTo(f[0], f[1]);
+ break;
+ case PathIterator.SEG_QUADTO:
+ quadTo(f[0], f[1], f[2], f[3]);
+ break;
+ case PathIterator.SEG_CUBICTO:
+ curveTo(f[0], f[1], f[2], f[3], f[4], f[5]);
+ break;
+ case PathIterator.SEG_CLOSE:
+ closePath();
+ break;
+ }
+
+ connect = false;
+ iter.next();
+ }
+ }
+
+ /**
+ * Returns the path’s current winding rule.
+ */
+ public int getWindingRule()
+ {
+ return rule;
+ }
+
+ /**
+ * Sets the path’s winding rule, which controls which areas are
+ * considered ’inside’ or ’outside’ the path
+ * on drawing. Valid rules are WIND_EVEN_ODD for an even-odd winding rule,
+ * or WIND_NON_ZERO for a non-zero winding rule.
+ */
+ public void setWindingRule(int rule)
+ {
+ if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO)
+ throw new IllegalArgumentException();
+ this.rule = rule;
+ }
+
+ /**
+ * Returns the current appending point of the path.
+ */
+ public Point2D getCurrentPoint()
+ {
+ if (subpath < 0)
+ return null;
+ return new Point2D.Float(xpoints[index - 1], ypoints[index - 1]);
+ }
+
+ /**
+ * Resets the path. All points and segments are destroyed.
+ */
+ public void reset()
+ {
+ subpath = -1;
+ index = 0;
+ }
+
+ /**
+ * Applies a transform to the path.
+ */
+ public void transform(AffineTransform xform)
+ {
+ double nx;
+ double ny;
+ double[] m = new double[6];
+ xform.getMatrix(m);
+ for (int i = 0; i < index; i++)
+ {
+ nx = m[0] * xpoints[i] + m[2] * ypoints[i] + m[4];
+ ny = m[1] * xpoints[i] + m[3] * ypoints[i] + m[5];
+ xpoints[i] = (float) nx;
+ ypoints[i] = (float) ny;
+ }
+ }
+
+ /**
+ * Creates a transformed version of the path.
+ * @param xform the transform to apply
+ * @return a new transformed GeneralPath
+ */
+ public Shape createTransformedShape(AffineTransform xform)
+ {
+ GeneralPath p = new GeneralPath(this);
+ p.transform(xform);
+ return p;
+ }
+
+ /**
+ * Returns the path’s bounding box.
+ */
+ public Rectangle getBounds()
+ {
+ return getBounds2D().getBounds();
+ }
+
+ /**
+ * Returns the path’s bounding box, in <code>float</code> precision
+ */
+ public Rectangle2D getBounds2D()
+ {
+ float x1;
+ float y1;
+ float x2;
+ float y2;
+
+ if (index > 0)
+ {
+ x1 = x2 = xpoints[0];
+ y1 = y2 = ypoints[0];
+ }
+ else
+ x1 = x2 = y1 = y2 = 0.0f;
+
+ for (int i = 0; i < index; i++)
+ {
+ x1 = Math.min(xpoints[i], x1);
+ y1 = Math.min(ypoints[i], y1);
+ x2 = Math.max(xpoints[i], x2);
+ y2 = Math.max(ypoints[i], y2);
+ }
+ return (new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1));
+ }
+
+ /**
+ * Evaluates if a point is within the GeneralPath,
+ * The NON_ZERO winding rule is used, regardless of the
+ * set winding rule.
+ * @param x x coordinate of the point to evaluate
+ * @param y y coordinate of the point to evaluate
+ * @return true if the point is within the path, false otherwise
+ */
+ public boolean contains(double x, double y)
+ {
+ return (getWindingNumber(x, y) != 0);
+ }
+
+ /**
+ * Evaluates if a Point2D is within the GeneralPath,
+ * The NON_ZERO winding rule is used, regardless of the
+ * set winding rule.
+ * @param p The Point2D to evaluate
+ * @return true if the point is within the path, false otherwise
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Evaluates if a rectangle is completely contained within the path.
+ * This method will return false in the cases when the box
+ * intersects an inner segment of the path.
+ * (i.e.: The method is accurate for the EVEN_ODD winding rule)
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ if (! getBounds2D().intersects(x, y, w, h))
+ return false;
+
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, false, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, false, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, true, h) != 0 /* right */
+ || getAxisIntersections(x, y, true, h) != 0) /* left */
+ return false;
+
+ /* No intersections, is any point inside? */
+ if (getWindingNumber(x, y) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Evaluates if a rectangle is completely contained within the path.
+ * This method will return false in the cases when the box
+ * intersects an inner segment of the path.
+ * (i.e.: The method is accurate for the EVEN_ODD winding rule)
+ * @param r the rectangle
+ * @return <code>true</code> if the rectangle is completely contained
+ * within the path, <code>false</code> otherwise
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Evaluates if a rectangle intersects the path.
+ * @param x x coordinate of the rectangle
+ * @param y y coordinate of the rectangle
+ * @param w width of the rectangle
+ * @param h height of the rectangle
+ * @return <code>true</code> if the rectangle intersects the path,
+ * <code>false</code> otherwise
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, false, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, false, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, true, h) != 0 /* right */
+ || getAxisIntersections(x, y, true, h) != 0) /* left */
+ return true;
+
+ /* No intersections, is any point inside? */
+ if (getWindingNumber(x, y) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Evaluates if a Rectangle2D intersects the path.
+ * @param r The rectangle
+ * @return <code>true</code> if the rectangle intersects the path,
+ * <code>false</code> otherwise
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * A PathIterator that iterates over the segments of a GeneralPath.
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ private static class GeneralPathIterator implements PathIterator
+ {
+ /**
+ * The number of coordinate values for each segment type.
+ */
+ private static final int[] NUM_COORDS = {
+ /* 0: SEG_MOVETO */ 1,
+ /* 1: SEG_LINETO */ 1,
+ /* 2: SEG_QUADTO */ 2,
+ /* 3: SEG_CUBICTO */ 3,
+ /* 4: SEG_CLOSE */ 0};
+
+ /**
+ * The GeneralPath whose segments are being iterated.
+ * This is package-private to avoid an accessor method.
+ */
+ final GeneralPath path;
+
+ /**
+ * The affine transformation used to transform coordinates.
+ */
+ private final AffineTransform transform;
+
+ /**
+ * The current position of the iterator.
+ */
+ private int pos;
+
+ /**
+ * Constructs a new iterator for enumerating the segments of a
+ * GeneralPath.
+ *
+ * @param path the path to enumerate
+ * @param transform an affine transformation for projecting the returned
+ * points, or <code>null</code> to return the original points
+ * without any mapping.
+ */
+ GeneralPathIterator(GeneralPath path, AffineTransform transform)
+ {
+ this.path = path;
+ this.transform = transform;
+ }
+
+ /**
+ * Returns the current winding rule of the GeneralPath.
+ */
+ public int getWindingRule()
+ {
+ return path.rule;
+ }
+
+ /**
+ * Determines whether the iterator has reached the last segment in
+ * the path.
+ */
+ public boolean isDone()
+ {
+ return pos >= path.index;
+ }
+
+ /**
+ * Advances the iterator position by one segment.
+ */
+ public void next()
+ {
+ int seg;
+
+ /*
+ * Increment pos by the number of coordinate pairs.
+ */
+ seg = path.types[pos];
+ if (seg == SEG_CLOSE)
+ pos++;
+ else
+ pos += NUM_COORDS[seg];
+ }
+
+ /**
+ * Returns the current segment in float coordinates.
+ */
+ public int currentSegment(float[] coords)
+ {
+ int seg;
+ int numCoords;
+
+ seg = path.types[pos];
+ numCoords = NUM_COORDS[seg];
+ if (numCoords > 0)
+ {
+ for (int i = 0; i < numCoords; i++)
+ {
+ coords[i << 1] = path.xpoints[pos + i];
+ coords[(i << 1) + 1] = path.ypoints[pos + i];
+ }
+
+ if (transform != null)
+ transform.transform( /* src */
+ coords, /* srcOffset */
+ 0, /* dest */ coords, /* destOffset */
+ 0, /* numPoints */ numCoords);
+ }
+ return seg;
+ }
+
+ /**
+ * Returns the current segment in double coordinates.
+ */
+ public int currentSegment(double[] coords)
+ {
+ int seg;
+ int numCoords;
+
+ seg = path.types[pos];
+ numCoords = NUM_COORDS[seg];
+ if (numCoords > 0)
+ {
+ for (int i = 0; i < numCoords; i++)
+ {
+ coords[i << 1] = (double) path.xpoints[pos + i];
+ coords[(i << 1) + 1] = (double) path.ypoints[pos + i];
+ }
+ if (transform != null)
+ transform.transform( /* src */
+ coords, /* srcOffset */
+ 0, /* dest */ coords, /* destOffset */
+ 0, /* numPoints */ numCoords);
+ }
+ return seg;
+ }
+ }
+
+ /**
+ * Creates a PathIterator for iterating along the segments of the path.
+ *
+ * @param at an affine transformation for projecting the returned
+ * points, or <code>null</code> to let the created iterator return
+ * the original points without any mapping.
+ */
+ public PathIterator getPathIterator(AffineTransform at)
+ {
+ return new GeneralPathIterator(this, at);
+ }
+
+ /**
+ * Creates a new FlatteningPathIterator for the path
+ */
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return new FlatteningPathIterator(getPathIterator(at), flatness);
+ }
+
+ /**
+ * Creates a new shape of the same run-time type with the same contents
+ * as this one.
+ *
+ * @return the clone
+ *
+ * @exception OutOfMemoryError If there is not enough memory available.
+ *
+ * @since 1.2
+ */
+ public Object clone()
+ {
+ // This class is final; no need to use super.clone().
+ return new GeneralPath(this);
+ }
+
+ /**
+ * Helper method - ensure the size of the data arrays,
+ * otherwise, reallocate new ones twice the size
+ */
+ private void ensureSize(int size)
+ {
+ if (subpath < 0)
+ throw new IllegalPathStateException("need initial moveto");
+ if (size <= xpoints.length)
+ return;
+ byte[] b = new byte[types.length << 1];
+ System.arraycopy(types, 0, b, 0, index);
+ types = b;
+ float[] f = new float[xpoints.length << 1];
+ System.arraycopy(xpoints, 0, f, 0, index);
+ xpoints = f;
+ f = new float[ypoints.length << 1];
+ System.arraycopy(ypoints, 0, f, 0, index);
+ ypoints = f;
+ }
+
+ /**
+ * Helper method - Get the total number of intersections from (x,y) along
+ * a given axis, within a given distance.
+ */
+ private int getAxisIntersections(double x, double y, boolean useYaxis,
+ double distance)
+ {
+ return (evaluateCrossings(x, y, false, useYaxis, distance));
+ }
+
+ /**
+ * Helper method - returns the winding number of a point.
+ */
+ private int getWindingNumber(double x, double y)
+ {
+ /* Evaluate the crossings from x,y to infinity on the y axis (arbitrary
+ choice). Note that we don't actually use Double.INFINITY, since that's
+ slower, and may cause problems. */
+ return (evaluateCrossings(x, y, true, true, BIG_VALUE));
+ }
+
+ /**
+ * Helper method - evaluates the number of intersections on an axis from
+ * the point (x,y) to the point (x,y+distance) or (x+distance,y).
+ * @param x x coordinate.
+ * @param y y coordinate.
+ * @param neg True if opposite-directed intersections should cancel,
+ * false to sum all intersections.
+ * @param useYaxis Use the Y axis, false uses the X axis.
+ * @param distance Interval from (x,y) on the selected axis to find
+ * intersections.
+ */
+ private int evaluateCrossings(double x, double y, boolean neg,
+ boolean useYaxis, double distance)
+ {
+ float cx = 0.0f;
+ float cy = 0.0f;
+ float firstx = 0.0f;
+ float firsty = 0.0f;
+
+ int negative = (neg) ? -1 : 1;
+ double x0;
+ double x1;
+ double x2;
+ double x3;
+ double y0;
+ double y1;
+ double y2;
+ double y3;
+ double[] r = new double[4];
+ int nRoots;
+ double epsilon = 0.0;
+ int pos = 0;
+ int windingNumber = 0;
+ boolean pathStarted = false;
+
+ if (index == 0)
+ return (0);
+ if (useYaxis)
+ {
+ float[] swap1;
+ swap1 = ypoints;
+ ypoints = xpoints;
+ xpoints = swap1;
+ double swap2;
+ swap2 = y;
+ y = x;
+ x = swap2;
+ }
+
+ /* Get a value which is hopefully small but not insignificant relative
+ the path. */
+ epsilon = ypoints[0] * 1E-7;
+
+ if(epsilon == 0)
+ epsilon = 1E-7;
+
+ pos = 0;
+ while (pos < index)
+ {
+ switch (types[pos])
+ {
+ case PathIterator.SEG_MOVETO:
+ if (pathStarted) // close old path
+ {
+ x0 = cx;
+ y0 = cy;
+ x1 = firstx;
+ y1 = firsty;
+
+ if (y0 == 0.0)
+ y0 -= epsilon;
+ if (y1 == 0.0)
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
+ windingNumber += (y1 < y0) ? 1 : negative;
+
+ cx = firstx;
+ cy = firsty;
+ }
+ cx = firstx = xpoints[pos] - (float) x;
+ cy = firsty = ypoints[pos++] - (float) y;
+ pathStarted = true;
+ break;
+ case PathIterator.SEG_CLOSE:
+ x0 = cx;
+ y0 = cy;
+ x1 = firstx;
+ y1 = firsty;
+
+ if (y0 == 0.0)
+ y0 -= epsilon;
+ if (y1 == 0.0)
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
+ windingNumber += (y1 < y0) ? 1 : negative;
+
+ cx = firstx;
+ cy = firsty;
+ pos++;
+ pathStarted = false;
+ break;
+ case PathIterator.SEG_LINETO:
+ x0 = cx;
+ y0 = cy;
+ x1 = xpoints[pos] - (float) x;
+ y1 = ypoints[pos++] - (float) y;
+
+ if (y0 == 0.0)
+ y0 -= epsilon;
+ if (y1 == 0.0)
+ y1 -= epsilon;
+ if (Line2D.linesIntersect(x0, y0, x1, y1,
+ epsilon, 0.0, distance, 0.0))
+ windingNumber += (y1 < y0) ? 1 : negative;
+
+ cx = xpoints[pos - 1] - (float) x;
+ cy = ypoints[pos - 1] - (float) y;
+ break;
+ case PathIterator.SEG_QUADTO:
+ x0 = cx;
+ y0 = cy;
+ x1 = xpoints[pos] - x;
+ y1 = ypoints[pos++] - y;
+ x2 = xpoints[pos] - x;
+ y2 = ypoints[pos++] - y;
+
+ /* check if curve may intersect X+ axis. */
+ if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0)
+ && (y0 * y1 <= 0 || y1 * y2 <= 0))
+ {
+ if (y0 == 0.0)
+ y0 -= epsilon;
+ if (y2 == 0.0)
+ y2 -= epsilon;
+
+ r[0] = y0;
+ r[1] = 2 * (y1 - y0);
+ r[2] = (y2 - 2 * y1 + y0);
+
+ /* degenerate roots (=tangent points) do not
+ contribute to the winding number. */
+ if ((nRoots = QuadCurve2D.solveQuadratic(r)) == 2)
+ for (int i = 0; i < nRoots; i++)
+ {
+ float t = (float) r[i];
+ if (t > 0.0f && t < 1.0f)
+ {
+ double crossing = t * t * (x2 - 2 * x1 + x0)
+ + 2 * t * (x1 - x0) + x0;
+ if (crossing >= 0.0 && crossing <= distance)
+ windingNumber += (2 * t * (y2 - 2 * y1 + y0)
+ + 2 * (y1 - y0) < 0) ? 1 : negative;
+ }
+ }
+ }
+
+ cx = xpoints[pos - 1] - (float) x;
+ cy = ypoints[pos - 1] - (float) y;
+ break;
+ case PathIterator.SEG_CUBICTO:
+ x0 = cx;
+ y0 = cy;
+ x1 = xpoints[pos] - x;
+ y1 = ypoints[pos++] - y;
+ x2 = xpoints[pos] - x;
+ y2 = ypoints[pos++] - y;
+ x3 = xpoints[pos] - x;
+ y3 = ypoints[pos++] - y;
+
+ /* check if curve may intersect X+ axis. */
+ if ((x0 > 0.0 || x1 > 0.0 || x2 > 0.0 || x3 > 0.0)
+ && (y0 * y1 <= 0 || y1 * y2 <= 0 || y2 * y3 <= 0))
+ {
+ if (y0 == 0.0)
+ y0 -= epsilon;
+ if (y3 == 0.0)
+ y3 -= epsilon;
+
+ r[0] = y0;
+ r[1] = 3 * (y1 - y0);
+ r[2] = 3 * (y2 + y0 - 2 * y1);
+ r[3] = y3 - 3 * y2 + 3 * y1 - y0;
+
+ if ((nRoots = CubicCurve2D.solveCubic(r)) != 0)
+ for (int i = 0; i < nRoots; i++)
+ {
+ float t = (float) r[i];
+ if (t > 0.0 && t < 1.0)
+ {
+ double crossing = -(t * t * t) * (x0 - 3 * x1
+ + 3 * x2 - x3)
+ + 3 * t * t * (x0 - 2 * x1 + x2)
+ + 3 * t * (x1 - x0) + x0;
+ if (crossing >= 0 && crossing <= distance)
+ windingNumber += (3 * t * t * (y3 + 3 * y1
+ - 3 * y2 - y0)
+ + 6 * t * (y0 - 2 * y1 + y2)
+ + 3 * (y1 - y0) < 0) ? 1 : negative;
+ }
+ }
+ }
+
+ cx = xpoints[pos - 1] - (float) x;
+ cy = ypoints[pos - 1] - (float) y;
+ break;
+ }
+ }
+
+ // swap coordinates back
+ if (useYaxis)
+ {
+ float[] swap;
+ swap = ypoints;
+ ypoints = xpoints;
+ xpoints = swap;
+ }
+ return (windingNumber);
+ }
+} // class GeneralPath
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/IllegalPathStateException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/IllegalPathStateException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/IllegalPathStateException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/IllegalPathStateException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,71 @@
+/* IllegalPathStateException.java -- an operation was in an illegal path state
+ Copyright (C) 2000, 2002 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.geom;
+
+/**
+ * Thrown when an operation on a path is in an illegal state, such as appending
+ * a segment to a <code>GeneralPath</code> without an initial moveto.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @see GeneralPath
+ * @status updated to 1.4
+ */
+public class IllegalPathStateException extends RuntimeException
+{
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = -5158084205220481094L;
+
+ /**
+ * Create an exception with no message.
+ */
+ public IllegalPathStateException()
+ {
+ }
+
+ /**
+ * Create an exception with a message.
+ *
+ * @param msg the message
+ */
+ public IllegalPathStateException(String msg)
+ {
+ super(msg);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Line2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Line2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Line2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Line2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1182 @@
+/* Line2D.java -- represents a line in 2-D space, plus operations on a line
+ Copyright (C) 2000, 2001, 2002 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.util.NoSuchElementException;
+
+/**
+ * Represents a directed line bewteen two points in (x,y) Cartesian space.
+ * Remember, on-screen graphics have increasing x from left-to-right, and
+ * increasing y from top-to-bottom. The storage is left to subclasses.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author David Gilbert
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class Line2D implements Shape, Cloneable
+{
+ /**
+ * The default constructor.
+ */
+ protected Line2D()
+ {
+ }
+
+ /**
+ * Return the x coordinate of the first point.
+ *
+ * @return the starting x coordinate
+ */
+ public abstract double getX1();
+
+ /**
+ * Return the y coordinate of the first point.
+ *
+ * @return the starting y coordinate
+ */
+ public abstract double getY1();
+
+ /**
+ * Return the first point.
+ *
+ * @return the starting point
+ */
+ public abstract Point2D getP1();
+
+ /**
+ * Return the x coordinate of the second point.
+ *
+ * @return the ending x coordinate
+ */
+ public abstract double getX2();
+
+ /**
+ * Return the y coordinate of the second point.
+ *
+ * @return the ending y coordinate
+ */
+ public abstract double getY2();
+
+ /**
+ * Return the second point.
+ *
+ * @return the ending point
+ */
+ public abstract Point2D getP2();
+
+ /**
+ * Set the coordinates of the line to the given coordinates. Loss of
+ * precision may occur due to rounding issues.
+ *
+ * @param x1 the first x coordinate
+ * @param y1 the first y coordinate
+ * @param x2 the second x coordinate
+ * @param y2 the second y coordinate
+ */
+ public abstract void setLine(double x1, double y1, double x2, double y2);
+
+ /**
+ * Set the coordinates to the given points.
+ *
+ * @param p1 the first point
+ * @param p2 the second point
+ * @throws NullPointerException if either point is null
+ */
+ public void setLine(Point2D p1, Point2D p2)
+ {
+ setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
+ }
+
+ /**
+ * Set the coordinates to those of the given line.
+ *
+ * @param l the line to copy
+ * @throws NullPointerException if l is null
+ */
+ public void setLine(Line2D l)
+ {
+ setLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
+ }
+
+ /**
+ * Computes the relative rotation direction needed to pivot the line about
+ * the first point in order to have the second point colinear with point p.
+ * Because of floating point rounding, don't expect this to be a perfect
+ * measure of colinearity. The answer is 1 if the line has a shorter rotation
+ * in the direction of the positive X axis to the negative Y axis
+ * (counter-clockwise in the default Java coordinate system), or -1 if the
+ * shortest rotation is in the opposite direction (clockwise). If p
+ * is already colinear, the return value is -1 if it lies beyond the first
+ * point, 0 if it lies in the segment, or 1 if it lies beyond the second
+ * point. If the first and second point are coincident, this returns 0.
+ *
+ * @param x1 the first x coordinate
+ * @param y1 the first y coordinate
+ * @param x2 the second x coordinate
+ * @param y2 the second y coordinate
+ * @param px the reference x coordinate
+ * @param py the reference y coordinate
+ * @return the relative rotation direction
+ */
+ public static int relativeCCW(double x1, double y1, double x2, double y2,
+ double px, double py)
+ {
+ if ((x1 == x2 && y1 == y2)
+ || (x1 == px && y1 == py))
+ return 0; // Coincident points.
+ // Translate to the origin.
+ x2 -= x1;
+ y2 -= y1;
+ px -= x1;
+ py -= y1;
+ double slope2 = y2 / x2;
+ double slopep = py / px;
+ if (slope2 == slopep || (x2 == 0 && px == 0))
+ return y2 > 0 // Colinear.
+ ? (py < 0 ? -1 : py > y2 ? 1 : 0)
+ : (py > 0 ? -1 : py < y2 ? 1 : 0);
+ if (x2 >= 0 && slope2 >= 0)
+ return px >= 0 // Quadrant 1.
+ ? (slope2 > slopep ? 1 : -1)
+ : (slope2 < slopep ? 1 : -1);
+ if (y2 > 0)
+ return px < 0 // Quadrant 2.
+ ? (slope2 > slopep ? 1 : -1)
+ : (slope2 < slopep ? 1 : -1);
+ if (slope2 >= 0.0)
+ return px >= 0 // Quadrant 3.
+ ? (slope2 < slopep ? 1 : -1)
+ : (slope2 > slopep ? 1 : -1);
+ return px < 0 // Quadrant 4.
+ ? (slope2 < slopep ? 1 : -1)
+ : (slope2 > slopep ? 1 : -1);
+ }
+
+ /**
+ * Computes the relative rotation direction needed to pivot this line about
+ * the first point in order to have the second point colinear with point p.
+ * Because of floating point rounding, don't expect this to be a perfect
+ * measure of colinearity. The answer is 1 if the line has a shorter rotation
+ * in the direction of the positive X axis to the negative Y axis
+ * (counter-clockwise in the default Java coordinate system), or -1 if the
+ * shortest rotation is in the opposite direction (clockwise). If p
+ * is already colinear, the return value is -1 if it lies beyond the first
+ * point, 0 if it lies in the segment, or 1 if it lies beyond the second
+ * point. If the first and second point are coincident, this returns 0.
+ *
+ * @param px the reference x coordinate
+ * @param py the reference y coordinate
+ * @return the relative rotation direction
+ * @see #relativeCCW(double, double, double, double, double, double)
+ */
+ public int relativeCCW(double px, double py)
+ {
+ return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py);
+ }
+
+ /**
+ * Computes the relative rotation direction needed to pivot this line about
+ * the first point in order to have the second point colinear with point p.
+ * Because of floating point rounding, don't expect this to be a perfect
+ * measure of colinearity. The answer is 1 if the line has a shorter rotation
+ * in the direction of the positive X axis to the negative Y axis
+ * (counter-clockwise in the default Java coordinate system), or -1 if the
+ * shortest rotation is in the opposite direction (clockwise). If p
+ * is already colinear, the return value is -1 if it lies beyond the first
+ * point, 0 if it lies in the segment, or 1 if it lies beyond the second
+ * point. If the first and second point are coincident, this returns 0.
+ *
+ * @param p the reference point
+ * @return the relative rotation direction
+ * @throws NullPointerException if p is null
+ * @see #relativeCCW(double, double, double, double, double, double)
+ */
+ public int relativeCCW(Point2D p)
+ {
+ return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
+ }
+
+ /**
+ * Computes twice the (signed) area of the triangle defined by the three
+ * points. This method is used for intersection testing.
+ *
+ * @param x1 the x-coordinate of the first point.
+ * @param y1 the y-coordinate of the first point.
+ * @param x2 the x-coordinate of the second point.
+ * @param y2 the y-coordinate of the second point.
+ * @param x3 the x-coordinate of the third point.
+ * @param y3 the y-coordinate of the third point.
+ *
+ * @return Twice the area.
+ */
+ private static double area2(double x1, double y1,
+ double x2, double y2,
+ double x3, double y3)
+ {
+ return (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
+ }
+
+ /**
+ * Returns <code>true</code> if (x3, y3) lies between (x1, y1) and (x2, y2),
+ * and false otherwise, This test assumes that the three points are
+ * collinear, and is used for intersection testing.
+ *
+ * @param x1 the x-coordinate of the first point.
+ * @param y1 the y-coordinate of the first point.
+ * @param x2 the x-coordinate of the second point.
+ * @param y2 the y-coordinate of the second point.
+ * @param x3 the x-coordinate of the third point.
+ * @param y3 the y-coordinate of the third point.
+ *
+ * @return A boolean.
+ */
+ private static boolean between(double x1, double y1,
+ double x2, double y2,
+ double x3, double y3)
+ {
+ if (x1 != x2) {
+ return (x1 <= x3 && x3 <= x2) || (x1 >= x3 && x3 >= x2);
+ }
+ else {
+ return (y1 <= y3 && y3 <= y2) || (y1 >= y3 && y3 >= y2);
+ }
+ }
+
+ /**
+ * Test if the line segment (x1,y1)->(x2,y2) intersects the line segment
+ * (x3,y3)->(x4,y4).
+ *
+ * @param x1 the first x coordinate of the first segment
+ * @param y1 the first y coordinate of the first segment
+ * @param x2 the second x coordinate of the first segment
+ * @param y2 the second y coordinate of the first segment
+ * @param x3 the first x coordinate of the second segment
+ * @param y3 the first y coordinate of the second segment
+ * @param x4 the second x coordinate of the second segment
+ * @param y4 the second y coordinate of the second segment
+ * @return true if the segments intersect
+ */
+ public static boolean linesIntersect(double x1, double y1,
+ double x2, double y2,
+ double x3, double y3,
+ double x4, double y4)
+ {
+ double a1, a2, a3, a4;
+
+ // deal with special cases
+ if ((a1 = area2(x1, y1, x2, y2, x3, y3)) == 0.0)
+ {
+ // check if p3 is between p1 and p2 OR
+ // p4 is collinear also AND either between p1 and p2 OR at opposite ends
+ if (between(x1, y1, x2, y2, x3, y3))
+ {
+ return true;
+ }
+ else
+ {
+ if (area2(x1, y1, x2, y2, x4, y4) == 0.0)
+ {
+ return between(x3, y3, x4, y4, x1, y1)
+ || between (x3, y3, x4, y4, x2, y2);
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ else if ((a2 = area2(x1, y1, x2, y2, x4, y4)) == 0.0)
+ {
+ // check if p4 is between p1 and p2 (we already know p3 is not
+ // collinear)
+ return between(x1, y1, x2, y2, x4, y4);
+ }
+
+ if ((a3 = area2(x3, y3, x4, y4, x1, y1)) == 0.0) {
+ // check if p1 is between p3 and p4 OR
+ // p2 is collinear also AND either between p1 and p2 OR at opposite ends
+ if (between(x3, y3, x4, y4, x1, y1)) {
+ return true;
+ }
+ else {
+ if (area2(x3, y3, x4, y4, x2, y2) == 0.0) {
+ return between(x1, y1, x2, y2, x3, y3)
+ || between (x1, y1, x2, y2, x4, y4);
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ else if ((a4 = area2(x3, y3, x4, y4, x2, y2)) == 0.0) {
+ // check if p2 is between p3 and p4 (we already know p1 is not
+ // collinear)
+ return between(x3, y3, x4, y4, x2, y2);
+ }
+ else { // test for regular intersection
+ return ((a1 > 0.0) ^ (a2 > 0.0)) && ((a3 > 0.0) ^ (a4 > 0.0));
+ }
+ }
+
+ /**
+ * Test if this line intersects the line given by (x1,y1)->(x2,y2).
+ *
+ * @param x1 the first x coordinate of the other segment
+ * @param y1 the first y coordinate of the other segment
+ * @param x2 the second x coordinate of the other segment
+ * @param y2 the second y coordinate of the other segment
+ * @return true if the segments intersect
+ * @see #linesIntersect(double, double, double, double,
+ * double, double, double, double)
+ */
+ public boolean intersectsLine(double x1, double y1, double x2, double y2)
+ {
+ return linesIntersect(getX1(), getY1(), getX2(), getY2(),
+ x1, y1, x2, y2);
+ }
+
+ /**
+ * Test if this line intersects the given line.
+ *
+ * @param l the other segment
+ * @return true if the segments intersect
+ * @throws NullPointerException if l is null
+ * @see #linesIntersect(double, double, double, double,
+ * double, double, double, double)
+ */
+ public boolean intersectsLine(Line2D l)
+ {
+ return linesIntersect(getX1(), getY1(), getX2(), getY2(),
+ l.getX1(), l.getY1(), l.getX2(), l.getY2());
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on the line segment. If the point is on the segment, the
+ * result will be 0.
+ *
+ * @param x1 the first x coordinate of the segment
+ * @param y1 the first y coordinate of the segment
+ * @param x2 the second x coordinate of the segment
+ * @param y2 the second y coordinate of the segment
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the square of the distance from the point to the segment
+ * @see #ptSegDist(double, double, double, double, double, double)
+ * @see #ptLineDistSq(double, double, double, double, double, double)
+ */
+ public static double ptSegDistSq(double x1, double y1, double x2, double y2,
+ double px, double py)
+ {
+ double pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
+
+ double x, y;
+ if (pd2 == 0)
+ {
+ // Points are coincident.
+ x = x1;
+ y = y2;
+ }
+ else
+ {
+ double u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2;
+
+ if (u < 0)
+ {
+ // "Off the end"
+ x = x1;
+ y = y1;
+ }
+ else if (u > 1.0)
+ {
+ x = x2;
+ y = y2;
+ }
+ else
+ {
+ x = x1 + u * (x2 - x1);
+ y = y1 + u * (y2 - y1);
+ }
+ }
+
+ return (x - px) * (x - px) + (y - py) * (y - py);
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * the line segment. If the point is on the segment, the result will be 0.
+ *
+ * @param x1 the first x coordinate of the segment
+ * @param y1 the first y coordinate of the segment
+ * @param x2 the second x coordinate of the segment
+ * @param y2 the second y coordinate of the segment
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the distance from the point to the segment
+ * @see #ptSegDistSq(double, double, double, double, double, double)
+ * @see #ptLineDist(double, double, double, double, double, double)
+ */
+ public static double ptSegDist(double x1, double y1, double x2, double y2,
+ double px, double py)
+ {
+ return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py));
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on this line segment. If the point is on the segment, the
+ * result will be 0.
+ *
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the square of the distance from the point to the segment
+ * @see #ptSegDistSq(double, double, double, double, double, double)
+ */
+ public double ptSegDistSq(double px, double py)
+ {
+ return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on this line segment. If the point is on the segment, the
+ * result will be 0.
+ *
+ * @param p the point
+ * @return the square of the distance from the point to the segment
+ * @throws NullPointerException if p is null
+ * @see #ptSegDistSq(double, double, double, double, double, double)
+ */
+ public double ptSegDistSq(Point2D p)
+ {
+ return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * this line segment. If the point is on the segment, the result will be 0.
+ *
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the distance from the point to the segment
+ * @see #ptSegDist(double, double, double, double, double, double)
+ */
+ public double ptSegDist(double px, double py)
+ {
+ return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py);
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * this line segment. If the point is on the segment, the result will be 0.
+ *
+ * @param p the point
+ * @return the distance from the point to the segment
+ * @throws NullPointerException if p is null
+ * @see #ptSegDist(double, double, double, double, double, double)
+ */
+ public double ptSegDist(Point2D p)
+ {
+ return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on the infinite line extended from the segment. If the point
+ * is on the segment, the result will be 0. If the segment is length 0,
+ * the distance is to the common endpoint.
+ *
+ * @param x1 the first x coordinate of the segment
+ * @param y1 the first y coordinate of the segment
+ * @param x2 the second x coordinate of the segment
+ * @param y2 the second y coordinate of the segment
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the square of the distance from the point to the extended line
+ * @see #ptLineDist(double, double, double, double, double, double)
+ * @see #ptSegDistSq(double, double, double, double, double, double)
+ */
+ public static double ptLineDistSq(double x1, double y1, double x2, double y2,
+ double px, double py)
+ {
+ double pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
+
+ double x, y;
+ if (pd2 == 0)
+ {
+ // Points are coincident.
+ x = x1;
+ y = y2;
+ }
+ else
+ {
+ double u = ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / pd2;
+ x = x1 + u * (x2 - x1);
+ y = y1 + u * (y2 - y1);
+ }
+
+ return (x - px) * (x - px) + (y - py) * (y - py);
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * the infinite line extended from the segment. If the point is on the
+ * segment, the result will be 0. If the segment is length 0, the distance
+ * is to the common endpoint.
+ *
+ * @param x1 the first x coordinate of the segment
+ * @param y1 the first y coordinate of the segment
+ * @param x2 the second x coordinate of the segment
+ * @param y2 the second y coordinate of the segment
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the distance from the point to the extended line
+ * @see #ptLineDistSq(double, double, double, double, double, double)
+ * @see #ptSegDist(double, double, double, double, double, double)
+ */
+ public static double ptLineDist(double x1, double y1,
+ double x2, double y2,
+ double px, double py)
+ {
+ return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py));
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on the infinite line extended from this segment. If the point
+ * is on the segment, the result will be 0. If the segment is length 0,
+ * the distance is to the common endpoint.
+ *
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the square of the distance from the point to the extended line
+ * @see #ptLineDistSq(double, double, double, double, double, double)
+ */
+ public double ptLineDistSq(double px, double py)
+ {
+ return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
+ }
+
+ /**
+ * Measures the square of the shortest distance from the reference point
+ * to a point on the infinite line extended from this segment. If the point
+ * is on the segment, the result will be 0. If the segment is length 0,
+ * the distance is to the common endpoint.
+ *
+ * @param p the point
+ * @return the square of the distance from the point to the extended line
+ * @throws NullPointerException if p is null
+ * @see #ptLineDistSq(double, double, double, double, double, double)
+ */
+ public double ptLineDistSq(Point2D p)
+ {
+ return ptLineDistSq(getX1(), getY1(), getX2(), getY2(),
+ p.getX(), p.getY());
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * the infinite line extended from this segment. If the point is on the
+ * segment, the result will be 0. If the segment is length 0, the distance
+ * is to the common endpoint.
+ *
+ * @param px the x coordinate of the point
+ * @param py the y coordinate of the point
+ * @return the distance from the point to the extended line
+ * @see #ptLineDist(double, double, double, double, double, double)
+ */
+ public double ptLineDist(double px, double py)
+ {
+ return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py);
+ }
+
+ /**
+ * Measures the shortest distance from the reference point to a point on
+ * the infinite line extended from this segment. If the point is on the
+ * segment, the result will be 0. If the segment is length 0, the distance
+ * is to the common endpoint.
+ *
+ * @param p the point
+ * @return the distance from the point to the extended line
+ * @throws NullPointerException if p is null
+ * @see #ptLineDist(double, double, double, double, double, double)
+ */
+ public double ptLineDist(Point2D p)
+ {
+ return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
+ }
+
+ /**
+ * Test if a point is contained inside the line. Since a line has no area,
+ * this returns false.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @return false; the line does not contain points
+ */
+ public boolean contains(double x, double y)
+ {
+ return false;
+ }
+
+ /**
+ * Test if a point is contained inside the line. Since a line has no area,
+ * this returns false.
+ *
+ * @param p the point
+ * @return false; the line does not contain points
+ */
+ public boolean contains(Point2D p)
+ {
+ return false;
+ }
+
+ /**
+ * Tests if this line intersects the interior of the specified rectangle.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @return true if the line intersects the rectangle
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ if (w <= 0 || h <= 0)
+ return false;
+ double x1 = getX1();
+ double y1 = getY1();
+ double x2 = getX2();
+ double y2 = getY2();
+
+ if (x1 >= x && x1 <= x + w && y1 >= y && y1 <= y + h)
+ return true;
+ if (x2 >= x && x2 <= x + w && y2 >= y && y2 <= y + h)
+ return true;
+
+ double x3 = x + w;
+ double y3 = y + h;
+
+ return (linesIntersect(x1, y1, x2, y2, x, y, x, y3)
+ || linesIntersect(x1, y1, x2, y2, x, y3, x3, y3)
+ || linesIntersect(x1, y1, x2, y2, x3, y3, x3, y)
+ || linesIntersect(x1, y1, x2, y2, x3, y, x, y));
+ }
+
+ /**
+ * Tests if this line intersects the interior of the specified rectangle.
+ *
+ * @param r the rectangle
+ * @return true if the line intersects the rectangle
+ * @throws NullPointerException if r is null
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Tests if the line contains a rectangle. Since lines have no area, this
+ * always returns false.
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @return false; the line does not contain points
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ return false;
+ }
+
+ /**
+ * Tests if the line contains a rectangle. Since lines have no area, this
+ * always returns false.
+ *
+ * @param r the rectangle
+ * @return false; the line does not contain points
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return false;
+ }
+
+ /**
+ * Gets a bounding box (not necessarily minimal) for this line.
+ *
+ * @return the integer bounding box
+ * @see #getBounds2D()
+ */
+ public Rectangle getBounds()
+ {
+ return getBounds2D().getBounds();
+ }
+
+ /**
+ * Return a path iterator, possibly applying a transform on the result. This
+ * iterator is not threadsafe.
+ *
+ * @param at the transform, or null
+ * @return a new path iterator
+ */
+ public PathIterator getPathIterator(final AffineTransform at)
+ {
+ return new PathIterator()
+ {
+ /** Current coordinate. */
+ private int current = 0;
+
+ public int getWindingRule()
+ {
+ return WIND_NON_ZERO;
+ }
+
+ public boolean isDone()
+ {
+ return current >= 2;
+ }
+
+ public void next()
+ {
+ current++;
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = (float) getX1();
+ coords[1] = (float) getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = (float) getX2();
+ coords[1] = (float) getY2();
+ result = SEG_LINETO;
+ break;
+ default:
+ throw new NoSuchElementException("line iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return result;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = getX1();
+ coords[1] = getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = getX2();
+ coords[1] = getY2();
+ result = SEG_LINETO;
+ break;
+ default:
+ throw new NoSuchElementException("line iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return result;
+ }
+ };
+ }
+
+ /**
+ * Return a flat path iterator, possibly applying a transform on the result.
+ * This iterator is not threadsafe.
+ *
+ * @param at the transform, or null
+ * @param flatness ignored, since lines are already flat
+ * @return a new path iterator
+ * @see #getPathIterator(AffineTransform)
+ */
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return getPathIterator(at);
+ }
+
+ /**
+ * Create a new line of the same run-time type with the same contents as
+ * this one.
+ *
+ * @return the clone
+ *
+ * @exception OutOfMemoryError If there is not enough memory available.
+ *
+ * @since 1.2
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * This class defines a point in <code>double</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Double extends Line2D
+ {
+ /** The x coordinate of the first point. */
+ public double x1;
+
+ /** The y coordinate of the first point. */
+ public double y1;
+
+ /** The x coordinate of the second point. */
+ public double x2;
+
+ /** The y coordinate of the second point. */
+ public double y2;
+
+ /**
+ * Construct the line segment (0,0)->(0,0).
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Construct the line segment with the specified points.
+ *
+ * @param x1 the x coordinate of the first point
+ * @param y1 the y coordinate of the first point
+ * @param x2 the x coordinate of the second point
+ * @param y2 the y coordinate of the second point
+ */
+ public Double(double x1, double y1, double x2, double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Construct the line segment with the specified points.
+ *
+ * @param p1 the first point
+ * @param p2 the second point
+ * @throws NullPointerException if either point is null
+ */
+ public Double(Point2D p1, Point2D p2)
+ {
+ x1 = p1.getX();
+ y1 = p1.getY();
+ x2 = p2.getX();
+ y2 = p2.getY();
+ }
+
+ /**
+ * Return the x coordinate of the first point.
+ *
+ * @return the value of x1
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Return the y coordinate of the first point.
+ *
+ * @return the value of y1
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Return the first point.
+ *
+ * @return the point (x1,y1)
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Double(x1, y1);
+ }
+
+ /**
+ * Return the x coordinate of the second point.
+ *
+ * @return the value of x2
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Return the y coordinate of the second point.
+ *
+ * @return the value of y2
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Return the second point.
+ *
+ * @return the point (x2,y2)
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Double(x2, y2);
+ }
+
+ /**
+ * Set this line to the given points.
+ *
+ * @param x1 the new x coordinate of the first point
+ * @param y1 the new y coordinate of the first point
+ * @param x2 the new x coordinate of the second point
+ * @param y2 the new y coordinate of the second point
+ */
+ public void setLine(double x1, double y1, double x2, double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Return the exact bounds of this line segment.
+ *
+ * @return the bounding box
+ */
+ public Rectangle2D getBounds2D()
+ {
+ double x = Math.min(x1, x2);
+ double y = Math.min(y1, y2);
+ double w = Math.abs(x1 - x2);
+ double h = Math.abs(y1 - y2);
+ return new Rectangle2D.Double(x, y, w, h);
+ }
+ } // class Double
+
+ /**
+ * This class defines a point in <code>float</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Float extends Line2D
+ {
+ /** The x coordinate of the first point. */
+ public float x1;
+
+ /** The y coordinate of the first point. */
+ public float y1;
+
+ /** The x coordinate of the second point. */
+ public float x2;
+
+ /** The y coordinate of the second point. */
+ public float y2;
+
+ /**
+ * Construct the line segment (0,0)->(0,0).
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Construct the line segment with the specified points.
+ *
+ * @param x1 the x coordinate of the first point
+ * @param y1 the y coordinate of the first point
+ * @param x2 the x coordinate of the second point
+ * @param y2 the y coordinate of the second point
+ */
+ public Float(float x1, float y1, float x2, float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Construct the line segment with the specified points.
+ *
+ * @param p1 the first point
+ * @param p2 the second point
+ * @throws NullPointerException if either point is null
+ */
+ public Float(Point2D p1, Point2D p2)
+ {
+ x1 = (float) p1.getX();
+ y1 = (float) p1.getY();
+ x2 = (float) p2.getX();
+ y2 = (float) p2.getY();
+ }
+
+ /**
+ * Return the x coordinate of the first point.
+ *
+ * @return the value of x1
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Return the y coordinate of the first point.
+ *
+ * @return the value of y1
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Return the first point.
+ *
+ * @return the point (x1,y1)
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Float(x1, y1);
+ }
+
+ /**
+ * Return the x coordinate of the second point.
+ *
+ * @return the value of x2
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Return the y coordinate of the second point.
+ *
+ * @return the value of y2
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Return the second point.
+ *
+ * @return the point (x2,y2)
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Float(x2, y2);
+ }
+
+ /**
+ * Set this line to the given points.
+ *
+ * @param x1 the new x coordinate of the first point
+ * @param y1 the new y coordinate of the first point
+ * @param x2 the new x coordinate of the second point
+ * @param y2 the new y coordinate of the second point
+ */
+ public void setLine(double x1, double y1, double x2, double y2)
+ {
+ this.x1 = (float) x1;
+ this.y1 = (float) y1;
+ this.x2 = (float) x2;
+ this.y2 = (float) y2;
+ }
+
+ /**
+ * Set this line to the given points.
+ *
+ * @param x1 the new x coordinate of the first point
+ * @param y1 the new y coordinate of the first point
+ * @param x2 the new x coordinate of the second point
+ * @param y2 the new y coordinate of the second point
+ */
+ public void setLine(float x1, float y1, float x2, float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Return the exact bounds of this line segment.
+ *
+ * @return the bounding box
+ */
+ public Rectangle2D getBounds2D()
+ {
+ float x = Math.min(x1, x2);
+ float y = Math.min(y1, y2);
+ float w = Math.abs(x1 - x2);
+ float h = Math.abs(y1 - y2);
+ return new Rectangle2D.Float(x, y, w, h);
+ }
+ } // class Float
+} // class Line2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/NoninvertibleTransformException.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/NoninvertibleTransformException.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/NoninvertibleTransformException.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/NoninvertibleTransformException.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,65 @@
+/* NoninvertibleTransformException.java -- a transform can't be inverted
+ Copyright (C) 2000, 2002 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.geom;
+
+/**
+ * Thrown if an operation requires an inverse of an
+ * <code>AffineTransform</code>, but the transform is in a non-invertible
+ * state.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @see AffineTransform
+ * @status updated to 1.4
+ */
+public class NoninvertibleTransformException extends Exception
+{
+ /**
+ * Compatible with JDK 1.2+.
+ */
+ private static final long serialVersionUID = 6137225240503990466L;
+
+ /**
+ * Create an exception with a message.
+ *
+ * @param s the message
+ */
+ public NoninvertibleTransformException(String s)
+ {
+ super(s);
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/PathIterator.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/PathIterator.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/PathIterator.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/PathIterator.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,189 @@
+/* PathIterator.java -- describes a shape by iterating over its vertices
+ Copyright (C) 2000, 2002, 2003 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.geom;
+
+/**
+ * This interface provides a directed path over the boundary of a shape. The
+ * path can contain 1st through 3rd order Bezier curves (lines, and quadratic
+ * and cubic splines). A shape can have multiple disjoint paths via the
+ * MOVETO directive, and can close a circular path back to the previos
+ * MOVETO via the CLOSE directive.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see java.awt.Shape
+ * @see java.awt.Stroke
+ * @see FlatteningPathIterator
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface PathIterator
+{
+ /**
+ * The even-odd winding mode: a point is internal to the shape if a ray
+ * from the point to infinity (in any direction) crosses an odd number of
+ * segments.
+ */
+ int WIND_EVEN_ODD = 0;
+
+ /**
+ * The non-zero winding mode: a point is internal to the shape if a ray
+ * from the point to infinity (in any direction) crosses a different number
+ * of segments headed clockwise than those headed counterclockwise.
+ */
+ int WIND_NON_ZERO = 1;
+
+ /**
+ * Starts a new subpath. There is no segment from the previous vertex.
+ */
+ int SEG_MOVETO = 0;
+
+ /**
+ * The current segment is a line.
+ */
+ int SEG_LINETO = 1;
+
+ /**
+ * The current segment is a quadratic parametric curve. It is interpolated
+ * as t varies from 0 to 1 over the current point (CP), first control point
+ * (P1), and final interpolated control point (P2):
+ * <pre>
+ * P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2
+ * 0 <= t <= 1
+ * B(n,m) = mth coefficient of nth degree Bernstein polynomial
+ * = C(n,m) * t^(m) * (1 - t)^(n-m)
+ * C(n,m) = Combinations of n things, taken m at a time
+ * = n! / (m! * (n-m)!)
+ * </pre>
+ */
+ int SEG_QUADTO = 2;
+
+ /**
+ * The current segment is a cubic parametric curve (more commonly known as
+ * a Bezier curve). It is interpolated as t varies from 0 to 1 over the
+ * current point (CP), first control point (P1), the second control point
+ * (P2), and final interpolated control point (P3):
+ * <pre>
+ * P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3
+ * 0 <= t <= 1
+ * B(n,m) = mth coefficient of nth degree Bernstein polynomial
+ * = C(n,m) * t^(m) * (1 - t)^(n-m)
+ * C(n,m) = Combinations of n things, taken m at a time
+ * = n! / (m! * (n-m)!)
+ * </pre>
+ */
+ int SEG_CUBICTO = 3;
+
+ /**
+ * The current segment closes a loop by an implicit line to the previous
+ * SEG_MOVETO coordinate.
+ */
+ int SEG_CLOSE = 4;
+
+ /**
+ * Returns the winding rule to determine which points are inside this path.
+ *
+ * @return the winding rule
+ * @see #WIND_EVEN_ODD
+ * @see #WIND_NON_ZERO
+ */
+ int getWindingRule();
+
+ /**
+ * Tests if the iterator is exhausted. If this returns true, currentSegment
+ * and next may throw a NoSuchElementException (although this is not
+ * required).
+ *
+ * @return true if the iteration is complete
+ */
+ boolean isDone();
+
+ /**
+ * Advance to the next segment in the iteration. It is not specified what
+ * this does if called when isDone() returns true.
+ *
+ * @throws java.util.NoSuchElementException optional when isDone() is true
+ */
+ void next();
+
+ /**
+ * Returns the coordinates of the next point(s), as well as the type of
+ * line segment. The input array must be at least a float[6], to accomodate
+ * up to three (x,y) point pairs (although if you know the iterator is
+ * flat, you can probably get by with a float[2]). If the returned type is
+ * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if
+ * the returned type is SEG_QUADTO, the first two points are modified; if
+ * the returned type is SEG_CUBICTO, all three points are modified; and if
+ * the returned type is SEG_CLOSE, the array is untouched.
+ *
+ * @param coords the array to place the point coordinates in
+ * @return the segment type
+ * @throws NullPointerException if coords is null
+ * @throws ArrayIndexOutOfBoundsException if coords is too small
+ * @throws java.util.NoSuchElementException optional when isDone() is true
+ * @see #SEG_MOVETO
+ * @see #SEG_LINETO
+ * @see #SEG_QUADTO
+ * @see #SEG_CUBICTO
+ * @see #SEG_CLOSE
+ */
+ int currentSegment(float[] coords);
+
+ /**
+ * Returns the coordinates of the next point(s), as well as the type of
+ * line segment. The input array must be at least a double[6], to accomodate
+ * up to three (x,y) point pairs (although if you know the iterator is
+ * flat, you can probably get by with a double[2]). If the returned type is
+ * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if
+ * the returned type is SEG_QUADTO, the first two points are modified; if
+ * the returned type is SEG_CUBICTO, all three points are modified; and if
+ * the returned type is SEG_CLOSE, the array is untouched.
+ *
+ * @param coords the array to place the point coordinates in
+ * @return the segment type
+ * @throws NullPointerException if coords is null
+ * @throws ArrayIndexOutOfBoundsException if coords is too small
+ * @throws java.util.NoSuchElementException optional when isDone() is true
+ * @see #SEG_MOVETO
+ * @see #SEG_LINETO
+ * @see #SEG_QUADTO
+ * @see #SEG_CUBICTO
+ * @see #SEG_CLOSE
+ */
+ int currentSegment(double[] coords);
+} // interface PathIterator
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Point2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Point2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Point2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Point2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,396 @@
+/* Point2D.java -- generic point in 2-D space
+ Copyright (C) 1999, 2000, 2002, 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.geom;
+
+/**
+ * This class implements a generic point in 2D Cartesian space. The storage
+ * representation is left up to the subclass. Point includes two useful
+ * nested classes, for float and double storage respectively.
+ *
+ * @author Per Bothner (bothner at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class Point2D implements Cloneable
+{
+ /**
+ * The default constructor.
+ *
+ * @see java.awt.Point
+ * @see Point2D.Float
+ * @see Point2D.Double
+ */
+ protected Point2D()
+ {
+ }
+
+ /**
+ * Get the X coordinate, in double precision.
+ *
+ * @return the x coordinate
+ */
+ public abstract double getX();
+
+ /**
+ * Get the Y coordinate, in double precision.
+ *
+ * @return the y coordinate
+ */
+ public abstract double getY();
+
+ /**
+ * Set the location of this point to the new coordinates. There may be a
+ * loss of precision.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ */
+ public abstract void setLocation(double x, double y);
+
+ /**
+ * Set the location of this point to the new coordinates. There may be a
+ * loss of precision.
+ *
+ * @param p the point to copy
+ * @throws NullPointerException if p is null
+ */
+ public void setLocation(Point2D p)
+ {
+ setLocation(p.getX(), p.getY());
+ }
+
+ /**
+ * Return the square of the distance between two points.
+ *
+ * @param x1 the x coordinate of point 1
+ * @param y1 the y coordinate of point 1
+ * @param x2 the x coordinate of point 2
+ * @param y2 the y coordinate of point 2
+ * @return (x2 - x1)^2 + (y2 - y1)^2
+ */
+ public static double distanceSq(double x1, double y1, double x2, double y2)
+ {
+ x2 -= x1;
+ y2 -= y1;
+ return x2 * x2 + y2 * y2;
+ }
+
+ /**
+ * Return the distance between two points.
+ *
+ * @param x1 the x coordinate of point 1
+ * @param y1 the y coordinate of point 1
+ * @param x2 the x coordinate of point 2
+ * @param y2 the y coordinate of point 2
+ * @return the distance from (x1,y1) to (x2,y2)
+ */
+ public static double distance(double x1, double y1, double x2, double y2)
+ {
+ return Math.sqrt(distanceSq(x1, y1, x2, y2));
+ }
+
+ /**
+ * Return the square of the distance from this point to the given one.
+ *
+ * @param x the x coordinate of the other point
+ * @param y the y coordinate of the other point
+ * @return the square of the distance
+ */
+ public double distanceSq(double x, double y)
+ {
+ return distanceSq(getX(), getY(), x, y);
+ }
+
+ /**
+ * Return the square of the distance from this point to the given one.
+ *
+ * @param p the other point
+ * @return the square of the distance
+ * @throws NullPointerException if p is null
+ */
+ public double distanceSq(Point2D p)
+ {
+ return distanceSq(getX(), getY(), p.getX(), p.getY());
+ }
+
+ /**
+ * Return the distance from this point to the given one.
+ *
+ * @param x the x coordinate of the other point
+ * @param y the y coordinate of the other point
+ * @return the distance
+ */
+ public double distance(double x, double y)
+ {
+ return distance(getX(), getY(), x, y);
+ }
+
+ /**
+ * Return the distance from this point to the given one.
+ *
+ * @param p the other point
+ * @return the distance
+ * @throws NullPointerException if p is null
+ */
+ public double distance(Point2D p)
+ {
+ return distance(getX(), getY(), p.getX(), p.getY());
+ }
+
+ /**
+ * Create a new point of the same run-time type with the same contents as
+ * this one.
+ *
+ * @return the clone
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * Return the hashcode for this point. The formula is not documented, but
+ * appears to be the same as:
+ * <pre>
+ * long l = Double.doubleToLongBits(getY());
+ * l = l * 31 ^ Double.doubleToLongBits(getX());
+ * return (int) ((l >> 32) ^ l);
+ * </pre>
+ *
+ * @return the hashcode
+ */
+ public int hashCode()
+ {
+ // Talk about a fun time reverse engineering this one!
+ long l = java.lang.Double.doubleToLongBits(getY());
+ l = l * 31 ^ java.lang.Double.doubleToLongBits(getX());
+ return (int) ((l >> 32) ^ l);
+ }
+
+ /**
+ * Compares two points for equality. This returns true if they have the
+ * same coordinates.
+ *
+ * @param o the point to compare
+ * @return true if it is equal
+ */
+ public boolean equals(Object o)
+ {
+ if (! (o instanceof Point2D))
+ return false;
+ Point2D p = (Point2D) o;
+ return getX() == p.getX() && getY() == p.getY();
+ }
+
+ /**
+ * This class defines a point in <code>double</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Double extends Point2D
+ {
+ /** The X coordinate. */
+ public double x;
+
+ /** The Y coordinate. */
+ public double y;
+
+ /**
+ * Create a new point at (0,0).
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Create a new point at (x,y).
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ */
+ public Double(double x, double y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Return the x coordinate.
+ *
+ * @return the x coordinate
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the y coordinate.
+ *
+ * @return the y coordinate
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Sets the location of this point.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ */
+ public void setLocation(double x, double y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Returns a string representation of this object. The format is:
+ * <code>"Point2D.Double[" + x + ", " + y + ']'</code>.
+ *
+ * @return a string representation of this object
+ */
+ public String toString()
+ {
+ return "Point2D.Double[" + x + ", " + y + ']';
+ }
+ } // class Double
+
+ /**
+ * This class defines a point in <code>float</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Float extends Point2D
+ {
+ /** The X coordinate. */
+ public float x;
+
+ /** The Y coordinate. */
+ public float y;
+
+ /**
+ * Create a new point at (0,0).
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Create a new point at (x,y).
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ */
+ public Float(float x, float y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Return the x coordinate.
+ *
+ * @return the x coordinate
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the y coordinate.
+ *
+ * @return the y coordinate
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Sets the location of this point.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ */
+ public void setLocation(double x, double y)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ }
+
+ /**
+ * Sets the location of this point.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ */
+ public void setLocation(float x, float y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Returns a string representation of this object. The format is:
+ * <code>"Point2D.Float[" + x + ", " + y + ']'</code>.
+ *
+ * @return a string representation of this object
+ */
+ public String toString()
+ {
+ return "Point2D.Float[" + x + ", " + y + ']';
+ }
+ } // class Float
+} // class Point2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/QuadCurve2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/QuadCurve2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/QuadCurve2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/QuadCurve2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,1467 @@
+/* QuadCurve2D.java -- represents a parameterized quadratic curve in 2-D space
+ Copyright (C) 2002, 2003, 2004 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.util.NoSuchElementException;
+
+/**
+ * A two-dimensional curve that is parameterized with a quadratic
+ * function.
+ *
+ * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a QuadCurve2D" />
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Graydon Hoare (graydon at redhat.com)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * @author Sven de Marothy (sven at physto.se)
+ *
+ * @since 1.2
+ */
+public abstract class QuadCurve2D implements Shape, Cloneable
+{
+ private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
+ private static final double EPSILON = 1E-10;
+
+ /**
+ * Constructs a new QuadCurve2D. Typical users will want to
+ * construct instances of a subclass, such as {@link
+ * QuadCurve2D.Float} or {@link QuadCurve2D.Double}.
+ */
+ protected QuadCurve2D()
+ {
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public abstract double getX1();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public abstract double getY1();
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public abstract Point2D getP1();
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s control
+ * point.
+ */
+ public abstract double getCtrlX();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s control
+ * point.
+ */
+ public abstract double getCtrlY();
+
+ /**
+ * Returns the curve’s control point.
+ */
+ public abstract Point2D getCtrlPt();
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public abstract double getX2();
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public abstract double getY2();
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public abstract Point2D getP2();
+
+ /**
+ * Changes the curve geometry, separately specifying each coordinate
+ * value.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new start
+ * point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new end
+ * point.
+ */
+ public abstract void setCurve(double x1, double y1, double cx, double cy,
+ double x2, double y2);
+
+ /**
+ * Changes the curve geometry, passing coordinate values in an
+ * array.
+ *
+ * @param coords an array containing the new coordinate values. The
+ * <i>x</i> coordinate of the new start point is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * new control point is located at <code>coords[offset + 2]</code>,
+ * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The
+ * <i>x</i> coordinate of the new end point is located at
+ * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 5]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public void setCurve(double[] coords, int offset)
+ {
+ setCurve(coords[offset++], coords[offset++], coords[offset++],
+ coords[offset++], coords[offset++], coords[offset++]);
+ }
+
+ /**
+ * Changes the curve geometry, specifying coordinate values in
+ * separate Point objects.
+ *
+ * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a QuadCurve2D" />
+ *
+ * <p>The curve does not keep any reference to the passed point
+ * objects. Therefore, a later change to <code>p1</code>,
+ * <code>c</code> <code>p2</code> will not affect the curve
+ * geometry.
+ *
+ * @param p1 the new start point.
+ * @param c the new control point.
+ * @param p2 the new end point.
+ */
+ public void setCurve(Point2D p1, Point2D c, Point2D p2)
+ {
+ setCurve(p1.getX(), p1.getY(), c.getX(), c.getY(), p2.getX(), p2.getY());
+ }
+
+ /**
+ * Changes the curve geometry, specifying coordinate values in an
+ * array of Point objects.
+ *
+ * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180"
+ * alt="A drawing of a QuadCurve2D" />
+ *
+ * <p>The curve does not keep references to the passed point
+ * objects. Therefore, a later change to the <code>pts</code> array
+ * or any of its elements will not affect the curve geometry.
+ *
+ * @param pts an array containing the points. The new start point
+ * is located at <code>pts[offset]</code>, the new control
+ * point at <code>pts[offset + 1]</code>, and the new end point
+ * at <code>pts[offset + 2]</code>.
+ *
+ * @param offset the offset of the start point in <code>pts</code>.
+ */
+ public void setCurve(Point2D[] pts, int offset)
+ {
+ setCurve(pts[offset].getX(), pts[offset].getY(), pts[offset + 1].getX(),
+ pts[offset + 1].getY(), pts[offset + 2].getX(),
+ pts[offset + 2].getY());
+ }
+
+ /**
+ * Changes the geometry of the curve to that of another curve.
+ *
+ * @param c the curve whose coordinates will be copied.
+ */
+ public void setCurve(QuadCurve2D c)
+ {
+ setCurve(c.getX1(), c.getY1(), c.getCtrlX(), c.getCtrlY(), c.getX2(),
+ c.getY2());
+ }
+
+ /**
+ * Calculates the squared flatness of a quadratic curve, directly
+ * specifying each coordinate value. The flatness is the distance of
+ * the control point to the line between start and end point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the square of the distance between C and the gray line, i.e.
+ * the squared length of the red line.
+ *
+ * @param x1 the <i>x</i> coordinate of the start point P1.
+ * @param y1 the <i>y</i> coordinate of the start point P1.
+ * @param cx the <i>x</i> coordinate of the control point C.
+ * @param cy the <i>y</i> coordinate of the control point C.
+ * @param x2 the <i>x</i> coordinate of the end point P2.
+ * @param y2 the <i>y</i> coordinate of the end point P2.
+ */
+ public static double getFlatnessSq(double x1, double y1, double cx,
+ double cy, double x2, double y2)
+ {
+ return Line2D.ptSegDistSq(x1, y1, x2, y2, cx, cy);
+ }
+
+ /**
+ * Calculates the flatness of a quadratic curve, directly specifying
+ * each coordinate value. The flatness is the distance of the
+ * control point to the line between start and end point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the distance between C and the gray line, i.e. the length of
+ * the red line.
+ *
+ * @param x1 the <i>x</i> coordinate of the start point P1.
+ * @param y1 the <i>y</i> coordinate of the start point P1.
+ * @param cx the <i>x</i> coordinate of the control point C.
+ * @param cy the <i>y</i> coordinate of the control point C.
+ * @param x2 the <i>x</i> coordinate of the end point P2.
+ * @param y2 the <i>y</i> coordinate of the end point P2.
+ */
+ public static double getFlatness(double x1, double y1, double cx, double cy,
+ double x2, double y2)
+ {
+ return Line2D.ptSegDist(x1, y1, x2, y2, cx, cy);
+ }
+
+ /**
+ * Calculates the squared flatness of a quadratic curve, specifying
+ * the coordinate values in an array. The flatness is the distance
+ * of the control point to the line between start and end point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the square of the distance between C and the gray line, i.e.
+ * the squared length of the red line.
+ *
+ * @param coords an array containing the coordinate values. The
+ * <i>x</i> coordinate of the start point P1 is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * control point C is located at <code>coords[offset + 2]</code>,
+ * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The
+ * <i>x</i> coordinate of the end point P2 is located at
+ * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 5]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public static double getFlatnessSq(double[] coords, int offset)
+ {
+ return Line2D.ptSegDistSq(coords[offset], coords[offset + 1],
+ coords[offset + 4], coords[offset + 5],
+ coords[offset + 2], coords[offset + 3]);
+ }
+
+ /**
+ * Calculates the flatness of a quadratic curve, specifying the
+ * coordinate values in an array. The flatness is the distance of
+ * the control point to the line between start and end point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the the distance between C and the gray line, i.e. the length of
+ * the red line.
+ *
+ * @param coords an array containing the coordinate values. The
+ * <i>x</i> coordinate of the start point P1 is located at
+ * <code>coords[offset]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 1]</code>. The <i>x</i> coordinate of the
+ * control point C is located at <code>coords[offset + 2]</code>,
+ * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The
+ * <i>x</i> coordinate of the end point P2 is located at
+ * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at
+ * <code>coords[offset + 5]</code>.
+ *
+ * @param offset the offset of the first coordinate value in
+ * <code>coords</code>.
+ */
+ public static double getFlatness(double[] coords, int offset)
+ {
+ return Line2D.ptSegDist(coords[offset], coords[offset + 1],
+ coords[offset + 4], coords[offset + 5],
+ coords[offset + 2], coords[offset + 3]);
+ }
+
+ /**
+ * Calculates the squared flatness of this curve. The flatness is
+ * the distance of the control point to the line between start and
+ * end point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the square of the distance between C and the gray line, i.e. the
+ * squared length of the red line.
+ */
+ public double getFlatnessSq()
+ {
+ return Line2D.ptSegDistSq(getX1(), getY1(), getX2(), getY2(), getCtrlX(),
+ getCtrlY());
+ }
+
+ /**
+ * Calculates the flatness of this curve. The flatness is the
+ * distance of the control point to the line between start and end
+ * point.
+ *
+ * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"
+ * alt="A drawing that illustrates the flatness" />
+ *
+ * <p>In the above drawing, the straight line connecting start point
+ * P1 and end point P2 is depicted in gray. The result will be the
+ * the distance between C and the gray line, i.e. the length of the
+ * red line.
+ */
+ public double getFlatness()
+ {
+ return Line2D.ptSegDist(getX1(), getY1(), getX2(), getY2(), getCtrlX(),
+ getCtrlY());
+ }
+
+ /**
+ * Subdivides this curve into two halves.
+ *
+ * <p><img src="doc-files/QuadCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a QuadCurve2D" />
+ *
+ * @param left a curve whose geometry will be set to the left half
+ * of this curve, or <code>null</code> if the caller is not
+ * interested in the left half.
+ *
+ * @param right a curve whose geometry will be set to the right half
+ * of this curve, or <code>null</code> if the caller is not
+ * interested in the right half.
+ */
+ public void subdivide(QuadCurve2D left, QuadCurve2D right)
+ {
+ // Use empty slots at end to share single array.
+ double[] d = new double[]
+ {
+ getX1(), getY1(), getCtrlX(), getCtrlY(), getX2(), getY2(),
+ 0, 0, 0, 0
+ };
+ subdivide(d, 0, d, 0, d, 4);
+ if (left != null)
+ left.setCurve(d, 0);
+ if (right != null)
+ right.setCurve(d, 4);
+ }
+
+ /**
+ * Subdivides a quadratic curve into two halves.
+ *
+ * <p><img src="doc-files/QuadCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a QuadCurve2D" />
+ *
+ * @param src the curve to be subdivided.
+ *
+ * @param left a curve whose geometry will be set to the left half
+ * of <code>src</code>, or <code>null</code> if the caller is not
+ * interested in the left half.
+ *
+ * @param right a curve whose geometry will be set to the right half
+ * of <code>src</code>, or <code>null</code> if the caller is not
+ * interested in the right half.
+ */
+ public static void subdivide(QuadCurve2D src, QuadCurve2D left,
+ QuadCurve2D right)
+ {
+ src.subdivide(left, right);
+ }
+
+ /**
+ * Subdivides a quadratic curve into two halves, passing all
+ * coordinates in an array.
+ *
+ * <p><img src="doc-files/QuadCurve2D-3.png" width="700"
+ * height="180" alt="A drawing that illustrates the effects of
+ * subdividing a QuadCurve2D" />
+ *
+ * <p>The left end point and the right start point will always be
+ * identical. Memory-concious programmers thus may want to pass the
+ * same array for both <code>left</code> and <code>right</code>, and
+ * set <code>rightOff</code> to <code>leftOff + 4</code>.
+ *
+ * @param src an array containing the coordinates of the curve to be
+ * subdivided. The <i>x</i> coordinate of the start point is
+ * located at <code>src[srcOff]</code>, its <i>y</i> at
+ * <code>src[srcOff + 1]</code>. The <i>x</i> coordinate of the
+ * control point is located at <code>src[srcOff + 2]</code>, its
+ * <i>y</i> at <code>src[srcOff + 3]</code>. The <i>x</i>
+ * coordinate of the end point is located at <code>src[srcOff +
+ * 4]</code>, its <i>y</i> at <code>src[srcOff + 5]</code>.
+ *
+ * @param srcOff an offset into <code>src</code>, specifying
+ * the index of the start point’s <i>x</i> coordinate.
+ *
+ * @param left an array that will receive the coordinates of the
+ * left half of <code>src</code>. It is acceptable to pass
+ * <code>src</code>. A caller who is not interested in the left half
+ * can pass <code>null</code>.
+ *
+ * @param leftOff an offset into <code>left</code>, specifying the
+ * index where the start point’s <i>x</i> coordinate will be
+ * stored.
+ *
+ * @param right an array that will receive the coordinates of the
+ * right half of <code>src</code>. It is acceptable to pass
+ * <code>src</code> or <code>left</code>. A caller who is not
+ * interested in the right half can pass <code>null</code>.
+ *
+ * @param rightOff an offset into <code>right</code>, specifying the
+ * index where the start point’s <i>x</i> coordinate will be
+ * stored.
+ */
+ public static void subdivide(double[] src, int srcOff, double[] left,
+ int leftOff, double[] right, int rightOff)
+ {
+ double x1;
+ double y1;
+ double xc;
+ double yc;
+ double x2;
+ double y2;
+
+ x1 = src[srcOff];
+ y1 = src[srcOff + 1];
+ xc = src[srcOff + 2];
+ yc = src[srcOff + 3];
+ x2 = src[srcOff + 4];
+ y2 = src[srcOff + 5];
+
+ if (left != null)
+ {
+ left[leftOff] = x1;
+ left[leftOff + 1] = y1;
+ }
+
+ if (right != null)
+ {
+ right[rightOff + 4] = x2;
+ right[rightOff + 5] = y2;
+ }
+
+ x1 = (x1 + xc) / 2;
+ x2 = (xc + x2) / 2;
+ xc = (x1 + x2) / 2;
+ y1 = (y1 + yc) / 2;
+ y2 = (y2 + yc) / 2;
+ yc = (y1 + y2) / 2;
+
+ if (left != null)
+ {
+ left[leftOff + 2] = x1;
+ left[leftOff + 3] = y1;
+ left[leftOff + 4] = xc;
+ left[leftOff + 5] = yc;
+ }
+
+ if (right != null)
+ {
+ right[rightOff] = xc;
+ right[rightOff + 1] = yc;
+ right[rightOff + 2] = x2;
+ right[rightOff + 3] = y2;
+ }
+ }
+
+ /**
+ * Finds the non-complex roots of a quadratic equation, placing the
+ * results into the same array as the equation coefficients. The
+ * following equation is being solved:
+ *
+ * <blockquote><code>eqn[2]</code> · <i>x</i><sup>2</sup>
+ * + <code>eqn[1]</code> · <i>x</i>
+ * + <code>eqn[0]</code>
+ * = 0
+ * </blockquote>
+ *
+ * <p>For some background about solving quadratic equations, see the
+ * article <a href=
+ * "http://planetmath.org/encyclopedia/QuadraticFormula.html"
+ * >“Quadratic Formula”</a> in <a href=
+ * "http://planetmath.org/">PlanetMath</a>. For an extensive library
+ * of numerical algorithms written in the C programming language,
+ * see the <a href="http://www.gnu.org/software/gsl/">GNU Scientific
+ * Library</a>.
+ *
+ * @see #solveQuadratic(double[], double[])
+ * @see CubicCurve2D#solveCubic(double[], double[])
+ *
+ * @param eqn an array with the coefficients of the equation. When
+ * this procedure has returned, <code>eqn</code> will contain the
+ * non-complex solutions of the equation, in no particular order.
+ *
+ * @return the number of non-complex solutions. A result of 0
+ * indicates that the equation has no non-complex solutions. A
+ * result of -1 indicates that the equation is constant (i.e.,
+ * always or never zero).
+ *
+ * @author Brian Gough (bjg at network-theory.com)
+ * (original C implementation in the <a href=
+ * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>)
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * (adaptation to Java)
+ */
+ public static int solveQuadratic(double[] eqn)
+ {
+ return solveQuadratic(eqn, eqn);
+ }
+
+ /**
+ * Finds the non-complex roots of a quadratic equation. The
+ * following equation is being solved:
+ *
+ * <blockquote><code>eqn[2]</code> · <i>x</i><sup>2</sup>
+ * + <code>eqn[1]</code> · <i>x</i>
+ * + <code>eqn[0]</code>
+ * = 0
+ * </blockquote>
+ *
+ * <p>For some background about solving quadratic equations, see the
+ * article <a href=
+ * "http://planetmath.org/encyclopedia/QuadraticFormula.html"
+ * >“Quadratic Formula”</a> in <a href=
+ * "http://planetmath.org/">PlanetMath</a>. For an extensive library
+ * of numerical algorithms written in the C programming language,
+ * see the <a href="http://www.gnu.org/software/gsl/">GNU Scientific
+ * Library</a>.
+ *
+ * @see CubicCurve2D#solveCubic(double[],double[])
+ *
+ * @param eqn an array with the coefficients of the equation.
+ *
+ * @param res an array into which the non-complex roots will be
+ * stored. The results may be in an arbitrary order. It is safe to
+ * pass the same array object reference for both <code>eqn</code>
+ * and <code>res</code>.
+ *
+ * @return the number of non-complex solutions. A result of 0
+ * indicates that the equation has no non-complex solutions. A
+ * result of -1 indicates that the equation is constant (i.e.,
+ * always or never zero).
+ *
+ * @author Brian Gough (bjg at network-theory.com)
+ * (original C implementation in the <a href=
+ * "http://www.gnu.org/software/gsl/">GNU Scientific Library</a>)
+ *
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ * (adaptation to Java)
+ */
+ public static int solveQuadratic(double[] eqn, double[] res)
+ {
+ // Taken from poly/solve_quadratic.c in the GNU Scientific Library
+ // (GSL), cvs revision 1.7 of 2003-07-26. For the original source,
+ // see http://www.gnu.org/software/gsl/
+ //
+ // Brian Gough, the author of that code, has granted the
+ // permission to use it in GNU Classpath under the GNU Classpath
+ // license, and has assigned the copyright to the Free Software
+ // Foundation.
+ //
+ // The Java implementation is very similar to the GSL code, but
+ // not a strict one-to-one copy. For example, GSL would sort the
+ // result.
+ double a;
+ double b;
+ double c;
+ double disc;
+
+ c = eqn[0];
+ b = eqn[1];
+ a = eqn[2];
+
+ // Check for linear or constant functions. This is not done by the
+ // GNU Scientific Library. Without this special check, we
+ // wouldn't return -1 for constant functions, and 2 instead of 1
+ // for linear functions.
+ if (a == 0)
+ {
+ if (b == 0)
+ return -1;
+
+ res[0] = -c / b;
+ return 1;
+ }
+
+ disc = b * b - 4 * a * c;
+
+ if (disc < 0)
+ return 0;
+
+ if (disc == 0)
+ {
+ // The GNU Scientific Library returns two identical results here.
+ // We just return one.
+ res[0] = -0.5 * b / a;
+ return 1;
+ }
+
+ // disc > 0
+ if (b == 0)
+ {
+ double r;
+
+ r = Math.abs(0.5 * Math.sqrt(disc) / a);
+ res[0] = -r;
+ res[1] = r;
+ }
+ else
+ {
+ double sgnb;
+ double temp;
+
+ sgnb = (b > 0 ? 1 : -1);
+ temp = -0.5 * (b + sgnb * Math.sqrt(disc));
+
+ // The GNU Scientific Library sorts the result here. We don't.
+ res[0] = temp / a;
+ res[1] = c / temp;
+ }
+ return 2;
+ }
+
+ /**
+ * Determines whether a point is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a QuadCurve2D.
+ */
+ public boolean contains(double x, double y)
+ {
+ if (! getBounds2D().contains(x, y))
+ return false;
+
+ return ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0);
+ }
+
+ /**
+ * Determines whether a point is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a QuadCurve2D.
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Determines whether any part of a rectangle is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” in a CubicCurve2D.
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ if (! getBounds2D().contains(x, y, w, h))
+ return false;
+
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, true, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, false, h) != 0 /* right */
+ || getAxisIntersections(x, y, false, h) != 0) /* left */
+ return true;
+
+ /* No intersections, is any point inside? */
+ if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Determines whether any part of a Rectangle2D is inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ * @see #intersects(double, double, double, double)
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Determines whether a rectangle is entirely inside the area bounded
+ * by the curve and the straight line connecting its end points.
+ *
+ * <p><img src="doc-files/QuadCurve2D-5.png" width="350" height="180"
+ * alt="A drawing of the area spanned by the curve" />
+ *
+ * <p>The above drawing illustrates in which area points are
+ * considered “inside” a QuadCurve2D.
+ * @see #contains(double, double)
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ if (! getBounds2D().intersects(x, y, w, h))
+ return false;
+
+ /* Does any edge intersect? */
+ if (getAxisIntersections(x, y, true, w) != 0 /* top */
+ || getAxisIntersections(x, y + h, true, w) != 0 /* bottom */
+ || getAxisIntersections(x + w, y, false, h) != 0 /* right */
+ || getAxisIntersections(x, y, false, h) != 0) /* left */
+ return false;
+
+ /* No intersections, is any point inside? */
+ if ((getAxisIntersections(x, y, true, BIG_VALUE) & 1) != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Determines whether a Rectangle2D is entirely inside the area that is
+ * bounded by the curve and the straight line connecting its end points.
+ * @see #contains(double, double, double, double)
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control point. As the illustration
+ * below shows, the invisible control point may cause the bounds to
+ * be much larger than the area that is actually covered by the
+ * curve.
+ *
+ * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180"
+ * alt="An illustration of the bounds of a QuadCurve2D" />
+ */
+ public Rectangle getBounds()
+ {
+ return getBounds2D().getBounds();
+ }
+
+ public PathIterator getPathIterator(final AffineTransform at)
+ {
+ return new PathIterator()
+ {
+ /** Current coordinate. */
+ private int current = 0;
+
+ public int getWindingRule()
+ {
+ return WIND_NON_ZERO;
+ }
+
+ public boolean isDone()
+ {
+ return current >= 2;
+ }
+
+ public void next()
+ {
+ current++;
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = (float) getX1();
+ coords[1] = (float) getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = (float) getCtrlX();
+ coords[1] = (float) getCtrlY();
+ coords[2] = (float) getX2();
+ coords[3] = (float) getY2();
+ result = SEG_QUADTO;
+ break;
+ default:
+ throw new NoSuchElementException("quad iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 2);
+ return result;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ int result;
+ switch (current)
+ {
+ case 0:
+ coords[0] = getX1();
+ coords[1] = getY1();
+ result = SEG_MOVETO;
+ break;
+ case 1:
+ coords[0] = getCtrlX();
+ coords[1] = getCtrlY();
+ coords[2] = getX2();
+ coords[3] = getY2();
+ result = SEG_QUADTO;
+ break;
+ default:
+ throw new NoSuchElementException("quad iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 2);
+ return result;
+ }
+ };
+ }
+
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return new FlatteningPathIterator(getPathIterator(at), flatness);
+ }
+
+ /**
+ * Creates a new curve with the same contents as this one.
+ *
+ * @return the clone.
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+
+ /**
+ * Helper method used by contains() and intersects() methods
+ * Return the number of curve/line intersections on a given axis
+ * extending from a certain point. useYaxis is true for using the Y axis,
+ * @param x x coordinate of the origin point
+ * @param y y coordinate of the origin point
+ * @param useYaxis axis to follow, if true the positive Y axis is used,
+ * false uses the positive X axis.
+ *
+ * This is an implementation of the line-crossings algorithm,
+ * Detailed in an article on Eric Haines' page:
+ * http://www.acm.org/tog/editors/erich/ptinpoly/
+ */
+ private int getAxisIntersections(double x, double y, boolean useYaxis,
+ double distance)
+ {
+ int nCrossings = 0;
+ double a0;
+ double a1;
+ double a2;
+ double b0;
+ double b1;
+ double b2;
+ double[] r = new double[3];
+ int nRoots;
+
+ a0 = a2 = 0.0;
+
+ if (useYaxis)
+ {
+ a0 = getY1() - y;
+ a1 = getCtrlY() - y;
+ a2 = getY2() - y;
+ b0 = getX1() - x;
+ b1 = getCtrlX() - x;
+ b2 = getX2() - x;
+ }
+ else
+ {
+ a0 = getX1() - x;
+ a1 = getCtrlX() - x;
+ a2 = getX2() - x;
+ b0 = getY1() - y;
+ b1 = getCtrlY() - y;
+ b2 = getY2() - y;
+ }
+
+ /* If the axis intersects a start/endpoint, shift it up by some small
+ amount to guarantee the line is 'inside'
+ If this is not done,bad behaviour may result for points on that axis. */
+ if (a0 == 0.0 || a2 == 0.0)
+ {
+ double small = getFlatness() * EPSILON;
+ if (a0 == 0.0)
+ a0 -= small;
+
+ if (a2 == 0.0)
+ a2 -= small;
+ }
+
+ r[0] = a0;
+ r[1] = 2 * (a1 - a0);
+ r[2] = (a2 - 2 * a1 + a0);
+
+ nRoots = solveQuadratic(r);
+ for (int i = 0; i < nRoots; i++)
+ {
+ double t = r[i];
+ if (t >= 0.0 && t <= 1.0)
+ {
+ double crossing = t * t * (b2 - 2 * b1 + b0) + 2 * t * (b1 - b0)
+ + b0;
+ /* single root is always doubly degenerate in quads */
+ if (crossing > 0 && crossing < distance)
+ nCrossings += (nRoots == 1) ? 2 : 1;
+ }
+ }
+
+ if (useYaxis)
+ {
+ if (Line2D.linesIntersect(b0, a0, b2, a2, EPSILON, 0.0, distance, 0.0))
+ nCrossings++;
+ }
+ else
+ {
+ if (Line2D.linesIntersect(a0, b0, a2, b2, 0.0, EPSILON, 0.0, distance))
+ nCrossings++;
+ }
+
+ return (nCrossings);
+ }
+
+ /**
+ * A two-dimensional curve that is parameterized with a quadratic
+ * function and stores coordinate values in double-precision
+ * floating-point format.
+ *
+ * @see QuadCurve2D.Float
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ public static class Double extends QuadCurve2D
+ {
+ /**
+ * The <i>x</i> coordinate of the curve’s start point.
+ */
+ public double x1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s start point.
+ */
+ public double y1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s control point.
+ */
+ public double ctrlx;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s control point.
+ */
+ public double ctrly;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s end point.
+ */
+ public double x2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s end point.
+ */
+ public double y2;
+
+ /**
+ * Constructs a new QuadCurve2D that stores its coordinate values
+ * in double-precision floating-point format. All points are
+ * initially at position (0, 0).
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Constructs a new QuadCurve2D that stores its coordinate values
+ * in double-precision floating-point format, specifying the
+ * initial position of each point.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s control
+ * point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s control
+ * point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public Double(double x1, double y1, double cx, double cy, double x2,
+ double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx = cx;
+ ctrly = cy;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Double(x1, y1);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s control
+ * point.
+ */
+ public double getCtrlX()
+ {
+ return ctrlx;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s control
+ * point.
+ */
+ public double getCtrlY()
+ {
+ return ctrly;
+ }
+
+ /**
+ * Returns the curve’s control point.
+ */
+ public Point2D getCtrlPt()
+ {
+ return new Point2D.Double(ctrlx, ctrly);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Double(x2, y2);
+ }
+
+ /**
+ * Changes the geometry of the curve.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new
+ * end point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new
+ * end point.
+ */
+ public void setCurve(double x1, double y1, double cx, double cy,
+ double x2, double y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx = cx;
+ ctrly = cy;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control point. As the
+ * illustration below shows, the invisible control point may cause
+ * the bounds to be much larger than the area that is actually
+ * covered by the curve.
+ *
+ * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180"
+ * alt="An illustration of the bounds of a QuadCurve2D" />
+ */
+ public Rectangle2D getBounds2D()
+ {
+ double nx1 = Math.min(Math.min(x1, ctrlx), x2);
+ double ny1 = Math.min(Math.min(y1, ctrly), y2);
+ double nx2 = Math.max(Math.max(x1, ctrlx), x2);
+ double ny2 = Math.max(Math.max(y1, ctrly), y2);
+ return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1);
+ }
+ }
+
+ /**
+ * A two-dimensional curve that is parameterized with a quadratic
+ * function and stores coordinate values in single-precision
+ * floating-point format.
+ *
+ * @see QuadCurve2D.Double
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @author Sascha Brawer (brawer at dandelis.ch)
+ */
+ public static class Float extends QuadCurve2D
+ {
+ /**
+ * The <i>x</i> coordinate of the curve’s start point.
+ */
+ public float x1;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s start point.
+ */
+ public float y1;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s control point.
+ */
+ public float ctrlx;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s control point.
+ */
+ public float ctrly;
+
+ /**
+ * The <i>x</i> coordinate of the curve’s end point.
+ */
+ public float x2;
+
+ /**
+ * The <i>y</i> coordinate of the curve’s end point.
+ */
+ public float y2;
+
+ /**
+ * Constructs a new QuadCurve2D that stores its coordinate values
+ * in single-precision floating-point format. All points are
+ * initially at position (0, 0).
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Constructs a new QuadCurve2D that stores its coordinate values
+ * in single-precision floating-point format, specifying the
+ * initial position of each point.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s start
+ * point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s control
+ * point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s control
+ * point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s end
+ * point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public Float(float x1, float y1, float cx, float cy, float x2, float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx = cx;
+ ctrly = cy;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getX1()
+ {
+ return x1;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s start
+ * point.
+ */
+ public double getY1()
+ {
+ return y1;
+ }
+
+ /**
+ * Returns the curve’s start point.
+ */
+ public Point2D getP1()
+ {
+ return new Point2D.Float(x1, y1);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s control
+ * point.
+ */
+ public double getCtrlX()
+ {
+ return ctrlx;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s control
+ * point.
+ */
+ public double getCtrlY()
+ {
+ return ctrly;
+ }
+
+ /**
+ * Returns the curve’s control point.
+ */
+ public Point2D getCtrlPt()
+ {
+ return new Point2D.Float(ctrlx, ctrly);
+ }
+
+ /**
+ * Returns the <i>x</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getX2()
+ {
+ return x2;
+ }
+
+ /**
+ * Returns the <i>y</i> coordinate of the curve’s end
+ * point.
+ */
+ public double getY2()
+ {
+ return y2;
+ }
+
+ /**
+ * Returns the curve’s end point.
+ */
+ public Point2D getP2()
+ {
+ return new Point2D.Float(x2, y2);
+ }
+
+ /**
+ * Changes the geometry of the curve, specifying coordinate values
+ * as double-precision floating-point numbers.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new
+ * end point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new
+ * end point.
+ */
+ public void setCurve(double x1, double y1, double cx, double cy,
+ double x2, double y2)
+ {
+ this.x1 = (float) x1;
+ this.y1 = (float) y1;
+ ctrlx = (float) cx;
+ ctrly = (float) cy;
+ this.x2 = (float) x2;
+ this.y2 = (float) y2;
+ }
+
+ /**
+ * Changes the geometry of the curve, specifying coordinate values
+ * as single-precision floating-point numbers.
+ *
+ * @param x1 the <i>x</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param y1 the <i>y</i> coordinate of the curve’s new
+ * start point.
+ *
+ * @param cx the <i>x</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param cy the <i>y</i> coordinate of the curve’s new
+ * control point.
+ *
+ * @param x2 the <i>x</i> coordinate of the curve’s new
+ * end point.
+ *
+ * @param y2 the <i>y</i> coordinate of the curve’s new
+ * end point.
+ */
+ public void setCurve(float x1, float y1, float cx, float cy, float x2,
+ float y2)
+ {
+ this.x1 = x1;
+ this.y1 = y1;
+ ctrlx = cx;
+ ctrly = cy;
+ this.x2 = x2;
+ this.y2 = y2;
+ }
+
+ /**
+ * Determines the smallest rectangle that encloses the
+ * curve’s start, end and control point. As the
+ * illustration below shows, the invisible control point may cause
+ * the bounds to be much larger than the area that is actually
+ * covered by the curve.
+ *
+ * <p><img src="doc-files/QuadCurve2D-2.png" width="350" height="180"
+ * alt="An illustration of the bounds of a QuadCurve2D" />
+ */
+ public Rectangle2D getBounds2D()
+ {
+ float nx1 = (float) Math.min(Math.min(x1, ctrlx), x2);
+ float ny1 = (float) Math.min(Math.min(y1, ctrly), y2);
+ float nx2 = (float) Math.max(Math.max(x1, ctrlx), x2);
+ float ny2 = (float) Math.max(Math.max(y1, ctrly), y2);
+ return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1);
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Rectangle2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Rectangle2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Rectangle2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/Rectangle2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,992 @@
+/* Rectangle2D.java -- generic rectangles in 2-D space
+ Copyright (C) 2000, 2001, 2002, 2004 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.geom;
+
+import java.util.NoSuchElementException;
+
+/**
+ * This class describes a rectangle by a point (x,y) and dimension (w x h).
+ * The actual storage is left up to subclasses.
+ *
+ * <p>It is valid for a rectangle to have negative width or height; but it
+ * is considered to have no area or internal points. Therefore, the behavior
+ * in methods like <code>contains</code> or <code>intersects</code> is
+ * undefined unless the rectangle has positive width and height.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public abstract class Rectangle2D extends RectangularShape
+{
+ /**
+ * The point lies left of the rectangle (p.x < r.x).
+ *
+ * @see #outcode(double, double)
+ */
+ public static final int OUT_LEFT = 1;
+
+ /**
+ * The point lies above the rectangle (p.y < r.y).
+ *
+ * @see #outcode(double, double)
+ */
+ public static final int OUT_TOP = 2;
+
+ /**
+ * The point lies right of the rectangle (p.x > r.maxX).
+ *
+ * @see #outcode(double, double)
+ */
+ public static final int OUT_RIGHT = 4;
+
+ /**
+ * The point lies below of the rectangle (p.y > r.maxY).
+ *
+ * @see #outcode(double, double)
+ */
+ public static final int OUT_BOTTOM = 8;
+
+ /**
+ * Default constructor.
+ */
+ protected Rectangle2D()
+ {
+ }
+
+ /**
+ * Set the bounding box of this rectangle.
+ *
+ * @param x the new X coordinate
+ * @param y the new Y coordinate
+ * @param w the new width
+ * @param h the new height
+ */
+ public abstract void setRect(double x, double y, double w, double h);
+
+ /**
+ * Set the bounding box of this rectangle from the given one.
+ *
+ * @param r rectangle to copy
+ * @throws NullPointerException if r is null
+ */
+ public void setRect(Rectangle2D r)
+ {
+ setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Tests if the specified line intersects the interior of this rectangle.
+ *
+ * @param x1 the first x coordinate of line segment
+ * @param y1 the first y coordinate of line segment
+ * @param x2 the second x coordinate of line segment
+ * @param y2 the second y coordinate of line segment
+ * @return true if the line intersects the rectangle
+ */
+ public boolean intersectsLine(double x1, double y1, double x2, double y2)
+ {
+ double x = getX();
+ double y = getY();
+ double w = getWidth();
+ double h = getHeight();
+ if (w <= 0 || h <= 0)
+ return false;
+
+ if (x1 >= x && x1 <= x + w && y1 >= y && y1 <= y + h)
+ return true;
+ if (x2 >= x && x2 <= x + w && y2 >= y && y2 <= y + h)
+ return true;
+
+ double x3 = x + w;
+ double y3 = y + h;
+
+ return (Line2D.linesIntersect(x1, y1, x2, y2, x, y, x, y3)
+ || Line2D.linesIntersect(x1, y1, x2, y2, x, y3, x3, y3)
+ || Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x3, y)
+ || Line2D.linesIntersect(x1, y1, x2, y2, x3, y, x, y));
+ }
+
+ /**
+ * Tests if the specified line intersects the interior of this rectangle.
+ *
+ * @param l the line segment
+ * @return true if the line intersects the rectangle
+ * @throws NullPointerException if l is null
+ */
+ public boolean intersectsLine(Line2D l)
+ {
+ return intersectsLine(l.getX1(), l.getY1(), l.getX2(), l.getY2());
+ }
+
+ /**
+ * Determine where the point lies with respect to this rectangle. The
+ * result will be the binary OR of the appropriate bit masks.
+ *
+ * @param x the x coordinate to check
+ * @param y the y coordinate to check
+ * @return the binary OR of the result
+ * @see #OUT_LEFT
+ * @see #OUT_TOP
+ * @see #OUT_RIGHT
+ * @see #OUT_BOTTOM
+ */
+ public abstract int outcode(double x, double y);
+
+ /**
+ * Determine where the point lies with respect to this rectangle. The
+ * result will be the binary OR of the appropriate bit masks.
+ *
+ * @param p the point to check
+ * @return the binary OR of the result
+ * @throws NullPointerException if p is null
+ * @see #OUT_LEFT
+ * @see #OUT_TOP
+ * @see #OUT_RIGHT
+ * @see #OUT_BOTTOM
+ */
+ public int outcode(Point2D p)
+ {
+ return outcode(p.getX(), p.getY());
+ }
+
+ /**
+ * Set the bounding box of this rectangle.
+ *
+ * @param x the new X coordinate
+ * @param y the new Y coordinate
+ * @param w the new width
+ * @param h the new height
+ */
+ public void setFrame(double x, double y, double w, double h)
+ {
+ setRect(x, y, w, h);
+ }
+
+ /**
+ * Returns the bounds of this rectangle. A pretty useless method, as this
+ * is already a rectangle.
+ *
+ * @return a copy of this rectangle
+ */
+ public Rectangle2D getBounds2D()
+ {
+ return (Rectangle2D) clone();
+ }
+
+ /**
+ * Test if the given point is contained in the rectangle.
+ *
+ * @param x the x coordinate of the point
+ * @param y the y coordinate of the point
+ * @return true if (x,y) is in the rectangle
+ */
+ public boolean contains(double x, double y)
+ {
+ double mx = getX();
+ double my = getY();
+ double w = getWidth();
+ double h = getHeight();
+ return w > 0 && h > 0 && x >= mx && x < mx + w && y >= my && y < my + h;
+ }
+
+ /**
+ * Tests if the given rectangle intersects this one. In other words, test if
+ * the two rectangles share at least one internal point.
+ *
+ * @param x the x coordinate of the other rectangle
+ * @param y the y coordinate of the other rectangle
+ * @param w the width of the other rectangle
+ * @param h the height of the other rectangle
+ * @return true if the rectangles intersect
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ double mx = getX();
+ double my = getY();
+ double mw = getWidth();
+ double mh = getHeight();
+ return w > 0 && h > 0 && mw > 0 && mh > 0
+ && x < mx + mw && x + w > mx && y < my + mh && y + h > my;
+ }
+
+ /**
+ * Tests if this rectangle contains the given one. In other words, test if
+ * this rectangle contains all points in the given one.
+ *
+ * @param x the x coordinate of the other rectangle
+ * @param y the y coordinate of the other rectangle
+ * @param w the width of the other rectangle
+ * @param h the height of the other rectangle
+ * @return true if this rectangle contains the other
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ double mx = getX();
+ double my = getY();
+ double mw = getWidth();
+ double mh = getHeight();
+ return w > 0 && h > 0 && mw > 0 && mh > 0
+ && x >= mx && x + w <= mx + mw && y >= my && y + h <= my + mh;
+ }
+
+ /**
+ * Return a new rectangle which is the intersection of this and the given
+ * one. The result will be empty if there is no intersection.
+ *
+ * @param r the rectangle to be intersected
+ * @return the intersection
+ * @throws NullPointerException if r is null
+ */
+ public abstract Rectangle2D createIntersection(Rectangle2D r);
+
+ /**
+ * Intersects a pair of rectangles, and places the result in the
+ * destination; this can be used to avoid object creation. This method
+ * even works when the destination is also a source, although you stand
+ * to lose the original data.
+ *
+ * @param src1 the first source
+ * @param src2 the second source
+ * @param dest the destination for the intersection
+ * @throws NullPointerException if any rectangle is null
+ */
+ public static void intersect(Rectangle2D src1, Rectangle2D src2,
+ Rectangle2D dest)
+ {
+ double x = Math.max(src1.getX(), src2.getX());
+ double y = Math.max(src1.getY(), src2.getY());
+ double maxx = Math.min(src1.getMaxX(), src2.getMaxX());
+ double maxy = Math.min(src1.getMaxY(), src2.getMaxY());
+ dest.setRect(x, y, maxx - x, maxy - y);
+ }
+
+ /**
+ * Return a new rectangle which is the union of this and the given one.
+ *
+ * @param r the rectangle to be merged
+ * @return the union
+ * @throws NullPointerException if r is null
+ */
+ public abstract Rectangle2D createUnion(Rectangle2D r);
+
+ /**
+ * Joins a pair of rectangles, and places the result in the destination;
+ * this can be used to avoid object creation. This method even works when
+ * the destination is also a source, although you stand to lose the
+ * original data.
+ *
+ * @param src1 the first source
+ * @param src2 the second source
+ * @param dest the destination for the union
+ * @throws NullPointerException if any rectangle is null
+ */
+ public static void union(Rectangle2D src1, Rectangle2D src2,
+ Rectangle2D dest)
+ {
+ double x = Math.min(src1.getX(), src2.getX());
+ double y = Math.min(src1.getY(), src2.getY());
+ double maxx = Math.max(src1.getMaxX(), src2.getMaxX());
+ double maxy = Math.max(src1.getMaxY(), src2.getMaxY());
+ dest.setRect(x, y, maxx - x, maxy - y);
+ }
+
+ /**
+ * Modifies this rectangle so that it represents the smallest rectangle
+ * that contains both the existing rectangle and the specified point.
+ * However, if the point falls on one of the two borders which are not
+ * inside the rectangle, a subsequent call to <code>contains</code> may
+ * return false.
+ *
+ * @param newx the X coordinate of the point to add to this rectangle
+ * @param newy the Y coordinate of the point to add to this rectangle
+ */
+ public void add(double newx, double newy)
+ {
+ double minx = Math.min(getX(), newx);
+ double maxx = Math.max(getMaxX(), newx);
+ double miny = Math.min(getY(), newy);
+ double maxy = Math.max(getMaxY(), newy);
+ setRect(minx, miny, maxx - minx, maxy - miny);
+ }
+
+ /**
+ * Modifies this rectangle so that it represents the smallest rectangle
+ * that contains both the existing rectangle and the specified point.
+ * However, if the point falls on one of the two borders which are not
+ * inside the rectangle, a subsequent call to <code>contains</code> may
+ * return false.
+ *
+ * @param p the point to add to this rectangle
+ * @throws NullPointerException if p is null
+ */
+ public void add(Point2D p)
+ {
+ add(p.getX(), p.getY());
+ }
+
+ /**
+ * Modifies this rectangle so that it represents the smallest rectangle
+ * that contains both the existing rectangle and the specified rectangle.
+ *
+ * @param r the rectangle to add to this rectangle
+ * @throws NullPointerException if r is null
+ * @see #union(Rectangle2D, Rectangle2D, Rectangle2D)
+ */
+ public void add(Rectangle2D r)
+ {
+ union(this, r, this);
+ }
+
+ /**
+ * 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 iterator is thread
+ * safe; modifications to the rectangle do not affect the results of this
+ * path instance.
+ *
+ * @param at an optional transform to apply to the iterator
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ public PathIterator getPathIterator(final AffineTransform at)
+ {
+ final double minx = getX();
+ final double miny = getY();
+ final double maxx = minx + getWidth();
+ final double maxy = miny + getHeight();
+ return new PathIterator()
+ {
+ /** Current coordinate. */
+ private int current = (maxx <= minx && maxy <= miny) ? 6 : 0;
+
+ public int getWindingRule()
+ {
+ // A test program showed that Sun J2SE 1.3.1 and 1.4.1_01
+ // return WIND_NON_ZERO paths. While this does not really
+ // make any difference for rectangles (because they are not
+ // self-intersecting), it seems appropriate to behave
+ // identically.
+
+ return WIND_NON_ZERO;
+ }
+
+ public boolean isDone()
+ {
+ return current > 5;
+ }
+
+ public void next()
+ {
+ current++;
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ switch (current)
+ {
+ case 1:
+ coords[0] = (float) maxx;
+ coords[1] = (float) miny;
+ break;
+ case 2:
+ coords[0] = (float) maxx;
+ coords[1] = (float) maxy;
+ break;
+ case 3:
+ coords[0] = (float) minx;
+ coords[1] = (float) maxy;
+ break;
+ case 0:
+ case 4:
+ coords[0] = (float) minx;
+ coords[1] = (float) miny;
+ break;
+ case 5:
+ return SEG_CLOSE;
+ default:
+ throw new NoSuchElementException("rect iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return current == 0 ? SEG_MOVETO : SEG_LINETO;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ switch (current)
+ {
+ case 1:
+ coords[0] = maxx;
+ coords[1] = miny;
+ break;
+ case 2:
+ coords[0] = maxx;
+ coords[1] = maxy;
+ break;
+ case 3:
+ coords[0] = minx;
+ coords[1] = maxy;
+ break;
+ case 0:
+ case 4:
+ coords[0] = minx;
+ coords[1] = miny;
+ break;
+ case 5:
+ return SEG_CLOSE;
+ default:
+ throw new NoSuchElementException("rect iterator out of bounds");
+ }
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return current == 0 ? SEG_MOVETO : SEG_LINETO;
+ }
+ };
+ }
+
+ /**
+ * 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 iterator is thread
+ * safe; modifications to the rectangle do not affect the results of this
+ * path instance. As the rectangle is already flat, the flatness parameter
+ * is ignored.
+ *
+ * @param at an optional transform to apply to the iterator
+ * @param flatness the maximum distance for deviation from the real boundary
+ * @return a new iterator over the boundary
+ * @since 1.2
+ */
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return getPathIterator(at);
+ }
+
+ /**
+ * Return the hashcode for this rectangle. The formula is not documented, but
+ * appears to be the same as:
+ * <pre>
+ * long l = Double.doubleToLongBits(getX())
+ * + 37 * Double.doubleToLongBits(getY())
+ * + 43 * Double.doubleToLongBits(getWidth())
+ * + 47 * Double.doubleToLongBits(getHeight());
+ * return (int) ((l >> 32) ^ l);
+ * </pre>
+ *
+ * @return the hashcode
+ */
+ public int hashCode()
+ {
+ // Talk about a fun time reverse engineering this one!
+ long l = java.lang.Double.doubleToLongBits(getX())
+ + 37 * java.lang.Double.doubleToLongBits(getY())
+ + 43 * java.lang.Double.doubleToLongBits(getWidth())
+ + 47 * java.lang.Double.doubleToLongBits(getHeight());
+ return (int) ((l >> 32) ^ l);
+ }
+
+ /**
+ * Tests this rectangle for equality against the specified object. This
+ * will be true if an only if the specified object is an instance of
+ * Rectangle2D with the same coordinates and dimensions.
+ *
+ * @param obj the object to test against for equality
+ * @return true if the specified object is equal to this one
+ */
+ public boolean equals(Object obj)
+ {
+ if (! (obj instanceof Rectangle2D))
+ return false;
+ Rectangle2D r = (Rectangle2D) obj;
+ return r.getX() == getX() && r.getY() == getY()
+ && r.getWidth() == getWidth() && r.getHeight() == getHeight();
+ }
+
+ /**
+ * This class defines a rectangle in <code>double</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Double extends Rectangle2D
+ {
+ /** The x coordinate of the lower left corner. */
+ public double x;
+
+ /** The y coordinate of the lower left corner. */
+ public double y;
+
+ /** The width of the rectangle. */
+ public double width;
+
+ /** The height of the rectangle. */
+ public double height;
+
+ /**
+ * Create a rectangle at (0,0) with width 0 and height 0.
+ */
+ public Double()
+ {
+ }
+
+ /**
+ * Create a rectangle with the given values.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ public Double(double x, double y, double w, double h)
+ {
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ }
+
+ /**
+ * Return the X coordinate.
+ *
+ * @return the value of x
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the Y coordinate.
+ *
+ * @return the value of y
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Return the width.
+ *
+ * @return the value of width
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Return the height.
+ *
+ * @return the value of height
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Test if the rectangle is empty.
+ *
+ * @return true if width or height is not positive
+ */
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ /**
+ * Set the contents of this rectangle to those specified.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ public void setRect(double x, double y, double w, double h)
+ {
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ }
+
+ /**
+ * Set the contents of this rectangle to those specified.
+ *
+ * @param r the rectangle to copy
+ * @throws NullPointerException if r is null
+ */
+ public void setRect(Rectangle2D r)
+ {
+ x = r.getX();
+ y = r.getY();
+ width = r.getWidth();
+ height = r.getHeight();
+ }
+
+ /**
+ * Determine where the point lies with respect to this rectangle. The
+ * result will be the binary OR of the appropriate bit masks.
+ *
+ * @param x the x coordinate to check
+ * @param y the y coordinate to check
+ * @return the binary OR of the result
+ * @see #OUT_LEFT
+ * @see #OUT_TOP
+ * @see #OUT_RIGHT
+ * @see #OUT_BOTTOM
+ * @since 1.2
+ */
+ public int outcode(double x, double y)
+ {
+ int result = 0;
+ if (width <= 0)
+ result |= OUT_LEFT | OUT_RIGHT;
+ else if (x < this.x)
+ result |= OUT_LEFT;
+ else if (x > this.x + width)
+ result |= OUT_RIGHT;
+ if (height <= 0)
+ result |= OUT_BOTTOM | OUT_TOP;
+ else if (y < this.y) // Remember that +y heads top-to-bottom.
+ result |= OUT_TOP;
+ else if (y > this.y + height)
+ result |= OUT_BOTTOM;
+ return result;
+ }
+
+ /**
+ * Returns the bounds of this rectangle. A pretty useless method, as this
+ * is already a rectangle.
+ *
+ * @return a copy of this rectangle
+ */
+ public Rectangle2D getBounds2D()
+ {
+ return new Double(x, y, width, height);
+ }
+
+ /**
+ * Return a new rectangle which is the intersection of this and the given
+ * one. The result will be empty if there is no intersection.
+ *
+ * @param r the rectangle to be intersected
+ * @return the intersection
+ * @throws NullPointerException if r is null
+ */
+ public Rectangle2D createIntersection(Rectangle2D r)
+ {
+ Double res = new Double();
+ intersect(this, r, res);
+ return res;
+ }
+
+ /**
+ * Return a new rectangle which is the union of this and the given one.
+ *
+ * @param r the rectangle to be merged
+ * @return the union
+ * @throws NullPointerException if r is null
+ */
+ public Rectangle2D createUnion(Rectangle2D r)
+ {
+ Double res = new Double();
+ union(this, r, res);
+ return res;
+ }
+
+ /**
+ * Returns a string representation of this rectangle. This is in the form
+ * <code>getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width
+ * + ",h=" + height + ']'</code>.
+ *
+ * @return a string representation of this rectangle
+ */
+ public String toString()
+ {
+ return getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width
+ + ",h=" + height + ']';
+ }
+ }
+
+ /**
+ * This class defines a rectangle in <code>float</code> precision.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+ public static class Float extends Rectangle2D
+ {
+ /** The x coordinate of the lower left corner. */
+ public float x;
+
+ /** The y coordinate of the lower left corner. */
+ public float y;
+
+ /** The width of the rectangle. */
+ public float width;
+
+ /** The height of the rectangle. */
+ public float height;
+
+ /**
+ * Create a rectangle at (0,0) with width 0 and height 0.
+ */
+ public Float()
+ {
+ }
+
+ /**
+ * Create a rectangle with the given values.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ public Float(float x, float y, float w, float h)
+ {
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ }
+
+ /**
+ * Create a rectangle with the given values.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ Float(double x, double y, double w, double h)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ width = (float) w;
+ height = (float) h;
+ }
+
+ /**
+ * Return the X coordinate.
+ *
+ * @return the value of x
+ */
+ public double getX()
+ {
+ return x;
+ }
+
+ /**
+ * Return the Y coordinate.
+ *
+ * @return the value of y
+ */
+ public double getY()
+ {
+ return y;
+ }
+
+ /**
+ * Return the width.
+ *
+ * @return the value of width
+ */
+ public double getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * Return the height.
+ *
+ * @return the value of height
+ */
+ public double getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Test if the rectangle is empty.
+ *
+ * @return true if width or height is not positive
+ */
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ /**
+ * Set the contents of this rectangle to those specified.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ public void setRect(float x, float y, float w, float h)
+ {
+ this.x = x;
+ this.y = y;
+ width = w;
+ height = h;
+ }
+
+ /**
+ * Set the contents of this rectangle to those specified.
+ *
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param w the width
+ * @param h the height
+ */
+ public void setRect(double x, double y, double w, double h)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ width = (float) w;
+ height = (float) h;
+ }
+
+ /**
+ * Set the contents of this rectangle to those specified.
+ *
+ * @param r the rectangle to copy
+ * @throws NullPointerException if r is null
+ */
+ public void setRect(Rectangle2D r)
+ {
+ x = (float) r.getX();
+ y = (float) r.getY();
+ width = (float) r.getWidth();
+ height = (float) r.getHeight();
+ }
+
+ /**
+ * Determine where the point lies with respect to this rectangle. The
+ * result will be the binary OR of the appropriate bit masks.
+ *
+ * @param x the x coordinate to check
+ * @param y the y coordinate to check
+ * @return the binary OR of the result
+ * @see #OUT_LEFT
+ * @see #OUT_TOP
+ * @see #OUT_RIGHT
+ * @see #OUT_BOTTOM
+ * @since 1.2
+ */
+ public int outcode(double x, double y)
+ {
+ int result = 0;
+ if (width <= 0)
+ result |= OUT_LEFT | OUT_RIGHT;
+ else if (x < this.x)
+ result |= OUT_LEFT;
+ else if (x > this.x + width)
+ result |= OUT_RIGHT;
+ if (height <= 0)
+ result |= OUT_BOTTOM | OUT_TOP;
+ else if (y < this.y) // Remember that +y heads top-to-bottom.
+ result |= OUT_TOP;
+ else if (y > this.y + height)
+ result |= OUT_BOTTOM;
+ return result;
+ }
+
+ /**
+ * Returns the bounds of this rectangle. A pretty useless method, as this
+ * is already a rectangle.
+ *
+ * @return a copy of this rectangle
+ */
+ public Rectangle2D getBounds2D()
+ {
+ return new Float(x, y, width, height);
+ }
+
+ /**
+ * Return a new rectangle which is the intersection of this and the given
+ * one. The result will be empty if there is no intersection.
+ *
+ * @param r the rectangle to be intersected
+ * @return the intersection
+ * @throws NullPointerException if r is null
+ */
+ public Rectangle2D createIntersection(Rectangle2D r)
+ {
+ Float res = new Float();
+ intersect(this, r, res);
+ return res;
+ }
+
+ /**
+ * Return a new rectangle which is the union of this and the given one.
+ *
+ * @param r the rectangle to be merged
+ * @return the union
+ * @throws NullPointerException if r is null
+ */
+ public Rectangle2D createUnion(Rectangle2D r)
+ {
+ Float res = new Float();
+ union(this, r, res);
+ return res;
+ }
+
+ /**
+ * Returns a string representation of this rectangle. This is in the form
+ * <code>getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width
+ * + ",h=" + height + ']'</code>.
+ *
+ * @return a string representation of this rectangle
+ */
+ public String toString()
+ {
+ return getClass().getName() + "[x=" + x + ",y=" + y + ",w=" + width
+ + ",h=" + height + ']';
+ }
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RectangularShape.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RectangularShape.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RectangularShape.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RectangularShape.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,385 @@
+/* RectangularShape.java -- a rectangular frame for several generic shapes
+ Copyright (C) 2000, 2002 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.geom;
+
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+/**
+ * This class provides a generic framework, and several helper methods, for
+ * subclasses which represent geometric objects inside a rectangular frame.
+ * This does not specify any geometry except for the bounding box.
+ *
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @see Arc2D
+ * @see Ellipse2D
+ * @see Rectangle2D
+ * @see RoundRectangle2D
+ * @status updated to 1.4
+ */
+public abstract class RectangularShape implements Shape, Cloneable
+{
+ /**
+ * Default constructor.
+ */
+ protected RectangularShape()
+ {
+ }
+
+ /**
+ * Get the x coordinate of the upper-left corner of the framing rectangle.
+ *
+ * @return the x coordinate
+ */
+ public abstract double getX();
+
+ /**
+ * Get the y coordinate of the upper-left corner of the framing rectangle.
+ *
+ * @return the y coordinate
+ */
+ public abstract double getY();
+
+ /**
+ * Get the width of the framing rectangle.
+ *
+ * @return the width
+ */
+ public abstract double getWidth();
+
+ /**
+ * Get the height of the framing rectangle.
+ *
+ * @return the height
+ */
+ public abstract double getHeight();
+
+ /**
+ * Get the minimum x coordinate in the frame. This is misnamed, or else
+ * Sun has a bug, because the implementation returns getX() even when
+ * getWidth() is negative.
+ *
+ * @return the minimum x coordinate
+ */
+ public double getMinX()
+ {
+ return getX();
+ }
+
+ /**
+ * Get the minimum y coordinate in the frame. This is misnamed, or else
+ * Sun has a bug, because the implementation returns getY() even when
+ * getHeight() is negative.
+ *
+ * @return the minimum y coordinate
+ */
+ public double getMinY()
+ {
+ return getY();
+ }
+
+ /**
+ * Get the maximum x coordinate in the frame. This is misnamed, or else
+ * Sun has a bug, because the implementation returns getX()+getWidth() even
+ * when getWidth() is negative.
+ *
+ * @return the maximum x coordinate
+ */
+ public double getMaxX()
+ {
+ return getX() + getWidth();
+ }
+
+ /**
+ * Get the maximum y coordinate in the frame. This is misnamed, or else
+ * Sun has a bug, because the implementation returns getY()+getHeight() even
+ * when getHeight() is negative.
+ *
+ * @return the maximum y coordinate
+ */
+ public double getMaxY()
+ {
+ return getY() + getHeight();
+ }
+
+ /**
+ * Return the x coordinate of the center point of the framing rectangle.
+ *
+ * @return the central x coordinate
+ */
+ public double getCenterX()
+ {
+ return getX() + getWidth() / 2;
+ }
+
+ /**
+ * Return the y coordinate of the center point of the framing rectangle.
+ *
+ * @return the central y coordinate
+ */
+ public double getCenterY()
+ {
+ return getY() + getHeight() / 2;
+ }
+
+ /**
+ * Return the frame around this object. Note that this may be a looser
+ * bounding box than getBounds2D.
+ *
+ * @return the frame, in double precision
+ * @see #setFrame(double, double, double, double)
+ */
+ public Rectangle2D getFrame()
+ {
+ return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
+ }
+
+ /**
+ * Test if the shape is empty, meaning that no points are inside it.
+ *
+ * @return true if the shape is empty
+ */
+ public abstract boolean isEmpty();
+
+ /**
+ * Set the framing rectangle of this shape to the given coordinate and size.
+ *
+ * @param x the new x coordinate
+ * @param y the new y coordinate
+ * @param w the new width
+ * @param h the new height
+ * @see #getFrame()
+ */
+ public abstract void setFrame(double x, double y, double w, double h);
+
+ /**
+ * Set the framing rectangle of this shape to the given coordinate and size.
+ *
+ * @param p the new point
+ * @param d the new dimension
+ * @throws NullPointerException if p or d is null
+ * @see #getFrame()
+ */
+ public void setFrame(Point2D p, Dimension2D d)
+ {
+ setFrame(p.getX(), p.getY(), d.getWidth(), d.getHeight());
+ }
+
+ /**
+ * Set the framing rectangle of this shape to the given rectangle.
+ *
+ * @param r the new framing rectangle
+ * @throws NullPointerException if r is null
+ * @see #getFrame()
+ */
+ public void setFrame(Rectangle2D r)
+ {
+ setFrame(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Set the framing rectangle of this shape using two points on a diagonal.
+ * The area will be positive.
+ *
+ * @param x1 the first x coordinate
+ * @param y1 the first y coordinate
+ * @param x2 the second x coordinate
+ * @param y2 the second y coordinate
+ */
+ public void setFrameFromDiagonal(double x1, double y1, double x2, double y2)
+ {
+ if (x1 > x2)
+ {
+ double t = x2;
+ x2 = x1;
+ x1 = t;
+ }
+ if (y1 > y2)
+ {
+ double t = y2;
+ y2 = y1;
+ y1 = t;
+ }
+ setFrame(x1, y1, x2 - x1, y2 - y1);
+ }
+
+ /**
+ * Set the framing rectangle of this shape using two points on a diagonal.
+ * The area will be positive.
+ *
+ * @param p1 the first point
+ * @param p2 the second point
+ * @throws NullPointerException if either point is null
+ */
+ public void setFrameFromDiagonal(Point2D p1, Point2D p2)
+ {
+ setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());
+ }
+
+ /**
+ * Set the framing rectangle of this shape using the center of the frame,
+ * and one of the four corners. The area will be positive.
+ *
+ * @param centerX the x coordinate at the center
+ * @param centerY the y coordinate at the center
+ * @param cornerX the x coordinate at a corner
+ * @param cornerY the y coordinate at a corner
+ */
+ public void setFrameFromCenter(double centerX, double centerY,
+ double cornerX, double cornerY)
+ {
+ double halfw = Math.abs(cornerX - centerX);
+ double halfh = Math.abs(cornerY - centerY);
+ setFrame(centerX - halfw, centerY - halfh, halfw + halfw, halfh + halfh);
+ }
+
+ /**
+ * Set the framing rectangle of this shape using the center of the frame,
+ * and one of the four corners. The area will be positive.
+ *
+ * @param center the center point
+ * @param corner a corner point
+ * @throws NullPointerException if either point is null
+ */
+ public void setFrameFromCenter(Point2D center, Point2D corner)
+ {
+ setFrameFromCenter(center.getX(), center.getY(),
+ corner.getX(), corner.getY());
+ }
+
+ /**
+ * Tests if a point is inside the boundary of the shape.
+ *
+ * @param p the point to test
+ * @return true if the point is inside the shape
+ * @throws NullPointerException if p is null
+ * @see #contains(double, double)
+ */
+ public boolean contains(Point2D p)
+ {
+ return contains(p.getX(), p.getY());
+ }
+
+ /**
+ * Tests if a rectangle and this shape share common internal points.
+ *
+ * @param r the rectangle to test
+ * @return true if the rectangle intersects this shpae
+ * @throws NullPointerException if r is null
+ * @see #intersects(double, double, double, double)
+ */
+ public boolean intersects(Rectangle2D r)
+ {
+ return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Tests if the shape completely contains the given rectangle.
+ *
+ * @param r the rectangle to test
+ * @return true if r is contained in this shape
+ * @throws NullPointerException if r is null
+ * @see #contains(double, double, double, double)
+ */
+ public boolean contains(Rectangle2D r)
+ {
+ return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
+ }
+
+ /**
+ * Returns a bounding box for this shape, in integer format. Notice that you
+ * may get a tighter bound with getBounds2D. If the frame is empty, the
+ * box is the default empty box at the origin.
+ *
+ * @return a bounding box
+ */
+ public Rectangle getBounds()
+ {
+ if (isEmpty())
+ return new Rectangle();
+ double x = getX();
+ double y = getY();
+ double maxx = Math.ceil(x + getWidth());
+ double maxy = Math.ceil(y + getHeight());
+ x = Math.floor(x);
+ y = Math.floor(y);
+ return new Rectangle((int) x, (int) y, (int) (maxx - x), (int) (maxy - y));
+ }
+
+ /**
+ * Return an iterator along the shape boundary. If the optional transform
+ * is provided, the iterator is transformed accordingly. The path is
+ * flattened until all segments differ from the curve by at most the value
+ * of the flatness parameter, within the limits of the default interpolation
+ * recursion limit of 1024 segments between actual points. Each call
+ * returns a new object, independent from others in use. The result is
+ * threadsafe if and only if the iterator returned by
+ * {@link #getPathIterator(AffineTransform)} is as well.
+ *
+ * @param at an optional transform to apply to the iterator
+ * @param flatness the desired flatness
+ * @return a new iterator over the boundary
+ * @throws IllegalArgumentException if flatness is invalid
+ * @since 1.2
+ */
+ public PathIterator getPathIterator(AffineTransform at, double flatness)
+ {
+ return new FlatteningPathIterator(getPathIterator(at), flatness);
+ }
+
+ /**
+ * Create a new shape of the same run-time type with the same contents as
+ * this one.
+ *
+ * @return the clone
+ */
+ public Object clone()
+ {
+ try
+ {
+ return super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw (Error) new InternalError().initCause(e); // Impossible
+ }
+ }
+} // class RectangularShape
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RoundRectangle2D.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RoundRectangle2D.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RoundRectangle2D.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/RoundRectangle2D.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,533 @@
+/* RoundRectangle2D.java -- represents a rectangle with rounded corners
+ Copyright (C) 2000, 2002, 2003, 2004 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.geom;
+
+import java.util.NoSuchElementException;
+
+
+/** This class implements a rectangle with rounded corners.
+ * @author Tom Tromey (tromey at cygnus.com)
+ * @date December 3, 2000
+ */
+public abstract class RoundRectangle2D extends RectangularShape
+{
+ /** Return the arc height of this round rectangle. */
+ public abstract double getArcHeight();
+
+ /** Return the arc width of this round rectangle. */
+ public abstract double getArcWidth();
+
+ /** Set the values of this round rectangle
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ * @param arcWidth The arc width
+ * @param arcHeight The arc height
+ */
+ public abstract void setRoundRect(double x, double y, double w, double h,
+ double arcWidth, double arcHeight);
+
+ /** Create a RoundRectangle2D. This is protected because this class
+ * is abstract and cannot be instantiated.
+ */
+ protected RoundRectangle2D()
+ {
+ }
+
+ /** Return true if this object contains the specified point.
+ * @param x The x coordinate
+ * @param y The y coordinate
+ */
+ public boolean contains(double x, double y)
+ {
+ double mx = getX();
+ double mw = getWidth();
+ if (x < mx || x >= mx + mw)
+ return false;
+ double my = getY();
+ double mh = getHeight();
+ if (y < my || y >= my + mh)
+ return false;
+
+ // Now check to see if the point is in range of an arc.
+ double dy = Math.min(Math.abs(my - y), Math.abs(my + mh - y));
+ double dx = Math.min(Math.abs(mx - x), Math.abs(mx + mw - x));
+
+ // The arc dimensions are that of the corresponding ellipse
+ // thus a 90 degree segment is half of that.
+ double aw = getArcWidth() / 2.0;
+ double ah = getArcHeight() / 2.0;
+ if (dx > aw || dy > ah)
+ return true;
+
+ // At this point DX represents the distance from the nearest edge
+ // of the rectangle. But we want to transform it to represent the
+ // scaled distance from the center of the ellipse that forms the
+ // arc. Hence this code:
+ dy = (ah - dy) / ah;
+ dx = (aw - dx) / aw;
+
+ return dx * dx + dy * dy <= 1.0;
+ }
+
+ /** Return true if this object contains the specified rectangle
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ */
+ public boolean contains(double x, double y, double w, double h)
+ {
+ // We have to check all four points here (for ordinary rectangles
+ // we can just check opposing corners).
+ return (contains(x, y) && contains(x, y + h) && contains(x + w, y + h)
+ && contains(x + w, y));
+ }
+
+ /** Return a new path iterator which iterates over this rectangle.
+ * @param at An affine transform to apply to the object
+ */
+ public PathIterator getPathIterator(final AffineTransform at)
+ {
+ final double minx = getX();
+ final double miny = getY();
+ final double maxx = minx + getWidth();
+ final double maxy = miny + getHeight();
+ final double arcwidth = getArcWidth();
+ final double archeight = getArcHeight();
+ return new PathIterator()
+ {
+ /** We iterate counterclockwise around the rectangle, starting in the
+ * upper right. This variable tracks our current point, which
+ * can be on either side of a given corner. */
+ private int current = 0;
+
+ /** Child path iterator, used for corners. */
+ private PathIterator corner;
+
+ /** This is used when rendering the corners. We re-use the arc
+ * for each corner. */
+ private Arc2D arc = new Arc2D.Double();
+
+ /** Temporary array used by getPoint. */
+ private double[] temp = new double[2];
+
+ public int getWindingRule()
+ {
+ return WIND_NON_ZERO;
+ }
+
+ public boolean isDone()
+ {
+ return current > 9;
+ }
+
+ private void getPoint(int val)
+ {
+ switch (val)
+ {
+ case 0:
+ case 8:
+ temp[0] = maxx;
+ temp[1] = miny + archeight;
+ break;
+ case 7:
+ temp[0] = maxx;
+ temp[1] = maxy - archeight;
+ break;
+ case 6:
+ temp[0] = maxx - arcwidth;
+ temp[1] = maxy;
+ break;
+ case 5:
+ temp[0] = minx + arcwidth;
+ temp[1] = maxy;
+ break;
+ case 4:
+ temp[0] = minx;
+ temp[1] = maxy - archeight;
+ break;
+ case 3:
+ temp[0] = minx;
+ temp[1] = miny + archeight;
+ break;
+ case 2:
+ temp[0] = minx + arcwidth;
+ temp[1] = miny;
+ break;
+ case 1:
+ temp[0] = maxx - arcwidth;
+ temp[1] = miny;
+ break;
+ }
+ }
+
+ public void next()
+ {
+ if (current >= 8)
+ ++current;
+ else if (corner != null)
+ {
+ // We're iterating through the corner. Work on the child
+ // iterator; if it finishes, reset and move to the next
+ // point along the rectangle.
+ corner.next();
+ if (corner.isDone())
+ {
+ corner = null;
+ ++current;
+ }
+ }
+ else
+ {
+ // Make an arc between this point on the rectangle and
+ // the next one, and then iterate over this arc.
+ getPoint(current);
+ double x1 = temp[0];
+ double y1 = temp[1];
+ getPoint(current + 1);
+ Rectangle2D.Double r = new Rectangle2D.Double(Math.min(x1,
+ temp[0]),
+ Math.min(y1,
+ temp[1]),
+ Math.abs(x1
+ - temp[0]),
+ Math.abs(y1
+ - temp[1]));
+ arc.setArc(r, (current >> 1) * 90.0, 90.0, Arc2D.OPEN);
+ corner = arc.getPathIterator(at);
+ }
+ }
+
+ public int currentSegment(float[] coords)
+ {
+ if (corner != null)
+ {
+ int r = corner.currentSegment(coords);
+ if (r == SEG_MOVETO)
+ r = SEG_LINETO;
+ return r;
+ }
+
+ if (current < 9)
+ {
+ getPoint(current);
+ coords[0] = (float) temp[0];
+ coords[1] = (float) temp[1];
+ }
+ else if (current == 9)
+ return SEG_CLOSE;
+ else
+ throw new NoSuchElementException("rect iterator out of bounds");
+
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return current == 0 ? SEG_MOVETO : SEG_LINETO;
+ }
+
+ public int currentSegment(double[] coords)
+ {
+ if (corner != null)
+ {
+ int r = corner.currentSegment(coords);
+ if (r == SEG_MOVETO)
+ r = SEG_LINETO;
+ return r;
+ }
+
+ if (current < 9)
+ {
+ getPoint(current);
+ coords[0] = temp[0];
+ coords[1] = temp[1];
+ }
+ else if (current == 9)
+ return SEG_CLOSE;
+ else
+ throw new NoSuchElementException("rect iterator out of bounds");
+
+ if (at != null)
+ at.transform(coords, 0, coords, 0, 1);
+ return current == 0 ? SEG_MOVETO : SEG_LINETO;
+ }
+ };
+ }
+
+ /** Return true if the given rectangle intersects this shape.
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ */
+ public boolean intersects(double x, double y, double w, double h)
+ {
+ // Check if any corner is within the rectangle
+ return (contains(x, y) || contains(x, y + h) || contains(x + w, y + h)
+ || contains(x + w, y));
+ }
+
+ /** Set the boundary of this round rectangle.
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ */
+ public void setFrame(double x, double y, double w, double h)
+ {
+ // This is a bit lame.
+ setRoundRect(x, y, w, h, getArcWidth(), getArcHeight());
+ }
+
+ /** Set the values of this round rectangle to be the same as those
+ * of the argument.
+ * @param rr The round rectangle to copy
+ */
+ public void setRoundRect(RoundRectangle2D rr)
+ {
+ setRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(),
+ rr.getArcWidth(), rr.getArcHeight());
+ }
+
+ /** A subclass of RoundRectangle which keeps its parameters as
+ * doubles. */
+ public static class Double extends RoundRectangle2D
+ {
+ /** The height of the corner arc. */
+ public double archeight;
+
+ /** The width of the corner arc. */
+ public double arcwidth;
+
+ /** The x coordinate of this object. */
+ public double x;
+
+ /** The y coordinate of this object. */
+ public double y;
+
+ /** The width of this object. */
+ public double width;
+
+ /** The height of this object. */
+ public double height;
+
+ /** Construct a new instance, with all parameters set to 0. */
+ public Double()
+ {
+ }
+
+ /** Construct a new instance with the given arguments.
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ * @param arcWidth The arc width
+ * @param arcHeight The arc height
+ */
+ public Double(double x, double y, double w, double h, double arcWidth,
+ double arcHeight)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = w;
+ this.height = h;
+ this.arcwidth = arcWidth;
+ this.archeight = arcHeight;
+ }
+
+ public double getArcHeight()
+ {
+ return archeight;
+ }
+
+ public double getArcWidth()
+ {
+ return arcwidth;
+ }
+
+ public Rectangle2D getBounds2D()
+ {
+ return new Rectangle2D.Double(x, y, width, height);
+ }
+
+ public double getX()
+ {
+ return x;
+ }
+
+ public double getY()
+ {
+ return y;
+ }
+
+ public double getWidth()
+ {
+ return width;
+ }
+
+ public double getHeight()
+ {
+ return height;
+ }
+
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ public void setRoundRect(double x, double y, double w, double h,
+ double arcWidth, double arcHeight)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = w;
+ this.height = h;
+ this.arcwidth = arcWidth;
+ this.archeight = arcHeight;
+ }
+ } // class Double
+
+ /** A subclass of RoundRectangle which keeps its parameters as
+ * floats. */
+ public static class Float extends RoundRectangle2D
+ {
+ /** The height of the corner arc. */
+ public float archeight;
+
+ /** The width of the corner arc. */
+ public float arcwidth;
+
+ /** The x coordinate of this object. */
+ public float x;
+
+ /** The y coordinate of this object. */
+ public float y;
+
+ /** The width of this object. */
+ public float width;
+
+ /** The height of this object. */
+ public float height;
+
+ /** Construct a new instance, with all parameters set to 0. */
+ public Float()
+ {
+ }
+
+ /** Construct a new instance with the given arguments.
+ * @param x The x coordinate
+ * @param y The y coordinate
+ * @param w The width
+ * @param h The height
+ * @param arcWidth The arc width
+ * @param arcHeight The arc height
+ */
+ public Float(float x, float y, float w, float h, float arcWidth,
+ float arcHeight)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = w;
+ this.height = h;
+ this.arcwidth = arcWidth;
+ this.archeight = arcHeight;
+ }
+
+ public double getArcHeight()
+ {
+ return archeight;
+ }
+
+ public double getArcWidth()
+ {
+ return arcwidth;
+ }
+
+ public Rectangle2D getBounds2D()
+ {
+ return new Rectangle2D.Float(x, y, width, height);
+ }
+
+ public double getX()
+ {
+ return x;
+ }
+
+ public double getY()
+ {
+ return y;
+ }
+
+ public double getWidth()
+ {
+ return width;
+ }
+
+ public double getHeight()
+ {
+ return height;
+ }
+
+ public boolean isEmpty()
+ {
+ return width <= 0 || height <= 0;
+ }
+
+ public void setRoundRect(float x, float y, float w, float h,
+ float arcWidth, float arcHeight)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = w;
+ this.height = h;
+ this.arcwidth = arcWidth;
+ this.archeight = arcHeight;
+ }
+
+ public void setRoundRect(double x, double y, double w, double h,
+ double arcWidth, double arcHeight)
+ {
+ this.x = (float) x;
+ this.y = (float) y;
+ this.width = (float) w;
+ this.height = (float) h;
+ this.arcwidth = (float) arcWidth;
+ this.archeight = (float) arcHeight;
+ }
+ } // class Float
+} // class RoundRectangle2D
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Area-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Area-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Area-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-3.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-3.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-3.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-4.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-4.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-4.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-5.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-5.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/CubicCurve2D-5.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Ellipse-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Ellipse-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/Ellipse-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/FlatteningPathIterator-1.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/FlatteningPathIterator-1.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/FlatteningPathIterator-1.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/FlatteningPathIterator-1.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,481 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>The GNU Implementation of java.awt.geom.FlatteningPathIterator</title>
+ <meta name="author" content="Sascha Brawer" />
+ <style type="text/css"><!--
+ td { white-space: nowrap; }
+ li { margin: 2mm 0; }
+ --></style>
+</head>
+<body>
+
+<h1>The GNU Implementation of FlatteningPathIterator</h1>
+
+<p><i><a href="http://www.dandelis.ch/people/brawer/">Sascha
+Brawer</a>, November 2003</i></p>
+
+<p>This document describes the GNU implementation of the class
+<code>java.awt.geom.FlatteningPathIterator</code>. It does
+<em>not</em> describe how a programmer should use this class; please
+refer to the generated API documentation for this purpose. Instead, it
+is intended for maintenance programmers who want to understand the
+implementation, for example because they want to extend the class or
+fix a bug.</p>
+
+
+<h2>Data Structures</h2>
+
+<p>The algorithm uses a stack. Its allocation is delayed to the time
+when the source path iterator actually returns the first curved
+segment (either <code>SEG_QUADTO</code> or <code>SEG_CUBICTO</code>).
+If the input path does not contain any curved segments, the value of
+the <code>stack</code> variable stays <code>null</code>. In this quite
+common case, the memory consumption is minimal.</p>
+
+<dl><dt><code>stack</code></dt><dd>The variable <code>stack</code> is
+a <code>double</code> array that holds the start, control and end
+points of individual sub-segments.</dd>
+
+<dt><code>recLevel</code></dt><dd>The variable <code>recLevel</code>
+holds how many recursive sub-divisions were needed to calculate a
+segment. The original curve has recursion level 0. For each
+sub-division, the corresponding recursion level is increased by
+one.</dd>
+
+<dt><code>stackSize</code></dt><dd>Finally, the variable
+<code>stackSize</code> indicates how many sub-segments are stored on
+the stack.</dd></dl>
+
+<h2>Algorithm</h2>
+
+<p>The implementation separately processes each segment that the
+base iterator returns.</p>
+
+<p>In the case of <code>SEG_CLOSE</code>,
+<code>SEG_MOVETO</code> and <code>SEG_LINETO</code> segments, the
+implementation simply hands the segment to the consumer, without actually
+doing anything.</p>
+
+<p>Any <code>SEG_QUADTO</code> and <code>SEG_CUBICTO</code> segments
+need to be flattened. Flattening is performed with a fixed-sized
+stack, holding the coordinates of subdivided segments. When the base
+iterator returns a <code>SEG_QUADTO</code> and
+<code>SEG_CUBICTO</code> segments, it is recursively flattened as
+follows:</p>
+
+<ol><li>Intialization: Allocate memory for the stack (unless a
+sufficiently large stack has been allocated previously). Push the
+original quadratic or cubic curve onto the stack. Mark that segment as
+having a <code>recLevel</code> of zero.</li>
+
+<li>If the stack is empty, flattening the segment is complete,
+and the next segment is fetched from the base iterator.</li>
+
+<li>If the stack is not empty, pop a curve segment from the
+stack.
+
+ <ul><li>If its <code>recLevel</code> exceeds the recursion limit,
+ hand the current segment to the consumer.</li>
+
+ <li>Calculate the squared flatness of the segment. If it smaller
+ than <code>flatnessSq</code>, hand the current segment to the
+ consumer.</li>
+
+ <li>Otherwise, split the segment in two halves. Push the right
+ half onto the stack. Then, push the left half onto the stack.
+ Continue with step two.</li></ul></li>
+</ol>
+
+<p>The implementation is slightly complicated by the fact that
+consumers <em>pull</em> the flattened segments from the
+<code>FlatteningPathIterator</code>. This means that we actually
+cannot “hand the curent segment over to the consumer.”
+But the algorithm is easier to understand if one assumes a
+<em>push</em> paradigm.</p>
+
+
+<h2>Example</h2>
+
+<p>The following example shows how a
+<code>FlatteningPathIterator</code> processes a
+<code>SEG_QUADTO</code> segment. It is (arbitrarily) assumed that the
+recursion limit was set to 2.</p>
+
+<blockquote>
+<table border="1" cellspacing="0" cellpadding="8">
+ <tr align="center" valign="baseline">
+ <th></th><th>A</th><th>B</th><th>C</th>
+ <th>D</th><th>E</th><th>F</th><th>G</th><th>H</th>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[0]</code></th>
+ <td>—</td>
+ <td>—</td>
+ <td><i>S<sub>ll</sub>.x</i></td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[1]</code></th>
+ <td>—</td>
+ <td>—</td>
+ <td><i>S<sub>ll</sub>.y</i></td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[2]</code></th>
+ <td>—</td>
+ <td>—</td>
+ <td><i>C<sub>ll</sub>.x</i></td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[3]</code></th>
+ <td>—</td>
+ <td>—</td>
+ <td><i>C<sub>ll</sub>.y</i></td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[4]</code></th>
+ <td>—</td>
+ <td><i>S<sub>l</sub>.x</i></td>
+ <td><i>E<sub>ll</sub>.x</i>
+ = <i>S<sub>lr</sub>.x</i></td>
+ <td><i>S<sub>lr</sub>.x</i></td>
+ <td>—</td>
+ <td><i>S<sub>rl</sub>.x</i></td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[5]</code></th>
+ <td>—</td>
+ <td><i>S<sub>l</sub>.y</i></td>
+ <td><i>E<sub>ll</sub>.x</i>
+ = <i>S<sub>lr</sub>.y</i></td>
+ <td><i>S<sub>lr</sub>.y</i></td>
+ <td>—</td>
+ <td><i>S<sub>rl</sub>.y</i></td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[6]</code></th>
+ <td>—</td>
+ <td><i>C<sub>l</sub>.x</i></td>
+ <td><i>C<sub>lr</sub>.x</i></td>
+ <td><i>C<sub>lr</sub>.x</i></td>
+ <td>—</td>
+ <td><i>C<sub>rl</sub>.x</i></td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[7]</code></th>
+ <td>—</td>
+ <td><i>C<sub>l</sub>.y</i></td>
+ <td><i>C<sub>lr</sub>.y</i></td>
+ <td><i>C<sub>lr</sub>.y</i></td>
+ <td>—</td>
+ <td><i>C<sub>rl</sub>.y</i></td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[8]</code></th>
+ <td><i>S.x</i></td>
+ <td><i>E<sub>l</sub>.x</i>
+ = <i>S<sub>r</sub>.x</i></td>
+ <td><i>E<sub>lr</sub>.x</i>
+ = <i>S<sub>r</sub>.x</i></td>
+ <td><i>E<sub>lr</sub>.x</i>
+ = <i>S<sub>r</sub>.x</i></td>
+ <td><i>S<sub>r</sub>.x</i></td>
+ <td><i>E<sub>rl</sub>.x</i>
+ = <i>S<sub>rr</sub>.x</i></td>
+ <td><i>S<sub>rr</sub>.x</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[9]</code></th>
+ <td><i>S.y</i></td>
+ <td><i>E<sub>l</sub>.y</i>
+ = <i>S<sub>r</sub>.y</i></td>
+ <td><i>E<sub>lr</sub>.y</i>
+ = <i>S<sub>r</sub>.y</i></td>
+ <td><i>E<sub>lr</sub>.y</i>
+ = <i>S<sub>r</sub>.y</i></td>
+ <td><i>S<sub>r</sub>.y</i></td>
+ <td><i>E<sub>rl</sub>.y</i>
+ = <i>S<sub>rr</sub>.y</i></td>
+ <td><i>S<sub>rr</sub>.y</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[10]</code></th>
+ <td><i>C.x</i></td>
+ <td><i>C<sub>r</sub>.x</i></td>
+ <td><i>C<sub>r</sub>.x</i></td>
+ <td><i>C<sub>r</sub>.x</i></td>
+ <td><i>C<sub>r</sub>.x</i></td>
+ <td><i>C<sub>rr</sub>.x</i></td>
+ <td><i>C<sub>rr</sub>.x</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[11]</code></th>
+ <td><i>C.y</i></td>
+ <td><i>C<sub>r</sub>.y</i></td>
+ <td><i>C<sub>r</sub>.y</i></td>
+ <td><i>C<sub>r</sub>.y</i></td>
+ <td><i>C<sub>r</sub>.y</i></td>
+ <td><i>C<sub>rr</sub>.y</i></td>
+ <td><i>C<sub>rr</sub>.y</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[12]</code></th>
+ <td><i>E.x</i></td>
+ <td><i>E<sub>r</sub>.x</i></td>
+ <td><i>E<sub>r</sub>.x</i></td>
+ <td><i>E<sub>r</sub>.x</i></td>
+ <td><i>E<sub>r</sub>.x</i></td>
+ <td><i>E<sub>rr</sub>.x</i></td>
+ <td><i>E<sub>rr</sub>.x</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stack[13]</code></th>
+ <td><i>E.y</i></td>
+ <td><i>E<sub>r</sub>.y</i></td>
+ <td><i>E<sub>r</sub>.y</i></td>
+ <td><i>E<sub>r</sub>.y</i></td>
+ <td><i>E<sub>r</sub>.y</i></td>
+ <td><i>E<sub>rr</sub>.y</i></td>
+ <td><i>E<sub>rr</sub>.x</i></td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>stackSize</code></th>
+ <td>1</td>
+ <td>2</td>
+ <td>3</td>
+ <td>2</td>
+ <td>1</td>
+ <td>2</td>
+ <td>1</td>
+ <td>0</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>recLevel[2]</code></th>
+ <td>—</td>
+ <td>—</td>
+ <td>2</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>recLevel[1]</code></th>
+ <td>—</td>
+ <td>1</td>
+ <td>2</td>
+ <td>2</td>
+ <td>—</td>
+ <td>2</td>
+ <td>—</td>
+ <td>—</td>
+ </tr>
+ <tr align="center" valign="baseline">
+ <th><code>recLevel[0]</code></th>
+ <td>0</td>
+ <td>1</td>
+ <td>1</td>
+ <td>1</td>
+ <td>1</td>
+ <td>2</td>
+ <td>2</td>
+ <td>—</td>
+ </tr>
+ </table>
+</blockquote>
+
+<ol>
+
+<li>The data structures are initialized as follows.
+
+<ul><li>The segment’s end point <i>E</i>, control point
+<i>C</i>, and start point <i>S</i> are pushed onto the stack.</li>
+
+ <li>Currently, the curve in the stack would be approximated by one
+ single straight line segment (<i>S</i> – <i>E</i>).
+ Therefore, <code>stackSize</code> is set to 1.</li>
+
+ <li>This single straight line segment is approximating the original
+ curve, which can be seen as the result of zero recursive
+ splits. Therefore, <code>recLevel[0]</code> is set to
+ zero.</li></ul>
+
+Column A shows the state after the initialization step.</li>
+
+<li>The algorithm proceeds by taking the topmost curve segment
+(<i>S</i> – <i>C</i> – <i>E</i>) from the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[0]</code>) is zero, which is smaller than
+ the limit 2.</li>
+
+ <li>The method <code>java.awt.geom.QuadCurve2D.getFlatnessSq</code>
+ is called to calculate the squared flatness.</li>
+
+ <li>For the sake of argument, we assume that the squared flatness is
+ exceeding the threshold stored in <code>flatnessSq</code>. Thus, the
+ curve segment <i>S</i> – <i>C</i> – <i>E</i> gets
+ subdivided into a left and a right half, namely
+ <i>S<sub>l</sub></i> – <i>C<sub>l</sub></i> –
+ <i>E<sub>l</sub></i> and <i>S<sub>r</sub></i> –
+ <i>C<sub>r</sub></i> – <i>E<sub>r</sub></i>. Both halves are
+ pushed onto the stack, so the left half is now on top.
+
+ <br /> <br />The left half starts at the same point
+ as the original curve, so <i>S<sub>l</sub></i> has the same
+ coordinates as <i>S</i>. Similarly, the end point of the right
+ half and of the original curve are identical
+ (<i>E<sub>r</sub></i> = <i>E</i>). More interestingly, the left
+ half ends where the right half starts. Because
+ <i>E<sub>l</sub></i> = <i>S<sub>r</sub></i>, their coordinates need
+ to be stored only once, which amounts to saving 16 bytes (two
+ <code>double</code> values) for each iteration.</li></ul>
+
+Column B shows the state after the first iteration.</li>
+
+<li>Again, the topmost curve segment (<i>S<sub>l</sub></i>
+– <i>C<sub>l</sub></i> – <i>E<sub>l</sub></i>) is
+taken from the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[1]</code>) is 1, which is smaller than
+ the limit 2.</li>
+
+ <li>The method <code>java.awt.geom.QuadCurve2D.getFlatnessSq</code>
+ is called to calculate the squared flatness.</li>
+
+ <li>Assuming that the segment is still not considered
+ flat enough, it gets subdivided into a left
+ (<i>S<sub>ll</sub></i> – <i>C<sub>ll</sub></i> –
+ <i>E<sub>ll</sub></i>) and a right (<i>S<sub>lr</sub></i>
+ – <i>C<sub>lr</sub></i> – <i>E<sub>lr</sub></i>)
+ half.</li></ul>
+
+Column C shows the state after the second iteration.</li>
+
+<li>The topmost curve segment (<i>S<sub>ll</sub></i> –
+<i>C<sub>ll</sub></i> – <i>E<sub>ll</sub></i>) is popped from
+the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[2]</code>) is 2, which is <em>not</em> smaller than
+ the limit 2. Therefore, a <code>SEG_LINETO</code> (from
+ <i>S<sub>ll</sub></i> to <i>E<sub>ll</sub></i>) is passed to the
+ consumer.</li></ul>
+
+ The new state is shown in column D.</li>
+
+
+<li>The topmost curve segment (<i>S<sub>lr</sub></i> –
+<i>C<sub>lr</sub></i> – <i>E<sub>lr</sub></i>) is popped from
+the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[1]</code>) is 2, which is <em>not</em> smaller than
+ the limit 2. Therefore, a <code>SEG_LINETO</code> (from
+ <i>S<sub>lr</sub></i> to <i>E<sub>lr</sub></i>) is passed to the
+ consumer.</li></ul>
+
+ The new state is shown in column E.</li>
+
+<li>The algorithm proceeds by taking the topmost curve segment
+(<i>S<sub>r</sub></i> – <i>C<sub>r</sub></i> –
+<i>E<sub>r</sub></i>) from the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[0]</code>) is 1, which is smaller than
+ the limit 2.</li>
+
+ <li>The method <code>java.awt.geom.QuadCurve2D.getFlatnessSq</code>
+ is called to calculate the squared flatness.</li>
+
+ <li>For the sake of argument, we again assume that the squared
+ flatness is exceeding the threshold stored in
+ <code>flatnessSq</code>. Thus, the curve segment
+ (<i>S<sub>r</sub></i> – <i>C<sub>r</sub></i> –
+ <i>E<sub>r</sub></i>) is subdivided into a left and a right half,
+ namely
+ <i>S<sub>rl</sub></i> – <i>C<sub>rl</sub></i> –
+ <i>E<sub>rl</sub></i> and <i>S<sub>rr</sub></i> –
+ <i>C<sub>rr</sub></i> – <i>E<sub>rr</sub></i>. Both halves
+ are pushed onto the stack.</li></ul>
+
+ The new state is shown in column F.</li>
+
+<li>The topmost curve segment (<i>S<sub>rl</sub></i> –
+<i>C<sub>rl</sub></i> – <i>E<sub>rl</sub></i>) is popped from
+the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[2]</code>) is 2, which is <em>not</em> smaller than
+ the limit 2. Therefore, a <code>SEG_LINETO</code> (from
+ <i>S<sub>rl</sub></i> to <i>E<sub>rl</sub></i>) is passed to the
+ consumer.</li></ul>
+
+ The new state is shown in column G.</li>
+
+<li>The topmost curve segment (<i>S<sub>rr</sub></i> –
+<i>C<sub>rr</sub></i> – <i>E<sub>rr</sub></i>) is popped from
+the stack.
+
+ <ul><li>The recursion level of this segment (stored in
+ <code>recLevel[2]</code>) is 2, which is <em>not</em> smaller than
+ the limit 2. Therefore, a <code>SEG_LINETO</code> (from
+ <i>S<sub>rr</sub></i> to <i>E<sub>rr</sub></i>) is passed to the
+ consumer.</li></ul>
+
+ The new state is shown in column H.</li>
+
+<li>The stack is now empty. The FlatteningPathIterator will fetch the
+next segment from the base iterator, and process it.</li>
+
+</ol>
+
+<p>In order to split the most recently pushed segment, the
+<code>subdivideQuadratic()</code> method passes <code>stack</code>
+directly to
+<code>QuadCurve2D.subdivide(double[],int,double[],int,double[],int)</code>.
+Because the stack grows towards the beginning of the array, no data
+needs to be copied around: <code>subdivide</code> will directly store
+the result into the stack, which will have the contents shown to the
+right.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/GeneralPath-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/GeneralPath-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/GeneralPath-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-1.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-1.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-2.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-2.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-2.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-3.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-3.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-3.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-4.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-4.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-4.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-5.png
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-5.png?rev=43913&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/doc-files/QuadCurve2D-5.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/geom/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.geom package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.geom</title></head>
+
+<body>
+<p>Classes to represent 2D objects and different path transformations.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputContext.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputContext.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputContext.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputContext.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,435 @@
+/* InputContext.java -- provides the context for text input
+ Copyright (C) 2002, 2003, 2004, 2005 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., 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.im;
+
+import gnu.java.util.EmptyEnumeration;
+
+import java.awt.AWTEvent;
+import java.awt.AWTException;
+import java.awt.Component;
+import java.awt.im.spi.InputMethod;
+import java.awt.im.spi.InputMethodDescriptor;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ * Provides a context for controlling input methods and keyboard layouts.
+ * This class provides the communication layer between the client component,
+ * and the various locale-dependent text entry input methods that can be used
+ * for the client. By default, there is one instance per Window, shared among
+ * all components, but this limits text entry to one component at a time.
+ * Thus, text components can create their own instance to allow text entry
+ * in multiple components at a time.
+ *
+ * <p>By using the interfaces of {@link java.awt.im.spi}, you can install
+ * extensions which allow additional input methods. Some of these may use
+ * platform native input methods, or keyboard layouts provided by the platform.
+ * Input methods are unavailable if none have been installed and the platform
+ * has no underlying native input methods. Extensions are installed as jar
+ * files, usually accessed in the default extension location or specified by
+ * the -extdir VM flag. The jar must contain a file named
+ * "META_INF/services/java.awt.im.spi.InputMethodDescriptor" which lists,
+ * one entry per line in UTF-8 encoding, each class in the jar that implements
+ * java.awt.im.spi.InputMethodDescriptor.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see Component#getInputContext()
+ * @see Component#enableInputMethods(boolean)
+ * @since 1.2
+ * @status updated to 1.4, but unverified
+ */
+public class InputContext
+{
+ /**
+ * The list of installed input method descriptors.
+ */
+ private static final ArrayList descriptors = new ArrayList();
+ static
+ {
+ Enumeration e;
+ try
+ {
+ e = ClassLoader.getSystemResources
+ ("META_INF/services/java.awt.im.spi.InputMethodDescriptor");
+ }
+ catch (IOException ex)
+ {
+ // XXX Should we do something else?
+ e = EmptyEnumeration.getInstance();
+ }
+ while (e.hasMoreElements())
+ {
+ URL url = (URL) e.nextElement();
+ BufferedReader in;
+ String line;
+ try
+ {
+ in = new BufferedReader
+ (new InputStreamReader(url.openConnection().getInputStream(),
+ "UTF-8"));
+ line = in.readLine().trim();
+ }
+ catch (IOException ignored)
+ {
+ continue;
+ }
+ outer:
+ while (line != null)
+ {
+ try
+ {
+ if (line.charAt(0) != '#')
+ {
+ Class c = Class.forName(line);
+ descriptors.add((InputMethodDescriptor) c.newInstance());
+ }
+ line = in.readLine().trim();
+ }
+ catch (IOException ex)
+ {
+ continue outer;
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+ }
+
+ /** The current input method; null if no input methods are installed. */
+ private InputMethod im;
+
+ /** Map of locales to the most recently selected input method. */
+ private final HashMap recent = new HashMap();
+
+ /** The list of acceptable character subsets. */
+ private Character.Subset[] subsets;
+
+ /**
+ * Construct an InputContext. This is protected, so clients must use
+ * {@link #getInstance()} instead.
+ */
+ protected InputContext()
+ {
+ }
+
+ /**
+ * Returns a new InputContext.
+ *
+ * @return a new instance, initialized to the default locale if available
+ */
+ public static InputContext getInstance()
+ {
+ InputContext ic = new InputContext();
+ ic.selectInputMethod(Locale.getDefault());
+ return ic;
+ }
+
+ /**
+ * Attempts to select an input method or keyboard layout which supports the
+ * given locale. This returns true if a locale is available and was selected.
+ * The following steps are taken in choosing an input method:<ul>
+ * <li>If the currently selected input method or keyboard layout supports
+ * the requested locale, it remains selected.</li>
+ * <li>If there is no input method or keyboard layout available that
+ * supports the requested locale, the current input method or keyboard
+ * layout remains selected.</li>
+ * <li>If the user has previously selected an input method or keyboard
+ * layout for the requested locale from the user interface, then the most
+ * recently selected such input method or keyboard layout is reselected.</li>
+ * <li>Otherwise, an input method or keyboard layout that supports the
+ * requested locale is selected in an implementation dependent way. This
+ * implementation chooses the first input method which supports the requested
+ * locale based on the InputMethodDescriptors loaded from the extensions
+ * installed on the CLASSPATH.</li>
+ * </ul>
+ *
+ * <p>Before switching away from an input method, any currently uncommitted
+ * text is committed. Not all host operating systems provide API to
+ * determine the locale of the currently selected native input method or
+ * keyboard layout, and to select a native input method or keyboard layout
+ * by locale. For host operating systems that don't provide such API,
+ * selectInputMethod assumes that native input methods or keyboard layouts
+ * provided by the host operating system support only the system's default
+ * locale.
+ *
+ * <p>An example of where this may be called is in a multi-language document,
+ * when moving the insertion point between sections of different locale, so
+ * that the user may use the input method appropriate to that section of the
+ * document.
+ *
+ * @param locale the desired new locale
+ * @return true if the new locale is active
+ * @throws NullPointerException if locale is null
+ */
+ public boolean selectInputMethod(Locale locale)
+ {
+ if (im != null && im.setLocale(locale))
+ {
+ recent.put(locale, im);
+ return true;
+ }
+ InputMethod next = (InputMethod) recent.get(locale);
+ outer:
+ if (next != null)
+ for (int i = 0, limit = descriptors.size(); i < limit; i++)
+ {
+ InputMethodDescriptor d = (InputMethodDescriptor) descriptors.get(i);
+ Locale[] list;
+ try
+ {
+ list = d.getAvailableLocales();
+ }
+ catch (AWTException ignored)
+ {
+ continue;
+ }
+ for (int j = list.length; --j >= 0; )
+ if (locale.equals(list[j]))
+ {
+ try
+ {
+ next = d.createInputMethod();
+ recent.put(locale, next);
+ }
+ catch (Exception ignored)
+ {
+ continue;
+ }
+ }
+ }
+ if (next == null)
+ return false;
+ // XXX I'm not sure if this does all the necessary steps in the switch.
+ if (im != null)
+ {
+ try
+ {
+ next.setCompositionEnabled(im.isCompositionEnabled());
+ }
+ catch (UnsupportedOperationException ignored)
+ {
+ }
+ im.endComposition();
+ im.deactivate(false);
+ im.hideWindows();
+ }
+ im = next;
+ im.setLocale(locale);
+ im.setCharacterSubsets(subsets);
+ return true;
+ }
+
+ /**
+ * Returns the current locale of the current input method or keyboard
+ * layout. Returns null if the input context does not have a current input
+ * method or keyboard layout or if the current input method's
+ * {@link InputMethod#getLocale()} method returns null. Not all host
+ * operating systems provide API to determine the locale of the currently
+ * selected native input method or keyboard layout. For host operating
+ * systems that don't provide such API, getLocale assumes that the current
+ * locale of all native input methods or keyboard layouts provided by the
+ * host operating system is the system's default locale.
+ *
+ * @return the locale of the current input method, or null
+ * @since 1.3
+ */
+ public Locale getLocale()
+ {
+ return im == null ? null : im.getLocale();
+ }
+
+ /**
+ * Sets the subsets of Unicode characters allowed to be input by the current
+ * input method, as well as subsequent input methods. The value of null
+ * implies all characters are legal. Applications should not rely on this
+ * behavior, since native host input methods may not allow restrictions.
+ * If no current input method is available, this has no immediate effect.
+ *
+ * @param subsets the set of Unicode subsets to accept, or null
+ */
+ public void setCharacterSubsets(Character.Subset[] subsets)
+ {
+ this.subsets = subsets;
+ if (im != null)
+ im.setCharacterSubsets(subsets);
+ }
+
+ /**
+ * Changes the enabled status of the current input method. An input method
+ * that is enabled for composition interprets incoming events for both
+ * composition and control purposes, while a disabled input method only
+ * interprets control commands (including commands to enable itself).
+ *
+ * @param enable whether to enable the input method
+ * @throws UnsupportedOperationException if there is no current input method,
+ * or the input method does not support enabling
+ * @see #isCompositionEnabled()
+ * @since 1.3
+ */
+ public void setCompositionEnabled(boolean enable)
+ {
+ if (im == null)
+ throw new UnsupportedOperationException();
+ im.setCompositionEnabled(enable);
+ }
+
+ /**
+ * Find out if the current input method is enabled.
+ *
+ * @return true if the current input method is enabled
+ * @throws UnsupportedOperationException if there is no current input method,
+ * or the input method does not support enabling
+ * @see #setCompositionEnabled(boolean)
+ * @since 1.3
+ */
+ public boolean isCompositionEnabled()
+ {
+ if (im == null)
+ throw new UnsupportedOperationException();
+ return im.isCompositionEnabled();
+ }
+
+ /**
+ * Starts a reconversion operation in the current input method. The input
+ * method gets the text to reconvert from the client component, using
+ * {@link InputMethodRequests#getSelectedText(Attribute[])}. Then the
+ * composed and committed text produced by the operation is sent back to
+ * the client using a sequence of InputMethodRequests.
+ *
+ * @throws UnsupportedOperationException if there is no current input method,
+ * or the input method does not support reconversion
+ * @since 1.3
+ */
+ public void reconvert()
+ {
+ if (im == null)
+ throw new UnsupportedOperationException();
+ im.reconvert();
+ }
+
+ /**
+ * Dispatches an event to the current input method. This is called
+ * automatically by AWT. If no input method is available, then the event
+ * will never be consumed.
+ *
+ * @param event the event to dispatch
+ * @throws NullPointerException if event is null
+ */
+ public void dispatchEvent(AWTEvent event)
+ {
+ if (im != null)
+ im.dispatchEvent(event);
+ }
+
+ /**
+ * Notifies the input context that a client component has been removed from
+ * its containment hierarchy, or that input method support has been disabled
+ * for the component. This method is usually called from the client
+ * component's {@link Component#removeNotify()} method. Potentially pending
+ * input from input methods for this component is discarded. If no input
+ * methods are available, then this method has no effect.
+ *
+ * @param client the client component
+ * @throws NullPointerException if client is null
+ */
+ public void removeNotify(Component client)
+ {
+ // XXX What to do with client information?
+ if (im != null)
+ {
+ im.deactivate(false);
+ im.removeNotify();
+ }
+ }
+
+ /**
+ * Ends any input composition that may currently be going on in this
+ * context. Depending on the platform and possibly user preferences, this
+ * may commit or delete uncommitted text. Any changes to the text are
+ * communicated to the active component using an input method event. If no
+ * input methods are available, then this method has no effect. This may
+ * be called for a variety of reasons, such as when the user moves the
+ * insertion point in the client text outside the range of the composed text,
+ * or when text is saved to file.
+ */
+ public void endComposition()
+ {
+ if (im != null)
+ im.endComposition();
+ }
+
+ /**
+ * Disposes of the input context and release the resources used by it.
+ * Called automatically by AWT for the default input context of each
+ * Window. If no input methods are available, then this method has no
+ * effect.
+ */
+ public void dispose()
+ {
+ if (im != null)
+ {
+ im.deactivate(false);
+ im.dispose();
+ }
+ }
+
+ /**
+ * Returns a control object from the current input method, or null. A
+ * control object provides implementation-dependent methods that control
+ * the behavior of the input method or obtain information from the input
+ * method. Clients have to compare the result against known input method
+ * control object types. If no input methods are available or the current
+ * input method does not provide an input method control object, then null
+ * is returned.
+ *
+ * @return the control object, or null
+ */
+ public Object getInputMethodControlObject()
+ {
+ return im == null ? null : im.getControlObject();
+ }
+} // class InputContext
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodHighlight.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodHighlight.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodHighlight.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodHighlight.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,188 @@
+/* InputMethodHighlight.java -- highlights the current text selection
+ Copyright (C) 2002, 2005 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., 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.im;
+
+import java.awt.Toolkit;
+import java.text.Annotation;
+import java.text.AttributedCharacterIterator;
+import java.util.Map;
+
+/**
+ * This describes the highlight attributes of text composed in an input method.
+ * The description includes an abstract level (whether text has been converted
+ * yet, and whether it is selected), and a concrete level (which style
+ * attributes are used in rendering). If no concrete level is defined, the
+ * renderer should use
+ * {@link Toolkit#mapInputMethodHighlight(InputMethodHighlight)}. An example
+ * of conversion state is kana -> kanji.
+ *
+ * <p>Instances of this class are typically used in
+ * AttributedCharacterIterators, and may be wrapped in Annotations to separate
+ * text segments.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see AttributedCharacterIterator
+ * @see Annotation
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public class InputMethodHighlight
+{
+ /** Raw text state (before conversion). */
+ public static final int RAW_TEXT = 0;
+
+ /** Converted text state (after conversion). */
+ public static final int CONVERTED_TEXT = 1;
+
+ /** Default do-nothing highlighting for unselected raw text. */
+ public static final InputMethodHighlight UNSELECTED_RAW_TEXT_HIGHLIGHT
+ = new InputMethodHighlight(false, RAW_TEXT);
+
+ /** Default do-nothing highlighting for selected raw text. */
+ public static final InputMethodHighlight SELECTED_RAW_TEXT_HIGHLIGHT
+ = new InputMethodHighlight(true, RAW_TEXT);
+
+ /** Default do-nothing highlighting for unselected converted text. */
+ public static final InputMethodHighlight UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
+ = new InputMethodHighlight(false, CONVERTED_TEXT);
+
+ /** Default do-nothing highlighting for selected converted text. */
+ public static final InputMethodHighlight SELECTED_CONVERTED_TEXT_HIGHLIGHT
+ = new InputMethodHighlight(true, CONVERTED_TEXT);
+
+ /** Whether the highlighting applies to selected text. */
+ private final boolean selected;
+
+ /** The state of highlighted text. */
+ private final int state;
+
+ /** Any variation on the highlighting style. */
+ private final int variation;
+
+ /** The unmodifiable map of rendering styles. */
+ private final Map style;
+
+ /**
+ * Create an input method highlight style, with variation 0 and null style
+ * mapping.
+ *
+ * @param selected whether the text range is selected
+ * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT}
+ * @throws IllegalArgumentException if state is invalid
+ */
+ public InputMethodHighlight(boolean selected, int state)
+ {
+ this(selected, state, 0, null);
+ }
+
+ /**
+ * Create an input method highlight style, with null style mapping.
+ *
+ * @param selected whether the text range is selected
+ * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT}
+ * @param variation the style variation
+ * @throws IllegalArgumentException if state is invalid
+ */
+ public InputMethodHighlight(boolean selected, int state, int variation)
+ {
+ this(selected, state, variation, null);
+ }
+
+ /**
+ * Create an input method highlight style.
+ *
+ * @param selected whether the text range is selected
+ * @param state either {@link #RAW_TEXT} or {@link #CONVERTED_TEXT}
+ * @param variation the style variation
+ * @param style an unmodifiable map of rendering styles, or null
+ * @throws IllegalArgumentException if state is invalid
+ * @since 1.3
+ */
+ public InputMethodHighlight(boolean selected, int state, int variation,
+ Map style)
+ {
+ if (state != RAW_TEXT && state != CONVERTED_TEXT)
+ throw new IllegalArgumentException();
+ this.selected = selected;
+ this.state = state;
+ this.variation = variation;
+ this.style = style;
+ }
+
+ /**
+ * Return whether the highlighting applies to selected text.
+ *
+ * @return the selection status
+ */
+ public boolean isSelected()
+ {
+ return selected;
+ }
+
+ /**
+ * Return the conversion state of the highlighted text.
+ *
+ * @return one of {@link #RAW_TEXT} or {@link #CONVERTED_TEXT}
+ */
+ public int getState()
+ {
+ return state;
+ }
+
+ /**
+ * Return the highlighting style variation.
+ *
+ * @return the variation
+ */
+ public int getVariation()
+ {
+ return variation;
+ }
+
+ /**
+ * Return the rendering style attributes map, or null if it should be the
+ * default mapping.
+ *
+ * @return the style map
+ * @since 1.3
+ */
+ public Map getStyle()
+ {
+ return style;
+ }
+} // class InputMethodHighlight
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodRequests.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodRequests.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodRequests.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputMethodRequests.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,155 @@
+/* InputMethodRequests.java -- handles text insertion via input methods
+ Copyright (C) 2002, 2005 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., 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.im;
+
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.font.TextHitInfo;
+import java.awt.event.InputMethodListener;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedCharacterIterator.Attribute;
+
+/**
+ * This interface handles requests made by input methods on text editing
+ * components. A component must specify a handler for input methods that
+ * implements this interface, and which supports one of two user interfaces:
+ * <ul><li><em>on-the-spot</em>: composed text is shown in place</li>
+ * <li><em>below-the-spot</em>: composed text is in a separate window,
+ * usually below the main text window, until it is committed into place at
+ * the insertion point, overwriting any selected text</li></ul>
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @see Component#getInputMethodRequests()
+ * @see InputMethodListener
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public interface InputMethodRequests
+{
+ /**
+ * Gets the location of a given offset of the text. This can be used to
+ * position a composition window near the location of where the composed
+ * text will be inserted.
+ *
+ * <p>If the component has composed text (from the most recent
+ * InputMethodEvent), then offset 0 indicates the location of the first
+ * character of this composed text. Otherwise, the offset is ignored, and
+ * the location should be the beginning of the final line of selected
+ * text (in horizontal left-to-right text, like English, this would be the
+ * lower left corner of the selction; in vertical top-to-bottom text, like
+ * Chinese, this would be the top right corner of the selection).
+ *
+ * <p>The location returned is a 0-thickness caret (either horizontal or
+ * vertical, depending on text flow), mapped to absolute screen coordinates.
+ *
+ * @param offset offset within composed text, or null
+ * @return the screen location of the caret at the offset
+ */
+ Rectangle getTextLocation(TextHitInfo offset);
+
+ /**
+ * Get the text offset for the given screen coordinate. The offset is
+ * relative to the composed text, and the return is null if it is outside
+ * the range of composed text. For example, this can be used to find
+ * where a mouse click should pop up a text composition window.
+ *
+ * @param x the x screen coordinate
+ * @param y the y screen coordinate
+ * @return a text hit info describing the composed text offset
+ */
+ TextHitInfo getLocationOffset(int x, int y);
+
+ /**
+ * Gets the offset where the committed text exists in the text editing
+ * component. This can be used to examine the text surrounding the insert
+ * position.
+ *
+ * @return the offset of the insert position
+ */
+ int getInsertPositionOffset();
+
+ /**
+ * Gets an interator which provides access to the text and its attributes,
+ * except for the uncommitted text. The input method may provide a list of
+ * attributes it is interested in; and the iterator need not provide
+ * information on the remaining attributes. If the attribute list is null,
+ * the iterator must list all attributes.
+ *
+ * @param beginIndex the index of the first character in the iteration
+ * @param endIndex the index of the last character in the iteration
+ * @param attributes a list of attributes interested in, or null
+ * @return an iterator over the region of text with its attributes
+ */
+ AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex,
+ Attribute[] attributes);
+
+ /**
+ * Gets the length of committed text.
+ *
+ * @return the number of committed characters
+ */
+ int getCommittedTextLength();
+
+ /**
+ * Gets the latest committed text, and removes it from the component's text
+ * body. This allows an input method to provide an "Undo" command. In
+ * general, this should only be supported immediately after a commit, and
+ * not when other actions intervene; if not supported, simply return null.
+ * The input method may provide a list of attributes it is interested in;
+ * and the iterator need not provide information on the remaining attributes.
+ * If the attribute list is null, the iterator must list all attributes.
+ *
+ * @param attributes a list of attributes interested in, or null
+ * @return the latest committed text, or null
+ */
+ AttributedCharacterIterator cancelLatestCommittedText
+ (Attribute[] attributes);
+
+ /**
+ * Gets the currently selected text. One use of this is to implement a
+ * "Reconvert" feature in an input method, which modifies the selection
+ * based on the text in the composition window. The input method may
+ * provide a list of attributes it is interested in; and the iterator need
+ * not provide information on the remaining attributes. If the attribute
+ * list is null, the iterator must list all attributes.
+ *
+ * @param attributes a list of attributes interested in, or null
+ * @return the current selection
+ */
+ AttributedCharacterIterator getSelectedText(Attribute[] attributes);
+} // interface InputMethodRequests
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputSubset.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputSubset.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputSubset.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/InputSubset.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,129 @@
+/* InputSubset.java -- subsets of Unicode important in text input
+ Copyright (C) 2002, 2003, 2005 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., 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.im;
+
+/**
+ * Defines additional Unicode character blocks for use by input methods.
+ * These constants encompass several Unicode blocks, or portions thereof, for
+ * simplification over {@link Character.UnicodeBlock}.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.2
+ * @status updated to 1.4
+ */
+public final class InputSubset extends Character.Subset
+{
+ /**
+ * Constant for all Latin characters, including the characters in the
+ * BASIC_LATIN, LATIN_1_SUPPLEMENT, LATIN_EXTENDED_A, LATIN_EXTENDED_B
+ * Unicode character blocks.
+ */
+ public static final InputSubset LATIN = new InputSubset("LATIN");
+
+ /**
+ * Constant for the digits included in the BASIC_LATIN Unicode character
+ * block.
+ */
+ public static final InputSubset LATIN_DIGITS
+ = new InputSubset("LATIN_DIGITS");
+
+ /**
+ * Constant for all Han characters used in writing Traditional Chinese,
+ * including a subset of the CJK unified ideographs as well as Traditional
+ * Chinese Han characters that may be defined as surrogate characters.
+ */
+ public static final InputSubset TRADITIONAL_HANZI
+ = new InputSubset("TRADITIONAL_HANZI");
+
+ /**
+ * Constant for all Han characters used in writing Simplified Chinese,
+ * including a subset of the CJK unified ideographs as well as Simplified
+ * Chinese Han characters that may be defined as surrogate characters.
+ */
+ public static final InputSubset SIMPLIFIED_HANZI
+ = new InputSubset("SIMPLIFIED_HANZI");
+
+ /**
+ * Constant for all Han characters used in writing Japanese, including a
+ * subset of the CJK unified ideographs as well as Japanese Han characters
+ * that may be defined as surrogate characters.
+ */
+ public static final InputSubset KANJI = new InputSubset("KANJI");
+
+ /**
+ * Constant for all Han characters used in writing Korean, including a
+ * subset of the CJK unified ideographs as well as Korean Han characters
+ * that may be defined as surrogate characters.
+ */
+ public static final InputSubset HANJA = new InputSubset("HANJA");
+
+ /**
+ * Constant for the halfwidth katakana subset of the Unicode halfwidth and
+ * fullwidth forms character block.
+ */
+ public static final InputSubset HALFWIDTH_KATAKANA
+ = new InputSubset("HALFWIDTH_KATAKANA");
+
+ /**
+ * Constant for the fullwidth ASCII variants subset of the Unicode
+ * halfwidth and fullwidth forms character block.
+ *
+ * @since 1.3
+ */
+ public static final InputSubset FULLWIDTH_LATIN
+ = new InputSubset("FULLWIDTH_LATIN");
+
+ /**
+ * Constant for the fullwidth digits included in the Unicode halfwidth and
+ * fullwidth forms character block.
+ *
+ * @since 1.3
+ */
+ public static final InputSubset FULLWIDTH_DIGITS
+ = new InputSubset("FULLWIDTH_DIGITS");
+
+ /**
+ * Construct a subset.
+ *
+ * @param name the subset name
+ */
+ private InputSubset(String name)
+ {
+ super(name);
+ }
+} // class InputSubset
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.im package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.im</title></head>
+
+<body>
+<p>Support for text input methods.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethod.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethod.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethod.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethod.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,244 @@
+/* InputMethod.java -- defines an interface for complex text input
+ Copyright (C) 2002, 2005 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., 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.im.spi;
+
+import java.awt.AWTEvent;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.im.InputContext;
+import java.awt.im.InputMethodRequests;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.Locale;
+
+/**
+ * This interface supports complex text input, often for situations where
+ * the text is more complex than a keyboard will accomodate. For example,
+ * this can be used for Chinese, Japanese, and Korean, where multiple
+ * keystrokes are necessary to compose text. This could also support things
+ * like phonetic English, or reordering Thai.
+ *
+ * <p>These contexts can be loaded by the input method framework, using
+ * {@link InputContext#selectInputMethod(Locale)}.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public interface InputMethod
+{
+ /**
+ * Set the input method context, which ties the input method to a client
+ * component. This is called once automatically when creating the input
+ * method.
+ *
+ * @param context the context for this input method
+ * @throws NullPointerException if context is null
+ */
+ void setInputMethodContext(InputMethodContext context);
+
+ /**
+ * Sets the input locale. If the input method supports that locale, it
+ * changes its behavior to be consistent with the locale and returns true.
+ * Otherwise, it returns false. This is called by
+ * {@link InputContext#selectInputMethod(Locale)} when the user specifies
+ * a locale, or when the previously selected input method had a locale.
+ *
+ * @param locale the locale to use for input
+ * @return true if the change is successful
+ * @throws NullPointerException if locale is null
+ */
+ boolean setLocale(Locale locale);
+
+ /**
+ * Returns the current input locale, or null if none is defined. This is
+ * called by {@link InputContext#getLocale()}, or before switching input
+ * methods.
+ *
+ * @return the current input locale, or null
+ */
+ Locale getLocale();
+
+ /**
+ * Sets the allowed Unicode subsets that this input method can use. Null
+ * indicates that all characters are allowed. This is called after creation,
+ * or when switching to this input method, by
+ * {@link InputContext#setCharacterSubsets(Character.Subset[])}.
+ *
+ * @param subsets the accepted subsets for this input method, or null for all
+ */
+ void setCharacterSubsets(Character.Subset[] subsets);
+
+ /**
+ * Changes the enabled status of this input method. An enabled input method
+ * accepts incoming events for composition and control purposes, while a
+ * disabled input method ignores events (except for control purposes). This
+ * is called by {@link InputContext#setCompositionEnabled(boolean)} or when
+ * switching from an input method if the previous input method returned
+ * without exception on {@link #isCompositionEnabled()}.
+ *
+ * @param enable whether to enable this input method
+ * @throws UnsupportedOperationException if enabling/disabling is unsupported
+ * @see #isCompositionEnabled()
+ */
+ void setCompositionEnabled(boolean enable);
+
+ /**
+ * Find out if this input method is enabled. This is called by
+ * {@link InputContext#isCompositionEnabled()}, or when switching input
+ * methods via {@link InputContext#selectInputMethod(Locale)}.
+ *
+ * @return true if this input method is enabled
+ * @throws UnsupportedOperationException if enabling/disabling is unsupported
+ * @see #setCompositionEnabled(boolean)
+ */
+ boolean isCompositionEnabled();
+
+ /**
+ * Starts a reconversion operation. The input method gets its text from the
+ * client, using {@link InputMethodRequests#getSelectedText(Attribute[])}.
+ * Then the composed and committed text produced by the operation is sent
+ * back to the client using a sequence of InputMethodEvents. This is called
+ * by {@link InputContext#reconvert()}.
+ *
+ * @throws UnsupportedOperationException if reconversion is unsupported
+ */
+ void reconvert();
+
+ /**
+ * Dispatch an event to the input method. If input method support is enabled,
+ * certain events are dispatched to the input method before the client
+ * component or event listeners. The input method must either consume the
+ * event or pass it on to the component. Instances of InputEvent, including
+ * KeyEvent and MouseEvent, are given to this input method. This method is
+ * called by {@link InputContext#dispatchEvent(AWTEvent)}.
+ *
+ * @param event the event to dispatch
+ * @throws NullPointerException if event is null
+ */
+ void dispatchEvent(AWTEvent event);
+
+ /**
+ * Notify this input method of changes in the client window. This is called
+ * when notifications are enabled (see {@link
+ * InputMethodContext#enableClientWindowNotification(InputMethod, boolean)},
+ * if {@link InputContext#removeNotify(Component)} has not been called.
+ * The following situations trigger a notification:<ul>
+ * <li>The client window changes in location, size, visibility,
+ * iconification, or is closed.</li>
+ * <li>When enabling client notification (or on the first activation after
+ * enabling if no client existed at the time).</li>
+ * <li>When activating a new client after <code>removeNotify</code> was
+ * called on a previous client.</li>
+ * </ul>
+ *
+ * @param bounds the client window's current bounds, or null
+ */
+ void notifyClientWindowChange(Rectangle bounds);
+
+ /**
+ * Activate this input method for input processing. If the input method
+ * provides its own windows, it should make them open and visible at this
+ * time. This method is called when a client component receives a
+ * FOCUS_GAINED event, or when switching to this input method from another
+ * one. It is only called when the input method is inactive, assuming that
+ * new instances begin in an inactive state.
+ */
+ void activate();
+
+ /**
+ * Deactivate this input method, either temporarily or permanently for the
+ * given client. If the input method provides its own windows, it should
+ * only close those related to the current composition (such as a lookup
+ * choice panel), while leaving more persistant windows (like a control
+ * panel) open to avoid screen flicker. Before control is given to another
+ * input method, {@link #hideWindows()} will be called on this instance.
+ * This method is called when a client component receives a
+ * FOCUS_LOST event, when switching to another input method, or before
+ * {@link #removeNotify()} when the client is removed.
+ *
+ * @param isTemporary true if the focus change is temporary
+ */
+ void deactivate(boolean isTemporary);
+
+ /**
+ * Close or hide all windows opened by this input method. This is called
+ * before activating a different input method, and before calling
+ * {@link #dispose()} on this instance. It is only called when the input
+ * method is inactive.
+ */
+ void hideWindows();
+
+ /**
+ * Notify the input method that a client component has been removed from its
+ * hierarchy, or that input method support has been disabled. This is
+ * called by {@link InputContext#removeNotify(Component)}, and only when the input
+ * method is inactive.
+ */
+ void removeNotify();
+
+ /**
+ * End any input composition currently taking place. Depending on the
+ * platform and user preferences, this may commit or delete uncommitted text,
+ * using input method events. This may be called for a variety of reasons,
+ * such as when the user moves the insertion point in the client text outside
+ * the range of the composed text, or when text is saved to file. This is
+ * called by {@link InputContext#endComposition()}, when switching to a
+ * new input method, or by {@link InputContext#selectInputMethod(Locale)}.
+ */
+ void endComposition();
+
+ /**
+ * Disposes the input method and release any resources it is using. In
+ * particular, the input method should dispose windows and close files. This
+ * is called by {@link InputContext#dispose()}, when the input method is
+ * inactive; and nothing will be called on this instance afterwards.
+ */
+ void dispose();
+
+ /**
+ * Returns a control object from this input method, or null. A control object
+ * provides method to control the behavior of this input method, as well as
+ * query information about it. The object is implementation dependent, so
+ * clients must compare the result against known input method control
+ * object types. This is called by
+ * {@link InputContext#getInputMethodControlObject()}.
+ *
+ * @return the control object, or null
+ */
+ Object getControlObject();
+} // interface InputMethod
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodContext.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodContext.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodContext.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodContext.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,125 @@
+/* InputMethodContext.java -- communication between an input method and client
+ Copyright (C) 2002, 2004 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., 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.im.spi;
+
+import java.awt.HeadlessException;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.font.TextHitInfo;
+import java.awt.im.InputMethodRequests;
+import java.text.AttributedCharacterIterator;
+
+import javax.swing.JFrame;
+
+/**
+ * Provides methods for the communication context between an input method
+ * and the client component. This should be passed to
+ * {@link InputMethod#setInputMethodContext(InputMethodContext)}.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public interface InputMethodContext extends InputMethodRequests
+{
+ /**
+ * Create an input method event and dispatch it to the client.
+ *
+ * @param id the event type
+ * @param text an iterator over the text to be committed
+ * @param count the count of characters to be committed
+ * @param caret the insertion point of the commit, or null
+ * @param visiblePosition the best location to make visible, or null
+ */
+ void dispatchInputMethodEvent(int id, AttributedCharacterIterator text,
+ int count, TextHitInfo caret,
+ TextHitInfo visiblePosition);
+
+ /**
+ * Creates a top-level window for use by the input method. This window should
+ * float above all document windows and dialogs, not receive focus, and have
+ * lightweight decorations (such as no title, reduced drag regions). But
+ * this behavior may be modified to meet the platform style. The title may
+ * or may not be displayed, depending on the platform.
+ *
+ * <p>If attachToInputContext is true, the new window will share the input
+ * context of the input method, so that events in the new window are
+ * dispatched to the input method. Also, this supresses deactivate and
+ * activate calls to the input method caused by setVisible.
+ *
+ * @param title the window title, if one is displayed; null becomes ""
+ * @param attachToInputContext true for the window to share context with
+ * the input method
+ * @return the new window for use by the input method
+ * @throws HeadlessException if GraphicsEnvironment.isHeadless is true
+ */
+ Window createInputMethodWindow(String title, boolean attachToInputContext);
+
+ /**
+ * Creates a top-level Swing JFrame for use by the input method. This frame
+ * should float above all document windows and dialogs, not receive focus,
+ * and have lightweight decorations (such as no title, reduced drag
+ * regions). But this behavior may be modified to meet the platform style.
+ * The title may or may not be displayed, depending on the platform.
+ *
+ * <p>If attachToInputContext is true, the new window will share the input
+ * context of the input method, so that events in the new window are
+ * dispatched to the input method. Also, this supresses deactivate and
+ * activate calls to the input method caused by setVisible.
+ *
+ * @param title the window title, if one is displayed; null becomes ""
+ * @param attachToInputContext true for the window to share context with
+ * the input method
+ * @return the new window for use by the input method
+ * @throws HeadlessException if GraphicsEnvironment.isHeadless is true
+ * @since 1.4
+ */
+ JFrame createInputMethodJFrame(String title, boolean attachToInputContext);
+
+ /**
+ * Sets whether notification of the client window's location and state should
+ * be enabled for the input method. When enabled, the input method's
+ * {@link InputMethod#notifyClientWindowChange(Rectangle)} method is called.
+ * Notification is automatically disabled when the input method is disposed.
+ *
+ * @param inputMethod the method to change status of
+ * @param enable true to enable notification
+ */
+ void enableClientWindowNotification(InputMethod inputMethod, boolean enable);
+} // interface InputMethodContext
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodDescriptor.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodDescriptor.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodDescriptor.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/InputMethodDescriptor.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,114 @@
+/* InputMethodDescriptor.java -- enables loading and use of an input method
+ Copyright (C) 2002, 2005 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., 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.im.spi;
+
+import java.awt.AWTException;
+import java.awt.Image;
+import java.awt.im.InputContext;
+import java.util.Locale;
+
+/**
+ * This interface provides information about an InputMethod before it is
+ * loaded.
+ *
+ * @author Eric Blake (ebb9 at email.byu.edu)
+ * @since 1.3
+ * @status updated to 1.4
+ */
+public interface InputMethodDescriptor
+{
+ /**
+ * Returns the locales supported by the input method this describes. This
+ * allows the selection of input methods by locale (by language only, or
+ * also by country and variant), via
+ * {@link InputContext#selectInputMethod(Locale)}. The returned list should
+ * ignore pass-through locales, so it is usually a subset of locales for
+ * which {@link InputMethod#setLocale(Locale)} returns true. If
+ * {@link #hasDynamicLocaleList()} returns true, this is called each time
+ * information is needed, allowing dynamic addition or removal of supported
+ * locales.
+ *
+ * @return the list of supported locales
+ * @throws AWTException if the input method is not available
+ */
+ Locale[] getAvailableLocales() throws AWTException;
+
+ /**
+ * Test whether the input method this describes has a static or dynamic
+ * locale list. For example, this would return true if the list of supported
+ * locales depends on adapters currently loaded over a network.
+ *
+ * @return true if the locale list is dynamic
+ */
+ boolean hasDynamicLocaleList();
+
+ /**
+ * Returns a user visible name of the input locale, displayed in the
+ * specified locale. The inputLocale parameter must be one obtained from
+ * the list in {@link #getAvailableLocales()}, or null for a
+ * locale-independent description of the input method. If a translation to
+ * the desired display language is not available, another language may be
+ * used.
+ *
+ * @param inputLocale the locale of the input method, or null
+ * @param displayLanguage the language of the result
+ * @return the name of the input method when using the given inputLocale
+ */
+ String getInputMethodDisplayName(Locale inputLocale,
+ Locale displayLanguage);
+
+ /**
+ * Returns a 16x16 icon for the input locale. The inputLocale parameter
+ * must be one obtained from the list in {@link #getAvailableLocales()}, or
+ * null for a locale-independent icon for the input method.
+ *
+ * @param inputLocale the locale of the input method, or null
+ * @return a 16x16 icon for the input method when using the given inputLocale
+ */
+ Image getInputMethodIcon(Locale inputLocale);
+
+ /**
+ * Creates a new instance of the input method.
+ *
+ * @return the newly created input method
+ * @throws Exception if anything goes wrong
+ */
+ InputMethod createInputMethod() throws Exception;
+
+} // interface InputMethodDescriptor
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/package.html
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/package.html?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/package.html (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/im/spi/package.html Thu Nov 8 16:56:19 2007
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.awt.im.spi package.
+ 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., 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. -->
+
+<html>
+<head><title>GNU Classpath - java.awt.im.spi</title></head>
+
+<body>
+<p>Interfaces for implementation of text input methods.</p>
+
+</body>
+</html>
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AffineTransformOp.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AffineTransformOp.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AffineTransformOp.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AffineTransformOp.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,375 @@
+/* AffineTransformOp.java -- This class performs affine
+ transformation between two images or rasters in 2 dimensions.
+ Copyright (C) 2004 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.image;
+
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+/**
+ * This class performs affine transformation between two images or
+ * rasters in 2 dimensions.
+ *
+ * @author Olga Rodimina (rodimina at redhat.com)
+ */
+public class AffineTransformOp implements BufferedImageOp, RasterOp
+{
+ public static final int TYPE_NEAREST_NEIGHBOR = 1;
+
+ public static final int TYPE_BILINEAR = 2;
+
+ /**
+ * @since 1.5.0
+ */
+ public static final int TYPE_BICUBIC = 3;
+
+ private AffineTransform transform;
+ private RenderingHints hints;
+
+ /**
+ * Construct AffineTransformOp with the given xform and interpolationType.
+ * Interpolation type can be TYPE_BILINEAR, TYPE_BICUBIC or
+ * TYPE_NEAREST_NEIGHBOR.
+ *
+ * @param xform AffineTransform that will applied to the source image
+ * @param interpolationType type of interpolation used
+ */
+ public AffineTransformOp (AffineTransform xform, int interpolationType)
+ {
+ this.transform = xform;
+ if (xform.getDeterminant() == 0)
+ throw new ImagingOpException(null);
+
+ switch (interpolationType)
+ {
+ case TYPE_BILINEAR:
+ hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ break;
+ case TYPE_BICUBIC:
+ hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ break;
+ default:
+ hints = new RenderingHints (RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+ }
+ }
+
+ /**
+ * Construct AffineTransformOp with the given xform and rendering hints.
+ *
+ * @param xform AffineTransform that will applied to the source image
+ * @param hints rendering hints that will be used during transformation
+ */
+ public AffineTransformOp (AffineTransform xform, RenderingHints hints)
+ {
+ this.transform = xform;
+ this.hints = hints;
+ if (xform.getDeterminant() == 0)
+ throw new ImagingOpException(null);
+ }
+
+ /**
+ * Creates empty BufferedImage with the size equal to that of the
+ * transformed image and correct number of bands. The newly created
+ * image is created with the specified ColorModel.
+ * If the ColorModel is equal to null, then image is created
+ * with the ColorModel of the source image.
+ *
+ * @param src source image
+ * @param destCM color model for the destination image
+ * @return new compatible destination image
+ */
+ public BufferedImage createCompatibleDestImage (BufferedImage src,
+ ColorModel destCM)
+ {
+
+ // if destCm is not specified, use color model of the source image
+
+ if (destCM == null)
+ destCM = src.getColorModel ();
+
+ return new BufferedImage (destCM,
+ createCompatibleDestRaster (src.getRaster ()),
+ src.isAlphaPremultiplied (),
+ null);
+
+ }
+
+ /**
+ * Creates empty WritableRaster with the size equal to the transformed
+ * source raster and correct number of bands
+ *
+ * @param src source raster
+ * @throws RasterFormatException if resulting width or height of raster is 0
+ * @return new compatible raster
+ */
+ public WritableRaster createCompatibleDestRaster (Raster src)
+ {
+ Rectangle rect = (Rectangle) getBounds2D (src);
+
+ // throw RasterFormatException if resulting width or height of the
+ // transformed raster is 0
+
+ if (rect.getWidth () == 0 || rect.getHeight () == 0)
+ throw new RasterFormatException("width or height is 0");
+
+ return src.createCompatibleWritableRaster ((int) rect.getWidth (),
+ (int) rect.getHeight ());
+ }
+
+ /**
+ * Transforms source image using transform specified at the constructor.
+ * The resulting transformed image is stored in the destination image.
+ *
+ * @param src source image
+ * @param dst destination image
+ * @return transformed source image
+ */
+ public final BufferedImage filter (BufferedImage src, BufferedImage dst)
+ {
+
+ if (dst == src)
+ throw new IllegalArgumentException ("src image cannot be the same as the dst image");
+
+ // If the destination image is null, then BufferedImage is
+ // created with ColorModel of the source image
+
+ if (dst == null)
+ dst = createCompatibleDestImage(src, src.getColorModel ());
+
+ // FIXME: Must check if color models of src and dst images are the same.
+ // If it is not, then source image should be converted to color model
+ // of the destination image
+
+ Graphics2D gr = (Graphics2D) dst.createGraphics ();
+ gr.setRenderingHints (hints);
+ gr.drawImage (src, transform, null);
+ return dst;
+
+ }
+
+ /**
+ * Transforms source raster using transform specified at the constructor.
+ * The resulting raster is stored in the destination raster.
+ *
+ * @param src source raster
+ * @param dst destination raster
+ * @return transformed raster
+ */
+ public final WritableRaster filter (Raster src, WritableRaster dst)
+ {
+ if (dst == src)
+ throw new IllegalArgumentException("src image cannot be the same as"
+ + " the dst image");
+
+ if (dst == null)
+ dst = createCompatibleDestRaster(src);
+
+ if (src.getNumBands() != dst.getNumBands())
+ throw new IllegalArgumentException("src and dst must have same number"
+ + " of bands");
+
+ double[] dpts = new double[dst.getWidth() * 2];
+ double[] pts = new double[dst.getWidth() * 2];
+ for (int x = 0; x < dst.getWidth(); x++)
+ {
+ dpts[2 * x] = x + dst.getMinX();
+ dpts[2 * x + 1] = x;
+ }
+ Rectangle srcbounds = src.getBounds();
+ if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR))
+ {
+ for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++)
+ {
+ try {
+ transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2);
+ } catch (NoninvertibleTransformException e) {
+ // Can't happen since the constructor traps this
+ e.printStackTrace();
+ }
+
+ for (int x = 0; x < dst.getWidth(); x++)
+ {
+ if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1]))
+ continue;
+ dst.setDataElements(x + dst.getMinX(), y,
+ src.getDataElements((int)pts[2 * x],
+ (int)pts[2 * x + 1],
+ null));
+ }
+ }
+ }
+ else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR))
+ {
+ double[] tmp = new double[4 * src.getNumBands()];
+ for (int y = dst.getMinY(); y < dst.getMinY() + dst.getHeight(); y++)
+ {
+ try {
+ transform.inverseTransform(dpts, 0, pts, 0, dst.getWidth() * 2);
+ } catch (NoninvertibleTransformException e) {
+ // Can't happen since the constructor traps this
+ e.printStackTrace();
+ }
+
+ for (int x = 0; x < dst.getWidth(); x++)
+ {
+ if (!srcbounds.contains(pts[2 * x], pts[2 * x + 1]))
+ continue;
+ int xx = (int)pts[2 * x];
+ int yy = (int)pts[2 * x + 1];
+ double dx = (pts[2 * x] - xx);
+ double dy = (pts[2 * x + 1] - yy);
+
+ // TODO write this more intelligently
+ if (xx == src.getMinX() + src.getWidth() - 1 ||
+ yy == src.getMinY() + src.getHeight() - 1)
+ {
+ // bottom or right edge
+ Arrays.fill(tmp, 0);
+ src.getPixel(xx, yy, tmp);
+ }
+ else
+ {
+ // Normal case
+ src.getPixels(xx, yy, 2, 2, tmp);
+ for (int b = 0; b < src.getNumBands(); b++)
+ tmp[b] = dx * dy * tmp[b]
+ + (1 - dx) * dy * tmp[b + src.getNumBands()]
+ + dx * (1 - dy) * tmp[b + 2 * src.getNumBands()]
+ + (1 - dx) * (1 - dy) * tmp[b + 3 * src.getNumBands()];
+ }
+ dst.setPixel(x, y, tmp);
+ }
+ }
+ }
+ else
+ {
+ // Bicubic
+ throw new UnsupportedOperationException("not implemented yet");
+ }
+
+ return dst;
+ }
+
+ /**
+ * Transforms source image using transform specified at the constructor and
+ * returns bounds of the transformed image.
+ *
+ * @param src image to be transformed
+ * @return bounds of the transformed image.
+ */
+ public final Rectangle2D getBounds2D (BufferedImage src)
+ {
+ return getBounds2D (src.getRaster());
+ }
+
+ /**
+ * Returns bounds of the transformed raster.
+ *
+ * @param src raster to be transformed
+ * @return bounds of the transformed raster.
+ */
+ public final Rectangle2D getBounds2D (Raster src)
+ {
+ // determine new size for the transformed raster.
+ // Need to calculate transformed coordinates of the lower right
+ // corner of the raster. The upper left corner is always (0,0)
+
+ double x2 = (double) src.getWidth () + src.getMinX ();
+ double y2 = (double) src.getHeight () + src.getMinY ();
+ Point2D p2 = getPoint2D (new Point2D.Double (x2,y2), null);
+
+ Rectangle2D rect = new Rectangle (0, 0, (int) p2.getX (), (int) p2.getY ());
+ return rect.getBounds ();
+ }
+
+ /**
+ * Returns interpolation type used during transformations
+ *
+ * @return interpolation type
+ */
+ public final int getInterpolationType ()
+ {
+ if(hints.containsValue (RenderingHints.VALUE_INTERPOLATION_BILINEAR))
+ return TYPE_BILINEAR;
+ else
+ return TYPE_NEAREST_NEIGHBOR;
+ }
+
+ /**
+ * Returns location of the transformed source point. The resulting point
+ * is stored in the dstPt if one is specified.
+ *
+ * @param srcPt point to be transformed
+ * @param dstPt destination point
+ * @return the location of the transformed source point.
+ */
+ public final Point2D getPoint2D (Point2D srcPt, Point2D dstPt)
+ {
+ return transform.transform (srcPt, dstPt);
+ }
+
+ /**
+ * Returns rendering hints that are used during transformation.
+ *
+ * @return rendering hints
+ */
+ public final RenderingHints getRenderingHints ()
+ {
+ return hints;
+ }
+
+ /**
+ * Returns transform used in transformation between source and destination
+ * image.
+ *
+ * @return transform
+ */
+ public final AffineTransform getTransform ()
+ {
+ return transform;
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AreaAveragingScaleFilter.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AreaAveragingScaleFilter.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AreaAveragingScaleFilter.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/AreaAveragingScaleFilter.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,269 @@
+/* AreaAveragingScaleFilter.java -- Java class for filtering images
+ Copyright (C) 1999,2006 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., 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.image;
+
+/**
+ * This filter should produce images which do not have image artifacts
+ * like broken lines which were originally unbroken. The cost is of
+ * course speed. Using bi-linear interpolation here against 4 pixel
+ * points should give the desired results although Sun does not
+ * specify what the exact algorithm should be.
+ * <br>
+ *
+ * @author C. Brian Jones (cbj at gnu.org)
+ */
+public class AreaAveragingScaleFilter extends ReplicateScaleFilter
+{
+ /**
+ * Construct an instance of <code>AreaAveragingScaleFilter</code> which
+ * should be used in conjunction with a <code>FilteredImageSource</code>
+ * object.
+ *
+ * @param width the width of the destination image
+ * @param height the height of the destination image
+ */
+ public AreaAveragingScaleFilter(int width, int height) {
+ super(width, height);
+ }
+
+ /**
+ * The <code>ImageProducer</code> should call this method with a
+ * bit mask of hints from any of <code>RANDOMPIXELORDER</code>,
+ * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>,
+ * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code> from the
+ * <code>ImageConsumer</code> interface.
+ * <br>
+ * FIXME - more than likely Sun's implementation desires
+ * <code>TOPDOWNLEFTRIGHT</code> order and this method is overloaded here
+ * in order to assure that mask is part of the hints added to
+ * the consumer.
+ *
+ * @param flags a bit mask of hints
+ * @see ImageConsumer
+ */
+ public void setHints(int flags)
+ {
+ if (consumer != null)
+ consumer.setHints(flags);
+ }
+
+ /**
+ * This function delivers a rectangle of pixels where any
+ * pixel(m,n) is stored in the array as a <code>byte</code> at
+ * index (n * scansize + m + offset).
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @param model the <code>ColorModel</code> used to translate the pixels
+ * @param pixels the array of pixel values
+ * @param offset the index of the first pixels in the <code>pixels</code> array
+ * @param scansize the width to use in extracting pixels from the <code>pixels</code> array
+ */
+ public void setPixels(int x, int y, int w, int h,
+ ColorModel model, byte[] pixels, int offset, int scansize)
+ {
+ double rx = ((double) srcWidth) / destWidth;
+ double ry = ((double) srcHeight) / destHeight;
+
+ int destScansize = (int) Math.round(scansize / rx);
+
+ byte[] destPixels = averagePixels(x, y, w, h,
+ model, pixels, offset, scansize,
+ rx, ry, destScansize);
+
+ if (consumer != null)
+ consumer.setPixels((int) Math.floor(x/rx), (int) Math.floor(y/ry),
+ (int) Math.ceil(w/rx), (int) Math.ceil(h/ry),
+ model, destPixels, 0, destScansize);
+ }
+
+ /**
+ * This function delivers a rectangle of pixels where any
+ * pixel(m,n) is stored in the array as an <code>int</code> at
+ * index (n * scansize + m + offset).
+ *
+ * @param x the x coordinate of the rectangle
+ * @param y the y coordinate of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @param model the <code>ColorModel</code> used to translate the pixels
+ * @param pixels the array of pixel values
+ * @param offset the index of the first pixels in the <code>pixels</code> array
+ * @param scansize the width to use in extracting pixels from the <code>pixels</code> array
+ */
+ public void setPixels(int x, int y, int w, int h,
+ ColorModel model, int[] pixels, int offset, int scansize)
+ {
+ double rx = ((double) srcWidth) / destWidth;
+ double ry = ((double) srcHeight) / destHeight;
+
+ int destScansize = (int) Math.round(scansize / rx);
+
+ int[] destPixels = averagePixels(x, y, w, h,
+ model, pixels, offset, scansize,
+ rx, ry, destScansize);
+
+ if (consumer != null)
+ consumer.setPixels((int) Math.floor(x/rx), (int) Math.floor(y/ry),
+ (int) Math.ceil(w/rx), (int) Math.ceil(h/ry),
+ model, destPixels, 0, destScansize);
+ }
+
+ /**
+ * This is a really terrible implementation,
+ * since it uses the nearest-neighbor method. This filter is rarely used though.
+ *
+ * @param srcx, srcy - Source rectangle upper-left corner
+ * @param srcw, srch - Source rectangle width and height
+ * @param model - Pixel color model
+ * @param srcPixels - Source pixel data.
+ * @param srcOffset - Starting offset into the source pixel data array.
+ * @param srcScansize - Source array scanline size.
+ * @param rx,ry - Scaling factor.
+ * @param dstScansize - Destination array scanline size.
+ */
+ private byte[] averagePixels(int srcx, int srcy, int srcw, int srch,
+ ColorModel model, byte[] srcPixels,
+ int srcOffset, int srcScansize,
+ double rx, double ry, int destScansize)
+ {
+ int destW = (int) Math.ceil(srcw/rx);
+ int destH = (int) Math.ceil(srch/ry);
+ byte[] destPixels = new byte[ destW * destH ];
+ int sx, sy;
+
+ int w = (int)Math.ceil(rx);
+ int h = (int)Math.ceil(ry);
+
+ for(int x = 0; x < destW; x++)
+ for(int y = 0; y < destH; y++)
+ {
+ sx = (int) (x * rx);
+ sy = (int) (y * ry);
+
+ int r,g,b,a;
+ r = g = b = a = 0;
+
+ for(int i = 0; i < w; i++)
+ {
+ for(int j = 0; j < h; j++)
+ {
+ int idx = srcx + sx + i + (srcy + sy + j)*srcScansize;
+ r += model.getRed(srcPixels[ idx ]);
+ g += model.getGreen(srcPixels[ idx ]);
+ b += model.getBlue(srcPixels[ idx ]);
+ a += model.getAlpha(srcPixels[ idx ]);
+ }
+ }
+
+ r = r / (w * h);
+ g = g / (w * h);
+ b = b / (w * h);
+ a = a / (w * h);
+
+ // Does this really work?
+ destPixels[x + destScansize*y] = (byte)model.getDataElement
+ (new int[]{r, g, b, a}, 0);
+ }
+
+ return destPixels;
+ }
+
+ /**
+ * This is a really terrible implementation,
+ * since it uses the nearest-neighbor method. This filter is rarely used though.
+ *
+ * @param srcx, srcy - Source rectangle upper-left corner
+ * @param srcw, srch - Source rectangle width and height
+ * @param model - Pixel color model
+ * @param srcPixels - Source pixel data.
+ * @param srcOffset - Starting offset into the source pixel data array.
+ * @param srcScansize - Source array scanline size.
+ * @param rx,ry - Scaling factor.
+ * @param dstScansize - Destination array scanline size.
+ */
+ private int[] averagePixels(int srcx, int srcy, int srcw, int srch,
+ ColorModel model, int[] srcPixels,
+ int srcOffset, int srcScansize,
+ double rx, double ry, int destScansize)
+ {
+ int destW = (int) Math.ceil(srcw/rx);
+ int destH = (int) Math.ceil(srch/ry);
+ int[] destPixels = new int[ destW * destH ];
+ int sx, sy;
+
+ int w = (int)Math.ceil(rx);
+ int h = (int)Math.ceil(ry);
+
+ for(int x = 0; x < destW; x++)
+ for(int y = 0; y < destH; y++)
+ {
+ sx = (int) (x * rx);
+ sy = (int) (y * ry);
+
+ int r,g,b,a;
+ r = g = b = a = 0;
+
+ for(int i = 0; i < w; i++)
+ {
+ for(int j = 0; j < h; j++)
+ {
+ int idx = srcx + sx + i + (srcy + sy + j)*srcScansize;
+ r += model.getRed(srcPixels[ idx ]);
+ g += model.getGreen(srcPixels[ idx ]);
+ b += model.getBlue(srcPixels[ idx ]);
+ a += model.getAlpha(srcPixels[ idx ]);
+ }
+ }
+
+ r = r / (w * h);
+ g = g / (w * h);
+ b = b / (w * h);
+ a = a / (w * h);
+
+ destPixels[x + destScansize*y] = model.getDataElement
+ (new int[]{r, g, b, a}, 0);
+ }
+
+ return destPixels;
+ }
+}
+
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandCombineOp.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandCombineOp.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandCombineOp.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandCombineOp.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,168 @@
+/* Copyright (C) 2004 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.image;
+
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Filter Raster pixels by applying a matrix.
+ *
+ * BandCombineOp applies a matrix to each pixel to produce new pixel values.
+ * The width of the matrix must be the same or one more than the number of
+ * bands in the source Raster. If one more, the pixels in the source are
+ * assumed to contain an implicit 1.0 at the end.
+ *
+ * The rows of the matrix are multiplied by the pixel to produce the values
+ * for the destination. Therefore the destination Raster must contain the
+ * same number of bands as the number of rows in the filter matrix.
+ *
+ * @author Jerry Quinn (jlquinn at optonline.net)
+ */
+public class BandCombineOp implements RasterOp
+{
+ private RenderingHints hints;
+ private float[][] matrix;
+
+ /**
+ * Construct a BandCombineOp.
+ *
+ * @param matrix The matrix to filter pixels with.
+ * @param hints Rendering hints to apply. Ignored.
+ */
+ public BandCombineOp(float[][] matrix, RenderingHints hints)
+ {
+ this.matrix = matrix;
+ this.hints = hints;
+ }
+
+ /**
+ * Filter Raster pixels through a matrix.
+ *
+ * Applies the Op matrix to source pixes to produce dest pixels. Each row
+ * of the matrix is multiplied by the src pixel components to produce the
+ * dest pixel. If matrix is one more than the number of bands in the src,
+ * the last element is implicitly multiplied by 1, i.e. added to the sum
+ * for that dest component.
+ *
+ * If dest is null, a suitable Raster is created. This implementation uses
+ * createCompatibleDestRaster.
+ *
+ * @param src The source Raster.
+ * @param dest The destination Raster, or null.
+ * @returns The destination Raster or an allocated Raster.
+ * @see java.awt.image.RasterOp#filter(java.awt.image.Raster,
+ *java.awt.image.WritableRaster)
+ */
+ public WritableRaster filter(Raster src, WritableRaster dest) {
+ if (dest == null)
+ dest = createCompatibleDestRaster(src);
+
+ // Filter the pixels
+ float[] spix = new float[matrix[0].length];
+ float[] dpix = new float[matrix.length];
+ for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
+ for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
+ {
+ // In case matrix rows have implicit translation
+ spix[spix.length - 1] = 1.0f;
+ src.getPixel(x, y, spix);
+ for (int i = 0; i < matrix.length; i++)
+ {
+ dpix[i] = 0;
+ for (int j = 0; j < matrix[0].length; j++)
+ dpix[i] += spix[j] * matrix[i][j];
+ }
+ dest.setPixel(x, y, dpix);
+ }
+
+ return dest;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#getBounds2D(java.awt.image.Raster)
+ */
+ public final Rectangle2D getBounds2D(Raster src)
+ {
+ return src.getBounds();
+ }
+
+ /**
+ * Creates a new WritableRaster that can be used as the destination for this
+ * Op. This implementation creates a Banded Raster with data type FLOAT.
+ * @see
+ *java.awt.image.RasterOp#createCompatibleDestRaster(java.awt.image.Raster)
+ */
+ public WritableRaster createCompatibleDestRaster(Raster src)
+ {
+ return Raster.createBandedRaster(DataBuffer.TYPE_FLOAT, src.getWidth(),
+ src.getHeight(), matrix.length,
+ new Point(src.getMinX(), src.getMinY()));
+ }
+
+ /** Return corresponding destination point for source point.
+ *
+ * LookupOp will return the value of src unchanged.
+ * @param src The source point.
+ * @param dst The destination point.
+ * @see java.awt.image.RasterOp#getPoint2D(java.awt.geom.Point2D,
+ *java.awt.geom.Point2D)
+ */
+ public final Point2D getPoint2D(Point2D src, Point2D dst)
+ {
+ if (dst == null) return (Point2D)src.clone();
+ dst.setLocation(src);
+ return dst;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.image.RasterOp#getRenderingHints()
+ */
+ public final RenderingHints getRenderingHints()
+ {
+ return hints;
+ }
+
+ /** Return the matrix for this Op. */
+ public final float[][] getMatrix()
+ {
+ return matrix;
+ }
+
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandedSampleModel.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandedSampleModel.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandedSampleModel.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BandedSampleModel.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,758 @@
+/* Copyright (C) 2004, 2005, 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.image;
+
+import gnu.java.awt.Buffers;
+
+/**
+ * A sample model that reads each sample value from a separate band in the
+ * {@link DataBuffer}.
+ *
+ * @author Jerry Quinn (jlquinn at optonline.net)
+ */
+public final class BandedSampleModel extends ComponentSampleModel
+{
+ private int[] bitMasks;
+ private int[] bitOffsets;
+ private int[] sampleSize;
+ private int dataBitOffset;
+ private int elemBits;
+ private int numberOfBits;
+ private int numElems;
+
+ private static int[] createBankArray(int size)
+ {
+ int[] result = new int[size];
+ for (int i = 0; i < size; i++)
+ result[i] = i;
+ return result;
+ }
+
+ /**
+ * Creates a new <code>BandedSampleModel</code>.
+ *
+ * @param dataType the data buffer type.
+ * @param w the width (in pixels).
+ * @param h the height (in pixels).
+ * @param numBands the number of bands.
+ */
+ public BandedSampleModel(int dataType, int w, int h, int numBands)
+ {
+ this(dataType, w, h, w, createBankArray(numBands), new int[numBands]);
+ }
+
+ /**
+ * Creates a new <code>BandedSampleModel</code>.
+ *
+ * @param dataType the data buffer type.
+ * @param w the width (in pixels).
+ * @param h the height (in pixels).
+ * @param scanlineStride the number of data elements from a pixel in one
+ * row to the corresponding pixel in the next row.
+ * @param bankIndices the bank indices.
+ * @param bandOffsets the band offsets.
+ */
+ public BandedSampleModel(int dataType, int w, int h, int scanlineStride,
+ int[] bankIndices, int[] bandOffsets)
+ {
+ super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);
+ }
+
+ /**
+ * Creates a new data buffer that is compatible with this sample model.
+ *
+ * @return The new data buffer.
+ */
+ public DataBuffer createDataBuffer()
+ {
+ int size = scanlineStride * height;
+ return Buffers.createBuffer(getDataType(), size, numBanks);
+ }
+
+ /**
+ * Creates a new <code>SampleModel</code> that is compatible with this
+ * model and has the specified width and height.
+ *
+ * @param w the width (in pixels, must be greater than zero).
+ * @param h the height (in pixels, must be greater than zero).
+ *
+ * @return The new sample model.
+ *
+ * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
+ * not greater than zero.
+ * @throws IllegalArgumentException if <code>w * h</code> exceeds
+ * <code>Integer.MAX_VALUE</code>.
+ */
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ // NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs
+ // disagree.
+
+ // Compress offsets so minimum is 0, others w*scanlineStride
+ int[] newoffsets = new int[bandOffsets.length];
+ int[] order = new int[bandOffsets.length];
+ for (int i = 0; i < bandOffsets.length; i++)
+ order[i] = i;
+ // FIXME: This is N^2, but not a big issue, unless there's a lot of
+ // bands...
+ for (int i = 0; i < bandOffsets.length; i++)
+ for (int j = i + 1; j < bandOffsets.length; j++)
+ if (bankIndices[order[i]] > bankIndices[order[j]]
+ || (bankIndices[order[i]] == bankIndices[order[j]]
+ && bandOffsets[order[i]] > bandOffsets[order[j]]))
+ {
+ int t = order[i]; order[i] = order[j]; order[j] = t;
+ }
+ int bank = 0;
+ int offset = 0;
+ for (int i = 0; i < bandOffsets.length; i++)
+ {
+ if (bankIndices[order[i]] != bank)
+ {
+ bank = bankIndices[order[i]];
+ offset = 0;
+ }
+ newoffsets[order[i]] = offset;
+ offset += w * scanlineStride;
+ }
+
+ return new BandedSampleModel(dataType, w, h, w, bankIndices, newoffsets);
+ }
+
+
+ public SampleModel createSubsetSampleModel(int[] bands)
+ {
+ if (bands.length > bankIndices.length)
+ throw new
+ RasterFormatException("BandedSampleModel createSubsetSampleModel too"
+ +" many bands");
+ int[] newoff = new int[bands.length];
+ int[] newbanks = new int[bands.length];
+ for (int i = 0; i < bands.length; i++)
+ {
+ int b = bands[i];
+ newoff[i] = bandOffsets[b];
+ newbanks[i] = bankIndices[b];
+ }
+
+ return new BandedSampleModel(dataType, width, height, scanlineStride,
+ newbanks, newoff);
+ }
+
+ /**
+ * Extract all samples of one pixel and return in an array of transfer type.
+ *
+ * Extracts the pixel at x, y from data and stores samples into the array
+ * obj. If obj is null, a new array of getTransferType() is created.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>obj</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>obj</code>.
+ * @param obj The primitive array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ * @see java.awt.image.SampleModel#getDataElements(int, int,
+ * java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public Object getDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ if (x < 0 || y < 0)
+ throw new ArrayIndexOutOfBoundsException(
+ "x and y must not be less than 0.");
+ int pixel = getSample(x, y, 0, data);
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ byte[] b = (byte[]) obj;
+ if (b == null) b = new byte[numBands];
+ for (int i = 0; i < numBands; i++)
+ b[i] = (byte)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_SHORT:
+ case DataBuffer.TYPE_USHORT:
+ {
+ short[] b = (short[]) obj;
+ if (b == null) b = new short[numBands];
+ for (int i = 0; i < numBands; i++)
+ b[i] = (short)getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ int[] b = (int[]) obj;
+ if (b == null) b = new int[numBands];
+ for (int i = 0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ float[] b = (float[]) obj;
+ if (b == null) b = new float[numBands];
+ for (int i = 0; i < numBands; i++)
+ b[i] = getSampleFloat(x, y, i, data);
+ return b;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ double[] b = (double[]) obj;
+ if (b == null)
+ b = new double[numBands];
+ for (int i = 0; i < numBands; i++)
+ b[i] = getSample(x, y, i, data);
+ return b;
+ }
+
+ default:
+ // Seems like the only sensible thing to do.
+ throw new ClassCastException();
+ }
+ }
+
+ /**
+ * Returns all the samples for the pixel at location <code>(x, y)</code>
+ * stored in the specified data buffer.
+ *
+ * @param x the x-coordinate.
+ * @param y the y-coordinate.
+ * @param iArray an array that will be populated with the sample values and
+ * returned as the result. The size of this array should be equal to the
+ * number of bands in the model. If the array is <code>null</code>, a new
+ * array is created.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The samples for the specified pixel.
+ *
+ * @see #setPixel(int, int, int[], DataBuffer)
+ */
+ public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ if (iArray == null)
+ iArray = new int[numBands];
+ for (int i = 0; i < numBands; i++)
+ iArray[i] = getSample(x, y, i, data);
+
+ return iArray;
+ }
+
+ /**
+ * Copy pixels from a region into an array.
+ *
+ * Copies the samples of the pixels in the rectangle starting at x, y that
+ * is w pixels wide and h scanlines high. When there is more than one band,
+ * the samples stored in order before the next pixel. This ordering isn't
+ * well specified in Sun's docs as of 1.4.2.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ if (x < 0 || y < 0)
+ throw new ArrayIndexOutOfBoundsException(
+ "x and y must not be less than 0.");
+ if (iArray == null)
+ iArray = new int[w * h * numBands];
+ int outOffset = 0;
+ int maxX = x + w;
+ int maxY = y + h;
+ for (int yy = x; yy < maxY; yy++)
+ {
+ for (int xx = x; xx < maxX; xx++)
+ {
+ for (int b = 0; b < numBands; b++)
+ {
+ int offset = bandOffsets[b] + yy * scanlineStride + xx;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ }
+ return iArray;
+ }
+
+ /**
+ * Returns a sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
+ public int getSample(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElem(bankIndices[b], offset);
+ }
+
+ /**
+ * Returns a sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ *
+ * @see #getSample(int, int, int, DataBuffer)
+ */
+ public float getSampleFloat(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemFloat(bankIndices[b], offset);
+ }
+
+ /**
+ * Returns the sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ *
+ * @see #getSample(int, int, int, DataBuffer)
+ */
+ public double getSampleDouble(int x, int y, int b, DataBuffer data)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + x;
+ return data.getElemDouble(bankIndices[b], offset);
+ }
+
+ /**
+ * Copy one band's samples from a region into an array.
+ *
+ * Copies from one band the samples of the pixels in the rectangle starting
+ * at x, y that is w pixels wide and h scanlines high.
+ *
+ * If iArray is null, a new array is allocated, filled, and returned.
+ *
+ * @param x The x-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param y The y-coordinate of the pixel rectangle to store in
+ * <code>iArray</code>.
+ * @param w The width in pixels of the rectangle.
+ * @param h The height in pixels of the rectangle.
+ * @param b The band to retrieve.
+ * @param iArray The int array to store the pixels into or null to force
+ * creation.
+ * @param data The DataBuffer that is the source of the pixel data.
+ * @return The primitive array containing the pixel data.
+ */
+ public int[] getSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ if (x < 0 || y < 0)
+ throw new ArrayIndexOutOfBoundsException(
+ "x and y must not be less than 0.");
+ if (iArray == null)
+ iArray = new int[w * h];
+ int outOffset = 0;
+ int maxX = x + w;
+ int maxY = y + h;
+ for (int yy = y; yy < maxY; yy++)
+ {
+ for (int xx = x; xx < maxX; xx++)
+ {
+ int offset = bandOffsets[b] + yy * scanlineStride + xx;
+ iArray[outOffset++] =
+ data.getElem(bankIndices[b], offset);
+ }
+ }
+ return iArray;
+ }
+
+ /**
+ * Set the pixel at x, y to the value in the first element of the primitive
+ * array obj.
+ *
+ * @param x The x-coordinate of the data elements in <code>obj</code>.
+ * @param y The y-coordinate of the data elements in <code>obj</code>.
+ * @param obj The primitive array containing the data elements to set.
+ * @param data The DataBuffer to store the data elements into.
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+ */
+ public void setDataElements(int x, int y, Object obj, DataBuffer data)
+ {
+ int transferType = getTransferType();
+ if (getTransferType() != data.getDataType())
+ {
+ throw new IllegalArgumentException("transfer type ("+
+ getTransferType()+"), "+
+ "does not match data "+
+ "buffer type (" +
+ data.getDataType() +
+ ").");
+ }
+
+ int offset = y * scanlineStride + x;
+
+ try
+ {
+ switch (transferType)
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] in = (byte[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] in = (short[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferUShort out = (DataBufferUShort) data;
+ short[] in = (short[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] in = (int[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ {
+ DataBufferFloat out = (DataBufferFloat) data;
+ float[] in = (float[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ case DataBuffer.TYPE_DOUBLE:
+ {
+ DataBufferDouble out = (DataBufferDouble) data;
+ double[] in = (double[]) obj;
+ for (int i = 0; i < numBands; i++)
+ out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
+ return;
+ }
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException aioobe)
+ {
+ String msg = "While writing data elements"
+ + ", x=" + x + ", y=" + y
+ + ", width=" + width + ", height=" + height
+ + ", scanlineStride=" + scanlineStride
+ + ", offset=" + offset
+ + ", data.getSize()=" + data.getSize()
+ + ", data.getOffset()=" + data.getOffset()
+ + ": " + aioobe;
+ throw new ArrayIndexOutOfBoundsException(msg);
+ }
+ }
+
+ /**
+ * Sets the samples for the pixel at (x, y) in the specified data buffer to
+ * the specified values.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param iArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
+ public void setPixel(int x, int y, int[] iArray, DataBuffer data)
+ {
+ for (int b = 0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
+ iArray[b]);
+ }
+
+ /**
+ * Sets the sample values for the pixels in the region specified by
+ * (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param iArray the pixel sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
+ public void setPixels(int x, int y, int w, int h, int[] iArray,
+ DataBuffer data)
+ {
+ int inOffset = 0;
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = y * scanlineStride + (x + ww);
+ for (int b = 0; b < numBands; b++)
+ data.setElem(bankIndices[b], bandOffsets[b] + offset,
+ iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ /**
+ * Sets the sample value for band <code>b</code> of the pixel at location
+ * <code>(x, y)</code> in the specified data buffer.
+ *
+ * @param x the x-coordinate.
+ * @param y the y-coordinate.
+ * @param b the band index.
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @see #getSample(int, int, int, DataBuffer)
+ */
+ public void setSample(int x, int y, int b, int s, DataBuffer data)
+ {
+ data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
+ }
+
+ /**
+ * Sets the sample value for a band for the pixel at (x, y) in the
+ * specified data buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
+ public void setSample(int x, int y, int b, float s, DataBuffer data)
+ {
+ data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
+ s);
+ }
+
+ /**
+ * Sets the sample value for a band for the pixel at (x, y) in the
+ * specified data buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
+ public void setSample(int x, int y, int b, double s, DataBuffer data)
+ {
+ data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
+ s);
+ }
+
+ /**
+ * Sets the sample values for one band for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer.
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param iArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
+ public void setSamples(int x, int y, int w, int h, int b, int[] iArray,
+ DataBuffer data)
+ {
+ if (x < 0 || y < 0)
+ throw new ArrayIndexOutOfBoundsException(
+ "x and y must not be less than 0.");
+ int inOffset = 0;
+
+ switch (getTransferType())
+ {
+ case DataBuffer.TYPE_BYTE:
+ {
+ DataBufferByte out = (DataBufferByte) data;
+ byte[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (byte)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_SHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_USHORT:
+ {
+ DataBufferShort out = (DataBufferShort) data;
+ short[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = (short)iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_INT:
+ {
+ DataBufferInt out = (DataBufferInt) data;
+ int[] bank = out.getData(bankIndices[b]);
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ bank[offset] = iArray[inOffset++];
+ }
+ y++;
+ }
+ return;
+ }
+ case DataBuffer.TYPE_FLOAT:
+ case DataBuffer.TYPE_DOUBLE:
+ break;
+ default:
+ throw new ClassCastException("Unsupported data type");
+ }
+
+ // Default implementation probably slower for float and double
+ for (int hh = 0; hh < h; hh++)
+ {
+ for (int ww = 0; ww < w; ww++)
+ {
+ int offset = bandOffsets[b] + y * scanlineStride + (x + ww);
+ data.setElem(bankIndices[b], offset, iArray[inOffset++]);
+ }
+ y++;
+ }
+ }
+
+ /**
+ * Creates a String with some information about this SampleModel.
+ * @return A String describing this SampleModel.
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(getClass().getName());
+ result.append("[");
+ result.append("scanlineStride=").append(scanlineStride);
+ for(int i = 0; i < bitMasks.length; i+=1)
+ {
+ result.append(", mask[").append(i).append("]=0x").append(
+ Integer.toHexString(bitMasks[i]));
+ }
+
+ result.append("]");
+ return result.toString();
+ }
+}
Added: llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BufferStrategy.java
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BufferStrategy.java?rev=43913&view=auto
==============================================================================
--- llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BufferStrategy.java (added)
+++ llvm-gcc-4.2/trunk/libjava/classpath/java/awt/image/BufferStrategy.java Thu Nov 8 16:56:19 2007
@@ -0,0 +1,124 @@
+/* BufferStrategy.java -- describes image buffering resources
+ Copyright (C) 2002, 2005 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., 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.image;
+
+import java.awt.BufferCapabilities;
+import java.awt.Graphics;
+
+/**
+ * This class describes a strategy for managing image buffering
+ * resources on a Canvas or Window. A given buffer strategy may make
+ * use of hardware acceleration or take advantage of features of the
+ * native graphics system. Examples of buffering strategies are
+ * double or triple buffering using either flipping or blitting. For
+ * the details of these algorithms see BufferCapabilities.
+ *
+ * To use a buffer strategy, you retrieve it from either the current
+ * GraphicsConfiguration or from the Component on which you'd like to
+ * draw. Then you can query the strategy's capabilities to make sure
+ * they're suitable.
+ *
+ * If the strategy's capabilities are suitable, you can obtain a
+ * graphics object and use it to draw with this strategy. Drawing
+ * with a buffer strategy requires extra care, however. You'll need
+ * to manually cause the next buffer to be shown on the output device.
+ * And since buffer strategies are usually implemented with a
+ * VolatileImage, you must frequently check that the contents of the
+ * buffer are valid and that the buffer still exists.
+ *
+ * A buffer strategy is usually implemented using a VolatileImage.
+ *
+ * @see VolatileImage
+ * @since 1.4
+ */
+public abstract class BufferStrategy
+{
+ /**
+ * Creates a new buffer strategy.
+ */
+ public BufferStrategy()
+ {
+ }
+
+ /**
+ * Retrieves the capabilities of this buffer strategy.
+ *
+ * @return this buffer strategy's capabilities
+ */
+ public abstract BufferCapabilities getCapabilities();
+
+ /**
+ * Retrieves a graphics object that can be used to draw using this
+ * buffer strategy. This method may not be synchronized so be
+ * careful when calling it from multiple threads. You also must
+ * manually dispose of this graphics object.
+ *
+ * @return a graphics object that can be used to draw using this
+ * buffer strategy
+ */
+ public abstract Graphics getDrawGraphics();
+
+ /**
+ * Returns whether or not the buffer's resources have been reclaimed
+ * by the native graphics system. If the buffer resources have been
+ * lost then you'll need to obtain new resources before drawing
+ * again. For details, see the documentation for VolatileImage.
+ *
+ * @return true if the contents were lost, false otherwise
+ */
+ public abstract boolean contentsLost();
+
+ /**
+ * Returns whether or not the buffer's resources were re-created and
+ * cleared to the default background color. If the buffer's
+ * resources have recently been re-created and initialized then the
+ * buffer's image may need to be re-rendered. For details, see the
+ * documentation for VolatileImage.
+ *
+ * @return true if the contents were restored, false otherwise
+ */
+ public abstract boolean contentsRestored();
+
+ /**
+ * Applies this buffer strategy. In other words, this method brings
+ * the contents of the back or intermediate buffers to the front
+ * buffer.
+ */
+ public abstract void show();
+}
More information about the llvm-commits
mailing list