Search in sources :

Example 1 with DrawingSupplier

use of org.jfree.chart.plot.DrawingSupplier in project processdash by dtuma.

the class StandardDiscItemRenderer method setPaintKeyMapper.

/**
     * Install an object that maps data keys to paint keys
     * @since 2.2.1
     */
public void setPaintKeyMapper(PaintKeyMapper paintKeyMapper) {
    this.paintKeyMapper = paintKeyMapper;
    this.discPaintMap = new PaintMap();
    DrawingSupplier ds = getDrawingSupplier();
    if (paintKeyMapper != null && ds != null) {
        try {
            Collection<Comparable> keys = paintKeyMapper.getAllPaintKeys();
            Paint bg = plot.getBackgroundPaint();
            for (Comparable oneKey : new TreeSet<Comparable>(keys)) {
                Paint onePaint = ds.getNextPaint();
                if (onePaint instanceof Color && bg instanceof Color)
                    onePaint = PaintUtils.adjustForContrast((Color) onePaint, (Color) bg);
                this.discPaintMap.put(oneKey, onePaint);
            }
        } catch (Throwable t) {
        // the "getAllPaintKeys" method was added in PD 2.3. If a
        // particular implementor doesn't support it yet, catch the
        // error and continue without preassigning colors.
        }
    }
}
Also used : PaintMap(org.jfree.chart.PaintMap) TreeSet(java.util.TreeSet) Color(java.awt.Color) DrawingSupplier(org.jfree.chart.plot.DrawingSupplier) Paint(java.awt.Paint)

Example 2 with DrawingSupplier

use of org.jfree.chart.plot.DrawingSupplier in project processdash by dtuma.

the class StandardDiscItemRenderer method lookupDiscPaint.

/**
     * Returns the paint for the specified disc.
     * 
     * @param key
     *                the disc key.
     * @param autoPopulate
     *                a flag that controls whether the drawing supplier is used
     *                to auto-populate the disc paint settings.
     * 
     * @return The paint.
     */
protected Paint lookupDiscPaint(Comparable key, boolean autoPopulate) {
    // if a paint key mapper is in effect, use it to translate the key
    if (paintKeyMapper != null)
        key = paintKeyMapper.getPaintKey(key);
    // see if this is the key for the base color
    if (key.equals(baseDiscPaintKey))
        return baseDiscPaint;
    // check if there is a paint defined for the specified key
    Paint result = this.discPaintMap.getPaint(key);
    if (result != null) {
        return result;
    }
    // nothing defined - do we autoPopulate?
    if (autoPopulate) {
        DrawingSupplier ds = getDrawingSupplier();
        if (ds != null) {
            result = ds.getNextPaint();
            Paint bg = plot.getBackgroundPaint();
            if (result instanceof Color && bg instanceof Color) {
                result = PaintUtils.adjustForContrast((Color) result, (Color) bg);
            }
            this.discPaintMap.put(key, result);
        } else {
            result = this.baseDiscPaint;
        }
    } else {
        result = this.baseDiscPaint;
    }
    return result;
}
Also used : Color(java.awt.Color) DrawingSupplier(org.jfree.chart.plot.DrawingSupplier) Paint(java.awt.Paint)

Aggregations

Color (java.awt.Color)2 Paint (java.awt.Paint)2 DrawingSupplier (org.jfree.chart.plot.DrawingSupplier)2 TreeSet (java.util.TreeSet)1 PaintMap (org.jfree.chart.PaintMap)1