Search in sources :

Example 36 with JBScrollPane

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

the class TaskDefaultFavoriteListProvider method showNotePopup.

private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) {
    final JTextArea textArea = new JTextArea(3, 50);
    textArea.setFont(UIUtil.getTreeFont());
    textArea.setText(initText);
    final JBScrollPane pane = new JBScrollPane(textArea);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    final JComponent content = popup.getContent();
    final AnAction action = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            popup.closeOk(e.getInputEvent());
            unregisterCustomShortcutSet(content);
            after.consume(textArea.getText());
        }
    };
    action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
    ApplicationManager.getApplication().invokeLater(() -> popup.showInCenterOf(tree), ModalityState.NON_MODAL, project.getDisposed());
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 37 with JBScrollPane

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

the class ScrollPaneFactory method createScrollPane.

public static JScrollPane createScrollPane(Component view, boolean withoutBorder) {
    JBScrollPane scrollPane = new JBScrollPane(view);
    if (withoutBorder) {
        // set empty border, because setting null doesn't always take effect
        scrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
        scrollPane.setViewportBorder(IdeBorderFactory.createEmptyBorder());
    }
    return scrollPane;
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 38 with JBScrollPane

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

the class ProjectSettingsStepBase method createPanel.

@Override
public JPanel createPanel() {
    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JLabel label = createErrorLabel();
    final JButton button = createActionButton();
    button.addActionListener(createCloseActionListener());
    Disposer.register(this, () -> UIUtil.dispose(button));
    final JPanel scrollPanel = createAndFillContentPanel();
    initGeneratorListeners();
    registerValidators();
    final JBScrollPane scrollPane = new JBScrollPane(scrollPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);
    mainPanel.add(scrollPane, BorderLayout.CENTER);
    final JPanel bottomPanel = new JPanel(new BorderLayout());
    bottomPanel.setName(BOTTOM_PANEL);
    bottomPanel.add(label, BorderLayout.NORTH);
    bottomPanel.add(button, BorderLayout.EAST);
    mainPanel.add(bottomPanel, BorderLayout.SOUTH);
    return mainPanel;
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 39 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane 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)

Example 40 with JBScrollPane

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

the class AbstractModuleDataService method ruleOrphanModules.

/**
   * There is a possible case that an external module has been un-linked from ide project. There are two ways to process
   * ide modules which correspond to that external project:
   * <pre>
   * <ol>
   *   <li>Remove them from ide project as well;</li>
   *   <li>Keep them at ide project as well;</li>
   * </ol>
   * </pre>
   * This method handles that situation, i.e. it asks a user what should be done and acts accordingly.
   *
   * @param orphanModules    modules which correspond to the un-linked external project
   * @param project          current ide project
   * @param externalSystemId id of the external system which project has been un-linked from ide project
   */
private static void ruleOrphanModules(@NotNull final List<Module> orphanModules, @NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @NotNull final Consumer<List<Module>> result) {
    ExternalSystemApiUtil.executeOnEdt(true, () -> {
        List<Module> toRemove = ContainerUtil.newSmartList();
        if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
            toRemove.addAll(orphanModules);
        } else {
            final JPanel content = new JPanel(new GridBagLayout());
            content.add(new JLabel(ExternalSystemBundle.message("orphan.modules.text", externalSystemId.getReadableName())), ExternalSystemUiUtil.getFillLineConstraints(0));
            final CheckBoxList<Module> orphanModulesList = new CheckBoxList<>();
            orphanModulesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            orphanModulesList.setItems(orphanModules, module -> module.getName());
            for (Module module : orphanModules) {
                orphanModulesList.setItemSelected(module, true);
            }
            orphanModulesList.setBorder(IdeBorderFactory.createEmptyBorder(8));
            content.add(orphanModulesList, ExternalSystemUiUtil.getFillLineConstraints(0));
            content.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 8, 0));
            DialogWrapper dialog = new DialogWrapper(project) {

                {
                    setTitle(ExternalSystemBundle.message("import.title", externalSystemId.getReadableName()));
                    init();
                }

                @Nullable
                @Override
                protected JComponent createCenterPanel() {
                    return new JBScrollPane(content);
                }

                @NotNull
                protected Action[] createActions() {
                    return new Action[] { getOKAction() };
                }
            };
            dialog.showAndGet();
            for (int i = 0; i < orphanModules.size(); i++) {
                Module module = orphanModules.get(i);
                if (orphanModulesList.isItemSelected(i)) {
                    toRemove.add(module);
                }
            }
        }
        result.consume(toRemove);
    });
}
Also used : CheckBoxList(com.intellij.ui.CheckBoxList) Module(com.intellij.openapi.module.Module) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

JBScrollPane (com.intellij.ui.components.JBScrollPane)51 ActionEvent (java.awt.event.ActionEvent)7 Nullable (org.jetbrains.annotations.Nullable)7 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 JBList (com.intellij.ui.components.JBList)6 ListSelectionEvent (javax.swing.event.ListSelectionEvent)6 ListSelectionListener (javax.swing.event.ListSelectionListener)5 JBTable (com.intellij.ui.table.JBTable)4 Tree (com.intellij.ui.treeStructure.Tree)4 java.awt (java.awt)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 javax.swing (javax.swing)4 TreePath (javax.swing.tree.TreePath)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3