19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import java.awt.BorderLayout;
22 import java.awt.Color;
24 import java.text.DecimalFormat;
25 import java.util.List;
26 import javax.swing.JLabel;
27 import org.jfree.chart.ChartFactory;
28 import org.jfree.chart.ChartPanel;
29 import org.jfree.chart.JFreeChart;
30 import org.jfree.chart.labels.PieSectionLabelGenerator;
31 import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
32 import org.jfree.chart.plot.PiePlot;
33 import org.jfree.data.general.DefaultPieDataset;
34 import org.openide.util.NbBundle.Messages;
40 "PieChartPanel_noDataLabel=No Data"
44 private static final long serialVersionUID = 1L;
46 private static final Font DEFAULT_FONT =
new JLabel().getFont();
52 private static final double NEAR_ZERO = Math.ulp(1d);
53 private static final Color NO_DATA_COLOR = Color.WHITE;
54 private static final double DEFAULT_CHART_PADDING = .1;
56 private static final Font DEFAULT_HEADER_FONT =
new Font(DEFAULT_FONT.getName(), DEFAULT_FONT.getStyle(), (int) (DEFAULT_FONT.getSize() * 1.5));
57 private static final PieSectionLabelGenerator DEFAULT_LABEL_GENERATOR
58 =
new StandardPieSectionLabelGenerator(
59 "{0}: {1} ({2})",
new DecimalFormat(
"#,###"),
new DecimalFormat(
"0.0%"));
61 private final ChartMessageOverlay overlay =
new ChartMessageOverlay();
62 private final DefaultPieDataset<String> dataset =
new DefaultPieDataset<>();
64 private final PiePlot<String>
plot;
66 @SuppressWarnings(
"unchecked")
67 private static PiePlot<String> getTypedPlot(JFreeChart chart) {
68 return ((PiePlot<String>) chart.getPlot());
86 this.chart = ChartFactory.createPieChart(
93 chart.setBackgroundPaint(null);
94 chart.getTitle().setFont(DEFAULT_HEADER_FONT);
95 this.plot = getTypedPlot(chart);
96 plot.setInteriorGap(DEFAULT_CHART_PADDING);
97 plot.setLabelGenerator(DEFAULT_LABEL_GENERATOR);
98 plot.setLabelFont(DEFAULT_FONT);
99 plot.setBackgroundPaint(null);
100 plot.setOutlinePaint(null);
103 ChartPanel panel =
new ChartPanel(chart);
104 panel.addOverlay(overlay);
105 panel.setPopupMenu(null);
107 this.setLayout(
new BorderLayout());
108 this.add(panel, BorderLayout.CENTER);
115 return (this.chart == null || this.chart.getTitle() == null)
117 : this.chart.getTitle().getText();
128 this.chart.
getTitle().setText(title);
134 this.overlay.setVisible(visible);
135 this.overlay.setMessage(message);
140 this.dataset.clear();
141 this.plot.clearSectionPaints(
false);
143 if (data != null && !data.isEmpty()) {
145 this.dataset.setValue(slice.getLabel(), slice.getValue());
146 if (slice.getColor() != null) {
147 this.plot.setSectionPaint(slice.getLabel(), slice.getColor());
154 this.dataset.setValue(Bundle.PieChartPanel_noDataLabel(), NEAR_ZERO);
155 this.plot.setSectionPaint(Bundle.PieChartPanel_noDataLabel(), NO_DATA_COLOR);
167 setMessage(
true, message);
PieChartPanel setTitle(String title)
void setResults(List< PieChartItem > data)
PieChartPanel(String title)
synchronized void showDataWithMessage(List< PieChartItem > data, String message)
void setMessage(boolean visible, String message)
final PiePlot< String > plot