protected void updateSvgDocument() {
    getBrowserExtension().clearLocalHyperlinkCache();
    getBrowserExtension().clearResourceCache();

    SVGDocument doc = getSvgDocument();
    if (doc == null) {
      getUiField().setText("");
      return;
    }
    try {
      // set the dimensions of the svg element to the size of the browser field
      Rectangle browserBounds = getAbsoluteBrowserBounds();
      doc.getRootElement()
          .setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, browserBounds.height + "px");
      doc.getRootElement()
          .setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, browserBounds.width + "px");

      // get the svg code as string and rewrite the local links
      String svgText =
          getBrowserExtension().adaptLocalHyperlinks(getSvgContentFromDocument(doc), 2);

      // bugfix for SVG fields to ensure all context menus are closed when the user clicks into the
      // svg field
      String contextMenuHideScript =
          "parent.parent.org.eclipse.rwt.MenuManager.getInstance().update(null, 'mousedown');";

      // bugfix so that the svg field inherits the color of the parent container. otherwise it is
      // always defined white.
      String backgroundColorInheritScript = null;
      if (getScoutObject().getBackgroundColor() == null) {
        backgroundColorInheritScript =
            "var iframes = parent.document.getElementsByTagName('iframe');"
                + "for(var i=0;i<iframes.length;i++) {"
                + "  var field=iframes[i].parentNode;"
                + "  var color=field.style.backgroundColor;"
                + "  if(color && color.toLowerCase() === 'rgb(255, 255, 255)') "
                + "    field.style.backgroundColor='';"
                + "}";
      } else {
        backgroundColorInheritScript = "";
      }

      // set the html content to the browser
      getUiField()
          .setText(
              "<html><body width=\"100%\" height=\"100%\" onload=\""
                  + backgroundColorInheritScript
                  + "\" onclick=\""
                  + contextMenuHideScript
                  + "\">"
                  + svgText
                  + "</body></html>");
    } catch (Exception e) {
      LOG.error("preparing svg browser content", e);
      getUiField().setText("");
    }
  }
 protected static String getSvgContentFromDocument(SVGDocument doc) throws ProcessingException {
   try {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     DOMSource domSource = new DOMSource(doc.getRootElement());
     StreamResult streamResult = new StreamResult(out);
     Transformer t = TransformerFactory.newInstance().newTransformer();
     t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
     t.setOutputProperty(OutputKeys.ENCODING, DOCUMENT_ENCODING);
     t.transform(domSource, streamResult);
     out.close();
     return new String(out.toByteArray(), DOCUMENT_ENCODING);
   } catch (Exception e) {
     throw new ProcessingException("Writing SVG Failed", e);
   }
 }
Example #3
0
  public Document(InputStream stream) throws IOException {
    f = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
    doc = f.createSVGDocument(null, stream);

    // Boot the CSS engine
    userAgent = new UserAgentAdapter();
    loader = new DocumentLoader(userAgent);
    ctx = new BridgeContext(userAgent, loader);
    ctx.setDynamicState(BridgeContext.DYNAMIC);
    builder = new GVTBuilder();
    rootGN = builder.build(ctx, doc);

    svgRoot = doc.getRootElement();
    vcss = (ViewCSS) doc.getDocumentElement();
  }
Example #4
0
 /**
  * Default implementation uses the root element of the document associated with BridgeContext.
  * This is useful for CSS case.
  */
 protected Element getBaseElement(BridgeContext ctx) {
   SVGDocument d = (SVGDocument) ctx.getDocument();
   return d.getRootElement();
 }