1 18 package org.apache.batik.dom.svg; 19 20 import org.apache.batik.parser.ParseException; 21 import org.apache.batik.parser.PointsHandler; 22 import org.apache.batik.parser.PointsParser; 23 import org.w3c.dom.DOMException ; 24 import org.w3c.dom.svg.SVGException; 25 import org.w3c.dom.svg.SVGMatrix; 26 import org.w3c.dom.svg.SVGPoint; 27 import org.w3c.dom.svg.SVGPointList; 28 29 30 31 38 public abstract class AbstractSVGPointList 39 extends AbstractSVGList 40 implements SVGPointList { 41 42 45 public final static String SVG_POINT_LIST_SEPARATOR 46 =" "; 47 48 51 protected String getItemSeparator(){ 52 return SVG_POINT_LIST_SEPARATOR; 53 } 54 55 60 protected abstract SVGException createSVGException(short type, 61 String key, 62 Object [] args); 63 64 67 protected AbstractSVGPointList() { 68 super(); 69 } 70 71 73 public SVGPoint initialize ( SVGPoint newItem ) 74 throws DOMException , SVGException { 75 76 return (SVGPoint)initializeImpl(newItem); 77 } 78 79 81 public SVGPoint getItem ( int index ) 82 throws DOMException { 83 84 return (SVGPoint)getItemImpl(index); 85 } 86 87 89 public SVGPoint insertItemBefore ( SVGPoint newItem, int index ) 90 throws DOMException , SVGException { 91 92 return (SVGPoint)insertItemBeforeImpl(newItem,index); 93 } 94 95 97 public SVGPoint replaceItem ( SVGPoint newItem, int index ) 98 throws DOMException , SVGException { 99 100 return (SVGPoint)replaceItemImpl(newItem,index); 101 } 102 103 105 public SVGPoint removeItem ( int index ) 106 throws DOMException { 107 108 return (SVGPoint)removeItemImpl(index); 109 } 110 111 113 public SVGPoint appendItem ( SVGPoint newItem ) 114 throws DOMException , SVGException { 115 116 return (SVGPoint) appendItemImpl(newItem); 117 } 118 119 121 protected SVGItem createSVGItem(Object newItem){ 122 123 SVGPoint point= (SVGPoint)newItem; 124 125 return new SVGPointItem(point.getX(), point.getY()); 126 } 127 128 134 protected void doParse(String value, ListHandler handler) 135 throws ParseException{ 136 137 PointsParser pointsParser = new PointsParser(); 138 139 PointsListBuilder builder = new PointsListBuilder(handler); 140 141 pointsParser.setPointsHandler(builder); 142 pointsParser.parse(value); 143 144 } 145 146 149 protected void checkItemType(Object newItem) 150 throws SVGException { 151 if ( !( newItem instanceof SVGPoint ) ){ 152 createSVGException(SVGException.SVG_WRONG_TYPE_ERR, 153 "expected SVGPoint", 154 null); 155 } 156 } 157 158 161 protected class SVGPointItem 162 extends AbstractSVGItem 163 implements SVGPoint { 164 165 protected float x; 167 protected float y; 169 170 175 public SVGPointItem(float x, float y){ 176 this.x = x; 177 this.y = y; 178 } 179 180 186 protected String getStringValue(){ 187 StringBuffer value = new StringBuffer (); 188 value.append(x); 189 value.append(','); 190 value.append(y); 191 192 return value.toString(); 193 } 194 195 197 public float getX(){ 198 return x; 199 } 200 202 public float getY(){ 203 return y; 204 } 205 207 public void setX(float x){ 208 this.x = x; 209 resetAttribute(); 210 } 211 213 public void setY(float y){ 214 this.y = y; 215 resetAttribute(); 216 } 217 219 public SVGPoint matrixTransform ( SVGMatrix matrix ){ 220 throw new RuntimeException (" !!! TODO: matrixTransform ( SVGMatrix matrix )"); 221 } 222 } 223 224 228 protected class PointsListBuilder 229 implements PointsHandler { 230 231 234 protected ListHandler listHandler; 235 236 public PointsListBuilder(ListHandler listHandler){ 237 this.listHandler = listHandler; 238 } 239 240 public void startPoints() 241 throws ParseException{ 242 243 listHandler.startList(); 244 } 245 249 public void point(float x, float y) 250 throws ParseException { 251 252 listHandler.item(new SVGPointItem(x,y)); 253 } 254 255 public void endPoints() 256 throws ParseException { 257 listHandler.endList(); 258 } 259 } 260 261 } 262 | Popular Tags |