private void setStroke(Color fromColor, String toColor, SVGElement node) throws SVGException { if (node.hasAttribute("stroke", AnimationElement.AT_CSS)) { StyleAttribute abs = node.getStyleAbsolute("stroke"); Color was = abs.getColorValue(); if (was.equals(fromColor)) { abs.setStringValue(toColor); } } for (int i = 0; i < node.getNumChildren(); ++i) { setStroke(fromColor, toColor, node.getChild(i)); } } private String getHexString(Color color) { return String.format("#%06x", (0xFFFFFF & color.getRGB())); }
public TrackBase(SVGElement parent, String attribName, int attribType) throws SVGElementException { this.parent = parent; this.attribName = attribName; this.attribType = attribType; //Make sure parent has an attribute we will write to if (attribType == AnimationElement.AT_AUTO && !parent.hasAttribute(attribName, AnimationElement.AT_CSS) && !parent.hasAttribute(attribName, AnimationElement.AT_XML)) { parent.addAttribute(attribName, AnimationElement.AT_CSS, ""); } else if (!parent.hasAttribute(attribName, attribType)) { parent.addAttribute(attribName, attribType, ""); } }
@Override protected void build() throws SVGException super.build();
attr = parent.getStyleAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break; case AnimationElement.AT_XML: attr = parent.getPresAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break; case AnimationElement.AT_AUTO: attr = parent.getStyleAbsolute(attribName); if (attr == null) attr = parent.getPresAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break;
SVGRoot root = getRoot(); if (root != null) if (ss != null) return ss.getStyle(attrib, getTagName(), cssClass); SVGElement parentContext = getParentContext(); if (parentContext != null) return parentContext.getStyle(attrib, true); return parent.getStyle(attrib, true);
attr = parent.getStyleAbsolute(attribName); retVal = attr.getDoubleValue(); break; case AnimationElement.AT_XML: attr = parent.getPresAbsolute(attribName); retVal = attr.getDoubleValue(); break; case AnimationElement.AT_AUTO: attr = parent.getStyleAbsolute(attribName); if (attr == null) attr = parent.getPresAbsolute(attribName); retVal = attr.getDoubleValue(); break;
/** * @param id - Id of svg element to return * @return the child of the given id, or null if no such child exists. */ public SVGElement getChild(String id) { for (SVGElement ele : children) { String eleId = ele.getId(); if (eleId != null && eleId.equals(id)) { return ele; } } return null; }
public boolean getStyle(StyleAttribute attrib) throws SVGException { return getStyle(attrib, true); }
public void addAttribute(String name, int attribType, String value) throws SVGElementException { if (hasAttribute(name, attribType)) throw new SVGElementException(this, "Attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + ") already exists"); //Alter layout for id attribute if ("id".equals(name)) { if (diagram != null) { diagram.removeElement(id); diagram.setElement(value, this); } this.id = value; } switch (attribType) { case AnimationElement.AT_CSS: inlineStyles.put(name, new StyleAttribute(name, value)); return; case AnimationElement.AT_XML: presAttribs.put(name, new StyleAttribute(name, value)); return; } throw new SVGElementException(this, "Invalid attribute type " + attribType); }
SVGElement parentContext = getParentContext(); if (parentContext != null) return parentContext.getStyle(attrib, true); if (parent != null) return parent.getStyle(attrib, true);
/** * @return an ordered list of nodes from the root of the tree to this node */ public List getPath(List retVec) { if (retVec == null) retVec = new ArrayList(); if (parent != null) { parent.getPath(retVec); } retVec.add(this); return retVec; }
/** * Called by internal processes to rebuild the geometry of this node * from it's presentation attributes, style attributes and animated tracks. */ protected void build() throws SVGException { StyleAttribute sty = new StyleAttribute(); if (getPres(sty.setName("id"))) { String newId = sty.getStringValue(); if (!newId.equals(id)) { diagram.removeElement(id); id = newId; diagram.setElement(this.id, this); } } if (getPres(sty.setName("class"))) cssClass = sty.getStringValue(); if (getPres(sty.setName("xml:base"))) xmlBase = sty.getURIValue(); }
attr = parent.getStyleAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break; case AnimationElement.AT_XML: attr = parent.getPresAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break; case AnimationElement.AT_AUTO: attr = parent.getStyleAbsolute(attribName); if (attr == null) attr = parent.getPresAbsolute(attribName); retVal.setTransform(SVGElement.parseSingleTransform(attr.getStringValue())); break;
SVGRoot root = getRoot(); if (root != null) if (ss != null) return ss.getStyle(attrib, getTagName(), cssClass); SVGElement parentContext = getParentContext(); if (parentContext != null) return parentContext.getStyle(attrib, true); return parent.getStyle(attrib, true);
attr = parent.getStyleAbsolute(attribName); retVal = attr.getDoubleValue(); break; case AnimationElement.AT_XML: attr = parent.getPresAbsolute(attribName); retVal = attr.getDoubleValue(); break; case AnimationElement.AT_AUTO: attr = parent.getStyleAbsolute(attribName); if (attr == null) attr = parent.getPresAbsolute(attribName); retVal = attr.getDoubleValue(); break;
/** * @param id - Id of svg element to return * @return the child of the given id, or null if no such child exists. */ public SVGElement getChild(String id) { for (SVGElement ele : children) { String eleId = ele.getId(); if (eleId != null && eleId.equals(id)) { return ele; } } return null; }
public boolean getStyle(StyleAttribute attrib) throws SVGException { return getStyle(attrib, true); }
public void addAttribute(String name, int attribType, String value) throws SVGElementException { if (hasAttribute(name, attribType)) { throw new SVGElementException(this, "Attribute " + name + "(" + AnimationElement.animationElementToString(attribType) + ") already exists"); } //Alter layout for id attribute if ("id".equals(name)) { if (diagram != null) { diagram.removeElement(id); diagram.setElement(value, this); } this.id = value; } switch (attribType) { case AnimationElement.AT_CSS: inlineStyles.put(name, new StyleAttribute(name, value)); return; case AnimationElement.AT_XML: presAttribs.put(name, new StyleAttribute(name, value)); return; } throw new SVGElementException(this, "Invalid attribute type " + attribType); }