Java Code Examples for org.jdesktop.swingx.decorator.ComponentAdapter

The following examples show how to use org.jdesktop.swingx.decorator.ComponentAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: zap-extensions   Source File: AjaxSpiderResultsTable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Component doHighlight(Component component, ComponentAdapter adapter) {
    ProcessedCellItem cell = (ProcessedCellItem) adapter.getValue(columnIndex);

    boolean processed = cell.getState() == ResourceState.PROCESSED;
    Icon icon = getProcessedIcon(processed);
    if (component instanceof IconAware) {
        ((IconAware) component).setIcon(icon);
    } else if (component instanceof JLabel) {
        ((JLabel) component).setIcon(icon);
    }

    if (component instanceof JLabel) {
        ((JLabel) component).setText(processed ? "" : cell.getLabel());
    }

    return component;
}
 
Example 2
Source Project: zap-extensions   Source File: AccessControlStatusPanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Component doHighlight(Component component, ComponentAdapter adapter) {
    AccessControlNodeResult cell = (AccessControlNodeResult) adapter.getValue(columnIndex);

    Icon icon = getIcon(cell);
    if (component instanceof IconAware) {
        ((IconAware) component).setIcon(icon);
    } else if (component instanceof JLabel) {
        ((JLabel) component).setIcon(icon);
    }

    if (component instanceof JLabel) {
        ((JLabel) component).setToolTipText(cell.toString());
    }

    return component;
}
 
Example 3
Source Project: dsworkbench   Source File: DSWorkbenchFarmManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
    int row = adapter.convertRowIndexToModel(adapter.row);
    FarmInformation elem = (FarmInformation) FarmManager.getSingleton().getAllElements().get(row);
    switch(type) {
        case BARBARIAN:
            return elem.getVillage().getTribe().equals(Barbarians.getSingleton());
        case PLAYER:
            return !elem.getVillage().getTribe().equals(Barbarians.getSingleton());
    }
    return false;
}
 
Example 4
Source Project: dsworkbench   Source File: GroupPredicate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test the value. This is called only if the 
 * pre-check returned true, because accessing the 
 * value might be potentially costly
 */
private boolean test(ComponentAdapter adapter) {
    // single test column
    if (testColumn >= 0) {
        return testColumn(adapter, testColumn);
    }
    // test all
    for (int column = 0; column < adapter.getColumnCount(); column++) {
        boolean result = testColumn(adapter, column);
        if (result) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 5 votes vote down vote up
@Override 
protected Component doHighlight(Component component, 
        ComponentAdapter adapter) { 
    // <snip> Relative Decorator 
    // configures the RelativePainter with the value returned by the 
    // Relativizer 
    float xPercent = relativizer.getRelativeValue(adapter); 
    getPainter().setXFactor(xPercent); 
    getPainter().setVisible(xPercent != Relativizer.ZERO); 
    return super.doHighlight(component, adapter); 
    // </snip> 
}
 
Example 6
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 5 votes vote down vote up
@Override 
public float getRelativeValue(ComponentAdapter adapter) { 
    if (getNumber(adapter) == null) { 
        return ZERO; 
    } 
    float value = getNumber(adapter).floatValue(); 
    float limit = Math.min(getCurrent().floatValue(), value); 
    if (isZero(limit)) { 
        return ZERO; 
    } 
    float percent = limit / getMax().floatValue(); 
  
    if (!spread) { 
        return percent; 
    } 
  
    int width = adapter.getComponent().getWidth(); 
    int pixelLocation = (int) (percent * width); 
    int visualColumn = getColumnAt(adapter, pixelLocation); 
    if (adapter.column < visualColumn) { 
        return ONE; 
    } else if (adapter.column > visualColumn) { 
        return ZERO; 
    } 
  
    int visualColumnWidth = getColumnWidth(adapter, visualColumn); 
    int startColumn = getColumnLocation(adapter, visualColumn); 
    int valueWidth = pixelLocation - startColumn; 
    return (float) valueWidth / (float) visualColumnWidth; 
    // </snip> 
}
 
Example 7
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 5 votes vote down vote up
private int getColumnLocation(ComponentAdapter adapter, int visualColumn) { 
    if (!(adapter.getComponent() instanceof JXTable)) { 
        return 0; 
    } 
    JXTable table = (JXTable) adapter.getComponent(); 
    // PENDING JW: guard against null header 
    return table.getTableHeader().getHeaderRect(visualColumn).x; 
}
 
Example 8
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 5 votes vote down vote up
private int getColumnWidth(ComponentAdapter adapter, int visualColumn) { 
    if (!(adapter.getComponent() instanceof JXTable)) { 
        return adapter.getComponent().getWidth(); 
    } 
    JXTable table = (JXTable) adapter.getComponent(); 
    return table.getColumn(visualColumn).getWidth(); 
}
 
Example 9
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 5 votes vote down vote up
private int getColumnAt(ComponentAdapter adapter, int pixelLocation) { 
    if (!(adapter.getComponent() instanceof JXTable)) { 
        return 0; 
    } 
    JXTable table = (JXTable) adapter.getComponent(); 
    // PENDING JW: guard against null header 
    return table.getTableHeader().columnAtPoint( 
            new Point(pixelLocation, 10)); 
}
 
Example 10
Source Project: zap-extensions   Source File: HttpFuzzerResultsTable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Component doHighlight(Component component, ComponentAdapter adapter) {
    @SuppressWarnings("unchecked")
    Map<String, Object> data =
            new HashMap<>((Map<String, Object>) adapter.getValue(columnIndex));

    StringBuilder labelBuilder = new StringBuilder();
    boolean iconSet = false;
    for (HttpFuzzerResultStateHighlighter highlighter : highlighters) {
        if (highlighter.isHighlighted(data)) {
            if (!iconSet) {
                if (component instanceof IconAware) {
                    ((IconAware) component).setIcon(highlighter.getIcon());
                    iconSet = true;
                } else if (component instanceof JLabel) {
                    ((JLabel) component).setIcon(highlighter.getIcon());
                    iconSet = true;
                }
            }

            if (component instanceof JLabel) {
                append(labelBuilder, highlighter.getLabel());
            }
            highlighter.removeState(data);
        }
    }

    for (Object value : data.values()) {
        append(labelBuilder, value);
    }

    if (!iconSet) {
        if (component instanceof IconAware) {
            ((IconAware) component).setIcon(null);
        } else if (component instanceof JLabel) {
            ((JLabel) component).setIcon(null);
        }
    }

    if (component instanceof JLabel) {
        ((JLabel) component).setText(labelBuilder.toString());
    }

    return component;
}
 
Example 11
Source Project: dsworkbench   Source File: GroupPredicate.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
    return isHighlightCandidate(adapter) && test(adapter);
}
 
Example 12
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 4 votes vote down vote up
@Override 
protected boolean canHighlight(Component component, ComponentAdapter adapter) { 
    return relativizer != null && super.canHighlight(component, adapter); 
}
 
Example 13
Source Project: ganttproject   Source File: GanttTree2.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isHighlighted(Component arg0, ComponentAdapter adapter) {
  return myOverRow == adapter.row;
}
 
Example 14
Source Project: zap-extensions   Source File: AjaxSpiderResultsTable.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to return true if the component is of type IconAware or of type JLabel,
 * false otherwise.
 *
 * <p>Note: special casing JLabel is for backward compatibility - application highlighting
 * code which doesn't use the Swingx renderers would stop working otherwise.
 */
// Method/JavaDoc copied from
// org.jdesktop.swingx.decorator.IconHighlighter#canHighlight(Component, ComponentAdapter)
@Override
protected boolean canHighlight(final Component component, final ComponentAdapter adapter) {
    return component instanceof IconAware || component instanceof JLabel;
}
 
Example 15
Source Project: zap-extensions   Source File: HttpFuzzerResultsTable.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to return true if the component is of type IconAware or of type JLabel,
 * false otherwise.
 *
 * <p>Note: special casing JLabel is for backward compatibility - application highlighting
 * code which doesn't use the Swingx renderers would stop working otherwise.
 */
// Method/JavaDoc copied from
// org.jdesktop.swingx.decorator.IconHighlighter#canHighlight(Component, ComponentAdapter)
@Override
protected boolean canHighlight(final Component component, final ComponentAdapter adapter) {
    return component instanceof IconAware || component instanceof JLabel;
}
 
Example 16
Source Project: zap-extensions   Source File: AccessControlStatusPanel.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to return true if the component is of type IconAware or of type JLabel,
 * false otherwise.
 *
 * <p>Note: special casing JLabel is for backward compatibility - application highlighting
 * code which doesn't use the Swingx renderers would stop working otherwise.
 */
// Method/JavaDoc copied from
// org.jdesktop.swingx.decorator.IconHighlighter#canHighlight(Component, ComponentAdapter)
@Override
protected boolean canHighlight(final Component component, final ComponentAdapter adapter) {
    return component instanceof IconAware || component instanceof JLabel;
}
 
Example 17
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 3 votes vote down vote up
/** 
 * Returns a Number representation of the cell value or null if it 
 * doesn't have any. Subclasses are meant to override this for custom 
 * mappings. 
 * <p> 
 *  
 * This implementation checks and returns the type of the current cell. 
 *  
 * @param adapter the ComponentAdapter which defines the current cell. 
 * @return a Number representing the current cell or null 
 */ 
// <snip> Relativizer 
// simple value-to-Number mapping which handles Number types. 
protected Number getNumber(ComponentAdapter adapter) { 
    if (adapter.getValue() instanceof Number) 
        return (Number) adapter.getValue(valueColumn); 
    return null; 
}
 
Example 18
Source Project: dsworkbench   Source File: GroupPredicate.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * A quick pre-check.
 * @param adapter
 * 
 * @return
 */
private boolean isHighlightCandidate(ComponentAdapter adapter) {
    return (groups != null)
            && ((highlightColumn < 0)
            || (highlightColumn == adapter.convertColumnIndexToModel(adapter.column)));
}
 
Example 19
Source Project: BART   Source File: RelativePainterHighlighter.java    License: MIT License 2 votes vote down vote up
/** 
 * Returns a float in the range of 0.0f to 1.0f inclusive which 
 * indicates the relative value of the given adapter's value. 
 *  
 * @param adapter 
 * @return 
 */ 
public float getRelativeValue(ComponentAdapter adapter);