Search in sources :

Example 16 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project intellij-community by JetBrains.

the class SearchForUsagesRunnable method notifyByFindBalloon.

private static void notifyByFindBalloon(@Nullable final HyperlinkListener listener, @NotNull final MessageType info, @NotNull FindUsagesProcessPresentation processPresentation, @NotNull final Project project, @NotNull final List<String> lines) {
    // in case tool window not registered
    com.intellij.usageView.UsageViewManager.getInstance(project);
    final Collection<VirtualFile> largeFiles = processPresentation.getLargeFiles();
    List<String> resultLines = new ArrayList<>(lines);
    HyperlinkListener resultListener = listener;
    if (!largeFiles.isEmpty()) {
        String shortMessage = "(<a href='" + LARGE_FILES_HREF_TARGET + "'>" + UsageViewBundle.message("large.files.were.ignored", largeFiles.size()) + "</a>)";
        resultLines.add(shortMessage);
        resultListener = addHrefHandling(resultListener, LARGE_FILES_HREF_TARGET, () -> {
            String detailedMessage = detailedLargeFilesMessage(largeFiles);
            List<String> strings = new ArrayList<>(lines);
            strings.add(detailedMessage);
            //noinspection SSBasedInspection
            ToolWindowManager.getInstance(project).notifyByBalloon(ToolWindowId.FIND, info, wrapInHtml(strings), AllIcons.Actions.Find, listener);
        });
    }
    Runnable searchIncludingProjectFileUsages = processPresentation.searchIncludingProjectFileUsages();
    if (searchIncludingProjectFileUsages != null) {
        resultLines.add("Occurrences in project configuration files are skipped. " + "<a href='" + SHOW_PROJECT_FILE_OCCURRENCES_HREF_TARGET + "'>Include them</a>");
        resultListener = addHrefHandling(resultListener, SHOW_PROJECT_FILE_OCCURRENCES_HREF_TARGET, searchIncludingProjectFileUsages);
    }
    //noinspection SSBasedInspection
    ToolWindowManager.getInstance(project).notifyByBalloon(ToolWindowId.FIND, info, wrapInHtml(resultLines), AllIcons.Actions.Find, resultListener);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 17 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project intellij-community by JetBrains.

the class HoverHyperlinkLabel method setupListener.

private void setupListener() {
    addMouseListener(new MouseAdapter() {

        public void mouseEntered(MouseEvent e) {
            HoverHyperlinkLabel.super.setText(underlineTextInHtml(myOriginalText));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            HoverHyperlinkLabel.super.setText(myOriginalText);
            setCursor(Cursor.getDefaultCursor());
        }
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            HyperlinkEvent event = new HyperlinkEvent(HoverHyperlinkLabel.this, HyperlinkEvent.EventType.ACTIVATED, null);
            for (HyperlinkListener listener : myListeners) {
                listener.hyperlinkUpdate(event);
            }
            return true;
        }
    }.installOn(this);
}
Also used : MouseEvent(java.awt.event.MouseEvent) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) MouseAdapter(java.awt.event.MouseAdapter)

Example 18 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project ChatGameFontificator by GlitchCog.

the class ControlWindow method constructAboutPopup.

/**
     * Construct the popup dialog containing the About message
     */
private void constructAboutPopup() {
    aboutPane = new JEditorPane("text/html", ABOUT_CONTENTS);
    aboutPane.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (EventType.ACTIVATED.equals(e.getEventType())) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(URI.create("https://" + e.getDescription()));
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
    aboutPane.setEditable(false);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) JEditorPane(javax.swing.JEditorPane) IOException(java.io.IOException)

Example 19 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project intellij-plugins by JetBrains.

the class JstdServerStatusView method installLinkHandler.

private static void installLinkHandler(@NotNull JEditorPane pane) {
    final Ref<String> urlRef = Ref.create(null);
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                urlRef.set(null);
            } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                urlRef.set(e.getDescription());
            } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(e.getDescription());
            }
        }
    });
    final CopyLinkAction copyLinkAction = new CopyLinkAction();
    final OpenLinkInBrowser openLinkInBrowserAction = new OpenLinkInBrowser();
    final DefaultActionGroup group = new DefaultActionGroup(openLinkInBrowserAction, copyLinkAction);
    pane.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            String url = urlRef.get();
            copyLinkAction.setUrl(url);
            openLinkInBrowserAction.setUrl(url);
            if (url != null) {
                ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group);
                popupMenu.getComponent().show(comp, x, y);
            }
        }
    });
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 20 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project processdash by dtuma.

the class AutoUpdateManager method displayUpdateMessage.

/** Display a message box, telling the user that various packages are
     *  now available for download.
     */
protected void displayUpdateMessage(Component parent, int numUpdatesFound) {
    HashSet urlsSeen = new HashSet();
    DashPackage pkg;
    StringBuffer html = new StringBuffer();
    html.append("<html><head><style>" + "UL { margin-top: 0pt; margin-bottom: 0pt }" + "</style></head><body>");
    for (int i = 0; i < packages.size(); i++) {
        pkg = (DashPackage) packages.get(i);
        if (!pkg.updateAvailable)
            continue;
        String userURL = pkg.userURL;
        if (userURL == null || urlsSeen.contains(userURL))
            continue;
        urlsSeen.add(userURL);
        ArrayList updates = new ArrayList();
        updates.add(pkg.name);
        for (int j = i + 1; j < packages.size(); j++) {
            pkg = (DashPackage) packages.get(j);
            if (pkg.updateAvailable && userURL.equals(pkg.userURL))
                updates.add(pkg.name);
        }
        Collections.sort(updates, String.CASE_INSENSITIVE_ORDER);
        html.append("<p>");
        String hyperlink = "<a href=\"" + userURL + "\">" + HTMLUtils.escapeEntities(userURL) + "</a>";
        html.append(resources.format("Updates_Available_Message_FMT", hyperlink, new Integer(updates.size())));
        html.append("<ul>");
        Iterator u = updates.iterator();
        while (u.hasNext()) {
            String updateName = Translator.translate((String) u.next());
            html.append("<li>").append(HTMLUtils.escapeEntities(updateName));
        }
        html.append("</ul>");
    }
    JEditorPane message = new JEditorPane();
    message.setContentType("text/html");
    message.setEditable(false);
    message.setBackground(null);
    message.setText(html.toString());
    message.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                Browser.launch(e.getURL().toString());
        }
    });
    JCheckBox disable = new JCheckBox(resources.getString("Do_Not_Check_Label"));
    Object[] messageDisplay = new Object[2];
    messageDisplay[0] = message;
    messageDisplay[1] = disable;
    String[] updateOptions = { resources.getString("Remind_Label"), resources.getString("Close_Label") };
    int choice = JOptionPane.showOptionDialog(parent, messageDisplay, resources.getString("Updates_Available_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, updateOptions, updateOptions[0]);
    if (choice == 0)
        InternalSettings.set(AUTO_UPDATE_SETTING + REMIND, "true");
    if (disable.isSelected())
        InternalSettings.set(AUTO_UPDATE_SETTING + DISABLED, "true");
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) ArrayList(java.util.ArrayList) JCheckBox(javax.swing.JCheckBox) HyperlinkListener(javax.swing.event.HyperlinkListener) Iterator(java.util.Iterator) JEditorPane(javax.swing.JEditorPane) HashSet(java.util.HashSet)

Aggregations

HyperlinkListener (javax.swing.event.HyperlinkListener)33 HyperlinkEvent (javax.swing.event.HyperlinkEvent)31 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 Project (com.intellij.openapi.project.Project)5 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)4 File (java.io.File)4 IOException (java.io.IOException)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Ref (com.intellij.openapi.util.Ref)3 Logger (com.intellij.openapi.diagnostic.Logger)2 MessageType (com.intellij.openapi.ui.MessageType)2 Balloon (com.intellij.openapi.ui.popup.Balloon)2 Computable (com.intellij.openapi.util.Computable)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 IdeFrame (com.intellij.openapi.wm.IdeFrame)2 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)2 JBScrollPane (com.intellij.ui.components.JBScrollPane)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2