1 18 package org.apache.batik.dom.svg; 19 20 import org.apache.batik.parser.NumberListHandler; 21 import org.apache.batik.parser.NumberListParser; 22 import org.apache.batik.parser.ParseException; 23 import org.w3c.dom.DOMException ; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.svg.SVGException; 26 import org.w3c.dom.svg.SVGNumber; 27 import org.w3c.dom.svg.SVGNumberList; 28 29 30 36 public abstract class AbstractSVGNumberList extends AbstractSVGList implements SVGNumberList { 37 38 41 public final static String SVG_NUMBER_LIST_SEPARATOR 42 =" "; 43 44 47 protected String getItemSeparator(){ 48 return SVG_NUMBER_LIST_SEPARATOR; 49 } 50 51 56 protected abstract SVGException createSVGException(short type, 57 String key, 58 Object [] args); 59 60 63 protected abstract Element getElement(); 64 65 68 protected AbstractSVGNumberList() { 69 super(); 70 } 71 72 74 public SVGNumber initialize ( SVGNumber newItem ) 75 throws DOMException , SVGException { 76 77 return (SVGNumber)initializeImpl(newItem); 78 } 79 80 82 public SVGNumber getItem ( int index ) 83 throws DOMException { 84 85 return (SVGNumber)getItemImpl(index); 86 } 87 88 90 public SVGNumber insertItemBefore ( SVGNumber newItem, int index ) 91 throws DOMException , SVGException { 92 93 return (SVGNumber)insertItemBeforeImpl(newItem,index); 94 } 95 96 98 public SVGNumber replaceItem ( SVGNumber newItem, int index ) 99 throws DOMException , SVGException { 100 101 return (SVGNumber)replaceItemImpl(newItem,index); 102 } 103 104 106 public SVGNumber removeItem ( int index ) 107 throws DOMException { 108 109 return (SVGNumber)removeItemImpl(index); 110 } 111 112 114 public SVGNumber appendItem ( SVGNumber newItem ) 115 throws DOMException , SVGException { 116 117 return (SVGNumber) appendItemImpl(newItem); 118 } 119 120 122 protected SVGItem createSVGItem(Object newItem){ 123 124 SVGNumber l = (SVGNumber)newItem; 125 126 return new SVGNumberItem(l.getValue()); 127 } 128 129 135 protected void doParse(String value, ListHandler handler) 136 throws ParseException{ 137 138 NumberListParser NumberListParser = new NumberListParser(); 139 140 NumberListBuilder builder = new NumberListBuilder(handler); 141 142 NumberListParser.setNumberListHandler(builder); 143 NumberListParser.parse(value); 144 145 } 146 147 150 protected void checkItemType(Object newItem) 151 throws SVGException { 152 if ( !( newItem instanceof SVGNumber ) ){ 153 createSVGException(SVGException.SVG_WRONG_TYPE_ERR, 154 "expected SVGNumber", 155 null); 156 } 157 } 158 159 162 protected class SVGNumberItem 163 extends AbstractSVGNumber 164 implements SVGItem { 165 166 169 public SVGNumberItem(float value){ 170 super(); 171 this.value = value; 172 } 173 174 public String getValueAsString(){ 175 return Float.toString(value); 176 } 177 178 181 protected AbstractSVGList parentList; 182 183 188 public void setParent(AbstractSVGList list){ 189 parentList = list; 190 } 191 192 198 public AbstractSVGList getParent(){ 199 return parentList; 200 } 201 202 206 protected void reset(){ 207 if ( parentList != null ){ 208 parentList.itemChanged(); 209 } 210 } 211 212 } 213 214 218 protected class NumberListBuilder 219 implements NumberListHandler { 220 221 224 protected ListHandler listHandler; 225 226 protected float currentValue; 228 229 231 public NumberListBuilder(ListHandler listHandler){ 232 this.listHandler = listHandler; 233 } 234 235 237 public void startNumberList() 238 throws ParseException{ 239 240 listHandler.startList(); 241 } 242 245 public void startNumber() throws ParseException { 246 currentValue = 0.0f; 247 } 248 249 252 public void numberValue(float v) throws ParseException { 253 currentValue = v; 254 } 255 256 259 public void endNumber() throws ParseException { 260 listHandler.item(new SVGNumberItem(currentValue)); 261 } 262 263 265 public void endNumberList() 266 throws ParseException { 267 listHandler.endList(); 268 } 269 } 270 } 271 | Popular Tags |