1 18 package org.apache.batik.dom.svg; 19 20 import java.awt.geom.AffineTransform ; 21 import java.util.List ; 22 23 import org.apache.batik.dom.AbstractDocument; 24 import org.apache.batik.dom.util.XLinkSupport; 25 import org.apache.batik.dom.util.XMLSupport; 26 import org.apache.batik.dom.util.ListNodeList; 27 28 import org.w3c.dom.DOMException ; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 import org.w3c.dom.css.CSSStyleDeclaration; 33 import org.w3c.dom.css.DocumentCSS; 34 import org.w3c.dom.css.ViewCSS; 35 import org.w3c.dom.events.DocumentEvent ; 36 import org.w3c.dom.events.Event ; 37 import org.w3c.dom.stylesheets.DocumentStyle; 38 import org.w3c.dom.stylesheets.StyleSheetList; 39 import org.w3c.dom.svg.SVGAngle; 40 import org.w3c.dom.svg.SVGAnimatedBoolean; 41 import org.w3c.dom.svg.SVGAnimatedLength; 42 import org.w3c.dom.svg.SVGAnimatedPreserveAspectRatio; 43 import org.w3c.dom.svg.SVGAnimatedRect; 44 import org.w3c.dom.svg.SVGElement; 45 import org.w3c.dom.svg.SVGException; 46 import org.w3c.dom.svg.SVGLength; 47 import org.w3c.dom.svg.SVGMatrix; 48 import org.w3c.dom.svg.SVGNumber; 49 import org.w3c.dom.svg.SVGPoint; 50 import org.w3c.dom.svg.SVGRect; 51 import org.w3c.dom.svg.SVGSVGElement; 52 import org.w3c.dom.svg.SVGStringList; 53 import org.w3c.dom.svg.SVGTransform; 54 import org.w3c.dom.svg.SVGViewSpec; 55 import org.w3c.dom.views.AbstractView; 56 import org.w3c.dom.views.DocumentView; 57 58 64 public class SVGOMSVGElement 65 extends SVGStylableElement 66 implements SVGSVGElement { 67 68 71 protected final static AttributeInitializer attributeInitializer; 72 static { 73 attributeInitializer = new AttributeInitializer(7); 74 attributeInitializer.addAttribute(XMLSupport.XMLNS_NAMESPACE_URI, 75 null, 76 "xmlns", 77 SVG_NAMESPACE_URI); 78 attributeInitializer.addAttribute(XMLSupport.XMLNS_NAMESPACE_URI, 79 "xmlns", 80 "xlink", 81 XLinkSupport.XLINK_NAMESPACE_URI); 82 attributeInitializer.addAttribute(null, 83 null, 84 SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE, 85 "xMidYMid meet"); 86 attributeInitializer.addAttribute(null, 87 null, 88 SVG_ZOOM_AND_PAN_ATTRIBUTE, 89 SVG_MAGNIFY_VALUE); 90 attributeInitializer.addAttribute(null, 91 null, 92 SVG_VERSION_ATTRIBUTE, 93 SVG_VERSION); 94 attributeInitializer.addAttribute(null, 95 null, 96 SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE, 97 "text/ecmascript"); 98 attributeInitializer.addAttribute(null, 99 null, 100 SVG_CONTENT_STYLE_TYPE_ATTRIBUTE, 101 "text/css"); 102 } 103 104 107 protected SVGOMSVGElement() { 108 } 109 110 115 public SVGOMSVGElement(String prefix, AbstractDocument owner) { 116 super(prefix, owner); 117 } 118 119 122 public String getLocalName() { 123 return SVG_SVG_TAG; 124 } 125 126 129 public SVGAnimatedLength getX() { 130 return getAnimatedLengthAttribute 131 (null, SVG_X_ATTRIBUTE, SVG_RECT_X_DEFAULT_VALUE, 132 SVGOMAnimatedLength.HORIZONTAL_LENGTH); 133 } 134 135 138 public SVGAnimatedLength getY() { 139 return getAnimatedLengthAttribute 140 (null, SVG_Y_ATTRIBUTE, SVG_SVG_Y_DEFAULT_VALUE, 141 SVGOMAnimatedLength.VERTICAL_LENGTH); 142 } 143 144 147 public SVGAnimatedLength getWidth() { 148 return getAnimatedLengthAttribute 149 (null, SVG_WIDTH_ATTRIBUTE, SVG_SVG_WIDTH_DEFAULT_VALUE, 150 SVGOMAnimatedLength.HORIZONTAL_LENGTH); 151 } 152 153 156 public SVGAnimatedLength getHeight() { 157 return getAnimatedLengthAttribute 158 (null, SVG_HEIGHT_ATTRIBUTE, SVG_SVG_HEIGHT_DEFAULT_VALUE, 159 SVGOMAnimatedLength.VERTICAL_LENGTH); 160 } 161 162 165 public String getContentScriptType() { 166 return getAttributeNS(null, SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE); 167 } 168 169 172 public void setContentScriptType(String type) { 173 setAttributeNS(null, SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE, type); 174 } 175 176 179 public String getContentStyleType() { 180 return getAttributeNS(null, SVG_CONTENT_STYLE_TYPE_ATTRIBUTE); 181 } 182 183 186 public void setContentStyleType(String type) { 187 setAttributeNS(null, SVG_CONTENT_STYLE_TYPE_ATTRIBUTE, type); 188 } 189 190 193 public SVGRect getViewport() { 194 SVGContext ctx = getSVGContext(); 195 return new SVGOMRect(0, 0, ctx.getViewportWidth(), 196 ctx.getViewportHeight()); 197 } 198 199 public float getPixelUnitToMillimeterX( ) { 200 return getSVGContext().getPixelUnitToMillimeter(); 201 } 202 public float getPixelUnitToMillimeterY( ) { 203 return getSVGContext().getPixelUnitToMillimeter(); 204 } 205 public float getScreenPixelToMillimeterX( ) { 206 return getSVGContext().getPixelUnitToMillimeter(); 207 } 208 public float getScreenPixelToMillimeterY( ) { 209 return getSVGContext().getPixelUnitToMillimeter(); 210 } 211 public boolean getUseCurrentView( ) { 212 throw new Error (); 213 } 214 public void setUseCurrentView( boolean useCurrentView ) 215 throws DOMException { 216 throw new Error (); 217 } 218 public SVGViewSpec getCurrentView( ) { 219 throw new Error (); 220 } 221 public float getCurrentScale( ) { 222 AffineTransform scrnTrans = getSVGContext().getScreenTransform(); 223 if (scrnTrans != null) 224 return (float)Math.sqrt(scrnTrans.getDeterminant()); 225 return 1; 226 } 227 public void setCurrentScale( float currentScale ) throws DOMException { 228 SVGContext context = getSVGContext(); 229 AffineTransform scrnTrans = context.getScreenTransform(); 230 float scale = 1; 231 if (scrnTrans != null) 232 scale = (float)Math.sqrt(scrnTrans.getDeterminant()); 233 float delta = currentScale/scale; 234 scrnTrans = new AffineTransform 237 (scrnTrans.getScaleX()*delta, scrnTrans.getShearY()*delta, 238 scrnTrans.getShearX()*delta, scrnTrans.getScaleY()*delta, 239 scrnTrans.getTranslateX(), scrnTrans.getTranslateY()); 240 context.setScreenTransform(scrnTrans); 241 } 242 243 public SVGPoint getCurrentTranslate( ) { 244 final SVGOMElement svgelt = this; 245 return new SVGPoint() { 246 AffineTransform getScreenTransform() { 247 SVGContext context = svgelt.getSVGContext(); 248 return context.getScreenTransform(); 249 } 250 251 public float getX() { 252 AffineTransform scrnTrans = getScreenTransform(); 253 return (float)scrnTrans.getTranslateX(); 254 } 255 public float getY() { 256 AffineTransform scrnTrans = getScreenTransform(); 257 return (float)scrnTrans.getTranslateY(); 258 } 259 public void setX(float newX) { 260 SVGContext context = svgelt.getSVGContext(); 261 AffineTransform scrnTrans = context.getScreenTransform(); 262 scrnTrans = new AffineTransform 263 (scrnTrans.getScaleX(), scrnTrans.getShearY(), 264 scrnTrans.getShearX(), scrnTrans.getScaleY(), 265 newX, scrnTrans.getTranslateY()); 266 context.setScreenTransform(scrnTrans); 267 } 268 public void setY(float newY) { 269 SVGContext context = svgelt.getSVGContext(); 270 AffineTransform scrnTrans = context.getScreenTransform(); 271 scrnTrans = new AffineTransform 272 (scrnTrans.getScaleX(), scrnTrans.getShearY(), 273 scrnTrans.getShearX(), scrnTrans.getScaleY(), 274 scrnTrans.getTranslateX(), newY); 275 context.setScreenTransform(scrnTrans); 276 } 277 public SVGPoint matrixTransform ( SVGMatrix mat ) { 278 AffineTransform scrnTrans = getScreenTransform(); 279 float x = (float)scrnTrans.getTranslateX(); 280 float y = (float)scrnTrans.getTranslateY(); 281 float newX = mat.getA()*x + mat.getC()*y + mat.getE(); 282 float newY = mat.getB()*x + mat.getD()*y + mat.getF(); 283 return new SVGOMPoint(newX, newY); 284 } 285 }; 286 } 287 288 public int suspendRedraw ( int max_wait_milliseconds ) { 289 throw new Error (); 290 } 291 public void unsuspendRedraw ( int suspend_handle_id ) 292 throws DOMException { 293 throw new Error (); 294 } 295 public void unsuspendRedrawAll ( ) { 296 throw new Error (); 297 } 298 public void forceRedraw ( ) { 299 throw new Error (); 300 } 301 public void pauseAnimations ( ) { 302 throw new Error (); 303 } 304 public void unpauseAnimations ( ) { 305 throw new Error (); 306 } 307 public boolean animationsPaused ( ) { 308 throw new Error (); 309 } 310 public float getCurrentTime ( ) { 311 throw new Error (); 312 } 313 public void setCurrentTime ( float seconds ) { 314 throw new Error (); 315 } 316 317 public NodeList getIntersectionList ( SVGRect rect, 318 SVGElement referenceElement ) { 319 SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); 320 List list = ctx.getIntersectionList(rect, referenceElement); 321 return new ListNodeList(list); 322 } 323 324 public NodeList getEnclosureList ( SVGRect rect, 325 SVGElement referenceElement ) { 326 SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); 327 List list = ctx.getEnclosureList(rect, referenceElement); 328 return new ListNodeList(list); 329 } 330 public boolean checkIntersection(SVGElement element, SVGRect rect) { 331 SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); 332 return ctx.checkIntersection(element, rect); 333 } 334 public boolean checkEnclosure(SVGElement element, SVGRect rect) { 335 SVGSVGContext ctx = (SVGSVGContext)getSVGContext(); 336 return ctx.checkEnclosure(element, rect); 337 } 338 339 public void deselectAll ( ) { 340 ((SVGSVGContext)getSVGContext()).deselectAll(); 341 } 342 343 346 public SVGNumber createSVGNumber() { 347 return new SVGNumber() { 348 float value; 349 public float getValue() { 350 return value; 351 } 352 public void setValue(float f) { 353 value = f; 354 } 355 }; 356 } 357 358 361 public SVGLength createSVGLength() { 362 return new SVGOMLength(this); 363 } 364 365 public SVGAngle createSVGAngle ( ) { 366 throw new Error (); 367 } 368 369 372 public SVGPoint createSVGPoint() { 373 return new SVGOMPoint(0, 0); 374 } 375 376 public SVGMatrix createSVGMatrix ( ) { 377 return new AbstractSVGMatrix() { 378 AffineTransform at = new AffineTransform (); 379 protected AffineTransform getAffineTransform() { return at; } 380 }; 381 } 382 public SVGRect createSVGRect ( ) { 383 return new SVGOMRect(0,0,0,0); 384 } 385 public SVGTransform createSVGTransform () { 386 SVGOMTransform ret = new SVGOMTransform(); 387 ret.setType(SVGTransform.SVG_TRANSFORM_MATRIX); 388 return ret; 389 } 390 public SVGTransform createSVGTransformFromMatrix ( SVGMatrix matrix ) { 391 SVGOMTransform tr = new SVGOMTransform(); 392 tr.setMatrix(matrix); 393 return tr; 394 } 395 public Element getElementById ( String elementId ) { 396 return ownerDocument.getChildElementById(this, elementId); 397 } 398 399 401 405 public SVGElement getNearestViewportElement() { 406 return SVGLocatableSupport.getNearestViewportElement(this); 407 } 408 409 413 public SVGElement getFarthestViewportElement() { 414 return SVGLocatableSupport.getFarthestViewportElement(this); 415 } 416 417 421 public SVGRect getBBox() { 422 return SVGLocatableSupport.getBBox(this); 423 } 424 425 429 public SVGMatrix getCTM() { 430 return SVGLocatableSupport.getCTM(this); 431 } 432 433 437 public SVGMatrix getScreenCTM() { 438 return SVGLocatableSupport.getScreenCTM(this); 439 } 440 441 445 public SVGMatrix getTransformToElement(SVGElement element) 446 throws SVGException { 447 return SVGLocatableSupport.getTransformToElement(this, element); 448 } 449 450 452 456 public DocumentView getDocument() { 457 return (DocumentView)getOwnerDocument(); 458 } 459 460 464 public CSSStyleDeclaration getComputedStyle(Element elt, 465 String pseudoElt) { 466 AbstractView av = ((DocumentView)getOwnerDocument()).getDefaultView(); 467 return ((ViewCSS)av).getComputedStyle(elt, pseudoElt); 468 } 469 470 472 476 public Event createEvent(String eventType) throws DOMException { 477 return ((DocumentEvent )getOwnerDocument()).createEvent(eventType); 478 } 479 480 482 486 public StyleSheetList getStyleSheets() { 487 return ((DocumentStyle)getOwnerDocument()).getStyleSheets(); 488 } 489 490 494 public CSSStyleDeclaration getOverrideStyle(Element elt, 495 String pseudoElt) { 496 return ((DocumentCSS)getOwnerDocument()).getOverrideStyle(elt, 497 pseudoElt); 498 } 499 500 502 505 public String getXMLlang() { 506 return XMLSupport.getXMLLang(this); 507 } 508 509 512 public void setXMLlang(String lang) { 513 setAttributeNS(XMLSupport.XML_NAMESPACE_URI, 514 XMLSupport.XML_LANG_ATTRIBUTE, 515 lang); 516 } 517 518 521 public String getXMLspace() { 522 return XMLSupport.getXMLSpace(this); 523 } 524 525 528 public void setXMLspace(String space) { 529 setAttributeNS(XMLSupport.XML_NAMESPACE_URI, 530 XMLSupport.XML_SPACE_ATTRIBUTE, 531 space); 532 } 533 534 536 540 public short getZoomAndPan() { 541 return SVGZoomAndPanSupport.getZoomAndPan(this); 542 } 543 544 548 public void setZoomAndPan(short val) { 549 SVGZoomAndPanSupport.setZoomAndPan(this, val); 550 } 551 552 554 558 public SVGAnimatedRect getViewBox() { 559 throw new RuntimeException (" !!! TODO: getViewBox()"); 560 } 561 562 566 public SVGAnimatedPreserveAspectRatio getPreserveAspectRatio() { 567 return SVGPreserveAspectRatioSupport.getPreserveAspectRatio(this); 568 } 569 570 572 576 public SVGAnimatedBoolean getExternalResourcesRequired() { 577 return SVGExternalResourcesRequiredSupport. 578 getExternalResourcesRequired(this); 579 } 580 581 583 587 public SVGStringList getRequiredFeatures() { 588 return SVGTestsSupport.getRequiredFeatures(this); 589 } 590 591 595 public SVGStringList getRequiredExtensions() { 596 return SVGTestsSupport.getRequiredExtensions(this); 597 } 598 599 603 public SVGStringList getSystemLanguage() { 604 return SVGTestsSupport.getSystemLanguage(this); 605 } 606 607 611 public boolean hasExtension(String extension) { 612 return SVGTestsSupport.hasExtension(this, extension); 613 } 614 615 619 protected AttributeInitializer getAttributeInitializer() { 620 return attributeInitializer; 621 } 622 623 626 protected Node newNode() { 627 return new SVGOMSVGElement(); 628 } 629 } 630 | Popular Tags |