package art.servers.gui.components;
|
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatPanel;
|
import art.servers.Shared;
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Font;
|
import org.jfree.chart.ChartFactory;
|
import org.jfree.chart.ChartPanel;
|
import org.jfree.chart.JFreeChart;
|
import org.jfree.chart.axis.CategoryAxis;
|
import org.jfree.chart.axis.CategoryLabelPositions;
|
import org.jfree.chart.axis.NumberAxis;
|
import org.jfree.chart.plot.CategoryPlot;
|
import org.jfree.chart.plot.PlotOrientation;
|
import org.jfree.chart.renderer.category.BarRenderer;
|
import org.jfree.data.Range;
|
import org.jfree.data.category.CategoryDataset;
|
import org.jfree.data.category.DefaultCategoryDataset;
|
|
|
public class PanelProcess_Chart extends FlatPanel
|
{
|
private JFreeChart chart1;
|
private DefaultCategoryDataset dataset1;
|
private String title = null;
|
private String description = null;
|
private Color background = new FlatButton().getLook().colorForegroundSelected;
|
|
public PanelProcess_Chart(String title, String description)
|
{
|
this.title = title;
|
this.description = description;
|
initialise();
|
}
|
|
|
|
public void reload(double value)
|
{
|
try
|
{
|
dataset1.clear();
|
dataset1.addValue(value, "", "");
|
CategoryPlot plot = chart1.getCategoryPlot();
|
BarRenderer renderer = (BarRenderer)plot.getRenderer();
|
renderer.setSeriesPaint(0, background);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
|
public void reload(double total, double value)
|
{
|
try
|
{
|
CategoryPlot plot = chart1.getCategoryPlot();
|
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
|
rangeAxis.setRange(new Range(0,total));
|
|
dataset1.clear();
|
dataset1.addValue(value, "", "");
|
BarRenderer renderer = (BarRenderer)plot.getRenderer();
|
renderer.setSeriesPaint(0, background);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
|
|
|
|
|
private void initialise()
|
{
|
dataset1 = new DefaultCategoryDataset();
|
chart1 = createChart(dataset1, 0, 100);
|
ChartPanel chartPanel1 = new ChartPanel(chart1);
|
|
this.setLayout(new java.awt.BorderLayout());
|
this.add(chartPanel1, BorderLayout.CENTER);
|
}
|
|
|
|
|
private JFreeChart createChart (CategoryDataset dataset, double min, double max)
|
{
|
// create the chart...
|
|
final JFreeChart chart = ChartFactory.createBarChart
|
(
|
Shared.getMessage(title), // chart title
|
"", // domain axis label
|
"", // range axis label
|
dataset, // data
|
PlotOrientation.VERTICAL, // orientation
|
false, // include legend
|
false, // tooltips?
|
false // URLs?
|
);
|
|
FlatButton reference = new FlatButton();
|
chart.setTitle(new org.jfree.chart.title.TextTitle(Shared.getMessage(description), reference.getFont().deriveFont(Font.PLAIN, 12)));
|
chart.setBackgroundPaint(this.getBackground());
|
|
// get a reference to the plot for further customisation...
|
CategoryPlot plot = chart.getCategoryPlot();
|
plot.setBackgroundPaint(Color.black);
|
plot.setForegroundAlpha(1.0f);
|
plot.setDomainGridlinePaint(reference.getLook().colorForegroundRollover);
|
plot.setRangeGridlinePaint(reference.getLook().colorForegroundRollover);
|
|
// set the range axis to display integers only...
|
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
|
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
|
rangeAxis.setRange(new Range(min,max));
|
rangeAxis.setVisible(true);
|
|
// disable bar outlines...
|
BarRenderer renderer = (BarRenderer)plot.getRenderer();
|
renderer.setDrawBarOutline(true);
|
renderer.setShadowVisible(false);
|
|
// set up gradient paints for series...
|
CategoryAxis domainAxis = plot.getDomainAxis();
|
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
|
domainAxis.setVisible(false);
|
|
return chart;
|
|
}
|
}
|