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
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 public class TotalTakeoffLandingsReportForm extends JPanel implements ReportRefresh {
46
47 private LogbookDelegate delegate;
48 private ChartPanel chartPanel;
49 private int totalAllLandings;
50 private int totalAllTakeoffs;
51
52 public TotalTakeoffLandingsReportForm() {
53 delegate = (LogbookDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.LOGBOOK_DELEGATE);
54 initComponents();
55 }
56
57 public void refresh() {
58 JFreeChart chart = ChartFactory.createPieChart("Takeoff/Landing Report - " + totalAllTakeoffs + "/" + totalAllLandings, getData(), true, true, false);
59 PiePlot plot = (PiePlot) chart.getPlot();
60 plot.setSectionOutlinesVisible(false);
61 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
62 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
63 plot.setCircular(false);
64 plot.setLabelGap(0.02);
65 chartPanel.setChart(chart);
66 }
67
68 private void initComponents() {
69 JFreeChart chart = ChartFactory.createPieChart("Takeoff/Landing Report", getData(), true, true, false);
70 PiePlot plot = (PiePlot) chart.getPlot();
71 plot.setSectionOutlinesVisible(false);
72 plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
73 plot.setNoDataMessage(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_NODATA));
74 plot.setCircular(false);
75 plot.setLabelGap(0.02);
76 chartPanel = new ChartPanel(chart);
77 add(chartPanel);
78 }
79
80 private DefaultPieDataset getData() {
81 java.util.List<Logbook> rows = delegate.getAllLogbookEntries();
82 int dayTakeoff = 0;
83 int dayLandings = 0;
84 int nightTakeoff = 0;
85 int nightLandings = 0;
86 for(Logbook item : rows) {
87 dayTakeoff = dayTakeoff + item.getDayTakeoffs();
88 dayLandings = dayLandings + item.getDayLandings();
89 nightTakeoff = nightTakeoff + item.getNightTakeoffs();
90 nightLandings = nightLandings + item.getNightLandings();
91 }
92 totalAllLandings = dayLandings + nightLandings;
93 totalAllTakeoffs = dayTakeoff + nightTakeoff;
94 DefaultPieDataset dataset = new DefaultPieDataset();
95 dataset.setValue("Day Takeoff", dayTakeoff);
96 dataset.setValue("Day Landing", dayLandings);
97 dataset.setValue("Night Takeoff", nightTakeoff);
98 dataset.setValue("Night Landing", nightLandings);
99 return dataset;
100 }
101 }