Class AbstractElement

  • All Implemented Interfaces:
    Element, PicObjectConstants
    Direct Known Subclasses:
    BranchElement, DefaultLeafElement, PicNodeConnection

    public abstract class AbstractElement
    extends java.lang.Object
    implements Element
    An abstract class that can serve as the basis class for elements of a Drawing.

    This implementation provides some useful behaviour where the integration of Element's in a tree-model is concerned.

    Since:
    PicEdt 1.0
    Author:
    Sylvain Reynal
    • Field Detail

      • parent

        protected Element parent
        the parent of this element
      • view

        protected View view
        the view that render this element
    • Constructor Detail

      • AbstractElement

        public AbstractElement()
        construct an AbstractElement with no parent and a default PicAttributeSet
      • AbstractElement

        public AbstractElement​(PicAttributeSet attributeSet)
        construct an AbstractElement with no parent and the given PicAttributeSet.
      • AbstractElement

        public AbstractElement​(AbstractElement obj)
        cloning constructor ; attribute set is deeply copied. The parent and the view are set to null.
    • Method Detail

      • clone

        public abstract java.lang.Object clone()
        Returns a clone of this Element
        Specified by:
        clone in interface Element
        Overrides:
        clone in class java.lang.Object
      • getDrawing

        public Drawing getDrawing()
        Retrieves the underlying drawing
        Specified by:
        getDrawing in interface Element
        Returns:
        the drawing ; null if this AbstractElement doesn't belong to any drawing yet.
      • getParent

        public Element getParent()
        Gets the parent of the element.
        Specified by:
        getParent in interface Element
        Returns:
        the parent
      • setParent

        public void setParent​(Element p)
        Sets the parent of this element to be the given element.
        Specified by:
        setParent in interface Element
      • fireChangedUpdate

        protected void fireChangedUpdate​(DrawingEvent.EventType eventType)
        Must be called each time this AbstractElement changes. This default implementation updates the associated View if any, then propagates upward along the tree by calling forwardChangedUpdate(this) on the Element's parent, if any.
        Tree's root-element should override so as to fire the change to the hosting drawing.
        If subclasser are willing to override this method, they should call super.fireChangeUpdate.
        Parameters:
        type - the event type
      • anchorPointsIterator

        public PointIndexIterator anchorPointsIterator()
        Create an Iterator over points that can serve as anchor points for grid alignment. This implementation returns a DefaultPointIndexIterator which simply iterates through all user-controlled points in ascending order.
        Specified by:
        anchorPointsIterator in interface Element
      • scale

        public void scale​(PicPoint ptOrg,
                          double sx,
                          double sy)
        Scale this object by (sx,sy) using ptOrg as origin sx and sy can be negative. This is a convenience call to scale(double,double,double,double).
        Specified by:
        scale in interface Element
      • getView

        public View getView()
        Returns the View that's responsible for rendering this AbstractElement
        Specified by:
        getView in interface Element
        Returns:
        the View that's responsible for rendering this Element
      • setViewFromFactory

        public void setViewFromFactory​(ViewFactory f)
        set the view for this AbstractElement from the given view factory or remove the view if f is null.
        Specified by:
        setViewFromFactory in interface Element
      • removeView

        public void removeView()
        remove the view that render this element ; this may be used to remove any reference to the view, and render it eligible for garbage collection ; if no View, does nothing.
        Specified by:
        removeView in interface Element
      • getAttributeSet

        public PicAttributeSet getAttributeSet()
        Returns the AttributeSet bound to this AbstractElement.

        Be careful that modifying attributes using this method does not fire any DrawingEvent's, hence does not keep the view synchronized with the state of the model.

        Specified by:
        getAttributeSet in interface Element
        Returns:
        AttributeSet for this Element
      • setAttributeSet

        public void setAttributeSet​(PicAttributeSet attributeSet)
        Bind the given attributes set to this Element. This implementation actually makes a deep copy of the given set beforehands.
        Specified by:
        setAttributeSet in interface Element
        Parameters:
        attributeSet - a new AttributeSet for this Element ; this actually make a deep copy of the given attribute set beforehands.
      • setAttribute

        public void setAttribute​(PicAttributeName name,
                                 java.lang.Object value)
        Set the given attribute name to the given value for this AbstractElement
        Specified by:
        setAttribute in interface Element
      • getAttribute

        public java.lang.Object getAttribute​(PicAttributeName name)
        Returns the value for the given attribute name
        Specified by:
        getAttribute in interface Element
        Returns:
        the value for the given attribute name
      • toString

        public java.lang.String toString()
        Returns a String representation of the attribute set for this AbstractElement
        Overrides:
        toString in class java.lang.Object