Search in sources :

Example 16 with JBScrollPane

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

the class TraceViewPanel method createUIComponents.

private void createUIComponents() {
    MouseAdapter l = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getSource() == myCloseLabel) {
                closeSearchComponent();
            } else if (e.getSource() == mySearchLabel) {
                showSearchComponent();
            } else if (e.getSource() == myZoomFitLabel) {
                myTraceViewCanvas.zoomFit();
            }
        }
    };
    myDefaultHeaderPanel = new EditorHeaderComponent();
    mySearchLabel = new JLabel(AllIcons.Actions.Search);
    mySearchLabel.addMouseListener(l);
    mySearchLabel.setToolTipText("Find (Ctrl + F)");
    myZoomFitLabel = new JLabel(AndroidIcons.ZoomFit);
    myZoomFitLabel.setToolTipText("Zoom Fit");
    myZoomFitLabel.addMouseListener(l);
    myFindPanel = new EditorHeaderComponent();
    myFindFieldWrapper = new NonOpaquePanel(new BorderLayout());
    mySearchField = createSearchField();
    myFindFieldWrapper.add(mySearchField);
    myCloseLabel = new JLabel(AllIcons.Actions.Cross);
    myCloseLabel.addMouseListener(l);
    myVmStatsTreeTableModel = new VmStatsTreeTableModel();
    myTreeTable = new TreeTable(myVmStatsTreeTableModel);
    myTraceViewCanvas = new TraceViewCanvasWrapper();
    JBScrollPane scrollPane = new JBScrollPane(myTreeTable);
    mySplitter = new JBSplitter(true, 0.75f);
    mySplitter.setShowDividerControls(true);
    mySplitter.setShowDividerIcon(true);
    mySplitter.setFirstComponent(myTraceViewCanvas);
    mySplitter.setSecondComponent(scrollPane);
}
Also used : NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) EditorHeaderComponent(com.intellij.openapi.editor.impl.EditorHeaderComponent) JBSplitter(com.intellij.ui.JBSplitter) JBScrollPane(com.intellij.ui.components.JBScrollPane) VmStatsTreeTableModel(com.android.tools.idea.editors.vmtrace.treemodel.VmStatsTreeTableModel)

Example 17 with JBScrollPane

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

the class ModuleAwareProjectConfigurable method createComponent.

@Override
public JComponent createComponent() {
    if (myProject.isDefault()) {
        T configurable = createDefaultProjectConfigurable();
        if (configurable != null) {
            myModuleConfigurables.put(null, configurable);
            return configurable.createComponent();
        }
    }
    final List<Module> modules = ContainerUtil.filter(ModuleAttachProcessor.getSortedModules(myProject), module -> isSuitableForModule(module));
    final T projectConfigurable = createProjectConfigurable();
    if (modules.size() == 1 && projectConfigurable == null) {
        Module module = modules.get(0);
        final T configurable = createModuleConfigurable(module);
        myModuleConfigurables.put(module, configurable);
        return configurable.createComponent();
    }
    final Splitter splitter = new Splitter(false, 0.25f);
    CollectionListModel<Module> listDataModel = new CollectionListModel<>(modules);
    final JBList moduleList = new JBList(listDataModel);
    new ListSpeedSearch(moduleList, (Function<Object, String>) o -> {
        if (o == null) {
            return getProjectConfigurableItemName();
        } else if (o instanceof Module) {
            return ((Module) o).getName();
        }
        return null;
    });
    moduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    moduleList.setCellRenderer(new ModuleListCellRenderer() {

        @Override
        public void customize(JList list, Module module, int index, boolean selected, boolean hasFocus) {
            if (module == null) {
                setText(getProjectConfigurableItemName());
                setIcon(getProjectConfigurableItemIcon());
            } else {
                super.customize(list, module, index, selected, hasFocus);
            }
        }
    });
    splitter.setFirstComponent(new JBScrollPane(moduleList));
    final CardLayout layout = new CardLayout();
    final JPanel cardPanel = new JPanel(layout);
    splitter.setSecondComponent(cardPanel);
    if (projectConfigurable != null) {
        myModuleConfigurables.put(null, projectConfigurable);
        final JComponent component = projectConfigurable.createComponent();
        cardPanel.add(component, PROJECT_ITEM_KEY);
        listDataModel.add(0, null);
    }
    for (Module module : modules) {
        final T configurable = createModuleConfigurable(module);
        myModuleConfigurables.put(module, configurable);
        final JComponent component = configurable.createComponent();
        cardPanel.add(component, module.getName());
    }
    moduleList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            final Module value = (Module) moduleList.getSelectedValue();
            layout.show(cardPanel, value == null ? PROJECT_ITEM_KEY : value.getName());
        }
    });
    if (moduleList.getItemsCount() > 0) {
        moduleList.setSelectedIndex(0);
        Module module = listDataModel.getElementAt(0);
        layout.show(cardPanel, module == null ? PROJECT_ITEM_KEY : module.getName());
    }
    return splitter;
}
Also used : ModuleAttachProcessor(com.intellij.platform.ModuleAttachProcessor) AllIcons(com.intellij.icons.AllIcons) HashMap(java.util.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) Nls(org.jetbrains.annotations.Nls) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Splitter(com.intellij.openapi.ui.Splitter) JBList(com.intellij.ui.components.JBList) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) Configurable(com.intellij.openapi.options.Configurable) CollectionListModel(com.intellij.ui.CollectionListModel) JBScrollPane(com.intellij.ui.components.JBScrollPane) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) javax.swing(javax.swing) Splitter(com.intellij.openapi.ui.Splitter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSpeedSearch(com.intellij.ui.ListSpeedSearch) JBList(com.intellij.ui.components.JBList) Module(com.intellij.openapi.module.Module) CollectionListModel(com.intellij.ui.CollectionListModel) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 18 with JBScrollPane

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

the class SearchEverywhereAction method updatePopupBounds.

private void updatePopupBounds() {
    if (myPopup == null || !myPopup.isVisible()) {
        return;
    }
    final Container parent = getField().getParent();
    final Dimension size = myList.getParent().getParent().getPreferredSize();
    size.width = myPopupActualWidth - 2;
    if (size.width + 2 < parent.getWidth()) {
        size.width = parent.getWidth();
    }
    if (myList.getItemsCount() == 0) {
        size.height = JBUI.scale(30);
    }
    Dimension sz = new Dimension(size.width, myList.getPreferredSize().height);
    if (!SystemInfo.isMac) {
        if ((sz.width > getPopupMaxWidth() || sz.height > getPopupMaxWidth())) {
            final JBScrollPane pane = new JBScrollPane();
            final int extraWidth = pane.getVerticalScrollBar().getWidth() + 1;
            final int extraHeight = pane.getHorizontalScrollBar().getHeight() + 1;
            sz = new Dimension(Math.min(getPopupMaxWidth(), Math.max(getField().getWidth(), sz.width + extraWidth)), Math.min(getPopupMaxWidth(), sz.height + extraHeight));
            sz.width += 20;
            sz.height += 2;
        } else {
            sz.width += 2;
            sz.height += 2;
        }
    }
    sz.width = Math.max(sz.width, myPopup.getSize().width);
    myPopup.setSize(sz);
    if (myActionEvent != null && myActionEvent.getInputEvent() == null) {
        final Point p = parent.getLocationOnScreen();
        p.y += parent.getHeight();
        if (parent.getWidth() < sz.width) {
            p.x -= sz.width - parent.getWidth();
        }
        myPopup.setLocation(p);
    } else {
        try {
            adjustPopup();
        } catch (Exception ignore) {
        }
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) JBScrollPane(com.intellij.ui.components.JBScrollPane) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 19 with JBScrollPane

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

the class ExtractedSettingsDialog method buildExtractedSettingsTree.

protected JComponent buildExtractedSettingsTree() {
    Collection<Value> unusedValues = ContainerUtil.newHashSet(myValues);
    myRoot = new DefaultMutableTreeNode();
    for (Map.Entry<LanguageCodeStyleSettingsProvider.SettingsType, Map<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>>> typeEntry : myNameProvider.mySettings.entrySet()) {
        DefaultMutableTreeNode settingsNode = null;
        for (Map.Entry<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>> groupEntry : typeEntry.getValue().entrySet()) {
            CodeStyleSettingPresentation.SettingsGroup group = groupEntry.getKey();
            List<CodeStyleSettingPresentation> representations = groupEntry.getValue();
            List<CodeStyleSettingPresentation> children = ContainerUtil.emptyList();
            DefaultMutableTreeNode groupNode = null;
            if (group.name == null && !representations.isEmpty()) {
                //there is a setting with name coinciding with group name
                if (representations.size() > 1) {
                    children = representations.subList(1, representations.size());
                }
                CodeStyleSettingPresentation headRep = representations.get(0);
                Value myValue = CodeStyleSettingsNameProvider.getValue(headRep, myValues);
                if (myValue == null) {
                    //value was not found (was not selected)
                    groupNode = new SettingsTreeNode(headRep.getUiName());
                } else {
                    groupNode = new SettingsTreeNode(headRep.getUiName());
                    groupNode.add(new SettingsTreeNode(headRep.getValueUiName(myValue.value), headRep, true, myValue));
                    unusedValues.remove(myValue);
                }
            } else {
                children = representations;
            }
            for (CodeStyleSettingPresentation representation : children) {
                Value myValue = CodeStyleSettingsNameProvider.getValue(representation, myValues);
                if (myValue != null) {
                    if (groupNode == null) {
                        groupNode = new SettingsTreeNode(group.name);
                    }
                    groupNode.add(new SettingsTreeNode(representation.getValueUiName(myValue.value), representation, false, myValue));
                    unusedValues.remove(myValue);
                }
            }
            if (groupNode != null && !groupNode.isLeaf()) {
                if (settingsNode == null) {
                    settingsNode = new SettingsTreeNode(CodeStyleSettingsNameProvider.getSettingsTypeName(typeEntry.getKey()));
                }
                settingsNode.add(groupNode);
            }
        }
        if (settingsNode != null) {
            myRoot.add(settingsNode);
        }
    }
    //TODO: for now, settings without UI presentation are not displayed. Do something about it.
    //unusedValues = ContainerUtil.filter(unusedValues, new Condition<Value>(){
    //  @Override
    //  public boolean value(Value value) {
    //    return value.state == Value.STATE.SELECTED;
    //  }
    //});
    //
    //DefaultMutableTreeNode unnamedNode = null;
    //for (Value value: unusedValues) {
    //  if (unnamedNode == null) {
    //    unnamedNode = new SettingsTreeNode("Settings without UI representation");
    //  }
    //  unnamedNode.add(new SettingsTreeNode(value.value.toString(), null, false, value.name, value));
    //}
    //
    //if (unnamedNode != null) {
    //  myRoot.add(unnamedNode);
    //}
    final ColumnInfo[] COLUMNS = new ColumnInfo[] { getTitleColumnInfo(), getValueColumnInfo() };
    ListTreeTableModel model = new ListTreeTableModel(myRoot, COLUMNS);
    final TreeTable treeTable = new TreeTable(model) {

        @Override
        public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
            TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
            UIUtil.setLineStyleAngled(tableRenderer);
            tableRenderer.setRootVisible(false);
            tableRenderer.setShowsRootHandles(true);
            return tableRenderer;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellRenderer(row, column);
            Object node = treePath.getLastPathComponent();
            TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
            return renderer == null ? super.getCellRenderer(row, column) : renderer;
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellEditor(row, column);
            Object node = treePath.getLastPathComponent();
            TableCellEditor editor = COLUMNS[column].getEditor(node);
            return editor == null ? super.getCellEditor(row, column) : editor;
        }
    };
    new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
    treeTable.setRootVisible(false);
    final JTree tree = treeTable.getTree();
    tree.setCellRenderer(myTitleRenderer);
    tree.setShowsRootHandles(true);
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setTableHeader(null);
    TreeUtil.expandAll(tree);
    treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
    treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
    int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
    final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
    titleColumn.setPreferredWidth(maxWidth);
    titleColumn.setMinWidth(maxWidth);
    titleColumn.setMaxWidth(maxWidth);
    titleColumn.setResizable(false);
    final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
    treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
    treeTable.setBackground(UIUtil.getPanelBackground());
    treeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    final Dimension screenSize = treeTable.getToolkit().getScreenSize();
    JBScrollPane scroller = new JBScrollPane(treeTable) {

        @Override
        public Dimension getMinimumSize() {
            return super.getPreferredSize();
        }
    };
    final Dimension preferredSize = new Dimension(Math.min(screenSize.width / 2, treeTable.getPreferredSize().width), Math.min(screenSize.height / 2, treeTable.getPreferredSize().height));
    getRootPane().setPreferredSize(preferredSize);
    return scroller;
}
Also used : TreeTableSpeedSearch(com.intellij.ui.TreeTableSpeedSearch) ColumnInfo(com.intellij.util.ui.ColumnInfo) CodeStyleSettingPresentation(com.intellij.psi.codeStyle.presentation.CodeStyleSettingPresentation) List(java.util.List) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TableCellEditor(javax.swing.table.TableCellEditor) TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumn(javax.swing.table.TableColumn) Value(com.intellij.psi.codeStyle.extractor.values.Value) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 20 with JBScrollPane

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

the class AbstractExternalSystemConfigurable method prepareProjectSettings.

@SuppressWarnings("unchecked")
private void prepareProjectSettings(@NotNull SystemSettings s) {
    myProjectsModel = new DefaultListModel();
    myProjectsList = new JBList(myProjectsModel);
    myProjectsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    addTitle(ExternalSystemBundle.message("settings.title.linked.projects", myExternalSystemId.getReadableName()));
    myComponent.add(new JBScrollPane(myProjectsList), ExternalSystemUiUtil.getFillLineConstraints(1));
    addTitle(ExternalSystemBundle.message("settings.title.project.settings"));
    List<ProjectSettings> settings = ContainerUtilRt.newArrayList(s.getLinkedProjectsSettings());
    myProjectsList.setVisibleRowCount(Math.max(3, Math.min(5, settings.size())));
    ContainerUtil.sort(settings, (s1, s2) -> getProjectName(s1.getExternalProjectPath()).compareTo(getProjectName(s2.getExternalProjectPath())));
    myProjectSettingsControls.clear();
    for (ProjectSettings setting : settings) {
        ExternalSystemSettingsControl<ProjectSettings> control = createProjectSettingsControl(setting);
        control.fillUi(myComponent, 1);
        myProjectsModel.addElement(getProjectName(setting.getExternalProjectPath()));
        myProjectSettingsControls.add(control);
        if (control instanceof AbstractExternalProjectSettingsControl<?>) {
            ((AbstractExternalProjectSettingsControl) control).setCurrentProject(myProject);
        }
        control.showUi(false);
    }
    myProjectsList.addListSelectionListener(new ListSelectionListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int i = myProjectsList.getSelectedIndex();
            if (i < 0) {
                return;
            }
            if (myActiveProjectSettingsControl != null) {
                myActiveProjectSettingsControl.showUi(false);
            }
            myActiveProjectSettingsControl = myProjectSettingsControls.get(i);
            myActiveProjectSettingsControl.showUi(true);
        }
    });
    if (!myProjectsModel.isEmpty()) {
        myProjectsList.setSelectedIndex(0);
    }
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) JBScrollPane(com.intellij.ui.components.JBScrollPane) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ListSelectionListener(javax.swing.event.ListSelectionListener)

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