Search in sources :

Example 1 with ColoredTableCellRenderer

use of com.intellij.ui.ColoredTableCellRenderer in project android by JetBrains.

the class NlMarginPropertyAccumulator method createTableCellRenderer.

private static ColoredTableCellRenderer createTableCellRenderer() {
    return new ColoredTableCellRenderer() {

        @Override
        protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
            assert value instanceof MarginGroupNode;
            MarginGroupNode node = (MarginGroupNode) value;
            NlMarginPropertyAccumulator accumulator = node.getAccumulator();
            append("[");
            append(node, accumulator.myAllMargin, null);
            append(", ");
            append(node, accumulator.myLeftMargin, accumulator.myStartMargin);
            append(", ");
            append(node, accumulator.myTopMargin, null);
            append(", ");
            append(node, accumulator.myRightMargin, accumulator.myEndMargin);
            append(", ");
            append(node, accumulator.myBottomMargin, null);
            append("]");
        }

        private void append(@NotNull MarginGroupNode node, @NotNull String propertyName, @Nullable String propertyOverride) {
            SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
            PTableItem property = node.getItemByName(propertyName);
            PTableItem override = propertyOverride != null ? node.getItemByName(propertyOverride) : null;
            String value = null;
            if (override != null) {
                value = override.getResolvedValue();
                if (!override.isDefaultValue(value)) {
                    attributes = SimpleTextAttributes.SYNTHETIC_ATTRIBUTES;
                }
            }
            if (property != null && value == null) {
                value = property.getResolvedValue();
                if (!property.isDefaultValue(value)) {
                    attributes = SimpleTextAttributes.SYNTHETIC_ATTRIBUTES;
                }
            }
            if (value == null) {
                value = "?";
            }
            append(value, attributes);
        }
    };
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem) NotNull(org.jetbrains.annotations.NotNull) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ColoredTableCellRenderer

use of com.intellij.ui.ColoredTableCellRenderer 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)

Aggregations

ColoredTableCellRenderer (com.intellij.ui.ColoredTableCellRenderer)2 Nullable (org.jetbrains.annotations.Nullable)2 PTableItem (com.android.tools.idea.uibuilder.property.ptable.PTableItem)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 DualView (com.intellij.ui.dualView.DualView)1 TreeTableView (com.intellij.ui.dualView.TreeTableView)1 TableCellRenderer (javax.swing.table.TableCellRenderer)1 NotNull (org.jetbrains.annotations.NotNull)1