Java 类org.w3c.dom.svg.SVGDocument 实例源码

项目:eurocarbdb    文件:SvgFactory.java   
private byte[] createImage(ImageTranscoder t) throws Exception {
    //*** get the SVG document ***
    SVGDocument doc = this.getSvgDoc();
    org.w3c.dom.Element root = doc.getDocumentElement();
    this.getRoot(root);

    //*** set the transcoder input and output ***
    TranscoderInput input = new TranscoderInput(doc);
    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(ostream);

    //*** perform the transcoding ***
    t.transcode(input, output);
    ostream.flush();
    ostream.close();
    return ostream.toByteArray();
}
项目:tabularius    文件:DocumentForm.java   
@Override
protected void execRowsSelected(List<? extends ITableRow> rows) {
    clearErrorStatus();
    try {
        Field field = (Field) rows.get(0).getCell(0).getValue();
        String svg = DocumentForm.this.getFieldByClass(SvgSourceField.class).getValue();
        SVGDocument doc = parseDocument(svg);
        DocumentForm.this.getFieldByClass(DocumentSvgField.class)
                .setSvgDocument(transformLeft(doc, field));
        DocumentForm.this.getFieldByClass(RightGroupBox.class).execDisplayField(field,
                transformRight(doc, field));
    } catch (Exception e) {
        e.printStackTrace();
        addErrorStatus(e.getMessage());
    }
}
项目:tabularius    文件:DocumentForm.java   
@Override
protected void execInitField() {
    setLabelVisible(false);
    setMultilineText(true);
    setMaxLength(1000000);

    clearErrorStatus();
    try {
        SVGDocument doc = generateDocument();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        SVGUtility.writeSVGDocument(doc, out, StandardCharsets.UTF_8.toString());
        setValue(prettyPrint(new String(out.toByteArray())));
    } catch (Exception e) {
        e.printStackTrace();
        addErrorStatus(e.getMessage());
    }
}
项目:jasperreports    文件:WrappingSvgDataToGraphics2DRenderer.java   
@Override
protected SVGDocument getSvgDocument(
    JasperReportsContext jasperReportsContext,
    SVGDocumentFactory documentFactory
    ) throws JRException
{
    try
    {
        return 
            documentFactory.createSVGDocument(
                null, 
                new ByteArrayInputStream(
                    dataRenderer.getData(jasperReportsContext)
                    )
                );
    }
    catch (IOException e)
    {
        throw new JRRuntimeException(e);
    }
}
项目:jasperreports    文件:SvgDataSniffer.java   
/**
 * 
 */
public SvgInfo getSvgInfo(byte[] data)
{
    try
    {
        SVGDocument document = 
            documentFactory.createSVGDocument(
                null,
                new ByteArrayInputStream(data)
                );

        return new SvgInfo(document.getInputEncoding());
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:geoxygene    文件:ExternalGraphic.java   
public SVGDocument getSVGDocument() {
  String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
  SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser);
  SVGDocument doc = null;
  try {
    if (this.href != null) {
      if (!this.href.substring(0, 4).equalsIgnoreCase("file")) {

        URL res = ExternalGraphic.class.getResource(this.href);
        if (res != null) {
          doc = df.createSVGDocument(
              ExternalGraphic.class.getResource(this.href).toString());
        }
      } else {
        doc = df.createSVGDocument(this.href);
      }
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  return doc;
}
项目:Push2Display    文件:DocumentLoader.java   
/**
 * Returns a document from the specified uri.
 * @param uri the uri of the document
 * @exception IOException if an I/O error occured while loading
 * the document
 */
public Document loadDocument(String uri) throws IOException {
    Document ret = checkCache(uri);
    if (ret != null)
        return ret;

    SVGDocument document = documentFactory.createSVGDocument(uri);

    DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
    DocumentState state = new DocumentState(uri, document, desc);
    synchronized (cacheMap) {
        cacheMap.put(uri, state);
    }

    return state.getDocument();
}
项目:Push2Display    文件:DocumentLoader.java   
/**
 * Returns a document from the specified uri.
 * @param uri the uri of the document
 * @exception IOException if an I/O error occured while loading
 * the document
 */
public Document loadDocument(String uri, InputStream is)
    throws IOException {
    Document ret = checkCache(uri);
    if (ret != null)
        return ret;

    SVGDocument document = documentFactory.createSVGDocument(uri, is);

    DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
    DocumentState state = new DocumentState(uri, document, desc);
    synchronized (cacheMap) {
        cacheMap.put(uri, state);
    }

    return state.getDocument();
}
项目:Push2Display    文件:JSVGScrollPane.java   
protected Rectangle2D getViewBoxRect() {
    SVGDocument doc = canvas.getSVGDocument();
    if (doc == null) return null;
    SVGSVGElement el = doc.getRootElement();
    if (el == null) return null;

    String viewBoxStr = el.getAttributeNS
        (null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
    if (viewBoxStr.length() != 0) {
        float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr, null);
        return new Rectangle2D.Float(rect[0], rect[1],
                                     rect[2], rect[3]);
    }
    GraphicsNode gn = canvas.getGraphicsNode();
    if (gn == null) return null;

    Rectangle2D bounds = gn.getBounds();
    if (bounds == null) return null;

    return (Rectangle2D) bounds.clone();
}
项目:Push2Display    文件:JSVGComponent.java   
/**
 * This Implementation simply forwards the request to the AWT thread.
 *
 * @param e   The <image> element that can't be loaded.
 * @param url The resolved url that can't be loaded.
 * @param msg As best as can be determined the reason it can't be
 *            loaded (not available, corrupt, unknown format,...).
 */
public SVGDocument getBrokenLinkDocument(final Element e,
                                         final String url,
                                         final String msg) {
    if (EventQueue.isDispatchThread())
        return userAgent.getBrokenLinkDocument(e, url, msg);

    class Query implements Runnable {
        SVGDocument doc;
        RuntimeException rex = null;
        public void run() {
            try {
                doc = userAgent.getBrokenLinkDocument(e, url, msg);
            } catch (RuntimeException re) { rex = re; }
        }
    }
    Query q = new Query();
    invokeAndWait(q);
    if (q.rex != null) throw q.rex;
    return q.doc;
}
项目:NBModeler    文件:SvgWidget.java   
public void setSVGDocument(SVGDocument doc) {
    svgDocument = doc;
    UserAgent userAgent = new UserAgentAdapter();
    DocumentLoader loader = new DocumentLoader(userAgent);
    ctx = new BridgeContext(userAgent, loader);
    ctx.setDynamicState(BridgeContext.DYNAMIC);
    GVTBuilder builder = new GVTBuilder();
    setGraphicsNode(builder.build(ctx, getSvgDocument()));

    outlineElement = doc.getElementById("OUTLINE");
    if (outlineElement != null) {
        outlineShape = ((org.apache.batik.gvt.ShapeNode) ctx.getGraphicsNode(outlineElement)).getShape();
    }

    if ("OUTER".equals(doc.getRootElement().getAttribute("resizeType"))) {
        setResizeType(ResizeType.OUTER);
    }

    revalidate();
}
项目:compomics-utilities    文件:Export.java   
/**
 * Draws the selected component (assumed to be a Component) into the
 * provided SVGGraphics2D object.
 *
 * @param component
 * @param bounds
 */
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {

    // Get a SVGDOMImplementation and create an XML document
    DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = "http://www.w3.org/2000/svg";
    SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
    svgGenerator.setSVGCanvasSize(bounds.getSize());

    // draw the panel in the SVG generator
    if (component instanceof JFreeChart) {
        ((JFreeChart) component).draw(svgGenerator, bounds);
    } else if (component instanceof JComponent) {
        ((JComponent) component).paintAll(svgGenerator);
    }

    return svgGenerator;
}
项目:elki    文件:SVGUtil.java   
/**
 * Convert the coordinates of an DOM Event from screen into element
 * coordinates.
 *
 * @param doc Document context
 * @param tag Element containing the coordinate system
 * @param evt Event to interpret
 * @return coordinates
 */
public static SVGPoint elementCoordinatesFromEvent(Document doc, Element tag, Event evt) {
  try {
    DOMMouseEvent gnme = (DOMMouseEvent) evt;
    SVGMatrix mat = ((SVGLocatable) tag).getScreenCTM();
    SVGMatrix imat = mat.inverse();
    SVGPoint cPt = ((SVGDocument) doc).getRootElement().createSVGPoint();
    cPt.setX(gnme.getClientX());
    cPt.setY(gnme.getClientY());
    return cPt.matrixTransform(imat);
  }
  catch(Exception e) {
    LoggingUtil.warning("Error getting coordinates from SVG event.", e);
    return null;
  }
}
项目:Push2Display    文件:DocumentLoader.java   
/**
 * Returns a document from the specified uri.
 * @param uri the uri of the document
 * @exception IOException if an I/O error occured while loading
 * the document
 */
public Document loadDocument(String uri) throws IOException {
    Document ret = checkCache(uri);
    if (ret != null)
        return ret;

    SVGDocument document = documentFactory.createSVGDocument(uri);

    DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
    DocumentState state = new DocumentState(uri, document, desc);
    synchronized (cacheMap) {
        cacheMap.put(uri, state);
    }

    return state.getDocument();
}
项目:Push2Display    文件:DocumentLoader.java   
/**
 * Returns a document from the specified uri.
 * @param uri the uri of the document
 * @exception IOException if an I/O error occured while loading
 * the document
 */
public Document loadDocument(String uri, InputStream is)
    throws IOException {
    Document ret = checkCache(uri);
    if (ret != null)
        return ret;

    SVGDocument document = documentFactory.createSVGDocument(uri, is);

    DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
    DocumentState state = new DocumentState(uri, document, desc);
    synchronized (cacheMap) {
        cacheMap.put(uri, state);
    }

    return state.getDocument();
}
项目:Push2Display    文件:JSVGScrollPane.java   
protected Rectangle2D getViewBoxRect() {
    SVGDocument doc = canvas.getSVGDocument();
    if (doc == null) return null;
    SVGSVGElement el = doc.getRootElement();
    if (el == null) return null;

    String viewBoxStr = el.getAttributeNS
        (null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
    if (viewBoxStr.length() != 0) {
        float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr, null);
        return new Rectangle2D.Float(rect[0], rect[1],
                                     rect[2], rect[3]);
    }
    GraphicsNode gn = canvas.getGraphicsNode();
    if (gn == null) return null;

    Rectangle2D bounds = gn.getBounds();
    if (bounds == null) return null;

    return (Rectangle2D) bounds.clone();
}
项目:Push2Display    文件:JSVGComponent.java   
/**
 * This Implementation simply forwards the request to the AWT thread.
 *
 * @param e   The <image> element that can't be loaded.
 * @param url The resolved url that can't be loaded.
 * @param msg As best as can be determined the reason it can't be
 *            loaded (not available, corrupt, unknown format,...).
 */
public SVGDocument getBrokenLinkDocument(final Element e,
                                         final String url,
                                         final String msg) {
    if (EventQueue.isDispatchThread())
        return userAgent.getBrokenLinkDocument(e, url, msg);

    class Query implements Runnable {
        SVGDocument doc;
        RuntimeException rex = null;
        public void run() {
            try {
                doc = userAgent.getBrokenLinkDocument(e, url, msg);
            } catch (RuntimeException re) { rex = re; }
        }
    }
    Query q = new Query();
    invokeAndWait(q);
    if (q.rex != null) throw q.rex;
    return q.doc;
}
项目:mitraq    文件:Export.java   
/**
 * Draws the selected component (assumed to be a Component) into the provided
 * SVGGraphics2D object.
 *
 * @param component
 * @param bounds
 */
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {

    // Get a SVGDOMImplementation and create an XML document
    DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = "http://www.w3.org/2000/svg";
    SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
    svgGenerator.setSVGCanvasSize(bounds.getSize());

    // draw the panel in the SVG generator
    if (component instanceof JFreeChart) {
        ((JFreeChart) component).draw(svgGenerator, bounds);
    } else if (component instanceof JComponent) {
        ((JComponent) component).paintAll(svgGenerator);
    }

    return svgGenerator;
}
项目:feathers-sdk    文件:DocumentLoader.java   
/**
 * Returns a document from the specified uri.
 * @param uri the uri of the document
 * @exception IOException if an I/O error occured while loading
 * the document
 */
public Document loadDocument(String uri, InputStream is) 
    throws IOException {
    Document ret = checkCache(uri);
    if (ret != null)
        return ret;

    SVGDocument document = documentFactory.createSVGDocument(uri, is);

    DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
    DocumentState state = new DocumentState(uri, document, desc);
    synchronized (cacheMap) {
        cacheMap.put(uri, state);
    }

    return state.getDocument();
}
项目:tabularius    文件:DocumentForm.java   
public void execDisplayField(Field field, SVGDocument svgDocument) {
    clearErrorStatus();
    try {
        FieldForm form = new FieldForm(field, svgDocument);
        DocumentForm.this.getFieldByClass(GroupFormField.class).setInnerForm(form);
    } catch (Exception e) {
        e.printStackTrace();
        addErrorStatus(e.getMessage());
    }
}
项目:tabularius    文件:DocumentForm.java   
protected SVGDocument transformLeft(SVGDocument input, Field field) throws IOException {
    SVGDocument doc = (SVGDocument) input.cloneNode(true);

    AtomicInteger counter = new AtomicInteger(0);
    document.fields.forEach(f -> {
        int number = counter.getAndIncrement();

        int height = 100;
        int space = 33;

        int base = 600 + number * (height + space);

        Element fieldMarker = doc.createElementNS("http://www.w3.org/2000/svg", "polygon");
        fieldMarker.setAttribute("points", "-10000," + base + " -10000," + (base + height) + " 10000,"
                + (base + height) + " 10000," + base);
        fieldMarker.setAttribute("id", "fieldMarker" + number);
        fieldMarker.setAttribute("data-ref", "fieldMarker" + number);
        fieldMarker.setAttribute("class", "app-link");
        fieldMarker.setAttribute("fill", "#014786");
        fieldMarker.setAttribute("fill-opacity", "0.0");

        Element set = doc.createElementNS("http://www.w3.org/2000/svg", "set");
        set.setAttribute("attributeName", "fill-opacity");
        set.setAttribute("to", "0.1");
        set.setAttribute("begin", "fieldMarker" + number + ".mouseover");
        set.setAttribute("end", "fieldMarker" + number + ".mouseout");
        fieldMarker.appendChild(set);

        Element documentElement = doc.getElementById("document");
        documentElement.getParentNode().appendChild(fieldMarker);
    });

    return doc;
}
项目:tabularius    文件:DocumentForm.java   
protected SVGDocument transformRight(SVGDocument input, Field field) throws IOException {
    SVGDocument doc = (SVGDocument) input.cloneNode(true);

    int height = 100;
    int space = 33;

    int base = 605 + document.fields.indexOf(field) * (height + space);

    doc.getElementById("svg").setAttribute("viewBox", "-10 " + base + " 861 " + (base + height));
    doc.getElementById("svg").setAttribute("preserveAspectRatio", "xMinYMin slice");
    return doc;
}
项目:tabularius    文件:DocumentForm.java   
protected SVGDocument parseDocument(String svgData) throws IOException {
    if (StringUtility.isNullOrEmpty(svgData)) {
        return null;
    }
    return SVGUtility
            .readSVGDocument(new ByteArrayInputStream(svgData.getBytes(StandardCharsets.UTF_8.name())));
}
项目:geoxygene    文件:ExternalGraphic.java   
public GraphicsNode getGraphicsNode() {

    SVGDocument doc = this.getSVGDocument();
    if (doc == null)
      return null;
    UserAgent userAgent = new UserAgentAdapter();
    DocumentLoader loader = new DocumentLoader(userAgent);
    BridgeContext ctx = new BridgeContext(userAgent, loader);
    ctx.setDynamicState(BridgeContext.DYNAMIC);
    GVTBuilder builder = new GVTBuilder();
    GraphicsNode rootGN = builder.build(ctx, doc);
    return rootGN;
  }
项目:Push2Display    文件:SVGImage.java   
/**
 * Load the SVG image from an input stream and replaces its color. The SVG format is a XML
 * format.
 *
 * @param inputStream From which to load the image
 * @param color The replacement color
 * @return The loaded SVG image document
 * @throws SAXException Parsing error
 * @throws IOException Could not load the image
 * @throws ParserConfigurationException Problem with XML parser
 */
public Document loadDocument (final InputStream inputStream, final Color color) throws SAXException, IOException, ParserConfigurationException
{
    final String parser = XMLResourceDescriptor.getXMLParserClassName ();
    final SAXSVGDocumentFactory f = new SAXSVGDocumentFactory (parser);

    final SVGDocument document = f.createSVGDocument ("xxx", inputStream);

    changeColorOfElement (color, document, "polygon");
    changeColorOfElement (color, document, "circle");
    changeColorOfElement (color, document, "path");
    changeColorOfElement (color, document, "rect");

    return document;
}
项目:Push2Display    文件:SVGImage.java   
/**
 * Adds a new fill color to all given elements.
 *
 * @param color The replacement color
 * @param document The document in which to replace the color
 * @param elementName The name of an XML element for which to replace the color
 */
private static void changeColorOfElement (final Color color, final SVGDocument document, final String elementName)
{
    final NodeList nodes = document.getElementsByTagName (elementName);
    for (int i = 0; i < nodes.getLength (); i++)
    {
        if (nodes.item (i) instanceof SVGElement)
        {
            final SVGElement element = (SVGElement) nodes.item (i);
            element.setAttribute ("fill", toText (color));
        }
    }
}
项目:Push2Display    文件:DocumentLoader.java   
/**
 * Returns the line in the source code of the specified element or
 * -1 if not found.
 *
 * @param e the element
 * @return -1 the document has been removed from the cache or has not
 * been loaded by this document loader.
 */
public int getLineNumber(Element e) {
    String uri = ((SVGDocument)e.getOwnerDocument()).getURL();
    DocumentState state;
    synchronized (cacheMap) {
        state = (DocumentState)cacheMap.get(uri);
    }
    if (state == null) {
        return -1;
    } else {
        return state.desc.getLocationLine(e);
    }
}
项目:Push2Display    文件:ScriptingEnvironment.java   
/**
 * Runs the script.
 */
public void handleEvent(Event evt) {
    Element elt = (Element)evt.getCurrentTarget();
    // Evaluate the script
    String script = elt.getAttributeNS(null, attribute);
    if (script.length() == 0)
        return;

    DocumentLoader dl = bridgeContext.getDocumentLoader();
    SVGDocument d = (SVGDocument)elt.getOwnerDocument();
    int line = dl.getLineNumber(elt);
    final String desc = Messages.formatMessage
        (EVENT_SCRIPT_DESCRIPTION,
         new Object [] {d.getURL(), attribute, new Integer(line)});

    // Find the scripting language
    Element e = elt;
    while (e != null &&
           (!SVGConstants.SVG_NAMESPACE_URI.equals
            (e.getNamespaceURI()) ||
            !SVGConstants.SVG_SVG_TAG.equals(e.getLocalName()))) {
        e = SVGUtilities.getParentElement(e);
    }
    if (e == null)
        return;

    String lang = e.getAttributeNS
        (null, SVGConstants.SVG_CONTENT_SCRIPT_TYPE_ATTRIBUTE);

    runEventHandler(script, evt, lang, desc);
}
项目:Push2Display    文件:BaseScriptingEnvironment.java   
/**
 * Creates a new BaseScriptingEnvironment.
 * @param ctx the bridge context
 */
public BaseScriptingEnvironment(BridgeContext ctx) {
    bridgeContext = ctx;
    document = ctx.getDocument();
    docPURL = new ParsedURL(((SVGDocument)document).getURL());
    userAgent     = bridgeContext.getUserAgent();
}
项目:Push2Display    文件:BridgeContext.java   
/**
 * Tells whether the given SVG document is Interactive.
 * We say it is, if it has any &lt;title>, &lt;desc>, or &lt;a> elements,
 * of if the 'cursor' property is anything but Auto on any element.
 */
public boolean isInteractiveDocument(Document doc) {

    Element root = ((SVGDocument)doc).getRootElement();
    if (!SVGConstants.SVG_NAMESPACE_URI.equals(root.getNamespaceURI()))
        return false;

    return checkInteractiveElement(root);
}
项目:Push2Display    文件:SVGImageElementBridge.java   
/**
 * Returns a GraphicsNode that represents an raster image in JPEG or PNG
 * format.
 *
 * @param ctx the bridge context
 * @param e the image element
 * @param img the image to use in creating the graphics node
 */
protected GraphicsNode createRasterImageNode(BridgeContext ctx,
                                             Element       e,
                                             Filter        img,
                                             ParsedURL     purl) {
    Rectangle2D bounds = getImageBounds(ctx, e);
    if ((bounds.getWidth() == 0) || (bounds.getHeight() == 0)) {
        ShapeNode sn = new ShapeNode();
        sn.setShape(bounds);
        return sn;
    }

    if (BrokenLinkProvider.hasBrokenLinkProperty(img)) {
        Object o=img.getProperty(BrokenLinkProvider.BROKEN_LINK_PROPERTY);
        String msg = "unknown";
        if (o instanceof String)
            msg = (String)o;
        SVGDocument doc = ctx.getUserAgent().getBrokenLinkDocument
            (e, purl.toString(), msg);
        return createSVGImageNode(ctx, e, doc);
    }

    RasterImageNode node = new RasterImageNode();
    node.setImage(img);
    Rectangle2D imgBounds = img.getBounds2D();

    // create the implicit viewBox for the raster image. The viewBox for a
    // raster image is the size of the image
    float [] vb = new float[4];
    vb[0] = 0; // x
    vb[1] = 0; // y
    vb[2] = (float)imgBounds.getWidth(); // width
    vb[3] = (float)imgBounds.getHeight(); // height

    // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets the
    // appropriate AffineTransform to the image node
    initializeViewport(ctx, e, node, vb, bounds);

    return node;
}
项目:Push2Display    文件:SVGImageElementBridge.java   
GraphicsNode createBrokenImageNode
    (BridgeContext ctx, Element e, String uri, String message) {
    SVGDocument doc = ctx.getUserAgent().getBrokenLinkDocument
        (e, uri, Messages.formatMessage(URI_IMAGE_ERROR,
                                       new Object[] { message } ));
    return createSVGImageNode(ctx, e, doc);
}
项目:Push2Display    文件:SVGLoadEventDispatcher.java   
/**
 * Creates a new SVGLoadEventDispatcher.
 */
public SVGLoadEventDispatcher(GraphicsNode gn,
                              SVGDocument doc,
                              BridgeContext bc,
                              UpdateManager um) {
    svgDocument = doc;
    root = gn;
    bridgeContext = bc;
    updateManager = um;
}
项目:Push2Display    文件:JSVGCanvas.java   
/**
 * Sets the tool tip on the input element.
 */
public void setToolTip(Element elt, String toolTip){
    if (toolTipMap == null) {
        toolTipMap = new WeakHashMap();
    }
    if (toolTipDocs == null) {
        toolTipDocs = new WeakHashMap();
    }
    SVGDocument doc = (SVGDocument)elt.getOwnerDocument();
    if (toolTipDocs.put(doc, MAP_TOKEN) == null) {
        NodeEventTarget root;
        root = (NodeEventTarget)doc.getRootElement();
        // On mouseover, it sets the tooltip to the given value
        root.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
                                SVGConstants.SVG_EVENT_MOUSEOVER,
                                toolTipListener,
                                false, null);
        // On mouseout, it removes the tooltip
        root.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI,
                                SVGConstants.SVG_EVENT_MOUSEOUT,
                                toolTipListener,
                                false, null);
    }

    toolTipMap.put(elt, toolTip);

    if (elt == lastTarget)
        EventQueue.invokeLater(new ToolTipRunnable(toolTip));
}
项目:Push2Display    文件:NullSetSVGDocumentTest.java   
public JSVGCanvasHandler createHandler() {
    return new JSVGCanvasHandler(this, this) {
            public JSVGCanvas createCanvas() { 
                return new JSVGCanvas() {
                        protected void installSVGDocument(SVGDocument doc){
                            super.installSVGDocument(doc);
                            if (doc != null) return;
                            handler.scriptDone();
                        }
                    };
            }
        };
}
项目:Push2Display    文件:EventListenerInitializerImpl.java   
/**
 * This method is called by the SVG viewer
 * when the scripts are loaded to register
 * the listener needed.
 * @param doc The current document.
 */
public void initializeEventListeners(SVGDocument doc) {
    System.err.println(">>>>>>>>>>>>>>>>>>> SVGDocument : " + doc);
    ((EventTarget)doc.getElementById("testContent")).
        addEventListener("mousedown", new EventListener() {
            public void handleEvent(Event evt) {
                ((Element)evt.getTarget()).setAttributeNS(null, "fill", "orange");
            }
        }, false);
}
项目:mars-sim    文件:SVGLoader.java   
/**
 * Load the SVG image with the specified name. This operation may either
 * create a new graphics node of returned a previously created one.
 * @param name Name of the SVG file to load.
 * @return GraphicsNode containing SVG image or null if none found.
 */
public static GraphicsNode getSVGImage(String name) {
    if (svgCache == null) svgCache = new HashMap<String, GraphicsNode>();

    GraphicsNode found = svgCache.get(name);
    if (found == null) {
        String fileName = SVG_DIR + name;
        URL resource = SVGLoader.class.getResource(fileName);

        try {
            String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser);
            SVGDocument doc = df.createSVGDocument(resource.toString());
            UserAgent userAgent = new UserAgentAdapter();
            DocumentLoader loader = new DocumentLoader(userAgent);
            BridgeContext ctx = new BridgeContext(userAgent, loader);
            ctx.setDynamicState(BridgeContext.DYNAMIC);
            GVTBuilder builder = new GVTBuilder();
            found = builder.build(ctx, doc);

            svgCache.put(name, found);
        }
        catch (Exception e) {
            System.err.println("getSVGImage error: " + fileName);
            e.printStackTrace(System.err);
        }
    }

    return found;
}
项目:eurocarbdb    文件:SvgFactory.java   
/**
 * Create the SVGDocument and the SVGGraphics2D objects of this SvgFactory.
 * This method is called by the constructors.
 */
private void setupFactory() {
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

    this.setSvgDoc((SVGDocument) impl.createDocument(svgNS, "svg", null));
    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.getSvgDoc());
    ctx.setComment("Generated by MonosaccharideDB (www.monosaccharidedb.org) with Batik SVG Generator");
    this.setSVGGraph2D(new SVGGraphics2D(ctx, false));
}
项目:eurocarbdb    文件:SvgFactory.java   
public void display() {
    SVGDocument doc = this.getSvgDoc();
    JSVGCanvas canvas = new JSVGCanvas();
    org.w3c.dom.Element root = doc.getDocumentElement();
    this.getRoot(root);
    JFrame f = new JFrame();
    f.getContentPane().add(canvas);
    canvas.setSVGDocument(doc);
    f.pack();
    f.setVisible(true);
    //f.dispose();
}
项目:NBModeler    文件:ModelerDocument.java   
/**
     * @return the document
     */
//  BUG : org.w3c.dom.svg.SVGDocument JAXB can't handle interface ; add JAB_API from Netbeans Module Platform
    @Override
    public SVGDocument getDocument() {
        return svgImage.getSvgDocument();
//        return document;
    }