Class 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 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:
        clone in interface Element
        Specified by:
        clone in class AbstractElement
      • 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 argument name is 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
      • 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.
      • 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 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 {@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 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 {@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 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 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:
        toString in class AbstractElement