1 package org.wcb.gui.forms.report;
2
3 import org.wcb.model.bd.LogbookDelegate;
4 import org.wcb.model.vo.hibernate.Logbook;
5 import org.wcb.model.util.SpringUtil;
6 import org.wcb.model.service.IServicesConstants;
7 import org.wcb.resources.MessageResourceRegister;
8 import org.wcb.resources.MessageKey;
9 import org.jfree.chart.JFreeChart;
10 import org.jfree.chart.ChartFactory;
11 import org.jfree.chart.ChartPanel;
12 import org.jfree.chart.plot.PiePlot;
13 import org.jfree.data.general.DefaultPieDataset;
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 TotalTimeInstrumentReportForm extends JPanel implements ReportRefresh {
47
48 private LogbookDelegate delegate;
49 private Double totalIMC;
50 final DecimalFormat formatter = new DecimalFormat("###,##0.0");
51 private ChartPanel chartPanel;
52
53 public TotalTimeInstrumentReportForm() {
54 delegate = (LogbookDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_DELEGATE);
55 initComponents();
56 }
57
58 public void refresh() {
59 DefaultPieDataset dataSet = groupByIMC();
60 JFreeChart chart = ChartFactory.createPieChart("Total Time Instrument " + formatter.format(totalIMC), dataSet, true, true, false);
61 PiePlot plot = (PiePlot) chart.getPlot();
62 plot.setSectionOutlinesVisible(false);
63 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
64 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
65 plot.setCircular(false);
66 plot.setLabelGap(0.02);
67 chartPanel.setChart(chart);
68 }
69
70 private void initComponents() {
71 DefaultPieDataset dataSet = groupByIMC();
72 JFreeChart chart = ChartFactory.createPieChart("Total Time Instrument " + formatter.format(totalIMC), dataSet, true, true, false);
73 PiePlot plot = (PiePlot) chart.getPlot();
74 plot.setSectionOutlinesVisible(false);
75 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
76 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
77 plot.setCircular(false);
78 plot.setLabelGap(0.02);
79 chartPanel = new ChartPanel(chart);
80 add(chartPanel);
81 }
82
83 private DefaultPieDataset groupByIMC() {
84 java.util.List<Logbook> rows = delegate.getAllLogbookEntries();
85 Double totalFlight = 0.0;
86 Double actualIMC = 0.0;
87 Double simulatedIMC = 0.0;
88 Double flightSim = 0.0;
89 for(Logbook item : rows) {
90 totalFlight = totalFlight + item.getFlightDuration();
91 flightSim = flightSim + item.getConditionFlightSim();
92 actualIMC = actualIMC + item.getConditionActualImc();
93 simulatedIMC = simulatedIMC + item.getConditionSimulatedImc();
94 }
95 totalIMC = flightSim + actualIMC + simulatedIMC;
96 Double regularFlight = totalFlight - totalIMC;
97 DefaultPieDataset dataset = new DefaultPieDataset();
98 dataset.setValue("Non-IMC", regularFlight);
99 dataset.setValue("Actual IMC" , actualIMC);
100 dataset.setValue("Hood", simulatedIMC);
101 dataset.setValue("Flight Sim", flightSim);
102 return dataset;
103 }
104 }