Search in sources :

Example 71 with TableCellRenderer

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

the class TableLinkMouseListener method getTagAt.

@Override
@Nullable
public Object getTagAt(@NotNull final MouseEvent e) {
    // TODO[yole]: don't update renderer on every event, like it's done in TreeLinkMouseListener
    Object tag;
    JTable table = (JTable) e.getSource();
    int row = table.rowAtPoint(e.getPoint());
    int column = table.columnAtPoint(e.getPoint());
    if (row == -1 || column == -1)
        return null;
    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    if (cellRenderer instanceof DualView.TableCellRendererWrapper) {
        cellRenderer = ((DualView.TableCellRendererWrapper) cellRenderer).getRenderer();
    }
    if (cellRenderer instanceof TreeTableView.CellRendererWrapper) {
        cellRenderer = ((TreeTableView.CellRendererWrapper) cellRenderer).getBaseRenderer();
    }
    if (cellRenderer instanceof ColoredTableCellRenderer) {
        final ColoredTableCellRenderer renderer = (ColoredTableCellRenderer) cellRenderer;
        tag = forColoredRenderer(e, table, row, column, renderer);
    } else {
        tag = tryGetTag(e, table, row, column);
    }
    return tag;
}
Also used : ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DualView(com.intellij.ui.dualView.DualView) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) TreeTableView(com.intellij.ui.dualView.TreeTableView) Nullable(org.jetbrains.annotations.Nullable)

Example 72 with TableCellRenderer

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

the class TreeTableView method getCellRenderer.

public TableCellRenderer getCellRenderer(int row, int column) {
    TableCellRenderer renderer = getColumnInfo(column).getRenderer(getRowElement(row));
    final TableCellRenderer baseRenderer = renderer == null ? super.getCellRenderer(row, column) : renderer;
    return new CellRendererWrapper(baseRenderer);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 73 with TableCellRenderer

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

the class MultiColumnList method setCellRenderer.

public void setCellRenderer(ListCellRenderer renderer) {
    myRenderer = renderer;
    setDefaultRenderer(Object.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            final int index = getModel().toListIndex(row, column);
            if (isSelected) {
                myList.addSelectionInterval(index, index);
            } else {
                myList.removeSelectionInterval(index, index);
            }
            return myRenderer.getListCellRendererComponent(myList, value, index, isSelected, hasFocus);
        }
    });
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 74 with TableCellRenderer

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

the class MultiColumnList method getPreferredSize.

@Override
public Dimension getPreferredSize() {
    if (myPrefSize == null) {
        Dimension dimension = new Dimension();
        int rowHeight = 0;
        for (int column = 0; column < getColumnCount(); column++) {
            int columnWidth = 0;
            for (int row = 0; row < getRowCount(); row++) {
                final TableCellRenderer renderer = getCellRenderer(row, column);
                if (renderer != null) {
                    final Object value = getValueAt(row, column);
                    final Component component = renderer.getTableCellRendererComponent(this, value, true, true, row, column);
                    if (component != null) {
                        final Dimension size = component.getPreferredSize();
                        rowHeight = Math.max(size.height, rowHeight);
                        columnWidth = Math.max(size.width, columnWidth);
                    }
                }
            }
            getColumnModel().getColumn(column).setWidth(columnWidth + 5);
            dimension.width += columnWidth + 5;
        }
        dimension.height = getRowCount() * rowHeight;
        myPrefSize = dimension;
    }
    return myPrefSize;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 75 with TableCellRenderer

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

the class SwingHelper method setNoBorderCellRendererFor.

public static void setNoBorderCellRendererFor(@NotNull TableColumn column) {
    final TableCellRenderer previous = column.getCellRenderer();
    column.setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component component;
            if (previous != null) {
                component = previous.getTableCellRendererComponent(table, value, isSelected, false, row, column);
            } else {
                component = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
            }
            if (component instanceof JComponent) {
                ((JComponent) component).setBorder(null);
            }
            return component;
        }
    });
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)122 TableColumn (javax.swing.table.TableColumn)50 Component (java.awt.Component)47 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)24 JComponent (javax.swing.JComponent)20 JTable (javax.swing.JTable)20 TableColumnModel (javax.swing.table.TableColumnModel)18 JLabel (javax.swing.JLabel)17 JTableHeader (javax.swing.table.JTableHeader)17 MouseEvent (java.awt.event.MouseEvent)11 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 MouseAdapter (java.awt.event.MouseAdapter)7 TableCellEditor (javax.swing.table.TableCellEditor)7 TableModel (javax.swing.table.TableModel)7 ActionListener (java.awt.event.ActionListener)6 List (java.util.List)6 JPanel (javax.swing.JPanel)6