Search in sources :

Example 21 with TableCellRenderer

use of javax.swing.table.TableCellRenderer 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 22 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.

the class JTableWrapper method packColumns.

private void packColumns() {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) myTable.getColumnModel();
    int[] colMinWidths = new int[myColumns.length];
    for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
        TableColumn col = colModel.getColumn(iColumn);
        colMinWidths[iColumn] = col.getMinWidth();
        if (!myColumns[iColumn].needPack()) {
            col.setWidth(col.getMinWidth());
            continue;
        }
        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
            renderer = myTable.getTableHeader().getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(myTable, col.getHeaderValue(), false, false, 0, 0);
        int colWidth = comp.getPreferredSize().width;
        for (int iRow = 0; iRow < myTable.getRowCount(); iRow++) {
            renderer = myTable.getCellRenderer(iRow, iColumn);
            comp = renderer.getTableCellRendererComponent(myTable, myTable.getValueAt(iRow, iColumn), false, false, iRow, iColumn);
            colWidth = Math.max(colWidth, comp.getPreferredSize().width);
        }
        colWidth += 2 * COLUMN_HEADER_MARGIN_WIDTH;
        col.setMaxWidth(colWidth);
        col.setMinWidth(colWidth);
    }
    for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
        TableColumn col = colModel.getColumn(iColumn);
        col.setMinWidth(colMinWidths[iColumn]);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 23 with TableCellRenderer

use of javax.swing.table.TableCellRenderer 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 24 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.

the class SimpleColoredComponentLinkMouseListener method tryGetTag.

@Override
protected Object tryGetTag(@NotNull MouseEvent e, @NotNull JTable table, int row, int column) {
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component component = cellRenderer.getTableCellRendererComponent(table, table.getValueAt(row, column), false, false, row, column);
    if (component instanceof SimpleColoredComponent) {
        Rectangle rc = table.getCellRect(row, column, false);
        return ((SimpleColoredComponent) component).getFragmentTagAt(e.getX() - rc.x);
    }
    return super.tryGetTag(e, table, row, column);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 25 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project intellij-community by JetBrains.

the class TaskExecutionTreeTable method getCellRenderer.

@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 0) {
        final TableCellRenderer cellRenderer = super.getCellRenderer(row, column);
        return new TableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component component = cellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                final Color bg = isSelected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
                component.setBackground(bg);
                return component;
            }
        };
    } else if (column == 1) {
        return new DefaultTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setHorizontalAlignment(SwingConstants.RIGHT);
                final Color fg = isSelected ? UIUtil.getTreeSelectionForeground() : SimpleTextAttributes.GRAY_ATTRIBUTES.getFgColor();
                setForeground(fg);
                return this;
            }
        };
    }
    return super.getCellRenderer(row, column);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)85 Component (java.awt.Component)30 TableColumn (javax.swing.table.TableColumn)30 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 JComponent (javax.swing.JComponent)12 JTable (javax.swing.JTable)12 JTableHeader (javax.swing.table.JTableHeader)12 TableColumnModel (javax.swing.table.TableColumnModel)12 MouseEvent (java.awt.event.MouseEvent)10 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 JLabel (javax.swing.JLabel)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 JButton (javax.swing.JButton)7 TableCellEditor (javax.swing.table.TableCellEditor)7 ActionEvent (java.awt.event.ActionEvent)6 MouseAdapter (java.awt.event.MouseAdapter)6 List (java.util.List)6 TableModel (javax.swing.table.TableModel)6 JTextField (javax.swing.JTextField)5 ActionListener (java.awt.event.ActionListener)4