1 18 package org.apache.batik.swing.svg; 19 20 import java.awt.Cursor ; 21 import java.awt.Dimension ; 22 import java.awt.EventQueue ; 23 import java.awt.Point ; 24 import java.awt.Rectangle ; 25 import java.awt.Shape ; 26 import java.awt.event.ComponentAdapter ; 27 import java.awt.event.ComponentEvent ; 28 import java.awt.event.KeyEvent ; 29 import java.awt.event.MouseEvent ; 30 import java.awt.geom.AffineTransform ; 31 import java.awt.geom.Dimension2D ; 32 import java.awt.geom.NoninvertibleTransformException ; 33 import java.awt.geom.Point2D ; 34 import java.util.ArrayList ; 35 import java.util.HashMap ; 36 import java.util.HashSet ; 37 import java.util.Iterator ; 38 import java.util.LinkedList ; 39 import java.util.List ; 40 import java.util.Map ; 41 import java.util.Set ; 42 43 import javax.swing.JOptionPane ; 44 45 import org.apache.batik.bridge.BridgeContext; 46 import org.apache.batik.bridge.BridgeException; 47 import org.apache.batik.bridge.BridgeExtension; 48 import org.apache.batik.bridge.DefaultScriptSecurity; 49 import org.apache.batik.bridge.DocumentLoader; 50 import org.apache.batik.bridge.ExternalResourceSecurity; 51 import org.apache.batik.bridge.RelaxedExternalResourceSecurity; 52 import org.apache.batik.bridge.ScriptSecurity; 53 import org.apache.batik.bridge.UpdateManager; 54 import org.apache.batik.bridge.UpdateManagerAdapter; 55 import org.apache.batik.bridge.UpdateManagerEvent; 56 import org.apache.batik.bridge.UpdateManagerListener; 57 import org.apache.batik.bridge.UserAgent; 58 import org.apache.batik.bridge.ViewBox; 59 import org.apache.batik.dom.svg.SVGDOMImplementation; 60 import org.apache.batik.dom.util.DOMUtilities; 61 import org.apache.batik.dom.util.XLinkSupport; 62 import org.apache.batik.ext.awt.image.spi.ImageTagRegistry; 63 import org.apache.batik.gvt.CanvasGraphicsNode; 64 import org.apache.batik.gvt.CompositeGraphicsNode; 65 import org.apache.batik.gvt.GraphicsNode; 66 import org.apache.batik.gvt.event.EventDispatcher; 67 import org.apache.batik.gvt.text.Mark; 68 import org.apache.batik.gvt.renderer.ImageRenderer; 69 import org.apache.batik.swing.gvt.GVTTreeRenderer; 70 import org.apache.batik.swing.gvt.GVTTreeRendererEvent; 71 import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; 72 import org.apache.batik.swing.gvt.JGVTComponent; 73 import org.apache.batik.swing.gvt.JGVTComponentListener; 74 import org.apache.batik.util.ParsedURL; 75 import org.apache.batik.util.RunnableQueue; 76 import org.apache.batik.util.SVGConstants; 77 import org.apache.batik.util.XMLResourceDescriptor; 78 import org.w3c.dom.Document ; 79 import org.w3c.dom.DOMImplementation ; 80 import org.w3c.dom.Element ; 81 import org.w3c.dom.svg.SVGAElement; 82 import org.w3c.dom.svg.SVGDocument; 83 import org.w3c.dom.svg.SVGSVGElement; 84 85 196 public class JSVGComponent extends JGVTComponent { 197 198 202 public final static int AUTODETECT = 0; 203 204 211 public final static int ALWAYS_DYNAMIC = 1; 212 213 221 public final static int ALWAYS_STATIC = 2; 222 223 230 public final static int ALWAYS_INTERACTIVE = 3; 231 232 235 protected SVGDocumentLoader documentLoader; 236 237 240 protected SVGDocumentLoader nextDocumentLoader; 241 242 245 protected DocumentLoader loader; 246 247 250 protected GVTTreeBuilder gvtTreeBuilder; 251 252 255 protected GVTTreeBuilder nextGVTTreeBuilder; 256 257 260 protected SVGLoadEventDispatcher svgLoadEventDispatcher; 261 262 265 protected UpdateManager updateManager; 266 267 270 protected UpdateManager nextUpdateManager; 271 272 275 protected SVGDocument svgDocument; 276 277 280 protected List svgDocumentLoaderListeners = new LinkedList (); 281 282 285 protected List gvtTreeBuilderListeners = new LinkedList (); 286 287 290 protected List svgLoadEventDispatcherListeners = new LinkedList (); 291 292 295 protected List linkActivationListeners = new LinkedList (); 296 297 300 protected List updateManagerListeners = new LinkedList (); 301 302 305 protected UserAgent userAgent; 306 307 310 protected SVGUserAgent svgUserAgent; 311 312 315 protected BridgeContext bridgeContext; 316 317 320 protected String fragmentIdentifier; 321 322 325 protected boolean isDynamicDocument; 326 327 330 protected boolean isInteractiveDocument; 331 332 335 protected int documentState; 336 337 protected Dimension prevComponentSize; 338 339 protected Runnable afterStopRunnable = null; 340 341 protected SVGUpdateOverlay updateOverlay; 343 protected boolean recenterOnResize = true; 344 345 protected AffineTransform viewingTransform = null; 346 347 350 public JSVGComponent() { 351 this(null, false, false); 352 } 353 354 361 public JSVGComponent(SVGUserAgent ua, boolean eventsEnabled, 362 boolean selectableText) { 363 super(eventsEnabled, selectableText); 364 365 svgUserAgent = ua; 366 367 userAgent = new BridgeUserAgentWrapper(createUserAgent()); 368 369 addSVGDocumentLoaderListener((SVGListener)listener); 370 addGVTTreeBuilderListener((SVGListener)listener); 371 addSVGLoadEventDispatcherListener((SVGListener)listener); 372 if (updateOverlay != null) 373 getOverlays().add(updateOverlay); 374 } 375 376 public void dispose() { 377 setSVGDocument(null); 378 } 379 380 386 public boolean getRecenterOnResize() { 387 return recenterOnResize; 388 } 389 392 public void setRecenterOnResize(boolean recenterOnResize) { 393 this.recenterOnResize = recenterOnResize; 394 } 395 396 400 public boolean isDynamic() { 401 return isDynamicDocument; 402 } 403 404 408 public boolean isInteractive() { 409 return isInteractiveDocument; 410 } 411 412 418 public void setDocumentState(int state) { 419 documentState = state; 420 } 421 422 438 public UpdateManager getUpdateManager() { 439 if (svgLoadEventDispatcher != null) { 440 return svgLoadEventDispatcher.getUpdateManager(); 441 } 442 if (nextUpdateManager != null) { 443 return nextUpdateManager; 444 } 445 return updateManager; 446 } 447 448 451 public void resumeProcessing() { 452 if (updateManager != null) { 453 updateManager.resume(); 454 } 455 } 456 457 460 public void suspendProcessing() { 461 if (updateManager != null) { 462 updateManager.suspend(); 463 } 464 } 465 466 469 public void stopProcessing() { 470 nextDocumentLoader = null; 471 nextGVTTreeBuilder = null; 472 473 if (documentLoader != null) { 474 documentLoader.halt(); 475 } 476 if (gvtTreeBuilder != null) { 477 gvtTreeBuilder.halt(); 478 } 479 if (svgLoadEventDispatcher != null) { 480 svgLoadEventDispatcher.halt(); 481 } 482 if (nextUpdateManager != null) { 483 nextUpdateManager.interrupt(); 484 nextUpdateManager = null; 485 } 486 if (updateManager != null) { 487 updateManager.interrupt(); 488 } 489 super.stopProcessing(); 490 } 491 492 499 public void loadSVGDocument(String url) { 500 String oldURI = null; 501 if (svgDocument != null) { 502 oldURI = svgDocument.getURL(); 503 } 504 final ParsedURL newURI = new ParsedURL(oldURI, url); 505 506 stopThenRun(new Runnable () { 507 public void run() { 508 String url = newURI.toString(); 509 fragmentIdentifier = newURI.getRef(); 510 511 loader = new DocumentLoader(userAgent); 512 nextDocumentLoader = new SVGDocumentLoader(url, loader); 513 nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); 514 515 Iterator it = svgDocumentLoaderListeners.iterator(); 516 while (it.hasNext()) { 517 nextDocumentLoader.addSVGDocumentLoaderListener 518 ((SVGDocumentLoaderListener)it.next()); 519 } 520 startDocumentLoader(); 521 } 522 }); 523 } 524 525 528 private void startDocumentLoader() { 529 documentLoader = nextDocumentLoader; 530 nextDocumentLoader = null; 531 documentLoader.start(); 532 } 533 534 550 public void setDocument(Document doc) { 551 if ((doc != null) && 552 !(doc.getImplementation() instanceof SVGDOMImplementation)) { 553 DOMImplementation impl; 554 impl = SVGDOMImplementation.getDOMImplementation(); 555 Document d = DOMUtilities.deepCloneDocument(doc, impl); 556 doc = d; 557 } 558 setSVGDocument((SVGDocument)doc); 559 } 560 561 578 public void setSVGDocument(SVGDocument doc) { 579 if ((doc != null) && 580 !(doc.getImplementation() instanceof SVGDOMImplementation)) { 581 DOMImplementation impl; 582 impl = SVGDOMImplementation.getDOMImplementation(); 583 Document d = DOMUtilities.deepCloneDocument(doc, impl); 584 doc = (SVGDocument)d; 585 } 586 587 final SVGDocument svgdoc = doc; 588 stopThenRun(new Runnable () { 589 public void run() { 590 installSVGDocument(svgdoc); 591 } 592 }); 593 } 594 595 600 protected void stopThenRun(final Runnable r) { 601 if (afterStopRunnable != null) { 602 afterStopRunnable = r; 605 return; 606 } 607 afterStopRunnable = r; 608 609 stopProcessing(); 610 611 if ((documentLoader == null) && 612 (gvtTreeBuilder == null) && 613 (gvtTreeRenderer == null) && 614 (svgLoadEventDispatcher == null) && 615 (nextUpdateManager == null) && 616 (updateManager == null)) { 617 Runnable asr = afterStopRunnable; 618 afterStopRunnable = null; 619 asr.run(); 620 } 621 } 622 623 628 protected void installSVGDocument(SVGDocument doc) { 629 svgDocument = doc; 630 631 if (bridgeContext != null) { 632 bridgeContext.dispose(); 633 bridgeContext = null; 634 } 635 636 releaseRenderingReferences(); 637 638 if (doc == null) { 639 isDynamicDocument = false; 640 isInteractiveDocument = false; 641 disableInteractions = true; 642 initialTransform = new AffineTransform (); 643 setRenderingTransform(initialTransform, false); 644 Rectangle vRect = getRenderRect(); 645 repaint(vRect.x, vRect.y, 646 vRect.width, vRect.height); 647 return; 648 } 649 650 bridgeContext = createBridgeContext(); 651 652 switch (documentState) { 653 case ALWAYS_STATIC: 654 isDynamicDocument = false; 655 isInteractiveDocument = false; 656 break; 657 case ALWAYS_INTERACTIVE: 658 isDynamicDocument = false; 659 isInteractiveDocument = true; 660 break; 661 case ALWAYS_DYNAMIC: 662 isDynamicDocument = true; 663 isInteractiveDocument = true; 664 break; 665 case AUTODETECT: 666 isDynamicDocument = bridgeContext.isDynamicDocument(doc); 667 if (isDynamicDocument) 668 isInteractiveDocument = true; 669 else 670 isInteractiveDocument = 671 bridgeContext.isInteractiveDocument(doc); 672 } 673 674 if (isInteractiveDocument) { 675 if (isDynamicDocument) 676 bridgeContext.setDynamicState(BridgeContext.DYNAMIC); 677 else 678 bridgeContext.setDynamicState(BridgeContext.INTERACTIVE); 679 } 680 681 Element root = doc.getDocumentElement(); 682 String znp = root.getAttributeNS 683 (null, SVGConstants.SVG_ZOOM_AND_PAN_ATTRIBUTE); 684 685 setDisableInteractions(!znp.equals(SVGConstants.SVG_MAGNIFY_VALUE)); 686 687 nextGVTTreeBuilder = new GVTTreeBuilder(doc, bridgeContext); 688 nextGVTTreeBuilder.setPriority(Thread.MIN_PRIORITY); 689 690 Iterator it = gvtTreeBuilderListeners.iterator(); 691 while (it.hasNext()) { 692 nextGVTTreeBuilder.addGVTTreeBuilderListener 693 ((GVTTreeBuilderListener)it.next()); 694 } 695 696 initializeEventHandling(); 697 698 if (gvtTreeBuilder == null && 699 documentLoader == null && 700 gvtTreeRenderer == null && 701 svgLoadEventDispatcher == null && 702 updateManager == null) { 703 startGVTTreeBuilder(); 704 } 705 } 706 707 710 protected void startGVTTreeBuilder() { 711 gvtTreeBuilder = nextGVTTreeBuilder; 712 nextGVTTreeBuilder = null; 713 gvtTreeBuilder.start(); 714 } 715 716 719 public SVGDocument getSVGDocument() { 720 return svgDocument; 721 } 722 723 726 public Dimension2D getSVGDocumentSize() { 727 return bridgeContext.getDocumentSize(); 728 } 729 730 733 public String getFragmentIdentifier() { 734 return fragmentIdentifier; 735 } 736 737 740 public void setFragmentIdentifier(String fi) { 741 fragmentIdentifier = fi; 742 if (computeRenderingTransform()) 743 scheduleGVTRendering(); 744 } 745 746 749 public void flushImageCache() { 750 ImageTagRegistry reg = ImageTagRegistry.getRegistry(); 751 reg.flushCache(); 752 } 753 754 public void setGraphicsNode(GraphicsNode gn, boolean createDispatcher) { 755 Dimension2D dim = bridgeContext.getDocumentSize(); 756 Dimension mySz = new Dimension ((int)dim.getWidth(), 757 (int)dim.getHeight()); 758 JSVGComponent.this.setMySize(mySz); 759 SVGSVGElement elt = svgDocument.getRootElement(); 760 prevComponentSize = getSize(); 761 AffineTransform at = calculateViewingTransform 762 (fragmentIdentifier, elt); 763 CanvasGraphicsNode cgn = getCanvasGraphicsNode(gn); 764 cgn.setViewingTransform(at); 765 viewingTransform = null; 766 initialTransform = new AffineTransform (); 767 setRenderingTransform(initialTransform, false); 768 jsvgComponentListener.updateMatrix(initialTransform); 769 addJGVTComponentListener(jsvgComponentListener); 770 addComponentListener(jsvgComponentListener); 771 super.setGraphicsNode(gn, createDispatcher); 772 } 773 774 777 protected BridgeContext createBridgeContext() { 778 if (loader == null) { 779 loader = new DocumentLoader(userAgent); 780 } 781 BridgeContext result = new BridgeContext(userAgent, loader); 782 return result; 783 } 784 785 788 protected void startSVGLoadEventDispatcher(GraphicsNode root) { 789 UpdateManager um = new UpdateManager(bridgeContext, 790 root, 791 svgDocument); 792 svgLoadEventDispatcher = 793 new SVGLoadEventDispatcher(root, 794 svgDocument, 795 bridgeContext, 796 um); 797 Iterator it = svgLoadEventDispatcherListeners.iterator(); 798 while (it.hasNext()) { 799 svgLoadEventDispatcher.addSVGLoadEventDispatcherListener 800 ((SVGLoadEventDispatcherListener)it.next()); 801 } 802 803 svgLoadEventDispatcher.start(); 804 } 805 806 809 protected ImageRenderer createImageRenderer() { 810 if (isDynamicDocument) { 811 return rendererFactory.createDynamicImageRenderer(); 812 } else { 813 return rendererFactory.createStaticImageRenderer(); 814 } 815 } 816 817 public CanvasGraphicsNode getCanvasGraphicsNode() { 818 return getCanvasGraphicsNode(gvtRoot); 819 820 } 821 822 protected CanvasGraphicsNode getCanvasGraphicsNode(GraphicsNode gn) { 823 if (!(gn instanceof CompositeGraphicsNode)) 824 return null; 825 CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn; 826 List children = cgn.getChildren(); 827 if (children.size() == 0) 828 return null; 829 gn = (GraphicsNode)children.get(0); 830 if (!(gn instanceof CanvasGraphicsNode)) 831 return null; 832 return (CanvasGraphicsNode)gn; 833 } 834 835 public AffineTransform getViewingTransform() { 836 AffineTransform vt; 837 synchronized (this) { 838 vt = viewingTransform; 839 if (vt == null) { 840 CanvasGraphicsNode cgn = getCanvasGraphicsNode(); 841 if (cgn != null) 842 vt = cgn.getViewingTransform(); 843 } 844 } 845 return vt; 846 } 847 848 851 public AffineTransform getViewBoxTransform() { 852 AffineTransform at = getRenderingTransform(); 853 if (at == null) at = new AffineTransform (); 854 else at = new AffineTransform (at); 855 AffineTransform vt = getViewingTransform(); 856 if (vt != null) { 857 at.concatenate(vt); 858 } 859 return at; 860 } 861 862 866 protected boolean computeRenderingTransform() { 867 if ((svgDocument == null) || (gvtRoot == null)) 868 return false; 869 870 boolean ret = updateRenderingTransform(); 871 initialTransform = new AffineTransform (); 872 if (!initialTransform.equals(getRenderingTransform())) { 873 setRenderingTransform(initialTransform, false); 874 ret = true; 875 } 876 return ret; 877 } 878 879 protected AffineTransform calculateViewingTransform 880 (String fragIdent, SVGSVGElement svgElt) { 881 Dimension d = getSize(); 882 if (d.width < 1) d.width = 1; 883 if (d.height < 1) d.height = 1; 884 return ViewBox.getViewTransform 885 (fragIdent, svgElt, d.width, d.height); 886 } 887 888 892 protected boolean updateRenderingTransform() { 893 if ((svgDocument == null) || (gvtRoot == null)) 894 return false; 895 896 try { 897 SVGSVGElement elt = svgDocument.getRootElement(); 898 Dimension d = getSize(); 899 Dimension oldD = prevComponentSize; 900 if (oldD == null) oldD = d; 901 prevComponentSize = d; 902 if (d.width < 1) d.width = 1; 903 if (d.height < 1) d.height = 1; 904 final AffineTransform at = calculateViewingTransform 905 (fragmentIdentifier, elt); 906 AffineTransform vt = getViewingTransform(); 907 if (at.equals(vt)) { 908 return ((oldD.width != d.width) || (oldD.height != d.height)); 911 } 912 913 if (!recenterOnResize) 914 return true; 915 916 Point2D pt = new Point2D.Float (oldD.width/2.0f, 922 oldD.height/2.0f); 923 AffineTransform rendAT = getRenderingTransform(); 924 if (rendAT != null) { 925 try { 926 AffineTransform invRendAT = rendAT.createInverse(); 927 pt = invRendAT.transform(pt, null); 928 } catch (NoninvertibleTransformException e) { } 929 } 930 if (vt != null) { 931 try { 932 AffineTransform invVT = vt.createInverse(); 933 pt = invVT.transform(pt, null); 934 } catch (NoninvertibleTransformException e) { } 935 } 936 if (at != null) 937 pt = at.transform(pt, null); 938 if (rendAT != null) 939 pt = rendAT.transform(pt, null); 940 941 float dx = (float)((d.width/2.0f) -pt.getX()); 944 float dy = (float)((d.height/2.0f)-pt.getY()); 945 dx = (int)((dx < 0)?(dx - .5):(dx + .5)); 947 dy = (int)((dy < 0)?(dy - .5):(dy + .5)); 948 if ((dx != 0) || (dy != 0)) { 949 rendAT.preConcatenate 950 (AffineTransform.getTranslateInstance(dx, dy)); 951 setRenderingTransform(rendAT, false); 952 } 953 synchronized (this) { 954 viewingTransform = at; 955 } 956 Runnable r = new Runnable () { 957 AffineTransform myAT = at; 958 CanvasGraphicsNode myCGN = getCanvasGraphicsNode(); 959 public void run() { 960 synchronized (JSVGComponent.this) { 961 myCGN.setViewingTransform(myAT); 962 if (viewingTransform == myAT) 963 viewingTransform = null; 964 } 965 } 966 }; 967 UpdateManager um = getUpdateManager(); 968 if (um != null) um.getUpdateRunnableQueue().invokeLater(r); 969 else r.run(); 970 } catch (BridgeException e) { 971 userAgent.displayError(e); 972 } 973 return true; 974 } 975 976 979 protected void renderGVTTree() { 980 if (!isInteractiveDocument || 981 updateManager == null || 982 !updateManager.isRunning()) { 983 super.renderGVTTree(); 984 return; 985 } 986 987 final Rectangle visRect = getRenderRect(); 988 if ((gvtRoot == null) || 989 (visRect.width <= 0) || 990 (visRect.height <= 0)) { 991 return; 992 } 993 994 AffineTransform inv = null; 996 try { 997 inv = renderingTransform.createInverse(); 998 } catch (NoninvertibleTransformException e) { 999 } 1000 final Shape s; 1001 if (inv == null) s = visRect; 1002 else s = inv.createTransformedShape(visRect); 1003 1004 class UpdateRenderingRunnable implements Runnable { 1005 AffineTransform at; 1006 boolean doubleBuf; 1007 boolean clearPaintTrans; 1008 Shape aoi; 1009 int width; 1010 int height; 1011 1012 boolean active; 1013 1014 public UpdateRenderingRunnable(AffineTransform at, 1015 boolean doubleBuf, 1016 boolean clearPaintTrans, 1017 Shape aoi, 1018 int width, int height) { 1019 updateInfo(at, doubleBuf, clearPaintTrans, aoi, width, height); 1020 active = true; 1021 } 1022 1023 public void updateInfo(AffineTransform at, 1024 boolean doubleBuf, 1025 boolean clearPaintTrans, 1026 Shape aoi, 1027 int width, int height) { 1028 this.at = at; 1029 this.doubleBuf = doubleBuf; 1030 this.clearPaintTrans = clearPaintTrans; 1031 this.aoi = aoi; 1032 this.width = width; 1033 this.height = height; 1034 active = true; 1035 } 1036 1037 public void deactivate() { 1038 active = false; 1039 } 1040 public void run() { 1041 if (!active) return; 1042 1043 updateManager.updateRendering 1044 (at, doubleBuf, clearPaintTrans, aoi, width, height); 1045 } 1046 } 1047 RunnableQueue rq = updateManager.getUpdateRunnableQueue(); 1048 1049 synchronized (rq.getIteratorLock()) { 1051 Iterator it = rq.iterator(); 1052 while (it.hasNext()) { 1053 Object next = it.next(); 1054 if (next instanceof UpdateRenderingRunnable) { 1055 ((UpdateRenderingRunnable)next).deactivate(); 1056 } 1057 } 1058 } 1059 1060 rq.invokeLater(new UpdateRenderingRunnable 1061 (renderingTransform, 1062 doubleBufferedRendering, true, s, 1063 visRect.width, visRect.height)); 1064 } 1065 1066 1069 protected void handleException(Exception e) { 1070 userAgent.displayError(e); 1071 } 1072 1073 1076 public void addSVGDocumentLoaderListener(SVGDocumentLoaderListener l) { 1077 svgDocumentLoaderListeners.add(l); 1078 } 1079 1080 1083 public void removeSVGDocumentLoaderListener(SVGDocumentLoaderListener l) { 1084 svgDocumentLoaderListeners.remove(l); 1085 } 1086 1087 1090 public void addGVTTreeBuilderListener(GVTTreeBuilderListener l) { 1091 gvtTreeBuilderListeners.add(l); 1092 } 1093 1094 1097 public void removeGVTTreeBuilderListener(GVTTreeBuilderListener l) { 1098 gvtTreeBuilderListeners.remove(l); 1099 } 1100 1101 1104 public void addSVGLoadEventDispatcherListener 1105 (SVGLoadEventDispatcherListener l) { 1106 svgLoadEventDispatcherListeners.add(l); 1107 } 1108 1109 1112 public void removeSVGLoadEventDispatcherListener 1113 (SVGLoadEventDispatcherListener l) { 1114 svgLoadEventDispatcherListeners.remove(l); 1115 } 1116 1117 1120 public void addLinkActivationListener(LinkActivationListener l) { 1121 linkActivationListeners.add(l); 1122 } 1123 1124 1127 public void removeLinkActivationListener(LinkActivationListener l) { 1128 linkActivationListeners.remove(l); 1129 } 1130 1131 1134 public void addUpdateManagerListener(UpdateManagerListener l) { 1135 updateManagerListeners.add(l); 1136 } 1137 1138 1141 public void removeUpdateManagerListener(UpdateManagerListener l) { 1142 updateManagerListeners.remove(l); 1143 } 1144 1145 1148 public void showAlert(String message) { 1149 JOptionPane.showMessageDialog 1150 (this, Messages.formatMessage("script.alert", 1151 new Object [] { message })); 1152 } 1153 1154 1157 public String showPrompt(String message) { 1158 return JOptionPane.showInputDialog 1159 (this, Messages.formatMessage("script.prompt", 1160 new Object [] { message })); 1161 } 1162 1163 1166 public String showPrompt(String message, String defaultValue) { 1167 return (String )JOptionPane.showInputDialog 1168 (this, 1169 Messages.formatMessage("script.prompt", 1170 new Object [] { message }), 1171 null, 1172 JOptionPane.PLAIN_MESSAGE, 1173 null, null, defaultValue); 1174 } 1175 1176 1179 public boolean showConfirm(String message) { 1180 return JOptionPane.showConfirmDialog 1181 (this, Messages.formatMessage("script.confirm", 1182 new Object [] { message }), 1183 "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; 1184 } 1185 1186 1187 1196 public void setMySize(Dimension d) { 1197 setPreferredSize(d); 1198 invalidate(); 1199 } 1200 1201 1204 protected JSVGComponentListener jsvgComponentListener = 1205 new JSVGComponentListener(); 1206 1207 protected class JSVGComponentListener extends ComponentAdapter 1208 implements JGVTComponentListener { 1209 float prevScale = 0; 1210 float prevTransX = 0; 1211 float prevTransY = 0; 1212 1213 public void componentResized(ComponentEvent ce) { 1214 if (isDynamicDocument && 1215 (updateManager != null) && updateManager.isRunning()) { 1216 updateManager.getUpdateRunnableQueue().invokeLater 1217 (new Runnable () { 1218 public void run() { 1219 try { 1220 updateManager.dispatchSVGResizeEvent(); 1221 } catch (InterruptedException ie) { 1222 } 1223 }}); 1224 } 1225 } 1226 1227 public void componentTransformChanged(ComponentEvent event) { 1228 AffineTransform at = getRenderingTransform(); 1229 1230 float currScale = (float)Math.sqrt(at.getDeterminant()); 1231 float currTransX = (float)at.getTranslateX(); 1232 float currTransY = (float)at.getTranslateY(); 1233 1234 final boolean dispatchZoom = (currScale != prevScale); 1235 final boolean dispatchScroll = ((currTransX != prevTransX) || 1236 (currTransX != prevTransX)); 1237 if (isDynamicDocument && 1238 (updateManager != null) && updateManager.isRunning()) { 1239 updateManager.getUpdateRunnableQueue().invokeLater 1240 (new Runnable () { 1241 public void run() { 1242 try { 1243 if (dispatchZoom) 1244 updateManager.dispatchSVGZoomEvent(); 1245 if (dispatchScroll) 1246 updateManager.dispatchSVGScrollEvent(); 1247 } catch (InterruptedException ie) { 1248 } 1249 }}); 1250 } 1251 prevScale = currScale; 1252 prevTransX = currTransX; 1253 prevTransY = currTransY; 1254 } 1255 1256 public void updateMatrix(AffineTransform at) { 1257 prevScale = (float)Math.sqrt(at.getDeterminant()); 1258 prevTransX = (float)at.getTranslateX(); 1259 prevTransY = (float)at.getTranslateY(); 1260 } 1261 } 1262 1263 1264 1267 protected Listener createListener() { 1268 return new SVGListener(); 1269 } 1270 1271 1274 protected class SVGListener 1275 extends Listener 1276 implements SVGDocumentLoaderListener, 1277 GVTTreeBuilderListener, 1278 SVGLoadEventDispatcherListener, 1279 UpdateManagerListener { 1280 1281 1284 protected SVGListener() { 1285 } 1286 1287 1289 1292 public void documentLoadingStarted(SVGDocumentLoaderEvent e) { 1293 } 1294 1295 1298 public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { 1299 if (nextDocumentLoader != null) { 1300 startDocumentLoader(); 1301 return; 1302 } 1303 1304 documentLoader = null; 1305 if (afterStopRunnable != null) { 1306 EventQueue.invokeLater(afterStopRunnable); 1307 afterStopRunnable = null; 1308 return; 1309 } 1310 1311 setSVGDocument(e.getSVGDocument()); 1312 } 1313 1314 1317 public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { 1318 if (nextDocumentLoader != null) { 1319 startDocumentLoader(); 1320 return; 1321 } 1322 1323 documentLoader = null; 1324 if (afterStopRunnable != null) { 1325 EventQueue.invokeLater(afterStopRunnable); 1326 afterStopRunnable = null; 1327 return; 1328 } 1329 1330 if (nextGVTTreeBuilder != null) { 1331 startGVTTreeBuilder(); 1332 return; 1333 } 1334 } 1335 1336 1339 public void documentLoadingFailed(SVGDocumentLoaderEvent e) { 1340 if (nextDocumentLoader != null) { 1341 startDocumentLoader(); 1342 return; 1343 } 1344 1345 documentLoader = null; 1346 userAgent.displayError(((SVGDocumentLoader)e.getSource()). 1347 getException()); 1348 1349 if (afterStopRunnable != null) { 1350 EventQueue.invokeLater(afterStopRunnable); 1351 afterStopRunnable = null; 1352 return; 1353 } 1354 if (nextGVTTreeBuilder != null) { 1355 startGVTTreeBuilder(); 1356 return; 1357 } 1358 } 1359 1360 1362 1366 public void gvtBuildStarted(GVTTreeBuilderEvent e) { 1367 removeJGVTComponentListener(jsvgComponentListener); 1368 removeComponentListener(jsvgComponentListener); 1369 } 1370 1371 1374 public void gvtBuildCompleted(GVTTreeBuilderEvent e) { 1375 if (nextGVTTreeBuilder != null) { 1376 startGVTTreeBuilder(); 1377 return; 1378 } 1379 1380 loader = null; 1381 gvtTreeBuilder = null; 1382 1383 if (afterStopRunnable != null) { 1384 EventQueue.invokeLater(afterStopRunnable); 1385 afterStopRunnable = null; 1386 return; 1387 } 1388 1389 if (nextDocumentLoader != null) { 1390 startDocumentLoader(); 1391 return; 1392 } 1393 1394 gvtRoot = null; 1395 1396 if (isDynamicDocument && JSVGComponent.this.eventsEnabled) { 1397 startSVGLoadEventDispatcher(e.getGVTRoot()); 1398 } else { 1399 if (isInteractiveDocument) { 1400 nextUpdateManager = new UpdateManager(bridgeContext, 1401 e.getGVTRoot(), 1402 svgDocument); 1403 } 1404 1405 JSVGComponent.this.setGraphicsNode(e.getGVTRoot(), false); 1406 scheduleGVTRendering(); 1407 } 1408 } 1409 1410 1413 public void gvtBuildCancelled(GVTTreeBuilderEvent e) { 1414 if (nextGVTTreeBuilder != null) { 1415 startGVTTreeBuilder(); 1416 return; 1417 } 1418 1419 loader = null; 1420 gvtTreeBuilder = null; 1421 1422 if (afterStopRunnable != null) { 1423 EventQueue.invokeLater(afterStopRunnable); 1424 afterStopRunnable = null; 1425 return; 1426 } 1427 1428 if (nextDocumentLoader != null) { 1429 startDocumentLoader(); 1430 return; 1431 } 1432 JSVGComponent.this.image = null; 1433 repaint(); 1434 } 1435 1436 1439 public void gvtBuildFailed(GVTTreeBuilderEvent e) { 1440 if (nextGVTTreeBuilder != null) { 1441 startGVTTreeBuilder(); 1442 return; 1443 } 1444 1445 loader = null; 1446 gvtTreeBuilder = null; 1447 1448 if (afterStopRunnable != null) { 1449 EventQueue.invokeLater(afterStopRunnable); 1450 afterStopRunnable = null; 1451 return; 1452 } 1453 1454 if (nextDocumentLoader != null) { 1455 startDocumentLoader(); 1456 return; 1457 } 1458 1459 GraphicsNode gn = e.getGVTRoot(); 1460 if (gn == null) { 1461 JSVGComponent.this.image = null; 1462 repaint(); 1463 } else { 1464 JSVGComponent.this.setGraphicsNode(gn, false); 1465 computeRenderingTransform(); 1466 } 1467 userAgent.displayError(((GVTTreeBuilder)e.getSource()) 1468 .getException()); 1469 } 1470 1471 1473 1476 public void svgLoadEventDispatchStarted 1477 (SVGLoadEventDispatcherEvent e) { 1478 } 1479 1480 1483 public void svgLoadEventDispatchCompleted 1484 (SVGLoadEventDispatcherEvent e) { 1485 nextUpdateManager = svgLoadEventDispatcher.getUpdateManager(); 1486 svgLoadEventDispatcher = null; 1487 1488 if (afterStopRunnable != null) { 1489 nextUpdateManager.interrupt(); 1490 nextUpdateManager = null; 1491 1492 EventQueue.invokeLater(afterStopRunnable); 1493 afterStopRunnable = null; 1494 return; 1495 } 1496 1497 if (nextGVTTreeBuilder != null) { 1498 nextUpdateManager.interrupt(); 1499 nextUpdateManager = null; 1500 1501 startGVTTreeBuilder(); 1502 return; 1503 } 1504 if (nextDocumentLoader != null) { 1505 nextUpdateManager.interrupt(); 1506 nextUpdateManager = null; 1507 1508 startDocumentLoader(); 1509 return; 1510 } 1511 1512 JSVGComponent.this.setGraphicsNode(e.getGVTRoot(), false); 1513 scheduleGVTRendering(); 1514 } 1515 1516 1519 public void svgLoadEventDispatchCancelled 1520 (SVGLoadEventDispatcherEvent e) { 1521 nextUpdateManager = svgLoadEventDispatcher.getUpdateManager(); 1522 svgLoadEventDispatcher = null; 1523 1524 nextUpdateManager.interrupt(); 1525 nextUpdateManager = null; 1526 1527 if (afterStopRunnable != null) { 1528 EventQueue.invokeLater(afterStopRunnable); 1529 afterStopRunnable = null; 1530 return; 1531 } 1532 1533 if (nextGVTTreeBuilder != null) { 1534 startGVTTreeBuilder(); 1535 return; 1536 } 1537 if (nextDocumentLoader != null) { 1538 startDocumentLoader(); 1539 return; 1540 } 1541 } 1542 1543 1546 public void svgLoadEventDispatchFailed 1547 (SVGLoadEventDispatcherEvent e) { 1548 nextUpdateManager = svgLoadEventDispatcher.getUpdateManager(); 1549 svgLoadEventDispatcher = null; 1550 1551 nextUpdateManager.interrupt(); 1552 nextUpdateManager = null; 1553 1554 if (afterStopRunnable != null) { 1555 EventQueue.invokeLater(afterStopRunnable); 1556 afterStopRunnable = null; 1557 return; 1558 } 1559 1560 if (nextGVTTreeBuilder != null) { 1561 startGVTTreeBuilder(); 1562 return; 1563 } 1564 if (nextDocumentLoader != null) { 1565 startDocumentLoader(); 1566 return; 1567 } 1568 1569 GraphicsNode gn = e.getGVTRoot(); 1570 if (gn == null) { 1571 JSVGComponent.this.image = null; 1572 repaint(); 1573 } else { 1574 JSVGComponent.this.setGraphicsNode(gn, false); 1575 computeRenderingTransform(); 1576 } 1577 userAgent.displayError(((SVGLoadEventDispatcher)e.getSource()) 1578 .getException()); 1579 } 1580 1581 1583 1586 public void gvtRenderingCompleted(GVTTreeRendererEvent e) { 1587 super.gvtRenderingCompleted(e); 1588 1589 if (afterStopRunnable != null) { 1590 if (nextUpdateManager != null) { 1591 nextUpdateManager.interrupt(); 1592 nextUpdateManager = null; 1593 } 1594 EventQueue.invokeLater(afterStopRunnable); 1595 afterStopRunnable = null; 1596 return; 1597 } 1598 1599 if (nextGVTTreeBuilder != null) { 1600 if (nextUpdateManager != null) { 1601 nextUpdateManager.interrupt(); 1602 nextUpdateManager = null; 1603 } 1604 startGVTTreeBuilder(); 1605 return; 1606 } 1607 if (nextDocumentLoader != null) { 1608 if (nextUpdateManager != null) { 1609 nextUpdateManager.interrupt(); 1610 nextUpdateManager = null; 1611 } 1612 startDocumentLoader(); 1613 return; 1614 } 1615 1616 if (nextUpdateManager != null) { 1617 updateManager = nextUpdateManager; 1618 nextUpdateManager = null; 1619 updateManager.addUpdateManagerListener(this); 1620 updateManager.manageUpdates(renderer); 1621 } 1622 } 1623 1624 1627 public void gvtRenderingCancelled(GVTTreeRendererEvent e) { 1628 super.gvtRenderingCancelled(e); 1629 1630 if (afterStopRunnable != null) { 1631 if (nextUpdateManager != null) { 1632 nextUpdateManager.interrupt(); 1633 nextUpdateManager = null; 1634 } 1635 1636 EventQueue.invokeLater(afterStopRunnable); 1637 afterStopRunnable = null; 1638 return; 1639 } 1640 1641 if (nextGVTTreeBuilder != null) { 1642 if (nextUpdateManager != null) { 1643 nextUpdateManager.interrupt(); 1644 nextUpdateManager = null; 1645 } 1646 1647 startGVTTreeBuilder(); 1648 return; 1649 } 1650 if (nextDocumentLoader != null) { 1651 if (nextUpdateManager != null) { 1652 nextUpdateManager.interrupt(); 1653 nextUpdateManager = null; 1654 } 1655 startDocumentLoader(); 1656 return; 1657 } 1658 } 1659 1660 1663 public void gvtRenderingFailed(GVTTreeRendererEvent e) { 1664 super.gvtRenderingFailed(e); 1665 1666 if (afterStopRunnable != null) { 1667 if (nextUpdateManager != null) { 1668 nextUpdateManager.interrupt(); 1669 nextUpdateManager = null; 1670 } 1671 1672 EventQueue.invokeLater(afterStopRunnable); 1673 afterStopRunnable = null; 1674 return; 1675 } 1676 1677 if (nextGVTTreeBuilder != null) { 1678 if (nextUpdateManager != null) { 1679 nextUpdateManager.interrupt(); 1680 nextUpdateManager = null; 1681 } 1682 1683 startGVTTreeBuilder(); 1684 return; 1685 } 1686 if (nextDocumentLoader != null) { 1687 if (nextUpdateManager != null) { 1688 nextUpdateManager.interrupt(); 1689 nextUpdateManager = null; 1690 } 1691 1692 startDocumentLoader(); 1693 return; 1694 } 1695 } 1696 1697 1699 1702 public void managerStarted(final UpdateManagerEvent e) { 1703 EventQueue.invokeLater(new Runnable () { 1704 public void run() { 1705 suspendInteractions = false; 1706 1707 Object [] dll = updateManagerListeners.toArray(); 1708 1709 if (dll.length > 0) { 1710 for (int i = 0; i < dll.length; i++) { 1711 ((UpdateManagerListener)dll[i]). 1712 managerStarted(e); 1713 } 1714 } 1715 } 1716 }); 1717 } 1718 1719 1722 public void managerSuspended(final UpdateManagerEvent e) { 1723 EventQueue.invokeLater(new Runnable () { 1724 public void run() { 1725 Object [] dll = updateManagerListeners.toArray(); 1726 1727 if (dll.length > 0) { 1728 for (int i = 0; i < dll.length; i++) { 1729 ((UpdateManagerListener)dll[i]). 1730 managerSuspended(e); 1731 } 1732 } 1733 } 1734 }); 1735 } 1736 1737 1740 public void managerResumed(final UpdateManagerEvent e) { 1741 EventQueue.invokeLater(new Runnable () { 1742 public void run() { 1743 Object [] dll = updateManagerListeners.toArray(); 1744 1745 if (dll.length > 0) { 1746 for (int i = 0; i < dll.length; i++) { 1747 ((UpdateManagerListener)dll[i]). 1748 managerResumed(e); 1749 } 1750 } 1751 } 1752 }); 1753 } 1754 1755 1758 public void managerStopped(final UpdateManagerEvent e) { 1759 EventQueue.invokeLater(new Runnable () { 1760 public void run() { 1761 updateManager = null; 1762 1763 1764 Object [] dll = updateManagerListeners.toArray(); 1765 1766 if (dll.length > 0) { 1767 for (int i = 0; i < dll.length; i++) { 1768 ((UpdateManagerListener)dll[i]). 1769 managerStopped(e); 1770 } 1771 } 1772 1773 if (afterStopRunnable != null) { 1774 EventQueue.invokeLater(afterStopRunnable); 1775 afterStopRunnable = null; 1776 return; 1777 } 1778 1779 if (nextGVTTreeBuilder != null) { 1780 startGVTTreeBuilder(); 1781 return; 1782 } 1783 if (nextDocumentLoader != null) { 1784 startDocumentLoader(); 1785 return; 1786 } 1787 } 1788 }); 1789 } 1790 1791 1794 public void updateStarted(final UpdateManagerEvent e) { 1795 EventQueue.invokeLater(new Runnable () { 1796 public void run() { 1797 if (!doubleBufferedRendering) { 1798 image = e.getImage(); 1799 } 1800 1801 Object [] dll = updateManagerListeners.toArray(); 1802 1803 if (dll.length > 0) { 1804 for (int i = 0; i < dll.length; i++) { 1805 ((UpdateManagerListener)dll[i]). 1806 updateStarted(e); 1807 } 1808 } 1809 } 1810 }); 1811 } 1812 1813 1816 public void updateCompleted(final UpdateManagerEvent e) { 1817 try { 1829 EventQueue.invokeAndWait(new Runnable () { 1830 public void run() { 1831 image = e.getImage(); 1832 if (e.getClearPaintingTransform()) 1833 paintingTransform = null; 1834 1835 List l = e.getDirtyAreas(); 1836 if (l != null) { 1837 Rectangle visRect = getRenderRect(); 1838 Iterator i = l.iterator(); 1839 while (i.hasNext()) { 1840 Rectangle r = (Rectangle )i.next(); 1841 if (updateOverlay != null) { 1842 updateOverlay.addRect(r); 1843 r = getRenderRect(); 1844 } 1845 1846 if (doubleBufferedRendering) 1847 repaint(r); 1848 else 1849 paintImmediately(r); 1850 } 1851 if (updateOverlay != null) 1852 updateOverlay.endUpdate(); 1853 } 1854 suspendInteractions = false; 1855 } 1856 }); 1857 } catch (Exception ex) { 1858 } 1859 1860 1861 EventQueue.invokeLater(new Runnable () { 1862 public void run() { 1863 Object [] dll = updateManagerListeners.toArray(); 1864 1865 if (dll.length > 0) { 1866 for (int i = 0; i < dll.length; i++) { 1867 ((UpdateManagerListener)dll[i]). 1868 updateCompleted(e); 1869 } 1870 } 1871 } 1872 }); 1873 } 1874 1875 1878 public void updateFailed(final UpdateManagerEvent e) { 1879 EventQueue.invokeLater(new Runnable () { 1880 public void run() { 1881 Object [] dll = updateManagerListeners.toArray(); 1882 1883 if (dll.length > 0) { 1884 for (int i = 0; i < dll.length; i++) { 1885 ((UpdateManagerListener)dll[i]). 1886 updateFailed(e); 1887 } 1888 } 1889 } 1890 }); 1891 } 1892 1893 1895 1898 protected void dispatchKeyTyped(final KeyEvent e) { 1899 if (!isDynamicDocument) { 1900 super.dispatchKeyTyped(e); 1901 return; 1902 } 1903 1904 if (updateManager != null && updateManager.isRunning()) { 1905 updateManager.getUpdateRunnableQueue().invokeLater 1906 (new Runnable () { 1907 public void run() { 1908 eventDispatcher.keyTyped(e); 1909 } 1910 }); 1911 } 1912 1913 } 1914 1915 1918 protected void dispatchKeyPressed(final KeyEvent e) { 1919 if (!isDynamicDocument) { 1920 super.dispatchKeyPressed(e); 1921 return; 1922 } 1923 1924 if (updateManager != null && updateManager.isRunning()) { 1925 updateManager.getUpdateRunnableQueue().invokeLater 1926 (new Runnable () { 1927 public void run() { 1928 eventDispatcher.keyPressed(e); 1929 } 1930 }); 1931 } 1932 } 1933 1934 1937 protected void dispatchKeyReleased(final KeyEvent e) { 1938 if (!isDynamicDocument) { 1939 super.dispatchKeyReleased(e); 1940 return; 1941 } 1942 1943 if (updateManager != null && updateManager.isRunning()) { 1944 updateManager.getUpdateRunnableQueue().invokeLater 1945 (new Runnable () { 1946 public void run() { 1947 eventDispatcher.keyReleased(e); 1948 } 1949 }); 1950 } 1951 } 1952 1953 1956 protected void dispatchMouseClicked(final MouseEvent e) { 1957 if (!isInteractiveDocument) { 1958 super.dispatchMouseClicked(e); 1959 return; 1960 } 1961 1962 if (updateManager != null && updateManager.isRunning()) { 1963 updateManager.getUpdateRunnableQueue().invokeLater 1964 (new Runnable () { 1965 public void run() { 1966 eventDispatcher.mouseClicked(e); 1967 1968 } 1969 }); 1970 } 1971 } 1972 1973 1976 protected void dispatchMousePressed(final MouseEvent e) { 1977 if (!isDynamicDocument) { 1978 super.dispatchMousePressed(e); 1979 return; 1980 } 1981 1982 if (updateManager != null && updateManager.isRunning()) { 1983 updateManager.getUpdateRunnableQueue().invokeLater 1984 (new Runnable () { 1985 public void run() { 1986 eventDispatcher.mousePressed(e); 1987 } 1988 }); 1989 } 1990 } 1991 1992 1995 protected void dispatchMouseReleased(final MouseEvent e) { 1996 if (!isDynamicDocument) { 1997 super.dispatchMouseReleased(e); 1998 return; 1999 } 2000 2001 if (updateManager != null && updateManager.isRunning()) { 2002 updateManager.getUpdateRunnableQueue().invokeLater 2003 (new Runnable () { 2004 public void run() { 2005 eventDispatcher.mouseReleased(e); 2006 } 2007 }); 2008 } 2009 } 2010 2011 2014 protected void dispatchMouseEntered(final MouseEvent e) { 2015 if (!isInteractiveDocument) { 2016 super.dispatchMouseEntered(e); 2017 return; 2018 } 2019 2020 if (updateManager != null && updateManager.isRunning()) { 2021 updateManager.getUpdateRunnableQueue().invokeLater 2022 (new Runnable () { 2023 public void run() { 2024 eventDispatcher.mouseEntered(e); 2025 } 2026 }); 2027 } 2028 } 2029 2030 2033 protected void dispatchMouseExited(final MouseEvent e) { 2034 if (!isInteractiveDocument) { 2035 super.dispatchMouseExited(e); 2036 return; 2037 } 2038 2039 if (updateManager != null && updateManager.isRunning()) { 2040 updateManager.getUpdateRunnableQueue().invokeLater 2041 (new Runnable () { 2042 public void run() { 2043 eventDispatcher.mouseExited(e); 2044 } 2045 }); 2046 } 2047 } 2048 2049 2052 protected void dispatchMouseDragged(MouseEvent e) { 2053 if (!isDynamicDocument) { 2054 super.dispatchMouseDragged(e); 2055 return; 2056 } 2057 2058 class MouseDraggedRunnable implements Runnable { 2059 MouseEvent event; 2060 MouseDraggedRunnable(MouseEvent evt) { 2061 event = evt; 2062 } 2063 public void run() { 2064 eventDispatcher.mouseDragged(event); 2065 } 2066 } 2067 2068 if (updateManager != null && updateManager.isRunning()) { 2069 RunnableQueue rq = updateManager.getUpdateRunnableQueue(); 2070 2071 synchronized (rq.getIteratorLock()) { 2073 Iterator it = rq.iterator(); 2074 while (it.hasNext()) { 2075 Object next = it.next(); 2076 if (next instanceof MouseDraggedRunnable) { 2077 MouseDraggedRunnable mdr; 2078 mdr = (MouseDraggedRunnable)next; 2079 MouseEvent mev = mdr.event; 2080 if (mev.getModifiers() == e.getModifiers()) { 2081 mdr.event = e; 2082 } 2083 return; 2084 } 2085 } 2086 } 2087 2088 rq.invokeLater(new MouseDraggedRunnable(e)); 2089 } 2090 } 2091 2092 2095 protected void dispatchMouseMoved(MouseEvent e) { 2096 if (!isInteractiveDocument) { 2097 super.dispatchMouseMoved(e); 2098 return; 2099 } 2100 2101 class MouseMovedRunnable implements Runnable { 2102 MouseEvent event; 2103 MouseMovedRunnable(MouseEvent evt) { 2104 event = evt; 2105 } 2106 public void run() { 2107 eventDispatcher.mouseMoved(event); 2108 } 2109 } 2110 2111 if (updateManager != null && updateManager.isRunning()) { 2112 RunnableQueue rq = updateManager.getUpdateRunnableQueue(); 2113 2114 int i = 0; 2116 synchronized (rq.getIteratorLock()) { 2117 Iterator it = rq.iterator(); 2118 while (it.hasNext()) { 2119 Object next = it.next(); 2120 if (next instanceof MouseMovedRunnable) { 2121 MouseMovedRunnable mmr; 2122 mmr = (MouseMovedRunnable)next; 2123 MouseEvent mev = mmr.event; 2124 if (mev.getModifiers() == e.getModifiers()) { 2125 mmr.event = e; 2126 } 2127 return; 2128 } 2129 i++; 2130 } 2131 2132 } 2133 2134 rq.invokeLater(new MouseMovedRunnable(e)); 2135 } 2136 } 2137 } 2138 2139 2142 protected UserAgent createUserAgent() { 2143 return new BridgeUserAgent(); 2144 } 2145 2146 2149 protected static class BridgeUserAgentWrapper implements UserAgent { 2150 2151 2154 protected UserAgent userAgent; 2155 2156 2159 public BridgeUserAgentWrapper(UserAgent ua) { 2160 userAgent = ua; 2161 } 2162 2163 2166 public EventDispatcher getEventDispatcher() { 2167 if (EventQueue.isDispatchThread()) { 2168 return userAgent.getEventDispatcher(); 2169 } else { 2170 class Query implements Runnable { 2171 EventDispatcher result; 2172 public void run() { 2173 result = userAgent.getEventDispatcher(); 2174 } 2175 } 2176 Query q = new Query(); 2177 invokeAndWait(q); 2178 return q.result; 2179 } 2180 } 2181 2182 2185 public Dimension2D getViewportSize() { 2186 if (EventQueue.isDispatchThread()) { 2187 return userAgent.getViewportSize(); 2188 } else { 2189 class Query implements Runnable { 2190 Dimension2D result; 2191 public void run() { 2192 result = userAgent.getViewportSize(); 2193 } 2194 } 2195 Query q = new Query(); 2196 invokeAndWait(q); 2197 return q.result; 2198 } 2199 } 2200 2201 2204 public void displayError(final Exception ex) { 2205 if (EventQueue.isDispatchThread()) { 2206 userAgent.displayError(ex); 2207 } else { 2208 EventQueue.invokeLater(new Runnable () { 2209 public void run() { 2210 userAgent.displayError(ex); 2211 } 2212 }); 2213 } 2214 } 2215 2216 2219 public void displayMessage(final String message) { 2220 if (EventQueue.isDispatchThread()) { 2221 userAgent.displayMessage(message); 2222 } else { 2223 EventQueue.invokeLater(new Runnable () { 2224 public void run() { 2225 userAgent.displayMessage(message); 2226 } 2227 }); 2228 } 2229 } 2230 2231 2234 public void showAlert(final String message) { 2235 if (EventQueue.isDispatchThread()) { 2236 userAgent.showAlert(message); 2237 } else { 2238 invokeAndWait(new Runnable () { 2239 public void run() { 2240 userAgent.showAlert(message); 2241 } 2242 }); 2243 } 2244 } 2245 2246 2249 public String showPrompt(final String message) { 2250 if (EventQueue.isDispatchThread()) { 2251 return userAgent.showPrompt(message); 2252 } else { 2253 class Query implements Runnable { 2254 String result; 2255 public void run() { 2256 result = userAgent.showPrompt(message); 2257 } 2258 } 2259 Query q = new Query(); 2260 invokeAndWait(q); 2261 return q.result; 2262 } 2263 } 2264 2265 2268 public String showPrompt(final String message, 2269 final String defaultValue) { 2270 if (EventQueue.isDispatchThread()) { 2271 return userAgent.showPrompt(message, defaultValue); 2272 } else { 2273 class Query implements Runnable { 2274 String result; 2275 public void run() { 2276 result = userAgent.showPrompt(message, defaultValue); 2277 } 2278 } 2279 Query q = new Query(); 2280 invokeAndWait(q); 2281 return q.result; 2282 } 2283 } 2284 2285 2288 public boolean showConfirm(final String message) { 2289 if (EventQueue.isDispatchThread()) { 2290 return userAgent.showConfirm(message); 2291 } else { 2292 class Query implements Runnable { 2293 boolean result; 2294 public void run() { 2295 result = userAgent.showConfirm(message); 2296 } 2297 } 2298 Query q = new Query(); 2299 invokeAndWait(q); 2300 return q.result; 2301 } 2302 } 2303 2304 2307 public float getPixelUnitToMillimeter() { 2308 if (EventQueue.isDispatchThread()) { 2309 return userAgent.getPixelUnitToMillimeter(); 2310 } else { 2311 class Query implements Runnable { 2312 float result; 2313 public void run() { 2314 result = userAgent.getPixelUnitToMillimeter(); 2315 } 2316 } 2317 Query q = new Query(); 2318 invokeAndWait(q); 2319 return q.result; 2320 } 2321 } 2322 2323 2328 public float getPixelToMM() { return getPixelUnitToMillimeter(); } 2329 2330 2331 2334 public String getDefaultFontFamily() { 2335 if (EventQueue.isDispatchThread()) { 2336 return userAgent.getDefaultFontFamily(); 2337 } else { 2338 class Query implements Runnable { 2339 String result; 2340 public void run() { 2341 result = userAgent.getDefaultFontFamily(); 2342 } 2343 } 2344 Query q = new Query(); 2345 invokeAndWait(q); 2346 return q.result; 2347 } 2348 } 2349 2350 public float getMediumFontSize() { 2351 if (EventQueue.isDispatchThread()) { 2352 return userAgent.getMediumFontSize(); 2353 } else { 2354 class Query implements Runnable { 2355 float result; 2356 public void run() { 2357 result = userAgent.getMediumFontSize(); 2358 } 2359 } 2360 Query q = new Query(); 2361 invokeAndWait(q); 2362 return q.result; 2363 } 2364 } 2365 2366 public float getLighterFontWeight(float f) { 2367 if (EventQueue.isDispatchThread()) { 2368 return userAgent.getLighterFontWeight(f); 2369 } else { 2370 final float ff = f; 2371 class Query implements Runnable { 2372 float result; 2373 public void run() { 2374 result = userAgent.getLighterFontWeight(ff); 2375 } 2376 } 2377 Query q = new Query(); 2378 invokeAndWait(q); 2379 return q.result; 2380 } 2381 } 2382 2383 public float getBolderFontWeight(float f) { 2384 if (EventQueue.isDispatchThread()) { 2385 return userAgent.getBolderFontWeight(f); 2386 } else { 2387 final float ff = f; 2388 class Query implements Runnable { 2389 float result; 2390 public void run() { 2391 result = userAgent.getBolderFontWeight(ff); 2392 } 2393 } 2394 Query q = new Query(); 2395 invokeAndWait(q); 2396 return q.result; 2397 } 2398 } 2399 2400 2403 public String getLanguages() { 2404 if (EventQueue.isDispatchThread()) { 2405 return userAgent.getLanguages(); 2406 } else { 2407 class Query implements Runnable { 2408 String result; 2409 public void run() { 2410 result = userAgent.getLanguages(); 2411 } 2412 } 2413 Query q = new Query(); 2414 invokeAndWait(q); 2415 return q.result; 2416 } 2417 } 2418 2419 2423 public String getUserStyleSheetURI() { 2424 if (EventQueue.isDispatchThread()) { 2425 return userAgent.getUserStyleSheetURI(); 2426 } else { 2427 class Query implements Runnable { 2428 String result; 2429 public void run() { 2430 result = userAgent.getUserStyleSheetURI(); 2431 } 2432 } 2433 Query q = new Query(); 2434 invokeAndWait(q); 2435 return q.result; 2436 } 2437 } 2438 2439 2443 public void openLink(final SVGAElement elt) { 2444 if (EventQueue.isDispatchThread()) { 2445 userAgent.openLink(elt); 2446 } else { 2447 EventQueue.invokeLater(new Runnable () { 2448 public void run() { 2449 userAgent.openLink(elt); 2450 } 2451 }); 2452 } 2453 } 2454 2455 2459 public void setSVGCursor(final Cursor cursor) { 2460 if (EventQueue.isDispatchThread()) { 2461 userAgent.setSVGCursor(cursor); 2462 } else { 2463 EventQueue.invokeLater(new Runnable () { 2464 public void run() { 2465 userAgent.setSVGCursor(cursor); 2466 } 2467 }); 2468 } 2469 } 2470 2471 2476 public void setTextSelection(final Mark start, final Mark end) { 2477 if (EventQueue.isDispatchThread()) { 2478 userAgent.setTextSelection(start, end); 2479 } else { 2480 EventQueue.invokeLater(new Runnable () { 2481 public void run() { 2482 userAgent.setTextSelection(start, end); 2483 } 2484 }); 2485 } 2486 } 2487 2488 2491 public void deselectAll() { 2492 if (EventQueue.isDispatchThread()) { 2493 userAgent.deselectAll(); 2494 } else { 2495 EventQueue.invokeLater(new Runnable () { 2496 public void run() { 2497 userAgent.deselectAll(); 2498 } 2499 }); 2500 } 2501 } 2502 2503 2506 public String getXMLParserClassName() { 2507 if (EventQueue.isDispatchThread()) { 2508 return userAgent.getXMLParserClassName(); 2509 } else { 2510 class Query implements Runnable { 2511 String result; 2512 public void run() { 2513 result = userAgent.getXMLParserClassName(); 2514 } 2515 } 2516 Query q = new Query(); 2517 invokeAndWait(q); 2518 return q.result; 2519 } 2520 } 2521 2522 2526 public boolean isXMLParserValidating() { 2527 if (EventQueue.isDispatchThread()) { 2528 return userAgent.isXMLParserValidating(); 2529 } else { 2530 class Query implements Runnable { 2531 boolean result; 2532 public void run() { 2533 result = userAgent.isXMLParserValidating(); 2534 } 2535 } 2536 Query q = new Query(); 2537 invokeAndWait(q); 2538 return q.result; 2539 } 2540 } 2541 2542 2546 public AffineTransform getTransform() { 2547 if (EventQueue.isDispatchThread()) { 2548 return userAgent.getTransform(); 2549 } else { 2550 class Query implements Runnable { 2551 AffineTransform result; 2552 public void run() { 2553 result = userAgent.getTransform(); 2554 } 2555 } 2556 Query q = new Query(); 2557 invokeAndWait(q); 2558 return q.result; 2559 } 2560 } 2561 2562 2566 public void setTransform(AffineTransform at) { 2567 if (EventQueue.isDispatchThread()) { 2568 userAgent.setTransform(at); 2569 } else { 2570 final AffineTransform affine = at; 2571 class Query implements Runnable { 2572 public void run() { 2573 userAgent.setTransform(affine); 2574 } 2575 } 2576 Query q = new Query(); 2577 invokeAndWait(q); 2578 } 2579 } 2580 2581 2584 public String getMedia() { 2585 if (EventQueue.isDispatchThread()) { 2586 return userAgent.getMedia(); 2587 } else { 2588 class Query implements Runnable { 2589 String result; 2590 public void run() { 2591 result = userAgent.getMedia(); 2592 } 2593 } 2594 Query q = new Query(); 2595 invokeAndWait(q); 2596 return q.result; 2597 } 2598 } 2599 2600 2603 public String getAlternateStyleSheet() { 2604 if (EventQueue.isDispatchThread()) { 2605 return userAgent.getAlternateStyleSheet(); 2606 } else { 2607 class Query implements Runnable { 2608 String result; 2609 public void run() { 2610 result = userAgent.getAlternateStyleSheet(); 2611 } 2612 } 2613 Query q = new Query(); 2614 invokeAndWait(q); 2615 return q.result; 2616 } 2617 } 2618 2619 2623 public Point getClientAreaLocationOnScreen() { 2624 if (EventQueue.isDispatchThread()) { 2625 return userAgent.getClientAreaLocationOnScreen(); 2626 } else { 2627 class Query implements Runnable { 2628 Point result; 2629 public void run() { 2630 result = userAgent.getClientAreaLocationOnScreen(); 2631 } 2632 } 2633 Query q = new Query(); 2634 invokeAndWait(q); 2635 return q.result; 2636 } 2637 } 2638 2639 2643 public boolean hasFeature(final String s) { 2644 if (EventQueue.isDispatchThread()) { 2645 return userAgent.hasFeature(s); 2646 } else { 2647 class Query implements Runnable { 2648 boolean result; 2649 public void run() { 2650 result = userAgent.hasFeature(s); 2651 } 2652 } 2653 Query q = new Query(); 2654 invokeAndWait(q); 2655 return q.result; 2656 } 2657 } 2658 2659 2663 public boolean supportExtension(final String s) { 2664 if (EventQueue.isDispatchThread()) { 2665 return userAgent.supportExtension(s); 2666 } else { 2667 class Query implements Runnable { 2668 boolean result; 2669 public void run() { 2670 result = userAgent.supportExtension(s); 2671 } 2672 } 2673 Query q = new Query(); 2674 invokeAndWait(q); 2675 return q.result; 2676 } 2677 } 2678 2679 2683 public void registerExtension(final BridgeExtension ext) { 2684 if (EventQueue.isDispatchThread()) { 2685 userAgent.registerExtension(ext); 2686 } else { 2687 EventQueue.invokeLater(new Runnable () { 2688 public void run() { 2689 userAgent.registerExtension(ext); 2690 } 2691 }); 2692 } 2693 } 2694 2695 2702 public void handleElement(final Element elt, final Object data) { 2703 if (EventQueue.isDispatchThread()) { 2704 userAgent.handleElement(elt, data); 2705 } else { 2706 EventQueue.invokeLater(new Runnable () { 2707 public void run() { 2708 userAgent.handleElement(elt, data); 2709 } 2710 }); 2711 } 2712 } 2713 2714 2727 public ScriptSecurity getScriptSecurity(String scriptType, 2728 ParsedURL scriptPURL, 2729 ParsedURL docPURL){ 2730 if (EventQueue.isDispatchThread()) { 2731 return userAgent.getScriptSecurity(scriptType, 2732 scriptPURL, 2733 docPURL); 2734 } else { 2735 final String st = scriptType; 2736 final ParsedURL sPURL= scriptPURL; 2737 final ParsedURL dPURL= docPURL; 2738 class Query implements Runnable { 2739 ScriptSecurity result; 2740 public void run() { 2741 result = userAgent.getScriptSecurity(st, sPURL, dPURL); 2742 } 2743 } 2744 Query q = new Query(); 2745 invokeAndWait(q); 2746 return q.result; 2747 } 2748 } 2749 2750 2768 public void checkLoadScript(String scriptType, 2769 ParsedURL scriptPURL, 2770 ParsedURL docPURL) throws SecurityException { 2771 if (EventQueue.isDispatchThread()) { 2772 userAgent.checkLoadScript(scriptType, 2773 scriptPURL, 2774 docPURL); 2775 } else { 2776 final String st = scriptType; 2777 final ParsedURL sPURL= scriptPURL; 2778 final ParsedURL dPURL= docPURL; 2779 class Query implements Runnable { 2780 SecurityException se = null; 2781 public void run() { 2782 try { 2783 userAgent.checkLoadScript(st, sPURL, dPURL); 2784 } catch (SecurityException se) { 2785 this.se = se; 2786 } 2787 } 2788 } 2789 Query q = new Query(); 2790 invokeAndWait(q); 2791 if (q.se != null) { 2792 q.se.fillInStackTrace(); 2793 throw q.se; 2794 } 2795 } 2796 } 2797 2798 2799 2810 public ExternalResourceSecurity 2811 getExternalResourceSecurity(ParsedURL resourcePURL, 2812 ParsedURL docPURL){ 2813 if (EventQueue.isDispatchThread()) { 2814 return userAgent.getExternalResourceSecurity(resourcePURL, 2815 docPURL); 2816 } else { 2817 final ParsedURL rPURL= resourcePURL; 2818 final ParsedURL dPURL= docPURL; 2819 class Query implements Runnable { 2820 ExternalResourceSecurity result; 2821 public void run() { 2822 result = userAgent.getExternalResourceSecurity(rPURL, dPURL); 2823 } 2824 } 2825 Query q = new Query(); 2826 invokeAndWait(q); 2827 return q.result; 2828 } 2829 } 2830 2831 2847 public void 2848 checkLoadExternalResource(ParsedURL resourceURL, 2849 ParsedURL docURL) throws SecurityException { 2850 if (EventQueue.isDispatchThread()) { 2851 userAgent.checkLoadExternalResource(resourceURL, 2852 docURL); 2853 } else { 2854 final ParsedURL rPURL= resourceURL; 2855 final ParsedURL dPURL= docURL; 2856 class Query implements Runnable { 2857 SecurityException se; 2858 public void run() { 2859 try { 2860 userAgent.checkLoadExternalResource(rPURL, dPURL); 2861 } catch (SecurityException se) { 2862 this.se = se; 2863 } 2864 } 2865 } 2866 Query q = new Query(); 2867 invokeAndWait(q); 2868 if (q.se != null) { 2869 q.se.fillInStackTrace(); 2870 throw q.se; 2871 } 2872 } 2873 } 2874 2875 2879 protected void invokeAndWait(Runnable r) { 2880 try { 2881 EventQueue.invokeAndWait(r); 2882 } catch (Exception e) { 2883 } 2884 } 2885 } 2886 2887 2890 protected class BridgeUserAgent implements UserAgent { 2891 2892 2895 protected BridgeUserAgent() { 2896 } 2897 2898 2901 public Dimension2D getViewportSize() { 2902 return getSize(); 2903 } 2904 2905 2909 public EventDispatcher getEventDispatcher() { 2910 return JSVGComponent.this.eventDispatcher; 2911 } 2912 2913 2916 public void displayError(String message) { 2917 if (svgUserAgent != null) { 2918 svgUserAgent.displayError(message); 2919 } 2920 } 2921 2922 2925 public void displayError(Exception ex) { 2926 if (svgUserAgent != null) { 2927 svgUserAgent.displayError(ex); 2928 } 2929 } 2930 2931 2934 public void displayMessage(String message) { 2935 if (svgUserAgent != null) { 2936 svgUserAgent.displayMessage(message); 2937 } 2938 } 2939 2940 2943 public void showAlert(String message) { 2944 if (svgUserAgent != null) { 2945 svgUserAgent.showAlert(message); 2946 return; 2947 } 2948 JSVGComponent.this.showAlert(message); 2949 } 2950 2951 2954 public String showPrompt(String message) { 2955 if (svgUserAgent != null) { 2956 return svgUserAgent.showPrompt(message); 2957 } 2958 return JSVGComponent.this.showPrompt(message); 2959 } 2960 2961 2964 public String showPrompt(String message, String defaultValue) { 2965 if (svgUserAgent != null) { 2966 return svgUserAgent.showPrompt(message, defaultValue); 2967 } 2968 return JSVGComponent.this.showPrompt(message, defaultValue); 2969 } 2970 2971 2974 public boolean showConfirm(String message) { 2975 if (svgUserAgent != null) { 2976 return svgUserAgent.showConfirm(message); 2977 } 2978 return JSVGComponent.this.showConfirm(message); 2979 } 2980 2981 2984 public float getPixelUnitToMillimeter() { 2985 if (svgUserAgent != null) { 2986 return svgUserAgent.getPixelUnitToMillimeter(); 2987 } 2988 return 0.264583333333333333333f; } 2990 2991 2996 public float getPixelToMM() { return getPixelUnitToMillimeter(); } 2997 2998 3001 public String getDefaultFontFamily() { 3002 if (svgUserAgent != null) { 3003 return svgUserAgent.getDefaultFontFamily(); 3004 } 3005 return "Arial, Helvetica, sans-serif"; 3006 } 3007 3008 3011 public float getMediumFontSize() { 3012 if (svgUserAgent != null) { 3013 return svgUserAgent.getMediumFontSize(); 3014 } 3015 return 9f * 25.4f / (72f * getPixelUnitToMillimeter()); 3017 } 3018 3019 3022 public float getLighterFontWeight(float f) { 3023 if (svgUserAgent != null) { 3024 return svgUserAgent.getLighterFontWeight(f); 3025 } 3026 int weight = ((int)((f+50)/100))*100; 3028 switch (weight) { 3029 case 100: return 100; 3030 case 200: return 100; 3031 case 300: return 200; 3032 case 400: return 300; 3033 case 500: return 400; 3034 case 600: return 400; 3035 case 700: return 400; 3036 case 800: return 400; 3037 case 900: return 400; 3038 default: 3039 throw new IllegalArgumentException ("Bad Font Weight: " + f); 3040 } 3041 } 3042 3043 3046 public float getBolderFontWeight(float f) { 3047 if (svgUserAgent != null) { 3048 return svgUserAgent.getBolderFontWeight(f); 3049 } 3050 int weight = ((int)((f+50)/100))*100; 3052 switch (weight) { 3053 case 100: return 600; 3054 case 200: return 600; 3055 case 300: return 600; 3056 case 400: return 600; 3057 case 500: return 600; 3058 case 600: return 700; 3059 case 700: return 800; 3060 case 800: return 900; 3061 case 900: return 900; 3062 default: 3063 throw new IllegalArgumentException ("Bad Font Weight: " + f); 3064 } 3065 } 3066 3067 3070 public String getLanguages() { 3071 if (svgUserAgent != null) { 3072 return svgUserAgent.getLanguages(); 3073 } 3074 return "en"; 3075 } 3076 3077 3081 public String getUserStyleSheetURI() { 3082 if (svgUserAgent != null) { 3083 return svgUserAgent.getUserStyleSheetURI(); 3084 } 3085 return null; 3086 } 3087 3088 3092 public void openLink(SVGAElement elt) { 3093 String show = XLinkSupport.getXLinkShow(elt); 3094 String href = XLinkSupport.getXLinkHref(elt); 3095 if (show.equals("new")) { 3096 fireLinkActivatedEvent(elt, href); 3097 if (svgUserAgent != null) { 3098 String oldURI = svgDocument.getURL(); 3099 ParsedURL newURI = null; 3100 if (elt.getOwnerDocument() != svgDocument) { 3102 SVGDocument doc = (SVGDocument)elt.getOwnerDocument(); 3103 href = new ParsedURL(doc.getURL(), href).toString(); 3104 } 3105 newURI = new ParsedURL(oldURI, href); 3106 href = newURI.toString(); 3107 svgUserAgent.openLink(href, true); 3108 } else { 3109 JSVGComponent.this.loadSVGDocument(href); 3110 } 3111 return; 3112 } 3113 3114 ParsedURL newURI = new ParsedURL 3117 (((SVGDocument)elt.getOwnerDocument()).getURL(), href); 3118 3119 href = newURI.toString(); 3121 3122 if (svgDocument != null) { 3124 3125 ParsedURL oldURI = new ParsedURL(svgDocument.getURL()); 3126 if (newURI.sameFile(oldURI)) { 3128 String s = newURI.getRef(); 3130 if ((fragmentIdentifier != s) && 3131 ((s == null) || (!s.equals(fragmentIdentifier)))) { 3132 fragmentIdentifier = s; 3134 if (computeRenderingTransform()) 3135 scheduleGVTRendering(); 3136 } 3137 fireLinkActivatedEvent(elt, href); 3140 return; 3141 } 3142 } 3143 3144 fireLinkActivatedEvent(elt, href); 3145 if (svgUserAgent != null) { 3146 svgUserAgent.openLink(href, false); 3147 } else { 3148 JSVGComponent.this.loadSVGDocument(href); 3149 } 3150 } 3151 3152 3155 protected void fireLinkActivatedEvent(SVGAElement elt, String href) { 3156 Object [] ll = linkActivationListeners.toArray(); 3157 3158 if (ll.length > 0) { 3159 LinkActivationEvent ev; 3160 ev = new LinkActivationEvent(JSVGComponent.this, elt, href); 3161 3162 for (int i = 0; i < ll.length; i++) { 3163 LinkActivationListener l = (LinkActivationListener)ll[i]; 3164 l.linkActivated(ev); 3165 } 3166 } 3167 } 3168 3169 3173 public void setSVGCursor(Cursor cursor) { 3174 if (cursor != JSVGComponent.this.getCursor()) 3175 JSVGComponent.this.setCursor(cursor); 3176 } 3177 3178 3183 public void setTextSelection(Mark start, Mark end) { 3184 JSVGComponent.this.select(start, end); 3185 } 3186 3187 3191 public void deselectAll() { 3192 JSVGComponent.this.deselectAll(); 3193 } 3194 3195 3198 public String getXMLParserClassName() { 3199 if (svgUserAgent != null) { 3200 return svgUserAgent.getXMLParserClassName(); 3201 } 3202 return XMLResourceDescriptor.getXMLParserClassName(); 3203 } 3204 3205 3209 public boolean isXMLParserValidating() { 3210 if (svgUserAgent != null) { 3211 return svgUserAgent.isXMLParserValidating(); 3212 } 3213 return false; 3214 } 3215 3216 3220 public AffineTransform getTransform() { 3221 return JSVGComponent.this.renderingTransform; 3222 } 3223 3224 3228 public void setTransform(AffineTransform at) { 3229 JSVGComponent.this.setRenderingTransform(at); 3230 } 3231 3232 3235 public String getMedia() { 3236 if (svgUserAgent != null) { 3237 return svgUserAgent.getMedia(); 3238 } 3239 return "screen"; 3240 } 3241 3242 3245 public String getAlternateStyleSheet() { 3246 if (svgUserAgent != null) { 3247 return svgUserAgent.getAlternateStyleSheet(); 3248 } 3249 return null; 3250 } 3251 3252 3256 public Point getClientAreaLocationOnScreen() { 3257 return getLocationOnScreen(); 3258 } 3259 3260 3264 public boolean hasFeature(String s) { 3265 return FEATURES.contains(s); 3266 } 3267 3268 protected Map extensions = new HashMap (); 3269 3270 3274 public boolean supportExtension(String s) { 3275 if ((svgUserAgent != null) && 3276 (svgUserAgent.supportExtension(s))) 3277 return true; 3278 3279 return extensions.containsKey(s); 3280 } 3281 3282 3286 public void registerExtension(BridgeExtension ext) { 3287 Iterator i = ext.getImplementedExtensions(); 3288 while (i.hasNext()) 3289 extensions.put(i.next(), ext); 3290 } 3291 3292 3293 3300 public void handleElement(Element elt, Object data) { 3301 if (svgUserAgent != null) { 3302 svgUserAgent.handleElement(elt, data); 3303 } 3304 } 3305 3306 3319 public ScriptSecurity getScriptSecurity(String scriptType, 3320 ParsedURL scriptURL, 3321 ParsedURL docURL){ 3322 if (svgUserAgent != null){ 3323 return svgUserAgent.getScriptSecurity(scriptType, 3324 scriptURL, 3325 docURL); 3326 } else { 3327 return new DefaultScriptSecurity(scriptType, 3328 scriptURL, 3329 docURL); 3330 } 3331 } 3332 3333 3351 public void checkLoadScript(String scriptType, 3352 ParsedURL scriptURL, 3353 ParsedURL docURL) throws SecurityException { 3354 if (svgUserAgent != null) { 3355 svgUserAgent.checkLoadScript(scriptType, 3356 scriptURL, 3357 docURL); 3358 } else { 3359 ScriptSecurity s = getScriptSecurity(scriptType, 3360 scriptURL, 3361 docURL); 3362 if (s != null) { 3363 s.checkLoadScript(); 3364 } 3365 } 3366 } 3367 3368 3379 public ExternalResourceSecurity 3380 getExternalResourceSecurity(ParsedURL resourceURL, 3381 ParsedURL docURL){ 3382 if (svgUserAgent != null){ 3383 return svgUserAgent.getExternalResourceSecurity(resourceURL, 3384 docURL); 3385 } else { 3386 return new RelaxedExternalResourceSecurity(resourceURL, 3387 docURL); 3388 } 3389 } 3390 3391 3407 public void 3408 checkLoadExternalResource(ParsedURL resourceURL, 3409 ParsedURL docURL) throws SecurityException { 3410 if (svgUserAgent != null) { 3411 svgUserAgent.checkLoadExternalResource(resourceURL, 3412 docURL); 3413 } else { 3414 ExternalResourceSecurity s 3415 = getExternalResourceSecurity(resourceURL, docURL); 3416 3417 if (s != null) { 3418 s.checkLoadExternalResource(); 3419 } 3420 } 3421 } 3422 3423 3424 } 3425 3426 protected final static Set FEATURES = new HashSet (); 3427 static { 3428 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_FEATURE); 3429 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_LANG_FEATURE); 3430 FEATURES.add(SVGConstants.SVG_ORG_W3C_SVG_STATIC_FEATURE); 3431 } 3432} 3433 | Popular Tags |