Search in sources :

Example 26 with HyperlinkListener

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

the class NotificationsManagerImpl method createBalloon.

@NotNull
public static Balloon createBalloon(@Nullable final JComponent windowComponent, @NotNull final Notification notification, final boolean showCallout, final boolean hideOnClickOutside, @NotNull Ref<BalloonLayoutData> layoutDataRef, @NotNull Disposable parentDisposable) {
    final BalloonLayoutData layoutData = layoutDataRef.isNull() ? new BalloonLayoutData() : layoutDataRef.get();
    if (layoutData.groupId == null) {
        if (NotificationsConfigurationImpl.getSettings(notification.getGroupId()).isShouldLog()) {
            layoutData.groupId = notification.getGroupId();
            layoutData.id = notification.id;
        }
    } else {
        layoutData.groupId = null;
        layoutData.mergeData = null;
    }
    layoutDataRef.set(layoutData);
    if (layoutData.fillColor == null) {
        layoutData.fillColor = FILL_COLOR;
    }
    if (layoutData.borderColor == null) {
        layoutData.borderColor = BORDER_COLOR;
    }
    boolean actions = !notification.getActions().isEmpty();
    boolean showFullContent = layoutData.showFullContent || notification instanceof NotificationActionProvider;
    Color foregroundR = Gray._0;
    Color foregroundD = Gray._191;
    final Color foreground = new JBColor(foregroundR, foregroundD);
    final JEditorPane text = new JEditorPane() {

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            if (layoutData.showMinSize) {
                Point location = getCollapsedTextEndLocation(this, layoutData);
                if (location != null) {
                    g.setColor(getForeground());
                    g.drawString("...", location.x, location.y + g.getFontMetrics().getAscent());
                }
            }
        }
    };
    text.setEditorKit(new HTMLEditorKit() {

        final HTMLEditorKit kit = UIUtil.getHTMLEditorKit();

        final HTMLFactory factory = new HTMLFactory() {

            public View create(Element e) {
                View view = super.create(e);
                if (view instanceof ParagraphView) {
                    // wrap too long words, for example: ATEST_TABLE_SIGNLE_ROW_UPDATE_AUTOCOMMIT_A_FIK
                    return new ParagraphView(e) {

                        protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
                            if (r == null) {
                                r = new SizeRequirements();
                            }
                            r.minimum = (int) layoutPool.getMinimumSpan(axis);
                            r.preferred = Math.max(r.minimum, (int) layoutPool.getPreferredSpan(axis));
                            r.maximum = Integer.MAX_VALUE;
                            r.alignment = 0.5f;
                            return r;
                        }
                    };
                }
                return view;
            }
        };

        @Override
        public StyleSheet getStyleSheet() {
            return kit.getStyleSheet();
        }

        @Override
        public ViewFactory getViewFactory() {
            return factory;
        }
    });
    text.setForeground(foreground);
    final HyperlinkListener listener = NotificationsUtil.wrapListener(notification);
    if (listener != null) {
        text.addHyperlinkListener(listener);
    }
    String fontStyle = NotificationsUtil.getFontStyle();
    int prefSize = new JLabel(NotificationsUtil.buildHtml(notification, null, true, null, fontStyle)).getPreferredSize().width;
    String style = prefSize > BalloonLayoutConfiguration.MaxWidth ? BalloonLayoutConfiguration.MaxWidthStyle : null;
    if (layoutData.showFullContent) {
        style = prefSize > BalloonLayoutConfiguration.MaxFullContentWidth ? BalloonLayoutConfiguration.MaxFullContentWidthStyle : null;
    }
    String textR = NotificationsUtil.buildHtml(notification, style, true, foregroundR, fontStyle);
    String textD = NotificationsUtil.buildHtml(notification, style, true, foregroundD, fontStyle);
    LafHandler lafHandler = new LafHandler(text, textR, textD);
    layoutData.lafHandler = lafHandler;
    text.setEditable(false);
    text.setOpaque(false);
    if (UIUtil.isUnderNimbusLookAndFeel()) {
        text.setBackground(UIUtil.TRANSPARENT_COLOR);
    }
    text.setBorder(null);
    final JPanel content = new NonOpaquePanel(new BorderLayout());
    if (text.getCaret() != null) {
        text.setCaretPosition(0);
    }
    final JScrollPane pane = createBalloonScrollPane(text, false);
    pane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            JScrollBar scrollBar = pane.getVerticalScrollBar();
            if (layoutData.showMinSize && scrollBar.getValue() > 0) {
                scrollBar.removeAdjustmentListener(this);
                scrollBar.setValue(0);
                scrollBar.addAdjustmentListener(this);
            }
        }
    });
    LinkLabel<Void> expandAction = null;
    int lines = 3;
    if (notification.hasTitle()) {
        lines--;
    }
    if (actions) {
        lines--;
    }
    layoutData.fullHeight = text.getPreferredSize().height;
    layoutData.twoLineHeight = calculateContentHeight(lines);
    layoutData.maxScrollHeight = Math.min(layoutData.fullHeight, calculateContentHeight(10));
    layoutData.configuration = BalloonLayoutConfiguration.create(notification, layoutData, actions);
    if (layoutData.welcomeScreen) {
        layoutData.maxScrollHeight = layoutData.fullHeight;
    } else if (!showFullContent && layoutData.maxScrollHeight != layoutData.fullHeight) {
        pane.setViewport(new GradientViewport(text, JBUI.insets(10, 0), true) {

            @Nullable
            @Override
            protected Color getViewColor() {
                return layoutData.fillColor;
            }

            @Override
            protected void paintGradient(Graphics g) {
                if (!layoutData.showMinSize) {
                    super.paintGradient(g);
                }
            }
        });
    }
    configureBalloonScrollPane(pane, layoutData.fillColor);
    if (showFullContent) {
        pane.setPreferredSize(text.getPreferredSize());
    } else if (layoutData.twoLineHeight < layoutData.fullHeight) {
        text.setPreferredSize(null);
        Dimension size = text.getPreferredSize();
        size.height = layoutData.twoLineHeight;
        text.setPreferredSize(size);
        text.setSize(size);
        layoutData.showMinSize = true;
        pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        pane.setPreferredSize(size);
        text.setCaret(new TextCaret(layoutData));
        expandAction = new LinkLabel<>(null, AllIcons.Ide.Notification.Expand, new LinkListener<Void>() {

            @Override
            public void linkSelected(LinkLabel link, Void ignored) {
                layoutData.showMinSize = !layoutData.showMinSize;
                text.setPreferredSize(null);
                Dimension size = text.getPreferredSize();
                if (layoutData.showMinSize) {
                    size.height = layoutData.twoLineHeight;
                    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
                    link.setIcon(AllIcons.Ide.Notification.Expand);
                    link.setHoveringIcon(AllIcons.Ide.Notification.ExpandHover);
                } else {
                    text.select(0, 0);
                    size.height = layoutData.fullHeight;
                    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                    link.setIcon(AllIcons.Ide.Notification.Collapse);
                    link.setHoveringIcon(AllIcons.Ide.Notification.CollapseHover);
                }
                text.setPreferredSize(size);
                text.setSize(size);
                if (!layoutData.showMinSize) {
                    size = new Dimension(size.width, layoutData.maxScrollHeight);
                }
                pane.setPreferredSize(size);
                content.doLayout();
                layoutData.doLayout.run();
            }
        });
        expandAction.setHoveringIcon(AllIcons.Ide.Notification.ExpandHover);
    }
    final CenteredLayoutWithActions layout = new CenteredLayoutWithActions(text, layoutData);
    JPanel centerPanel = new NonOpaquePanel(layout) {

        @Override
        protected void paintChildren(Graphics g) {
            super.paintChildren(g);
            Component title = layout.getTitle();
            if (title != null && layoutData.showActions != null && layoutData.showActions.compute()) {
                int width = layoutData.configuration.allActionsOffset;
                int x = getWidth() - width - JBUI.scale(5);
                int y = layoutData.configuration.topSpaceHeight;
                int height = title instanceof JEditorPane ? getFirstLineHeight((JEditorPane) title) : title.getHeight();
                g.setColor(layoutData.fillColor);
                g.fillRect(x, y, width, height);
                width = layoutData.configuration.beforeGearSpace;
                x -= width;
                ((Graphics2D) g).setPaint(new GradientPaint(x, y, ColorUtil.withAlpha(layoutData.fillColor, 0.2), x + width, y, layoutData.fillColor));
                g.fillRect(x, y, width, height);
            }
        }
    };
    content.add(centerPanel, BorderLayout.CENTER);
    if (notification.hasTitle()) {
        String titleStyle = StringUtil.defaultIfEmpty(fontStyle, "") + "white-space:nowrap;";
        String titleR = NotificationsUtil.buildHtml(notification, titleStyle, false, foregroundR, null);
        String titleD = NotificationsUtil.buildHtml(notification, titleStyle, false, foregroundD, null);
        JLabel title = new JLabel();
        lafHandler.setTitle(title, titleR, titleD);
        title.setOpaque(false);
        if (UIUtil.isUnderNimbusLookAndFeel()) {
            title.setBackground(UIUtil.TRANSPARENT_COLOR);
        }
        title.setForeground(foreground);
        centerPanel.add(title, BorderLayout.NORTH);
    }
    if (expandAction != null) {
        centerPanel.add(expandAction, BorderLayout.EAST);
    }
    if (notification.hasContent()) {
        centerPanel.add(layoutData.welcomeScreen ? text : pane, BorderLayout.CENTER);
    }
    if (!layoutData.welcomeScreen) {
        final Icon icon = NotificationsUtil.getIcon(notification);
        JComponent iconComponent = new JComponent() {

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                icon.paintIcon(this, g, layoutData.configuration.iconOffset.width, layoutData.configuration.iconOffset.height);
            }
        };
        iconComponent.setOpaque(false);
        iconComponent.setPreferredSize(new Dimension(layoutData.configuration.iconPanelWidth, 2 * layoutData.configuration.iconOffset.height + icon.getIconHeight()));
        content.add(iconComponent, BorderLayout.WEST);
    }
    JPanel buttons = createButtons(notification, content, listener);
    if (buttons != null) {
        layoutData.groupId = null;
        layoutData.mergeData = null;
        buttons.setBorder(new EmptyBorder(0, 0, JBUI.scale(5), JBUI.scale(7)));
    }
    HoverAdapter hoverAdapter = new HoverAdapter();
    hoverAdapter.addSource(content);
    hoverAdapter.addSource(centerPanel);
    hoverAdapter.addSource(text);
    hoverAdapter.addSource(pane);
    if (buttons == null && actions) {
        createActionPanel(notification, centerPanel, layoutData.configuration.actionGap, hoverAdapter);
    }
    if (expandAction != null) {
        hoverAdapter.addComponent(expandAction, component -> {
            Rectangle bounds;
            Point location = SwingUtilities.convertPoint(content.getParent(), content.getLocation(), component.getParent());
            if (layoutData.showMinSize) {
                Component centerComponent = layoutData.welcomeScreen ? text : pane;
                Point centerLocation = SwingUtilities.convertPoint(centerComponent.getParent(), centerComponent.getLocation(), component.getParent());
                bounds = new Rectangle(location.x, centerLocation.y, content.getWidth(), centerComponent.getHeight());
            } else {
                bounds = new Rectangle(location.x, component.getY(), content.getWidth(), component.getHeight());
                JBInsets.addTo(bounds, JBUI.insets(5, 0, 7, 0));
            }
            return bounds;
        });
    }
    hoverAdapter.initListeners();
    if (layoutData.mergeData != null) {
        createMergeAction(layoutData, content);
    }
    text.setSize(text.getPreferredSize());
    Dimension paneSize = new Dimension(text.getPreferredSize());
    int maxWidth = JBUI.scale(600);
    if (windowComponent != null) {
        maxWidth = Math.min(maxWidth, windowComponent.getWidth() - 20);
    }
    if (paneSize.width > maxWidth) {
        pane.setPreferredSize(new Dimension(maxWidth, paneSize.height + UIUtil.getScrollBarWidth()));
    }
    final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(content);
    builder.setFillColor(layoutData.fillColor).setCloseButtonEnabled(buttons == null).setShowCallout(showCallout).setShadow(false).setAnimationCycle(200).setHideOnClickOutside(hideOnClickOutside).setHideOnAction(hideOnClickOutside).setHideOnKeyOutside(hideOnClickOutside).setHideOnFrameResize(false).setBorderColor(layoutData.borderColor).setBorderInsets(JBUI.emptyInsets());
    if (layoutData.fadeoutTime != 0) {
        builder.setFadeoutTime(layoutData.fadeoutTime);
    }
    final BalloonImpl balloon = (BalloonImpl) builder.createBalloon();
    balloon.setAnimationEnabled(false);
    notification.setBalloon(balloon);
    balloon.setShadowBorderProvider(new NotificationBalloonShadowBorderProvider(layoutData.fillColor, layoutData.borderColor));
    if (!layoutData.welcomeScreen && buttons == null) {
        balloon.setActionProvider(new NotificationBalloonActionProvider(balloon, layout.getTitle(), layoutData, notification.getGroupId()));
    }
    Disposer.register(parentDisposable, balloon);
    return balloon;
}
Also used : NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) HyperlinkListener(javax.swing.event.HyperlinkListener) EmptyBorder(javax.swing.border.EmptyBorder) GradientViewport(com.intellij.ui.components.GradientViewport) ParagraphView(javax.swing.text.html.ParagraphView) ParagraphView(javax.swing.text.html.ParagraphView) LinkLabel(com.intellij.ui.components.labels.LinkLabel) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with HyperlinkListener

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

the class SheetController method createSheetPanel.

private JPanel createSheetPanel(String title, String message, JButton[] buttons) {
    JPanel sheetPanel = new JPanel() {

        @Override
        protected void paintComponent(@NotNull Graphics g2d) {
            final Graphics2D g = (Graphics2D) g2d.create();
            super.paintComponent(g);
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getSheetAlpha()));
            g.setColor(new JBColor(Gray._230, UIUtil.getPanelBackground()));
            Rectangle2D dialog = new Rectangle2D.Double(SHADOW_BORDER, 0, SHEET_WIDTH, SHEET_HEIGHT);
            paintShadow(g);
            // draw the sheet background
            if (UIUtil.isUnderDarcula()) {
                g.fillRoundRect((int) dialog.getX(), (int) dialog.getY() - 5, (int) dialog.getWidth(), (int) (5 + dialog.getHeight()), 5, 5);
            } else {
                //todo make bottom corners
                g.fill(dialog);
            }
            paintShadowFromParent(g);
        }
    };
    sheetPanel.setOpaque(false);
    sheetPanel.setLayout(null);
    JPanel ico = new JPanel() {

        @Override
        protected void paintComponent(@NotNull Graphics g) {
            super.paintComponent(g);
            myIcon.paintIcon(this, g, 0, 0);
        }
    };
    JEditorPane headerLabel = new JEditorPane();
    headerLabel.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    headerLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    headerLabel.setEditable(false);
    headerLabel.setContentType("text/html");
    headerLabel.setSize(250, Short.MAX_VALUE);
    headerLabel.setText(title);
    headerLabel.setSize(250, headerLabel.getPreferredSize().height);
    headerLabel.setOpaque(false);
    headerLabel.setFocusable(false);
    sheetPanel.add(headerLabel);
    headerLabel.repaint();
    messageTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    Font font = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
    messageTextPane.setFont(font);
    messageTextPane.setEditable(false);
    messageTextPane.setContentType("text/html");
    messageTextPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        URL url = he.getURL();
                        if (url != null) {
                            Desktop.getDesktop().browse(url.toURI());
                        } else {
                            LOG.warn("URL is null; HyperlinkEvent: " + he.toString());
                        }
                    } catch (IOException | URISyntaxException e) {
                        LOG.error(e);
                    }
                }
            }
        }
    });
    FontMetrics fontMetrics = sheetPanel.getFontMetrics(font);
    int widestWordWidth = 250;
    String[] words = (message == null) ? ArrayUtil.EMPTY_STRING_ARRAY : message.split(SPACE_OR_LINE_SEPARATOR_PATTERN);
    for (String word : words) {
        widestWordWidth = Math.max(fontMetrics.stringWidth(word), widestWordWidth);
    }
    messageTextPane.setSize(widestWordWidth, Short.MAX_VALUE);
    messageTextPane.setText(handleBreaks(message));
    messageArea.setSize(widestWordWidth, messageTextPane.getPreferredSize().height);
    SHEET_WIDTH = Math.max(LEFT_SHEET_OFFSET + widestWordWidth + RIGHT_OFFSET, SHEET_WIDTH);
    messageTextPane.setSize(messageArea);
    messageTextPane.setOpaque(false);
    messageTextPane.setFocusable(false);
    sheetPanel.add(messageTextPane);
    messageTextPane.repaint();
    ico.setOpaque(false);
    ico.setSize(new Dimension(AllIcons.Logo_welcomeScreen.getIconWidth(), AllIcons.Logo_welcomeScreen.getIconHeight()));
    ico.setLocation(LEFT_SHEET_PADDING, TOP_SHEET_PADDING);
    sheetPanel.add(ico);
    headerLabel.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING);
    messageTextPane.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES);
    SHEET_HEIGHT = TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES + messageArea.height + GAP_BETWEEN_LINES;
    if (myDoNotAskOption != null) {
        layoutDoNotAskCheckbox(sheetPanel);
    }
    layoutWithAbsoluteLayout(buttons, sheetPanel);
    int BOTTOM_SHEET_PADDING = 10;
    SHEET_HEIGHT += BOTTOM_SHEET_PADDING;
    if (SHEET_HEIGHT < SHEET_MINIMUM_HEIGHT) {
        SHEET_HEIGHT = SHEET_MINIMUM_HEIGHT;
        shiftButtonsToTheBottom(SHEET_MINIMUM_HEIGHT - SHEET_HEIGHT);
    }
    sheetPanel.setFocusCycleRoot(true);
    recalculateShadow();
    sheetPanel.setSize(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);
    return sheetPanel;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Rectangle2D(java.awt.geom.Rectangle2D) NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) HyperlinkListener(javax.swing.event.HyperlinkListener) JBColor(com.intellij.ui.JBColor)

Example 28 with HyperlinkListener

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

the class ExportTestResultsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    final ExportTestResultsConfiguration config = ExportTestResultsConfiguration.getInstance(project);
    final String name = ExecutionBundle.message("export.test.results.filename", PathUtil.suggestFileName(myRunConfiguration.getName()));
    String filename = name + "." + config.getExportFormat().getDefaultExtension();
    boolean showDialog = true;
    while (showDialog) {
        final ExportTestResultsDialog d = new ExportTestResultsDialog(project, config, filename);
        if (!d.showAndGet()) {
            return;
        }
        filename = d.getFileName();
        showDialog = getOutputFile(config, project, filename).exists() && Messages.showOkCancelDialog(project, ExecutionBundle.message("export.test.results.file.exists.message", filename), ExecutionBundle.message("export.test.results.file.exists.title"), Messages.getQuestionIcon()) != Messages.OK;
    }
    final String filename_ = filename;
    ProgressManager.getInstance().run(new Task.Backgroundable(project, ExecutionBundle.message("export.test.results.task.name"), false, new PerformInBackgroundOption() {

        @Override
        public boolean shouldStartInBackground() {
            return true;
        }

        @Override
        public void processSentToBackground() {
        }
    }) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            final File outputFile = getOutputFile(config, project, filename_);
            final String outputText;
            try {
                outputText = getOutputText(config);
                if (outputText == null) {
                    return;
                }
            } catch (IOException | SAXException | TransformerException ex) {
                LOG.warn(ex);
                showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null);
                return;
            } catch (RuntimeException ex) {
                ExportTestResultsConfiguration c = new ExportTestResultsConfiguration();
                c.setExportFormat(ExportTestResultsConfiguration.ExportFormat.Xml);
                c.setOpenResults(false);
                try {
                    String xml = getOutputText(c);
                    LOG.error(LogMessageEx.createEvent("Failed to export test results", ExceptionUtil.getThrowableText(ex), null, null, new Attachment("dump.xml", xml)));
                } catch (Throwable ignored) {
                    LOG.error("Failed to export test results", ex);
                }
                return;
            }
            final Ref<VirtualFile> result = new Ref<>();
            final Ref<String> error = new Ref<>();
            ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    result.set(ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {

                        @Override
                        public VirtualFile compute() {
                            outputFile.getParentFile().mkdirs();
                            final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(outputFile.getParentFile());
                            if (parent == null || !parent.isValid()) {
                                error.set(ExecutionBundle.message("failed.to.create.output.file", outputFile.getPath()));
                                return null;
                            }
                            try {
                                VirtualFile result = parent.findChild(outputFile.getName());
                                if (result == null) {
                                    result = parent.createChildData(this, outputFile.getName());
                                }
                                VfsUtil.saveText(result, outputText);
                                return result;
                            } catch (IOException e) {
                                LOG.warn(e);
                                error.set(e.getMessage());
                                return null;
                            }
                        }
                    }));
                }
            });
            if (!result.isNull()) {
                if (config.isOpenResults()) {
                    openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
                } else {
                    HyperlinkListener listener = new HyperlinkListener() {

                        @Override
                        public void hyperlinkUpdate(HyperlinkEvent e) {
                            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
                            }
                        }
                    };
                    showBalloon(project, MessageType.INFO, ExecutionBundle.message("export.test.results.succeeded", outputFile.getName()), listener);
                }
            } else {
                showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", error.get()), null);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Attachment(com.intellij.openapi.diagnostic.Attachment) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Computable(com.intellij.openapi.util.Computable)

Example 29 with HyperlinkListener

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

the class RenameProcessor method performRefactoring.

@Override
public void performRefactoring(@NotNull UsageInfo[] usages) {
    List<Runnable> postRenameCallbacks = new ArrayList<>();
    final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);
    for (final PsiElement element : myAllRenames.keySet()) {
        String newName = myAllRenames.get(element);
        final RefactoringElementListener elementListener = getTransaction().getElementListener(element);
        final RenamePsiElementProcessor renamePsiElementProcessor = RenamePsiElementProcessor.forElement(element);
        Runnable postRenameCallback = renamePsiElementProcessor.getPostRenameCallback(element, newName, elementListener);
        final Collection<UsageInfo> infos = classified.get(element);
        try {
            RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject, elementListener);
        } catch (final IncorrectOperationException e) {
            RenameUtil.showErrorMessage(e, element, myProject);
            return;
        }
        if (postRenameCallback != null) {
            postRenameCallbacks.add(postRenameCallback);
        }
    }
    for (Runnable runnable : postRenameCallbacks) {
        runnable.run();
    }
    List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
    for (UsageInfo usage : usages) {
        if (usage instanceof NonCodeUsageInfo) {
            nonCodeUsages.add((NonCodeUsageInfo) usage);
        }
    }
    myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
    if (!mySkippedUsages.isEmpty()) {
        if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
            ApplicationManager.getApplication().invokeLater(() -> {
                final IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(myProject);
                if (ideFrame != null) {
                    StatusBarEx statusBar = (StatusBarEx) ideFrame.getStatusBar();
                    HyperlinkListener listener = new HyperlinkListener() {

                        @Override
                        public void hyperlinkUpdate(HyperlinkEvent e) {
                            if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
                                return;
                            Messages.showMessageDialog("<html>Following usages were safely skipped:<br>" + StringUtil.join(mySkippedUsages, unresolvableCollisionUsageInfo -> unresolvableCollisionUsageInfo.getDescription(), "<br>") + "</html>", "Not All Usages Were Renamed", null);
                        }
                    };
                    statusBar.notifyProgressByBalloon(MessageType.WARNING, "<html><body>Unable to rename certain usages. <a href=\"\">Browse</a></body></html>", null, listener);
                }
            }, ModalityState.NON_MODAL);
        }
    }
}
Also used : DescriptiveNameUtil(com.intellij.lang.findUsages.DescriptiveNameUtil) IdeFrame(com.intellij.openapi.wm.IdeFrame) java.util(java.util) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ModalityState(com.intellij.openapi.application.ModalityState) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) UsageInfo(com.intellij.usageView.UsageInfo) RefactoringBundle(com.intellij.refactoring.RefactoringBundle) BaseRefactoringProcessor(com.intellij.refactoring.BaseRefactoringProcessor) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) AutomaticRenamer(com.intellij.refactoring.rename.naming.AutomaticRenamer) ContainerUtil(com.intellij.util.containers.ContainerUtil) CopyFilesOrDirectoriesHandler(com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) HyperlinkListener(javax.swing.event.HyperlinkListener) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StatusBarEx(com.intellij.openapi.wm.ex.StatusBarEx) StringUtil(com.intellij.openapi.util.text.StringUtil) WindowManager(com.intellij.openapi.wm.WindowManager) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) LightElement(com.intellij.psi.impl.light.LightElement) AutomaticRenamerFactory(com.intellij.refactoring.rename.naming.AutomaticRenamerFactory) UsageViewUtil(com.intellij.usageView.UsageViewUtil) UsageViewDescriptor(com.intellij.usageView.UsageViewDescriptor) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) Nullable(org.jetbrains.annotations.Nullable) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) ApplicationManager(com.intellij.openapi.application.ApplicationManager) RelatedUsageInfo(com.intellij.refactoring.util.RelatedUsageInfo) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) HyperlinkEvent(javax.swing.event.HyperlinkEvent) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) IdeFrame(com.intellij.openapi.wm.IdeFrame) HyperlinkListener(javax.swing.event.HyperlinkListener) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StatusBarEx(com.intellij.openapi.wm.ex.StatusBarEx) UsageInfo(com.intellij.usageView.UsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) NonCodeUsageInfo(com.intellij.refactoring.util.NonCodeUsageInfo) RelatedUsageInfo(com.intellij.refactoring.util.RelatedUsageInfo)

Example 30 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project android by JetBrains.

the class ManifestPanel method createDetailsPane.

private JEditorPane createDetailsPane(@NotNull final AndroidFacet facet) {
    JEditorPane details = new JEditorPane();
    details.setMargin(JBUI.insets(5));
    details.setContentType(UIUtil.HTML_MIME);
    details.setEditable(false);
    details.setFont(myDefaultFont);
    details.setBackground(myBackgroundColor);
    HyperlinkListener hyperLinkListener = e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            String url = e.getDescription();
            myHtmlLinkManager.handleUrl(url, facet.getModule(), null, null, null);
        }
    };
    details.addHyperlinkListener(hyperLinkListener);
    return details;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) FN_BUILD_GRADLE(com.android.SdkConstants.FN_BUILD_GRADLE) NamedObject(com.android.tools.idea.gradle.parser.NamedObject) HyperlinkEvent(javax.swing.event.HyperlinkEvent) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) IdeActions(com.intellij.openapi.actionSystem.IdeActions) PsiManager(com.intellij.psi.PsiManager) JBMenuItem(com.intellij.openapi.ui.JBMenuItem) Matcher(java.util.regex.Matcher) JBUI(com.intellij.util.ui.JBUI) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) MouseAdapter(java.awt.event.MouseAdapter) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) SourcePosition(com.android.ide.common.blame.SourcePosition) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) MouseListener(java.awt.event.MouseListener) XmlTag(com.intellij.psi.xml.XmlTag) SourceFile(com.android.ide.common.blame.SourceFile) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) XmlHighlighterColors(com.intellij.openapi.editor.XmlHighlighterColors) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) com.intellij.ui(com.intellij.ui) Sets(com.google.common.collect.Sets) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) JBScrollPane(com.intellij.ui.components.JBScrollPane) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) EXPLODED_AAR(com.android.tools.idea.gradle.project.model.AndroidModuleModel.EXPLODED_AAR) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) javax.swing.tree(javax.swing.tree) Pattern(java.util.regex.Pattern) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) SdkConstants(com.android.SdkConstants) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ModuleManager(com.intellij.openapi.module.ModuleManager) PositionXmlParser(com.android.utils.PositionXmlParser) SourceFilePosition(com.android.ide.common.blame.SourceFilePosition) MergingReport(com.android.manifmerger.MergingReport) AndroidLibrary(com.android.builder.model.AndroidLibrary) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ActionManager(com.intellij.openapi.actionSystem.ActionManager) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) TreeUtil(com.intellij.util.ui.tree.TreeUtil) HyperlinkListener(javax.swing.event.HyperlinkListener) org.w3c.dom(org.w3c.dom) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) MavenCoordinates(com.android.builder.model.MavenCoordinates) HtmlBuilder(com.android.utils.HtmlBuilder) MergedManifest(com.android.tools.idea.model.MergedManifest) AnAction(com.intellij.openapi.actionSystem.AnAction) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) java.awt(java.awt) CommandProcessor(com.intellij.openapi.command.CommandProcessor) XmlNode(com.android.manifmerger.XmlNode) Actions(com.android.manifmerger.Actions) GradleUtil(com.android.tools.idea.gradle.util.GradleUtil) javax.swing(javax.swing) HyperlinkListener(javax.swing.event.HyperlinkListener)

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