Ejemplo n.º 1
0
 /**
  * Checks whether the hyperlink event originated on a <a ...> element with a relative href
  * consisting of a URL fragment only, i.e. <a href="#thisIsALocalFragment">. If so,
  * replies the fragment, i.e. "thisIsALocalFragment".
  *
  * <p>Otherwise, replies <code>null</code>
  *
  * @param e the hyperlink event
  * @return the local fragment or <code>null</code>
  */
 protected String getUrlFragment(HyperlinkEvent e) {
   AttributeSet set = e.getSourceElement().getAttributes();
   Object value = set.getAttribute(Tag.A);
   if (!(value instanceof SimpleAttributeSet)) return null;
   SimpleAttributeSet atts = (SimpleAttributeSet) value;
   value = atts.getAttribute(javax.swing.text.html.HTML.Attribute.HREF);
   if (value == null) return null;
   String s = (String) value;
   if (s.matches("#.*")) return s.substring(1);
   return null;
 }
Ejemplo n.º 2
0
  @Override
  public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      panel.history.goTo(Integer.parseInt(e.getDescription()));
      panel.refresh();
    } else {
      final Element element = e.getSourceElement();
      final int start = element.getStartOffset();
      final int length = element.getEndOffset() - start;
      final HTMLDocument html = ((HTMLDocument) getDocument());

      if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
        html.setParagraphAttributes(start, length, hoverAttr, false);
      }
      if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
        html.setParagraphAttributes(start, length, normalAttr, false);
      }
    }
  }
  /**
   * Try to transform an address such as scilab://scilab.help/bvode into a conform URL pointing to
   * the corresponding file in using jar: protocol. E.g. scilab://scilab.help/bvode will be
   * transform into
   * jar:file:SCI/modules/helptools/jar/scilab_fr_FR_help.jar!/scilab_fr_FR_help/bvode.html (where
   * SCI has the good value)
   *
   * @param event the yperlink event
   * @return the correct address in using jar:// protocol
   */
  public URL resolvScilabLink(HyperlinkEvent event) {
    int pos = SCILAB_PROTO.length();
    String addr = event.getDescription();
    addr = addr.trim().replaceAll("\\\\", "/");
    addr = addr.substring(pos);

    pos = addr.indexOf("/");
    String location;
    String path = "";
    if (pos != -1) {
      location = addr.substring(0, pos);
      if (pos != addr.length()) {
        path = addr.substring(pos + 1);
      }
    } else {
      return getURLFromID(addr);
    }

    String[] splitLoc = location.split("\\.");
    String mainLocation = null;
    String subLocation;

    if (splitLoc.length >= 1) {
      mainLocation = splitLoc[0];
    }
    if (splitLoc.length >= 2) {
      subLocation = splitLoc[1];
    } else {
      System.err.println("Unable decode the Scilab content type\n" + event.getDescription());
      return null;
    }

    switch (subLocation) {
      case "help":
        if ("scilab".equals(mainLocation)) {
          return getURLFromID(path);
        } else {
          return getURLFromID(mainLocation, path);
        }
      case "xcos":
      case "scinotes":
        if ("scilab".equals(mainLocation)) {
          exec(subLocation, SCI + "/modules/" + path);
        } else {
          exec(subLocation, getToolboxPath() + "/" + path);
        }
        break;
      case "demos":
        if ("scilab".equals(mainLocation)) {
          exec(SCI + "/modules/" + path + ".sce");
        } else {
          exec(getToolboxPath() + "/demos/" + path + ".sce");
        }
        break;
      case "execexample":
        execExample(
            event
                .getSourceElement()
                .getParentElement()
                .getParentElement()
                .getParentElement()
                .getElement(0)
                .getElement(0));
        break;
      case "editexample":
        editExample(
            event
                .getSourceElement()
                .getParentElement()
                .getParentElement()
                .getParentElement()
                .getElement(0)
                .getElement(0));
        break;
      case "exec":
        if (mainLocation.equals("scilab")) {
          exec(SCI + "/modules/" + path);
        } else {
          exec(getToolboxPath() + "/" + path);
        }
        break;
    }

    return null;
  }
  /**
   * Try to transform an address such as scilab://scilab.help/bvode into a conform URL pointing to
   * the corresponding file in using jar: protocol. E.g. scilab://scilab.help/bvode will be
   * transform into
   * jar:file:SCI/modules/helptools/jar/scilab_fr_FR_help.jar!/scilab_fr_FR_help/bvode.html (where
   * SCI has the good value)
   *
   * @param address the address to convert
   * @return the correct address in using jar:// protocol
   */
  public URL resolvScilabLink(HyperlinkEvent event) {
    int pos = SCILAB_PROTO.length();
    String addr = event.getDescription();
    addr = addr.trim().replaceAll("\\\\", "/");
    addr = addr.substring(pos);

    pos = addr.indexOf("/");
    String location;
    String path = "";
    if (pos != -1) {
      location = addr.substring(0, pos);
      if (pos != addr.length()) {
        path = addr.substring(pos + 1);
      }
    } else {
      return getURLFromID(addr);
    }

    String[] splitLoc = location.split("\\.");
    String mainLocation = null;
    String subLocation = null;

    if (splitLoc.length >= 1) {
      mainLocation = splitLoc[0];
    }
    if (splitLoc.length >= 2) {
      subLocation = splitLoc[1];
    }

    if (subLocation.equals("help")) {
      if (mainLocation.equals("scilab")) {
        return getURLFromID(path);
      } else {
        return getURLFromID(mainLocation, path);
      }
    } else if (subLocation.equals("xcos") || subLocation.equals("scinotes")) {
      if (!mainLocation.equals("scilab")) {
        exec(subLocation, getToolboxPath() + "/" + path);
      } else {
        exec(subLocation, SCI + "/modules/" + path);
      }
    } else if (subLocation.equals("demos")) {
      if (!mainLocation.equals("scilab")) {
        exec(getToolboxPath() + "/demos/" + path + ".sce");
      } else {
        exec(SCI + "/modules/" + path + ".sce");
      }
    } else if (subLocation.equals("execexample")) {
      execExample(
          event
              .getSourceElement()
              .getParentElement()
              .getParentElement()
              .getParentElement()
              .getElement(0)
              .getElement(0));
    } else if (subLocation.equals("editexample")) {
      editExample(
          event
              .getSourceElement()
              .getParentElement()
              .getParentElement()
              .getParentElement()
              .getElement(0)
              .getElement(0));
    } else if (subLocation.equals("exec")) {
      if (!mainLocation.equals("scilab")) {
        exec(getToolboxPath() + "/" + path);
      } else {
        exec(SCI + "/modules/" + path);
      }
    }

    return null;
  }