http://www.jpicedt.org

jpicedt.graphic.model
Class PicParallelogram

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by jpicedt.graphic.model.DefaultLeafElement
          extended by 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 using getSpecificationPointX/Y. These are obviously stored in the pts ArrayList, 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
protected  PicVector b2tVec
          see documentation for l2rVec
static BasicEditPointConstraint CENTER_FIXED
          predefined constraint for setPoint()
static BasicEditPointConstraint DEFAULT
          predefined constraint for setPoint()
static int FIRST_PT
          Index of first control-point
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().
static int LAST_PT
          Index of last control-point
static int P_BL
          Bottom-Left corner (also first specification point)
static int P_BR
          Bottom-Right corner (also second specification point)
static int P_CENTER
          Parallelogram's centre
static int P_SPEC_BL
          1st specification point : Bottom-Left corner
static int P_SPEC_BR
          2nd specification point : Bottom-Right corner
static int P_SPEC_TR
          3rd specification point : Top-Right corner
static int P_TL
          Top-Left corner
static int P_TR
          Top-Right corner (also third specification point)
static int SIDE_B
          Bottom side mid-point
static int SIDE_L
          Left side mid-pint
static int SIDE_R
          Right side mid-point
static int SIDE_T
          Top side mid-point
static BasicEditPointConstraint SQUARE
          predefined 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
PicParallelogram()
          Creates a new PicParallelogram reduced to (0,0)
PicParallelogram(PicAttributeSet set)
          Creates a new PicParallelogram reduced to (0,0), with the given attribute set
PicParallelogram(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 position
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.
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
 Object clone()
          Overrides Object.clone() method
 PicMultiCurve convertToMultiCurve()
          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 object
 AbstractCustomizer createCustomizer()
          Returns a customizer (Swing) component
 Rectangle2D getBoundingBox(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.
 PicPoint getCenter(PicPoint src)
          Return the parallelogram's centre
 double getCenterX()
          Return the X-coord of the parallelogram's center
 double getCenterY()
          Return the Y-coord of the parallelogram's center
 int getFirstPointIndex()
          Return the index of the first point that can be retrieved by getPoint
 int getLastPointIndex()
          Return the index of the last point that can be retrieved by getPoint
 String getName()
          Returns a non-localised string representing this object's name This default implementation returns the class name.
 PicPoint getPoint(int numPoint, PicPoint src)
          Return the user-controlled point having the given index.
 double getPointX(int numPoint)
          Return the X-coord of the control-point indexed by numPoint.
 double getPointY(int numPoint)
          Return the Y-coord of the control-point indexed by numPoint.
 boolean isRectangle()
          Returns true if this parallelogram is a rectangle
 void rotate(PicPoint ptOrg, double angle)
          Rotate this Element by the given angle along the given point
 void setPoint(int numPoint, PicPoint pt, EditPointConstraint constraint)
          Set the coordinate of the control-point indexed by "numPoint" to the given value.
 void shear(PicPoint ptOrg, double shx, double shy)
          Shear this Element by the given params wrt to the given origin
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.
 String toString()
          Implementation of the Object.toString() method, used for debugging purpose
protected  void updateParalleloBasis()
          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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.


b2tVec

protected PicVector b2tVec
see documentation for l2rVec

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 Object clone()
Overrides Object.clone() method

Specified by:
clone in interface Element
Overrides:
clone in class DefaultLeafElement
Since:
jpicedt 1.3.3

getName

public String getName()
Description copied from class: DefaultLeafElement
Returns a non-localised string representing this object's name This default implementation returns the class name.

Specified by:
getName in interface Element
Overrides:
getName in class DefaultLeafElement
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 by numPoint.

Specified by:
getPointX in interface Element
Overrides:
getPointX in class DefaultLeafElement
Parameters:
numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
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 by numPoint.

Specified by:
getPointY in interface Element
Overrides:
getPointY in class DefaultLeafElement
Parameters:
numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
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 the setPoint method.

Specified by:
getPoint in interface Element
Overrides:
getPoint in class DefaultLeafElement
Parameters:
numPoint - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
Returns:
the point indexed by numPoint ; if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and 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:
getFirstPointIndex in interface Element
Overrides:
getFirstPointIndex in class DefaultLeafElement

getLastPointIndex

public int getLastPointIndex()
Return the index of the last point that can be retrieved by getPoint

Specified by:
getLastPointIndex in interface Element
Overrides:
getLastPointIndex in class DefaultLeafElement

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 :
where e3 denotes the z-axis unit vector of the (x,y,z) direct diedra.

Note that updateParalleloBasis must be called beforehands for this method to return a valid results [SR:pending] need to be cleaned up.

Parameters:
ptOrg - origin of parallelogram's basis
ptSrc - source point, coordinates of which have to be converted
ptDest - 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 :

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:
setPoint in interface Element
Overrides:
setPoint in class DefaultLeafElement
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 src is null, allocates a new PicPoint and return it, otherwise directly modifies src and 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:
rotate in interface Element
Overrides:
rotate in class DefaultLeafElement
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:
shear in interface Element
Overrides:
shear in class DefaultLeafElement

convertToMultiCurve

public PicMultiCurve convertToMultiCurve()
Return a polygon created from the sides of this parallelogram.

Specified by:
convertToMultiCurve in interface PicMultiCurveConvertable
Since:
jpicedt 1.3.3

getBoundingBox

public Rectangle2D getBoundingBox(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:
getBoundingBox in interface Element
Overrides:
getBoundingBox in class DefaultLeafElement
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 String toString()
Implementation of the Object.toString() method, used for debugging purpose

Overrides:
toString in class DefaultLeafElement

createActions

public PEAction[] createActions(ActionDispatcher actionDispatcher,
                                ActionLocalizer localizer,
                                HitInfo hi)
Create an array of Action's related to this object

Specified by:
createActions in interface ActionFactory
Parameters:
actionDispatcher - dispatches events to the proper PECanvas
localizer - i18n localizer for PEAction's
hi - a HitInfo containing information related to the mouse-event which triggered the popup menu.

createCustomizer

public AbstractCustomizer createCustomizer()
Description copied from interface: CustomizerFactory
Returns a customizer (Swing) component

Specified by:
createCustomizer in interface CustomizerFactory
Returns:
a Customizer for geometry editing
Since:
jpicedt 1.4

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org