Alejandro Acuña
2024-10-25 e51f4a713ed6e744c203c9493165584728a29c52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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;
 
    }    
}