AWT/Swing merge from GNU Classpath.

From-SVN: r56147
This commit is contained in:
Bryce McKinlay 2002-08-09 04:26:17 +00:00 committed by Bryce McKinlay
parent 097684ce62
commit 7bde45b2eb
490 changed files with 86038 additions and 9753 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,183 @@
/* Area.java -- represents a shape built by constructive area geometry
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt.geom;
import java.awt.Rectangle;
import java.awt.Shape;
/**
* STUBS ONLY
* XXX Implement and document.
*/
public class Area implements Shape, Cloneable
{
public Area()
{
}
public Area(Shape s)
{
}
public void add(Area a)
{
// XXX Implement.
throw new Error("not implemented");
}
public void subtract(Area a)
{
// XXX Implement.
throw new Error("not implemented");
}
public void intersect(Area a)
{
// XXX Implement.
throw new Error("not implemented");
}
public void exclusiveOr(Area a)
{
// XXX Implement.
throw new Error("not implemented");
}
public void reset()
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean isEmpty()
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean isPolygonal()
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean isRectangular()
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean isSingular()
{
// XXX Implement.
throw new Error("not implemented");
}
public Rectangle2D getBounds2D()
{
// XXX Implement.
throw new Error("not implemented");
}
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
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw (Error) new InternalError().initCause(e); // Impossible
}
}
public boolean equals(Area a)
{
// XXX Implement.
throw new Error("not implemented");
}
public void transform(AffineTransform at)
{
// XXX Implement.
throw new Error("not implemented");
}
public Area createTransformedArea(AffineTransform at)
{
Area a = (Area) clone();
a.transform(at);
return a;
}
public boolean contains(double x, double y)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Point2D p)
{
return contains(p.getX(), p.getY());
}
public boolean contains(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Rectangle2D r)
{
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean intersects(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean intersects(Rectangle2D r)
{
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public PathIterator getPathIterator(AffineTransform at)
{
// XXX Implement.
throw new Error("not implemented");
}
public PathIterator getPathIterator(AffineTransform at, double flatness)
{
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
} // class Area

View file

@ -0,0 +1,519 @@
/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt.geom;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.NoSuchElementException;
/**
* STUBS ONLY
* XXX Implement and document.
*/
public abstract class CubicCurve2D implements Shape, Cloneable
{
protected CubicCurve2D()
{
}
public abstract double getX1();
public abstract double getY1();
public abstract Point2D getP1();
public abstract double getCtrlX1();
public abstract double getCtrlY1();
public abstract Point2D getCtrlP1();
public abstract double getCtrlX2();
public abstract double getCtrlY2();
public abstract Point2D getCtrlP2();
public abstract double getX2();
public abstract double getY2();
public abstract Point2D getP2();
public abstract void setCurve(double x1, double y1, double cx1, double cy1,
double cx2, double cy2, double x2, double y2);
public void setCurve(double[] coords, int offset)
{
setCurve(coords[offset++], coords[offset++],
coords[offset++], coords[offset++],
coords[offset++], coords[offset++],
coords[offset++], coords[offset++]);
}
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());
}
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());
}
public void setCurve(CubicCurve2D c)
{
setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(),
c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2());
}
public static double getFlatnessSq(double x1, double y1, double cx1,
double cy1, double cx2, double cy2,
double x2, double y2)
{
// XXX Implement.
throw new Error("not implemented");
}
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));
}
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++]);
}
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++]));
}
public double getFlatnessSq()
{
return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),
getCtrlX2(), getCtrlY2(), getX2(), getY2());
}
public double getFlatness()
{
return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX1(),
getCtrlY1(), getCtrlX2(), getCtrlY2(),
getX2(), getY2()));
}
public void subdivide(CubicCurve2D l, CubicCurve2D r)
{
if (l == null)
l = new CubicCurve2D.Double();
if (r == null)
r = new CubicCurve2D.Double();
// 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);
l.setCurve(d, 0);
r.setCurve(d, 6);
}
public static void subdivide(CubicCurve2D src,
CubicCurve2D l, CubicCurve2D r)
{
src.subdivide(l, r);
}
public static void subdivide(double[] src, int srcOff,
double[] left, int leftOff,
double[] right, int rightOff)
{
// XXX Implement.
throw new Error("not implemented");
}
public static int solveCubic(double[] eqn)
{
return solveCubic(eqn, eqn);
}
public static int solveCubic(double[] eqn, double[] res)
{
if (eqn[3] == 0)
return QuadCurve2D.solveQuadratic(eqn, res);
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(double x, double y)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Point2D p)
{
return contains(p.getX(), p.getY());
}
public boolean intersects(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean intersects(Rectangle2D r)
{
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean contains(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Rectangle2D r)
{
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public Rectangle getBounds()
{
return getBounds2D().getBounds();
}
public PathIterator getPathIterator(final AffineTransform at)
{
return new PathIterator()
{
/** Current coordinate. */
private int current;
public int getWindingRule()
{
return WIND_NON_ZERO;
}
public boolean isDone()
{
return current < 2;
}
public void next()
{
current++;
}
public int currentSegment(float[] coords)
{
if (current == 0)
{
coords[0] = (float) getX1();
coords[1] = (float) getY1();
if (at != null)
at.transform(coords, 0, coords, 0, 1);
return SEG_MOVETO;
}
if (current == 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();
if (at != null)
at.transform(coords, 0, coords, 0, 3);
return SEG_CUBICTO;
}
throw new NoSuchElementException("cubic iterator out of bounds");
}
public int currentSegment(double[] coords)
{
if (current == 0)
{
coords[0] = getX1();
coords[1] = getY1();
if (at != null)
at.transform(coords, 0, coords, 0, 1);
return SEG_MOVETO;
}
if (current == 1)
{
coords[0] = getCtrlX1();
coords[1] = getCtrlY1();
coords[2] = getCtrlX2();
coords[3] = getCtrlY2();
coords[4] = getX2();
coords[5] = getY2();
if (at != null)
at.transform(coords, 0, coords, 0, 3);
return SEG_CUBICTO;
}
throw new NoSuchElementException("cubic iterator out of bounds");
}
};
}
public PathIterator getPathIterator(AffineTransform at, double flatness)
{
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
/**
* Create a new curve 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
}
}
/**
* STUBS ONLY
*/
public static class Double extends CubicCurve2D
{
public double x1;
public double y1;
public double ctrlx1;
public double ctrly1;
public double ctrlx2;
public double ctrly2;
public double x2;
public double y2;
public Double()
{
}
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;
}
public double getX1()
{
return x1;
}
public double getY1()
{
return y1;
}
public Point2D getP1()
{
return new Point2D.Double(x1, y1);
}
public double getCtrlX1()
{
return ctrlx1;
}
public double getCtrlY1()
{
return ctrly1;
}
public Point2D getCtrlP1()
{
return new Point2D.Double(ctrlx1, ctrly1);
}
public double getCtrlX2()
{
return ctrlx2;
}
public double getCtrlY2()
{
return ctrly2;
}
public Point2D getCtrlP2()
{
return new Point2D.Double(ctrlx2, ctrly2);
}
public double getX2()
{
return x2;
}
public double getY2()
{
return y2;
}
public Point2D getP2()
{
return new Point2D.Double(x2, y2);
}
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;
}
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);
}
} // class Double
/**
* STUBS ONLY
*/
public static class Float extends CubicCurve2D
{
public float x1;
public float y1;
public float ctrlx1;
public float ctrly1;
public float ctrlx2;
public float ctrly2;
public float x2;
public float y2;
public Float()
{
}
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;
}
public double getX1()
{
return x1;
}
public double getY1()
{
return y1;
}
public Point2D getP1()
{
return new Point2D.Float(x1, y1);
}
public double getCtrlX1()
{
return ctrlx1;
}
public double getCtrlY1()
{
return ctrly1;
}
public Point2D getCtrlP1()
{
return new Point2D.Float(ctrlx1, ctrly1);
}
public double getCtrlX2()
{
return ctrlx2;
}
public double getCtrlY2()
{
return ctrly2;
}
public Point2D getCtrlP2()
{
return new Point2D.Float(ctrlx2, ctrly2);
}
public double getX2()
{
return x2;
}
public double getY2()
{
return y2;
}
public Point2D getP2()
{
return new Point2D.Float(x2, y2);
}
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;
}
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;
}
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);
}
} // class Float
} // class CubicCurve2D

View file

@ -1,4 +1,5 @@
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
/* Dimension2D.java -- abstraction of a dimension
Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -34,39 +35,79 @@ 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@cygnus.com>
* @date February, 1999.
* @author Eric Blake <ebb9@email.byu.edu>
* @since 1.2
* @status updated to 1.4
*/
/* Written using online API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct.
*/
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();
public abstract void setSize (double width, double height);
/**
* 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);
public void setSize (Dimension2D dim)
/**
* 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(dim.getWidth(), dim.getHeight());
setSize(d.getWidth(), d.getHeight());
}
public Object clone ()
/**
* Create a new dimension 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 _) {return null;}
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw (Error) new InternalError().initCause(e); // Impossible
}
}
protected Dimension2D ()
{
}
}
} // class Dimension2D

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* Ellipse2D.java -- represents an ellipse in 2-D space
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -38,39 +39,40 @@ package java.awt.geom;
/**
* @author Tom Tromey <tromey@cygnus.com>
* @date April 16, 2000
* @author Eric Blake <ebb9@email.byu.edu>
* @since 1.2
* @status still needs documentation
*/
public abstract class Ellipse2D extends RectangularShape
{
protected Ellipse2D ()
protected Ellipse2D()
{
}
public boolean contains (double x, double y)
public boolean contains(double x, double y)
{
double rx = getWidth () / 2;
double ry = getHeight () / 2;
double tx = (x - getCenterX ()) / rx;
double ty = (y - getCenterY ()) / ry;
double rx = getWidth() / 2;
double ry = getHeight() / 2;
double tx = (x - getCenterX()) / rx;
double ty = (y - getCenterY()) / ry;
return tx * tx + ty * ty <= 1.0;
}
public boolean contains (double x, double y, double w, double h)
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));
return (contains(x, y) && contains(x, y2)
&& contains(x2, y) && contains(x2, y2));
}
public PathIterator getPathIterator (AffineTransform at)
public PathIterator getPathIterator(AffineTransform at)
{
// fixme;
return null;
// An ellipse is just a complete arc.
return new Arc2D.ArcIterator(this, at);
}
public boolean intersects (double x, double y, double w, double h)
public boolean intersects(double x, double y, double w, double h)
{
// fixme
return false;
@ -83,57 +85,56 @@ public abstract class Ellipse2D extends RectangularShape
public double x;
public double y;
public Double ()
public Double()
{
height = width = x = y = 0;
}
public Double (double x, double y, double w, double h)
public Double(double x, double y, double w, double h)
{
this.x = x;
this.y = y;
this.height = h;
this.width = w;
height = h;
width = w;
}
public Rectangle2D getBounds2D ()
public Rectangle2D getBounds2D()
{
return new Rectangle2D.Double (x, y, width, height);
return new Rectangle2D.Double(x, y, width, height);
}
public double getHeight ()
public double getHeight()
{
return height;
}
public double getWidth ()
public double getWidth()
{
return width;
}
public double getX ()
public double getX()
{
return x;
}
public double getY ()
public double getY()
{
return y;
}
public boolean isEmpty ()
public boolean isEmpty()
{
return height <= 0 || width <= 0;
}
public void setFrame (double x, double y, double w, double h)
public void setFrame(double x, double y, double w, double h)
{
this.x = x;
this.y = y;
this.height = h;
this.width = w;
height = h;
width = w;
}
}
} // class Double
public static class Float extends Ellipse2D
{
@ -142,12 +143,11 @@ public abstract class Ellipse2D extends RectangularShape
public float x;
public float y;
public Float ()
public Float()
{
height = width = x = y = 0;
}
public Float (float x, float y, float w, float h)
public Float(float x, float y, float w, float h)
{
this.x = x;
this.y = y;
@ -155,50 +155,50 @@ public abstract class Ellipse2D extends RectangularShape
this.width = w;
}
public Rectangle2D getBounds2D ()
public Rectangle2D getBounds2D()
{
return new Rectangle2D.Float (x, y, width, height);
return new Rectangle2D.Float(x, y, width, height);
}
public double getHeight ()
public double getHeight()
{
return height;
}
public double getWidth ()
public double getWidth()
{
return width;
}
public double getX ()
public double getX()
{
return x;
}
public double getY ()
public double getY()
{
return y;
}
public boolean isEmpty ()
public boolean isEmpty()
{
return height <= 0 || width <= 0;
}
public void setFrame (float x, float y, float w, float h)
public void setFrame(float x, float y, float w, float h)
{
this.x = x;
this.y = y;
this.height = h;
this.width = w;
height = h;
width = w;
}
public void setFrame (double x, double y, double w, double h)
public void setFrame(double x, double y, double w, double h)
{
this.x = (float) x;
this.y = (float) y;
this.height = (float) h;
this.width = (float) w;
height = (float) h;
width = (float) w;
}
}
}
} // class Float
} // class Ellipse2D

View file

@ -0,0 +1,105 @@
/* FlatteningPathIterator.java -- performs interpolation of curved paths
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt.geom;
/**
* This class can be used to perform the flattening required by the Shape
* interface. It interpolates a curved path segment into a sequence of flat
* ones within a certain flatness, up to a recursion limit.
*
* @author Eric Blake <ebb9@email.byu.edu>
* @see Shape
* @see RectangularShape#getPathIterator(AffineTransform, double)
* @since 1.2
* @status STUBS ONLY
*/
public class FlatteningPathIterator implements PathIterator
{
// The iterator we are applied to.
private PathIterator subIterator;
private double flatness;
private int limit;
public FlatteningPathIterator(PathIterator src, double flatness)
{
this(src, flatness, 10);
}
public FlatteningPathIterator(PathIterator src, double flatness, int limit)
{
subIterator = src;
this.flatness = flatness;
this.limit = limit;
if (flatness < 0 || limit < 0)
throw new IllegalArgumentException();
}
public double getFlatness()
{
return flatness;
}
public int getRecursionLimit()
{
return limit;
}
public int getWindingRule()
{
return subIterator.getWindingRule();
}
public boolean isDone()
{
return subIterator.isDone();
}
public void next()
{
throw new Error("not implemented");
}
public int currentSegment(double[] coords)
{
throw new Error("not implemented");
}
public int currentSegment(float[] coords)
{
throw new Error("not implemented");
}
} // class FlatteningPathIterator

View file

@ -0,0 +1,361 @@
/* GeneralPath.java -- represents a shape built from subpaths
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt.geom;
import java.awt.Rectangle;
import java.awt.Shape;
/**
* STUBS ONLY
* XXX Implement and document. Note that Sun's implementation only expects
* float precision, not double.
*/
public final class GeneralPath implements Shape, Cloneable
{
public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD;
public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO;
/** Initial size if not specified. */
private static final int INIT_SIZE = 20;
/** The winding rule. */
private int rule;
/**
* The path type in points. Note that points[index] maps to
* types[index >> 1]; the control points of quad and cubic paths map as
* well but are ignored.
*/
private byte[] types;
/**
* The list of all points seen. Since you can only append floats, it makes
* sense for this to be a float[]. I have no idea why Sun didn't choose to
* allow a general path of double precision points.
*/
private float[] points;
/** The index of the most recent moveto point, or null. */
private int subpath = -1;
/** The next available index into points. */
private int index;
public GeneralPath()
{
this(WIND_NON_ZERO, INIT_SIZE);
}
public GeneralPath(int rule)
{
this(rule, INIT_SIZE);
}
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 >> 1];
points = new float[capacity];
}
public GeneralPath(Shape s)
{
types = new byte[INIT_SIZE >> 1];
points = new float[INIT_SIZE];
PathIterator pi = s.getPathIterator(null);
setWindingRule(pi.getWindingRule());
append(pi, false);
}
public void moveTo(float x, float y)
{
subpath = index;
ensureSize(index + 2);
types[index >> 1] = PathIterator.SEG_MOVETO;
points[index++] = x;
points[index++] = y;
}
public void lineTo(float x, float y)
{
ensureSize(index + 2);
types[index >> 1] = PathIterator.SEG_LINETO;
points[index++] = x;
points[index++] = y;
}
public void quadTo(float x1, float y1, float x2, float y2)
{
ensureSize(index + 4);
types[index >> 1] = PathIterator.SEG_QUADTO;
points[index++] = x1;
points[index++] = y1;
points[index++] = x2;
points[index++] = y2;
}
public void curveTo(float x1, float y1, float x2, float y2,
float x3, float y3)
{
ensureSize(index + 6);
types[index >> 1] = PathIterator.SEG_QUADTO;
points[index++] = x1;
points[index++] = y1;
points[index++] = x2;
points[index++] = y2;
points[index++] = x3;
points[index++] = y3;
}
public void closePath()
{
ensureSize(index + 2);
types[index >> 1] = PathIterator.SEG_CLOSE;
points[index++] = points[subpath];
points[index++] = points[subpath + 1];
}
public void append(Shape s, boolean connect)
{
append(s.getPathIterator(null), connect);
}
public void append(PathIterator i, boolean connect)
{
float[] f = new float[6];
while (! i.isDone())
{
int result = i.currentSegment(f);
switch (result)
{
case PathIterator.SEG_MOVETO:
if (! connect)
{
moveTo(f[0], f[1]);
break;
}
if (subpath >= 0 && f[0] == points[subpath]
&& f[1] == points[subpath + 1])
break;
// Fallthrough.
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;
default:
closePath();
}
connect = false;
}
}
public int getWindingRule()
{
return rule;
}
public void setWindingRule(int rule)
{
if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO)
throw new IllegalArgumentException();
this.rule = rule;
}
public Point2D getCurrentPoint()
{
if (subpath < 0)
return null;
return new Point2D.Float(points[subpath], points[subpath + 1]);
}
public void reset()
{
subpath = -1;
index = 0;
}
public void transform(AffineTransform xform)
{
xform.transform(points, 0, points, 0, index >> 1);
}
public Shape createTransformedShape(AffineTransform xform)
{
GeneralPath p = new GeneralPath(this);
p.transform(xform);
return p;
}
public Rectangle getBounds()
{
return getBounds2D().getBounds();
}
public Rectangle2D getBounds2D()
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(double x, double y)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Point2D p)
{
return contains(p.getX(), p.getY());
}
public boolean contains(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Rectangle2D r)
{
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean intersects(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean intersects(Rectangle2D r)
{
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public PathIterator getPathIterator(final AffineTransform at)
{
return new PathIterator()
{
int current = 0;
public int getWindingRule()
{
return rule;
}
public boolean isDone()
{
return current >= index;
}
public void next()
{
current++;
}
public int currentSegment(float[] coords)
{
if (current >= index)
return SEG_CLOSE;
int result = types[current >> 1];
int i = 0;
if (result == 3)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
}
if (result == 2)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
}
if (result < 2)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
if (at != null)
at.transform(coords, 0, coords, 0, result == 0 ? 1 : result);
}
return result;
}
public int currentSegment(double[] coords)
{
if (current >= index)
return SEG_CLOSE;
int result = types[current >> 1];
int i = 0;
if (result == 3)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
}
if (result == 2)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
}
if (result < 2)
{
coords[i++] = points[current++];
coords[i++] = points[current++];
if (at != null)
at.transform(coords, 0, coords, 0, result == 0 ? 1 : result);
}
return result;
}
};
}
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()
{
// This class is final; no need to use super.clone().
return new GeneralPath(this);
}
private void ensureSize(int size)
{
if (subpath < 0)
throw new IllegalPathStateException("need initial moveto");
if (size <= points.length)
return;
byte[] b = new byte[points.length];
System.arraycopy(types, 0, b, 0, index >> 1);
types = b;
float[] f = new float[points.length << 1];
System.arraycopy(points, 0, f, 0, index);
points = f;
}
} // class GeneralPath

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* IllegalPathStateException.java -- an operation was in an illegal path state
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -37,19 +38,34 @@ 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@cygnus.com>
* @date July 17, 2000
* @see GeneralPath
* @status updated to 1.4
*/
public class IllegalPathStateException extends RuntimeException
{
public IllegalPathStateException ()
/**
* Compatible with JDK 1.2+.
*/
private static final long serialVersionUID = -5158084205220481094L;
/**
* Create an exception with no message.
*/
public IllegalPathStateException()
{
super ();
}
public IllegalPathStateException (String msg)
/**
* Create an exception with a message.
*
* @param msg the message
*/
public IllegalPathStateException(String msg)
{
super (msg);
super(msg);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* NoninvertibleTransformException.java -- a transform can't be inverted
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -37,14 +38,28 @@ 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@cygnus.com>
* @date July 15, 2000
* @see AffineTransform
* @status updated to 1.4
*/
public class NoninvertibleTransformException extends Exception
{
public NoninvertibleTransformException (String s)
/**
* 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);
super(s);
}
}

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* PathIterator.java -- describes a shape by iterating over its vertices
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -37,23 +38,152 @@ 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@cygnus.com>
* @date April 16, 2000
* @author Eric Blake <ebb9@email.byu.edu>
* @see Shape
* @see Stroke
* @see FlatteningPathIterator
* @since 1.2
* @status updated to 1.4
*/
public interface PathIterator
{
public static final int SEG_CLOSE = 4;
public static final int SEG_CUBICTO = 3;
public static final int SEG_LINETO = 1;
public static final int SEG_MOVETO = 0;
public static final int SEG_QUADTO = 2;
public static final int WIND_EVEN_ODD = 0;
public static final int WIND_NON_ZERO = 1;
/**
* 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;
public int currentSegment (double[] coords);
public int currentSegment (float[] coords);
public int getWindingRule ();
public boolean isDone ();
public void next ();
}
/**
* 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 false, 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 false.
*
* @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

View file

@ -1,4 +1,5 @@
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
/* Point2D.java -- generic point in 2-D space
Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -37,161 +38,358 @@ 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@cygnus.com>
* @date February 8, 1999.
* @author Eric Blake <ebb9@email.byu.edu>
* @since 1.2
* @status updated to 1.4
*/
/* Written using "Java Class Libraries", 2nd edition, plus online
* API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: Believed complete and correct, except that neither toString
* nor hashCode have been compared with JDK output.
*/
public abstract class Point2D implements Cloneable
{
/**
* The default constructor.
*
* @see 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();
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 x the new x coordinate
* @param y the new y coordinate
*/
public abstract void setLocation(double x, double y);
protected Point2D ()
/**
* 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());
}
public void setLocation (Point2D pt) { setLocation(pt.getX(), pt.getY()); }
static public double distanceSq (double X1, double Y1, double X2, double Y2)
/**
* 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;
x2 -= x1;
y2 -= y1;
return x2 * x2 + y2 * y2;
}
static public double distance (double X1, double Y1, double X2, double 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)
*/
static public double distance(double x1, double y1, double x2, double y2)
{
return Math.sqrt(distanceSq(X1, Y1, X2, Y2));
return Math.sqrt(distanceSq(x1, y1, x2, y2));
}
public double distanceSq (double PX, double PY)
/**
* 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(), PX, getY(), PY);
return distanceSq(getX(), x, getY(), y);
}
public double distance (double PX, double PY)
/**
* 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 distance (getX(), PX, getY(), PY);
return distanceSq(getX(), p.getX(), getY(), p.getY());
}
public double distanceSq (Point2D pt)
/**
* 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 distanceSq (getX(), pt.getX(), getY(), pt.getY());
return distance(getX(), x, getY(), y);
}
public double distance (Point2D pt)
/**
* 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(), pt.getX(), getY(), pt.getY());
return distance(getX(), p.getX(), getY(), p.getY());
}
public int hashCode() { return (int) getX() ^ (int) 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 _) {return null;}
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw (Error) new InternalError().initCause(e); // Impossible
}
}
public boolean equals (Object o)
/**
* 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 ();
return getX() == p.getX() && getY() == p.getY();
}
/**
* This class defines a point in <code>double</code> precision.
*
* @author Eric Blake <ebb9@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;
public Double ()
/**
* Create a new point at (0,0).
*/
public Double()
{
x = 0;
y = 0;
}
public Double (double x, double y)
/**
* 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;
}
public double getX ()
/**
* Return the x coordinate.
*
* @return the x coordinate
*/
public double getX()
{
return x;
}
public double getY ()
/**
* Return the y coordinate.
*
* @return the y coordinate
*/
public double getY()
{
return y;
}
public void setLocation (double x, double 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;
}
public String toString ()
/**
* 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 "(" + x + ", " + y + ")";
return "Point2D.Double[" + x + ", " + y + ']';
}
}
} // class Double
/**
* This class defines a point in <code>float</code> precision.
*
* @author Eric Blake <ebb9@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;
public Float ()
/**
* Create a new point at (0,0).
*/
public Float()
{
x = 0;
y = 0;
}
public Float (float x, float y)
/**
* 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;
}
public double getX ()
/**
* Return the x coordinate.
*
* @return the x coordinate
*/
public double getX()
{
return x;
}
public double getY ()
/**
* Return the y coordinate.
*
* @return the y coordinate
*/
public double getY()
{
return y;
}
public void setLocation (double x, double 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;
}
public void setLocation (float x, 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;
}
public String toString ()
/**
* 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 "(" + x + ", " + y + ")";
return "Point2D.Float[" + x + ", " + y + ']';
}
}
}
} // class Float
} // class Point2D

View file

@ -0,0 +1,486 @@
/* QuadCurve2D.java -- represents a parameterized quadratic curve in 2-D space
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt.geom;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.NoSuchElementException;
/**
* STUBS ONLY
* XXX Implement and document.
*/
public abstract class QuadCurve2D implements Shape, Cloneable
{
protected QuadCurve2D()
{
}
public abstract double getX1();
public abstract double getY1();
public abstract Point2D getP1();
public abstract double getCtrlX();
public abstract double getCtrlY();
public abstract Point2D getCtrlPt();
public abstract double getX2();
public abstract double getY2();
public abstract Point2D getP2();
public abstract void setCurve(double x1, double y1, double cx, double cy,
double x2, double y2);
public void setCurve(double[] coords, int offset)
{
setCurve(coords[offset++], coords[offset++],
coords[offset++], coords[offset++],
coords[offset++], coords[offset++]);
}
public void setCurve(Point2D p1, Point2D c, Point2D p2)
{
setCurve(p1.getX(), p1.getY(), c.getX(), c.getY(),
p2.getX(), p2.getY());
}
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());
}
public void setCurve(QuadCurve2D c)
{
setCurve(c.getX1(), c.getY1(), c.getCtrlX(), c.getCtrlY(),
c.getX2(), c.getY2());
}
public static double getFlatnessSq(double x1, double y1, double cx,
double cy, double x2, double y2)
{
// XXX Implement.
throw new Error("not implemented");
}
public static double getFlatness(double x1, double y1, double cx, double cy,
double x2, double y2)
{
return Math.sqrt(getFlatnessSq(x1, y1, cx, cy, x2, y2));
}
public static double getFlatnessSq(double[] coords, int offset)
{
return getFlatnessSq(coords[offset++], coords[offset++],
coords[offset++], coords[offset++],
coords[offset++], coords[offset++]);
}
public static double getFlatness(double[] coords, int offset)
{
return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++],
coords[offset++], coords[offset++],
coords[offset++], coords[offset++]));
}
public double getFlatnessSq()
{
return getFlatnessSq(getX1(), getY1(), getCtrlX(), getCtrlY(),
getX2(), getY2());
}
public double getFlatness()
{
return Math.sqrt(getFlatnessSq(getX1(), getY1(), getCtrlX(), getCtrlY(),
getX2(), getY2()));
}
public void subdivide(QuadCurve2D l, QuadCurve2D r)
{
if (l == null)
l = new QuadCurve2D.Double();
if (r == null)
r = new QuadCurve2D.Double();
// 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);
l.setCurve(d, 0);
r.setCurve(d, 4);
}
public static void subdivide(QuadCurve2D src, QuadCurve2D l, QuadCurve2D r)
{
src.subdivide(l, r);
}
public static void subdivide(double[] src, int srcOff,
double[] left, int leftOff,
double[] right, int rightOff)
{
// XXX Implement.
throw new Error("not implemented");
}
public static int solveQuadratic(double[] eqn)
{
return solveQuadratic(eqn, eqn);
}
public static int solveQuadratic(double[] eqn, double[] res)
{
double c = eqn[0];
double b = eqn[1];
double a = eqn[2];
if (a == 0)
{
if (b == 0)
return -1;
res[0] = -c / b;
return 1;
}
c /= a;
b /= a * 2;
double det = Math.sqrt(b * b - c);
if (det != det)
return 0;
// For fewer rounding errors, we calculate the two roots differently.
if (b > 0)
{
res[0] = -b - det;
res[1] = -c / (b + det);
}
else
{
res[0] = -c / (b - det);
res[1] = -b + det;
}
return 2;
}
public boolean contains(double x, double y)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Point2D p)
{
return contains(p.getX(), p.getY());
}
public boolean intersects(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean intersects(Rectangle2D r)
{
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean contains(double x, double y, double w, double h)
{
// XXX Implement.
throw new Error("not implemented");
}
public boolean contains(Rectangle2D r)
{
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public Rectangle getBounds()
{
return getBounds2D().getBounds();
}
public PathIterator getPathIterator(final AffineTransform at)
{
return new PathIterator()
{
/** Current coordinate. */
private int current;
public int getWindingRule()
{
return WIND_NON_ZERO;
}
public boolean isDone()
{
return current < 2;
}
public void next()
{
current++;
}
public int currentSegment(float[] coords)
{
if (current == 0)
{
coords[0] = (float) getX1();
coords[1] = (float) getY1();
if (at != null)
at.transform(coords, 0, coords, 0, 1);
return SEG_MOVETO;
}
if (current == 1)
{
coords[0] = (float) getCtrlX();
coords[1] = (float) getCtrlY();
coords[2] = (float) getX2();
coords[3] = (float) getY2();
if (at != null)
at.transform(coords, 0, coords, 0, 2);
return SEG_QUADTO;
}
throw new NoSuchElementException("quad iterator out of bounds");
}
public int currentSegment(double[] coords)
{
if (current == 0)
{
coords[0] = getX1();
coords[1] = getY1();
if (at != null)
at.transform(coords, 0, coords, 0, 1);
return SEG_MOVETO;
}
if (current == 1)
{
coords[0] = getCtrlX();
coords[1] = getCtrlY();
coords[2] = getX2();
coords[3] = getY2();
if (at != null)
at.transform(coords, 0, coords, 0, 2);
return SEG_QUADTO;
}
throw new NoSuchElementException("quad iterator out of bounds");
}
};
}
public PathIterator getPathIterator(AffineTransform at, double flatness)
{
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
/**
* Create a new curve 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
}
}
/**
* STUBS ONLY
*/
public static class Double extends QuadCurve2D
{
public double x1;
public double y1;
public double ctrlx;
public double ctrly;
public double x2;
public double y2;
public Double()
{
}
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;
}
public double getX1()
{
return x1;
}
public double getY1()
{
return y1;
}
public Point2D getP1()
{
return new Point2D.Double(x1, y1);
}
public double getCtrlX()
{
return ctrlx;
}
public double getCtrlY()
{
return ctrly;
}
public Point2D getCtrlPt()
{
return new Point2D.Double(ctrlx, ctrly);
}
public double getX2()
{
return x2;
}
public double getY2()
{
return y2;
}
public Point2D getP2()
{
return new Point2D.Double(x2, y2);
}
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;
}
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);
}
} // class Double
/**
* STUBS ONLY
*/
public static class Float extends QuadCurve2D
{
public float x1;
public float y1;
public float ctrlx;
public float ctrly;
public float x2;
public float y2;
public Float()
{
}
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;
}
public double getX1()
{
return x1;
}
public double getY1()
{
return y1;
}
public Point2D getP1()
{
return new Point2D.Float(x1, y1);
}
public double getCtrlX()
{
return ctrlx;
}
public double getCtrlY()
{
return ctrly;
}
public Point2D getCtrlPt()
{
return new Point2D.Float(ctrlx, ctrly);
}
public double getX2()
{
return x2;
}
public double getY2()
{
return y2;
}
public Point2D getP2()
{
return new Point2D.Float(x2, y2);
}
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;
}
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;
}
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);
}
} // class Float
} // class CubicCurve2D

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* RectangularShape.java -- a rectangular frame for several generic shapes
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -34,77 +35,196 @@ 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.*;
import java.awt.geom.Rectangle2D;
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@cygnus.com>
* @date April 16, 2000
* @author Eric Blake <ebb9@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
{
protected RectangularShape ()
/**
* Default constructor.
*/
protected RectangularShape()
{
}
public abstract double getX ();
public abstract double getY ();
public abstract double getWidth ();
public abstract double getHeight ();
/**
* Get the x coordinate of the upper-left corner of the framing rectangle.
*
* @return the x coordinate
*/
public abstract double getX();
public double getMinX ()
{
return Math.min (getX (), getX () + getWidth ());
}
/**
* Get the y coordinate of the upper-left corner of the framing rectangle.
*
* @return the y coordinate
*/
public abstract double getY();
public double getMinY ()
/**
* 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 Math.min (getY (), getY () + getHeight ());
return getX();
}
public double getMaxX ()
{
return Math.max (getX (), getX () + getWidth ());
}
public double getMaxY ()
/**
* 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 Math.max (getY (), getY () + getHeight ());
return getY();
}
public double getCenterX ()
/**
* 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 () / 2;
return getX() + getWidth();
}
public double getCenterY ()
/**
* 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 () / 2;
return getY() + getHeight();
}
public Rectangle2D getFrame ()
/**
* Return the x coordinate of the center point of the framing rectangle.
*
* @return the central x coordinate
*/
public double getCenterX()
{
return new Rectangle2D.Double (getX (), getY (),
getWidth (), getHeight ());
return getX() + getWidth() / 2;
}
public abstract boolean isEmpty ();
public abstract void setFrame (double x, double y, double w, double h);
public void setFrame (Point2D loc, Dimension2D size)
/**
* Return the y coordinate of the center point of the framing rectangle.
*
* @return the central y coordinate
*/
public double getCenterY()
{
setFrame (loc.getX (), loc.getY (), size.getWidth (), size.getHeight ());
return getY() + getHeight() / 2;
}
public void setFrame (Rectangle2D r)
/**
* 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()
{
setFrame (r.getX (), r.getY (), r.getWidth (), r.getHeight ());
return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight());
}
public void setFrameFromDiagonal (double x1, double y1,
double x2, double y2)
/**
* 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)
{
@ -118,206 +238,148 @@ public abstract class RectangularShape implements Shape, Cloneable
y2 = y1;
y1 = t;
}
setFrame (x1, y1, x2 - x1, y2 - y1);
setFrame(x1, y1, x2 - x1, y2 - y1);
}
public void setFrameFromDiagonal (Point2D p1, Point2D p2)
/**
* 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 ());
setFrameFromDiagonal(p1.getX(), p1.getY(), p2.getX(), p2.getY());
}
public void setFrameFromCenter (double centerX, double centerY,
double cornerX, double cornerY)
/**
* 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,
2 * halfw, 2 * halfh);
double halfw = Math.abs(cornerX - centerX);
double halfh = Math.abs(cornerY - centerY);
setFrame(centerX - halfw, centerY - halfh, halfw + halfw, halfh + halfh);
}
public void setFrameFromCenter (Point2D center, Point2D corner)
/**
* 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 ());
setFrameFromCenter(center.getX(), center.getY(),
corner.getX(), corner.getY());
}
public boolean contains (Point2D p)
/**
* 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)
{
double x = p.getX ();
double y = p.getY ();
double rx = getX ();
double ry = getY ();
double w = getWidth ();
double h = getHeight ();
return x >= rx && x < rx + w && y >= ry && y < ry + h;
return contains(p.getX(), p.getY());
}
public boolean intersects (Rectangle2D r)
/**
* 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)
{
double x = getX ();
double w = getWidth ();
double mx = r.getX ();
double mw = r.getWidth ();
if (x < mx || x >= mx + mw || x + w < mx || x + w >= mx + mw)
return false;
double y = getY ();
double h = getHeight ();
double my = r.getY ();
double mh = r.getHeight ();
return y >= my && y < my + mh && y + h >= my && y + h < my + mh;
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
private boolean containsPoint (double x, double y)
/**
* 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)
{
double mx = getX ();
double mw = getWidth ();
if (x < mx || x >= mx + mw)
return false;
double my = getY ();
double mh = getHeight ();
return y >= my && y < my + mh;
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
}
public boolean contains (Rectangle2D r)
/**
* 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()
{
return (containsPoint (r.getMinX (), r.getMinY ())
&& containsPoint (r.getMaxX (), r.getMaxY ()));
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));
}
public Rectangle getBounds ()
/**
* 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 transform 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 Rectangle ((int) getX (), (int) getY (),
(int) getWidth (), (int) getHeight ());
return new FlatteningPathIterator(getPathIterator(at), flatness);
}
public PathIterator getPathIterator (AffineTransform at, double flatness)
{
return at.new Iterator (new Iterator ());
}
public Object clone ()
/**
* 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 _) {return null;}
{
return super.clone();
}
catch (CloneNotSupportedException e)
{
throw (Error) new InternalError().initCause(e); // Impossible
}
}
// This implements the PathIterator for all RectangularShape objects
// that don't override getPathIterator.
private class Iterator implements PathIterator
{
// Our current coordinate.
private int coord;
private static final int START = 0;
private static final int END_PLUS_ONE = 5;
public Iterator ()
{
coord = START;
}
public int currentSegment (double[] coords)
{
int r;
switch (coord)
{
case 0:
coords[0] = getX ();
coords[1] = getY ();
r = SEG_MOVETO;
break;
case 1:
coords[0] = getX () + getWidth ();
coords[1] = getY ();
r = SEG_LINETO;
break;
case 2:
coords[0] = getX () + getWidth ();
coords[1] = getY () + getHeight ();
r = SEG_LINETO;
break;
case 3:
coords[0] = getX ();
coords[1] = getY () + getHeight ();
r = SEG_LINETO;
break;
case 4:
r = SEG_CLOSE;
break;
default:
// It isn't clear what to do if the caller calls us after
// isDone returns true.
r = SEG_CLOSE;
break;
}
return r;
}
public int currentSegment (float[] coords)
{
int r;
switch (coord)
{
case 0:
coords[0] = (float) getX ();
coords[1] = (float) getY ();
r = SEG_MOVETO;
break;
case 1:
coords[0] = (float) (getX () + getWidth ());
coords[1] = (float) getY ();
r = SEG_LINETO;
break;
case 2:
coords[0] = (float) (getX () + getWidth ());
coords[1] = (float) (getY () + getHeight ());
r = SEG_LINETO;
break;
case 3:
coords[0] = (float) getX ();
coords[1] = (float) (getY () + getHeight ());
r = SEG_LINETO;
break;
case 4:
default:
// It isn't clear what to do if the caller calls us after
// isDone returns true. We elect to keep returning
// SEG_CLOSE.
r = SEG_CLOSE;
break;
}
return r;
}
public int getWindingRule ()
{
return WIND_NON_ZERO;
}
public boolean isDone ()
{
return coord == END_PLUS_ONE;
}
public void next ()
{
if (coord < END_PLUS_ONE)
++coord;
}
}
}
} // class RectangularShape

View file

@ -1,4 +1,5 @@
/* Copyright (C) 2000, 2002 Free Software Foundation
/* RoundRectangle2D.java -- represents a rectangle with rounded corners
Copyright (C) 2000, 2002 Free Software Foundation
This file is part of GNU Classpath.
@ -43,10 +44,10 @@ package java.awt.geom;
public abstract class RoundRectangle2D extends RectangularShape
{
/** Return the arc height of this round rectangle. */
public abstract double getArcHeight ();
public abstract double getArcHeight();
/** Return the arc width of this round rectangle. */
public abstract double getArcWidth ();
public abstract double getArcWidth();
/** Set the values of this round rectangle
* @param x The x coordinate
@ -56,13 +57,13 @@ public abstract class RoundRectangle2D extends RectangularShape
* @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);
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 ()
protected RoundRectangle2D()
{
}
@ -70,22 +71,22 @@ public abstract class RoundRectangle2D extends RectangularShape
* @param x The x coordinate
* @param y The y coordinate
*/
public boolean contains (double x, double y)
public boolean contains(double x, double y)
{
double mx = getX ();
double mw = getWidth ();
double mx = getX();
double mw = getWidth();
if (x < mx || x >= mx + mw)
return false;
double my = getY ();
double mh = getHeight ();
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));
double aw = getArcWidth ();
double ah = getArcHeight ();
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));
double aw = getArcWidth();
double ah = getArcHeight();
if (dx > aw || dy > ah)
return true;
@ -105,18 +106,18 @@ public abstract class RoundRectangle2D extends RectangularShape
* @param w The width
* @param h The height
*/
public boolean contains (double x, double y, double w, double h)
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 + w, h)
&& contains (x, y + h) && contains (x + w, y + h));
return (contains(x, y) && contains(x + w, h)
&& contains(x, y + h) && contains(x + w, y + h));
}
/** Return a new path iterator which iterates over this rectangle.
* @param at An affine transform to apply to the object
*/
public PathIterator getPathIterator (AffineTransform at)
public PathIterator getPathIterator(AffineTransform at)
{
// FIXME.
return null;
@ -128,15 +129,15 @@ public abstract class RoundRectangle2D extends RectangularShape
* @param w The width
* @param h The height
*/
public boolean intersects (double x, double y, double w, double h)
public boolean intersects(double x, double y, double w, double h)
{
// Here we can use the same code we use for an ordinary rectangle.
double mx = getX ();
double mw = getWidth ();
double mx = getX();
double mw = getWidth();
if (x < mx || x >= mx + mw || x + w < mx || x + w >= mx + mw)
return false;
double my = getY ();
double mh = getHeight ();
double my = getY();
double mh = getHeight();
return y >= my && y < my + mh && y + h >= my && y + h < my + mh;
}
@ -146,130 +147,20 @@ public abstract class RoundRectangle2D extends RectangularShape
* @param w The width
* @param h The height
*/
public void setFrame (double x, double y, double w, double h)
public void setFrame(double x, double y, double w, double h)
{
// This is a bit lame.
setRoundRect (x, y, w, h, getArcWidth (), getArcHeight ());
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)
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
* 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 ()
{
this (0, 0, 0, 0, 0, 0);
}
/** 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;
}
setRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(),
rr.getArcWidth(), rr.getArcHeight());
}
/** A subclass of RoundRectangle which keeps its parameters as
@ -295,9 +186,8 @@ public abstract class RoundRectangle2D extends RectangularShape
public double height;
/** Construct a new instance, with all parameters set to 0. */
public Double ()
public Double()
{
this (0, 0, 0, 0, 0, 0);
}
/** Construct a new instance with the given arguments.
@ -308,8 +198,8 @@ public abstract class RoundRectangle2D extends RectangularShape
* @param arcWidth The arc width
* @param arcHeight The arc height
*/
public Double (double x, double y, double w, double h,
double arcWidth, double arcHeight)
public Double(double x, double y, double w, double h,
double arcWidth, double arcHeight)
{
this.x = x;
this.y = y;
@ -319,48 +209,48 @@ public abstract class RoundRectangle2D extends RectangularShape
this.archeight = arcHeight;
}
public double getArcHeight ()
public double getArcHeight()
{
return archeight;
}
public double getArcWidth ()
public double getArcWidth()
{
return arcwidth;
}
public Rectangle2D getBounds2D ()
public Rectangle2D getBounds2D()
{
return new Rectangle2D.Double (x, y, width, height);
return new Rectangle2D.Double(x, y, width, height);
}
public double getX ()
public double getX()
{
return x;
}
public double getY ()
public double getY()
{
return y;
}
public double getWidth ()
public double getWidth()
{
return width;
}
public double getHeight ()
public double getHeight()
{
return height;
}
public boolean isEmpty ()
public boolean isEmpty()
{
return width <= 0 || height <= 0;
}
public void setRoundRect (double x, double y, double w, double h,
double arcWidth, double arcHeight)
public void setRoundRect(double x, double y, double w, double h,
double arcWidth, double arcHeight)
{
this.x = x;
this.y = y;
@ -369,5 +259,114 @@ public abstract class RoundRectangle2D extends RectangularShape
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