19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import java.awt.BorderLayout;
23 import java.util.List;
24 import javax.swing.JLabel;
25 import org.apache.commons.collections4.CollectionUtils;
26 import org.jfree.chart.ChartFactory;
27 import org.jfree.chart.ChartPanel;
28 import org.jfree.chart.JFreeChart;
29 import org.jfree.chart.axis.ValueAxis;
30 import org.jfree.chart.plot.CategoryPlot;
31 import org.jfree.chart.plot.PlotOrientation;
32 import org.jfree.chart.renderer.category.BarRenderer;
33 import org.jfree.chart.renderer.category.StandardBarPainter;
34 import org.jfree.data.category.DefaultCategoryDataset;
45 private static final Font
DEFAULT_HEADER_FONT =
new Font(DEFAULT_FONT.getName(), DEFAULT_FONT.getStyle(), (int) (DEFAULT_FONT.getSize() * 1.5));
47 private final ChartMessageOverlay
overlay =
new ChartMessageOverlay();
48 private final DefaultCategoryDataset
dataset =
new DefaultCategoryDataset();
50 private final CategoryPlot
plot;
56 this(null, null, null);
66 public BarChartPanel(String title, String categoryLabel, String valueLabel) {
67 this.chart = ChartFactory.createStackedBarChart(
72 PlotOrientation.VERTICAL,
76 chart.setBackgroundPaint(null);
77 chart.getTitle().setFont(DEFAULT_HEADER_FONT);
79 this.plot = ((CategoryPlot) chart.getPlot());
80 this.plot.getRenderer().setBaseItemLabelFont(DEFAULT_FONT);
81 plot.setBackgroundPaint(null);
82 plot.setOutlinePaint(null);
85 ValueAxis range = plot.getRangeAxis();
86 range.setVisible(
false);
89 plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10);
91 ((BarRenderer) plot.getRenderer()).setBarPainter(
new StandardBarPainter());
94 ChartPanel panel =
new ChartPanel(chart);
95 panel.addOverlay(overlay);
96 panel.setPopupMenu(null);
98 this.setLayout(
new BorderLayout());
99 this.add(panel, BorderLayout.CENTER);
106 return (this.chart == null || this.chart.getTitle() == null)
108 : this.chart.getTitle().getText();
119 this.chart.
getTitle().setText(title);
125 this.overlay.setVisible(visible);
126 this.overlay.setMessage(message);
131 this.dataset.clear();
133 if (CollectionUtils.isNotEmpty(data)) {
134 for (
int s = 0; s < data.size(); s++) {
136 if (series != null && CollectionUtils.isNotEmpty(series.
getItems())) {
138 this.plot.getRenderer().setSeriesPaint(s, series.
getColor());
141 for (
int i = 0; i < series.
getItems().size(); i++) {
final DefaultCategoryDataset dataset
static final Font DEFAULT_FONT
void setResults(List< BarChartSeries > data)
final ChartMessageOverlay overlay
void setMessage(boolean visible, String message)
static final long serialVersionUID
List< BarChartItem > getItems()
BarChartPanel setTitle(String title)
static final Font DEFAULT_HEADER_FONT
BarChartPanel(String title, String categoryLabel, String valueLabel)