Class CompositeGraphicsNode

java.lang.Object
io.sf.carte.echosvg.gvt.AbstractGraphicsNode
io.sf.carte.echosvg.gvt.CompositeGraphicsNode
All Implemented Interfaces:
GraphicsNode, Iterable<GraphicsNode>, Collection<GraphicsNode>, List<GraphicsNode>, SequencedCollection<GraphicsNode>
Direct Known Subclasses:
CanvasGraphicsNode, ImageNode, RootGraphicsNode

public class CompositeGraphicsNode extends AbstractGraphicsNode implements List<GraphicsNode>
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.
  • Field Details

    • VIEWPORT

      public static final Rectangle2D VIEWPORT
    • NULL_RECT

      public static final 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 Rectangle2D backgroundEnableRgn
      This flag indicates if this node has BackgroundEnable = 'new'. If so traversal of the gvt tree can halt here.
  • Constructor Details

    • CompositeGraphicsNode

      public CompositeGraphicsNode()
      Constructs a new empty CompositeGraphicsNode.
  • Method Details

    • getChildren

      public List<GraphicsNode> getChildren()
      Returns the list of children.
    • setBackgroundEnable

      public void setBackgroundEnable(Rectangle2D bgRgn)
      Sets the enable background property to the specified rectangle.
      Parameters:
      bgRgn - the region that defines the background enable property
    • getBackgroundEnable

      public 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:
      setVisible in interface GraphicsNode
      Overrides:
      setVisible in class AbstractGraphicsNode
      Parameters:
      isVisible - If true this node is visible
    • primitivePaint

      public void primitivePaint(Graphics2D g2d)
      Paints this node without applying Filter, Mask, Composite, and clip.
      Specified by:
      primitivePaint in interface GraphicsNode
      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:
      invalidateGeometryCache in class AbstractGraphicsNode
    • getPrimitiveBounds

      public Rectangle2D getPrimitiveBounds()
      Returns the bounds of the area covered by this node's primitive paint.
      Specified by:
      getPrimitiveBounds in interface GraphicsNode
    • getTransformedBBox

      public static Rectangle2D getTransformedBBox(Rectangle2D r2d, 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 Rectangle2D getTransformedPrimitiveBounds(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:
      getTransformedPrimitiveBounds in interface GraphicsNode
      Overrides:
      getTransformedPrimitiveBounds in class AbstractGraphicsNode
      Parameters:
      txf - the affine transform with which this node's transform should be concatenated. Should not be null.
    • getGeometryBounds

      public 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:
      getGeometryBounds in interface GraphicsNode
    • getTransformedGeometryBounds

      public Rectangle2D getTransformedGeometryBounds(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:
      getTransformedGeometryBounds in interface GraphicsNode
      Overrides:
      getTransformedGeometryBounds in class AbstractGraphicsNode
      Parameters:
      txf - the affine transform with which this node's transform should be concatenated. Should not be null.
    • getSensitiveBounds

      public 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:
      getSensitiveBounds in interface GraphicsNode
    • getTransformedSensitiveBounds

      public Rectangle2D getTransformedSensitiveBounds(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:
      getTransformedSensitiveBounds in interface GraphicsNode
      Overrides:
      getTransformedSensitiveBounds in class AbstractGraphicsNode
      Parameters:
      txf - the affine transform with which this node's transform should be concatenated. Should not be null.
    • contains

      public boolean contains(Point2D p)
      Returns true if the specified Point2D is inside the boundary of this node, false otherwise.
      Specified by:
      contains in interface GraphicsNode
      Overrides:
      contains in class AbstractGraphicsNode
      Parameters:
      p - the specified Point2D in the user space
    • nodeHitAt

      public GraphicsNode nodeHitAt(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:
      nodeHitAt in interface GraphicsNode
      Overrides:
      nodeHitAt in class AbstractGraphicsNode
      Parameters:
      p - the specified Point2D in the user space
    • getOutline

      public Shape getOutline()
      Returns the outline of this node.
      Specified by:
      getOutline in interface GraphicsNode
    • setRoot

      protected void setRoot(RootGraphicsNode newRoot)
      Sets the root node of this grahics node and modify all its children.
      Overrides:
      setRoot in class AbstractGraphicsNode
      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:
      size in interface Collection<GraphicsNode>
      Specified by:
      size in interface List<GraphicsNode>
    • isEmpty

      public boolean isEmpty()
      Returns true if this composite graphics node does not contain graphics node, false otherwise.
      Specified by:
      isEmpty in interface Collection<GraphicsNode>
      Specified by:
      isEmpty in interface List<GraphicsNode>
    • contains

      public boolean contains(Object node)
      Returns true if this composite graphics node contains the specified graphics node, false otherwise.
      Specified by:
      contains in interface Collection<GraphicsNode>
      Specified by:
      contains in interface List<GraphicsNode>
      Parameters:
      node - the node to check
    • iterator

      public Iterator<GraphicsNode> iterator()
      Returns an iterator over the children of this graphics node.
      Specified by:
      iterator in interface Collection<GraphicsNode>
      Specified by:
      iterator in interface Iterable<GraphicsNode>
      Specified by:
      iterator in interface List<GraphicsNode>
    • toArray

      public GraphicsNode[] 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:
      toArray in interface Collection<GraphicsNode>
      Specified by:
      toArray in interface List<GraphicsNode>
    • toArray

      public <T> T[] toArray(T[] 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:
      toArray in interface Collection<GraphicsNode>
      Specified by:
      toArray in interface List<GraphicsNode>
      Parameters:
      a - the array to fit if possible
    • get

      public GraphicsNode get(int index)
      Returns the graphics node at the specified position in the children list.
      Specified by:
      get in interface List<GraphicsNode>
      Parameters:
      index - the index of the graphics node to return
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • set

      public GraphicsNode set(int index, GraphicsNode o)
      Replaces the graphics node at the specified position in the children list with the specified graphics node.
      Specified by:
      set in interface List<GraphicsNode>
      Parameters:
      index - the index of the graphics node to replace
      o - the graphics node to be stored at the specified position
      Returns:
      the graphics node previously at the specified position
      Throws:
      IndexOutOfBoundsException - if the index is out of range
      IllegalArgumentException - if the node is not an instance of GraphicsNode
    • add

      public boolean add(GraphicsNode node)
      Adds the specified graphics node to this composite graphics node.
      Specified by:
      add in interface Collection<GraphicsNode>
      Specified by:
      add in interface List<GraphicsNode>
      Parameters:
      node - the graphics node to add
      Returns:
      true (as per the general contract of Collection.add)
      Throws:
      IllegalArgumentException - if the node is not an instance of GraphicsNode
    • add

      public void add(int index, GraphicsNode node)
      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:
      add in interface List<GraphicsNode>
      Parameters:
      index - the position at which the specified graphics node is to be inserted.
      node - the graphics node to be inserted.
      Throws:
      IndexOutOfBoundsException - if the index is out of range
      IllegalArgumentException - if the node is not an instance of GraphicsNode
    • addAll

      public boolean addAll(Collection<? extends GraphicsNode> c)
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      addAll in interface Collection<GraphicsNode>
      Specified by:
      addAll in interface List<GraphicsNode>
    • addAll

      public boolean addAll(int index, Collection<? extends GraphicsNode> c)
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      addAll in interface List<GraphicsNode>
    • remove

      public boolean remove(Object o)
      Removes the first instance of the specified graphics node from the children list.
      Specified by:
      remove in interface Collection<GraphicsNode>
      Specified by:
      remove in interface List<GraphicsNode>
      Parameters:
      o - the node the remove
      Returns:
      true if the children list contains the specified graphics node
      Throws:
      IllegalArgumentException - if the node is not an instance of GraphicsNode
      IndexOutOfBoundsException - when o is not in children list
    • remove

      public GraphicsNode 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:
      remove in interface List<GraphicsNode>
      Parameters:
      index - the position of the graphics node to remove
      Returns:
      the graphics node that was removed
      Throws:
      IndexOutOfBoundsException - if index out of range
    • removeAll

      public boolean removeAll(Collection<?> c)
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      removeAll in interface Collection<GraphicsNode>
      Specified by:
      removeAll in interface List<GraphicsNode>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      retainAll in interface Collection<GraphicsNode>
      Specified by:
      retainAll in interface List<GraphicsNode>
    • clear

      public void clear()
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      clear in interface Collection<GraphicsNode>
      Specified by:
      clear in interface List<GraphicsNode>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Returns true if this composite graphics node contains all the graphics node in the specified collection, false otherwise.
      Specified by:
      containsAll in interface Collection<GraphicsNode>
      Specified by:
      containsAll in interface List<GraphicsNode>
      Parameters:
      c - the collection to be checked for containment
    • indexOf

      public int indexOf(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:
      indexOf in interface List<GraphicsNode>
      Parameters:
      node - the graphics node to search for
    • lastIndexOf

      public int lastIndexOf(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:
      lastIndexOf in interface List<GraphicsNode>
      Parameters:
      node - the graphics node to search for
    • listIterator

      public ListIterator<GraphicsNode> listIterator()
      Returns an iterator over the children of this graphics node.
      Specified by:
      listIterator in interface List<GraphicsNode>
    • listIterator

      public ListIterator<GraphicsNode> listIterator(int index)
      Returns an iterator over the children of this graphics node, starting at the specified position in the children list.
      Specified by:
      listIterator in interface List<GraphicsNode>
      Parameters:
      index - the index of the first graphics node to return from the children list
    • subList

      public List<GraphicsNode> subList(int fromIndex, int toIndex)
      Not supported - Throws UnsupportedOperationException exception.
      Specified by:
      subList in interface List<GraphicsNode>
    • 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.