public abstract class AbstractCurve extends DefaultLeafElement implements ActionFactory
There are two sort of points in this curve:
pts
ArrayList inherited from
DefaultLeafElement, which (according to the contract in the
latter class) store specification points, contain the coordinates
of all Bezier points with the following indexing scheme :
Arrays of specification-point coordinates are managed differently if the curve is open or close :
Modifier and Type | Field and Description |
---|---|
static int |
FIRST_CURVE_END_POINT
constant field for getPointType()
|
static int |
FIRST_SEGMENT_CONTROL_POINT
constant field for getPointType()
|
static int |
INVALID_POINT_INDEX
constant field for getPointType()
|
protected boolean |
isClosed
tells whether this curve is closed of not
|
static int |
LAST_CURVE_END_POINT
constant field for getPointType()
|
static int |
SECOND_SEGMENT_CONTROL_POINT
constant field for getPointType()
|
static int |
SUBDIVISION_POINT
constant field for getPointType()
|
nodeConnections, nodeName, pts
attributeSet, parent, view
ARROW_GLOBAL_SCALE_LENGTH, ARROW_GLOBAL_SCALE_WIDTH, ARROW_INSET_SCALE, ARROW_LENGTH_SCALE, ARROW_WIDTH_LINEWIDTH_SCALE, ARROW_WIDTH_MINIMUM_MM, BRACKET_LENGTH_SCALE, CROSSHATCH, CROSSHATCH_FILLED, DASH_OPAQUE, DASH_TRANSPARENT, DASH1, DASH2, DASH3, DASHED, DIMEN, DOT_SEP, DOT_SEP1, DOT_SEP2, DOT_SEP3, DOTTED, DOUBLE_COLOR, DOUBLE_LINE, DOUBLE_SEP, FILL_COLOR, FILL_STYLE, HATCH_ANGLE, HATCH_COLOR, HATCH_SEP, HATCH_WIDTH, HLINES, HLINES_FILLED, INNER, LEFT_ARROW, LINE_COLOR, LINE_STYLE, LINE_WIDTH, MIDDLE, NONE, OUTER, OVER_STRIKE, OVER_STRIKE_COLOR, OVER_STRIKE_WIDTH, POLYDOTS_ANGLE, POLYDOTS_CIRCLE, POLYDOTS_DISK, POLYDOTS_PENTAGON, POLYDOTS_PENTAGON_FILLED, POLYDOTS_PLUS, POLYDOTS_SCALE_H, POLYDOTS_SCALE_V, POLYDOTS_SIZE_LINEWIDTH_SCALE, POLYDOTS_SIZE_MINIMUM_MM, POLYDOTS_SQUARE, POLYDOTS_SQUARE_FILLED, POLYDOTS_STYLE, POLYDOTS_SUPERIMPOSE, POLYDOTS_TRIANGLE, POLYDOTS_TRIANGLE_FILLED, PS_POINT, PST_CUSTOM, RBRACKET_LENGTH_SCALE, RIGHT_ARROW, SHADOW, SHADOW_ANGLE, SHADOW_COLOR, SHADOW_SIZE, SOLID, TBAR_WIDTH_LINEWIDTH_SCALE, TBAR_WIDTH_MINIMUM_MM, TEXT_BOX_CIRCLE, TEXT_BOX_NO_FRAME, TEXT_BOX_OVAL, TEXT_BOX_RECTANGLE, TEXT_FRAME, TEXT_HALIGN_CENTER, TEXT_HALIGN_LEFT, TEXT_HALIGN_RIGHT, TEXT_HOR_ALIGN, TEXT_ROTATION, TEXT_VALIGN_BASELINE, TEXT_VALIGN_BOTTOM, TEXT_VALIGN_CENTER, TEXT_VALIGN_TOP, TEXT_VERT_ALIGN, VLINES, VLINES_FILLED
Constructor and Description |
---|
AbstractCurve()
Creates a new empty open Abstract curve
|
AbstractCurve(AbstractCurve curve)
"cloning" constructor (to be used by clone())
|
AbstractCurve(boolean closed)
Creates a new empty Abstract curve
|
AbstractCurve(boolean closed,
PicAttributeSet set)
Creates a new empty Abstract curve with the given set of attributes
|
AbstractCurve(int nbSegments,
boolean closed)
Creates a new Abstract curve and allocates as many points as needed by
the given number of segments.
|
AbstractCurve(int nbSegments,
boolean closed,
PicAttributeSet set)
Creates a new Abstract curve with the given number of segments, and attaches the given attribute set to it.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
addPoint(PicPoint pt)
Adds the given point to the end of this curve.
|
PEAction[] |
createActions(ActionDispatcher actionDispatcher,
ActionLocalizer localizer,
HitInfo hi)
Creates an array of Action's related to this object
|
AbstractCustomizer |
createCustomizer()
Returns a Customizer for geometry editing
|
void |
curveTo(PicPoint ptCtrl1,
PicPoint ptCtrl2,
PicPoint ptEnd)
If this curve if OPEN and NON-EMPTY,
adds the given points (2 control points and an endpoint) to the end of the curve.
If the curve is closed, use splitSegment instead. |
int |
getAlternateControlPoint(int controlPtIdx)
Returns the bezier-index of the alternate control-point of the given control-point.
|
PicVector |
getIncomingTangent(int subdivIndex)
Return a non-normalized vector tangent to the incoming segment (i.e., wrt the control-point that comes before the given subdivision point)
|
int |
getNearestSubdivisionPoint(int controlPtIdx)
Returns the bezier-index of the nearest subdivision-point of the given control-point.
|
int |
getNumberOfSegments()
Returns the number of segments that make up this curve.
|
int |
getNumberOfSubdivisionPoints()
Returns the number of subdivision points (including endpoints if the curve is open)
|
PicVector |
getOutgoingTangent(int subdivIndex)
Return a non-normalized vector tangent to the outcoming segment (i.e., wrt the control-point that comes after the given subdivision point)
|
int |
getPBCBezierIndex(int bezierPtIdx)
Convenience method for Periodic Boundary Condition (PBC) management when curve is CLOSED.
|
int |
getPBCSegmentIndex(int segmentIdx)
Convenience method for Periodic Boundary Condition (PBC) management when curve is CLOSED.
|
int |
getPointType(int index)
Returns whether the given point index relates to a curve's end-point,
a subdivision point, a control point (in which case
this method returns the rank of the control point inside the segment to which it belongs), or (if the curve
is open) is an invalid point index.
Note that if this curve is CLOSED, this method never returns FIRST_CURVE_END_POINT nor LAST_CURVE_END_POINT for that matter. |
java.awt.geom.Rectangle2D |
getShapeBounds2D(java.awt.geom.Rectangle2D r)
Returns the the smallest rectangle enclosing the shape of this curve, as
opposed to
getBoundingBox
which is defined as the smallest rectangle encompassing ALL
specification points. |
protected PicPoint |
getSpecificationPoint(int index)
Returns a reference on the specification point with the given index.
|
protected boolean |
hasValidSize()
Return whether the current nb of specification points is valid, i.e.
|
boolean |
isClosed()
Returns true if this curve is closed.
|
boolean |
isControlPoint(int index)
Return whether the bezier-point with the given index is a control-point.
|
boolean |
isPolygon()
Return true if this curve is a polygon, ie has only straight segments
|
boolean |
isSmooth(int subdivIndex)
Check whether the two control points around the given subdivision point satisfy (up to 5%)
the 2nd order smoothness criterion.
|
boolean |
isStraight(int segIndex)
Returns whether the given segment is straight.
|
boolean |
isSymmetric(int subdivIndex)
Check whether the control points around the given subdivision point satisfy (up to 5%) the
symmetry criterion.
|
boolean |
isValidBezierIndex(int pointIndex)
Returns true iff the given bezier point index is a valid point index.
|
boolean |
isValidSegmentIndex(int segIdx)
Returns true iff the given segment index is a valid segment index.
|
void |
lineTo(PicPoint pt)
Adds a STRAIGHT segment to the end of this curve, i.e.
|
int |
pointToSegmentIndex(int pointIndex)
Returns the index of the segment the given point belongs to.
|
void |
removeLastSubdivisionPoint()
Removes the last subdivision point.
|
abstract void |
removePoint(int index)
Remove the point with the given index from this curve
|
void |
removeSubdivisionPoint(int subdivIndex)
Remove a subdivision point from this curve, together with the two neighbouring control points.
|
int |
segmentToPointIndex(int segmentIndex,
int pointType)
Returns the index of the bezier-point belonging to the given segment, and having the given
pointType.
|
void |
setClosed(boolean state)
close or open this curve, either by opening the last segment if curve is closed,
or by adding two control-points after the last segment if it is open.
This methods doesn't fire any DrawingEvent. |
void |
setPoint(int index,
PicPoint pt,
EditPointConstraint c)
Set the coordinates of the Bezier point with the given index to the given location,
but doesn't fire any DrawingEvent.
|
abstract int |
splitSegment(int index,
PicPoint pt)
Split the segment having the given index.
|
int |
splitSegment(int seg,
PicPoint ptleft,
PicPoint pt,
PicPoint ptright)
Split a segment (either straight or curved) at a given point using two additionnal control points given
as parameters.
|
java.lang.String |
toString()
Returns a string for debugging purpose.
|
addConnection, clone, fireChangedUpdate, forwardChangedUpdate, getAllowsChildren, getBoundingBox, getFirstPointIndex, getLastPointIndex, getName, getNodeName, getNumberOfSpecificationPoints, getPoint, getPoint, getPointX, getPointY, getSpecificationPoint, getSpecificationPointX, getSpecificationPointY, isNode, isNodeable, iterator, nodeConnectionOrigin, nodeReferencePoint, nodeReferencePointX, nodeReferencePointY, removeAllConnections, removeConnection, rotate, scale, setNodeName, setPoint, setSpecificationPoint, shear, translate
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
public static final int INVALID_POINT_INDEX
public static final int FIRST_CURVE_END_POINT
public static final int SUBDIVISION_POINT
public static final int FIRST_SEGMENT_CONTROL_POINT
public static final int SECOND_SEGMENT_CONTROL_POINT
public static final int LAST_CURVE_END_POINT
protected boolean isClosed
public AbstractCurve()
public AbstractCurve(boolean closed)
closed
- whether the generated multi-curve will be closed or notpublic AbstractCurve(boolean closed, PicAttributeSet set)
closed
- whether the generated multi-curve will be closed or notset
- attribute set to be bound to this curvepublic AbstractCurve(int nbSegments, boolean closed)
nbSegments
- nb of elementary lines or cubic Bezier curves ; if 0, this curve is reduced to a single pointclosed
- whether this curve is closed or notjava.lang.IllegalArgumentException
- if nbSegments is negativepublic AbstractCurve(int nbSegments, boolean closed, PicAttributeSet set)
nbSegments
- nb of elementary lines or cubic Bezier curvesset
- attribute set to be bound to this elementpublic AbstractCurve(AbstractCurve curve)
public int getPointType(int index)
public int getPBCBezierIndex(int bezierPtIdx)
If curve is CLOSED, returns the given index modulo the number of bezier points, i.e. an index
guaranteed to lie b/w 0 and the number of bezier points minus one.
Otherwise leaves unchanged.
bezierPtIdx
- any integer, positive or not, greater than the number of bezier points or not, etc...public int getPBCSegmentIndex(int segmentIdx)
If curve is CLOSED, returns the given index modulo the number of segment, i.e. an index
guaranteed to lie b/w 0 and the number of segments minus one.
Otherwise leaves unchanged.
segmentIdx
- any integer, positive or not, greater than the number of bezier points or not, etc...public int getNearestSubdivisionPoint(int controlPtIdx)
public int getAlternateControlPoint(int controlPtIdx)
public boolean isControlPoint(int index)
public int pointToSegmentIndex(int pointIndex)
public int segmentToPointIndex(int segmentIndex, int pointType)
pointType
- one of SUBDIVISION_POINT, FIRST_SEGMENT_CONTROL_POINT or SECOND_SEGMENT_CONTROL_POINT.
Other qualifiers are meaningless here, and act as the SUBDIVISION_POINT qualifier.public boolean isValidBezierIndex(int pointIndex)
getPointType(int)
public boolean isValidSegmentIndex(int segIdx)
protected final boolean hasValidSize()
protected PicPoint getSpecificationPoint(int index)
getSpecificationPoint
in class DefaultLeafElement
public void setPoint(int index, PicPoint pt, EditPointConstraint c)
setPoint
in interface Element
setPoint
in class DefaultLeafElement
c
- not used herepublic abstract void addPoint(PicPoint pt)
public abstract int splitSegment(int index, PicPoint pt)
public abstract void removePoint(int index)
public void curveTo(PicPoint ptCtrl1, PicPoint ptCtrl2, PicPoint ptEnd)
splitSegment
instead.ptCtrl1
- first control point of the new Bezier segmentptCtrl2
- second control point of the new Bezier segmentptEnd
- second end-point of the new Bezier segmentpublic void lineTo(PicPoint pt)
curveTo
.
Note that this method does NOT fire any DrawingEvent.
This method does nothing if the curve is EMPTY or CLOSED.
pt
- The second end-point of the line to be addedpublic int splitSegment(int seg, PicPoint ptleft, PicPoint pt, PicPoint ptright)
Implementation works as follow : parameters ptLeft and ptRight act as new control points, the original segment - labelled as [a,b,c,d] - being split up into two new segments, i.e. [a,b,ptleft,pt] and [pt,ptright,c,d]. These two segments inherit their straightness attribute from the original segment. This works for closed as well as open curves.
Note that this method does NOT fire any DrawingEvent.
seg
- index of segment to be split, i.e. 0,1,2,... for the 1st, 2nd, 3rd,... segment.ptleft
- first new control-pointpt
- the point at which segment must be split (= new subdivision point)ptright
- second new control-pointpublic void removeSubdivisionPoint(int subdivIndex)
This method does NOT fire any DrawingEvent.
index
- index of the subdivision point to be removed with respect to SUBDIVISION point numbering scheme,
e.g. 0 for the first subdivision point (= first curve end-point), 1 for the second one (= bezier point
with index "3"), etc... This is similar to the SEGMENT numbering scheme incidentally.an
- IllegalArgumentException if the given index is not a valid subdivision point index, i.e.
is greater than the nb of segments.public void removeLastSubdivisionPoint()
removeSubdivisionPoint
.public int getNumberOfSegments()
public int getNumberOfSubdivisionPoints()
public PicVector getIncomingTangent(int subdivIndex)
public PicVector getOutgoingTangent(int subdivIndex)
public boolean isStraight(int segIndex)
segIndex
- segment index with respect to the segment numbering scheme, that is, 0 for the first segment, etc...public boolean isPolygon()
public boolean isSmooth(int subdivIndex)
subdivIndex
relates
to a curve's end-point, return true. If one of the neighbouring segment is straight, end-points are
used instead of control-points.subdivIndex
- subdivision-point index, with respect to subdivision-point (SP) numbering scheme, i.e.
0,1,2,... for the 1st, 2nd, 3rd... subdivision point.public boolean isSymmetric(int subdivIndex)
subdivIndex
- subdivision-point index (with respect to subdivision-point numbering scheme), that is,
0,1,2,... for the 1st, 2nd, 3rd,... subdivision point.public void setClosed(boolean state)
state
- The new closeness valuepublic boolean isClosed()
public java.awt.geom.Rectangle2D getShapeBounds2D(java.awt.geom.Rectangle2D r)
getBoundingBox
which is defined as the smallest rectangle encompassing ALL
specification points.r
- if null, gets allocated and returned for conveniencejava.awt.Shape.getBounds2D()
public java.lang.String toString()
toString
in class DefaultLeafElement
public PEAction[] createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
createActions
in interface ActionFactory
actionDispatcher
- dispatches events to the proper PECanvaslocalizer
- i18n localizer for PEAction'shi
- a HitInfo containing information related to the mouse-event which triggered the popup menu.public AbstractCustomizer createCustomizer()
Submit a bug : syd@jpicedt.org