1 18 package org.apache.batik.dom.svg; 19 20 import org.w3c.dom.Attr ; 21 import org.w3c.dom.DOMException ; 22 import org.w3c.dom.Element ; 23 import org.w3c.dom.svg.SVGAnimatedLengthList; 24 import org.w3c.dom.svg.SVGException; 25 import org.w3c.dom.svg.SVGLengthList; 26 27 34 public class SVGOMAnimatedLengthList 35 implements SVGAnimatedLengthList, 36 LiveAttributeValue { 37 38 41 protected AbstractElement element; 42 43 46 protected String namespaceURI; 47 48 51 protected String localName; 52 53 56 protected boolean changing; 57 58 61 protected AbstractSVGLengthList lengths; 62 63 66 protected String defaultValue; 67 68 71 protected short direction; 72 73 75 public SVGOMAnimatedLengthList(AbstractElement elt, 76 String ns, 77 String ln, 78 String defaultValue, 79 short direction){ 80 81 element = elt; 82 namespaceURI = ns; 83 localName = ln; 84 this.defaultValue = defaultValue; 85 this.direction = direction; 86 } 87 88 95 public SVGLengthList getBaseVal(){ 96 if ( lengths == null ){ 97 lengths = new SVGOMLengthList(direction); 98 } 99 return lengths; 100 } 101 102 104 public SVGLengthList getAnimVal(){ 105 throw new RuntimeException ("TODO : getAnimVal() !!"); 106 } 107 108 111 public void attrAdded(Attr node, String newv) { 112 if (!changing && lengths != null) { 113 lengths.invalidate(); 114 } 115 } 116 117 120 public void attrModified(Attr node, String oldv, String newv) { 121 if (!changing && lengths != null) { 122 lengths.invalidate(); 123 } 124 } 125 126 129 public void attrRemoved(Attr node, String oldv) { 130 if (!changing && lengths != null) { 131 lengths.invalidate(); 132 } 133 } 134 135 138 public class SVGOMLengthList extends AbstractSVGLengthList { 139 140 public SVGOMLengthList(short direction){ 141 super(direction); 142 } 143 144 147 protected DOMException createDOMException(short type, 148 String key, 149 Object [] args){ 150 return element.createDOMException(type,key,args); 151 } 152 153 156 protected SVGException createSVGException(short type, 157 String key, 158 Object [] args){ 159 160 return ((SVGOMElement)element).createSVGException(type,key,args); 161 } 162 163 165 protected Element getElement(){ 166 return element; 167 } 168 169 172 protected String getValueAsString(){ 173 Attr attr = element.getAttributeNodeNS(namespaceURI, localName); 174 if (attr == null) { 175 return defaultValue; 176 } 177 return attr.getValue(); 178 } 179 180 183 protected void setAttributeValue(String value){ 184 try{ 185 changing = true; 186 element.setAttributeNS(namespaceURI, localName, value); 187 } 188 finally{ 189 changing = false; 190 } 191 } 192 } 193 } 194 | Popular Tags |