19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import java.awt.BorderLayout;
22 import java.awt.Color;
24 import java.util.Collections;
25 import java.util.List;
26 import javax.swing.JLabel;
27 import org.apache.commons.collections4.CollectionUtils;
28 import org.jfree.chart.ChartFactory;
29 import org.jfree.chart.ChartPanel;
30 import org.jfree.chart.JFreeChart;
31 import org.jfree.chart.axis.ValueAxis;
32 import org.jfree.chart.plot.CategoryPlot;
33 import org.jfree.chart.plot.PlotOrientation;
34 import org.jfree.chart.renderer.category.BarRenderer;
35 import org.jfree.chart.renderer.category.StandardBarPainter;
36 import org.jfree.data.category.DefaultCategoryDataset;
49 private final Comparable<?>
key;
51 private final List<BarChartItem>
items;
60 public BarChartSeries(Comparable<?> key, Color color, List<BarChartItem> items) {
63 this.items = (items == null) ? Collections.emptyList() : Collections.unmodifiableList(items);
93 private final Comparable<?>
key;
127 public static class OrderedKey implements Comparable<OrderedKey> {
147 Object getKeyValue() {
166 return Integer.compare(this.getKeyIndex(), o.getKeyIndex());
183 if (getClass() != obj.getClass()) {
187 if (this.keyIndex != other.
keyIndex) {
196 return this.getKeyValue() == null ? null : this.getKeyValue().toString();
203 private static final Font
DEFAULT_HEADER_FONT =
new Font(DEFAULT_FONT.getName(), DEFAULT_FONT.getStyle(), (int) (DEFAULT_FONT.getSize() * 1.5));
205 private final ChartMessageOverlay
overlay =
new ChartMessageOverlay();
206 private final DefaultCategoryDataset
dataset =
new DefaultCategoryDataset();
208 private final CategoryPlot
plot;
214 this(null, null, null);
224 public BarChartPanel(String title, String categoryLabel, String valueLabel) {
225 this.chart = ChartFactory.createStackedBarChart(
230 PlotOrientation.VERTICAL,
234 chart.setBackgroundPaint(null);
235 chart.getTitle().setFont(DEFAULT_HEADER_FONT);
237 this.plot = ((CategoryPlot) chart.getPlot());
238 this.plot.getRenderer().setBaseItemLabelFont(DEFAULT_FONT);
239 plot.setBackgroundPaint(null);
240 plot.setOutlinePaint(null);
243 ValueAxis range = plot.getRangeAxis();
244 range.setVisible(
false);
247 plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10);
249 ((BarRenderer) plot.getRenderer()).setBarPainter(
new StandardBarPainter());
252 ChartPanel panel =
new ChartPanel(chart);
253 panel.addOverlay(overlay);
254 panel.setPopupMenu(null);
256 this.setLayout(
new BorderLayout());
257 this.add(panel, BorderLayout.CENTER);
264 return (this.chart == null || this.chart.getTitle() == null)
266 : this.chart.getTitle().getText();
277 this.chart.
getTitle().setText(title);
283 this.overlay.setVisible(visible);
284 this.overlay.setMessage(message);
288 protected void setResults(List<BarChartPanel.BarChartSeries> data) {
289 this.dataset.clear();
291 if (CollectionUtils.isNotEmpty(data)) {
292 for (
int s = 0; s < data.size(); s++) {
294 if (series != null && CollectionUtils.isNotEmpty(series.getItems())) {
295 if (series.getColor() != null) {
296 this.plot.getRenderer().setSeriesPaint(s, series.getColor());
299 for (
int i = 0; i < series.getItems().size(); i++) {
301 this.dataset.setValue(bar.
getValue(), series.getKey(), bar.
getKey());
BarChartSeries(Comparable<?> key, Color color, List< BarChartItem > items)
BarChartItem(Comparable<?> key, double value)
final DefaultCategoryDataset dataset
List< BarChartItem > getItems()
int compareTo(OrderedKey o)
static final Font DEFAULT_FONT
OrderedKey(Object keyValue, int keyIndex)
final List< BarChartItem > items
void setResults(List< BarChartPanel.BarChartSeries > data)
final ChartMessageOverlay overlay
void setMessage(boolean visible, String message)
static final long serialVersionUID
BarChartPanel setTitle(String title)
static final Font DEFAULT_HEADER_FONT
boolean equals(Object obj)
BarChartPanel(String title, String categoryLabel, String valueLabel)