1 package org.wcb.gui.forms.report;
2
3 import org.jfree.chart.JFreeChart;
4 import org.jfree.chart.ChartFactory;
5 import org.jfree.chart.ChartPanel;
6 import org.jfree.chart.plot.PiePlot;
7 import org.jfree.data.general.DefaultPieDataset;
8 import org.wcb.model.vo.hibernate.Logbook;
9 import org.wcb.model.bd.LogbookDelegate;
10 import org.wcb.model.util.SpringUtil;
11 import org.wcb.model.service.IServicesConstants;
12 import org.wcb.resources.MessageResourceRegister;
13 import org.wcb.resources.MessageKey;
14
15 import javax.swing.*;
16 import java.awt.*;
17 import java.text.DecimalFormat;
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 public class TotalTimeReportForm extends JPanel implements ReportRefresh {
47
48 private LogbookDelegate delegate;
49 private Double totalTime = 0.0;
50 private final DecimalFormat formatter = new DecimalFormat("###,##0.0");
51 private ChartPanel chartPanel;
52
53 public TotalTimeReportForm() {
54 delegate = (LogbookDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_DELEGATE);
55 initComponents();
56 }
57
58 public void refresh() {
59 totalTime = 0.0;
60 DefaultPieDataset dataset = getData();
61 JFreeChart chart = ChartFactory.createPieChart3D("Total Time " + formatter.format(totalTime) + " hours", dataset, true, true, false);
62 PiePlot plot = (PiePlot) chart.getPlot();
63 plot.setSectionOutlinesVisible(false);
64 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
65 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
66 plot.setCircular(false);
67 plot.setForegroundAlpha(.5f);
68 plot.setLabelGap(0.02);
69 chartPanel.setChart(chart);
70 }
71
72 private void initComponents() {
73 DefaultPieDataset dataset = getData();
74 JFreeChart chart = ChartFactory.createPieChart3D("Total Time " + formatter.format(totalTime) + " hours", dataset, true, true, false);
75 PiePlot plot = (PiePlot) chart.getPlot();
76 plot.setSectionOutlinesVisible(false);
77 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
78 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
79 plot.setCircular(false);
80 plot.setForegroundAlpha(.5f);
81 plot.setLabelGap(0.02);
82 chartPanel = new ChartPanel(chart);
83 add(chartPanel);
84 }
85
86 private DefaultPieDataset getData() {
87 java.util.List<Logbook> rows = delegate.getAllLogbookEntries();
88 Double pic = 0.0;
89 Double sic = 0.0;
90 Double xCountry = 0.0;
91 Double instructing = 0.0;
92 Double safety = 0.0;
93 Double dual = 0.0;
94 Double solo = 0.0;
95 Double actualIMC = 0.0;
96 Double simulatedIMC = 0.0;
97 Double flightSim = 0.0;
98 Double nightFlight = 0.0;
99 for(Logbook item : rows) {
100 totalTime = totalTime + item.getFlightDuration();
101 pic = pic + item.getPic();
102 sic = sic + item.getSic();
103 xCountry = xCountry + item.getCrossCountry();
104 instructing = instructing + item.getFlightInstructing();
105 safety = safety + item.getSafetyPilot();
106 dual = dual + item.getDualReceived();
107 solo = solo + item.getSolo();
108 nightFlight = nightFlight + item.getConditionNight();
109 actualIMC = actualIMC + item.getConditionActualImc();
110 simulatedIMC = simulatedIMC + item.getConditionSimulatedImc();
111 flightSim = flightSim + item.getConditionFlightSim();
112 }
113 DefaultPieDataset dataset = new DefaultPieDataset();
114 dataset.setValue("PIC", pic);
115 dataset.setValue("SIC", sic);
116 dataset.setValue("X-country", xCountry);
117 dataset.setValue("Instructing", instructing);
118 dataset.setValue("Safety Pilot", safety);
119 dataset.setValue("Dual", dual);
120 dataset.setValue("Solo", solo);
121 dataset.setValue("Actual IMC" , actualIMC);
122 dataset.setValue("Hood", simulatedIMC);
123 dataset.setValue("Simulator", flightSim);
124 dataset.setValue("Night", nightFlight);
125 return dataset;
126 }
127 }