Search in sources :

Example 21 with JBScrollPane

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

the class ImageDuplicateResultsDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    DataManager.registerDataProvider(panel, new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            final TreePath path = myTree.getSelectionPath();
            if (path != null) {
                Object component = path.getLastPathComponent();
                VirtualFile file = null;
                if (component instanceof MyFileNode) {
                    component = ((MyFileNode) component).getParent();
                }
                if (component instanceof MyDuplicatesNode) {
                    file = ((MyDuplicatesNode) component).getUserObject().iterator().next();
                }
                if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
                    return file;
                }
                if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId) && file != null) {
                    return new VirtualFile[] { file };
                }
            }
            return null;
        }
    });
    final JBList list = new JBList(new ResourceModules().getModuleNames());
    final NotNullFunction<Object, JComponent> modulesRenderer = dom -> new JLabel(dom instanceof Module ? ((Module) dom).getName() : dom.toString(), PlatformIcons.SOURCE_FOLDERS_ICON, SwingConstants.LEFT);
    list.installCellRenderer(modulesRenderer);
    final JPanel modulesPanel = ToolbarDecorator.createDecorator(list).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final Module[] all = ModuleManager.getInstance(myProject).getModules();
            Arrays.sort(all, (o1, o2) -> o1.getName().compareTo(o2.getName()));
            final JBList modules = new JBList(all);
            modules.installCellRenderer(modulesRenderer);
            JBPopupFactory.getInstance().createListPopupBuilder(modules).setTitle("Add Resource Module").setFilteringEnabled(o -> ((Module) o).getName()).setItemChoosenCallback(() -> {
                final Object value = modules.getSelectedValue();
                if (value instanceof Module && !myResourceModules.contains((Module) value)) {
                    myResourceModules.add((Module) value);
                    ((DefaultListModel) list.getModel()).addElement(((Module) value).getName());
                }
                ((DefaultTreeModel) myTree.getModel()).reload();
                TreeUtil.expandAll(myTree);
            }).createPopup().show(button.getPreferredPopupPoint());
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final Object[] values = list.getSelectedValues();
            for (Object value : values) {
                myResourceModules.remove((String) value);
                ((DefaultListModel) list.getModel()).removeElement(value);
            }
            ((DefaultTreeModel) myTree.getModel()).reload();
            TreeUtil.expandAll(myTree);
        }
    }).disableDownAction().disableUpAction().createPanel();
    modulesPanel.setPreferredSize(new Dimension(-1, 60));
    final JPanel top = new JPanel(new BorderLayout());
    top.add(new JLabel("Image modules:"), BorderLayout.NORTH);
    top.add(modulesPanel, BorderLayout.CENTER);
    panel.add(top, BorderLayout.NORTH);
    panel.add(new JBScrollPane(myTree), BorderLayout.CENTER);
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            VirtualFile file = getFileFromSelection();
            if (file != null) {
                final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
                if (psiFile != null) {
                    final ImplementationViewComponent viewComponent = new ImplementationViewComponent(new PsiElement[] { psiFile }, 0);
                    final TreeSelectionListener listener = new TreeSelectionListener() {

                        @Override
                        public void valueChanged(TreeSelectionEvent e) {
                            final VirtualFile selection = getFileFromSelection();
                            if (selection != null) {
                                final PsiFile newElement = PsiManager.getInstance(myProject).findFile(selection);
                                if (newElement != null) {
                                    viewComponent.update(new PsiElement[] { newElement }, 0);
                                }
                            }
                        }
                    };
                    myTree.addTreeSelectionListener(listener);
                    final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(viewComponent, viewComponent.getPreferredFocusableComponent()).setProject(myProject).setDimensionServiceKey(myProject, ImageDuplicateResultsDialog.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(false).setCancelCallback(() -> {
                        myTree.removeTreeSelectionListener(listener);
                        return true;
                    }).setTitle("Image Preview").createPopup();
                    final Window window = ImageDuplicateResultsDialog.this.getWindow();
                    popup.show(new RelativePoint(window, new Point(window.getWidth(), 0)));
                    viewComponent.setHint(popup, "Image Preview");
                }
            }
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), panel);
    int total = myDuplicates.values().stream().mapToInt(Set::size).sum() - myDuplicates.size();
    final JLabel label = new JLabel("<html>Press <b>Enter</b> to preview image<br>Total images found: " + myImages.size() + ". Total duplicates found: " + total + "</html>");
    panel.add(label, BorderLayout.SOUTH);
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) PsiManager(com.intellij.psi.PsiManager) ModuleUtil(com.intellij.openapi.module.ModuleUtil) TreeSelectionListener(javax.swing.event.TreeSelectionListener) PropertyName(com.intellij.ide.util.PropertyName) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Tree(com.intellij.ui.treeStructure.Tree) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) DataManager(com.intellij.ide.DataManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) PlatformIcons(com.intellij.util.PlatformIcons) JBList(com.intellij.ui.components.JBList) TreeUtil(com.intellij.util.ui.tree.TreeUtil) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) TreePath(javax.swing.tree.TreePath) StringUtil(com.intellij.openapi.util.text.StringUtil) NotNullFunction(com.intellij.util.NotNullFunction) com.intellij.ui(com.intellij.ui) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) NotNull(org.jetbrains.annotations.NotNull) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) javax.swing(javax.swing) TreeSelectionListener(javax.swing.event.TreeSelectionListener) RelativePoint(com.intellij.ui.awt.RelativePoint) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) TreePath(javax.swing.tree.TreePath) JBList(com.intellij.ui.components.JBList) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 22 with JBScrollPane

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

the class OptionTableWithPreviewPanel method init.

@Override
protected void init() {
    super.init();
    myPanel.setLayout(new GridBagLayout());
    initTables();
    myTreeTable = createOptionsTree(getSettings());
    myTreeTable.setBackground(UIUtil.getPanelBackground());
    myTreeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    JBScrollPane scrollPane = new JBScrollPane(myTreeTable) {

        @Override
        public Dimension getMinimumSize() {
            return super.getPreferredSize();
        }
    };
    myPanel.add(scrollPane, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
    final JPanel previewPanel = createPreviewPanel();
    myPanel.add(previewPanel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
    installPreviewPanel(previewPanel);
    addPanelToWatch(myPanel);
    isFirstUpdate = false;
    customizeSettings();
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 23 with JBScrollPane

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

the class ActionTracer method getComponent.

@Override
public JComponent getComponent() {
    if (myComponent == null) {
        myText = new JTextArea();
        final JBScrollPane log = new JBScrollPane(myText);
        final AnAction clear = new AnAction("Clear", "Clear log", AllIcons.General.Reset) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                myText.setText(null);
            }
        };
        myComponent = new JPanel(new BorderLayout());
        final DefaultActionGroup group = new DefaultActionGroup();
        group.add(clear);
        myComponent.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH);
        myComponent.add(log);
        ActionManager.getInstance().addAnActionListener(this);
    }
    return myComponent;
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 24 with JBScrollPane

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

the class ScrollPaneFactory method createScrollPane.

/**
   * Creates a {@link JScrollPane} object for the specified {@code view} and initializes its border.
   *
   * @param view    the component to display in a {@code JScrollPane}'s viewport
   * @param borders the {@link SideBorder}'s flags, which define a {@code JScrollPane}'s border
   * @return new {@code JScrollPane} object
   *
   * @see IdeBorderFactory#createBorder(int)
   */
public static JScrollPane createScrollPane(Component view, @MagicConstant(flagsFromClass = SideBorder.class) int borders) {
    JBScrollPane scrollPane = new JBScrollPane(view);
    scrollPane.setBorder(IdeBorderFactory.createBorder(borders));
    return scrollPane;
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 25 with JBScrollPane

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

the class ColumnTreeBuilder method build.

public JComponent build() {
    // Stash this value since it'll get stomped WideSelectionTreeUI.
    boolean showsRootHandles = myTree.getShowsRootHandles();
    myTree.setUI(new ColumnTreeUI());
    myTree.setShowsRootHandles(showsRootHandles);
    myTree.setCellRenderer(myCellRenderer);
    myTable.getColumnModel().addColumnModelListener(new TableColumnModelListener() {

        @Override
        public void columnAdded(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent tableColumnModelEvent) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent changeEvent) {
            myTree.revalidate();
            myTree.repaint();
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent listSelectionEvent) {
        }
    });
    myTable.setRowSorter(myRowSorter);
    myRowSorter.addRowSorterListener(event -> {
        if (myTreeSorter != null && !myRowSorter.getSortKeys().isEmpty()) {
            RowSorter.SortKey key = myRowSorter.getSortKeys().get(0);
            Comparator<?> comparator = myRowSorter.getComparator(key.getColumn());
            Enumeration<TreePath> expanded = myTree.getExpandedDescendants(new TreePath(myTree.getModel().getRoot()));
            comparator = key.getSortOrder() == SortOrder.ASCENDING ? comparator : Collections.reverseOrder(comparator);
            myTreeSorter.sort(comparator, key.getSortOrder());
            if (expanded != null) {
                while (expanded.hasMoreElements()) {
                    myTree.expandPath(expanded.nextElement());
                }
            }
        }
    });
    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    for (ColumnBuilder column : myColumnBuilders) {
        column.create(myTableModel);
    }
    for (int i = 0; i < myColumnBuilders.size(); i++) {
        ColumnBuilder column = myColumnBuilders.get(i);
        column.configure(i, myTable, myRowSorter, myCellRenderer);
    }
    JPanel panel = new TreeWrapperPanel(myTable, myTree);
    if (myBackground != null) {
        panel.setBackground(myBackground);
    }
    JTableHeader header = myTable.getTableHeader();
    header.setReorderingAllowed(false);
    JViewport viewport = new JViewport();
    viewport.setView(header);
    JBScrollPane scrollPane = new JBScrollPane(panel);
    scrollPane.setColumnHeader(viewport);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    return scrollPane;
}
Also used : TableColumnModelEvent(javax.swing.event.TableColumnModelEvent) TableColumnModelListener(javax.swing.event.TableColumnModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) 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