You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/09/13 11:37:23 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt AbstractGraphicsNode.java CompositeGraphicsNode.java ShapeNode.java
tkormann 01/09/13 02:37:23
Modified: sources/org/apache/batik/gvt AbstractGraphicsNode.java
CompositeGraphicsNode.java ShapeNode.java
Log:
start cleaning GVT (only update the javadoc at this time).
Revision Changes Path
1.24 +162 -166 xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java
Index: AbstractGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- AbstractGraphicsNode.java 2001/09/13 08:42:49 1.23
+++ AbstractGraphicsNode.java 2001/09/13 09:37:23 1.24
@@ -48,7 +48,7 @@
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
* @author <a href="mailto:etissandier@ilog.fr">Emmanuel Tissandier</a>
* @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
- * @version $Id: AbstractGraphicsNode.java,v 1.23 2001/09/13 08:42:49 tkormann Exp $
+ * @version $Id: AbstractGraphicsNode.java,v 1.24 2001/09/13 09:37:23 tkormann Exp $
*/
public abstract class AbstractGraphicsNode implements GraphicsNode {
@@ -136,6 +136,7 @@
/**
* Sets the transform of this node.
+ *
* @param newTransform the new transform of this node
*/
public void setTransform(AffineTransform newTransform) {
@@ -157,14 +158,14 @@
}
/**
- * Returns the transform of this node.
+ * Returns the transform of this node or null if any.
*/
public AffineTransform getTransform() {
return transform;
}
/**
- * Returns the inverse transform of this node
+ * Returns the inverse transform for this node.
*/
public AffineTransform getInverseTransform(){
return inverseTransform;
@@ -188,6 +189,7 @@
/**
* Sets the composite of this node.
+ *
* @param composite the composite of this node
*/
public void setComposite(Composite newComposite) {
@@ -196,7 +198,7 @@
}
/**
- * Returns the composite of this node.
+ * Returns the composite of this node or null if any.
*/
public Composite getComposite() {
return composite;
@@ -204,6 +206,7 @@
/**
* Sets if this node is visible or not depending on the specified value.
+ *
* @param isVisible If true this node is visible
*/
public void setVisible(boolean isVisible) {
@@ -211,18 +214,12 @@
}
/**
- * Determines whether or not this node is visible when its parent
- * is visible. Nodes are initially visible.
- * @return true if this node is visible, false otherwise
+ * Returns true if this node is visible, false otherwise.
*/
public boolean isVisible() {
return isVisible;
}
- /**
- * Sets the clipping filter for this node.
- * @param newClipper the new clipping filter of this node
- */
public void setClip(ClipRable newClipper) {
invalidateGeometryCache();
this.clip = newClipper;
@@ -236,11 +233,12 @@
}
/**
- * Maps the specified key to the specified value in the rendering
- * hints of this node.
+ * Maps the specified key to the specified value in the rendering hints of
+ * this node.
+ *
* @param key the key of the hint to be set
* @param value the value indicating preferences for the specified
- * hint category.
+ * hint category.
*/
public void setRenderingHint(RenderingHints.Key key, Object value) {
if (this.hints == null) {
@@ -253,6 +251,7 @@
/**
* Copies all of the mappings from the specified Map to the
* rendering hints of this node.
+ *
* @param hints the rendering hints to be set
*/
public void setRenderingHints(Map hints) {
@@ -265,6 +264,7 @@
/**
* Sets the rendering hints of this node.
+ *
* @param newHints the new rendering hints of this node
*/
public void setRenderingHints(RenderingHints newHints) {
@@ -280,6 +280,7 @@
/**
* Sets the mask of this node.
+ *
* @param newMask the new mask of this node
*/
public void setMask(Mask newMask) {
@@ -296,6 +297,7 @@
/**
* Sets the filter of this node.
+ *
* @param newFilter the new filter of this node
*/
public void setFilter(Filter newFilter) {
@@ -318,7 +320,6 @@
* Paints this node.
*
* @param g2d the Graphics2D to use
- * @param rc the GraphicsNodeRenderContext to use
*/
public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc){
@@ -334,11 +335,8 @@
return; // No point in drawing
}
- //
- // Set up graphic context. It is important to setup the
- // transform first, because the clip is defined in this
- // node's user space.
- //
+ // Set up graphic context. It is important to setup the transform first,
+ // because the clip is defined in this node's user space.
Shape defaultClip = g2d.getClip();
Composite defaultComposite = g2d.getComposite();
AffineTransform defaultTransform = g2d.getTransform();
@@ -365,10 +363,8 @@
rc.setRenderingHints(g2d.getRenderingHints());
rc.setAreaOfInterest(curClip);
- //
// Check if any painting is needed at all. Get the clip (in user space)
// and see if it intersects with this node's bounds (in user space).
- //
boolean paintNeeded = true;
Rectangle2D bounds = getBounds(rc);
Shape g2dClip = g2d.getClip();
@@ -382,10 +378,7 @@
}
}
- //
// Only paint if needed.
- //
- // paintNeeded = true;
if (paintNeeded){
AffineTransform txf = g2d.getTransform();
boolean antialiasedClip = false;
@@ -471,8 +464,8 @@
}
/**
- * Returns true of an offscreen buffer is needed to render this
- * node, false otherwise.
+ * Returns true of an offscreen buffer is needed to render this node, false
+ * otherwise.
*/
protected boolean isOffscreenBufferNeeded() {
return ((filter != null) ||
@@ -519,10 +512,36 @@
// Event support methods
//
+ /**
+ * Dispatches the specified event to the interested registered listeners.
+ *
+ * @param evt the event to dispatch
+ */
+ public void dispatchEvent(GraphicsNodeEvent evt) {
+ switch(evt.getID()) {
+ case GraphicsNodeMouseEvent.MOUSE_PRESSED:
+ case GraphicsNodeMouseEvent.MOUSE_RELEASED:
+ case GraphicsNodeMouseEvent.MOUSE_MOVED:
+ case GraphicsNodeMouseEvent.MOUSE_ENTERED:
+ case GraphicsNodeMouseEvent.MOUSE_EXITED:
+ case GraphicsNodeMouseEvent.MOUSE_DRAGGED:
+ processMouseEvent((GraphicsNodeMouseEvent)evt);
+ break;
+ case GraphicsNodeKeyEvent.KEY_TYPED:
+ case GraphicsNodeKeyEvent.KEY_PRESSED:
+ case GraphicsNodeKeyEvent.KEY_RELEASED:
+ processKeyEvent((GraphicsNodeKeyEvent)evt);
+ break;
+ default:
+ break;
+ }
+ }
+
/**
- * Adds the specified graphics node mouse listener to receive
- * graphics node mouse events from this node.
- * @param l the graphics node mouse listener to add
+ * Adds the specified graphics node mouse listener to receive graphics node
+ * mouse events from this node.
+ *
+ * @param l the graphics node mouse listener to add
*/
public void addGraphicsNodeMouseListener(GraphicsNodeMouseListener l) {
if (listeners == null) {
@@ -532,9 +551,10 @@
}
/**
- * Removes the specified graphics node mouse listener so that it
- * no longer receives graphics node mouse events from this node.
- * @param l the graphics node mouse listener to remove
+ * Removes the specified graphics node mouse listener so that it no longer
+ * receives graphics node mouse events from this node.
+ *
+ * @param l the graphics node mouse listener to remove
*/
public void removeGraphicsNodeMouseListener(GraphicsNodeMouseListener l) {
if (listeners != null) {
@@ -543,9 +563,10 @@
}
/**
- * Adds the specified graphics node key listener to receive
- * graphics node key events from this node.
- * @param l the graphics node key listener to add
+ * Adds the specified graphics node key listener to receive graphics node
+ * key events from this node.
+ *
+ * @param l the graphics node key listener to add
*/
public void addGraphicsNodeKeyListener(GraphicsNodeKeyListener l) {
if (listeners == null) {
@@ -555,9 +576,10 @@
}
/**
- * Removes the specified graphics node key listener so that it
- * no longer receives graphics node key events from this node.
- * @param l the graphics node key listener to remove
+ * Removes the specified graphics node key listener so that it no longer
+ * receives graphics node key events from this node.
+ *
+ * @param l the graphics node key listener to remove
*/
public void removeGraphicsNodeKeyListener(GraphicsNodeKeyListener l) {
if (listeners != null) {
@@ -567,6 +589,7 @@
/**
* Sets the hit detector for this node.
+ *
* @param hitDetector the new hit detector
*/
public void setGraphicsNodeHitDetector(GraphicsNodeHitDetector hitDetector){
@@ -580,54 +603,10 @@
return hitDetector;
}
- /**
- * Returns an array of listeners that were added to this node and
- * of the specified type.
- * @param listenerType the type of the listeners to return
- */
- public EventListener [] getListeners(Class listenerType) {
- Object array =
- Array.newInstance(listenerType,
- listeners.getListenerCount(listenerType));
- Object[] pairElements = listeners.getListenerList();
- for (int i=0, j=0;i<pairElements.length-1;i+=2) {
- if (pairElements[i].equals(listenerType)) {
- Array.set(array, j, pairElements[i+1]);
- ++j;
- }
- }
- return (EventListener[]) array;
- // XXX: Code below is a jdk 1.3 dependency! Should be removed.
- //return listeners.getListeners(listenerType);
- }
-
- /**
- * Dispatches the specified event to the interested registered listeners.
- * @param evt the event to dispatch
- */
- public void dispatchEvent(GraphicsNodeEvent evt) {
- switch(evt.getID()) {
- case GraphicsNodeMouseEvent.MOUSE_PRESSED:
- case GraphicsNodeMouseEvent.MOUSE_RELEASED:
- case GraphicsNodeMouseEvent.MOUSE_MOVED:
- case GraphicsNodeMouseEvent.MOUSE_ENTERED:
- case GraphicsNodeMouseEvent.MOUSE_EXITED:
- case GraphicsNodeMouseEvent.MOUSE_DRAGGED:
- processMouseEvent((GraphicsNodeMouseEvent)evt);
- break;
- case GraphicsNodeKeyEvent.KEY_TYPED:
- case GraphicsNodeKeyEvent.KEY_PRESSED:
- case GraphicsNodeKeyEvent.KEY_RELEASED:
- processKeyEvent((GraphicsNodeKeyEvent)evt);
- break;
- default:
- break;
- }
- }
-
/**
- * Processes a mouse event occuring on this graphics node.
- * @param evt the event to process
+ * Dispatches a graphics node mouse event to this node or one of its child.
+ *
+ * @param evt the evt to dispatch
*/
public void processMouseEvent(GraphicsNodeMouseEvent evt) {
if ((listeners != null) && acceptEvent(evt)) {
@@ -678,12 +657,12 @@
evt.consume();
}
-
/**
- * Processes a key event occuring on this graphics node.
- * @param evt the event to process
+ * Dispatches a graphics node key event to this node or one of its child.
+ *
+ * @param evt the evt to dispatch
*/
- public void processKeyEvent(GraphicsNodeKeyEvent evt) {
+ public void processKeyEvent(GraphicsNodeKeyEvent evt) {
if ((listeners != null) && acceptEvent(evt)) {
GraphicsNodeKeyListener[] listeners =
(GraphicsNodeKeyListener[])
@@ -713,7 +692,18 @@
}
/**
+ * Returns an array of listeners that were added to this node and of the
+ * specified type.
+ *
+ * @param listenerType the type of the listeners to return
+ */
+ public EventListener [] getListeners(Class listenerType) {
+ return listeners.getListeners(listenerType);
+ }
+
+ /**
* Returns true is this node accepts the specified event, false otherwise.
+ *
* @param evt the event to check
* @return always true at this time
*/
@@ -733,8 +723,8 @@
}
/**
- * Returns the root of the GVT tree or <code>null</code> if
- * the node is not part of a GVT tree.
+ * Returns the root of the GVT tree or null if the node is not part of a GVT
+ * tree.
*/
public RootGraphicsNode getRoot() {
return root;
@@ -742,6 +732,7 @@
/**
* Sets the root node of this graphics node.
+ *
* @param newRoot the new root node of this node
*/
protected void setRoot(RootGraphicsNode newRoot) {
@@ -750,6 +741,7 @@
/**
* Sets the parent node of this graphics node.
+ *
* @param newParent the new parent node of this node
*/
protected void setParent(CompositeGraphicsNode newParent) {
@@ -773,12 +765,52 @@
}
/**
+ * Returns the bounds of this node in user space. This includes primitive
+ * paint, filtering, clipping and masking.
+ */
+ public Rectangle2D getBounds(GraphicsNodeRenderContext rc){
+ // Get the primitive bounds
+ // Rectangle2D bounds = null;
+ if(bounds == null){
+ // The painted region, before cliping, masking and compositing is
+ // either the area painted by the primitive paint or the area
+ // painted by the filter.
+ if(filter == null){
+ bounds = getPrimitiveBounds(rc);
+ } else {
+ bounds = filter.getBounds2D();
+ }
+ // Factor in the clipping area, if any
+ if(bounds != null){
+ if (clip != null) {
+ Rectangle2D clipR = clip.getClipPath().getBounds2D();
+ if (clipR.intersects(bounds))
+ Rectangle2D.intersect(bounds, clipR, bounds);
+ }
+ // Factor in the mask, if any
+ if (mask != null) {
+ Rectangle2D maskR = mask.getBounds2D();
+ if (maskR.intersects(bounds))
+ Rectangle2D.intersect(bounds, maskR, bounds);
+ }
+ }
+
+ // Make sure we haven't been interrupted
+ if (Thread.currentThread().isInterrupted()) {
+ // The Thread has been interrupted. Invalidate
+ // any cached values and proceed.
+ invalidateGeometryCache();
+ }
+ }
+ return bounds;
+ }
+
+ /**
* Returns the bounds of this node after applying the input transform
* (if any), concatenated with this node's transform (if any).
*
* @param txf the affine transform with which this node's transform should
* be concatenated. Should not be null.
- * @param rc the GraphicsNodeRenderContext
*/
public Rectangle2D getTransformedBounds(AffineTransform txf,
GraphicsNodeRenderContext rc){
@@ -793,7 +825,8 @@
// area painted by the filter.
Rectangle2D tBounds = null;
if(filter == null){
- tBounds = getTransformedPrimitiveBounds(txf, rc); /* Use txf, not t */
+ // Use txf, not t
+ tBounds = getTransformedPrimitiveBounds(txf, rc);
} else {
tBounds = t.createTransformedShape
(filter.getBounds2D()).getBounds2D();
@@ -801,23 +834,31 @@
// Factor in the clipping area, if any
if(tBounds != null){
if(clip != null) {
- tBounds.intersect(tBounds,
- t.createTransformedShape(clip.getClipPath()).getBounds2D(),
- tBounds);
+ tBounds.intersect
+ (tBounds,
+ t.createTransformedShape(clip.getClipPath()).getBounds2D(),
+ tBounds);
}
// Factor in the mask, if any
if(mask != null) {
- tBounds.intersect(tBounds,
- t.createTransformedShape(mask.getBounds2D()).getBounds2D(),
- tBounds);
+ tBounds.intersect
+ (tBounds,
+ t.createTransformedShape(mask.getBounds2D()).getBounds2D(),
+ tBounds);
}
}
return tBounds;
}
- public Rectangle2D getTransformedPrimitiveBounds
- (AffineTransform txf, GraphicsNodeRenderContext rc) {
+ /**
+ * Returns the bounds of this node's primitivePaint after applying the input
+ * transform (if any), concatenated with this node's transform (if any).
+ *
+ * @param txf the affine transform with which this node's transform should
+ * be concatenated. Should not be null.
+ */
+ public Rectangle2D getTransformedPrimitiveBounds(AffineTransform txf, GraphicsNodeRenderContext rc) {
Rectangle2D tpBounds = getPrimitiveBounds(rc);
if (tpBounds == null) {
@@ -832,8 +873,12 @@
return t.createTransformedShape(tpBounds).getBounds2D();
}
- public Rectangle2D getTransformedGeometryBounds
- (AffineTransform txf, GraphicsNodeRenderContext rc) {
+ /**
+ * Returns the bounds of the area covered by this node, without taking any
+ * of its rendering attribute into account. i.e., exclusive of any clipping,
+ * masking, filtering or stroking, for example.
+ */
+ public Rectangle2D getTransformedGeometryBounds(AffineTransform txf, GraphicsNodeRenderContext rc) {
Rectangle2D tpBounds = getGeometryBounds(rc);
if (tpBounds == null) {
@@ -849,67 +894,30 @@
}
/**
- * Compute the rendered bounds of this node based on it's
- * renderBounds. i.e., the area painted by its primitivePaint
- * method. This is used in addition to the mask, clip and filter
- * to compute the area actually rendered by this node.
+ * Returns true if the specified Point2D is inside the boundary of this
+ * node, false otherwise.
+ *
+ * @param p the specified Point2D in the user space
*/
- public Rectangle2D getBounds(GraphicsNodeRenderContext rc){
- // Get the primitive bounds
- // Rectangle2D bounds = null;
- if(bounds == null){
- // The painted region, before cliping, masking and
- // compositing is either the area painted by the primitive
- // paint or the area painted by the filter.
- if(filter == null){
- bounds = getPrimitiveBounds(rc);
- } else {
- bounds = filter.getBounds2D();
- }
- // Factor in the clipping area, if any
- if(bounds != null){
- if (clip != null) {
- Rectangle2D clipR = clip.getClipPath().getBounds2D();
- if (clipR.intersects(bounds))
- Rectangle2D.intersect(bounds, clipR, bounds);
- }
- // Factor in the mask, if any
- if (mask != null) {
- Rectangle2D maskR = mask.getBounds2D();
- if (maskR.intersects(bounds))
- Rectangle2D.intersect(bounds, maskR, bounds);
- }
- }
-
- // Make sure we haven't been interrupted
- if (Thread.currentThread().isInterrupted()) {
- // The Thread has been interrupted. Invalidate
- // any cached values and proceed.
- invalidateGeometryCache();
- }
- }
- return bounds;
+ public boolean contains(Point2D p, GraphicsNodeRenderContext rc) {
+ return getBounds(rc).contains(p);
}
/**
- * Returns true if the specified coordinates are inside the
- * interior of the bounds of this node, false otherwise.
+ * Returns true if the interior of this node intersects the interior of a
+ * specified Rectangle2D, false otherwise.
*
- * @param p the specified Point2D in the user space
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return true if the coordinates are inside, false otherwise
+ * @param r the specified Rectangle2D in the user node space
*/
- public boolean contains(Point2D p, GraphicsNodeRenderContext rc) {
- return getBounds(rc).contains(p);
+ public boolean intersects(Rectangle2D r, GraphicsNodeRenderContext rc) {
+ return getBounds(rc).intersects(r);
}
/**
- * Returns the GraphicsNode containing point p if this node or one of
- * its children is sensitive to mouse events at p.
+ * Returns the GraphicsNode containing point p if this node or one of its
+ * children is sensitive to mouse events at p.
*
* @param p the specified Point2D in the user space
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return the GraphicsNode containing p on this branch of the GVT tree.
*/
public GraphicsNode nodeHitAt(Point2D p, GraphicsNodeRenderContext rc) {
if (hitDetector != null) {
@@ -921,17 +929,5 @@
} else {
return (contains(p, rc) ? this : null);
}
- }
-
- /**
- * Tests if the bounds of this node intersects the interior of a
- * specified Rectangle2D.
- *
- * @param r the specified Rectangle2D in the user node space
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return true if the rectangle intersects, false otherwise
- */
- public boolean intersects(Rectangle2D r, GraphicsNodeRenderContext rc) {
- return getBounds(rc).intersects(r);
}
}
1.22 +165 -151 xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java
Index: CompositeGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- CompositeGraphicsNode.java 2001/09/13 08:42:49 1.21
+++ CompositeGraphicsNode.java 2001/09/13 09:37:23 1.22
@@ -33,10 +33,11 @@
* A CompositeGraphicsNode is a graphics node that can contain graphics nodes.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: CompositeGraphicsNode.java,v 1.21 2001/09/13 08:42:49 tkormann Exp $
+ * @version $Id: CompositeGraphicsNode.java,v 1.22 2001/09/13 09:37:23 tkormann Exp $
*/
-public class CompositeGraphicsNode extends AbstractGraphicsNode
- implements List {
+public class CompositeGraphicsNode extends AbstractGraphicsNode
+ implements List {
+
public static final Rectangle2D VIEWPORT = new Rectangle(0, 0, 0, 0);
/**
@@ -70,8 +71,10 @@
* Internal Cache: Primitive bounds.
*/
private Rectangle2D primitiveBounds;
-
+ /**
+ * Internal Cache: the outline.
+ */
private Shape outline;
/**
@@ -84,7 +87,7 @@
//
/**
- * Returns the list of children. Never null.
+ * Returns the list of children.
*/
public List getChildren() {
return this;
@@ -92,6 +95,7 @@
/**
* Sets the enable background property to the specified rectangle.
+ *
* @param bgRgn the region that defines the background enable property
*/
public void setBackgroundEnable(Rectangle2D bgRgn) {
@@ -110,10 +114,9 @@
//
/**
- * Paints this node without applying Filter, Mask, Composite and clip.
+ * Paints this node without applying Filter, Mask, Composite, and clip.
*
* @param g2d the Graphics2D to use
- * @param rc the GraphicsNodeRenderContext to use
*/
public void primitivePaint(Graphics2D g2d, GraphicsNodeRenderContext rc) {
if (count == 0) {
@@ -135,32 +138,8 @@
//
/**
- * Adds the specified composite graphics node listener to receive
- * composite graphics node events from this node.
- * @param l the composite graphics node listener to add
- */
- public void addCompositeGraphicsNodeListener(
- CompositeGraphicsNodeListener l) {
- if (listeners == null) {
- listeners = new EventListenerList();
- }
- listeners.add(CompositeGraphicsNodeListener.class, l);
- }
-
- /**
- * Removes the specified composite graphics node listener so that it
- * no longer receives composite graphics node events from this node.
- * @param l the composite graphics node listener to remove
- */
- public void removeCompositeGraphicsNodeListener(
- CompositeGraphicsNodeListener l) {
- if (listeners != null) {
- listeners.remove(CompositeGraphicsNodeListener.class, l);
- }
- }
-
- /**
* Dispatches the specified event to the interested registered listeners.
+ *
* @param evt the event to dispatch
*/
public void dispatchEvent(GraphicsNodeEvent evt) {
@@ -176,7 +155,37 @@
}
/**
+ * Adds the specified composite graphics node listener to receive composite
+ * graphics node events from this node.
+ *
+ * @param l the composite graphics node listener to add
+ */
+ public void addCompositeGraphicsNodeListener
+ (CompositeGraphicsNodeListener l) {
+
+ if (listeners == null) {
+ listeners = new EventListenerList();
+ }
+ listeners.add(CompositeGraphicsNodeListener.class, l);
+ }
+
+ /**
+ * Removes the specified composite graphics node listener so that it no
+ * longer receives composite graphics node events from this node.
+ *
+ * @param l the composite graphics node listener to remove
+ */
+ public void removeCompositeGraphicsNodeListener
+ (CompositeGraphicsNodeListener l) {
+
+ if (listeners != null) {
+ listeners.remove(CompositeGraphicsNodeListener.class, l);
+ }
+ }
+
+ /**
* Processes a composite event occuring on this graphics node.
+ *
* @param evt the event to process
*/
public void processCompositeEvent(CompositeGraphicsNodeEvent evt) {
@@ -207,6 +216,11 @@
// Geometric methods
//
+ /**
+ * Invalidates the cached geometric bounds. This method is called
+ * each time an attribute that affects the bounds of this node
+ * changed.
+ */
protected void invalidateGeometryCache() {
super.invalidateGeometryCache();
geometryBounds = null;
@@ -214,63 +228,9 @@
outline = null;
}
- public boolean contains(Point2D p, GraphicsNodeRenderContext rc) {
- if (count > 0 && getBounds(rc).contains(p)) {
- Point2D pt = null;
- Point2D cp = null; // Propagated to children
- for (int i=0; i < count; ++i) {
- AffineTransform t = children[i].getInverseTransform();
- if(t != null){
- pt = t.transform(p, pt);
- cp = pt;
- }
- else{
- cp = p;
- }
-
- if (children[i].contains(cp, rc)) {
- return true;
- }
- }
- }
- return false;
- }
-
- public GraphicsNode nodeHitAt(Point2D p, GraphicsNodeRenderContext rc) {
- Rectangle2D bounds = getBounds(rc);
- if (count > 0 && bounds != null && bounds.contains(p)) {
- //
- // Go backward because the children are in rendering order
- //
- Point2D pt = null;
- Point2D cp = null; // Propagated to children
- for (int i=count-1; i >= 0; --i) {
- AffineTransform t = children[i].getInverseTransform();
- if(t != null){
- pt = t.transform(p, pt);
- cp = pt;
- }
- else{
- cp = p;
- }
- GraphicsNode node = children[i].nodeHitAt(cp, rc);
- if (node != null) {
- return node;
- }
- }
- }
- return null;
- }
-
/**
- * Returns the bounds of the area covered by this node's
- * primitive paint.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
- *
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- */
+ * Returns the bounds of the area covered by this node's primitive paint.
+ */
public Rectangle2D getPrimitiveBounds(GraphicsNodeRenderContext rc) {
if (primitiveBounds == null) {
int i=0;
@@ -304,14 +264,12 @@
}
/**
- * Returns the bounds of the area covered by this node's
- * primitive paint.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
+ * Returns the bounds of this node's primitivePaint after applying the input
+ * transform (if any), concatenated with this node's transform (if any).
*
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- */
+ * @param txf the affine transform with which this node's transform should
+ * be concatenated. Should not be null.
+ */
public Rectangle2D getTransformedPrimitiveBounds(AffineTransform txf,
GraphicsNodeRenderContext rc) {
AffineTransform t = txf;
@@ -338,15 +296,10 @@
}
/**
- * Returns the bounds of the area covered by this node, without
- * taking any of its rendering attribute into account, i.e., exclusive
- * of any clipping, masking, filtering or stroking, for example.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
- *
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- */
+ * Returns the bounds of the area covered by this node, without taking any
+ * of its rendering attribute into account. i.e., exclusive of any clipping,
+ * masking, filtering or stroking, for example.
+ */
public Rectangle2D getGeometryBounds(GraphicsNodeRenderContext rc) {
if(geometryBounds == null){
// System.out.println("geometryBounds are null");
@@ -374,18 +327,15 @@
}
/**
- * Returns the bounds of the area covered by this node, without
- * taking any of its rendering attribute into account, i.e., exclusive
- * of any clipping, masking, filtering or stroking, for example.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
- *
- * The returned Rectangle2D is transformed through the contenation of the
- * input transform and this node's transform.
+ * Returns the bounds of the area covered by this node, without taking any
+ * of its rendering attribute into accoun. i.e., 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.
*
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- */
+ * @param txf the affine transform with which this node's transform should
+ * be concatenated. Should not be null.
+ */
public Rectangle2D getTransformedGeometryBounds
(AffineTransform txf, GraphicsNodeRenderContext rc) {
@@ -408,16 +358,73 @@
gb.add(cgb);
}
}
-
return gb;
}
+ /**
+ * Returns true if the specified Point2D is inside the boundary of this
+ * node, false otherwise.
+ *
+ * @param p the specified Point2D in the user space
+ */
+ public boolean contains(Point2D p, GraphicsNodeRenderContext rc) {
+ if (count > 0 && getBounds(rc).contains(p)) {
+ Point2D pt = null;
+ Point2D cp = null; // Propagated to children
+ for (int i=0; i < count; ++i) {
+ AffineTransform t = children[i].getInverseTransform();
+ if(t != null){
+ pt = t.transform(p, pt);
+ cp = pt;
+ }
+ else{
+ cp = p;
+ }
+
+ if (children[i].contains(cp, rc)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
/**
- * Returns the outline of this <tt>CompositeGraphicsNode</tt>.
+ * Returns the GraphicsNode containing point p if this node or one of its
+ * children is sensitive to mouse events at p.
*
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return the outline of this node
+ * @param p the specified Point2D in the user space
*/
+ public GraphicsNode nodeHitAt(Point2D p, GraphicsNodeRenderContext rc) {
+ Rectangle2D bounds = getBounds(rc);
+ if (count > 0 && bounds != null && bounds.contains(p)) {
+ //
+ // Go backward because the children are in rendering order
+ //
+ Point2D pt = null;
+ Point2D cp = null; // Propagated to children
+ for (int i=count-1; i >= 0; --i) {
+ AffineTransform t = children[i].getInverseTransform();
+ if(t != null){
+ pt = t.transform(p, pt);
+ cp = pt;
+ }
+ else{
+ cp = p;
+ }
+ GraphicsNode node = children[i].nodeHitAt(cp, rc);
+ if (node != null) {
+ return node;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the outline of this node.
+ */
public Shape getOutline(GraphicsNodeRenderContext rc) {
if (outline == null) {
outline = new GeneralPath();
@@ -501,10 +508,10 @@
}
/**
- * Returns an array containing all of the graphics node in the
- * children list of this composite graphics node in the correct
- * order.
- * @param a the array to fit if possible
+ * Returns an array containing all of the graphics node in the children list
+ * of this composite graphics node in the correct order.
+ *
+ * @param a the array to fit if possible
*/
public Object[] toArray(Object [] a) {
if (a.length < count) {
@@ -519,6 +526,7 @@
/**
* Returns the graphics node at the specified position in the children list.
+ *
* @param index the index of the graphics node to return
* @exception IndexOutOfBoundsException if the index is out of range
*/
@@ -530,14 +538,15 @@
// Modification Operations
/**
- * Replaces the graphics node at the specified position in the
- * children list with the specified graphics node.
+ * Replaces the graphics node at the specified position in the children list
+ * with the specified graphics node.
+ *
* @param index the index of the graphics node to replace
* @param o the graphics node to be stored at the specified position
* @return the graphics node previously at the specified position
* @exception IndexOutOfBoundsException if the index is out of range
* @exception IllegalArgumentException if the node is not an
- * instance of GraphicsNode
+ * instance of GraphicsNode
*/
public Object set(int index, Object o) {
// Check for correct arguments
@@ -571,6 +580,7 @@
/**
* Adds the specified graphics node to this composite graphics node.
+ *
* @param o the graphics node to add
* @return true (as per the general contract of Collection.add)
* @exception IllegalArgumentException if the node is not an
@@ -602,17 +612,17 @@
}
/**
- * 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).
+ * 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).
*
* @param index the position at which the specified graphics node is to
* be inserted.
* @param o the graphics node to be inserted.
* @exception IndexOutOfBoundsException if the index is out of range
* @exception IllegalArgumentException if the node is not an
- * instance of GraphicsNode
+ * instance of GraphicsNode
*/
public void add(int index, Object o) {
// Check for correct arguments
@@ -662,6 +672,7 @@
/**
* Removes the specified graphics node from the children list.
+ *
* @param o the node the remove
* @return true if the children list contains the specified graphics node
* @exception IllegalArgumentException if the node is not an
@@ -685,11 +696,12 @@
/**
* 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).
+ * Shifts any subsequent graphics nodes to the left (subtracts one from
+ * their indices).
+ *
* @param index the position of the graphics node to remove
* @return the graphics node that was removed
- * @exception IndexOutOfBoundsException if index out of range <tt>
+ * @exception IndexOutOfBoundsException if index out of range <tt>
*/
public Object remove(int index) {
// Check for correct argument
@@ -742,9 +754,10 @@
}
/**
- * Returns true if this composite graphics node contains all the
- * graphics node in the specified collection, false otherwise.
- * @param c the collection to be checked for containment
+ * Returns true if this composite graphics node contains all the graphics
+ * node in the specified collection, false otherwise.
+ *
+ * @param c the collection to be checked for containment
*/
public boolean containsAll(Collection c) {
Iterator i = c.iterator();
@@ -759,11 +772,10 @@
// Search Operations
/**
- * Returns the index in the children list of the specified
- * graphics node or -1 if the children list does not contain this
- * graphics 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.
*
- * @param node the graphics node to search for
+ * @param node the graphics node to search for
*/
public int indexOf(Object node) {
if (node == null || !(node instanceof GraphicsNode)) {
@@ -780,11 +792,11 @@
}
/**
- * 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.
+ * 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.
*
- * @param node the graphics node to search for
+ * @param node the graphics node to search for
*/
public int lastIndexOf(Object node) {
if (node == null || !(node instanceof GraphicsNode)) {
@@ -810,10 +822,11 @@
}
/**
- * Returns an iterator over the children of this graphics node,
- * starting at the specified position in the children list.
+ * Returns an iterator over the children of this graphics node, starting at
+ * the specified position in the children list.
+ *
* @param index the index of the first graphics node to return
- * from the children list
+ * from the children list
*/
public ListIterator listIterator(int index) {
if (index < 0 || index > count) {
@@ -835,6 +848,7 @@
/**
* Checks if the given index is in range. If not, throws an appropriate
* runtime exception.
+ *
* @param index the index to check
*/
private void checkRange(int index) {
@@ -845,9 +859,9 @@
}
/**
- * 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.
+ * 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.
*
* @param minCapacity the desired minimum capacity.
*/
1.9 +19 -43 xml-batik/sources/org/apache/batik/gvt/ShapeNode.java
Index: ShapeNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/ShapeNode.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ShapeNode.java 2001/03/21 15:03:25 1.8
+++ ShapeNode.java 2001/09/13 09:37:23 1.9
@@ -20,7 +20,7 @@
* A graphics node that represents a shape.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: ShapeNode.java,v 1.8 2001/03/21 15:03:25 cjolif Exp $
+ * @version $Id: ShapeNode.java,v 1.9 2001/09/13 09:37:23 tkormann Exp $
*/
public class ShapeNode extends AbstractGraphicsNode {
@@ -79,10 +79,10 @@
}
/**
- * Sets the <tt>ShapePainter</tt> used by this shape node to
- * render its shape.
+ * Sets the <tt>ShapePainter</tt> used by this shape node to render its
+ * shape.
*
- * @param newShapePainter the new ShapePainter to use
+ * @param newShapePainter the new ShapePainter to use
*/
public void setShapePainter(ShapePainter newShapePainter) {
invalidateGeometryCache();
@@ -93,8 +93,8 @@
}
/**
- * Returns the <tt>ShapePainter</tt> used by this shape node to
- * render its shape.
+ * Returns the <tt>ShapePainter</tt> used by this shape node to render its
+ * shape.
*/
public ShapePainter getShapePainter() {
return shapePainter;
@@ -105,10 +105,9 @@
//
/**
- * Paints this node if visible.
+ * Paints this node.
*
* @param g2d the Graphics2D to use
- * @param rc the GraphicsNodeRenderContext to use
*/
public void paint(Graphics2D g2d, GraphicsNodeRenderContext rc) {
if (isVisible) {
@@ -118,10 +117,9 @@
}
/**
- * Paints this node without applying Filter, Mask, Composite and clip.
+ * Paints this node without applying Filter, Mask, Composite, and clip.
*
* @param g2d the Graphics2D to use
- * @param rc the GraphicsNodeRenderContext to use
*/
public void primitivePaint(Graphics2D g2d, GraphicsNodeRenderContext rc) {
if (shapePainter != null) {
@@ -134,9 +132,9 @@
//
/**
- * Invalidates this <tt>ShapeNode</tt>. This node and all its
- * ancestors have been informed that all its cached values related
- * to its bounds must be recomputed.
+ * Invalidates this <tt>ShapeNode</tt>. This node and all its ancestors have
+ * been informed that all its cached values related to its bounds must be
+ * recomputed.
*/
protected void invalidateGeometryCache() {
super.invalidateGeometryCache();
@@ -146,14 +144,10 @@
}
/**
- * Tests if the specified Point2D is inside the boundary of this node.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
+ * Returns true if the specified Point2D is inside the boundary of this
+ * node, false otherwise.
*
* @param p the specified Point2D in the user space
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return true if the coordinates are inside, false otherwise
*/
public boolean contains(Point2D p, GraphicsNodeRenderContext rc) {
Rectangle2D b = getBounds(rc);
@@ -166,15 +160,10 @@
}
/**
- * Tests if the interior of this node intersects the interior of a
- * specified Rectangle2D.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
+ * Returns true if the interior of this node intersects the interior of a
+ * specified Rectangle2D, false otherwise.
*
* @param r the specified Rectangle2D in the user node space
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return true if the rectangle intersects, false otherwise
*/
public boolean intersects(Rectangle2D r, GraphicsNodeRenderContext rc) {
Rectangle2D b = getBounds(rc);
@@ -188,11 +177,6 @@
/**
* Returns the bounds of the area covered by this node's primitive paint.
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
- *
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
*/
public Rectangle2D getPrimitiveBounds(GraphicsNodeRenderContext rc) {
if (primitiveBounds == null) {
@@ -213,14 +197,9 @@
}
/**
- * Returns the bounds of the area covered by this <tt>ShapeNode</tt>,
- * without taking any of its rendering attribute into account.
- * (i.e., exclusive of any clipping, masking, filtering or stroking...)
- * <b>Note</b>: The boundaries of some nodes (notably, text element nodes)
- * cannot be precisely determined independent of their
- * GraphicsNodeRenderContext.
- *
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
+ * Returns the bounds of the area covered by this node, without taking any
+ * of its rendering attribute into account. i.e., exclusive of any clipping,
+ * masking, filtering or stroking, for example.
*/
public Rectangle2D getGeometryBounds(GraphicsNodeRenderContext rc){
if (geometryBounds == null) {
@@ -233,10 +212,7 @@
}
/**
- * Returns the outline of this <tt>ShapeNode</tt>.
- *
- * @param rc the GraphicsNodeRenderContext for which this dimension applies
- * @return the outline of this node
+ * Returns the outline of this node.
*/
public Shape getOutline(GraphicsNodeRenderContext rc) {
return shape;
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org