Search in sources :

Example 1 with HyperlinkListener

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

the class DesignerEditorPanel method addErrorMessage.

protected void addErrorMessage(final FixableMessageInfo message, Icon icon) {
    if (message.myLinkText.length() > 0 || message.myAfterLinkText.length() > 0) {
        HyperlinkLabel warnLabel = new HyperlinkLabel();
        warnLabel.setOpaque(false);
        warnLabel.setHyperlinkText(message.myBeforeLinkText, message.myLinkText, message.myAfterLinkText);
        warnLabel.setIcon(icon);
        if (message.myQuickFix != null) {
            warnLabel.addHyperlinkListener(new HyperlinkListener() {

                public void hyperlinkUpdate(final HyperlinkEvent e) {
                    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                        message.myQuickFix.run();
                    }
                }
            });
        }
        myErrorMessages.add(warnLabel);
    } else {
        JBLabel warnLabel = new JBLabel();
        warnLabel.setOpaque(false);
        warnLabel.setText("<html><body>" + message.myBeforeLinkText.replace("\n", "<br>") + "</body></html>");
        warnLabel.setIcon(icon);
        myErrorMessages.add(warnLabel);
    }
    if (message.myAdditionalFixes != null && message.myAdditionalFixes.size() > 0) {
        JPanel fixesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
        fixesPanel.setBorder(IdeBorderFactory.createEmptyBorder(3, 0, 10, 0));
        fixesPanel.setOpaque(false);
        fixesPanel.add(Box.createHorizontalStrut(icon.getIconWidth()));
        for (Pair<String, Runnable> pair : message.myAdditionalFixes) {
            HyperlinkLabel fixLabel = new HyperlinkLabel();
            fixLabel.setOpaque(false);
            fixLabel.setHyperlinkText(pair.getFirst());
            final Runnable fix = pair.getSecond();
            fixLabel.addHyperlinkListener(new HyperlinkListener() {

                @Override
                public void hyperlinkUpdate(HyperlinkEvent e) {
                    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                        fix.run();
                    }
                }
            });
            fixesPanel.add(fixLabel);
        }
        myErrorMessages.add(fixesPanel);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) HyperlinkListener(javax.swing.event.HyperlinkListener) JBLabel(com.intellij.ui.components.JBLabel) ThrowableRunnable(com.intellij.util.ThrowableRunnable) HyperlinkLabel(com.intellij.ui.HyperlinkLabel)

Example 2 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project pcgen by PCGen.

the class Initiative method addTab.

/**
	 * <p>
	 * Adds a tab to the {@code tpaneInfo} member. All methods adding
	 * character tabs to {@code tpaneInfo} should call this method to do
	 * so, as it provides a standard setup for the text panes and installs
	 * hyperlink listeners.
	 * </p>
	 *
	 * @param cbt Combatant to add.
	 */
void addTab(final Combatant cbt) {
    javax.swing.JTextPane lp = new javax.swing.JTextPane();
    lp.setContentType("text/html");
    InfoCharacterDetails ic = new InfoCharacterDetails(cbt, lp);
    tpaneInfo.addTab(cbt.getName(), ic.getScrollPane());
    lp.setEditable(false);
    lp.addHyperlinkListener(new HyperlinkListener() {

        private final Combatant combatant = cbt;

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            hyperLinkSelected(e, combatant);
        }
    });
}
Also used : InfoCharacterDetails(gmgen.plugin.InfoCharacterDetails) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) Combatant(gmgen.plugin.Combatant) PcgCombatant(gmgen.plugin.PcgCombatant) XMLCombatant(plugin.initiative.XMLCombatant)

Example 3 with HyperlinkListener

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

the class SceneBuilderEditor method createErrorPage.

private void createErrorPage() {
    myErrorLabel.setOpaque(false);
    myErrorLabel.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            updateState();
        }
    });
    myErrorStack = new JTextArea(50, 20);
    myErrorStack.setEditable(false);
    myErrorPanel.add(myErrorLabel, BorderLayout.NORTH);
    myErrorPanel.add(ScrollPaneFactory.createScrollPane(myErrorStack), BorderLayout.CENTER);
    myPanel.add(myErrorPanel);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 4 with HyperlinkListener

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

the class CopiesPanel method updateList.

private void updateList(@NotNull final List<WCInfo> infoList, @NotNull final List<WorkingCopyFormat> supportedFormats) {
    myPanel.removeAll();
    final Insets nullIndent = new Insets(1, 3, 1, 0);
    final GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 0, 0), 0, 0);
    gb.insets.left = 4;
    myPanel.add(myRefreshLabel, gb);
    gb.insets.left = 1;
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    final Insets topIndent = new Insets(10, 3, 0, 0);
    for (final WCInfo wcInfo : infoList) {
        final Collection<WorkingCopyFormat> upgradeFormats = getUpgradeFormats(wcInfo, supportedFormats);
        final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(wcInfo.getPath()));
        final VirtualFile root = (vf == null) ? wcInfo.getVcsRoot() : vf;
        final JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, "");
        editorPane.setEditable(false);
        editorPane.setFocusable(true);
        editorPane.setBackground(UIUtil.getPanelBackground());
        editorPane.setOpaque(false);
        editorPane.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    if (CONFIGURE_BRANCHES.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Configure Branches"))
                            return;
                        BranchConfigurationDialog.configureBranches(myProject, root);
                    } else if (FIX_DEPTH.equals(e.getDescription())) {
                        final int result = Messages.showOkCancelDialog(myVcs.getProject(), "You are going to checkout into '" + wcInfo.getPath() + "' with 'infinity' depth.\n" + "This will update your working copy to HEAD revision as well.", "Set Working Copy Infinity Depth", Messages.getWarningIcon());
                        if (result == Messages.OK) {
                            // update of view will be triggered by roots changed event
                            SvnCheckoutProvider.checkout(myVcs.getProject(), new File(wcInfo.getPath()), wcInfo.getRootUrl(), SVNRevision.HEAD, Depth.INFINITY, false, null, wcInfo.getFormat());
                        }
                    } else if (CHANGE_FORMAT.equals(e.getDescription())) {
                        changeFormat(wcInfo, upgradeFormats);
                    } else if (MERGE_FROM.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Merge From"))
                            return;
                        mergeFrom(wcInfo, root, editorPane);
                    } else if (CLEANUP.equals(e.getDescription())) {
                        if (!checkRoot(root, wcInfo.getPath(), " invoke Cleanup"))
                            return;
                        new CleanupWorker(myVcs, singletonList(root)).execute();
                    }
                }
            }

            private boolean checkRoot(VirtualFile root, final String path, final String actionName) {
                if (root == null) {
                    Messages.showWarningDialog(myProject, "Invalid working copy root: " + path, "Can not " + actionName);
                    return false;
                }
                return true;
            }
        });
        editorPane.setBorder(null);
        editorPane.setText(formatWc(wcInfo, upgradeFormats));
        final JPanel copyPanel = new JPanel(new GridBagLayout());
        final GridBagConstraints gb1 = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, nullIndent, 0, 0);
        gb1.insets.top = 1;
        gb1.gridwidth = 3;
        gb.insets = topIndent;
        gb.fill = GridBagConstraints.HORIZONTAL;
        ++gb.gridy;
        final JPanel contForCopy = new JPanel(new BorderLayout());
        contForCopy.add(copyPanel, BorderLayout.WEST);
        myPanel.add(contForCopy, gb);
        copyPanel.add(editorPane, gb1);
        gb1.insets = nullIndent;
    }
    myPanel.revalidate();
    myPanel.repaint();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) CleanupWorker(org.jetbrains.idea.svn.actions.CleanupWorker)

Example 5 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)

Aggregations

HyperlinkListener (javax.swing.event.HyperlinkListener)59 HyperlinkEvent (javax.swing.event.HyperlinkEvent)57 JEditorPane (javax.swing.JEditorPane)14 URL (java.net.URL)11 JScrollPane (javax.swing.JScrollPane)9 IOException (java.io.IOException)8 JTextPane (javax.swing.JTextPane)8 Dimension (java.awt.Dimension)7 JPanel (javax.swing.JPanel)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 URI (java.net.URI)6 NotNull (org.jetbrains.annotations.NotNull)6 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)5 ActionEvent (java.awt.event.ActionEvent)5 HTMLDocument (javax.swing.text.html.HTMLDocument)5 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)5 Project (com.intellij.openapi.project.Project)4 BorderLayout (java.awt.BorderLayout)4 JButton (javax.swing.JButton)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3