Search in sources :

Example 1 with ComponentAdapter

use of org.jdesktop.swingx.decorator.ComponentAdapter in project com.revolsys.open by revolsys.

the class BaseJTable method addLastRowBorderPredicate.

protected void addLastRowBorderPredicate() {
    final HighlightPredicate lastPredicate = (final Component renderer, final ComponentAdapter adapter) -> {
        final int row = adapter.row;
        final int lastRowIndex = getRowCount() - 1;
        return row == lastRowIndex;
    };
    addHighlighter(new BorderHighlighter(lastPredicate, BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(191, 191, 191))));
}
Also used : Color(java.awt.Color) HighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate) BorderHighlighter(org.jdesktop.swingx.decorator.BorderHighlighter) JComponent(javax.swing.JComponent) Component(java.awt.Component) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter)

Example 2 with ComponentAdapter

use of org.jdesktop.swingx.decorator.ComponentAdapter in project com.revolsys.open by revolsys.

the class LabelCountMapTableModel method newTable.

public BaseJTable newTable() {
    final BaseJTable table = new BaseJTable(this);
    setTable(table);
    final TableColumnModel columnModel = table.getColumnModel();
    for (int columnIndex = 0; columnIndex < getColumnCount(); columnIndex++) {
        final int columnIndex1 = columnIndex;
        final TableColumn column = columnModel.getColumn(columnIndex1);
        setColumnWidth(columnIndex1, column);
    }
    table.setAutoCreateColumnsFromModel(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    final RowSorter<? extends TableModel> rowSorter = table.getRowSorter();
    final SortKey sortKey = new SortKey(0, SortOrder.ASCENDING);
    rowSorter.setSortKeys(Arrays.asList(sortKey));
    table.addHighlighter(new ColorHighlighter((final Component renderer, final ComponentAdapter adapter) -> {
        final int row = adapter.convertRowIndexToModel(adapter.row);
        if (getValueAt(row, 0).equals(LabelCountMapTableModel.this.selectedLabel)) {
            return true;
        }
        return false;
    }, WebColors.ForestGreen, WebColors.Yellow, WebColors.DarkGreen, WebColors.Yellow));
    table.addHighlighter(new ColorHighlighter((final Component renderer, final ComponentAdapter adapter) -> {
        final int column = adapter.convertColumnIndexToModel(adapter.column);
        final int row = adapter.convertRowIndexToModel(adapter.row);
        if (getValueAt(row, 0).equals(LabelCountMapTableModel.this.selectedLabel)) {
            if (getColumnName(column).equals(LabelCountMapTableModel.this.selectedCountName)) {
                return true;
            }
        }
        return false;
    }, WebColors.Yellow, WebColors.DarkGreen, WebColors.Gold, WebColors.DarkGreen));
    return table;
}
Also used : ColorHighlighter(org.jdesktop.swingx.decorator.ColorHighlighter) BaseJTable(com.revolsys.swing.table.BaseJTable) TableColumnModel(javax.swing.table.TableColumnModel) SortKey(javax.swing.RowSorter.SortKey) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter)

Example 3 with ComponentAdapter

use of org.jdesktop.swingx.decorator.ComponentAdapter in project com.revolsys.open by revolsys.

the class RecordValidationDialog method newInvalidRecordsTablePanel.

private TablePanel newInvalidRecordsTablePanel() {
    final RecordDefinition recordDefinition = this.layer.getRecordDefinition();
    final List<String> fieldNames = this.layer.getFieldNames();
    final RecordListTableModel model = new RecordListTableModel(recordDefinition, this.invalidRecords, fieldNames);
    model.setReadOnlyFieldNames(this.layer.getUserReadOnlyFieldNames());
    final RecordRowTable table = new RecordRowTable(model);
    table.setVisibleRowCount(Math.min(10, model.getRowCount() + 1));
    table.setSortable(true);
    table.resizeColumnsToContent();
    final HighlightPredicate invalidFieldPredicate = (final Component renderer, final ComponentAdapter adapter) -> {
        try {
            final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
            final int columnIndex = adapter.convertColumnIndexToModel(adapter.column);
            final Map<String, String> fieldErrors = this.invalidRecordErrors.get(rowIndex);
            if (!fieldErrors.isEmpty()) {
                final String fieldName = this.layer.getFieldName(columnIndex);
                final String errorMessage = fieldErrors.get(fieldName);
                if (Property.hasValue(errorMessage)) {
                    final JComponent jcomponent = (JComponent) renderer;
                    jcomponent.setToolTipText(errorMessage);
                    return true;
                }
            }
        } catch (final Throwable e) {
        }
        return false;
    };
    final Highlighter invalidFieldHighlighter = new ColorHighlighter(invalidFieldPredicate, WebColors.newAlpha(Color.RED, 64), Color.RED, Color.RED, Color.YELLOW);
    table.addHighlighter(invalidFieldHighlighter);
    final HighlightPredicate validRecordPredicate = (final Component renderer, final ComponentAdapter adapter) -> {
        try {
            final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
            final Map<String, String> fieldErrors = this.invalidRecordErrors.get(rowIndex);
            if (fieldErrors.isEmpty()) {
                return true;
            }
        } catch (final Throwable e) {
        }
        return false;
    };
    table.addHighlighter(new ColorHighlighter(new AndHighlightPredicate(validRecordPredicate, HighlightPredicate.EVEN), WebColors.newAlpha(WebColors.LimeGreen, 127), WebColors.Black, WebColors.newAlpha(WebColors.DarkGreen, 191), Color.WHITE));
    table.addHighlighter(new ColorHighlighter(new AndHighlightPredicate(validRecordPredicate, HighlightPredicate.ODD), WebColors.LimeGreen, WebColors.Black, WebColors.DarkGreen, Color.WHITE));
    final TablePanel tablePanel = new TablePanel(table);
    tablePanel.setBorder(BorderFactory.createTitledBorder(table.getRowCount() + " invalid records"));
    return tablePanel;
}
Also used : JComponent(javax.swing.JComponent) RecordDefinition(com.revolsys.record.schema.RecordDefinition) ColorHighlighter(com.revolsys.swing.table.highlighter.ColorHighlighter) HighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate) AndHighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate) JComponent(javax.swing.JComponent) Component(java.awt.Component) AndHighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate) HashMap(java.util.HashMap) Map(java.util.Map) RecordListTableModel(com.revolsys.swing.table.record.model.RecordListTableModel) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) Highlighter(org.jdesktop.swingx.decorator.Highlighter) ColorHighlighter(com.revolsys.swing.table.highlighter.ColorHighlighter) TablePanel(com.revolsys.swing.table.TablePanel)

Aggregations

Component (java.awt.Component)3 ComponentAdapter (org.jdesktop.swingx.decorator.ComponentAdapter)3 JComponent (javax.swing.JComponent)2 HighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 BaseJTable (com.revolsys.swing.table.BaseJTable)1 TablePanel (com.revolsys.swing.table.TablePanel)1 ColorHighlighter (com.revolsys.swing.table.highlighter.ColorHighlighter)1 RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)1 RecordListTableModel (com.revolsys.swing.table.record.model.RecordListTableModel)1 Color (java.awt.Color)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortKey (javax.swing.RowSorter.SortKey)1 TableColumn (javax.swing.table.TableColumn)1 TableColumnModel (javax.swing.table.TableColumnModel)1 BorderHighlighter (org.jdesktop.swingx.decorator.BorderHighlighter)1 ColorHighlighter (org.jdesktop.swingx.decorator.ColorHighlighter)1 AndHighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate)1 Highlighter (org.jdesktop.swingx.decorator.Highlighter)1