Class PicParallelogram
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.DefaultLeafElement
-
- jpicedt.graphic.model.PicParallelogram
-
- All Implemented Interfaces:
Element,PicMultiCurveConvertable,PicObjectConstants,ActionFactory,CustomizerFactory
- Direct Known Subclasses:
PicEllipse
public class PicParallelogram extends DefaultLeafElement implements CustomizerFactory, ActionFactory, PicMultiCurveConvertable
A class implementing a parallelogram. Geometry is fully specified by three corner points (namely, the bottom-left, bottom-right and top-right corners), which thus act as specification-points (see DefaultLeafElement for details), and can be retrieved usinggetSpecificationPointX/Y. These are obviously stored in theptsArrayList, as defined in DefaultLeafElement.[SR:TODO] add rounded-corners feature.
- Since:
- jPicEdt 1.4
- Version:
- $Id: PicParallelogram.java,v 1.28.2.1 2007/09/02 11:56:27 reynal Exp $
- Author:
- Vincent Guirardel.
-
-
Field Summary
Fields Modifier and Type Field Description protected PicVectorb2tVecsee documentation forl2rVecstatic BasicEditPointConstraintCENTER_FIXEDpredefined constraint for setPoint()static BasicEditPointConstraintDEFAULTpredefined constraint for setPoint()static intFIRST_PTIndex of first control-pointprotected PicVectorl2rVec"l2rVec" is a vector pointing from P_BL to P_BR (or equally, from P_TL to P_TR) "b2tVec" is a vector pointing from P_BR to P_TR (or equally, from P_BL to P_TL) These two vectors simply define a convenient parallelogram's basis, and are updated by a call to updateParalleloBasis().static intLAST_PTIndex of last control-pointstatic intP_BLBottom-Left corner (also first specification point)static intP_BRBottom-Right corner (also second specification point)static intP_CENTERParallelogram's centrestatic intP_SPEC_BL1st specification point : Bottom-Left cornerstatic intP_SPEC_BR2nd specification point : Bottom-Right cornerstatic intP_SPEC_TR3rd specification point : Top-Right cornerstatic intP_TLTop-Left cornerstatic intP_TRTop-Right corner (also third specification point)static intSIDE_BBottom side mid-pointstatic intSIDE_LLeft side mid-pintstatic intSIDE_RRight side mid-pointstatic intSIDE_TTop side mid-pointstatic BasicEditPointConstraintSQUAREpredefined constraint for setPoint()-
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 PicParallelogram()Creates a new PicParallelogram reduced to (0,0)PicParallelogram(PicAttributeSet set)Creates a new PicParallelogram reduced to (0,0), with the given attribute setPicParallelogram(PicParallelogram parallelo)"cloning" constructor (to be used by clone())PicParallelogram(PicPoint pt, PicAttributeSet set)Create a new PicParallelogram reduced to a point located at the given positionPicParallelogram(PicPoint pt1, PicPoint pt3)Create a new rectangle with axes parallel to X- and Y-axes, using the 2 given points to build the diagonal, and a default attribute set.PicParallelogram(PicPoint pt1, PicPoint pt2, PicPoint pt3)Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram, and a default attribute set.PicParallelogram(PicPoint pt1, PicPoint pt2, PicPoint pt3, PicAttributeSet set)Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Overrides Object.clone() methodPicMultiCurveconvertToMultiCurve()Return a polygon created from the sides of this parallelogram.PEAction[]createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)Create an array of Action's related to this objectAbstractCustomizercreateCustomizer()Returns a customizer (Swing) componentjava.awt.geom.Rectangle2DgetBoundingBox(java.awt.geom.Rectangle2D r)Returns the bounding box (ie the surrounding rectangle) in double precision Used for instance to determine the arguments of a \\begin{picture} command.PicPointgetCenter(PicPoint src)Return the parallelogram's centredoublegetCenterX()Return the X-coord of the parallelogram's centerdoublegetCenterY()Return the Y-coord of the parallelogram's centerintgetFirstPointIndex()Return the index of the first point that can be retrieved by getPointintgetLastPointIndex()Return the index of the last point that can be retrieved by getPointjava.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 having the given index.doublegetPointX(int numPoint)Return the X-coord of the control-point indexed bynumPoint.doublegetPointY(int numPoint)Return the Y-coord of the control-point indexed bynumPoint.booleanisRectangle()Returns true if this parallelogram is a rectanglevoidrotate(PicPoint ptOrg, double angle)Rotate this Element by the given angle along the given pointvoidsetPoint(int numPoint, PicPoint pt, EditPointConstraint constraint)Set the coordinate of the control-point indexed by "numPoint" to the given value.voidshear(PicPoint ptOrg, double shx, double shy)Shear this Element by the given params wrt to the given originprotected PicVectortoParalleloBasisCoordinates(PicPoint ptOrg, PicPoint ptSrc, PicVector ptDest)Compute the contravariant coordinate of the given point "ptSrc" along the "l2r" and "b2t" vectors of the parallelogram's basis, the origin of the basis being set at "ptOrg" This simply reduces to a contravariant change of coordinates from the cartesian basis to the (non-orthonormalized) parallelogram basis.
To wind up : denoting OM = vec(ptOrg -> ptSrc), (e1,e2) the cartesian basis (ie std model-coordinates), and (x',y') the new coords in the (l2r,b2t) basis, yields :
OM = x e1 + y e2 = x' l2r + y' b2t.java.lang.StringtoString()Implementation of the Object.toString() method, used for debugging purposeprotected voidupdateParalleloBasis()Compute the "l2r" and "b2t" vectors of the parallelogram basis from the location of the three specification-points of this parallelogram.-
Methods inherited from class jpicedt.graphic.model.DefaultLeafElement
addConnection, fireChangedUpdate, forwardChangedUpdate, getAllowsChildren, getNodeName, getNumberOfSpecificationPoints, getPoint, getSpecificationPoint, getSpecificationPoint, getSpecificationPointX, getSpecificationPointY, isNode, isNodeable, iterator, nodeConnectionOrigin, nodeReferencePoint, nodeReferencePointX, nodeReferencePointY, removeAllConnections, removeConnection, scale, setNodeName, setPoint, setSpecificationPoint, translate
-
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
-
-
-
-
Field Detail
-
P_BL
public static final int P_BL
Bottom-Left corner (also first specification point)- See Also:
- Constant Field Values
-
P_BR
public static final int P_BR
Bottom-Right corner (also second specification point)- See Also:
- Constant Field Values
-
P_TR
public static final int P_TR
Top-Right corner (also third specification point)- See Also:
- Constant Field Values
-
P_TL
public static final int P_TL
Top-Left corner- See Also:
- Constant Field Values
-
SIDE_B
public static final int SIDE_B
Bottom side mid-point- See Also:
- Constant Field Values
-
SIDE_R
public static final int SIDE_R
Right side mid-point- See Also:
- Constant Field Values
-
SIDE_T
public static final int SIDE_T
Top side mid-point- See Also:
- Constant Field Values
-
SIDE_L
public static final int SIDE_L
Left side mid-pint- See Also:
- Constant Field Values
-
P_CENTER
public static final int P_CENTER
Parallelogram's centre- See Also:
- Constant Field Values
-
FIRST_PT
public static final int FIRST_PT
Index of first control-point- See Also:
- Constant Field Values
-
LAST_PT
public static final int LAST_PT
Index of last control-point- See Also:
- Constant Field Values
-
SQUARE
public static final BasicEditPointConstraint SQUARE
predefined constraint for setPoint()
-
DEFAULT
public static final BasicEditPointConstraint DEFAULT
predefined constraint for setPoint()
-
CENTER_FIXED
public static final BasicEditPointConstraint CENTER_FIXED
predefined constraint for setPoint()
-
P_SPEC_BL
public static final int P_SPEC_BL
1st specification point : Bottom-Left corner- See Also:
- Constant Field Values
-
P_SPEC_BR
public static final int P_SPEC_BR
2nd specification point : Bottom-Right corner- See Also:
- Constant Field Values
-
P_SPEC_TR
public static final int P_SPEC_TR
3rd specification point : Top-Right corner- See Also:
- Constant Field Values
-
l2rVec
protected PicVector l2rVec
"l2rVec" is a vector pointing from P_BL to P_BR (or equally, from P_TL to P_TR) "b2tVec" is a vector pointing from P_BR to P_TR (or equally, from P_BL to P_TL) These two vectors simply define a convenient parallelogram's basis, and are updated by a call to updateParalleloBasis(). They are used e.g. when moving a corner-point.An essential function of these vectors is to "retain" the initial parallelogram basis even if the element becomes flat at some point during an edit operation.
-
-
Constructor Detail
-
PicParallelogram
public PicParallelogram()
Creates a new PicParallelogram reduced to (0,0)- Since:
- jpicedt 1.3.3
-
PicParallelogram
public PicParallelogram(PicAttributeSet set)
Creates a new PicParallelogram reduced to (0,0), with the given attribute set- Since:
- jpicedt 1.3.3
-
PicParallelogram
public PicParallelogram(PicPoint pt1, PicPoint pt2, PicPoint pt3)
Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram, and a default attribute set.- Since:
- jpicedt 1.4
-
PicParallelogram
public PicParallelogram(PicPoint pt1, PicPoint pt2, PicPoint pt3, PicAttributeSet set)
Create a new PicParallelogram object using the 3 given points as 3 consecutive points of the parallelogram.- Since:
- jpicedt 1.3.3
-
PicParallelogram
public PicParallelogram(PicPoint pt1, PicPoint pt3)
Create a new rectangle with axes parallel to X- and Y-axes, using the 2 given points to build the diagonal, and a default attribute set.- Since:
- jpicedt 1.4
-
PicParallelogram
public PicParallelogram(PicPoint pt, PicAttributeSet set)
Create a new PicParallelogram reduced to a point located at the given position- Since:
- jpicedt 1.3.3
-
PicParallelogram
public PicParallelogram(PicParallelogram parallelo)
"cloning" constructor (to be used by clone())- Parameters:
The- PicParallelogram object to clone- Since:
- jpicedt 1.3.3
-
-
Method Detail
-
clone
public java.lang.Object clone()
Overrides Object.clone() method- Specified by:
clonein interfaceElement- Overrides:
clonein classDefaultLeafElement- Since:
- jpicedt 1.3.3
-
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
- Since:
- jpicedt 1.3.3
-
getPointX
public double getPointX(int numPoint)
Return the X-coord of the control-point indexed bynumPoint.- Specified by:
getPointXin interfaceElement- Overrides:
getPointXin classDefaultLeafElement- Parameters:
numPoint- 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 numPoint)
Return the Y-coord of the control-point indexed bynumPoint.- Specified by:
getPointYin interfaceElement- Overrides:
getPointYin classDefaultLeafElement- Parameters:
numPoint- 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
-
getPoint
public PicPoint getPoint(int numPoint, PicPoint src)
Return the user-controlled 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.- 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.
-
getFirstPointIndex
public int getFirstPointIndex()
Return the index of the first point that can be retrieved by getPoint- Specified by:
getFirstPointIndexin interfaceElement- Overrides:
getFirstPointIndexin classDefaultLeafElement
-
getLastPointIndex
public int getLastPointIndex()
Return the index of the last point that can be retrieved by getPoint- Specified by:
getLastPointIndexin interfaceElement- Overrides:
getLastPointIndexin classDefaultLeafElement
-
updateParalleloBasis
protected void updateParalleloBasis()
Compute the "l2r" and "b2t" vectors of the parallelogram basis from the location of the three specification-points of this parallelogram.- Since:
- jpicedt 1.3.3
-
toParalleloBasisCoordinates
protected PicVector toParalleloBasisCoordinates(PicPoint ptOrg, PicPoint ptSrc, PicVector ptDest)
Compute the contravariant coordinate of the given point "ptSrc" along the "l2r" and "b2t" vectors of the parallelogram's basis, the origin of the basis being set at "ptOrg" This simply reduces to a contravariant change of coordinates from the cartesian basis to the (non-orthonormalized) parallelogram basis.
To wind up : denoting OM = vec(ptOrg -> ptSrc), (e1,e2) the cartesian basis (ie std model-coordinates), and (x',y') the new coords in the (l2r,b2t) basis, yields :
OM = x e1 + y e2 = x' l2r + y' b2t.
Change of coordinates is carried out by using elementary geometry. This yields :
- x' = (OM x b2t).e3/||l2r x b2t||
- y' = -(OM x l2r).e3/||l2r x b2t||
Note that
updateParalleloBasismust be called beforehands for this method to return a valid results [SR:pending] need to be cleaned up.- Parameters:
ptOrg- origin of parallelogram's basisptSrc- source point, coordinates of which have to be convertedptDest- if null, gets allocated and returned for convenience ; besides, it is perfectly safe to call this method with ptDest and one of ptOrg and ptSrc referencing the same PicPoint.- Returns:
- the new coordinates (x',y') along (l2r,b2t), encapsulated in a PicVector
- Since:
- jpicedt 1.3.3
-
setPoint
public void setPoint(int numPoint, PicPoint pt, EditPointConstraint constraint)Set the coordinate of the control-point indexed by "numPoint" to the given value. The control-policy for the default (null or DEFAULT) constraint is as follows :- when moving a corner, the opposite CORNER is kept fixed (ie segments experience a parallel transport)
- when moving a SIDE_X point, the opposite SEGMENT is kept fixed, so that this operation allows one to change the parallelogram skewness.
The SQUARE constraint imposes that the parallelogram be a square. The square diagonal is computed from the current control-point and its opposite corner. Other spec' points are set accordingly.
The CENTER_FIXED constraint imposes that the parallelogram center be kept fixed. Spec' points are set accordingly.
- Specified by:
setPointin interfaceElement- Overrides:
setPointin classDefaultLeafElement- Parameters:
numPoint- one of P_TL, P_TR, P_BL, P_BR, SIDE_T, SIDE_B, SIDE_L, SIDE_R or P_CENTER.constraint- either null, DEFAULT, CENTER_FIXED or SQUARE- Since:
- jpicedt 1.3.3
-
getCenterX
public double getCenterX()
Return the X-coord of the parallelogram's center- Since:
- jpicedt 1.3.3
-
getCenterY
public double getCenterY()
Return the Y-coord of the parallelogram's center- Since:
- jpicedt 1.3.3
-
getCenter
public PicPoint getCenter(PicPoint src)
Return the parallelogram's centre- Returns:
- if
srcis null, allocates a new PicPoint and return it, otherwise directly modifiessrcand returns it as well for convenience. - Since:
- jpicedt 1.3.3
-
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
-
convertToMultiCurve
public PicMultiCurve convertToMultiCurve()
Return a polygon created from the sides of this parallelogram.- Specified by:
convertToMultiCurvein interfacePicMultiCurveConvertable- Since:
- jpicedt 1.3.3
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Returns the bounding box (ie the surrounding rectangle) in double precision Used for instance to determine the arguments of a \\begin{picture} command.This implementation compute the bounding-box from the smallest rectangle that encompasses all the specification-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
-
isRectangle
public boolean isRectangle()
Returns true if this parallelogram is a rectangle
-
toString
public java.lang.String toString()
Implementation of the Object.toString() method, used for debugging purpose- Overrides:
toStringin classDefaultLeafElement
-
createActions
public PEAction[] createActions(ActionDispatcher actionDispatcher, ActionLocalizer localizer, HitInfo hi)
Create an array of Action's related to this object- Specified by:
createActionsin interfaceActionFactory- 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 interface:CustomizerFactoryReturns a customizer (Swing) component- Specified by:
createCustomizerin interfaceCustomizerFactory- Returns:
- a Customizer for geometry editing
- Since:
- jpicedt 1.4
-
-