Class DefaultLeafElement
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.DefaultLeafElement
-
- All Implemented Interfaces:
Element,PicObjectConstants
- Direct Known Subclasses:
AbstractCurve,PicParallelogram,TextEditable
public class DefaultLeafElement extends AbstractElement
This is a default implementation of AbstractElement targetting leaf Element's, i.e. Element's that can NOT have children.
The element's geometry is backed by an array of coordinates (labelled specification points) containing the minimum number of pair of coordinates required to fully specify the shape of the element. For convenience, this array has been made accessible by means of thegetSpecificationPointX/Y()methods : this may be used e.g. by an associated View to create the appropriate java.awt.Shape if required.Even if, as of this implementation, specification points act as user-controlled point, there may be more control points however (e.g. for a rectangle, there are two "specification" points, yet five control points, including the center).
- Since:
- jpicedt 1.3.3
- Author:
- Sylvain Reynal
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayListnodeConnectionsa list of node-connection this element is attached toprotected java.lang.StringnodeNamename of node for pstricks exportprotected java.util.ArrayListptsan ArrayList containing PicPoint's representing the geometry of this element (specification points)-
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 DefaultLeafElement()construct an Element with no parent and a default PicAttributeSet, and no specification points.DefaultLeafElement(int nPts)construct a Element with no parent and a default PicAttributeSet, and the given number of specification points.DefaultLeafElement(int nPts, PicAttributeSet attributeSet)construct a DefaultElement with no parent and the given PicAttributeSet, and the given number of specification points.DefaultLeafElement(DefaultLeafElement obj)cloning constructor ; specification points and attribute set are deeply copied.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddConnection(PicNodeConnection edge)java.lang.Objectclone()Returns a clone of this elementprotected voidfireChangedUpdate(DrawingEvent.EventType eventType)Overriden in order to support forwarding to node connections.voidforwardChangedUpdate(Element child, DrawingEvent.EventType eventType)Called by a child of this element to inform its parent of some change that occured to it or one of its children.booleangetAllowsChildren()Returns true if the receiver allows children.java.awt.geom.Rectangle2DgetBoundingBox(java.awt.geom.Rectangle2D r)Returns the bounding box (i.e.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.java.lang.StringgetNodeName()gets node name.intgetNumberOfSpecificationPoints()Return the number of specification points backing the geometry of this element.PicPointgetPoint(int numPoint)Convenience call to getPoint(numPoint,null), i.e., a new Point is allocated on the fly.PicPointgetPoint(int numPoint, PicPoint src)Return the user-controlled point having the given index.doublegetPointX(int index)This default implementation returns the X-coord of the specification-point with the same index.doublegetPointY(int index)This default implementation returns the Y-coord of the specification-point with the same index.protected PicPointgetSpecificationPoint(int index)Return a reference on the specification point with the given index.PicPointgetSpecificationPoint(int index, PicPoint src)Return the specification-point having the given index.doublegetSpecificationPointX(int index)Return the X-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int). getSpecificationPoint(index)}.doublegetSpecificationPointY(int index)Return the Y-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int). getSpecificationPoint(index)}.booleanisNode()Are we a Node ?(ie do we have connections ?)booleanisNodeable()Can we be made into a node ? to be overriden by subclassjava.util.Iteratoriterator()Returns an iterator over all the node connectionsPicPointnodeConnectionOrigin(double dx, double dy)PicPointnodeReferencePoint()doublenodeReferencePointX()doublenodeReferencePointY()voidremoveAllConnections()voidremoveConnection(PicNodeConnection edge)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.voidsetNodeName(java.lang.String name)sets node name.voidsetPoint(int index, PicPoint pt)Deprecated.use setPoint(index,pt,constraint) insteadvoidsetPoint(int index, PicPoint pt, EditPointConstraint constraint)Set the user-controlled point indexed by "index" to the given value, using the specified geometrical constraint.protected voidsetSpecificationPoint(int index, PicPoint pt)set the specification point with the given index to the given location.voidshear(PicPoint ptOrg, double shx, double shy)Shear this Element by the given params wrt to the given originjava.lang.StringtoString()Returns a String representation of this DefaultElementvoidtranslate(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.AbstractElement
anchorPointsIterator, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
-
-
-
-
Field Detail
-
pts
protected java.util.ArrayList pts
an ArrayList containing PicPoint's representing the geometry of this element (specification points)
-
nodeName
protected java.lang.String nodeName
name of node for pstricks export
-
nodeConnections
protected java.util.ArrayList nodeConnections
a list of node-connection this element is attached to
-
-
Constructor Detail
-
DefaultLeafElement
public DefaultLeafElement()
construct an Element with no parent and a default PicAttributeSet, and no specification points.
-
DefaultLeafElement
public DefaultLeafElement(int nPts)
construct a Element with no parent and a default PicAttributeSet, and the given number of specification points.
-
DefaultLeafElement
public DefaultLeafElement(int nPts, PicAttributeSet attributeSet)construct a DefaultElement with no parent and the given PicAttributeSet, and the given number of specification points.
-
DefaultLeafElement
public DefaultLeafElement(DefaultLeafElement obj)
cloning constructor ; specification points and attribute set are deeply copied. The parent and the view are set to null.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns a non-localised string representing this object's name This default implementation returns the class name.
-
clone
public java.lang.Object clone()
Returns a clone of this element- Specified by:
clonein interfaceElement- Specified by:
clonein classAbstractElement
-
iterator
public java.util.Iterator iterator()
Returns an iterator over all the node connections
-
isNode
public boolean isNode()
Are we a Node ?(ie do we have connections ?)
-
setNodeName
public void setNodeName(java.lang.String name)
sets node name. If argumentnameis null, create a new name.
-
getNodeName
public java.lang.String getNodeName()
gets node name. If nodeName is null, create a new name.
-
isNodeable
public boolean isNodeable()
Can we be made into a node ? to be overriden by subclass
-
addConnection
public void addConnection(PicNodeConnection edge)
-
removeConnection
public void removeConnection(PicNodeConnection edge)
-
removeAllConnections
public void removeAllConnections()
-
nodeReferencePoint
public PicPoint nodeReferencePoint()
-
nodeReferencePointX
public double nodeReferencePointX()
-
nodeReferencePointY
public double nodeReferencePointY()
-
nodeConnectionOrigin
public PicPoint nodeConnectionOrigin(double dx, double dy)
-
getAllowsChildren
public boolean getAllowsChildren()
Returns true if the receiver allows children. This implementation returns false.
-
forwardChangedUpdate
public void forwardChangedUpdate(Element child, DrawingEvent.EventType eventType)
Called by a child of this element to inform its parent of some change that occured to it or one of its children. This gives a chance to the receiver to update its layout, then to propagate the change-event upward.This implementation does nothing, since this method can never be called.
- Parameters:
eventType- the event typechild- the child that sent the change-event.
-
fireChangedUpdate
protected void fireChangedUpdate(DrawingEvent.EventType eventType)
Overriden in order to support forwarding to node connections.- Overrides:
fireChangedUpdatein classAbstractElement- Since:
- jpicedt 1.4pre5
-
getSpecificationPointX
public double getSpecificationPointX(int index)
Return the X-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int). getSpecificationPoint(index)}.- Parameters:
index- the point index, should be greater or equal to zero, and lower or equal to the index returned bygetNumberOfSpecificationPoints().- Since:
- jpicedt1.3.3
-
getSpecificationPointY
public double getSpecificationPointY(int index)
Return the Y-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int). getSpecificationPoint(index)}.- Parameters:
index- the point index, should be greater or equal to zero, and lower or equal to the index returned bygetNumberOfSpecificationPoints().- Since:
- jpicedt1.3.3
-
getSpecificationPoint
public PicPoint getSpecificationPoint(int index, PicPoint src)
Return the specification-point having the given index. This implementation exactly mimics the general contract forgetPoint()in interface Element, and simply clones a PicPoint obtained by a call to {@link #getSpecificationPoint(int). getSpecificationPoint(index)}.- Parameters:
index- the point index, should be greater or equal to zero, and lower or equal to the index returned bygetNumberOfSpecificationPoints().- Returns:
- the specification-point indexed by
index; ifsrcis null, allocates a new PicPoint and return it, otherwise directly modifiessrcand returns it as well for convenience. - Since:
- jpicedt1.3.3
-
getSpecificationPoint
protected PicPoint getSpecificationPoint(int index)
Return a reference on the specification point with the given index. This may be used when subclassers wants to apply a transformation to the given point (e.g. PicPoint.translate()) w/o having to resort to an intermediate buffer.It is enough to override this method if one wants to change the behaviour of all other getSpecificationPoint() methods at once (typical applications include : carrying out security checks on the given index, applying a geometric transformation on the PicPoint to be returned, creating index aliases, ...).
[developpers] protecting access is MAN-DA-TO-RY ! I don't trust ourselves enough to let us play with references from outta-hood ;-)
-
getNumberOfSpecificationPoints
public int getNumberOfSpecificationPoints()
Return the number of specification points backing the geometry of this element.
-
getFirstPointIndex
public int getFirstPointIndex()
Returns the index of the first user-controlled point that can be retrieved bygetPoint(). This default implementation returns 0.
-
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 specification points minus one.
-
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.
This implementation simply call getSpecificationPoint() with the same arguments.- 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.
-
getPoint
public PicPoint getPoint(int numPoint)
Convenience call to getPoint(numPoint,null), i.e., a new Point is allocated on the fly.
-
getPointX
public double getPointX(int index)
This default implementation returns the X-coord of the specification-point with the same index. This might be a valid implementation as long as subclasses don't have other user-controlled points.- 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:
- PicEdt 1.0
-
getPointY
public double getPointY(int index)
This default implementation returns the Y-coord of the specification-point with the same index. This might be a valid implementation as long as subclasses don't have other user-controlled points.- 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:
- PicEdt 1.0
-
setPoint
public void setPoint(int index, PicPoint pt)Deprecated.use setPoint(index,pt,constraint) insteadSet the user-controlled point with the given index to the given value. This default implementation simply call setSpecificationPoint, then fires a change-update of type GEOMETRY_CHANGE
-
setPoint
public void setPoint(int index, PicPoint pt, EditPointConstraint constraint)Set the user-controlled point indexed by "index" to the given value, using the specified geometrical constraint. Constraints depend on the particular concrete implementation, and may involve restricting movement along a particular direction, moving several points at once to preserve parallelism,... The default constraint in this implementation reduces to simply calling setSpecificationPoint, then firing a GEOMETRY_CHANGE change-update.- Parameters:
constraint- a geometry constraint, or null if no particular constraint is being imposed (aka default).
-
setSpecificationPoint
protected void setSpecificationPoint(int index, PicPoint pt)set the specification point with the given index to the given location. This method does NOT fire any DrawingEvent ! It's up to receivers to do so, e.g. setPoint().
[developpers] this method is protected because i don't want to break the general contract in Element, which says that the getters'n setters for the geometry are throught getPoint/setPoint methods, possibly using appropriate constraints. This method is thus just a convenience to you.
-
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.- 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.
-
rotate
public void rotate(PicPoint ptOrg, double angle)
Rotate this Element by the given angle along the given point- 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
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Returns the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of a \\begin{picture} command.This implementation compute the bb from the smallest rectangle that encompasses all specification-points.
- 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:
- PicEdt 1.0
-
toString
public java.lang.String toString()
Returns a String representation of this DefaultElement- Overrides:
toStringin classAbstractElement
-
-