summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/kitfox/svg/Group.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/kitfox/svg/Group.java')
-rw-r--r--src/main/java/com/kitfox/svg/Group.java120
1 files changed, 63 insertions, 57 deletions
diff --git a/src/main/java/com/kitfox/svg/Group.java b/src/main/java/com/kitfox/svg/Group.java
index 5fa1e92..78320ff 100644
--- a/src/main/java/com/kitfox/svg/Group.java
+++ b/src/main/java/com/kitfox/svg/Group.java
@@ -33,12 +33,10 @@
*
* Created on January 26, 2004, 1:56 AM
*/
-
package com.kitfox.svg;
import com.kitfox.svg.xml.StyleAttribute;
import java.awt.Graphics2D;
-import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
@@ -48,34 +46,29 @@ import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.List;
-
/**
* @author Mark McKay
* @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
*/
public class Group extends ShapeElement
{
-
+ public static final String TAG_NAME = "group";
+
//Cache bounding box for faster clip testing
Rectangle2D boundingBox;
Shape cachedShape;
- //Cache clip bounds
-// final Rectangle clipBounds = new Rectangle();
-
- /** Creates a new instance of Stop */
- public Group() {
+ /**
+ * Creates a new instance of Stop
+ */
+ public Group()
+ {
}
- /*
- public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
+ public String getTagName()
{
- //Load style string
- super.loaderStartElement(helper, attrs, parent);
-
- //String transform = attrs.getValue("transform");
+ return TAG_NAME;
}
- */
/**
* Called after the start element but before the end element to indicate
@@ -84,8 +77,6 @@ public class Group extends ShapeElement
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
{
super.loaderAddChild(helper, child);
-
-// members.add(child);
}
protected boolean outsideClip(Graphics2D g) throws SVGException
@@ -98,12 +89,6 @@ public class Group extends ShapeElement
//g.getClipBounds(clipBounds);
Rectangle2D rect = getBoundingBox();
-//if (rect == null)
-//{
-// rect = getBoundingBox();
-//}
-
-// if (rect.intersects(clipBounds))
if (clip.intersects(rect))
{
return false;
@@ -120,21 +105,20 @@ public class Group extends ShapeElement
try
{
xform.inverseTransform(point, xPoint);
- }
- catch (NoninvertibleTransformException ex)
+ } catch (NoninvertibleTransformException ex)
{
throw new SVGException(ex);
}
}
-
-
+
+
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
-
+ RenderableElement rendEle = (RenderableElement) ele;
+
rendEle.pick(xPoint, boundingBox, retVec);
}
}
@@ -147,15 +131,15 @@ public class Group extends ShapeElement
ltw = new AffineTransform(ltw);
ltw.concatenate(xform);
}
-
-
+
+
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
-
+ RenderableElement rendEle = (RenderableElement) ele;
+
rendEle.pick(pickArea, ltw, boundingBox, retVec);
}
}
@@ -167,12 +151,15 @@ public class Group extends ShapeElement
StyleAttribute styleAttrib = new StyleAttribute();
if (getStyle(styleAttrib.setName("visibility")))
{
- if (!styleAttrib.getStringValue().equals("visible")) return;
+ if (!styleAttrib.getStringValue().equals("visible"))
+ {
+ return;
+ }
}
-
+
//Do not process offscreen groups
boolean ignoreClip = diagram.ignoringClipHeuristic();
- if (!ignoreClip && outsideClip(g))
+ if (!ignoreClip && outsideClip(g))
{
return;
}
@@ -195,18 +182,18 @@ public class Group extends ShapeElement
Shape clip = g.getClip();
while (it.hasNext())
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
+ RenderableElement rendEle = (RenderableElement) ele;
// if (shapeEle == null) continue;
if (!(ele instanceof Group))
{
//Skip if clipping area is outside our bounds
- if (!ignoreClip && clip != null
- && !clip.intersects(rendEle.getBoundingBox()))
+ if (!ignoreClip && clip != null
+ && !clip.intersects(rendEle.getBoundingBox()))
{
continue;
}
@@ -219,13 +206,15 @@ public class Group extends ShapeElement
finishLayer(g);
}
-
/**
* Retrieves the cached bounding box of this group
*/
public Shape getShape()
{
- if (cachedShape == null) calcShape();
+ if (cachedShape == null)
+ {
+ calcShape();
+ }
return cachedShape;
}
@@ -235,11 +224,11 @@ public class Group extends ShapeElement
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof ShapeElement)
{
- ShapeElement shpEle = (ShapeElement)ele;
+ ShapeElement shpEle = (ShapeElement) ele;
Shape shape = shpEle.getShape();
if (shape != null)
{
@@ -256,14 +245,17 @@ public class Group extends ShapeElement
*/
public Rectangle2D getBoundingBox() throws SVGException
{
- if (boundingBox == null) calcBoundingBox();
+ if (boundingBox == null)
+ {
+ calcBoundingBox();
+ }
// calcBoundingBox();
return boundingBox;
}
/**
* Recalculates the bounding box by taking the union of the bounding boxes
- * of all children. Caches the result.
+ * of all children. Caches the result.
*/
public void calcBoundingBox() throws SVGException
{
@@ -272,16 +264,21 @@ public class Group extends ShapeElement
for (Iterator it = children.iterator(); it.hasNext();)
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
if (ele instanceof RenderableElement)
{
- RenderableElement rendEle = (RenderableElement)ele;
+ RenderableElement rendEle = (RenderableElement) ele;
Rectangle2D bounds = rendEle.getBoundingBox();
if (bounds != null)
{
- if (retRect == null) retRect = bounds;
- else retRect = retRect.createUnion(bounds);
+ if (retRect == null)
+ {
+ retRect = bounds;
+ } else
+ {
+ retRect = retRect.createUnion(bounds);
+ }
}
}
}
@@ -292,7 +289,10 @@ public class Group extends ShapeElement
// }
//If no contents, use degenerate rectangle
- if (retRect == null) retRect = new Rectangle2D.Float();
+ if (retRect == null)
+ {
+ retRect = new Rectangle2D.Float();
+ }
boundingBox = boundsToParent(retRect);
}
@@ -305,14 +305,20 @@ public class Group extends ShapeElement
//Distribute message to all members of this group
while (it.hasNext())
{
- SVGElement ele = (SVGElement)it.next();
+ SVGElement ele = (SVGElement) it.next();
boolean updateVal = ele.updateTime(curTime);
changeState = changeState || updateVal;
//Update our shape if shape aware children change
- if (ele instanceof ShapeElement) cachedShape = null;
- if (ele instanceof RenderableElement) boundingBox = null;
+ if (ele instanceof ShapeElement)
+ {
+ cachedShape = null;
+ }
+ if (ele instanceof RenderableElement)
+ {
+ boundingBox = null;
+ }
}
return changeState;