Package org.apache.batik.gvt
Class CompositeGraphicsNode
- java.lang.Object
-
- org.apache.batik.gvt.AbstractGraphicsNode
-
- org.apache.batik.gvt.CompositeGraphicsNode
-
- All Implemented Interfaces:
java.lang.Iterable,java.util.Collection,java.util.List,GraphicsNode
- Direct Known Subclasses:
CanvasGraphicsNode,ImageNode,RootGraphicsNode
public class CompositeGraphicsNode extends AbstractGraphicsNode implements java.util.List
A CompositeGraphicsNode is a graphics node that can contain graphics nodes.
Note: this class is a 'little bit aware of' other threads, but not really threadsafe.- Version:
- $Id: CompositeGraphicsNode.java 1808023 2017-09-11 12:43:22Z ssteiner $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classCompositeGraphicsNode.ItrAn implementation of the java.util.Iterator interface.private classCompositeGraphicsNode.ListItrAn implementation of the java.util.ListIterator interface.
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.geom.Rectangle2DbackgroundEnableRgnThis flag indicates if this node has BackgroundEnable = 'new'.protected GraphicsNode[]childrenThe children of this composite graphics node.protected intcountThe number of children of this composite graphics node.private java.awt.geom.Rectangle2DgeometryBoundsInternal Cache: Geometry bounds for this node, not taking into account any of its children rendering attributes into accountprotected intmodCountThe number of times the children list has been structurally modified.static java.awt.geom.Rectangle2DNULL_RECTprivate java.awt.ShapeoutlineInternal Cache: the outline.private java.awt.geom.Rectangle2DprimitiveBoundsInternal Cache: Primitive bounds.private java.awt.geom.Rectangle2DsensitiveBoundsInternal Cache: Sensitive bounds.static java.awt.geom.Rectangle2DVIEWPORT-
Fields inherited from class org.apache.batik.gvt.AbstractGraphicsNode
changeCompletedEvent, changeStartedEvent, clip, composite, enableBackgroundGraphicsNodeRable, EPSILON, filter, graphicsNodeRable, hints, inverseTransform, isVisible, listeners, mask, parent, pointerEventType, root, transform, weakRef
-
Fields inherited from interface org.apache.batik.gvt.GraphicsNode
ALL, FILL, IDENTITY, NONE, PAINTED, STROKE, VISIBLE, VISIBLE_FILL, VISIBLE_PAINTED, VISIBLE_STROKE
-
-
Constructor Summary
Constructors Constructor Description CompositeGraphicsNode()Constructs a new emptyCompositeGraphicsNode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, java.lang.Object o)Inserts the specified graphics node at the specified position in this children list.booleanadd(java.lang.Object o)Adds the specified graphics node to this composite graphics node.booleanaddAll(int index, java.util.Collection c)Not supported - ThrowsUnsupportedOperationExceptionexception.booleanaddAll(java.util.Collection c)Not supported - ThrowsUnsupportedOperationExceptionexception.private voidcheckRange(int index)Checks if the given index is in range.voidclear()Not supported - ThrowsUnsupportedOperationExceptionexception.booleancontains(java.awt.geom.Point2D p)Returns true if the specified Point2D is inside the boundary of this node, false otherwise.booleancontains(java.lang.Object node)Returns true if this composite graphics node contains the specified graphics node, false otherwise.booleancontainsAll(java.util.Collection c)Returns true if this composite graphics node contains all the graphics node in the specified collection, false otherwise.voidensureCapacity(int minCapacity)Increases the capacity of the children list, if necessary, to ensure that it can hold at least the number of graphics nodes specified by the minimum capacity argument.java.lang.Objectget(int index)Returns the graphics node at the specified position in the children list.java.awt.geom.Rectangle2DgetBackgroundEnable()Returns the region defining the background enable property.java.util.ListgetChildren()Returns the list of children.java.awt.geom.Rectangle2DgetGeometryBounds()Returns the bounds of the area covered by this node, without taking any of its rendering attributes into account.java.awt.ShapegetOutline()Returns the outline of this node.java.awt.geom.Rectangle2DgetPrimitiveBounds()Returns the bounds of the area covered by this node's primitive paint.java.awt.geom.Rectangle2DgetSensitiveBounds()Returns the bounds of the sensitive area covered by this node, This includes the stroked area but does not include the effects of clipping, masking or filtering.static java.awt.geom.Rectangle2DgetTransformedBBox(java.awt.geom.Rectangle2D r2d, java.awt.geom.AffineTransform t)Transforms a Rectangle 2D by an affine transform.java.awt.geom.Rectangle2DgetTransformedGeometryBounds(java.awt.geom.AffineTransform txf)Returns the bounds of the area covered by this node, without taking any of its rendering attribute into accoun.java.awt.geom.Rectangle2DgetTransformedPrimitiveBounds(java.awt.geom.AffineTransform txf)Returns the bounds of this node's primitivePaint after applying the input transform (if any), concatenated with this node's transform (if any).java.awt.geom.Rectangle2DgetTransformedSensitiveBounds(java.awt.geom.AffineTransform txf)Returns the bounds of the sensitive area covered by this node, This includes the stroked area but does not include the effects of clipping, masking or filtering.intindexOf(java.lang.Object node)Returns the index in the children list of the specified graphics node or -1 if the children list does not contain this graphics node.protected voidinvalidateGeometryCache()Invalidates the cached geometric bounds.booleanisEmpty()Returns true if this composite graphics node does not contain graphics node, false otherwise.java.util.Iteratoriterator()Returns an iterator over the children of this graphics node.intlastIndexOf(java.lang.Object node)Returns the index in this children list of the last occurence of the specified graphics node, or -1 if the list does not contain this graphics node.java.util.ListIteratorlistIterator()Returns an iterator over the children of this graphics node.java.util.ListIteratorlistIterator(int index)Returns an iterator over the children of this graphics node, starting at the specified position in the children list.GraphicsNodenodeHitAt(java.awt.geom.Point2D p)Returns the GraphicsNode containing point p if this node or one of its children is sensitive to mouse events at p.voidprimitivePaint(java.awt.Graphics2D g2d)Paints this node without applying Filter, Mask, Composite, and clip.java.lang.Objectremove(int index)Removes the graphics node at the specified position in the children list.booleanremove(java.lang.Object o)Removes the first instance of the specified graphics node from the children list.booleanremoveAll(java.util.Collection c)Not supported - ThrowsUnsupportedOperationExceptionexception.booleanretainAll(java.util.Collection c)Not supported - ThrowsUnsupportedOperationExceptionexception.java.lang.Objectset(int index, java.lang.Object o)Replaces the graphics node at the specified position in the children list with the specified graphics node.voidsetBackgroundEnable(java.awt.geom.Rectangle2D bgRgn)Sets the enable background property to the specified rectangle.protected voidsetRoot(RootGraphicsNode newRoot)Sets the root node of this grahics node and modify all its children.voidsetVisible(boolean isVisible)Sets if this node is visible or not depending on the specified value.intsize()Returns the number of children of this composite graphics node.java.util.ListsubList(int fromIndex, int toIndex)Not supported - ThrowsUnsupportedOperationExceptionexception.java.lang.Object[]toArray()Returns an array containing all of the graphics node in the children list of this composite graphics node in the correct order.java.lang.Object[]toArray(java.lang.Object[] a)Returns an array containing all of the graphics node in the children list of this composite graphics node in the correct order.-
Methods inherited from class org.apache.batik.gvt.AbstractGraphicsNode
fireGraphicsNodeChangeCompleted, fireGraphicsNodeChangeStarted, fireGraphicsNodeChangeStarted, fireGraphicsNodeChangeStarted, getBounds, getClip, getComposite, getEnableBackgroundGraphicsNodeRable, getFilter, getGlobalTransform, getGraphicsNodeRable, getInverseTransform, getMask, getParent, getPointerEventType, getRenderingHints, getRoot, getTransform, getTransformedBounds, getWeakReference, intersects, isAntialiasedClip, isOffscreenBufferNeeded, isVisible, normalizeRectangle, paint, setClip, setComposite, setFilter, setMask, setParent, setPointerEventType, setRenderingHint, setRenderingHints, setRenderingHints, setTransform
-
-
-
-
Field Detail
-
VIEWPORT
public static final java.awt.geom.Rectangle2D VIEWPORT
-
NULL_RECT
public static final java.awt.geom.Rectangle2D NULL_RECT
-
children
protected GraphicsNode[] children
The children of this composite graphics node.
-
count
protected volatile int count
The number of children of this composite graphics node.
-
modCount
protected volatile int modCount
The number of times the children list has been structurally modified.
-
backgroundEnableRgn
protected java.awt.geom.Rectangle2D backgroundEnableRgn
This flag indicates if this node has BackgroundEnable = 'new'. If so traversal of the gvt tree can halt here.
-
geometryBounds
private volatile java.awt.geom.Rectangle2D geometryBounds
Internal Cache: Geometry bounds for this node, not taking into account any of its children rendering attributes into account
-
primitiveBounds
private volatile java.awt.geom.Rectangle2D primitiveBounds
Internal Cache: Primitive bounds.
-
sensitiveBounds
private volatile java.awt.geom.Rectangle2D sensitiveBounds
Internal Cache: Sensitive bounds.
-
outline
private java.awt.Shape outline
Internal Cache: the outline.
-
-
Method Detail
-
getChildren
public java.util.List getChildren()
Returns the list of children.
-
setBackgroundEnable
public void setBackgroundEnable(java.awt.geom.Rectangle2D bgRgn)
Sets the enable background property to the specified rectangle.- Parameters:
bgRgn- the region that defines the background enable property
-
getBackgroundEnable
public java.awt.geom.Rectangle2D getBackgroundEnable()
Returns the region defining the background enable property.
-
setVisible
public void setVisible(boolean isVisible)
Sets if this node is visible or not depending on the specified value. Don't fire a graphicsNodeChange event because this doesn't really effect us (it effects our children through CSS inheritence).- Specified by:
setVisiblein interfaceGraphicsNode- Overrides:
setVisiblein classAbstractGraphicsNode- Parameters:
isVisible- If true this node is visible
-
primitivePaint
public void primitivePaint(java.awt.Graphics2D g2d)
Paints this node without applying Filter, Mask, Composite, and clip.- Specified by:
primitivePaintin interfaceGraphicsNode- Parameters:
g2d- the Graphics2D to use
-
invalidateGeometryCache
protected void invalidateGeometryCache()
Invalidates the cached geometric bounds. This method is called each time an attribute that affects the bounds of this node changed.- Overrides:
invalidateGeometryCachein classAbstractGraphicsNode
-
getPrimitiveBounds
public java.awt.geom.Rectangle2D getPrimitiveBounds()
Returns the bounds of the area covered by this node's primitive paint.- Specified by:
getPrimitiveBoundsin interfaceGraphicsNode
-
getTransformedBBox
public static java.awt.geom.Rectangle2D getTransformedBBox(java.awt.geom.Rectangle2D r2d, java.awt.geom.AffineTransform t)Transforms a Rectangle 2D by an affine transform. It assumes the transform is only scale/translate so there is no loss of precision over transforming the source geometry.
-
getTransformedPrimitiveBounds
public java.awt.geom.Rectangle2D getTransformedPrimitiveBounds(java.awt.geom.AffineTransform txf)
Returns the bounds of this node's primitivePaint after applying the input transform (if any), concatenated with this node's transform (if any).- Specified by:
getTransformedPrimitiveBoundsin interfaceGraphicsNode- Overrides:
getTransformedPrimitiveBoundsin classAbstractGraphicsNode- Parameters:
txf- the affine transform with which this node's transform should be concatenated. Should not be null.
-
getGeometryBounds
public java.awt.geom.Rectangle2D getGeometryBounds()
Returns the bounds of the area covered by this node, without taking any of its rendering attributes into account. That is, exclusive of any clipping, masking, filtering or stroking, for example.- Specified by:
getGeometryBoundsin interfaceGraphicsNode
-
getTransformedGeometryBounds
public java.awt.geom.Rectangle2D getTransformedGeometryBounds(java.awt.geom.AffineTransform txf)
Returns the bounds of the area covered by this node, without taking any of its rendering attribute into accoun. That is, exclusive of any clipping, masking, filtering or stroking, for example. The returned value is transformed by the concatenation of the input transform and this node's transform.- Specified by:
getTransformedGeometryBoundsin interfaceGraphicsNode- Overrides:
getTransformedGeometryBoundsin classAbstractGraphicsNode- Parameters:
txf- the affine transform with which this node's transform should be concatenated. Should not be null.
-
getSensitiveBounds
public java.awt.geom.Rectangle2D getSensitiveBounds()
Returns the bounds of the sensitive area covered by this node, This includes the stroked area but does not include the effects of clipping, masking or filtering.- Specified by:
getSensitiveBoundsin interfaceGraphicsNode
-
getTransformedSensitiveBounds
public java.awt.geom.Rectangle2D getTransformedSensitiveBounds(java.awt.geom.AffineTransform txf)
Returns the bounds of the sensitive area covered by this node, This includes the stroked area but does not include the effects of clipping, masking or filtering. The returned value is transformed by the concatenation of the input transform and this node's transform.- Specified by:
getTransformedSensitiveBoundsin interfaceGraphicsNode- Overrides:
getTransformedSensitiveBoundsin classAbstractGraphicsNode- Parameters:
txf- the affine transform with which this node's transform should be concatenated. Should not be null.
-
contains
public boolean contains(java.awt.geom.Point2D p)
Returns true if the specified Point2D is inside the boundary of this node, false otherwise.- Specified by:
containsin interfaceGraphicsNode- Overrides:
containsin classAbstractGraphicsNode- Parameters:
p- the specified Point2D in the user space
-
nodeHitAt
public GraphicsNode nodeHitAt(java.awt.geom.Point2D p)
Returns the GraphicsNode containing point p if this node or one of its children is sensitive to mouse events at p.- Specified by:
nodeHitAtin interfaceGraphicsNode- Overrides:
nodeHitAtin classAbstractGraphicsNode- Parameters:
p- the specified Point2D in the user space
-
getOutline
public java.awt.Shape getOutline()
Returns the outline of this node.- Specified by:
getOutlinein interfaceGraphicsNode
-
setRoot
protected void setRoot(RootGraphicsNode newRoot)
Sets the root node of this grahics node and modify all its children.- Overrides:
setRootin classAbstractGraphicsNode- Parameters:
newRoot- the new root node of this node
-
size
public int size()
Returns the number of children of this composite graphics node.- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List
-
isEmpty
public boolean isEmpty()
Returns true if this composite graphics node does not contain graphics node, false otherwise.- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.List
-
contains
public boolean contains(java.lang.Object node)
Returns true if this composite graphics node contains the specified graphics node, false otherwise.- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.List- Parameters:
node- the node to check
-
iterator
public java.util.Iterator iterator()
Returns an iterator over the children of this graphics node.- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List
-
toArray
public java.lang.Object[] toArray()
Returns an array containing all of the graphics node in the children list of this composite graphics node in the correct order.- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the graphics node in the children list of this composite graphics node in the correct order. If the children list fits in the specified array, it is returned therein. Otherwise, a new array is allocated.- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List- Parameters:
a- the array to fit if possible
-
get
public java.lang.Object get(int index)
Returns the graphics node at the specified position in the children list.- Specified by:
getin interfacejava.util.List- Parameters:
index- the index of the graphics node to return- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range
-
set
public java.lang.Object set(int index, java.lang.Object o)Replaces the graphics node at the specified position in the children list with the specified graphics node.- Specified by:
setin interfacejava.util.List- Parameters:
index- the index of the graphics node to replaceo- the graphics node to be stored at the specified position- Returns:
- the graphics node previously at the specified position
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of rangejava.lang.IllegalArgumentException- if the node is not an instance of GraphicsNode
-
add
public boolean add(java.lang.Object o)
Adds the specified graphics node to this composite graphics node.- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List- Parameters:
o- the graphics node to add- Returns:
- true (as per the general contract of Collection.add)
- Throws:
java.lang.IllegalArgumentException- if the node is not an instance of GraphicsNode
-
add
public void add(int index, java.lang.Object o)Inserts the specified graphics node at the specified position in this children list. Shifts the graphics node currently at that position (if any) and any subsequent graphics nodes to the right (adds one to their indices).- Specified by:
addin interfacejava.util.List- Parameters:
index- the position at which the specified graphics node is to be inserted.o- the graphics node to be inserted.- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of rangejava.lang.IllegalArgumentException- if the node is not an instance of GraphicsNode
-
addAll
public boolean addAll(java.util.Collection c)
Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.List
-
addAll
public boolean addAll(int index, java.util.Collection c)Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
addAllin interfacejava.util.List
-
remove
public boolean remove(java.lang.Object o)
Removes the first instance of the specified graphics node from the children list.- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.List- Parameters:
o- the node the remove- Returns:
- true if the children list contains the specified graphics node
- Throws:
java.lang.IllegalArgumentException- if the node is not an instance of GraphicsNodejava.lang.IndexOutOfBoundsException- when o is not in children list
-
remove
public java.lang.Object remove(int index)
Removes the graphics node at the specified position in the children list. Shifts any subsequent graphics nodes to the left (subtracts one from their indices).- Specified by:
removein interfacejava.util.List- Parameters:
index- the position of the graphics node to remove- Returns:
- the graphics node that was removed
- Throws:
java.lang.IndexOutOfBoundsException- if index out of range
-
removeAll
public boolean removeAll(java.util.Collection c)
Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
removeAllin interfacejava.util.Collection- Specified by:
removeAllin interfacejava.util.List
-
retainAll
public boolean retainAll(java.util.Collection c)
Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
retainAllin interfacejava.util.Collection- Specified by:
retainAllin interfacejava.util.List
-
clear
public void clear()
Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.List
-
containsAll
public boolean containsAll(java.util.Collection c)
Returns true if this composite graphics node contains all the graphics node in the specified collection, false otherwise.- Specified by:
containsAllin interfacejava.util.Collection- Specified by:
containsAllin interfacejava.util.List- Parameters:
c- the collection to be checked for containment
-
indexOf
public int indexOf(java.lang.Object node)
Returns the index in the children list of the specified graphics node or -1 if the children list does not contain this graphics node.- Specified by:
indexOfin interfacejava.util.List- Parameters:
node- the graphics node to search for
-
lastIndexOf
public int lastIndexOf(java.lang.Object node)
Returns the index in this children list of the last occurence of the specified graphics node, or -1 if the list does not contain this graphics node.- Specified by:
lastIndexOfin interfacejava.util.List- Parameters:
node- the graphics node to search for
-
listIterator
public java.util.ListIterator listIterator()
Returns an iterator over the children of this graphics node.- Specified by:
listIteratorin interfacejava.util.List
-
listIterator
public java.util.ListIterator listIterator(int index)
Returns an iterator over the children of this graphics node, starting at the specified position in the children list.- Specified by:
listIteratorin interfacejava.util.List- Parameters:
index- the index of the first graphics node to return from the children list
-
subList
public java.util.List subList(int fromIndex, int toIndex)Not supported - ThrowsUnsupportedOperationExceptionexception.- Specified by:
subListin interfacejava.util.List
-
checkRange
private void checkRange(int index)
Checks if the given index is in range. If not, throws an appropriate runtime exception.- Parameters:
index- the index to check
-
ensureCapacity
public void ensureCapacity(int minCapacity)
Increases the capacity of the children list, if necessary, to ensure that it can hold at least the number of graphics nodes specified by the minimum capacity argument.- Parameters:
minCapacity- the desired minimum capacity.
-
-