Search in sources :

Example 21 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class DefaultPolarItemRenderer method getLegendItem.

/**
 * Return the legend for the given series.
 *
 * @param series  the series index.
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int series) {
    LegendItem result;
    PolarPlot plot = getPlot();
    if (plot == null) {
        return null;
    }
    XYDataset dataset = plot.getDataset(plot.getIndexOf(this));
    if (dataset == null) {
        return null;
    }
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Comparable seriesKey = dataset.getSeriesKey(series);
    String label = seriesKey.toString();
    String description = label;
    Shape shape = lookupSeriesShape(series);
    Paint paint;
    if (this.useFillPaint) {
        paint = lookupSeriesFillPaint(series);
    } else {
        paint = lookupSeriesPaint(series);
    }
    Stroke stroke = lookupSeriesStroke(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean shapeOutlined = isSeriesFilled(series) && this.drawOutlineWhenFilled;
    result = new LegendItem(label, description, toolTipText, urlText, getShapesVisible(), shape, /* shapeFilled=*/
    true, paint, shapeOutlined, outlinePaint, outlineStroke, /* lineVisible= */
    true, this.legendLine, stroke, paint);
    result.setToolTipText(toolTipText);
    result.setURLText(urlText);
    result.setDataset(dataset);
    result.setSeriesKey(seriesKey);
    result.setSeriesIndex(series);
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) PolarPlot(org.jfree.chart.plot.PolarPlot) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint)

Example 22 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class WaferMapRenderer method getLegendCollection.

/**
 * Builds the list of legend entries.  called by getLegendItems in
 * WaferMapPlot to populate the plot legend.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendCollection() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.paintIndex != null && this.paintIndex.size() > 0) {
        if (this.paintIndex.size() <= this.paintLimit) {
            for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext(); ) {
                // in this case, every color has a unique value
                Map.Entry entry = (Map.Entry) i.next();
                String label = entry.getKey().toString();
                String description = label;
                Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
                Paint paint = lookupSeriesPaint(((Integer) entry.getValue()).intValue());
                Paint outlinePaint = Color.black;
                Stroke outlineStroke = DEFAULT_STROKE;
                result.add(new LegendItem(label, description, null, null, shape, paint, outlineStroke, outlinePaint));
            }
        } else {
            // in this case, every color has a range of values
            Set unique = new HashSet();
            for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry entry = (Map.Entry) i.next();
                if (unique.add(entry.getValue())) {
                    String label = getMinPaintValue((Integer) entry.getValue()).toString() + " - " + getMaxPaintValue((Integer) entry.getValue()).toString();
                    String description = label;
                    Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
                    Paint paint = getSeriesPaint(((Integer) entry.getValue()).intValue());
                    Paint outlinePaint = Color.black;
                    Stroke outlineStroke = DEFAULT_STROKE;
                    result.add(new LegendItem(label, description, null, null, shape, paint, outlineStroke, outlinePaint));
                }
            }
        // end foreach map entry
        }
    // end else
    }
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) Set(java.util.Set) HashSet(java.util.HashSet) LegendItemCollection(org.jfree.chart.LegendItemCollection) Paint(java.awt.Paint) LegendItem(org.jfree.chart.LegendItem) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class AreaRenderer method getLegendItem.

/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    // if there is no plot, there is no dataset to access...
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }
    CategoryDataset dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    LegendItem result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 24 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class XYDifferenceRenderer method getLegendItem.

/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    LegendItem result = null;
    XYPlot p = getPlot();
    if (p != null) {
        XYDataset dataset = p.getDataset(datasetIndex);
        if (dataset != null) {
            if (getItemVisible(series, 0)) {
                String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
                String description = label;
                String toolTipText = null;
                if (getLegendItemToolTipGenerator() != null) {
                    toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
                }
                String urlText = null;
                if (getLegendItemURLGenerator() != null) {
                    urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
                }
                Paint paint = lookupSeriesPaint(series);
                Stroke stroke = lookupSeriesStroke(series);
                Shape line = getLegendLine();
                result = new LegendItem(label, description, toolTipText, urlText, line, stroke, paint);
                result.setLabelFont(lookupLegendTextFont(series));
                Paint labelPaint = lookupLegendTextPaint(series);
                if (labelPaint != null) {
                    result.setLabelPaint(labelPaint);
                }
                result.setDataset(dataset);
                result.setDatasetIndex(datasetIndex);
                result.setSeriesKey(dataset.getSeriesKey(series));
                result.setSeriesIndex(series);
            }
        }
    }
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.LegendItem) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint)

Example 25 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class XYDotRenderer method getLegendItem.

/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly <code>null</code>).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    // if the renderer isn't assigned to a plot, then we don't have a
    // dataset...
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }
    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    LegendItem result = null;
    if (getItemVisible(series, 0)) {
        String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String description = label;
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
            toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
            urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        Paint fillPaint = lookupSeriesPaint(series);
        result = new LegendItem(label, description, toolTipText, urlText, getLegendShape(), fillPaint);
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
            result.setLabelPaint(labelPaint);
        }
        result.setSeriesKey(dataset.getSeriesKey(series));
        result.setSeriesIndex(series);
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
    }
    return result;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.LegendItem) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint)

Aggregations

LegendItem (org.jfree.chart.LegendItem)51 Paint (java.awt.Paint)26 Test (org.junit.Test)25 NumberAxis (org.jfree.chart.axis.NumberAxis)20 JFreeChart (org.jfree.chart.JFreeChart)19 Stroke (java.awt.Stroke)18 XYPlot (org.jfree.chart.plot.XYPlot)18 Shape (java.awt.Shape)17 LegendItemCollection (org.jfree.chart.LegendItemCollection)17 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)13 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeries (org.jfree.data.xy.XYSeries)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 GradientPaint (java.awt.GradientPaint)7 BasicStroke (java.awt.BasicStroke)6 Iterator (java.util.Iterator)5 List (java.util.List)5