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;
}
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]);
}
}
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;
}
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);
}
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);
}
Aggregations