Exemple #1
0
    @Override
    public void hyperlinkUpdate(@NotNull HyperlinkEvent e) {
      if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
        return;
      }

      String description = e.getDescription();
      if (StringUtil.isEmpty(description)
          || !description.startsWith(DocumentationManager.PSI_ELEMENT_PROTOCOL)) {
        return;
      }

      String elementName =
          e.getDescription().substring(DocumentationManager.PSI_ELEMENT_PROTOCOL.length());

      final PsiElement targetElement =
          myProvider.getDocumentationElementForLink(
              PsiManager.getInstance(myProject), elementName, myContext);
      if (targetElement != null) {
        LightweightHint hint = myHint;
        if (hint != null) {
          hint.hide(true);
        }
        myDocumentationManager.showJavaDocInfo(targetElement, myContext, true, null);
      }
    }
 @Override
 protected void hyperlinkActivated(HyperlinkEvent e) {
   final Module moduleByName =
       ModuleManager.getInstance(myProject).findModuleByName(e.getDescription());
   if (moduleByName != null) {
     myConfiguration.getConfigurationModule().setModule(moduleByName);
     try {
       final Executor executor =
           myConsoleProperties.isDebug()
               ? DefaultDebugExecutor.getDebugExecutorInstance()
               : DefaultRunExecutor.getRunExecutorInstance();
       final ProgramRunner runner =
           RunnerRegistry.getInstance().getRunner(executor.getId(), myConfiguration);
       assert runner != null;
       runner.execute(
           executor,
           new ExecutionEnvironment(
               myConfiguration,
               myProject,
               getRunnerSettings(),
               getConfigurationSettings(),
               null));
       final Balloon balloon = myToolWindowManager.getToolWindowBalloon(myTestRunDebugId);
       if (balloon != null) {
         balloon.hide();
       }
     } catch (ExecutionException e1) {
       LOG.error(e1);
     }
   }
 }
 @Override
 public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
   if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED
       && event.getDescription().equals("saver")) {
     showSavedChanges();
   }
 }
 /**
  * Update the browser links
  *
  * @param event on hyperlink event
  */
 @Override
 public void hyperlinkUpdate(HyperlinkEvent event) {
   if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
     if (event.getDescription().startsWith("http://")
         || event.getDescription().startsWith("https://")
         || event.getDescription().startsWith("ftp://")) {
       WebBrowser.openUrl(event.getURL(), event.getDescription());
     } else if (event.getDescription().startsWith(SCILAB_PROTO)) {
       if (helpSets == null) {
         initHelpSets(x.getModel().getHelpSet());
       }
       URL url = resolvScilabLink(event);
       if (url != null) {
         super.hyperlinkUpdate(
             new HyperlinkEvent(event.getSource(), event.getEventType(), url, ""));
       }
     } else if (event.getDescription().startsWith(FILE_PROTO)) {
       String url = event.getDescription();
       url = url.replaceFirst("SCI", Matcher.quoteReplacement(SCI));
       WebBrowser.openUrl(url);
     } else {
       super.hyperlinkUpdate(event);
     }
   }
 }
 @Override
 protected void hyperlinkActivated(
     @NotNull Notification notification, @NotNull HyperlinkEvent event) {
   if (event.getDescription().equals("configure") && !myProject.isDisposed()) {
     ShowSettingsUtil.getInstance()
         .showSettingsDialog(myProject, ActionsBundle.message("group.VcsGroup.text"));
     Collection<VcsRootError> errorsAfterPossibleFix = getInstance(myProject).scan();
     if (errorsAfterPossibleFix.isEmpty() && !notification.isExpired()) {
       notification.expire();
     }
   } else if (event.getDescription().equals("ignore")) {
     mySettings.addIgnoredUnregisteredRoots(
         ContainerUtil.map(myImportantUnregisteredRoots, PATH_FROM_ROOT_ERROR));
     notification.expire();
   } else if (event.getDescription().equals("add")) {
     List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
     for (VcsRootError root : myImportantUnregisteredRoots) {
       mappings = VcsUtil.addMapping(mappings, root.getMapping(), root.getVcsKey().getName());
     }
     myVcsManager.setDirectoryMappings(mappings);
   }
 }
 /**
  * Makes the links active.
  *
  * @param evt
  */
 private void textJEditorPaneHyperlinkUpdate(
     javax.swing.event.HyperlinkEvent evt) { // GEN-FIRST:event_textJEditorPaneHyperlinkUpdate
   if (evt.getEventType()
       .toString()
       .equalsIgnoreCase(javax.swing.event.HyperlinkEvent.EventType.ENTERED.toString())) {
     setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
   } else if (evt.getEventType()
       .toString()
       .equalsIgnoreCase(javax.swing.event.HyperlinkEvent.EventType.EXITED.toString())) {
     setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
   } else if (evt.getEventType()
       .toString()
       .equalsIgnoreCase(javax.swing.event.HyperlinkEvent.EventType.ACTIVATED.toString())) {
     if (evt.getDescription().startsWith("#")) {
       textJEditorPane.scrollToReference(evt.getDescription());
     } else {
       this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
       BareBonesBrowserLaunch.openURL(evt.getDescription());
       this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
     }
   }
 } // GEN-LAST:event_textJEditorPaneHyperlinkUpdate
    /** @param e */
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
        StringTokenizer st = new StringTokenizer(e.getDescription(), " ");
        if (st.hasMoreTokens()) {
          String selectedID = st.nextToken();

          if (selectedID.startsWith("play=")) {
            selectedID = selectedID.replace("play=", "");
            playResult(selectedID);
          } else if (selectedID.startsWith("show=")) {
            selectedID = selectedID.replace("show=", "");
            showResult(selectedID);
          }
        }
      }
    }
 @Override
 public void hyperlinkUpdate(
     @NotNull final Notification notification, @NotNull HyperlinkEvent event) {
   if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED
       && event.getDescription().equals("resolve")) {
     notification.expire();
     ApplicationManager.getApplication()
         .executeOnPooledThread(
             new Runnable() {
               @Override
               public void run() {
                 mergeNoProceed();
               }
             });
   }
 }
  @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);
      }
    }
  }
  @Override
  public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e instanceof FormSubmitEvent) {
      FormSubmitEvent event = (FormSubmitEvent) e;

      // Just pushed the download the file button...
      LOG.debugf("File offer download requested. FileId: {0}", event.getData());

      try {
        String dataStr = event.getData();
        String fileIdEncoded = dataStr.substring(dataStr.indexOf("=") + 1).trim();
        String fileId = URLDecoder.decode(fileIdEncoded, "UTF-8");
        downloadFileOffer(fileId);
      } catch (UnsupportedEncodingException uee) {
        throw new RuntimeException(uee); // impossible
      }
    } else if (HyperlinkEvent.EventType.ACTIVATED == e.getEventType()) {
      handleLinkClick(e.getDescription(), e.getURL());
    }
  }
  @Override
  public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType().equals(EventType.ACTIVATED)) {
      String code = e.getDescription();

      if (code.matches("v[0-9]+")) {
        int register = Integer.parseInt(code.substring(1));

        rend.setSelectedInstruction(ih);
        rend.setSelectedRegister(register);

        ArrayList<InstructionHandle> result =
            new ArrayList<InstructionHandle>(AnalysisGraph.lastInstruction(ih, register));

        rend.setLastInstructions(result);
        rend.showResults();

      } else throw new IllegalArgumentException("Wrong Event");
    }
  }
Exemple #12
0
  // implemented for HyperlinkListener
  public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      JEditorPane ep = (JEditorPane) (e.getSource());

      // handle frame events properly
      if (e instanceof HTMLFrameHyperlinkEvent) {
        HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
        HTMLDocument doc = (HTMLDocument) (ep.getDocument());
        doc.processHTMLFrameHyperlinkEvent(evt);
      } else // handle normal links
      {
        try {
          URL currentLoc = new URL(location);
          URL newLoc = new URL(currentLoc, e.getDescription());

          setBrowserLocation(newLoc.toString());
        } catch (MalformedURLException malUrl) {
          JOptionPane.showMessageDialog(
              this, "Malformed URL", "Browser Error", JOptionPane.ERROR_MESSAGE);
          return;
        }
      }
    }
  }
  /** {@inheritDoc} */
  public void urlClicked(HyperlinkEvent e, Completion c, DescWindowCallback callback) {

    // A "real" URL (starts with http://, for example) should be opened
    // in the system browser, not the completion description window.
    URL url = e.getURL();
    if (url != null) {
      // Try loading in external browser (Java 6+ only).
      try {
        Util.browse(new URI(url.toString()));
      } catch (/*IO*/ URISyntaxException ioe) {
        UIManager.getLookAndFeel().provideErrorFeedback(null);
        ioe.printStackTrace();
      }
      return;
    }

    // A relative path URL (no leading "http://") results in a null URL.
    // Class should be in the same package as the one we're currently
    // viewing.  Example:  java.lang.String class documentation
    String desc = e.getDescription();
    Logger.log(desc);
    if (desc != null) {

      if (isRelativeUrl(desc)) {
        int ext = desc.indexOf(".htm");
        if (ext > -1) {

          // Could be <a href="Character.html#section"> link.  A
          // popular href format is "../../util/Formatter.html#syntax".
          // We must determine "relative" package location.
          String anchor = getAnchor(desc);
          String clazz = desc.substring(0, ext);
          int backups = 0;
          while (clazz.startsWith("../")) {
            backups++;
            clazz = clazz.substring(3);
          }
          clazz = clazz.replace('/', '.');

          String pkg = getPackage(c, desc);
          if (pkg != null) {
            clazz = doBackups(pkg, backups) + "." + clazz;
            JavaScriptLanguageSupport jls = getJavaScriptLanguageSupport();
            ClassFile cf = jls.getJarManager().getClassEntry(clazz);
            if (cf != null) {
              JSClassCompletion cc = new JSClassCompletion(c.getProvider(), cf);
              callback.showSummaryFor(cc, anchor);
            }
          }
        }
      }

      // Could be format "com.mycompany.pkg.MyClass", with optional
      // #method() (for example, @see's).
      else {

        JavaScriptLanguageSupport jls = getJavaScriptLanguageSupport();

        String clazz = desc;
        String member = null;
        int pound = desc.indexOf('#');
        if (pound > -1) { // TODO: Handle properly
          member = clazz.substring(pound + 1);
          clazz = clazz.substring(0, pound);
        }

        // Just a class name, i.e. "String", "java.util.regex.Pattern".
        if (member == null) {
          boolean guessedPackage = false;
          if (clazz.indexOf('.') == -1) {
            String pkg = getPackage(c, desc);
            if (pkg != null) {
              clazz = pkg + "." + clazz;
            }
            guessedPackage = true;
          }
          ClassFile cf = jls.getJarManager().getClassEntry(clazz);
          if (cf == null && guessedPackage) {
            // Wasn't in the same package as "c", try java.lang
            int lastDot = clazz.lastIndexOf('.');
            clazz = "java.lang." + clazz.substring(lastDot + 1);
            cf = jls.getJarManager().getClassEntry(clazz);
          }
          if (cf != null) {
            JSClassCompletion cc = new JSClassCompletion(c.getProvider(), cf);
            callback.showSummaryFor(cc, null);
          } else {
            UIManager.getLookAndFeel().provideErrorFeedback(null);
            Logger.log("Unknown class: " + clazz);
          }
        }

        // Member specified, such as "String#format(...)",
        // "java.util.regex.Pattern.compile(...)", or "#method()".
        else {

          boolean guessedPackage = false;

          if (pound == 0) { // Member of this class (i.e. "#foobar(bas)")
            // "clazz" was incorrect previously in this case
            clazz = getClass(c, desc);
          } else { // i.e. "String#CASE_INSENSITIVE_ORDER"
            // If no package specified, assume clazz is in the same
            // package as the currently displayed completion.
            if (clazz.indexOf('.') == -1) {
              String pkg = getPackage(c, desc);
              if (pkg != null) {
                clazz = pkg + "." + clazz;
              }
              guessedPackage = true;
            }
          }

          ClassFile cf = clazz != null ? jls.getJarManager().getClassEntry(clazz) : null;
          if (cf == null && guessedPackage) {
            // Wasn't in the same package as "c", try java.lang
            int lastDot = clazz.lastIndexOf('.');
            clazz = "java.lang." + clazz.substring(lastDot + 1);
            cf = jls.getJarManager().getClassEntry(clazz);
          }

          if (cf != null) {

            Completion memberCompletion = null;
            int lparen = member.indexOf('(');
            if (lparen == -1) { // A field, or method with args omitted
              FieldInfo fi = cf.getFieldInfoByName(member);
              if (fi != null) { // Try fields first, it's most likely
                memberCompletion = new JSFieldCompletion(c.getProvider(), fi);
              } else { // Try methods second
                List miList = cf.getMethodInfoByName(member, -1);
                if (miList != null && miList.size() > 0) {
                  MethodInfo mi = (MethodInfo) miList.get(0); // Just show the first if multiple
                  memberCompletion = new JSFunctionCompletion(c.getProvider(), mi);
                }
              }
            } else {
              String[] args = getArgs(member);
              String methodName = member.substring(0, lparen);
              List miList = cf.getMethodInfoByName(methodName, args.length);
              if (miList != null && miList.size() > 0) {
                if (miList.size() > 1) {
                  // TODO: Pick correct overload based on args
                  Logger.log("Multiple overload support not yet implemented");
                } else {
                  MethodInfo mi = (MethodInfo) miList.get(0);
                  memberCompletion = new JSFunctionCompletion(c.getProvider(), mi);
                }
              }
            }

            if (memberCompletion != null) {
              callback.showSummaryFor(memberCompletion, null);
            }

          } else {
            UIManager.getLookAndFeel().provideErrorFeedback(null);
            Logger.logError("Unknown class: " + clazz + " (href: " + desc + ")");
          }
        }
      }
    }
  }
 @Override
 public void hyperlinkUpdate(HyperlinkEvent e) {
   if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
     OpenBrowser.displayUrl(e.getDescription());
   }
 }
  /**
   * 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;
  }
Exemple #17
0
  /**
   * Method to handle hyper link events.
   *
   * @param event hyper link event
   */
  public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
      setCursor(cbusy);
      try {
        URL url = event.getURL();

        int ind1 = event.getDescription().indexOf("[");
        int ind2 = event.getDescription().lastIndexOf("]");

        String search = "";
        if (ind1 > -1 && ind2 > -1) search = event.getDescription().substring(ind1 + 1, ind2);
        else {
          ind1 = event.getDescription().indexOf("=") + 1; // genedb
          if (ind1 > -1) search = event.getDescription().substring(ind1);
        }

        if (desktop != null) {
          if (BigPane.srsTabPane.isSelected()) setUpSRSFrame(url, search);

          if (BigPane.srsWin.isSelected()) {
            int hgt = (2 * desktop.getHeight()) / 3;
            Annotation edPane = new Annotation(url);
            JScrollPane jsp = new JScrollPane(edPane);
            JInternalFrame jif =
                new JInternalFrame(
                    "SRS " + search,
                    true, // resizable
                    true, // closable
                    true, // maximizable
                    true); // iconifiable);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(new CommonMenu(jif));
            jif.setJMenuBar(menuBar);
            jif.getContentPane().add(jsp);
            jif.setLocation(0, 0);
            jif.setSize(800, hgt);
            jif.setVisible(true);
            desktop.add(jif);
          }

          if (BigPane.srsBrowser.isSelected()) BrowserControl.displayURL(event.getDescription());
        } else {
          setPage(url);
          back.add(url);
        }
      } catch (IOException ioe) {
        String msg = event.getDescription();
        if (msg.length() > 50) msg = msg.substring(0, 50) + "....";

        JOptionPane.showMessageDialog(
            this, "Cannot reach URL:\n" + msg, "Cannot Connect", JOptionPane.INFORMATION_MESSAGE);
        //      ioe.printStackTrace();
        //      ("Can't follow link to " +
        //                event.getURL().toExternalForm() );
      }

      setCursor(cdone);
    } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) {
      try {
        JTextField statusField = (JTextField) BigPane.srsFrame.getContentPane().getComponent(1);
        statusField.setText(event.getDescription());
      } catch (Exception exp) {
      }

    } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) {
      try {
        JTextField statusField = (JTextField) BigPane.srsFrame.getContentPane().getComponent(1);
        statusField.setText("");
      } catch (Exception exp) {
      }
    }
  }