edu.neu.ccs.gui
Class BaseShape

java.lang.Object
  extended byedu.neu.ccs.gui.BaseShape
All Implemented Interfaces:
Shape, SupportsPropertyChange
Direct Known Subclasses:
BaseVertexShape, TweakableShape

public class BaseShape
extends Object
implements Shape, SupportsPropertyChange

Class BaseShape encapsulates a Shape defined using vertex and tangent data.

Specifically, BaseShape encapsulates:

A BaseShape is parametrized by three additional settings:

Class BaseShape contains the common code and data for the derived classes:

Class BaseShape may not be instantiated directly since it does not have a public constructor.

In 2.4.0, the restriction that the internal vertex and tangent array must be non-null and of form float[N][2] for the same N was weakened to permit the tangent array to be null. It is still the case that the vertex array must be non-null and of form float[N][2] and that if the tangent array is non-null then it must have the same form. The relaxation was introduced to support the derived classes whose Path.Strategy does not use tangents and for which creation of a tangent array is unnecessary.

If the internal tangent array is null and a tangent is requested by some method then it is treated as [0;0].

Since:
2.3
Version:
2.4.0

Field Summary
private  PropertyChangeSupport changeAdapter
          The main listener for this BaseShape object to implement the interface SupportsPropertyChange.
private  ClosureMode closuremode
          The ClosureMode: OPEN or CLOSED.
private  PropertyChangeForwardingListener forwardingListener
          The forwarding listener for this BaseShape object to implement the interface SupportsPropertyChange.
private  GeneralPath path
          The GeneralPath used to implement the Shape.
private  Path.Strategy pathstrategy
          The Path.Strategy.
static String REMOVE_SHAPE_DATA
          Bound property name to clear/remove all vertex and tangent data.
static String SET_CLOSURE_MODE
          Bound property name for set closure mode.
static String SET_PATH_STRATEGY
          Bound property name for set path strategy.
static String SET_WINDING_RULE
          Bound property name for set winding rule.
protected  float[][] tangent
          The tangent data of the shape.
protected  float[][] vertex
          The vertex data of the shape.
private  WindingRule windingrule
          The WindingRule: WIND_NON_ZERO or WIND_EVEN_ODD.
 
Constructor Summary
protected BaseShape()
          The protected default constructor.
 
Method Summary
 void addForwardingListener(Object object)
          Add the forwarding listener as a property change listener for the given object if the object supports property change.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list for a specific property.
 void addPropertyChangeListeners(PropertyChangeListener[] listeners)
          Add all items in the given PropertyChangeListener array to the listener list.
 void addPropertyChangeListeners(String propertyName, PropertyChangeListener[] listeners)
          Add all items in the given PropertyChangeListener array to the listener list for a specific property.
static float[][] bezierTangentSegmentPoints(float[][] vertex, float[][] tangent)
          Static method that returns a float array that contains the Bezier tangent segments for the given vertex and tangent arrays.
static float[][] closedBezierControlPoints(float[][] vertex, float[][] tangent)
          Static method that returns a float array that contains the Bezier control points for the closed curve with the given vertex and tangent arrays.
static float[][] closedBezierFramePoints(float[][] vertex, float[][] tangent)
          Static method that returns a float array that contains the points on the closed Bezier frame for the given vertex and tangent arrays.
 boolean contains(double x, double y)
          Tests if the specified coordinates are inside the boundary of the Shape.
 boolean contains(double x, double y, double w, double h)
          Tests if the interior of the Shape entirely contains the specified rectangular area.
 boolean contains(Point2D p)
          Tests if a specified Point2D is inside the boundary of the Shape.
 boolean contains(Rectangle2D r)
          Tests if the interior of the Shape entirely contains the specified rectangular area.
 int findControlA(double x, double y, double epsilon)
          Returns the index of the first ahead control point that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such ahead control point exists.
 int findControlA(double x, double y, double epsilon, Metric metric)
          Returns the index of the first ahead control point that is within epsilon of (x,y) relative to the given metric; returns -1 if no such ahead control point exists.
 int findControlB(double x, double y, double epsilon)
          Returns the index of the first behind control point that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such behind control point exists.
 int findControlB(double x, double y, double epsilon, Metric metric)
          Returns the index of the first behind control point that is within epsilon of (x,y) relative to the given metric; returns -1 if no such behind control point exists.
 int findVertex(double x, double y, double epsilon)
          Returns the index of the first vertex that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such vertex exists.
 int findVertex(double x, double y, double epsilon, Metric metric)
          Returns the index of the first vertex that is within epsilon of (x,y) relative to the given metric; returns -1 if no such vertex exists.
 void firePropertyChange(PropertyChangeEvent evt)
          Fire an existing PropertyChangeEvent to any registered listeners.
 void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, byte oldValue, byte newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, char oldValue, char newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, double oldValue, double newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, float oldValue, float newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, int oldValue, int newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, long oldValue, long newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Report a bound property update to any registered listeners.
 void firePropertyChange(String propertyName, short oldValue, short newValue)
          Report a bound property update to any registered listeners.
 float getAX(int index)
          Returns the x-coordinate of the Bezier control point that is ahead of the vertex at the given index.
 float getAY(int index)
          Returns the y-coordinate of the Bezier control point that is ahead of the vertex at the given index.
 float[][] getBezierTangentSegmentData()
          Returns the Bezier tangent segment data corresponding to the vertex and tangent data.
 Rectangle getBounds()
          Returns an integer Rectangle that completely encloses the Shape.
 Rectangle2D getBounds2D()
          Returns a high precision and more accurate bounding box of the Shape than the getBounds method.
 float getBX(int index)
          Returns the x-coordinate of the Bezier control point that is behind the vertex at the given index.
 float getBY(int index)
          Returns the y-coordinate of the Bezier control point that is behind the vertex at the given index.
 float[][] getClosedBezierControlData()
          Returns the closed Bezier control points corresponding to the vertex and tangent data.
 float[][] getClosedBezierFrameData()
          Returns the closed Bezier frame data corresponding to the vertex and tangent data.
 ClosureMode getClosureMode()
          Get the closure mode.
 float[] getControlA(int index)
          Returns a copy of the Bezier control point that is ahead of the vertex at the given index.
 float[] getControlB(int index)
          Returns a copy of the Bezier control point that is behind the vertex at the given index.
 float[] getCubicCurvePoint(float t)
          Returns an array float[2] with the coordinates of a point on the closed cubic curve determined by the internal vertex and tangent data and the float parameter t.
 PropertyChangeForwardingListener getForwardingListener()
          Returns the PropertyChangeForwardingListener that will forward the property change events it receives to this object.
 float[][] getOpenBezierControlData()
          Returns the open Bezier control points corresponding to the vertex and tangent data.
 float[][] getOpenBezierFrameData()
          Returns the open Bezier frame data corresponding to the vertex and tangent data.
 GeneralPath getPath()
          Returns a copy of the GeneralPath that defines this Shape based on the vertex data, tangent data, path strategy, closure mode, and winding rule.
 PathIterator getPathIterator(AffineTransform at)
          Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.
 PathIterator getPathIterator(AffineTransform at, double flatness)
          Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.
 Path.Strategy getPathStrategy()
          Get the PathStrategy.
 float[] getPolygonPoint(float t)
          Returns an array float[2] with the coordinates of a point on the closed polygon determined by the internal vertex data and the float parameter t.
 PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all listeners that were added to this object.
 PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
          Returns an array of all listeners that were added to this object and associated with the named property.
 float[] getTangent(int index)
          Returns a copy of the tangent at the given index.
 float[][] getTangentData()
          Returns a copy of the tangent data.
 Shape getTransformedShape(AffineTransform at)
          Returns a new Shape obtained from this object by using the path iterator corresponding to the given transform.
 Shape getTransformedShape(AffineTransform at, double flatness)
          Returns a new Shape obtained from this object by using the path iterator corresponding to the given transform and flatness.
 float getTX(int index)
          Returns the x-coordinate of the tangent data if the given index is in bounds or 0 if the index is out of bounds or if the tangent data is null.
 float getTY(int index)
          Returns the y-coordinate of the tangent data if the given index is in bounds or 0 if the index is out of bounds or if the tangent data is null.
 float[] getVertex(int index)
          Returns a copy of the vertex at the given index.
 float[][] getVertexData()
          Returns a copy of the vertex data.
 float[] getVertexTangent(int index)
          Returns a copy of the combined vertex and tangent data at the given index.
 float[][] getVertexTangentData()
          Returns a copy of the vertex and tangent data.
 float getVX(int index)
          Returns the x-coordinate of the vertex data if the given index is in bounds or 0 if the index is out of bounds.
 float getVY(int index)
          Returns the y-coordinate of the vertex data if the given index is in bounds or 0 if the index is out of bounds.
 WindingRule getWindingRule()
          Get the winding rule.
 boolean hasListeners(String propertyName)
          Check if there are any listeners for a specific property.
 boolean intersects(double x, double y, double w, double h)
          Tests if the interior of the Shape intersects the interior of a specified rectangular area.
 boolean intersects(Rectangle2D r)
          Tests if the interior of the Shape intersects the interior of a specified rectangular area.
 boolean isTangentNull()
          Returns true if the internal tangent data is null.
 int length()
          Returns the length N of the vertex data; if the tangent data is non-null then this data has the same length.
 TweakableShape makeBezierTangentSegments()
          Returns a new TweakableShape whose vertex and tangent data is a copy of the corresponding vertex and tangent data of this shape, whose Path.Strategy is Path.BEZIER_TANGENT_SEGMENTS, and whose winding rule is the same as this shape.
 PolygonShape makeClosedBezierFrame()
          Returns a new closed PolygonShape whose vertex data is the closed Bezier frame corresponding to the vertex and tangent data of this shape and whose winding rule is the same as this shape.
 PolygonDotsShape makeClosedControlDots()
          Returns a new PolygonDotsShape whose vertex data is the closed Bezier control point list corresponding to the vertex and tangent data of this shape.
 PolygonShape makeClosedPolygon()
          Returns a new closed PolygonShape whose vertex data is a copy of the vertex data of this shape.
 PolygonShape makeOpenBezierFrame()
          Returns a new open PolygonShape whose vertex data is the open Bezier frame corresponding to the vertex and tangent data of this shape and whose winding rule is the same as this shape.
 PolygonDotsShape makeOpenControlDots()
          Returns a new PolygonDotsShape whose vertex data is the open Bezier control point list corresponding to the vertex and tangent data of this shape.
 PolygonShape makeOpenPolygon()
          Returns a new open PolygonShape whose vertex data is a copy of the vertex data of this shape.
protected  void makePath()
          Make the path for the shape using the internal vertex and tangent data and the path strategy, closure mode, and winding rule settings.
 PolygonDotsShape makePolygonDots()
          Returns a new PolygonDotsShape whose vertex data is a copy of the vertex data of this shape.
static float[][] openBezierControlPoints(float[][] vertex, float[][] tangent)
          Static method that returns a float array that contains the Bezier control points for the open curve with the given vertex and tangent arrays.
static float[][] openBezierFramePoints(float[][] vertex, float[][] tangent)
          Static method that returns a float array that contains the points on the open Bezier frame for the given vertex and tangent arrays.
 void removeAndAddForwardingListener(Object oldobject, Object newobject)
          Remove the forwarding listener as a property change listener for the old object if the old object supports property change and add the forwarding listener as a property change listener for the new object if the new object supports property change.
 void removeForwardingListener(Object object)
          Remove the forwarding listener as a property change listener for the given object if the object supports property change.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Remove a PropertyChangeListener for a specific property.
 void removeShapeData()
          Removes all vertex and tangent data and makes a new path.
 void setClosureMode(ClosureMode closuremode)
          Sets the closure mode and makes a new path.
 void setPathStrategy(Path.Strategy pathstrategy)
          Sets the path strategy and makes a new path.
 void setWindingRule(int rule)
          Sets the winding rule via an int and makes a new path.
 void setWindingRule(WindingRule windingrule)
          Sets the winding rule and makes a new path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SET_PATH_STRATEGY

public static final String SET_PATH_STRATEGY
Bound property name for set path strategy.

See Also:
Constant Field Values

SET_CLOSURE_MODE

public static final String SET_CLOSURE_MODE
Bound property name for set closure mode.

See Also:
Constant Field Values

SET_WINDING_RULE

public static final String SET_WINDING_RULE
Bound property name for set winding rule.

See Also:
Constant Field Values

REMOVE_SHAPE_DATA

public static final String REMOVE_SHAPE_DATA
Bound property name to clear/remove all vertex and tangent data.

See Also:
Constant Field Values

vertex

protected float[][] vertex

The vertex data of the shape.

Derived classes must ensure that this member data is not null and that it has the form float[N][2].

The initial default is new float[0][2].


tangent

protected float[][] tangent

The tangent data of the shape.

Derived classes must ensure that this member data is either null or that it has the form float[N][2] for the same N as in the vertex array.

The requirement on the tangent array to permit null was introduced in 2.4.0.

The initial default is null.


path

private GeneralPath path
The GeneralPath used to implement the Shape.


pathstrategy

private Path.Strategy pathstrategy

The Path.Strategy.

.

The initial default is Path.POLYGON.


closuremode

private ClosureMode closuremode

The ClosureMode: OPEN or CLOSED.

The initial default is ClosureMode.CLOSED.


windingrule

private WindingRule windingrule

The WindingRule: WIND_NON_ZERO or WIND_EVEN_ODD.

The initial default is WindingRule.WIND_NON_ZERO.


changeAdapter

private final PropertyChangeSupport changeAdapter

The main listener for this BaseShape object to implement the interface SupportsPropertyChange.

Note: In this implementation, PropertyChangeSupport is used rather than SwingPropertyChangeSupport to ensure thread safety.


forwardingListener

private final PropertyChangeForwardingListener forwardingListener

The forwarding listener for this BaseShape object to implement the interface SupportsPropertyChange.

Constructor Detail

BaseShape

protected BaseShape()

The protected default constructor.

The default settings are as follows:

Method Detail

length

public final int length()
Returns the length N of the vertex data; if the tangent data is non-null then this data has the same length.


isTangentNull

public final boolean isTangentNull()
Returns true if the internal tangent data is null.


getVX

public final float getVX(int index)
Returns the x-coordinate of the vertex data if the given index is in bounds or 0 if the index is out of bounds.

Parameters:
index - the index of the vertex

getVY

public final float getVY(int index)
Returns the y-coordinate of the vertex data if the given index is in bounds or 0 if the index is out of bounds.

Parameters:
index - the index of the vertex

getVertex

public final float[] getVertex(int index)

Returns a copy of the vertex at the given index.

More precisely, returns:

  new float[] { getVX(index), getVY(index) }

In particular, returns [0;0] if the given index is out of bounds.


getTX

public final float getTX(int index)
Returns the x-coordinate of the tangent data if the given index is in bounds or 0 if the index is out of bounds or if the tangent data is null.

Parameters:
index - the index of the tangent

getTY

public final float getTY(int index)
Returns the y-coordinate of the tangent data if the given index is in bounds or 0 if the index is out of bounds or if the tangent data is null.

Parameters:
index - the index of the tangent

getTangent

public final float[] getTangent(int index)

Returns a copy of the tangent at the given index.

More precisely, returns:

  new float[] { getTX(index), getTY(index) }

In particular, returns [0;0] if the given index is out of bounds or if the tangent data is null.


getAX

public final float getAX(int index)

Returns the x-coordinate of the Bezier control point that is ahead of the vertex at the given index.

Specifically, returns:

  getVX(index) + getTX(index)

Parameters:
index - the index of the ahead control point

getAY

public final float getAY(int index)

Returns the y-coordinate of the Bezier control point that is ahead of the vertex at the given index.

Specifically, returns:

  getVY(index) + getTY(index)

Parameters:
index - the index of the ahead control point

getControlA

public final float[] getControlA(int index)

Returns a copy of the Bezier control point that is ahead of the vertex at the given index.

Specifically, returns:

  new float[] { getAX(index), getAY(index) }

Parameters:
index - the index of the ahead control point

getBX

public final float getBX(int index)

Returns the x-coordinate of the Bezier control point that is behind the vertex at the given index.

Specifically, returns:

  getVX(index) - getTX(index)

Parameters:
index - the index of the behind control point

getBY

public final float getBY(int index)

Returns the y-coordinate of the Bezier control point that is behind the vertex at the given index.

Specifically, returns:

  getVY(index) - getTY(index)

Parameters:
index - the index of the behind control point

getControlB

public final float[] getControlB(int index)

Returns a copy of the Bezier control point that is behind the vertex at the given index.

Specifically, returns:

  new float[] { getBX(index), getBY(index) }

Parameters:
index - the index of the behind control point

getVertexTangent

public final float[] getVertexTangent(int index)

Returns a copy of the combined vertex and tangent data at the given index.

More precisely, returns:

  new float[] { getVX(index), getVY(index), getTX(index), getTY(index) }

In particular, returns [0;0] if the given index is out of bounds.


getVertexData

public final float[][] getVertexData()

Returns a copy of the vertex data.

The returned array will have the form float[N][2] where N is the length.

The row at index i will contain:

  getVertex(i)

Returns:
a copy of the vertex data

getTangentData

public final float[][] getTangentData()

Returns a copy of the tangent data.

The returned array will have the form float[N][2] where N is the length even if the internal tangent array is null.

The row at index i will contain:

  getTangent(i)

Use the method isTangentNull() to test if the internal tangent array is null.

Returns:
a copy of the tangent data

getVertexTangentData

public final float[][] getVertexTangentData()

Returns a copy of the vertex and tangent data.

The returned array will have the form float[N][4] where N is the length.

The row at index i will contain:

  getVertexTangent(i)

Returns:
the a copy of the vertex and tangent data

getPolygonPoint

public final float[] getPolygonPoint(float t)

Returns an array float[2] with the coordinates of a point on the closed polygon determined by the internal vertex data and the float parameter t.

Let N denote the length of the vertex data array.

If N == 0, return [0;0].

If N == 1 or if N > 1 and either t <= 0 or t >= N, return getVertex(0).

Otherwise, let t = a + f where a is an integer and 0 <= f < 1. Let b = a+1 modulo N.

Then, return the linear interpolation between the points getVertex(a) and getVertex(b) corresponding to the parameter f.

Parameters:
t - the parameter that determines the point

getCubicCurvePoint

public final float[] getCubicCurvePoint(float t)

Returns an array float[2] with the coordinates of a point on the closed cubic curve determined by the internal vertex and tangent data and the float parameter t.

Let N denote the length of the vertex data array.

If N == 0, return [0;0].

If N == 1 or if N > 1 and either t <= 0 or t >= N, return getVertex(0).

Otherwise, let t = a + f where a is an integer and 0 <= f < 1. Let b = a+1 modulo N.

Then, return the Bezier cubic point corresponding to the parameter f and the 4 Bezier control points given below.

Parameters:
t - the parameter that determines the point

findVertex

public final int findVertex(double x,
                            double y,
                            double epsilon)

Returns the index of the first vertex that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such vertex exists.

The intended use of this method is to locate a vertex using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness

findVertex

public final int findVertex(double x,
                            double y,
                            double epsilon,
                            Metric metric)

Returns the index of the first vertex that is within epsilon of (x,y) relative to the given metric; returns -1 if no such vertex exists.

If the given metric is null then Metric.MAX is used.

The intended use of this method is to locate a vertex using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness
metric - the metric to do the distance computation

findControlA

public final int findControlA(double x,
                              double y,
                              double epsilon)

Returns the index of the first ahead control point that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such ahead control point exists.

The intended use of this method is to locate an ahead control point using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness

findControlA

public final int findControlA(double x,
                              double y,
                              double epsilon,
                              Metric metric)

Returns the index of the first ahead control point that is within epsilon of (x,y) relative to the given metric; returns -1 if no such ahead control point exists.

If the given metric is null then Metric.MAX is used.

The intended use of this method is to locate an ahead control point using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness
metric - the metric to do the distance computation

findControlB

public final int findControlB(double x,
                              double y,
                              double epsilon)

Returns the index of the first behind control point that is within epsilon of (x,y) relative to the metric Metric.MAX; returns -1 if no such behind control point exists.

The intended use of this method is to locate a behind control point using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness

findControlB

public final int findControlB(double x,
                              double y,
                              double epsilon,
                              Metric metric)

Returns the index of the first behind control point that is within epsilon of (x,y) relative to the given metric; returns -1 if no such behind control point exists.

If the given metric is null then Metric.MAX is used.

The intended use of this method is to locate a behind control point using an approximate mouse position.

Parameters:
x - the x-coordinate of the search point
y - the y-coordinate of the search point
epsilon - the measure of closeness
metric - the metric to do the distance computation

setPathStrategy

public void setPathStrategy(Path.Strategy pathstrategy)

Sets the path strategy and makes a new path.

Does nothing if its parameter is null.

Fires property change: SET_PATH_STRATEGY.

This method may be overridden in a derived class but only if the following contract is observed:

This contract permits the definition of derived classes that are intended to support a specific Path.Strategy.

Parameters:
pathstrategy - the path strategy to set

getPathStrategy

public final Path.Strategy getPathStrategy()
Get the PathStrategy.

Returns:
the path strategy

setClosureMode

public final void setClosureMode(ClosureMode closuremode)

Sets the closure mode and makes a new path.

Does nothing if its parameter is null.

Fires property change: SET_CLOSURE_MODE.

Parameters:
closuremode - the closure mode to set

getClosureMode

public final ClosureMode getClosureMode()
Get the closure mode.

Returns:
the closure mode

setWindingRule

public final void setWindingRule(WindingRule windingrule)

Sets the winding rule and makes a new path.

Does nothing if its parameter is null.

Fires property change: SET_WINDING_RULE.

Parameters:
windingrule - the winding rule to set

setWindingRule

public final void setWindingRule(int rule)

Sets the winding rule via an int and makes a new path.

GeneralPath.WIND_NON_ZERO corresponds to WindingRule.WIND_NON_ZERO.

GeneralPath.WIND_EVEN_ODD corresponds to WindingRule.WIND_EVEN_ODD.

Ignores an invalid parameter.

Fires property change: SET_WINDING_RULE.

Parameters:
rule - the winding rule as an int

getWindingRule

public final WindingRule getWindingRule()
Get the winding rule.

Returns:
the winding rule

removeShapeData

public final void removeShapeData()

Removes all vertex and tangent data and makes a new path.

Fires property change: REMOVE_SHAPE_DATA.


getPath

public final GeneralPath getPath()

Returns a copy of the GeneralPath that defines this Shape based on the vertex data, tangent data, path strategy, closure mode, and winding rule.

Specifically, calls pathstrategy.makePath using the current path strategy and passing the current vertex data, tangent data, closure mode, and winding rule.


makePath

protected void makePath()

Make the path for the shape using the internal vertex and tangent data and the path strategy, closure mode, and winding rule settings.

May be overridden in a derived class if some settings such as the tangent data must be computed before the path is constructed and set.

To assist in a possible override, we reveal additional detail about the implementation.

BaseShape maintains a private member path of type GeneralPath. The implementation of this method is:

  path = getPath();

An override method should make any necessary changes to the vertex data, tangent data, closure mode, and winding rule, and then call:

  super.makePath();

Normally, an override method will change only the tangent data.

An override method may not directly access the path member variable since it is private.


makeClosedPolygon

public final PolygonShape makeClosedPolygon()
Returns a new closed PolygonShape whose vertex data is a copy of the vertex data of this shape.


makeOpenPolygon

public final PolygonShape makeOpenPolygon()
Returns a new open PolygonShape whose vertex data is a copy of the vertex data of this shape.


makePolygonDots

public final PolygonDotsShape makePolygonDots()
Returns a new PolygonDotsShape whose vertex data is a copy of the vertex data of this shape.


makeClosedBezierFrame

public final PolygonShape makeClosedBezierFrame()
Returns a new closed PolygonShape whose vertex data is the closed Bezier frame corresponding to the vertex and tangent data of this shape and whose winding rule is the same as this shape.


makeOpenBezierFrame

public final PolygonShape makeOpenBezierFrame()
Returns a new open PolygonShape whose vertex data is the open Bezier frame corresponding to the vertex and tangent data of this shape and whose winding rule is the same as this shape.


makeClosedControlDots

public final PolygonDotsShape makeClosedControlDots()
Returns a new PolygonDotsShape whose vertex data is the closed Bezier control point list corresponding to the vertex and tangent data of this shape.


makeOpenControlDots

public final PolygonDotsShape makeOpenControlDots()
Returns a new PolygonDotsShape whose vertex data is the open Bezier control point list corresponding to the vertex and tangent data of this shape.


makeBezierTangentSegments

public final TweakableShape makeBezierTangentSegments()
Returns a new TweakableShape whose vertex and tangent data is a copy of the corresponding vertex and tangent data of this shape, whose Path.Strategy is Path.BEZIER_TANGENT_SEGMENTS, and whose winding rule is the same as this shape.


getClosedBezierFrameData

public final float[][] getClosedBezierFrameData()

Returns the closed Bezier frame data corresponding to the vertex and tangent data.

If N is length of the vertex data then the returned array will have the form float[3*N][2].

If the internal tangent array is null then it is treated as an array of zeroes.

For each index i less than N with j=(i+1)%N, this method places the following three points into successive cells in the result array:

  getVertex(i)
  getControlA(i)
  getControlB(j)

Returns:
the closed Bezier frame data

getOpenBezierFrameData

public final float[][] getOpenBezierFrameData()

Returns the open Bezier frame data corresponding to the vertex and tangent data.

If N is length of the vertex data then the returned array will have the form float[3*N-2][2] if N is positive and float[0][2] if N is zero.

If the internal tangent array is null then it is treated as an array of zeroes.

For each index i less than (N-1) with j=(i+1), this method places the following three points into successive cells in the result array:

  getVertex(i)
  getControlA(i)
  getControlB(j)

The last point placed into the array is:

  getVertex(N-1)

Returns:
the open Bezier frame data

getClosedBezierControlData

public final float[][] getClosedBezierControlData()

Returns the closed Bezier control points corresponding to the vertex and tangent data.

If N is length of the vertex data then the returned array will have the form float[2*N][2].

If the internal tangent array is null then it is treated as an array of zeroes.

For each index i less than N with j=(i+1)%N, this method places the following two points into successive cells in the result array:

  getControlA(i)
  getControlB(j)

Returns:
the closed Bezier control points

getOpenBezierControlData

public final float[][] getOpenBezierControlData()

Returns the open Bezier control points corresponding to the vertex and tangent data.

If N is length of the vertex data then the returned array will have the form float[2*N-2][2] if N is greater than 1 and float[0][2] if N is 0 or 1.

If the internal tangent array is null then it is treated as an array of zeroes.

For each index i less than (N-1) with j=(i+1), this method places the following two points into successive cells in the result array:

  getControlA(i)
  getControlB(j)

Returns:
the open Bezier control points

getBezierTangentSegmentData

public final float[][] getBezierTangentSegmentData()

Returns the Bezier tangent segment data corresponding to the vertex and tangent data.

If N is length of the vertex data then the returned array will have the form float[2*N][2].

If the internal tangent array is null then it is treated as an array of zeroes.

For each index i less than N, this method places the following two points into successive cells in the result array:

  getControlB(i)
  getControlA(i)

Returns:
the Bezier tangent segment data

closedBezierFramePoints

public static float[][] closedBezierFramePoints(float[][] vertex,
                                                float[][] tangent)

Static method that returns a float array that contains the points on the closed Bezier frame for the given vertex and tangent arrays.

Precondition: For some integer N:

If the precondition holds, a new BaseShape is constructed and this method then returns the result of getClosedBezierFrameData on that shape.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the closed Bezier frame points

openBezierFramePoints

public static float[][] openBezierFramePoints(float[][] vertex,
                                              float[][] tangent)

Static method that returns a float array that contains the points on the open Bezier frame for the given vertex and tangent arrays.

Precondition: For some integer N:

If the precondition holds, a new BaseShape is constructed and this method then returns the result of getOpenBezierFrameData on that shape.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the open Bezier frame points

closedBezierControlPoints

public static float[][] closedBezierControlPoints(float[][] vertex,
                                                  float[][] tangent)

Static method that returns a float array that contains the Bezier control points for the closed curve with the given vertex and tangent arrays.

Precondition: For some integer N:

If the precondition holds, a new BaseShape is constructed and this method then returns the result of getClosedBezierControlData on that shape.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the closed Bezier control points

openBezierControlPoints

public static float[][] openBezierControlPoints(float[][] vertex,
                                                float[][] tangent)

Static method that returns a float array that contains the Bezier control points for the open curve with the given vertex and tangent arrays.

Precondition: For some integer N:

If the precondition holds, a new BaseShape is constructed and this method then returns the result of getOpenBezierControlData on that shape.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the open Bezier control points

bezierTangentSegmentPoints

public static float[][] bezierTangentSegmentPoints(float[][] vertex,
                                                   float[][] tangent)

Static method that returns a float array that contains the Bezier tangent segments for the given vertex and tangent arrays.

Precondition: For some integer N:

If the precondition holds, a new BaseShape is constructed and this method then returns the result of getBezierTangentSegmentData on that shape.

If the precondition fails, then float[0][2] is returned.

Parameters:
vertex - the array of vertex information
tangent - the array of tangent information
Returns:
the array with the Bezier tangent segments

contains

public final boolean contains(double x,
                              double y)
Tests if the specified coordinates are inside the boundary of the Shape.

Specified by:
contains in interface Shape
Parameters:
x - the x-coordinate of the position tested
y - the y-coordinate of the position tested

contains

public final boolean contains(Point2D p)
Tests if a specified Point2D is inside the boundary of the Shape.

Specified by:
contains in interface Shape
Parameters:
p - the position tested

contains

public final boolean contains(double x,
                              double y,
                              double w,
                              double h)

Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectangular area to be considered contained within the Shape.

This method might conservatively return false when:

This means that this method might return false even though the Shape contains the rectangular area. The Area class can be used to perform more accurate computations of geometric intersection for any Shape object if a more precise answer is required.

Specified by:
contains in interface Shape
Parameters:
x - the x-coordinate of the rectangle's topleft corner
y - the y-coordinate of the rectangle's topleft corner
w - the rectangle's width
h - the rectangle's height

contains

public final boolean contains(Rectangle2D r)

Tests if the interior of the Shape entirely contains the specified rectangular area. All coordinates that lie inside the rectangular area must lie within the Shape for the entire rectangular area to be considered contained within the Shape.

This method might conservatively return false when:

This means that this method might return false even though the Shape contains the rectangular area. The Area class can be used to perform more accurate computations of geometric intersection for any Shape object if a more precise answer is required.

Specified by:
contains in interface Shape
Parameters:
r - the rectangle

intersects

public final boolean intersects(double x,
                                double y,
                                double w,
                                double h)

Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.

This method might conservatively return true when:

This means that this method might return true even though the rectangular area does not intersect the Shape. The Area class can be used to perform more accurate computations of geometric intersection for any Shape object if a more precise answer is required.

Specified by:
intersects in interface Shape
Parameters:
x - the x-coordinate of the rectangle's topleft corner
y - the y-coordinate of the rectangle's topleft corner
w - the rectangle's width
h - the rectangle's height

intersects

public final boolean intersects(Rectangle2D r)

Tests if the interior of the Shape intersects the interior of a specified rectangular area. The rectangular area is considered to intersect the Shape if any point is contained in both the interior of the Shape and the specified rectangular area.

This method might conservatively return true when:

This means that this method might return true even though the rectangular area does not intersect the Shape. The Area class can be used to perform more accurate computations of geometric intersection for any Shape object if a more precise answer is required.

Specified by:
intersects in interface Shape
Parameters:
r - the rectangle

getBounds

public final Rectangle getBounds()
Returns an integer Rectangle that completely encloses the Shape. Note that there is no guarantee that the returned Rectangle is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle. The returned Rectangle might also fail to completely enclose the Shape if the Shape overflows the limited range of the integer data type. The getBounds2D method generally returns a tighter bounding box due to its greater flexibility in representation.

Specified by:
getBounds in interface Shape

getBounds2D

public final Rectangle2D getBounds2D()
Returns a high precision and more accurate bounding box of the Shape than the getBounds method. Note that there is no guarantee that the returned Rectangle2D is the smallest bounding box that encloses the Shape, only that the Shape lies entirely within the indicated Rectangle2D. The bounding box returned by this method is usually tighter than that returned by the getBounds method and never fails due to overflow problems since the return value can be an instance of the Rectangle2D that uses double precision values to store the dimensions.

Specified by:
getBounds2D in interface Shape

getPathIterator

public final PathIterator getPathIterator(AffineTransform at)

Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.

If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.

Each call to this method returns a fresh PathIterator object that traverses the geometry of the Shape object independently from any other PathIterator objects in use at the same time.

Specified by:
getPathIterator in interface Shape
Parameters:
at - the transform to apply to the path

getPathIterator

public final PathIterator getPathIterator(AffineTransform at,
                                          double flatness)

Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.

Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.

If an optional AffineTransform is specified, the coordinates returned in the iteration are transformed accordingly.

The amount of subdivision of the curved segments is controlled by the flatness parameter, which specifies the maximum distance that any point on the unflattened transformed curve can deviate from the returned flattened path segments. Note that a limit on the accuracy of the flattened path might be silently imposed, causing very small flattening parameters to be treated as larger values. This limit, if there is one, is defined by the particular implementation that is used.

Each call to this method returns a fresh PathIterator object that traverses the Shape object geometry independently from any other PathIterator objects in use at the same time.

Specified by:
getPathIterator in interface Shape
Parameters:
at - the transform to apply to the path
flatness - the flatness to use to simplify the path

getTransformedShape

public final Shape getTransformedShape(AffineTransform at)

Returns a new Shape obtained from this object by using the path iterator corresponding to the given transform.

Parameters:
at - the transform to apply to the path

getTransformedShape

public final Shape getTransformedShape(AffineTransform at,
                                       double flatness)

Returns a new Shape obtained from this object by using the path iterator corresponding to the given transform and flatness.

Parameters:
at - the transform to apply to the path
flatness - the flatness to use to simplify the path

addPropertyChangeListener

public final void addPropertyChangeListener(PropertyChangeListener listener)

Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Specified by:
addPropertyChangeListener in interface SupportsPropertyChange
Parameters:
listener - the PropertyChangeListener to be added

addPropertyChangeListener

public final void addPropertyChangeListener(String propertyName,
                                            PropertyChangeListener listener)

Add a PropertyChangeListener to the listener list for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property.

Specified by:
addPropertyChangeListener in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to listen on
listener - the PropertyChangeListener to be added

addPropertyChangeListeners

public void addPropertyChangeListeners(PropertyChangeListener[] listeners)

Add all items in the given PropertyChangeListener array to the listener list. These items are registered for all properties.

Specified by:
addPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
listeners - the PropertyChangeListener array to be added

addPropertyChangeListeners

public void addPropertyChangeListeners(String propertyName,
                                       PropertyChangeListener[] listeners)

Add all items in the given PropertyChangeListener array to the listener list for a specific property. These items will be invoked only when a call on firePropertyChange names that specific property.

Specified by:
addPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
listeners - the PropertyChangeListener array to be added

removePropertyChangeListener

public final void removePropertyChangeListener(PropertyChangeListener listener)

Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Specified by:
removePropertyChangeListener in interface SupportsPropertyChange
Parameters:
listener - the PropertyChangeListener to be removed

removePropertyChangeListener

public final void removePropertyChangeListener(String propertyName,
                                               PropertyChangeListener listener)

Remove a PropertyChangeListener for a specific property.

Specified by:
removePropertyChangeListener in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property that was listened on
listener - the PropertyChangeListener to be removed

getPropertyChangeListeners

public final PropertyChangeListener[] getPropertyChangeListeners()

Returns an array of all listeners that were added to this object.

Specified by:
getPropertyChangeListeners in interface SupportsPropertyChange
Returns:
an array with all listeners

getPropertyChangeListeners

public final PropertyChangeListener[] getPropertyChangeListeners(String propertyName)

Returns an array of all listeners that were added to this object and associated with the named property.

Specified by:
getPropertyChangeListeners in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to seek
Returns:
an array with all listeners for the given named property

hasListeners

public final boolean hasListeners(String propertyName)

Check if there are any listeners for a specific property.

Specified by:
hasListeners in interface SupportsPropertyChange
Parameters:
propertyName - the name of the property to check
Returns:
whether or not there are any listeners for a specific property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     Object oldValue,
                                     Object newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal and non-null.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     boolean oldValue,
                                     boolean newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     char oldValue,
                                     char newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     byte oldValue,
                                     byte newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     short oldValue,
                                     short newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     int oldValue,
                                     int newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     long oldValue,
                                     long newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     float oldValue,
                                     float newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(String propertyName,
                                     double oldValue,
                                     double newValue)

Report a bound property update to any registered listeners. No event is fired if the old and new values are equal.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
propertyName - the programmatic name of the property that was changed
oldValue - the old value of the property
newValue - the new value of the property

firePropertyChange

public final void firePropertyChange(PropertyChangeEvent evt)

Fire an existing PropertyChangeEvent to any registered listeners. No event is fired if the given event's old and new values are equal and non-null.

Specified by:
firePropertyChange in interface SupportsPropertyChange
Parameters:
evt - the PropertyChangeEvent object

getForwardingListener

public final PropertyChangeForwardingListener getForwardingListener()

Returns the PropertyChangeForwardingListener that will forward the property change events it receives to this object.

Specified by:
getForwardingListener in interface SupportsPropertyChange
Returns:
the forwarding listener

addForwardingListener

public final void addForwardingListener(Object object)
Add the forwarding listener as a property change listener for the given object if the object supports property change.

Specified by:
addForwardingListener in interface SupportsPropertyChange
Parameters:
object - the object that should add the forwarding listener

removeForwardingListener

public final void removeForwardingListener(Object object)
Remove the forwarding listener as a property change listener for the given object if the object supports property change.

Specified by:
removeForwardingListener in interface SupportsPropertyChange
Parameters:
object - the object that should remove the forwarding listener

removeAndAddForwardingListener

public final void removeAndAddForwardingListener(Object oldobject,
                                                 Object newobject)
Remove the forwarding listener as a property change listener for the old object if the old object supports property change and add the forwarding listener as a property change listener for the new object if the new object supports property change.

Specified by:
removeAndAddForwardingListener in interface SupportsPropertyChange
Parameters:
oldobject - the old object that should remove the forwarding listener
newobject - the new object that should add the forwarding listener