http://www.jpicedt.org

jpicedt.graphic.model
Class DefaultLeafElement

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by 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 the getSpecificationPointX/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
protected  ArrayList nodeConnections
          a list of node-connection this element is attached to
protected  String nodeName
          name of node for pstricks export
protected  ArrayList pts
          an 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
DefaultLeafElement()
          construct an Element with no parent and a default PicAttributeSet, and no specification points.
DefaultLeafElement(DefaultLeafElement obj)
          cloning constructor ; specification points and attribute set are deeply copied.
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.
 
Method Summary
 void addConnection(PicNodeConnection edge)
           
 Object clone()
          Returns a clone of this element
protected  void fireChangedUpdate(DrawingEvent.EventType eventType)
          Overriden in order to support forwarding to node connections.
 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.
 boolean getAllowsChildren()
          Returns true if the receiver allows children.
 Rectangle2D getBoundingBox(Rectangle2D r)
          Returns the bounding box (i.e.
 int getFirstPointIndex()
          Returns the index of the first user-controlled point that can be retrieved by getPoint().
 int getLastPointIndex()
          Returns the index of the last user-controlled 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.
 String getNodeName()
          gets node name.
 int getNumberOfSpecificationPoints()
          Return the number of specification points backing the geometry of this element.
 PicPoint getPoint(int numPoint)
          Convenience call to getPoint(numPoint,null), i.e., a new Point is allocated on the fly.
 PicPoint getPoint(int numPoint, PicPoint src)
          Return the user-controlled point having the given index.
 double getPointX(int index)
          This default implementation returns the X-coord of the specification-point with the same index.
 double getPointY(int index)
          This default implementation returns the Y-coord of the specification-point with the same index.
protected  PicPoint getSpecificationPoint(int index)
          Return a reference on the specification point with the given index.
 PicPoint getSpecificationPoint(int index, PicPoint src)
          Return the specification-point having the given index.
 double getSpecificationPointX(int index)
          Return the X-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int).
 double getSpecificationPointY(int index)
          Return the Y-coordinate of the specification point with the given index, by calling {@link #getSpecificationPoint(int).
 boolean isNode()
          Are we a Node ?(ie do we have connections ?)
 boolean isNodeable()
          Can we be made into a node ? to be overriden by subclass
 Iterator iterator()
          Returns an iterator over all the node connections
 PicPoint nodeConnectionOrigin(double dx, double dy)
           
 PicPoint nodeReferencePoint()
           
 double nodeReferencePointX()
           
 double nodeReferencePointY()
           
 void removeAllConnections()
           
 void removeConnection(PicNodeConnection edge)
           
 void rotate(PicPoint ptOrg, double angle)
          Rotate this Element by the given angle along the given point
 void scale(double ptOrgX, double ptOrgY, double sx, double sy)
          Scale this object by (sx,sy) using (ptOrgX,ptOrgY) as the origin.
 void setNodeName(String name)
          sets node name.
 void setPoint(int index, PicPoint pt)
          Deprecated. use setPoint(index,pt,constraint) instead
 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.
protected  void setSpecificationPoint(int index, PicPoint pt)
          set the specification point with the given index to the given location.
 void shear(PicPoint ptOrg, double shx, double shy)
          Shear this Element by the given params wrt to the given origin
 String toString()
          Returns a String representation of this DefaultElement
 void translate(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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pts

protected ArrayList pts
an ArrayList containing PicPoint's representing the geometry of this element (specification points)


nodeName

protected String nodeName
name of node for pstricks export


nodeConnections

protected 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 String getName()
Returns a non-localised string representing this object's name This default implementation returns the class name.


clone

public Object clone()
Returns a clone of this element

Specified by:
clone in interface Element
Specified by:
clone in class AbstractElement

iterator

public 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(String name)
sets node name. If argument name is null, create a new name.


getNodeName

public 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 type
child - the child that sent the change-event.

fireChangedUpdate

protected void fireChangedUpdate(DrawingEvent.EventType eventType)
Overriden in order to support forwarding to node connections.

Overrides:
fireChangedUpdate in class AbstractElement
Since:
jpicedt 1.4pre5

getSpecificationPointX

public double getSpecificationPointX(int index)
Return the X-coordinate of the specification point with the given index, by calling getSpecificationPoint(index).

Parameters:
index - the point index, should be greater or equal to zero, and lower or equal to the index returned by getNumberOfSpecificationPoints().
Since:
jpicedt1.3.3

getSpecificationPointY

public double getSpecificationPointY(int index)
Return the Y-coordinate of the specification point with the given index, by calling getSpecificationPoint(index).

Parameters:
index - the point index, should be greater or equal to zero, and lower or equal to the index returned by getNumberOfSpecificationPoints().
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 for getPoint() in interface Element, and simply clones a PicPoint obtained by a call to getSpecificationPoint(index).

Parameters:
index - the point index, should be greater or equal to zero, and lower or equal to the index returned by getNumberOfSpecificationPoints().
Returns:
the specification-point indexed by index ; if src is null, allocates a new PicPoint and return it, otherwise directly modifies src and 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 by getPoint(). This default implementation returns 0.


getLastPointIndex

public int getLastPointIndex()
Returns the index of the last user-controlled point that can be retrieved by getPoint(). 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 the setPoint method.
This implementation simply call getSpecificationPoint() with the same arguments.

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.

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 by getFirstPointIndex, and lower or equal to getLastPointIndex.
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 by getFirstPointIndex, and lower or equal to getLastPointIndex.
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) instead

Set 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 vector
dy - 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 that sx and sy may 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 Rectangle2D getBoundingBox(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 String toString()
Returns a String representation of this DefaultElement

Overrides:
toString in class AbstractElement

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org