1 package org.wcb.gui.dialog;
2
3 import org.wcb.gui.forms.report.*;
4 import org.wcb.gui.component.JXTitlePanel;
5 import org.wcb.gui.component.WaveButton;
6 import org.wcb.gui.util.PrintUtilities;
7 import org.wcb.gui.util.UIHelper;
8 import org.wcb.resources.MessageResourceRegister;
9 import org.wcb.resources.MessageKey;
10 import org.jdesktop.swingx.border.DropShadowBorder;
11
12 import javax.swing.*;
13 import javax.swing.border.Border;
14 import javax.swing.border.CompoundBorder;
15 import java.awt.event.ActionListener;
16 import java.awt.event.ActionEvent;
17 import java.awt.*;
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 ReportDisplayDialog extends JDialog implements ActionListener{
47
48 private JButton closeButton;
49 private JButton printButton;
50 private JPanel form;
51 private String optionValue;
52
53 public ReportDisplayDialog(int rType) {
54 this(rType, null);
55 }
56
57 public ReportDisplayDialog(int rType, String sVal) {
58 setTitle("Logbook Report");
59 setModal(true);
60 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
61 this.optionValue = sVal;
62 initForm(rType);
63 initComponents();
64 }
65
66 public void addActionListener(ActionListener listener) {
67 closeButton.addActionListener(listener);
68 }
69
70 public void refresh() {
71 ((ReportRefresh) form).refresh();
72 }
73
74 private void initForm(int rType) {
75 switch(rType)
76 {
77 case 0:
78 form = new TotalTimeReportForm();
79 break;
80 case 1:
81 form = new TotalTimeAircraftReportForm(optionValue);
82 break;
83 case 2:
84 form = new TotalTimeInstrumentReportForm();
85 break;
86 case 3:
87 form = new TotalTakeoffLandingsReportForm();
88 break;
89 case 4:
90 form = new AircraftMakeModelReportForm();
91 break;
92 default:
93 form = new TotalTimeReportForm();
94 }
95 }
96
97
98
99
100 private void initComponents() {
101 closeButton = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_CLOSE));
102 printButton = new WaveButton(MessageResourceRegister.getInstance().getValue(MessageKey.BUTTON_PRINT));
103 printButton.addActionListener(this);
104 getContentPane().setLayout(new BorderLayout());
105
106 JPanel mainPanel = new JXTitlePanel("Pilot Logbook Report", new Color(0x522aec));
107 Border shadow = new DropShadowBorder(Color.BLACK, 1, 10, .5f, 15, false, true, true, true);
108 mainPanel.setBorder(new CompoundBorder(shadow, mainPanel.getBorder()));
109 mainPanel.setLayout(new GridBagLayout());
110 GridBagConstraints gridBagConstraints;
111
112 gridBagConstraints = new GridBagConstraints();
113 gridBagConstraints.gridx = 0;
114 gridBagConstraints.gridy = 0;
115 gridBagConstraints.anchor = GridBagConstraints.CENTER;
116 mainPanel.add(form, gridBagConstraints);
117
118 gridBagConstraints = new GridBagConstraints();
119 gridBagConstraints.gridx = 0;
120 gridBagConstraints.gridy = 1;
121 gridBagConstraints.anchor = GridBagConstraints.WEST;
122 mainPanel.add(closeButton, gridBagConstraints);
123
124 gridBagConstraints = new GridBagConstraints();
125 gridBagConstraints.gridx = 1;
126 gridBagConstraints.gridy = 1;
127 gridBagConstraints.anchor = GridBagConstraints.WEST;
128 mainPanel.add(printButton, gridBagConstraints);
129
130 getContentPane().add(mainPanel, BorderLayout.CENTER);
131 pack();
132 UIHelper.centerDialogToScreen(this);
133 }
134
135 public void actionPerformed(ActionEvent evt) {
136 PrintUtilities.printComponent(form);
137 }
138 }