Search in sources :

Example 6 with ColumnInfo

use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.

the class DualView method createFlatComponent.

private Component createFlatComponent(DualViewColumnInfo[] columns) {
    ArrayList<ColumnInfo> shownColumns = new ArrayList<>();
    for (DualViewColumnInfo column : columns) {
        if (column.shouldBeShownIsTheTable()) {
            shownColumns.add(column);
        }
    }
    ListTableModel flatModel = new ListTableModel(shownColumns.toArray(new ColumnInfo[shownColumns.size()]));
    //noinspection unchecked
    myFlatView = new TableView(flatModel) {

        public TableCellRenderer getCellRenderer(int row, int column) {
            return createWrappedRenderer(super.getCellRenderer(row, column));
        }

        @NotNull
        @Override
        public Component prepareRenderer(@NotNull TableCellRenderer renderer, int row, int column) {
            final Component c = super.prepareRenderer(renderer, row, column);
            if (c instanceof JComponent && !myFlatView.getCellSelectionEnabled()) {
                ((JComponent) c).setBorder(null);
            }
            return c;
        }

        @Override
        public void doLayout() {
            try {
                mySuppressStore = true;
                super.doLayout();
            } finally {
                mySuppressStore = false;
            }
        }

        @Override
        public void updateColumnSizes() {
        // suppress automatic layout, use stored values instead
        }
    };
    myFlatView.setCellSelectionEnabled(false);
    myFlatView.setColumnSelectionAllowed(false);
    myFlatView.setRowSelectionAllowed(true);
    refreshFlatModel();
    JPanel result = new JPanel(new BorderLayout());
    result.add(ScrollPaneFactory.createScrollPane(myFlatView), BorderLayout.CENTER);
    return result;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) ArrayList(java.util.ArrayList) ColumnInfo(com.intellij.util.ui.ColumnInfo) NotNull(org.jetbrains.annotations.NotNull) ListTableModel(com.intellij.util.ui.ListTableModel) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) BaseTableView(com.intellij.ui.table.BaseTableView) TableView(com.intellij.ui.table.TableView)

Example 7 with ColumnInfo

use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.

the class DualView method createTreeColumns.

private static ColumnInfo[] createTreeColumns(DualViewColumnInfo[] columns) {
    Collection<ColumnInfo> result = new ArrayList<>();
    final ColumnInfo firstColumn = columns[0];
    ColumnInfo firstTreeColumn = new ColumnInfo(firstColumn.getName()) {

        public Object valueOf(Object object) {
            return firstColumn.valueOf(object);
        }

        public Class getColumnClass() {
            return TreeTableModel.class;
        }

        public boolean isCellEditable(Object o) {
            return true;
        }
    };
    result.add(firstTreeColumn);
    for (int i = 1; i < columns.length; i++) {
        DualViewColumnInfo column = columns[i];
        if (column.shouldBeShownIsTheTree())
            result.add(column);
    }
    return result.toArray(new ColumnInfo[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) ColumnInfo(com.intellij.util.ui.ColumnInfo) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel)

Example 8 with ColumnInfo

use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.

the class TableView method updateColumnSizes.

public void updateColumnSizes() {
    final JTableHeader header = getTableHeader();
    final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer();
    final RowSorter<? extends TableModel> sorter = getRowSorter();
    final RowSorter.SortKey sortKey = sorter == null ? null : ContainerUtil.getFirstItem(sorter.getSortKeys());
    ColumnInfo[] columnInfos = getListTableModel().getColumnInfos();
    TableColumnModel columnModel = getColumnModel();
    int visibleColumnCount = columnModel.getColumnCount();
    int[] sizeMode = new int[visibleColumnCount];
    int[] headers = new int[visibleColumnCount];
    int[] widths = new int[visibleColumnCount];
    int allColumnWidth = 0;
    int allColumnCurrent = 0;
    int varCount = 0;
    Icon sortIcon = UIManager.getIcon("Table.ascendingSortIcon");
    // calculate
    for (int i = 0; i < visibleColumnCount; i++) {
        final TableColumn column = columnModel.getColumn(i);
        final ColumnInfo columnInfo = columnInfos[column.getModelIndex()];
        TableCellRenderer columnHeaderRenderer = column.getHeaderRenderer();
        if (columnHeaderRenderer == null) {
            columnHeaderRenderer = defaultRenderer;
        }
        final Component headerComponent = columnHeaderRenderer == null ? null : columnHeaderRenderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, i);
        if (headerComponent != null) {
            headers[i] = headerComponent.getPreferredSize().width;
            // add sort icon width
            if (sorter != null && columnInfo.isSortable() && sortIcon != null && (sortKey == null || sortKey.getColumn() != i)) {
                headers[i] += sortIcon.getIconWidth() + (headerComponent instanceof JLabel ? ((JLabel) headerComponent).getIconTextGap() : 0);
            }
        }
        final String maxStringValue;
        final String preferredValue;
        if (columnInfo.getWidth(this) > 0) {
            sizeMode[i] = 1;
            int width = columnInfo.getWidth(this);
            widths[i] = width;
        } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) {
            sizeMode[i] = 2;
            widths[i] = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth();
            varCount++;
        } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) {
            sizeMode[i] = 3;
            widths[i] = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth();
            varCount++;
        }
        allColumnWidth += widths[i];
        allColumnCurrent += column.getPreferredWidth();
    }
    allColumnWidth = Math.max(allColumnWidth, allColumnCurrent);
    // apply: distribute available space between resizable columns
    //        and make sure that header will fit as well
    int viewWidth = getParent() != null ? getParent().getWidth() : getWidth();
    double gold = 0.5 * (3 - Math.sqrt(5));
    int addendum = varCount == 0 || viewWidth < allColumnWidth ? 0 : (int) ((allColumnWidth < gold * viewWidth ? gold * viewWidth : allColumnWidth < (1 - gold) * viewWidth ? (1 - gold) * viewWidth : viewWidth) - allColumnWidth) / varCount;
    for (int i = 0; i < visibleColumnCount; i++) {
        TableColumn column = columnModel.getColumn(i);
        int width = widths[i];
        if (sizeMode[i] == 1) {
            column.setMaxWidth(width);
            column.setPreferredWidth(width);
            column.setMinWidth(width);
        } else if (sizeMode[i] == 2) {
            // do not shrink columns
            width = Math.max(column.getPreferredWidth(), Math.max(width + addendum, headers[i]));
            column.setPreferredWidth(width);
            column.setMaxWidth(width);
        } else if (sizeMode[i] == 3) {
            // do not shrink columns
            width = Math.max(column.getPreferredWidth(), Math.max(width + addendum, headers[i]));
            column.setPreferredWidth(width);
        }
    }
}
Also used : BooleanTableCellRenderer(com.intellij.ui.BooleanTableCellRenderer) ColumnInfo(com.intellij.util.ui.ColumnInfo)

Example 9 with ColumnInfo

use of com.intellij.util.ui.ColumnInfo in project intellij-community by JetBrains.

the class InjectionsSettingsUI method createInjectionColumnInfos.

private ColumnInfo[] createInjectionColumnInfos() {
    final TableCellRenderer booleanCellRenderer = createBooleanCellRenderer();
    final TableCellRenderer displayNameCellRenderer = createDisplayNameCellRenderer();
    final TableCellRenderer languageCellRenderer = createLanguageCellRenderer();
    final Comparator<InjInfo> languageComparator = (o1, o2) -> Comparing.compare(o1.injection.getInjectedLanguageId(), o2.injection.getInjectedLanguageId());
    final Comparator<InjInfo> displayNameComparator = (o1, o2) -> {
        final int support = Comparing.compare(o1.injection.getSupportId(), o2.injection.getSupportId());
        if (support != 0)
            return support;
        return Comparing.compare(o1.injection.getDisplayName(), o2.injection.getDisplayName());
    };
    final ColumnInfo[] columnInfos = { new ColumnInfo<InjInfo, Boolean>(" ") {

        @Override
        public Class getColumnClass() {
            return Boolean.class;
        }

        @Override
        public Boolean valueOf(final InjInfo o) {
            return o.injection.isEnabled();
        }

        @Override
        public boolean isCellEditable(final InjInfo injection) {
            return true;
        }

        @Override
        public void setValue(final InjInfo injection, final Boolean value) {
            injection.injection.setPlaceEnabled(null, value.booleanValue());
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo injection) {
            return booleanCellRenderer;
        }
    }, new ColumnInfo<InjInfo, InjInfo>("Name") {

        @Override
        public InjInfo valueOf(final InjInfo info) {
            return info;
        }

        @Override
        public Comparator<InjInfo> getComparator() {
            return displayNameComparator;
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo injection) {
            return displayNameCellRenderer;
        }
    }, new ColumnInfo<InjInfo, InjInfo>("Language") {

        @Override
        public InjInfo valueOf(final InjInfo info) {
            return info;
        }

        @Override
        public Comparator<InjInfo> getComparator() {
            return languageComparator;
        }

        @Override
        public TableCellRenderer getRenderer(final InjInfo info) {
            return languageCellRenderer;
        }
    } };
    if (myInfos.length > 1) {
        final TableCellRenderer typeRenderer = createTypeRenderer();
        return ArrayUtil.append(columnInfos, new ColumnInfo<InjInfo, String>("Scope") {

            @Override
            public String valueOf(final InjInfo info) {
                return info.bundled ? "Built-in" : info.cfgInfo.title;
            }

            @Override
            public TableCellRenderer getRenderer(final InjInfo injInfo) {
                return typeRenderer;
            }

            @Override
            public int getWidth(final JTable table) {
                return table.getFontMetrics(table.getFont()).stringWidth(StringUtil.repeatSymbol('m', 6));
            }

            @Override
            public Comparator<InjInfo> getComparator() {
                return (o1, o2) -> Comparing.compare(valueOf(o1), valueOf(o2));
            }
        });
    }
    return columnInfos;
}
Also used : Language(com.intellij.lang.Language) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) ColumnInfo(com.intellij.util.ui.ColumnInfo) THashSet(gnu.trove.THashSet) TableCellRenderer(javax.swing.table.TableCellRenderer) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) Nls(org.jetbrains.annotations.Nls) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) NullableFactory(com.intellij.openapi.util.NullableFactory) TableView(com.intellij.ui.table.TableView) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) Configurable(com.intellij.openapi.options.Configurable) ReferenceInjector(com.intellij.psi.injection.ReferenceInjector) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) InputEvent(java.awt.event.InputEvent) java.util(java.util) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) ContainerUtil(com.intellij.util.containers.ContainerUtil) Comparing(com.intellij.openapi.util.Comparing) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) DataManager(com.intellij.ide.DataManager) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) Convertor(com.intellij.util.containers.Convertor) IOException(java.io.IOException) FileType(com.intellij.openapi.fileTypes.FileType) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) TableCellRenderer(javax.swing.table.TableCellRenderer) ColumnInfo(com.intellij.util.ui.ColumnInfo)

Example 10 with ColumnInfo

use of com.intellij.util.ui.ColumnInfo in project intellij-plugins by JetBrains.

the class DartConfigurable method createUIComponents.

private void createUIComponents() {
    mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof CheckedTreeNode))
                return;
            final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
            final CheckedTreeNode node = (CheckedTreeNode) value;
            final Object userObject = node.getUserObject();
            if (userObject instanceof Project) {
                if (!dartSupportEnabled) {
                    //disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
                    getCheckbox().setEnabled(false);
                }
                getTextRenderer().setEnabled(dartSupportEnabled);
                getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
            } else if (userObject instanceof Module) {
                getCheckbox().setEnabled(dartSupportEnabled);
                getTextRenderer().setEnabled(dartSupportEnabled);
                final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
                getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
                getTextRenderer().append(((Module) userObject).getName());
            }
        }
    };
    myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
    myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {

        @Override
        public void nodeStateChanged(@NotNull CheckedTreeNode node) {
            updateErrorLabel();
        }
    });
    //myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
    myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {

        public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
        }

        public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
            throw new ExpandVetoException(event);
        }
    });
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) ComboBox(com.intellij.openapi.ui.ComboBox) ColumnInfo(com.intellij.util.ui.ColumnInfo) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo) ExpandVetoException(javax.swing.tree.ExpandVetoException) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo)

Aggregations

ColumnInfo (com.intellij.util.ui.ColumnInfo)27 TableCellRenderer (javax.swing.table.TableCellRenderer)7 TreeTableView (com.intellij.ui.dualView.TreeTableView)4 TreeTableModel (com.intellij.ui.treeStructure.treetable.TreeTableModel)4 ListTableModel (com.intellij.util.ui.ListTableModel)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 NotNull (org.jetbrains.annotations.NotNull)4 TableView (com.intellij.ui.table.TableView)3 ListTreeTableModelOnColumns (com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns)3 List (java.util.List)3 TableColumn (javax.swing.table.TableColumn)3 Project (com.intellij.openapi.project.Project)2 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)2 TreeColumnInfo (com.intellij.ui.treeStructure.treetable.TreeColumnInfo)2 AsyncProcessIcon (com.intellij.util.ui.AsyncProcessIcon)2 ArrayList (java.util.ArrayList)2 TableCellEditor (javax.swing.table.TableCellEditor)2 Nullable (org.jetbrains.annotations.Nullable)2 DependencyCellRenderer (com.android.tools.idea.gradle.structure.configurables.ui.dependencies.AbstractDeclaredDependenciesTableModel.DependencyCellRenderer)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1