public abstract class BranchElement extends AbstractElement implements java.util.Collection
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 (however no rescale capability is available here
using the setPoint() method, use the PicGroup class instead).
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
changeLock
a semaphor that signals a change of state is underway in this BranchElement and
it shouldn't process events coming from its children before the change is completed
(hence this is used inside
forwardChangedUpdate());
set it to true each time you start modifying children in batch mode and you don't want
events to be forwarded to the root of the hierarchy before everything is completed (e.g. |
protected java.util.ArrayList |
children
the array that contains children
|
protected double[] |
ptsX
an array of X-coordinates representing the two opposite corner of the bounding box that contains all children
|
protected double[] |
ptsY
an array of Y-coordinates representing the two opposite corner of the bounding box that contains all children
|
attributeSet, parent, viewARROW_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 and Description |
|---|
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
|
| Modifier and Type | Method and Description |
|---|---|
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 |
containsClass(java.lang.Class clazz)
Returns whether this BranchElement contains objects that are of the same type of inherit from the
given clazz.
|
java.util.ArrayList |
createFilteredCollection(java.lang.Class clazz)
Returns a list containing children of this BranchElement that are of the same type or
inherit the given clazz.
|
boolean |
equals(java.lang.Object o) |
void |
forwardChangedUpdate(Element child,
DrawingEvent.EventType eventType)
Called by a child of this BranchElement 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.
|
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()
Return the index of the first user-controlled point that can be retrieved by getPoint()
|
int |
getLastPointIndex()
Return the index of the last user-controlled point that can be retrieved by getPoint()
|
PicPoint |
getPoint(int numPoint,
PicPoint src)
Return the user-controlled point having the given index.
|
double |
getPointX(int numPoint)
Same as
getPoint(), yet return the x-coordinate only. |
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() |
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 |
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 children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.
|
void |
scale(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 index,
PicPoint pt)
Deprecated.
use setPoint(int, PicPoint, EditPointConstraint) instead.
|
void |
setPoint(int numPoint,
PicPoint pt,
EditPointConstraint c)
Set the point indexed by "numPoint" to the given value.
|
void |
setViewFromFactory(ViewFactory f)
set the view for this Element from the given view factory, then set the view for children.
|
void |
shear(PicPoint ptOrg,
double shx,
double shy)
Shear this Element by the given params wrt to the given origin
|
int |
size() |
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).
|
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getParent, getView, setParentfinalize, getClass, hashCode, notify, notifyAll, wait, wait, waitprotected java.util.ArrayList children
protected boolean changeLock
forwardChangedUpdate());
set it to true each time you start modifying children in batch mode and you don't want
events to be forwarded to the root of the hierarchy before everything is completed (e.g. to
get rid of side-effects, or to reduce the burden for the repaint manager).
Example of use : whenever we call translate() on this BranchElement,
protected double[] ptsX
protected double[] ptsY
public BranchElement()
public BranchElement(PicAttributeSet attributeSet)
public BranchElement(BranchElement src)
public BranchElement(java.util.Collection c)
public abstract java.lang.Object clone()
AbstractElementclone in interface Elementclone in class AbstractElementpublic boolean getAllowsChildren()
getAllowsChildren in interface Elementpublic Element getChildAt(int childIndex)
public int getChildCount()
public java.util.Iterator children()
public int getChildIndex(Element node)
public boolean contains(Element o)
public void addChild(Element child)
public void addChild(int position,
Element child)
public void replaceChild(int position,
Element newChild)
public void removeChild(Element child)
public void removeAllChildren()
public int getFirstPointIndex()
ElementgetFirstPointIndex in interface Elementpublic int getLastPointIndex()
ElementgetLastPointIndex in interface Elementpublic double getPointX(int numPoint)
ElementgetPoint(), yet return the x-coordinate only.public double getPointY(int numPoint)
ptsY[numPoint].This might be a valid implementation
as long as subclasses don't have other control points.public PicPoint getPoint(int numPoint, PicPoint src)
setPoint method,
hence this implementation simply calls getPointX() and getPointY().getPoint in interface ElementnumPoint - the point index, should be greater or equal to the value returned by
getFirstPointIndex, and lower or equal to getLastPointIndex.numPoint ;
if src is null, allocates a new PicPoint and return it,
otherwise directly modifies src and returns it as well for convenience.public void setPoint(int index,
PicPoint pt)
public void setPoint(int numPoint,
PicPoint pt,
EditPointConstraint c)
public void translate(double dx,
double dy)
public void scale(PicPoint ptOrg, double sx, double sy)
scale in interface Elementscale in class AbstractElementpublic void scale(double ptOrgX,
double ptOrgY,
double sx,
double sy)
public void rotate(PicPoint ptOrg, double angle)
public void shear(PicPoint ptOrg, double shx, double shy)
public void forwardChangedUpdate(Element child, DrawingEvent.EventType eventType)
forwardChangedUpdate in interface ElementeventType - the event typechild - public void setViewFromFactory(ViewFactory f)
setViewFromFactory in interface ElementsetViewFromFactory in class AbstractElementpublic void removeView()
removeView in interface ElementremoveView in class AbstractElementpublic void bringToBack(Element obj)
public void bringToFront(Element obj)
public void bringBackward(Element obj)
public void bringForward(Element obj)
public boolean isToBack(Element obj)
public boolean isToFront(Element obj)
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Straigthforwardly computed from the diagonal
getBoundingBox in interface Elementprotected void updateBoundingBox()
public void setAttributeSet(PicAttributeSet set)
setAttributeSet in interface ElementsetAttributeSet in class AbstractElementset - a new AttributeSet for this Element ; this actually make a deep copy of the
given attribute set beforehands.public void setAttribute(PicAttributeName name, java.lang.Object value)
setAttribute in interface ElementsetAttribute in class AbstractElementpublic java.lang.String toString()
toString in class AbstractElementpublic boolean add(java.lang.Object o)
add in interface java.util.Collectionpublic boolean addAll(java.util.Collection c)
addAll in interface java.util.Collectionpublic void clear()
clear in interface java.util.Collectionpublic int size()
size in interface java.util.Collectionpublic boolean isEmpty()
isEmpty in interface java.util.Collectionpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectionpublic java.lang.Object[] toArray()
toArray in interface java.util.Collectionpublic java.lang.Object[] toArray(java.lang.Object[] a)
toArray in interface java.util.Collectionpublic boolean remove(java.lang.Object o)
remove in interface java.util.Collectiono - element to be removed from this BranchElement, if present.public boolean containsAll(java.util.Collection c)
containsAll in interface java.util.Collectionpublic boolean removeAll(java.util.Collection c)
removeAll in interface java.util.Collectionc - elements to be removed from this collection.public boolean retainAll(java.util.Collection c)
retainAll in interface java.util.Collectionc - elements to be retained in this collection.public boolean equals(java.lang.Object o)
equals in interface java.util.Collectionequals in class java.lang.Objectpublic java.util.ArrayList createFilteredCollection(java.lang.Class clazz)
public boolean containsClass(java.lang.Class clazz)
Submit a bug : syd@jpicedt.org