1 18 package org.apache.batik.dom.svg; 19 20 import org.apache.batik.parser.UnitProcessor; 21 import org.w3c.dom.Attr ; 22 import org.w3c.dom.svg.SVGAnimatedLength; 23 import org.w3c.dom.svg.SVGLength; 24 25 32 public abstract class AbstractSVGAnimatedLength 33 implements SVGAnimatedLength, 34 LiveAttributeValue { 35 36 39 public final static short HORIZONTAL_LENGTH = 40 UnitProcessor.HORIZONTAL_LENGTH; 41 42 45 public final static short VERTICAL_LENGTH = 46 UnitProcessor.VERTICAL_LENGTH; 47 48 51 public final static short OTHER_LENGTH = 52 UnitProcessor.OTHER_LENGTH; 53 54 57 protected AbstractElement element; 58 59 62 protected String namespaceURI; 63 64 67 protected String localName; 68 69 72 protected short direction; 73 74 77 protected BaseSVGLength baseVal; 78 79 82 protected boolean changing; 83 84 91 protected AbstractSVGAnimatedLength(AbstractElement elt, 92 String ns, 93 String ln, 94 short dir) { 95 element = elt; 96 namespaceURI = ns; 97 localName = ln; 98 direction = dir; 99 } 100 101 105 protected abstract String getDefaultValue(); 106 107 110 public SVGLength getBaseVal() { 111 if (baseVal == null) { 112 baseVal = new BaseSVGLength(direction); 113 } 114 return baseVal; 115 } 116 117 120 public SVGLength getAnimVal() { 121 throw new RuntimeException ("!!! TODO: getAnimVal()"); 122 } 123 124 127 public void attrAdded(Attr node, String newv) { 128 if (!changing && baseVal != null) { 129 baseVal.invalidate(); 130 } 131 } 132 133 136 public void attrModified(Attr node, String oldv, String newv) { 137 if (!changing && baseVal != null) { 138 baseVal.invalidate(); 139 } 140 } 141 142 145 public void attrRemoved(Attr node, String oldv) { 146 if (!changing && baseVal != null) { 147 baseVal.invalidate(); 148 } 149 } 150 151 154 protected class BaseSVGLength extends AbstractSVGLength { 155 156 159 protected boolean valid; 160 161 164 public BaseSVGLength(short direction) { 165 super(direction); 166 } 167 168 171 public void invalidate() { 172 valid = false; 173 } 174 175 178 protected void reset() { 179 try { 180 changing = true; 181 String value = getValueAsString(); 182 element.setAttributeNS(namespaceURI, localName, value); 183 } finally { 184 changing = false; 185 } 186 } 187 188 191 protected void revalidate() { 192 if (valid) { 193 return; 194 } 195 196 String s = null; 197 198 Attr attr = element.getAttributeNodeNS(namespaceURI, localName); 199 200 if (attr == null) { 201 s = getDefaultValue(); 202 } 203 else{ 204 s = attr.getValue(); 205 } 206 207 parse(s); 208 209 valid = true; 210 } 211 212 214 protected SVGOMElement getAssociatedElement(){ 215 return (SVGOMElement)element; 216 } 217 } 218 } 219 | Popular Tags |