1 package org.wcb.gui.forms;
2
3 import org.wcb.model.bd.AircraftDelegate;
4 import org.wcb.model.vo.hibernate.AircraftTypeBO;
5 import org.wcb.model.vo.hibernate.AircraftBO;
6 import org.wcb.model.util.SpringUtil;
7 import org.wcb.model.service.IServicesConstants;
8 import org.wcb.gui.dialog.AircraftTypeTableDisplayDialog;
9 import org.wcb.gui.component.JXTitlePanel;
10 import org.wcb.resources.MessageResourceRegister;
11 import org.wcb.resources.MessageKey;
12 import org.jdesktop.swingx.border.DropShadowBorder;
13
14 import javax.swing.*;
15 import javax.swing.border.CompoundBorder;
16 import java.awt.*;
17 import java.awt.event.ActionListener;
18 import java.awt.event.ActionEvent;
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 public class AircraftEntryForm extends JXTitlePanel implements ActionListener {
48
49 private JTextField jTextFieldRegistration;
50 private JButton selectAircraftTypeButton;
51 private JLabel aircraftTypeLabel;
52 private AircraftDelegate delegate;
53 private AircraftBO oAircraft;
54 private AircraftTypeBO oAircraftType;
55
56
57 public AircraftEntryForm() {
58 super("AircraftBO", new Color(0x522aec));
59 this.setBorder(new CompoundBorder(new DropShadowBorder(Color.BLACK, 0, 5, .5f, 12, true, true, true, true), this.getBorder()));
60 delegate = (AircraftDelegate) SpringUtil.getApplicationContext().getBean(IServicesConstants.AIRCRAFT_DELEGATE);
61 initComponents();
62 }
63
64
65
66
67 private void initComponents() {
68 jTextFieldRegistration = new JTextField(15);
69 selectAircraftTypeButton = new JButton("Select");
70 selectAircraftTypeButton.setToolTipText("Select an aircraft type");
71 selectAircraftTypeButton.addActionListener(this);
72 aircraftTypeLabel = new JLabel("Cessna 172M t");
73
74
75 setLayout(new GridBagLayout());
76
77 GridBagConstraints gridBagConstraints = new GridBagConstraints();
78 gridBagConstraints.anchor = GridBagConstraints.WEST;
79 gridBagConstraints.insets = new Insets(0, 5, 0, 0);
80 add(new JLabel(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_REGISTRATION)), gridBagConstraints);
81
82 gridBagConstraints = new GridBagConstraints();
83 gridBagConstraints.gridwidth = 2;
84 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
85 gridBagConstraints.insets = new Insets(0, 5, 0, 5);
86 add(jTextFieldRegistration, gridBagConstraints);
87
88 gridBagConstraints = new GridBagConstraints();
89 gridBagConstraints.gridx = 0;
90 gridBagConstraints.gridy = 1;
91 gridBagConstraints.anchor = GridBagConstraints.WEST;
92 gridBagConstraints.insets = new Insets(0, 5, 0, 0);
93 add(new JLabel(MessageResourceRegister.getInstance().getValue(MessageKey.LABEL_AIRCRAFT_TYPE)), gridBagConstraints);
94
95 gridBagConstraints = new GridBagConstraints();
96 gridBagConstraints.gridx = 1;
97 gridBagConstraints.gridy = 1;
98 gridBagConstraints.insets = new Insets(0, 5, 0, 5);
99 add(selectAircraftTypeButton, gridBagConstraints);
100
101 gridBagConstraints = new GridBagConstraints();
102 gridBagConstraints.gridx = 2;
103 gridBagConstraints.gridy = 1;
104 gridBagConstraints.insets = new Insets(0, 0, 0, 5);
105 add(aircraftTypeLabel, gridBagConstraints);
106 }
107
108
109
110
111 public void reset() {
112 this.setRegistration("");
113 this.aircraftTypeLabel.setText("");
114 oAircraftType = new AircraftTypeBO();
115 }
116
117
118
119
120
121 private AircraftBO marshalFromForm(AircraftBO oCraft) {
122 oCraft.setRegistrationNumber(this.getRegistration());
123 oCraft.setTypeId(this.getAircraftType().getId());
124 return oCraft;
125 }
126
127 private void marshalToForm(AircraftBO oCraft) {
128 this.setRegistration(oCraft.getRegistrationNumber());
129 this.setAircraftType(delegate.getAircraftType(oCraft.getTypeId()));
130 this.aircraftTypeLabel.setText(this.getAircraftType().getManufacturer() + " " + this.getAircraftType().getModel());
131 }
132
133 public AircraftBO getAircraft() {
134 if (oAircraft == null)
135 {
136 oAircraft = new AircraftBO();
137 }
138 return this.marshalFromForm(oAircraft);
139 }
140
141 public void setAircraft(AircraftBO oValue) {
142 this.oAircraft = oValue;
143 marshalToForm(oAircraft);
144 }
145
146 public void setRegistration(String sVal) {
147 jTextFieldRegistration.setText(sVal);
148 }
149
150 public String getRegistration() {
151 return jTextFieldRegistration.getText();
152 }
153
154 public void setAircraftType(AircraftTypeBO val) {
155 oAircraftType = val;
156 this.aircraftTypeLabel.setText(this.getAircraftType().getManufacturer() + " " + this.getAircraftType().getModel());
157 }
158
159 public AircraftTypeBO getAircraftType() {
160 return oAircraftType;
161 }
162
163 public void actionPerformed(ActionEvent evt) {
164 AircraftTypeTableDisplayDialog dialog = new AircraftTypeTableDisplayDialog(this);
165 dialog.setVisible(true);
166 }
167 }