Example usage for org.jfree.data.general SelectionChangeListener SelectionChangeListener

List of usage examples for org.jfree.data.general SelectionChangeListener SelectionChangeListener

Introduction

In this page you can find the example usage for org.jfree.data.general SelectionChangeListener SelectionChangeListener.

Prototype

SelectionChangeListener

Source Link

Usage

From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset,
        DatasetSelectionExtension<PieCursor<String>> ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset);

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("One", new Color(160, 160, 255));
    plot.setSectionPaint("Two", new Color(128, 128, 255 - 32));
    plot.setSectionPaint("Three", new Color(96, 96, 255 - 64));
    plot.setSectionPaint("Four", new Color(64, 64, 255 - 96));
    plot.setSectionPaint("Five", new Color(32, 32, 255 - 128));
    plot.setSectionPaint("Six", new Color(0, 0, 255 - 144));

    plot.setNoDataMessage("No data available");

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)"));
    plot.setLabelBackgroundPaint(new Color(220, 220, 220));

    plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    plot.setSimpleLabels(true);/*from w w w. ja  v  a 2 s  . c o  m*/
    plot.setInteriorGap(0.1);

    //pie plots done use abstract renderers need to react to selection on our own
    final PieCursor<String> cursor = new PieCursor<String>();

    ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() {
        public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) {
            for (int i = 0; i < dataset.getItemCount(); i++) {
                cursor.setPosition((String) dataset.getKey(i));
                if (event.getSelectionExtension().isSelected(cursor)) {
                    plot.setExplodePercent(cursor.key, 0.15);
                } else {
                    plot.setExplodePercent(cursor.key, 0.0);
                }
            }
        }
    });

    return chart;
}