Esempio n. 1
0
 /** Method to dispatch SVG Resize event. */
 protected void dispatchSVGResizeEvent() {
   if (bridgeContext.isSVG12()) {
     dispatchSVGDocEvent("resize");
   } else {
     dispatchSVGDocEvent("SVGResize");
   }
 }
Esempio n. 2
0
 /** Method to dispatch SVG Zoom event. */
 protected void dispatchSVGZoomEvent() {
   if (bridgeContext.isSVG12()) {
     dispatchSVGDocEvent("zoom");
   } else {
     dispatchSVGDocEvent("SVGZoom");
   }
 }
Esempio n. 3
0
 /** Method to dispatch SVG Scroll event. */
 protected void dispatchSVGScrollEvent() {
   if (bridgeContext.isSVG12()) {
     dispatchSVGDocEvent("scroll");
   } else {
     dispatchSVGDocEvent("SVGScroll");
   }
 }
Esempio n. 4
0
  /** Auxiliary method for dispatchSVGLoad. */
  protected void dispatchSVGLoad(Element elt, boolean checkCanRun, String lang) {
    for (Node n = elt.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() == Node.ELEMENT_NODE) {
        dispatchSVGLoad((Element) n, checkCanRun, lang);
      }
    }

    DocumentEvent de = (DocumentEvent) elt.getOwnerDocument();
    AbstractEvent ev = (AbstractEvent) de.createEvent("SVGEvents");
    String type;
    if (bridgeContext.isSVG12()) {
      type = "load";
    } else {
      type = "SVGLoad";
    }
    ev.initEventNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, type, false, false);
    NodeEventTarget t = (NodeEventTarget) elt;

    final String s = elt.getAttributeNS(null, SVGConstants.SVG_ONLOAD_ATTRIBUTE);
    if (s.length() == 0) {
      // No script to run so just dispatch the event to DOM
      // (For java presumably).
      t.dispatchEvent(ev);
      return;
    }

    final Interpreter interp = getInterpreter();
    if (interp == null) {
      // Can't load interpreter so just dispatch normal event
      // to the DOM (for java presumably).
      t.dispatchEvent(ev);
      return;
    }

    if (checkCanRun) {
      // Check that it is ok to run embeded scripts
      checkCompatibleScriptURL(lang, docPURL);
      checkCanRun = false; // we only check once for onload handlers
    }

    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(), SVGConstants.SVG_ONLOAD_ATTRIBUTE, new Integer(line)});

    EventListener l =
        new EventListener() {
          public void handleEvent(Event evt) {
            try {
              Object event;
              if (evt instanceof ScriptEventWrapper) {
                event = ((ScriptEventWrapper) evt).getEventObject();
              } else {
                event = evt;
              }
              interp.bindObject(EVENT_NAME, event);
              interp.bindObject(ALTERNATE_EVENT_NAME, event);
              interp.evaluate(new StringReader(s), desc);
            } catch (IOException io) {
            } catch (InterpreterException e) {
              handleInterpreterException(e);
            }
          }
        };
    t.addEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, type, l, false, null);
    t.dispatchEvent(ev);
    t.removeEventListenerNS(XMLConstants.XML_EVENTS_NAMESPACE_URI, type, l, false);
  }