org.jdesktop.swingx.decorator.ComponentAdapter Java Examples

The following examples show how to use org.jdesktop.swingx.decorator.ComponentAdapter. 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 File: AjaxSpiderResultsTable.java    From zap-extensions with 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 File: AccessControlStatusPanel.java    From zap-extensions with 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 File: RelativePainterHighlighter.java    From BART with 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 #4
Source File: DSWorkbenchFarmManager.java    From dsworkbench with 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 #5
Source File: GroupPredicate.java    From dsworkbench with 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 #6
Source File: RelativePainterHighlighter.java    From BART with 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 #7
Source File: RelativePainterHighlighter.java    From BART with 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 #8
Source File: RelativePainterHighlighter.java    From BART with 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 #9
Source File: RelativePainterHighlighter.java    From BART with 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 #10
Source File: HttpFuzzerResultsTable.java    From zap-extensions with 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 File: GanttTree2.java    From ganttproject with 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 #12
Source File: GroupPredicate.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
    return isHighlightCandidate(adapter) && test(adapter);
}
 
Example #13
Source File: RelativePainterHighlighter.java    From BART with MIT License 4 votes vote down vote up
@Override 
protected boolean canHighlight(Component component, ComponentAdapter adapter) { 
    return relativizer != null && super.canHighlight(component, adapter); 
}
 
Example #14
Source File: AjaxSpiderResultsTable.java    From zap-extensions with 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 File: RelativePainterHighlighter.java    From BART with 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 #16
Source File: AccessControlStatusPanel.java    From zap-extensions with 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 File: HttpFuzzerResultsTable.java    From zap-extensions with 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 #18
Source File: RelativePainterHighlighter.java    From BART with 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);
 
Example #19
Source File: GroupPredicate.java    From dsworkbench with 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)));
}