Search in sources :

Example 11 with HyperlinkListener

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

the class SwingHelper method createHtmlLabel.

public static JEditorPane createHtmlLabel(@NotNull final String innerHtml, @Nullable String disabledHtml, @Nullable final Consumer<String> hyperlinkListener) {
    disabledHtml = disabledHtml == null ? innerHtml : disabledHtml;
    final Font font = UIUtil.getLabelFont();
    String html = buildHtml(UIUtil.getCssFontDeclaration(font, UIUtil.getInactiveTextColor(), null, null), innerHtml);
    String disabled = buildHtml(UIUtil.getCssFontDeclaration(font, UIUtil.getInactiveTextColor(), null, null), disabledHtml);
    final JEditorPane pane = new SwingHelper.HtmlViewerBuilder().setCarryTextOver(false).setFont(UIUtil.getLabelFont()).setDisabledHtml(disabled).create();
    pane.setText(html);
    pane.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (hyperlinkListener != null)
                    hyperlinkListener.consume(e.getURL() == null ? "" : e.getURL().toString());
                else
                    BrowserUtil.browse(e.getURL());
            }
        }
    });
    return pane;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 12 with HyperlinkListener

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

the class LineTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
    if (myText == null)
        return null;
    //setup text
    myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
    final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
    final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    final JComponent contentComponent = editor.getContentComponent();
    final JComponent editorComponent = editor.getComponent();
    if (!editorComponent.isShowing())
        return null;
    final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
    hintHint.setContentActive(isActiveHtml(myText));
    if (!hintHint.isAwtTooltip()) {
        correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
    }
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
    scrollPane.setBorder(null);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.setBackground(hintHint.getTextBackground());
    scrollPane.getViewport().setBackground(hintHint.getTextBackground());
    scrollPane.setViewportBorder(null);
    if (hintHint.isRequestFocus()) {
        pane.setFocusable(true);
    }
    final Ref<AnAction> actionRef = new Ref<>();
    final LightweightHint hint = new LightweightHint(scrollPane) {

        @Override
        public void hide() {
            onHide(pane);
            super.hide();
            final AnAction action = actionRef.get();
            if (action != null) {
                action.unregisterCustomShortcutSet(contentComponent);
            }
        }
    };
    actionRef.set(new AnAction() {

        // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
        {
            registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
            hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
            expand(hint, editor, p, pane, alignToRight, group, hintHint);
        }
    });
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            myActiveLink = true;
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                myActiveLink = false;
                return;
            }
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final URL url = e.getURL();
                if (url != null) {
                    BrowserUtil.browse(url);
                    hint.hide();
                    return;
                }
                final String description = e.getDescription();
                if (description != null && handle(description, editor)) {
                    hint.hide();
                    return;
                }
                if (!expanded) {
                    expand(hint, editor, p, pane, alignToRight, group, hintHint);
                } else {
                    stripDescription();
                    hint.hide();
                    TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
                }
            }
        }
    });
    // This listener makes hint transparent for mouse events. It means that hint is closed
    // by MousePressed and this MousePressed goes into the underlying editor component.
    pane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!myActiveLink) {
                MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
                hint.hide();
                contentComponent.dispatchEvent(newMouseEvent);
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            if (!expanded) {
                hint.hide();
            }
        }
    });
    hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    return hint;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Html(com.intellij.util.ui.Html) LightweightHint(com.intellij.ui.LightweightHint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) URL(java.net.URL) KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 13 with HyperlinkListener

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

the class IdeErrorsDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    DefaultActionGroup goBack = new DefaultActionGroup();
    BackAction back = new BackAction();
    goBack.add(back);
    ActionToolbar backToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, goBack, true);
    backToolbar.getComponent().setBorder(IdeBorderFactory.createEmptyBorder());
    backToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    myBackButtonPanel.add(backToolbar.getComponent(), BorderLayout.CENTER);
    DefaultActionGroup goForward = new DefaultActionGroup();
    ForwardAction forward = new ForwardAction();
    goForward.add(forward);
    ActionToolbar forwardToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, goForward, true);
    forwardToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    forwardToolbar.getComponent().setBorder(IdeBorderFactory.createEmptyBorder());
    myNextButtonPanel.add(forwardToolbar.getComponent(), BorderLayout.CENTER);
    myTabs = new HeaderlessTabbedPane(getDisposable());
    final LabeledTextComponent.TextListener commentsListener = new LabeledTextComponent.TextListener() {

        @Override
        public void textChanged(String newText) {
            if (myMute) {
                return;
            }
            AbstractMessage message = getSelectedMessage();
            if (message != null) {
                message.setAdditionalInfo(newText);
            }
        }
    };
    if (!myInternalMode) {
        myDetailsTabForm = new DetailsTabForm(null, false);
        myCommentsTabForm = new CommentsTabForm();
        myCommentsTabForm.addCommentsListener(commentsListener);
        myTabs.addTab(DiagnosticBundle.message("error.comments.tab.title"), myCommentsTabForm.getContentPane());
        myDetailsTabForm.setCommentsAreaVisible(false);
    } else {
        final AnAction analyzePlatformAction = ActionManager.getInstance().getAction("AnalyzeStacktraceOnError");
        if (analyzePlatformAction != null) {
            myAnalyzeAction = new AnalyzeAction(analyzePlatformAction);
        }
        myDetailsTabForm = new DetailsTabForm(myAnalyzeAction, true);
        myDetailsTabForm.setCommentsAreaVisible(true);
        myDetailsTabForm.addCommentsListener(commentsListener);
    }
    myTabs.addTab(DiagnosticBundle.message("error.details.tab.title"), myDetailsTabForm.getContentPane());
    myAttachmentsTabForm = new AttachmentsTabForm();
    myAttachmentsTabForm.addInclusionListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            updateAttachmentWarning(getSelectedMessage());
        }
    });
    int activeTabIndex = Integer.parseInt(PropertiesComponent.getInstance().getValue(ACTIVE_TAB_OPTION, "0"));
    if (activeTabIndex >= myTabs.getTabCount() || activeTabIndex < 0) {
        // may happen if myInternalMode changed since last open
        activeTabIndex = 0;
    }
    myTabs.setSelectedIndex(activeTabIndex);
    myTabs.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            final JComponent c = getPreferredFocusedComponent();
            if (c != null) {
                IdeFocusManager.findInstanceByComponent(myContentPane).requestFocus(c, true);
            }
        }
    });
    myTabsPanel.add(myTabs, BorderLayout.CENTER);
    myDisableLink.setHyperlinkText(UIUtil.removeMnemonic(DiagnosticBundle.message("error.list.disable.plugin")));
    myDisableLink.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                disablePlugin();
            }
        }
    });
    myCredentialsLabel.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JetBrainsAccountDialogKt.showJetBrainsAccountDialog(getRootPane()).show();
                updateCredentialsPane(getSelectedMessage());
            }
        }
    });
    myAttachmentWarningLabel.setIcon(UIUtil.getBalloonWarningIcon());
    myAttachmentWarningLabel.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                myTabs.setSelectedIndex(myTabs.indexOfComponent(myAttachmentsTabForm.getContentPane()));
                myAttachmentsTabForm.selectFirstIncludedAttachment();
            }
        }
    });
    myDetailsTabForm.addAssigneeListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (myMute)
                return;
            AbstractMessage message = getSelectedMessage();
            if (message != null) {
                message.setAssigneeId(myDetailsTabForm.getAssigneeId());
            }
        }
    });
    return myContentPane;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) ActionEvent(java.awt.event.ActionEvent) HeaderlessTabbedPane(com.intellij.ui.HeaderlessTabbedPane) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) HyperlinkListener(javax.swing.event.HyperlinkListener) ChangeListener(javax.swing.event.ChangeListener)

Example 14 with HyperlinkListener

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

the class NotificationsManagerImpl method showNotification.

private static void showNotification(@NotNull final Notification notification, @Nullable final Project project) {
    Application application = ApplicationManager.getApplication();
    if (application instanceof ApplicationEx && !((ApplicationEx) application).isLoaded()) {
        application.invokeLater(() -> showNotification(notification, project), ModalityState.current());
        return;
    }
    String groupId = notification.getGroupId();
    final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(groupId);
    NotificationDisplayType type = settings.getDisplayType();
    String toolWindowId = NotificationsConfigurationImpl.getInstanceImpl().getToolWindowId(groupId);
    if (type == NotificationDisplayType.TOOL_WINDOW && (toolWindowId == null || project == null || !ToolWindowManager.getInstance(project).canShowNotification(toolWindowId))) {
        type = NotificationDisplayType.BALLOON;
    }
    switch(type) {
        case NONE:
            return;
        //  break;
        case STICKY_BALLOON:
        case BALLOON:
        default:
            Balloon balloon = notifyByBalloon(notification, type, project);
            if (project == null || project.isDefault()) {
                return;
            }
            if (!settings.isShouldLog() || type == NotificationDisplayType.STICKY_BALLOON) {
                if (balloon == null) {
                    notification.expire();
                } else {
                    balloon.addListener(new JBPopupAdapter() {

                        @Override
                        public void onClosed(LightweightWindowEvent event) {
                            if (!event.isOk()) {
                                notification.expire();
                            }
                        }
                    });
                }
            }
            break;
        case TOOL_WINDOW:
            MessageType messageType = notification.getType() == NotificationType.ERROR ? MessageType.ERROR : notification.getType() == NotificationType.WARNING ? MessageType.WARNING : MessageType.INFO;
            final NotificationListener notificationListener = notification.getListener();
            HyperlinkListener listener = notificationListener == null ? null : new HyperlinkListener() {

                @Override
                public void hyperlinkUpdate(HyperlinkEvent e) {
                    notificationListener.hyperlinkUpdate(notification, e);
                }
            };
            assert toolWindowId != null;
            String msg = notification.getTitle();
            if (StringUtil.isNotEmpty(notification.getContent())) {
                if (StringUtil.isNotEmpty(msg)) {
                    msg += "<br>";
                }
                msg += notification.getContent();
            }
            Window window = findWindowForBalloon(project);
            if (window instanceof IdeFrame) {
                BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
                if (layout != null) {
                    ((BalloonLayoutImpl) layout).remove(notification);
                }
            }
            //noinspection SSBasedInspection
            ToolWindowManager.getInstance(project).notifyByBalloon(toolWindowId, messageType, msg, notification.getIcon(), listener);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) IdeFrame(com.intellij.openapi.wm.IdeFrame) WelcomeBalloonLayoutImpl(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeBalloonLayoutImpl) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) HyperlinkListener(javax.swing.event.HyperlinkListener) Application(com.intellij.openapi.application.Application) MessageType(com.intellij.openapi.ui.MessageType)

Example 15 with HyperlinkListener

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

the class TipUIUtil method createTipBrowser.

@NotNull
public static JEditorPane createTipBrowser() {
    JEditorPane browser = new JEditorPane();
    browser.setEditable(false);
    browser.setBackground(UIUtil.getTextFieldBackground());
    browser.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(e.getURL());
            }
        }
    });
    URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
    final StyleSheet styleSheet = UIUtil.loadStyleSheet(resource);
    HTMLEditorKit kit = new HTMLEditorKit() {

        @Override
        public StyleSheet getStyleSheet() {
            return styleSheet != null ? styleSheet : super.getStyleSheet();
        }
    };
    browser.setEditorKit(kit);
    return browser;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) StyleSheet(javax.swing.text.html.StyleSheet) HyperlinkListener(javax.swing.event.HyperlinkListener) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) NotNull(org.jetbrains.annotations.NotNull)

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