Search in sources :

Example 91 with HyperlinkEvent

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

the class EventLog method formatForLog.

public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
    DocumentImpl logDoc = new DocumentImpl("", true);
    AtomicBoolean showMore = new AtomicBoolean(false);
    Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
    List<RangeMarker> lineSeparators = new ArrayList<>();
    String title = notification.getTitle();
    String subtitle = notification.getSubtitle();
    if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
        title += " (" + subtitle + ")";
    }
    title = truncateLongString(showMore, title);
    String content = truncateLongString(showMore, notification.getContent());
    RangeMarker afterTitle = null;
    boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
    if (StringUtil.isNotEmpty(title)) {
        if (StringUtil.isNotEmpty(content)) {
            appendText(logDoc, ": ");
            afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
        }
    }
    int titleLength = logDoc.getTextLength();
    hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
    List<AnAction> actions = notification.getActions();
    if (!actions.isEmpty()) {
        String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {

            private int index;

            @Override
            public String fun(AnAction action) {
                return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
            }
        }, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
        Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
                Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
            }
        });
        if (title.length() > 0 || content.length() > 0) {
            lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
        }
        hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
    }
    String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
    indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
    ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
    for (RangeMarker marker : links.keySet()) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
    }
    if (showMore.get()) {
        String sb = "show balloon";
        if (!logDoc.getText().endsWith(" ")) {
            appendText(logDoc, " ");
        }
        appendText(logDoc, "(" + sb + ")");
        list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
    }
    return new LogEntry(logDoc.getText(), status, list, titleLength);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) RelativePoint(com.intellij.ui.awt.RelativePoint) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 92 with HyperlinkEvent

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

the class UnusedDeclarationPresentation method getCustomPreviewPanel.

@Override
public JComponent getCustomPreviewPanel(RefEntity entity) {
    final Project project = entity.getRefManager().getProject();
    JEditorPane htmlView = new JEditorPane() {

        @Override
        public String getToolTipText(MouseEvent evt) {
            int pos = viewToModel(evt.getPoint());
            if (pos >= 0) {
                HTMLDocument hdoc = (HTMLDocument) getDocument();
                javax.swing.text.Element e = hdoc.getCharacterElement(pos);
                AttributeSet a = e.getAttributes();
                SimpleAttributeSet value = (SimpleAttributeSet) a.getAttribute(HTML.Tag.A);
                if (value != null) {
                    String objectPackage = (String) value.getAttribute("qualifiedname");
                    if (objectPackage != null) {
                        return objectPackage;
                    }
                }
            }
            return null;
        }
    };
    htmlView.setContentType(UIUtil.HTML_MIME);
    htmlView.setEditable(false);
    htmlView.setOpaque(false);
    htmlView.setBackground(UIUtil.getLabelBackground());
    htmlView.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        protected void hyperlinkActivated(HyperlinkEvent e) {
            URL url = e.getURL();
            if (url == null) {
                return;
            }
            @NonNls String ref = url.getRef();
            int offset = Integer.parseInt(ref);
            String fileURL = url.toExternalForm();
            fileURL = fileURL.substring(0, fileURL.indexOf('#'));
            VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
            if (vFile == null) {
                vFile = VfsUtil.findFileByURL(url);
            }
            if (vFile != null) {
                final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, offset);
                FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
            }
        }
    });
    final StyleSheet css = ((HTMLEditorKit) htmlView.getEditorKit()).getStyleSheet();
    css.addRule("p.problem-description-group {text-indent: " + JBUI.scale(9) + "px;font-weight:bold;}");
    css.addRule("div.problem-description {margin-left: " + JBUI.scale(9) + "px;}");
    css.addRule("ul {margin-left:" + JBUI.scale(10) + "px;text-indent: 0}");
    css.addRule("code {font-family:" + UIUtil.getLabelFont().getFamily() + "}");
    final StringBuffer buf = new StringBuffer();
    getComposer().compose(buf, entity, false);
    final String text = buf.toString();
    SingleInspectionProfilePanel.readHTML(htmlView, SingleInspectionProfilePanel.toHTML(htmlView, text, false));
    return ScrollPaneFactory.createScrollPane(htmlView, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MouseEvent(java.awt.event.MouseEvent) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Project(com.intellij.openapi.project.Project) StyleSheet(javax.swing.text.html.StyleSheet) AttributeSet(javax.swing.text.AttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Example 93 with HyperlinkEvent

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

the class FileInEditorProcessor method processCode.

public void processCode() {
    if (myShouldOptimizeImports) {
        myProcessor = new OptimizeImportsProcessor(myProject, myFile);
    }
    if (myProcessChangesTextOnly && !FormatChangedTextUtil.hasChanges(myFile)) {
        myNoChangesDetected = true;
    }
    myProcessor = mixWithReformatProcessor(myProcessor);
    if (myShouldRearrangeCode) {
        myProcessor = mixWithRearrangeProcessor(myProcessor);
    }
    if (shouldNotify()) {
        myProcessor.setCollectInfo(true);
        myProcessor.setPostRunnable(() -> {
            String message = prepareMessage();
            if (!myEditor.isDisposed() && myEditor.getComponent().isShowing()) {
                HyperlinkListener hyperlinkListener = new HyperlinkAdapter() {

                    @Override
                    protected void hyperlinkActivated(HyperlinkEvent e) {
                        AnAction action = ActionManager.getInstance().getAction("ShowReformatFileDialog");
                        DataManager manager = DataManager.getInstance();
                        if (manager != null) {
                            DataContext context = manager.getDataContext(myEditor.getContentComponent());
                            action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", context));
                        }
                    }
                };
                showHint(myEditor, message, hyperlinkListener);
            }
        });
    }
    myProcessor.run();
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) DataManager(com.intellij.ide.DataManager) AnAction(com.intellij.openapi.actionSystem.AnAction) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Example 94 with HyperlinkEvent

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

the class DvcsBranchPopup method notifyAboutSyncedBranches.

private void notifyAboutSyncedBranches() {
    String description = "You have several " + myVcs.getDisplayName() + " roots in the project and they all are checked out at the same branch. " + "We've enabled synchronous branch control for the project. <br/>" + "If you wish to control branches in different roots separately, " + "you may <a href='settings'>disable</a> the setting.";
    NotificationListener listener = new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs.getConfigurable().getDisplayName());
                if (myVcsSettings.getSyncSetting() == DvcsSyncSettings.Value.DONT_SYNC) {
                    notification.expire();
                }
            }
        }
    };
    VcsNotifier.getInstance(myProject).notifyImportantInfo("Synchronous branch control enabled", description, listener);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 95 with HyperlinkEvent

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

the class IntentionDescriptionPanel method setupPoweredByPanel.

private void setupPoweredByPanel(final IntentionActionMetaData actionMetaData) {
    PluginId pluginId = actionMetaData == null ? null : actionMetaData.getPluginId();
    JComponent owner;
    if (pluginId == null) {
        @NonNls String label = XmlStringUtil.wrapInHtml("<b>" + ApplicationNamesInfo.getInstance().getFullProductName() + "</b>");
        owner = new JLabel(label);
    } else {
        final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
        HyperlinkLabel label = new HyperlinkLabel(CodeInsightBundle.message("powered.by.plugin", pluginDescriptor.getName()));
        label.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
                final PluginManagerConfigurable pluginConfigurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance());
                final Project project = ProjectManager.getInstance().getDefaultProject();
                util.editConfigurable(project, pluginConfigurable, () -> pluginConfigurable.select(pluginDescriptor));
            }
        });
        owner = label;
    }
    //myPoweredByContainer.setVisible(true);
    myPoweredByPanel.removeAll();
    myPoweredByPanel.add(owner, BorderLayout.CENTER);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ShowSettingsUtil(com.intellij.openapi.options.ShowSettingsUtil) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) PluginManagerConfigurable(com.intellij.ide.plugins.PluginManagerConfigurable) Project(com.intellij.openapi.project.Project) HyperlinkListener(javax.swing.event.HyperlinkListener) HyperlinkLabel(com.intellij.ui.HyperlinkLabel)

Aggregations

HyperlinkEvent (javax.swing.event.HyperlinkEvent)132 HyperlinkListener (javax.swing.event.HyperlinkListener)55 Notification (com.intellij.notification.Notification)41 NotificationListener (com.intellij.notification.NotificationListener)39 NotNull (org.jetbrains.annotations.NotNull)36 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)20 Project (com.intellij.openapi.project.Project)15 URL (java.net.URL)15 File (java.io.File)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)13 JEditorPane (javax.swing.JEditorPane)13 IOException (java.io.IOException)10 JPanel (javax.swing.JPanel)9 ActionEvent (java.awt.event.ActionEvent)8 JScrollPane (javax.swing.JScrollPane)8 JTextPane (javax.swing.JTextPane)8 URI (java.net.URI)7 HTMLDocument (javax.swing.text.html.HTMLDocument)7 Dimension (java.awt.Dimension)6