Class PicSmoothPolygon
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.DefaultLeafElement
-
- jpicedt.graphic.model.AbstractCurve
-
- jpicedt.graphic.model.PicSmoothPolygon
-
- All Implemented Interfaces:
Element,PicMultiCurveConvertable,PicObjectConstants,ActionFactory,CustomizerFactory
public class PicSmoothPolygon extends AbstractCurve implements ActionFactory, CustomizerFactory, PicMultiCurveConvertable
A multicurve, either close or not, whose geometry is specified using a polygon, in such a way that the curve snakes "smoothly" along the polygon. For each polygon point, a coefficient helps altering the smoothness of the the path. Like the class it inherits from, this element has a variable number of user-controlled points that can be added/inserted/deleted by the user.
Each polygon point is also an anchor point (e.g. for grid alignment).Implementation notes : inherited
ptsArrayList acts as an array of specification points for the multicurve (this behaviour being mostly inherited from superclass). Besides, there's an ArrayList of PicPoint's, namelypolygonPts, which backs the geometry of the polygon, and acts as a list of user-controlled points. Moving a control-point thus updates specification points as appropriate. [SR:todo:11/01/2003] add documentation about curve equation.- Since:
- jpicedt 1.3.3
- Version:
- $Id: PicSmoothPolygon.java,v 1.18.2.1 2007/09/02 11:56:27 reynal Exp $
- Author:
- Vincent Guirardel
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCOEF_SLIDER_MAXMax value of smoothness coefficient accessible to Jslider in the geometry editorprotected static intCOEF_SLIDER_MINMin value of smoothness coefficient accessible to JSlider in the geometry editorprotected static doubleDEFAULT_SMOOTH_COEFFthe default value for the smoothness coefficient on startup.protected java.util.ArrayListpolygonPtsAn array of PicPoint's backing the geometry of the polygon.protected java.util.ArrayListsmoothCoeffThe following array contains one Double per polygon point, specifying how close to polygon points the curve should go along.-
Fields inherited from class jpicedt.graphic.model.AbstractCurve
FIRST_CURVE_END_POINT, FIRST_SEGMENT_CONTROL_POINT, INVALID_POINT_INDEX, isClosed, LAST_CURVE_END_POINT, SECOND_SEGMENT_CONTROL_POINT, SUBDIVISION_POINT
-
Fields inherited from class jpicedt.graphic.model.DefaultLeafElement
nodeConnections, nodeName, pts
-
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, parent, view
-
Fields inherited from interface jpicedt.graphic.model.PicObjectConstants
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 Summary
Constructors Constructor Description PicSmoothPolygon()Create a new empty open smooth polygon, with a default attribute set.PicSmoothPolygon(boolean closed)Create a new empty smooth polygon, open or closed, with a default attribute set bound to it.PicSmoothPolygon(boolean closed, PicAttributeSet set)Create a new empty smooth polygon with the given attribute set.PicSmoothPolygon(PicSmoothPolygon poly)"cloning" constructor (to be used by clone())PicSmoothPolygon(PicPoint[] polygonPts, boolean closed, double[] smoothCoeffs, PicAttributeSet set)Create a new smooth polygon initialized from the given array of PicPoint's, using the given array of smoothness values.PicSmoothPolygon(PicPoint[] polyPts, boolean closed, double smoothCoeff, PicAttributeSet set)Create a new smooth polygon initialized from the given array of PicPoint's.PicSmoothPolygon(PicPoint[] polygonPts, boolean closed, PicAttributeSet set)Create a new smooth polygon initialized from the given array of PicPoint's, using the default smoothness value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPoint(int ptIndex, PicPoint pt)Adds the given polygon point at the given position, shifting ensuing point indices to the right.voidaddPoint(int ptIndex, PicPoint pt, double smoothCoeff)Adds the given polygon point at the given position, shifting ensuing point indices to the right.voidaddPoint(PicPoint pt)adds the given point at the end of this PicSmoothPolygon.voidaddPoint(PicPoint pt, double smoothCoeff)adds the given point with the given smoothness-coefficient at the end of this PicSmoothPolygon.java.lang.Objectclone()Overide Object.clone() methodPicMultiCurveconvertToMultiCurve()converts this PicSmoothPolygon to a PicMultiCurve, by simply relying on the appropriate constructor in classPicMultiCurve.PEAction[]createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)Create an array of Action's related to this objectAbstractCustomizercreateCustomizer()Returns a Customizer for geometry editingjava.awt.geom.Rectangle2DgetBoundingBox(java.awt.geom.Rectangle2D r)Returns the bounding box (ie the surrounding rectangle) in double precision This implementation compute the bb from the union of : the bb as computed by super-class and the smallest rectangle that encompasses all the polygon-points.intgetFirstPointIndex()Returns the index of the first user-controlled point that can be retrieved bygetPoint().intgetLastPointIndex()Returns the index of the last user-controlled point that can be retrieved bygetPoint().java.lang.StringgetName()Returns a non-localised string representing this object's name This default implementation returns the class name.PicPointgetPoint(int numPoint, PicPoint src)Return the user-controlled point (ie a polygon point, not a bezier point) having the given index.doublegetPointX(int index)This implementation returns the X-coord of the polygon-point with the same index.doublegetPointY(int index)This implementation returns the Y-coord of the polygon-point with the same index.protected PicPointgetPolygonPoint(int numPoint)Return a reference on the polygon point with the given index.doublegetSmoothCoefficient(int index)voidremoveLastPoint()removes the last point of this PicSmoothPolygon.voidremovePoint(int pos)Remove a point at the given position from this PicSmoothPolygon, then fire a changed-update.voidrotate(PicPoint ptOrg, double angle)Rotate this Element by the given angle along the given pointvoidscale(double ptOrgX, double ptOrgY, double sx, double sy)Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin.voidsetClosed(boolean state)set close path state, then fires a changed-update.voidsetPoint(int index, PicPoint pt, EditPointConstraint constraint)Set the user-controlled point with the given index to the given value.voidsetSmoothCoefficient(int index, double c)voidshear(PicPoint ptOrg, double shx, double shy)Shear this Element by the given params wrt to the given originintsplitSegment(int segIdx, PicPoint pt)Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position.intsplitSegment(int segIdx, PicPoint pt, double smoothCoeff)Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position.java.lang.StringtoString()Used for debugging purpose.voidtranslate(double dx, double dy)Translate this Element by (dx,dy) ; this implementation translates the specification-points, then fires a changed-update event.-
Methods inherited from class jpicedt.graphic.model.AbstractCurve
curveTo, getAlternateControlPoint, getIncomingTangent, getNearestSubdivisionPoint, getNumberOfSegments, getNumberOfSubdivisionPoints, getOutgoingTangent, getPBCBezierIndex, getPBCSegmentIndex, getPointType, getShapeBounds2D, getSpecificationPoint, hasValidSize, isClosed, isControlPoint, isPolygon, isSmooth, isStraight, isSymmetric, isValidBezierIndex, isValidSegmentIndex, lineTo, pointToSegmentIndex, removeLastSubdivisionPoint, removeSubdivisionPoint, segmentToPointIndex, splitSegment
-
Methods inherited from class jpicedt.graphic.model.DefaultLeafElement
addConnection, fireChangedUpdate, forwardChangedUpdate, getAllowsChildren, getNodeName, getNumberOfSpecificationPoints, getPoint, getSpecificationPoint, getSpecificationPointX, getSpecificationPointY, isNode, isNodeable, iterator, nodeConnectionOrigin, nodeReferencePoint, nodeReferencePointX, nodeReferencePointY, removeAllConnections, removeConnection, setNodeName, setPoint, setSpecificationPoint
-
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
-
-
-
-
Field Detail
-
polygonPts
protected java.util.ArrayList polygonPts
An array of PicPoint's backing the geometry of the polygon. Aka caching mechanism holding a list of user-controlled points.
-
smoothCoeff
protected java.util.ArrayList smoothCoeff
The following array contains one Double per polygon point, specifying how close to polygon points the curve should go along.
-
DEFAULT_SMOOTH_COEFF
protected static double DEFAULT_SMOOTH_COEFF
the default value for the smoothness coefficient on startup. [SR:pending] fetch from a Properties object in constructor
-
COEF_SLIDER_MIN
protected static int COEF_SLIDER_MIN
Min value of smoothness coefficient accessible to JSlider in the geometry editor
-
COEF_SLIDER_MAX
protected static int COEF_SLIDER_MAX
Max value of smoothness coefficient accessible to Jslider in the geometry editor
-
-
Constructor Detail
-
PicSmoothPolygon
public PicSmoothPolygon()
Create a new empty open smooth polygon, with a default attribute set.
-
PicSmoothPolygon
public PicSmoothPolygon(boolean closed)
Create a new empty smooth polygon, open or closed, with a default attribute set bound to it.- Parameters:
closed- whether the generated multi-curve will be closed or not
-
PicSmoothPolygon
public PicSmoothPolygon(boolean closed, PicAttributeSet set)Create a new empty smooth polygon with the given attribute set.- Parameters:
set- attribute set to be bound to this elementclosed- whether the generated multi-curve will be closed or not
-
PicSmoothPolygon
public PicSmoothPolygon(PicPoint[] polyPts, boolean closed, double smoothCoeff, PicAttributeSet set)
Create a new smooth polygon initialized from the given array of PicPoint's.- Parameters:
polyPts- array of PicPoint's specifying the polygon geometry.set- attribute set to be bound to this elementclosed- whether the generated multi-curve will be closed or notsmoothCoeff- the default smoothness value for each polygon point- Since:
- PicEdt 1.3.3
-
PicSmoothPolygon
public PicSmoothPolygon(PicPoint[] polygonPts, boolean closed, double[] smoothCoeffs, PicAttributeSet set)
Create a new smooth polygon initialized from the given array of PicPoint's, using the given array of smoothness values. If array sizes do not match, number of polygon points gets trimmed to the smaller of both.- Parameters:
polygonPts- array of PicPoint's specifying the polygon geometry.set- attribute set to be bound to this elementclosed- whether the generated multi-curve will be closed or notsmoothCoeff- array of smoothness values for each polygon point- Since:
- PicEdt 1.3.3
-
PicSmoothPolygon
public PicSmoothPolygon(PicPoint[] polygonPts, boolean closed, PicAttributeSet set)
Create a new smooth polygon initialized from the given array of PicPoint's, using the default smoothness value.- Parameters:
polygonPts- array of PicPoint's specifying the polygon geometry.set- attribute set to be bound to this elementclosed- whether the generated multi-curve will be closed or not- Since:
- PicEdt 1.3.3
-
PicSmoothPolygon
public PicSmoothPolygon(PicSmoothPolygon poly)
"cloning" constructor (to be used by clone())- Parameters:
poly- PicSmoothPolygon to be cloned- Since:
- jpicedt 1.3.3
-
-
Method Detail
-
clone
public java.lang.Object clone()
Overide Object.clone() method- Specified by:
clonein interfaceElement- Overrides:
clonein classDefaultLeafElement- Returns:
- Description of the Return Value
- Since:
- PicEdt 1.1
-
getName
public java.lang.String getName()
Description copied from class:DefaultLeafElementReturns a non-localised string representing this object's name This default implementation returns the class name.- Specified by:
getNamein interfaceElement- Overrides:
getNamein classDefaultLeafElement- Returns:
- a localised string that represents this object's name
-
getFirstPointIndex
public int getFirstPointIndex()
Returns the index of the first user-controlled point that can be retrieved bygetPoint(). This implementation returns 0.- Specified by:
getFirstPointIndexin interfaceElement- Overrides:
getFirstPointIndexin classDefaultLeafElement
-
getLastPointIndex
public int getLastPointIndex()
Returns the index of the last user-controlled point that can be retrieved bygetPoint(). This default implementation returns the number of polygon-points minus one.- Specified by:
getLastPointIndexin interfaceElement- Overrides:
getLastPointIndexin classDefaultLeafElement
-
getPoint
public PicPoint getPoint(int numPoint, PicPoint src)
Return the user-controlled point (ie a polygon point, not a bezier point) having the given index. The general contract in Element is to return an IMMUTABLE instance of PicPoint, so that the only way to alter the geometry of this element is by calling thesetPointmethod.
Overriden so as to return a "polygon" point instead of a bezier-point (which act as specification-point here).- Specified by:
getPointin interfaceElement- Overrides:
getPointin classDefaultLeafElement- Parameters:
numPoint- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the point indexed by
numPoint; ifsrcis null, allocates a new PicPoint and return it, otherwise directly modifiessrcand returns it as well for convenience.
-
getPolygonPoint
protected final PicPoint getPolygonPoint(int numPoint)
Return a reference on the polygon point with the given index. This is equivalent to calling getPoint(int,PicPoint), except that a mere reference is returned.
-
getPointX
public double getPointX(int index)
This implementation returns the X-coord of the polygon-point with the same index.- Specified by:
getPointXin interfaceElement- Overrides:
getPointXin classDefaultLeafElement- Parameters:
index- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the X-coord of the point indexed by
index. - Since:
- jpicedt 1.3.3
-
getPointY
public double getPointY(int index)
This implementation returns the Y-coord of the polygon-point with the same index.- Specified by:
getPointYin interfaceElement- Overrides:
getPointYin classDefaultLeafElement- Parameters:
index- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the Y-coord of the point indexed by
index. - Since:
- jpicedt 1.3.3
-
translate
public void translate(double dx, double dy)Translate this Element by (dx,dy) ; this implementation translates the specification-points, then fires a changed-update event.- Specified by:
translatein interfaceElement- Overrides:
translatein classDefaultLeafElement- Parameters:
dx- The X coordinate of translation vectordy- The Y coordinate of translation vector- Since:
- PicEdt 1.0
-
scale
public void scale(double ptOrgX, double ptOrgY, double sx, double sy)Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin. This implementation simply apply a scaling transform to all specification-points. Note thatsxandsymay be negative. This method eventually fires a changed-update event.- Specified by:
scalein interfaceElement- Overrides:
scalein classDefaultLeafElement
-
rotate
public void rotate(PicPoint ptOrg, double angle)
Rotate this Element by the given angle along the given point- Specified by:
rotatein interfaceElement- Overrides:
rotatein classDefaultLeafElement- Parameters:
angle- rotation angle in radians
-
shear
public void shear(PicPoint ptOrg, double shx, double shy)
Shear this Element by the given params wrt to the given origin- Specified by:
shearin interfaceElement- Overrides:
shearin classDefaultLeafElement
-
setPoint
public void setPoint(int index, PicPoint pt, EditPointConstraint constraint)Set the user-controlled point with the given index to the given value. This implementation sets the value of the polygon-point having the same index, then update the associated Bezier curve, and fires a changed-update event.- Specified by:
setPointin interfaceElement- Overrides:
setPointin classAbstractCurve- Parameters:
constraint- not used so far
-
addPoint
public void addPoint(PicPoint pt)
adds the given point at the end of this PicSmoothPolygon.- Specified by:
addPointin classAbstractCurve
-
addPoint
public void addPoint(PicPoint pt, double smoothCoeff)
adds the given point with the given smoothness-coefficient at the end of this PicSmoothPolygon.
-
addPoint
public void addPoint(int ptIndex, PicPoint pt)Adds the given polygon point at the given position, shifting ensuing point indices to the right. For instance, adding at point at position "1" is equivalent to splitting segment "0".
-
addPoint
public void addPoint(int ptIndex, PicPoint pt, double smoothCoeff)Adds the given polygon point at the given position, shifting ensuing point indices to the right. For instance, adding at point at position "1" is equivalent to splitting segment "0".
-
splitSegment
public int splitSegment(int segIdx, PicPoint pt)Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position. then fires a changed-update. For instance, spliting segment "2" yields the following polygon points : 0, 1, 2, insertion pt, 3, 4, etc...- Specified by:
splitSegmentin classAbstractCurve- Parameters:
segIdx- index of the polygon segment that must be split.pt- the PicPoint to be added- Returns:
- the index of the user-controlled point which got inserted, according to the indexing scheme of set/getPoint(). This may for instance allow a receiver to control the "new" segment shape by calling setPoint() with this index as a parameter w/o the burden of computing an exact point index (a thing that may depend on the particular implementation of this method).
-
splitSegment
public int splitSegment(int segIdx, PicPoint pt, double smoothCoeff)Split the given polygon segment (starting from 0), by inserting a new polygon point at the appropriate position. then fires a changed-update. For instance, spliting segment "2" yields the following polygon points : 0, 1, 2, insertion pt, 3, 4, etc...- Parameters:
segIdx- index of the polygon segment that must be split.smoothCoeff- the smoothness coefficient to be used for the new polygon point.pt- the PicPoint to be added
-
removePoint
public void removePoint(int pos)
Remove a point at the given position from this PicSmoothPolygon, then fire a changed-update. This shifts any subsequent points to the left.Nothing is done if this polygon has only one point.
- Specified by:
removePointin classAbstractCurve- Parameters:
pos- index of point to be removed
-
removeLastPoint
public void removeLastPoint()
removes the last point of this PicSmoothPolygon. This is a convenience call toremovePoint(polygonPts.size()-1)
-
convertToMultiCurve
public PicMultiCurve convertToMultiCurve()
converts this PicSmoothPolygon to a PicMultiCurve, by simply relying on the appropriate constructor in classPicMultiCurve.- Specified by:
convertToMultiCurvein interfacePicMultiCurveConvertable
-
getSmoothCoefficient
public double getSmoothCoefficient(int index)
- Parameters:
index- Description of the Parameter- Returns:
- smoothness smoothCoeff of the given control point
-
setSmoothCoefficient
public void setSmoothCoefficient(int index, double c)- Parameters:
index- index of point whose smoothCoeff is to be adjustedc- value of the smoothCoeff
-
setClosed
public void setClosed(boolean state)
set close path state, then fires a changed-update.- Overrides:
setClosedin classAbstractCurve- Parameters:
state- The new closed value
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Returns the bounding box (ie the surrounding rectangle) in double precision This implementation compute the bb from the union of :- the bb as computed by super-class
- and the smallest rectangle that encompasses all the polygon-points.
- Specified by:
getBoundingBoxin interfaceElement- Overrides:
getBoundingBoxin classDefaultLeafElement- Returns:
- the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command. If r is null, allocate a new rectangle and returns it. Otherwise the source rectangle is modified and returned for convenience. [todo:reynal] this really need to be improved : this method would probably better be moved to the attached view, since the latter knows exactly what the TRUE bounding box is.
- Since:
- jpicedt 1.3.3
-
toString
public java.lang.String toString()
Used for debugging purpose.- Overrides:
toStringin classAbstractCurve
-
createActions
public PEAction[] createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
Create an array of Action's related to this object- Specified by:
createActionsin interfaceActionFactory- Overrides:
createActionsin classAbstractCurve- Parameters:
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.
-
createCustomizer
public AbstractCustomizer createCustomizer()
Description copied from class:AbstractCurveReturns a Customizer for geometry editing- Specified by:
createCustomizerin interfaceCustomizerFactory- Overrides:
createCustomizerin classAbstractCurve- Returns:
- a Customizer for geometry editing
-
-