From 041e5a149ded1b80ec2d57e12f658130bc50815b Mon Sep 17 00:00:00 2001 From: kitfox Date: Sun, 1 Jan 2012 03:35:30 +0000 Subject: Roots now automatically assigned a diagram when attached to SVGDiagram. git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@103 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b --- src/main/java/com/kitfox/svg/SVGDiagram.java | 1 + src/main/java/com/kitfox/svg/SVGElement.java | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/kitfox/svg/SVGDiagram.java b/src/main/java/com/kitfox/svg/SVGDiagram.java index c28e6e6..236de83 100644 --- a/src/main/java/com/kitfox/svg/SVGDiagram.java +++ b/src/main/java/com/kitfox/svg/SVGDiagram.java @@ -202,6 +202,7 @@ public class SVGDiagram implements Serializable public void setRoot(SVGRoot root) { this.root = root; + root.setDiagram(this); } public boolean ignoringClipHeuristic() { return ignoreClipHeuristic; } diff --git a/src/main/java/com/kitfox/svg/SVGElement.java b/src/main/java/com/kitfox/svg/SVGElement.java index 08cb36c..08a801c 100644 --- a/src/main/java/com/kitfox/svg/SVGElement.java +++ b/src/main/java/com/kitfox/svg/SVGElement.java @@ -286,11 +286,14 @@ abstract public class SVGElement implements Serializable if (hasAttribute(name, attribType)) throw new SVGElementException(this, "Attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + ") already exists"); //Alter layout for id attribute - if ("id".equals(name) && diagram != null) + if ("id".equals(name)) { - diagram.removeElement(this.id); - this.id = name; - diagram.setElement(this.id, this); + if (diagram != null) + { + diagram.removeElement(id); + diagram.setElement(value, this); + } + this.id = value; } switch (attribType) @@ -354,7 +357,7 @@ abstract public class SVGElement implements Serializable } } - private void setDiagram(SVGDiagram diagram) + protected void setDiagram(SVGDiagram diagram) { this.diagram = diagram; diagram.setElement(id, this); @@ -510,9 +513,12 @@ abstract public class SVGElement implements Serializable //Alter layout for relevant attributes if ("id".equals(styAttr.getName())) { - diagram.removeElement(this.id); - this.id = name; - diagram.setElement(this.id, this); + if (diagram != null) + { + diagram.removeElement(this.id); + diagram.setElement(value, this); + } + this.id = value; } styAttr.setStringValue(value); -- cgit v1.2.3-55-g7522