Search in sources :

Example 6 with LinkLabel

use of com.intellij.ui.components.labels.LinkLabel in project intellij-community by JetBrains.

the class Banner method addAction.

public void addAction(final Action action) {
    action.addPropertyChangeListener(this);
    final LinkLabel label = new LinkLabel(null, null, new LinkListener() {

        @Override
        public void linkSelected(final LinkLabel aSource, final Object aLinkData) {
            action.actionPerformed(new ActionEvent(Banner.this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY));
        }
    }) {

        @Override
        protected Color getTextColor() {
            return PlatformColors.BLUE;
        }
    };
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    myActions.put(action, label);
    myActionsPanel.add(label);
    updateAction(action);
}
Also used : LinkListener(com.intellij.ui.components.labels.LinkListener) LinkLabel(com.intellij.ui.components.labels.LinkLabel) ActionEvent(java.awt.event.ActionEvent)

Example 7 with LinkLabel

use of com.intellij.ui.components.labels.LinkLabel in project intellij-community by JetBrains.

the class NewWelcomeScreen method createFooterPanel.

private static JPanel createFooterPanel() {
    JLabel versionLabel = new JLabel(ApplicationNamesInfo.getInstance().getFullProductName() + " " + ApplicationInfo.getInstance().getFullVersion() + " Build " + ApplicationInfo.getInstance().getBuild().asStringWithoutProductCode());
    makeSmallFont(versionLabel);
    versionLabel.setForeground(WelcomeScreenColors.FOOTER_FOREGROUND);
    JPanel footerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    footerPanel.setBackground(WelcomeScreenColors.FOOTER_BACKGROUND);
    footerPanel.setBorder(new EmptyBorder(2, 5, 2, 5) {

        @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            g.setColor(WelcomeScreenColors.BORDER_COLOR);
            g.drawLine(x, y, x + width, y);
        }
    });
    footerPanel.add(versionLabel);
    footerPanel.add(makeSmallFont(new JLabel(".  ")));
    footerPanel.add(makeSmallFont(new LinkLabel("Check", null, new LinkListener() {

        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
            UpdateChecker.updateAndShowResult(null, null);
        }
    })));
    footerPanel.add(makeSmallFont(new JLabel(" for updates now.")));
    return footerPanel;
}
Also used : LinkListener(com.intellij.ui.components.labels.LinkListener) LinkLabel(com.intellij.ui.components.labels.LinkLabel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 8 with LinkLabel

use of com.intellij.ui.components.labels.LinkLabel 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 9 with LinkLabel

use of com.intellij.ui.components.labels.LinkLabel in project intellij-community by JetBrains.

the class NotificationsManagerImpl method createActionPanel.

private static void createActionPanel(@NotNull final Notification notification, @NotNull JPanel centerPanel, int gap, @NotNull HoverAdapter hoverAdapter) {
    JPanel actionPanel = new NonOpaquePanel(new HorizontalLayout(gap, SwingConstants.CENTER));
    centerPanel.add(BorderLayout.SOUTH, actionPanel);
    List<AnAction> actions = notification.getActions();
    if (actions.size() > 2) {
        DropDownAction action = new DropDownAction(notification.getDropDownText(), new LinkListener<Void>() {

            @Override
            public void linkSelected(LinkLabel link, Void ignored) {
                Container parent = link.getParent();
                int size = parent.getComponentCount();
                DefaultActionGroup group = new DefaultActionGroup();
                for (int i = 1; i < size; i++) {
                    Component component = parent.getComponent(i);
                    if (!component.isVisible()) {
                        group.add(((LinkLabel<AnAction>) component).getLinkData());
                    }
                }
                showPopup(link, group);
            }
        });
        Notification.setDataProvider(notification, action);
        action.setVisible(false);
        actionPanel.add(action);
    }
    for (AnAction action : actions) {
        Presentation presentation = action.getTemplatePresentation();
        actionPanel.add(HorizontalLayout.LEFT, new LinkLabel<>(presentation.getText(), presentation.getIcon(), new LinkListener<AnAction>() {

            @Override
            public void linkSelected(LinkLabel aSource, AnAction action) {
                Notification.fire(notification, action);
            }
        }, action));
    }
    Insets hover = JBUI.insets(8, 5, 8, 7);
    int count = actionPanel.getComponentCount();
    for (int i = 0; i < count; i++) {
        hoverAdapter.addComponent(actionPanel.getComponent(i), hover);
    }
    hoverAdapter.addSource(actionPanel);
}
Also used : JBInsets(com.intellij.util.ui.JBInsets) LinkListener(com.intellij.ui.components.labels.LinkListener) HorizontalLayout(com.intellij.ui.components.panels.HorizontalLayout) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) LinkLabel(com.intellij.ui.components.labels.LinkLabel)

Example 10 with LinkLabel

use of com.intellij.ui.components.labels.LinkLabel in project intellij-community by JetBrains.

the class CustomizeFeaturedPluginsStepPanel method onPluginGroupsLoaded.

private void onPluginGroupsLoaded() {
    List<IdeaPluginDescriptor> pluginsFromRepository = myPluginGroups.getPluginsFromRepository();
    if (pluginsFromRepository.isEmpty()) {
        myInProgressLabel.setText("Cannot get featured plugins description online.");
        return;
    }
    removeAll();
    JPanel gridPanel = new JPanel(new GridLayout(0, 3));
    JBScrollPane scrollPane = CustomizePluginsStepPanel.createScrollPane(gridPanel);
    Map<String, String> config = myPluginGroups.getFeaturedPlugins();
    for (Map.Entry<String, String> entry : config.entrySet()) {
        JPanel groupPanel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.weightx = 1;
        String title = entry.getKey();
        String s = entry.getValue();
        int i = s.indexOf(':');
        String topic = s.substring(0, i);
        int j = s.indexOf(':', i + 1);
        String description = s.substring(i + 1, j);
        final String pluginId = s.substring(j + 1);
        IdeaPluginDescriptor foundDescriptor = null;
        for (IdeaPluginDescriptor descriptor : pluginsFromRepository) {
            if (descriptor.getPluginId().getIdString().equals(pluginId) && !PluginManagerCore.isBrokenPlugin(descriptor)) {
                foundDescriptor = descriptor;
                break;
            }
        }
        if (foundDescriptor == null)
            continue;
        final IdeaPluginDescriptor descriptor = foundDescriptor;
        final boolean isVIM = PluginGroups.IDEA_VIM_PLUGIN_ID.equals(descriptor.getPluginId().getIdString());
        boolean isCloud = "#Cloud".equals(topic);
        if (isCloud) {
            title = descriptor.getName();
            description = StringUtil.defaultIfEmpty(descriptor.getDescription(), "No description available");
            topic = StringUtil.defaultIfEmpty(descriptor.getCategory(), "Unknown");
        }
        JLabel titleLabel = new JLabel("<html><body><h2 style=\"text-align:left;\">" + title + "</h2></body></html>");
        JLabel topicLabel = new JLabel("<html><body><h4 style=\"text-align:left;color:#808080;font-weight:bold;\">" + topic + "</h4></body></html>");
        JLabel descriptionLabel = createHTMLLabel(description);
        JLabel warningLabel = null;
        if (isVIM || isCloud) {
            if (isCloud) {
                warningLabel = createHTMLLabel("From your JetBrains account");
                warningLabel.setIcon(AllIcons.General.BalloonInformation);
            } else {
                warningLabel = createHTMLLabel("Recommended only if you are<br> familiar with Vim.");
                warningLabel.setIcon(AllIcons.General.BalloonWarning);
            }
            if (!SystemInfo.isWindows)
                UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, warningLabel);
        }
        final CardLayout wrapperLayout = new CardLayout();
        final JPanel buttonWrapper = new JPanel(wrapperLayout);
        final JButton installButton = new JButton(isVIM ? "Install and Enable" : "Install");
        final JProgressBar progressBar = new JProgressBar(0, 100);
        progressBar.setStringPainted(true);
        JPanel progressPanel = new JPanel(new VerticalFlowLayout(true, false));
        progressPanel.add(progressBar);
        final LinkLabel cancelLink = new LinkLabel("Cancel", AllIcons.Actions.Cancel);
        JPanel linkWrapper = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
        linkWrapper.add(cancelLink);
        progressPanel.add(linkWrapper);
        final JPanel buttonPanel = new JPanel(new VerticalFlowLayout(0, 0));
        buttonPanel.add(installButton);
        buttonWrapper.add(buttonPanel, "button");
        buttonWrapper.add(progressPanel, "progress");
        wrapperLayout.show(buttonWrapper, "button");
        final ProgressIndicatorEx indicator = new AbstractProgressIndicatorExBase(true) {

            @Override
            public void start() {
                myCanceled.set(false);
                super.start();
                SwingUtilities.invokeLater(() -> wrapperLayout.show(buttonWrapper, "progress"));
            }

            @Override
            public void processFinish() {
                super.processFinish();
                SwingUtilities.invokeLater(() -> {
                    wrapperLayout.show(buttonWrapper, "button");
                    installButton.setEnabled(false);
                    installButton.setText("Installed");
                });
            }

            @Override
            public void setFraction(final double fraction) {
                super.setFraction(fraction);
                SwingUtilities.invokeLater(() -> {
                    int value = (int) (100 * fraction + .5);
                    progressBar.setValue(value);
                    progressBar.setString(value + "%");
                });
            }

            @Override
            public void cancel() {
                stop();
                myCanceled.set(true);
                super.cancel();
                SwingUtilities.invokeLater(() -> {
                    wrapperLayout.show(buttonWrapper, "button");
                    progressBar.setValue(0);
                    progressBar.setString("0%");
                });
            }
        };
        installButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                wrapperLayout.show(buttonWrapper, "progress");
                ourService.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            indicator.start();
                            IdeInitialConfigButtonUsages.addDownloadedPlugin(descriptor.getPluginId().getIdString());
                            PluginDownloader downloader = PluginDownloader.createDownloader(descriptor);
                            downloader.prepareToInstall(indicator);
                            downloader.install();
                            indicator.processFinish();
                        } catch (Exception ignored) {
                            if (!myCanceled.get()) {
                                onFail();
                            }
                        }
                    }

                    void onFail() {
                        //noinspection SSBasedInspection
                        SwingUtilities.invokeLater(() -> {
                            indicator.stop();
                            wrapperLayout.show(buttonWrapper, "progress");
                            progressBar.setString("Cannot download plugin");
                        });
                    }
                });
            }
        });
        cancelLink.setListener(new LinkListener() {

            @Override
            public void linkSelected(LinkLabel aSource, Object aLinkData) {
                indicator.cancel();
            }
        }, null);
        gbc.insets.left = installButton.getInsets().left / 2;
        gbc.insets.right = installButton.getInsets().right / 2;
        gbc.insets.bottom = -5;
        groupPanel.add(titleLabel, gbc);
        gbc.insets.bottom = SMALL_GAP;
        groupPanel.add(topicLabel, gbc);
        groupPanel.add(descriptionLabel, gbc);
        gbc.weighty = 1;
        groupPanel.add(Box.createVerticalGlue(), gbc);
        gbc.weighty = 0;
        if (warningLabel != null) {
            Insets insetsBefore = gbc.insets;
            gbc.insets = new Insets(0, -10, SMALL_GAP, -10);
            gbc.insets.left += insetsBefore.left;
            gbc.insets.right += insetsBefore.right;
            JPanel warningPanel = new JPanel(new BorderLayout());
            warningPanel.setBorder(new EmptyBorder(5, 10, 5, 10));
            warningPanel.add(warningLabel);
            groupPanel.add(warningPanel, gbc);
            gbc.insets = insetsBefore;
        }
        gbc.insets.bottom = gbc.insets.left = gbc.insets.right = 0;
        groupPanel.add(buttonWrapper, gbc);
        gridPanel.add(groupPanel);
    }
    while (gridPanel.getComponentCount() < 4) {
        gridPanel.add(Box.createVerticalBox());
    }
    int cursor = 0;
    Component[] components = gridPanel.getComponents();
    int rowCount = components.length / COLS;
    for (Component component : components) {
        ((JComponent) component).setBorder(new CompoundBorder(new CustomLineBorder(ColorUtil.withAlpha(JBColor.foreground(), .2), 0, 0, cursor / 3 < rowCount && (!(component instanceof Box)) ? 1 : 0, cursor % COLS != COLS - 1 && (!(component instanceof Box)) ? 1 : 0) {

            @Override
            protected Color getColor() {
                return ColorUtil.withAlpha(JBColor.foreground(), .2);
            }
        }, BorderFactory.createEmptyBorder(0, SMALL_GAP, 0, SMALL_GAP)));
        cursor++;
    }
    add(scrollPane);
    revalidate();
    repaint();
}
Also used : VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) ActionEvent(java.awt.event.ActionEvent) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginDownloader(com.intellij.openapi.updateSettings.impl.PluginDownloader) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) LinkListener(com.intellij.ui.components.labels.LinkListener) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) ActionListener(java.awt.event.ActionListener) LinkLabel(com.intellij.ui.components.labels.LinkLabel) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) Map(java.util.Map) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

LinkLabel (com.intellij.ui.components.labels.LinkLabel)14 LinkListener (com.intellij.ui.components.labels.LinkListener)6 EmptyBorder (javax.swing.border.EmptyBorder)4 NonOpaquePanel (com.intellij.ui.components.panels.NonOpaquePanel)3 NotNull (org.jetbrains.annotations.NotNull)2 CommonBundle.getCancelButtonText (com.intellij.CommonBundle.getCancelButtonText)1 IdeBundle (com.intellij.ide.IdeBundle)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 com.intellij.ide.todo (com.intellij.ide.todo)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 ActionPlaces (com.intellij.openapi.actionSystem.ActionPlaces)1 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationActivationListener (com.intellij.openapi.application.ApplicationActivationListener)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationNamesInfo (com.intellij.openapi.application.ApplicationNamesInfo)1 ModalityState (com.intellij.openapi.application.ModalityState)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1