Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jpicedt.graphic.model
Class BranchElement  view BranchElement download BranchElement.java

java.lang.Object
  extended byjpicedt.graphic.model.AbstractElement
      extended byjpicedt.graphic.model.BranchElement
All Implemented Interfaces:
java.util.Collection, Element, java.lang.Iterable, PicObjectConstants
Direct Known Subclasses:
Drawing.RootElement, PicGroup

public abstract class BranchElement
extends AbstractElement
implements java.util.Collection

An abstract class for Element's that allow children

The implementation of the Collection interface is done through calls to addChild, removeChild, children, removeAllChildren, except for the addAll method which is implemented from scratch so as to fire a changed-event only once all elements have been added.
As a result, subclasses only need to override these methods to change the behaviour of content-modifying methods.

This element has only one control point, namely, the bottom-left corner of the bounding box. Moving this point result in a global translation of the element (no rescale, use PicGroup instead).

Since:
jPicEdt 1.3.2

Nested Class Summary
 
Nested classes inherited from class jpicedt.graphic.model.AbstractElement
AbstractElement.DefaultPointIterator
 
Nested classes inherited from class jpicedt.graphic.model.Element
Element.PointIterator
 
Field Summary
protected  boolean changeLock
          a flag that signals a change is underway (uses by forwardChangedUpdate) and that this element shouldn't process events coming from children before the change is completed ; set it to true in subclasses e.g.
protected  java.util.ArrayList children
          the array that contains children
private static int P_ANCHOR
           
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, parent, ptsX, ptsY, view
 
Fields inherited from interface jpicedt.graphic.model.PicObjectConstants
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, MaxAttributeNameIndex, MIDDLE, NONE, OUTER, POLYGON_DOTS, POLYGON_SOLID, POLYGON_STYLE, PS_POINT, RIGHT_ARROW, SHADOW, SHADOW_ANGLE, SHADOW_COLOR, SHADOW_SIZE, SOLID, VLINES, VLINES_FILLED
 
Constructor Summary
BranchElement()
          construct a BranchElement with no parent and a default PicAttributeSet
BranchElement(BranchElement src)
          cloning constructor (though with no parent and no view) : 1) attribute set is deeply copied.
BranchElement(java.util.Collection c)
          create a new BranchElement from the content of the given Collection of Element's.
BranchElement(PicAttributeSet attributeSet)
          construct a BranchElement with no parent and the given PicAttributeSet
 
Method Summary
 boolean add(java.lang.Object o)
          add the given object as a new child of this BranchElement, but only if it's an instance of Element, and return true.
 boolean addAll(java.util.Collection c)
          adds all the elements in the given collection that are instance of Element as children of this BranchElement.
 void addChild(Element child)
          add the given child to this BranchElement, setting its parent to this.
 void addChild(int position, Element child)
          insert the given child in this BranchElement at the given position, setting its parent to this, and create a view for the child using the ViewFactory that produced the View for this BranchElement.
 void bringBackward(Element obj)
          Move the given child one position backward, i.e.
 void bringForward(Element obj)
          Move the given child one position forward, i.e.
 void bringToBack(Element obj)
          Move the given child to back (i.e.
 void bringToFront(Element obj)
          Move the given child to front, i.e.
 java.util.Iterator children()
           
 void clear()
          remove all the children
abstract  java.lang.Object clone()
          Returns a clone of this element
 boolean contains(Element o)
           
 boolean contains(java.lang.Object o)
          Returns true if this collection contains the specified element.
 boolean containsAll(java.util.Collection c)
          Returns true if this BranchElement contains all of the elements in the specified collection.
 boolean equals(java.lang.Object o)
          Test whether this collection is equal to some object.
protected  void forwardChangedUpdate(Element child, jpicedt.graphic.event.DrawingEvent.EventType eventType)
          called by a child to inform its parent of some change that occured to it or one of its children.
 java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
          Returns the bounding box (i.e.
 Element getChildAt(int childIndex)
           
 int getChildCount()
           
 int getChildIndex(Element node)
          Returns the index of the given Element in the receivers children.
 int getFirstPointIndex()
          Returns the index of the first point that can be retrieved by getPoint This default implementation returns 0.
 int getLastPointIndex()
          Returns the index of the last point that can be retrieved by getPoint This default implementation returns the greater index allowed in ptsX (or ptsY).
 double getPointX(int numPoint)
          This default implementation returns ptsX[numPoint].
 double getPointY(int numPoint)
          This default implementation returns ptsY[numPoint].This might be a valid implementation as long as subclasses don't have other control points.
 boolean isEmpty()
          Test whether this collection is empty, that is, if size() == 0.
 boolean isToBack(Element obj)
           
 boolean isToFront(Element obj)
           
 java.util.Iterator iterator()
          Returns an iterator over children.
 boolean remove(java.lang.Object o)
          Removes a single instance of the specified Element from this BranchElement, if it is present AND is instance of Element.
 boolean removeAll(java.util.Collection c)
          Removes all this collection's elements that are also contained in the specified collection.
 void removeAllChildren()
          remove all children from this BranchElement, set each child's parent to null.
 void removeChild(Element child)
          remove the given child from this BranchElement, setting its parent to null so that the given child become (possibly) eligible for garbage collection if there are no other reference to it.
 void removeView()
          remove the view that render this element and propagate to children ; this may be used to remove any reference to the view, and render it eligible for garbage collection ; if no View, does nothing.
 void replaceChild(int position, Element newChild)
          replace the child at the given position by the given child
 boolean retainAll(java.util.Collection c)
          Retains only the elements in this BranchElement that are contained in the specified collection
 void scale(double ptOrgX, double ptOrgY, double sx, double sy)
          Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.
 void scale(jpicedt.graphic.PicPoint ptOrg, double sx, double sy)
          Scale children by (sx,sy) using ptOrg as origin ; sx and sy can be negative.
 void setAttribute(PicAttributeName name, java.lang.Object value)
          set an Attribute for this BranchElement and propagate to children
 void setAttributeSet(PicAttributeSet set)
          set AttributeSet for this BranchElement and propagate to children
 void setPoint(int numPoint, jpicedt.graphic.PicPoint pt)
          Set the point indexed by "numPoint" to the given value.
 void setViewFromFactory(jpicedt.graphic.view.ViewFactory f)
          set the view for this Element from the given view factory, then set the view for children.
 int size()
          Get the number of elements in this collection.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this collection.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array containing all of the elements in this collection whose runtime type is that of the specified array.
 java.lang.String toString()
          Returns a String representing the group for debugging use only.
 void translate(double dx, double dy)
          Translate children by the given vector
protected  void updateBoundingBox()
          Update the bounding box by "unioning" the children's bounding box (actually computes the two specification points defining the diagonal of the box).
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getName, getParent, getPoint, getView, setParent
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
hashCode
 

Field Detail

children

protected java.util.ArrayList children
the array that contains children


changeLock

protected boolean changeLock
a flag that signals a change is underway (uses by forwardChangedUpdate) and that this element shouldn't process events coming from children before the change is completed ; set it to true in subclasses e.g. each time you start modifying children and you don't want events to be forwarded to the root of the hierarchy before everything is completed


P_ANCHOR

private static final int P_ANCHOR
See Also:
Constant Field Values
Constructor Detail

BranchElement

public BranchElement()
construct a BranchElement with no parent and a default PicAttributeSet


BranchElement

public BranchElement(PicAttributeSet attributeSet)
construct a BranchElement with no parent and the given PicAttributeSet


BranchElement

public BranchElement(BranchElement src)
cloning constructor (though with no parent and no view) : 1) attribute set is deeply copied. 2) source's children are cloned, then the copy is added to this BranchElement


BranchElement

public BranchElement(java.util.Collection c)
create a new BranchElement from the content of the given Collection of Element's. Children are cloned as well (i.e. this isa deep copy).

Method Detail

clone

public abstract java.lang.Object clone()
Description copied from class: AbstractElement
Returns a clone of this element

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

getChildAt

public Element getChildAt(int childIndex)

getChildCount

public int getChildCount()

children

public java.util.Iterator children()

getChildIndex

public int getChildIndex(Element node)
Returns the index of the given Element in the receivers children. If the receiver does not contain the given Element, -1 will be returned.


contains

public boolean contains(Element o)

addChild

public void addChild(Element child)
add the given child to this BranchElement, setting its parent to this. Since a child can't have two parents, this also remove the child from its former parent, if any.
If view is non-null, use the associated ViewFactory to create View's for the new child.


addChild

public void addChild(int position,
                     Element child)
insert the given child in this BranchElement at the given position, setting its parent to this, and create a view for the child using the ViewFactory that produced the View for this BranchElement.


replaceChild

public void replaceChild(int position,
                         Element newChild)
replace the child at the given position by the given child


removeChild

public void removeChild(Element child)
remove the given child from this BranchElement, setting its parent to null so that the given child become (possibly) eligible for garbage collection if there are no other reference to it.


removeAllChildren

public void removeAllChildren()
remove all children from this BranchElement, set each child's parent to null.


getFirstPointIndex

public int getFirstPointIndex()
Description copied from class: AbstractElement
Returns the index of the first point that can be retrieved by getPoint This default implementation returns 0.

Specified by:
getFirstPointIndex in interface Element
Overrides:
getFirstPointIndex in class AbstractElement

getLastPointIndex

public int getLastPointIndex()
Description copied from class: AbstractElement
Returns the index of the last point that can be retrieved by getPoint This default implementation returns the greater index allowed in ptsX (or ptsY).

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

getPointX

public double getPointX(int numPoint)
Description copied from class: AbstractElement
This default implementation returns ptsX[numPoint]. This might be a valid implementation as long as subclasses don't have other control points.

Specified by:
getPointX in interface Element
Overrides:
getPointX in class AbstractElement
Since:
PicEdt 1.0

getPointY

public double getPointY(int numPoint)
This default implementation returns ptsY[numPoint].This might be a valid implementation as long as subclasses don't have other control points.

Specified by:
getPointY in interface Element
Overrides:
getPointY in class AbstractElement
Since:
PicEdt 1.0

setPoint

public void setPoint(int numPoint,
                     jpicedt.graphic.PicPoint pt)
Set the point indexed by "numPoint" to the given value. This implementation calls setPointX and setPointY.

Specified by:
setPoint in interface Element
Overrides:
setPoint in class AbstractElement

translate

public void translate(double dx,
                      double dy)
Translate children by the given vector

Specified by:
translate in interface Element
Overrides:
translate in class AbstractElement
Since:
jPicEdt 1.3.2

scale

public void scale(jpicedt.graphic.PicPoint ptOrg,
                  double sx,
                  double sy)
Scale children by (sx,sy) using ptOrg as origin ; sx and sy can be negative.

Specified by:
scale in interface Element
Overrides:
scale in class AbstractElement

scale

public void scale(double ptOrgX,
                  double ptOrgY,
                  double sx,
                  double sy)
Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.

Specified by:
scale in interface Element
Overrides:
scale in class AbstractElement

forwardChangedUpdate

protected void forwardChangedUpdate(Element child,
                                    jpicedt.graphic.event.DrawingEvent.EventType eventType)
called by a child 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 update the bounding-box, then fire a changedUpdate event ONLY if changeLock is false. Otherwise, does nothing (this is the exact semantic behing "changeLock").


setViewFromFactory

public void setViewFromFactory(jpicedt.graphic.view.ViewFactory f)
set the view for this Element from the given view factory, then set the view for children.

Specified by:
setViewFromFactory in interface Element
Overrides:
setViewFromFactory in class AbstractElement

removeView

public void removeView()
remove the view that render this element and propagate to children ; 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
Overrides:
removeView in class AbstractElement

bringToBack

public void bringToBack(Element obj)
Move the given child to back (i.e. following z-ordering policy), i.e. removes it from its current position and insert it at position 0
Does nothing if the given child can't be found in this Drawing or is already to back.


bringToFront

public void bringToFront(Element obj)
Move the given child to front, i.e. removes it from its current position and appends to the drawing.
Does nothing if the given obj can't be found in this Drawing or if it's already to front.


bringBackward

public void bringBackward(Element obj)
Move the given child one position backward, i.e. removes it from its current position and insert it one position backward.
Does nothing if the given obj can't be found in this Drawing, or if it's already to back.


bringForward

public void bringForward(Element obj)
Move the given child one position forward, i.e. removes it from its current position and insert it one position forward.
Does nothing if the given obj can't be found in this Drawing, or if it's already to front.


isToBack

public boolean isToBack(Element obj)

isToFront

public boolean isToFront(Element obj)

getBoundingBox

public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Description copied from class: AbstractElement
Returns the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command.

This implementation compute the bb from the smallest rectangle that encompasses all the specification points.

Specified by:
getBoundingBox in interface Element
Overrides:
getBoundingBox in class AbstractElement
Since:
PicEdt 1.0

updateBoundingBox

protected void updateBoundingBox()
Update the bounding box by "unioning" the children's bounding box (actually computes the two specification points defining the diagonal of the box). Should be called each time the content of this element gets modified : this may include addition or deletion of a child, and modification of a child by the child itself.


setAttributeSet

public void setAttributeSet(PicAttributeSet set)
set AttributeSet for this BranchElement and propagate to children

Specified by:
setAttributeSet in interface Element
Overrides:
setAttributeSet in class AbstractElement

setAttribute

public void setAttribute(PicAttributeName name,
                         java.lang.Object value)
set an Attribute for this BranchElement and propagate to children

Specified by:
setAttribute in interface Element
Overrides:
setAttribute in class AbstractElement

toString

public java.lang.String toString()
Returns a String representing the group for debugging use only.

Overrides:
toString in class AbstractElement

add

public boolean add(java.lang.Object o)
add the given object as a new child of this BranchElement, but only if it's an instance of Element, and return true. Return false otherwise

Specified by:
add in interface java.util.Collection

addAll

public boolean addAll(java.util.Collection c)
adds all the elements in the given collection that are instance of Element as children of this BranchElement.

Specified by:
addAll in interface java.util.Collection

clear

public void clear()
remove all the children

Specified by:
clear in interface java.util.Collection

size

public int size()
Description copied from interface: java.util.Collection
Get the number of elements in this collection.

Specified by:
size in interface java.util.Collection

isEmpty

public boolean isEmpty()
Description copied from interface: java.util.Collection
Test whether this collection is empty, that is, if size() == 0.

Specified by:
isEmpty in interface java.util.Collection

contains

public boolean contains(java.lang.Object o)
Returns true if this collection contains the specified element.

Specified by:
contains in interface java.util.Collection

iterator

public java.util.Iterator iterator()
Returns an iterator over children.

Specified by:
iterator in interface java.util.Collection

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this collection.

Specified by:
toArray in interface java.util.Collection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this collection whose runtime type is that of the specified array.

Specified by:
toArray in interface java.util.Collection

remove

public boolean remove(java.lang.Object o)
Removes a single instance of the specified Element from this BranchElement, if it is present AND is instance of Element.

Specified by:
remove in interface java.util.Collection

containsAll

public boolean containsAll(java.util.Collection c)
Returns true if this BranchElement contains all of the elements in the specified collection.

Specified by:
containsAll in interface java.util.Collection

removeAll

public boolean removeAll(java.util.Collection c)
Removes all this collection's elements that are also contained in the specified collection. After this call returns, this collection will contain no elements in common with the specified collection.

Specified by:
removeAll in interface java.util.Collection

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this BranchElement that are contained in the specified collection

Specified by:
retainAll in interface java.util.Collection

equals

public boolean equals(java.lang.Object o)
Description copied from interface: java.util.Collection
Test whether this collection is equal to some object. The Collection interface does not explicitly require any behaviour from this method, and it may be left to the default implementation provided by Object. The Set and List interfaces do, however, require specific behaviour from this method.

If an implementation of Collection, which is not also an implementation of Set or List, should choose to implement this method, it should take care to obey the contract of the equals method of Object. In particular, care should be taken to return false when o is a Set or a List, in order to preserve the symmetry of the relation.

Specified by:
equals in interface java.util.Collection