1   package org.wcb.gui.forms.wizard;
2   
3   import org.wcb.gui.component.JXTitlePanel;
4   import org.wcb.model.vo.hibernate.FAA8710ApplicationBO;
5   import org.jdesktop.swingx.border.DropShadowBorder;
6   import org.apache.commons.lang.StringUtils;
7   
8   import javax.swing.border.Border;
9   import javax.swing.border.CompoundBorder;
10  import javax.swing.*;
11  import java.awt.*;
12  import java.awt.event.ItemListener;
13  import java.awt.event.ItemEvent;
14  import java.util.Date;
15  
16  import com.toedter.calendar.JDateChooser;
17  
18  /**
19   * <small>
20   * <p/>
21   * Copyright (C)  2006  wbogaardt.
22   * This library is free software; you can redistribute it and/or
23   * modify it under the terms of the GNU Lesser General Public
24   * License as published by the Free Software Foundation; either
25   * version 2.1 of the License, or (at your option) any later version.
26   * <p/>
27   * This library is distributed in the hope that it will be useful,
28   * but WITHOUT ANY WARRANTY; without even the implied warranty of
29   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
30   * Lesser General Public License for more details.
31   * <p/>
32   * You should have received a copy of the GNU Lesser General Public
33   * License along with this library; if not, write to the Free Software
34   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
35   * <p/>
36   * $File:  $ <br>
37   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Oct 26, 2006 2:43:12 PM $ <br>
38   * </small>
39   *
40   * @author wbogaardt
41   *        Step 3 is personal airman information.
42   */
43  
44  public class Step3of8710Wizard extends JXTitlePanel implements ItemListener {
45  
46      public Step3of8710Wizard() {
47          super("Step 3 of 6 - Citizenship/Airmen records", new Color(0x3779ff));
48          Border shadow = new DropShadowBorder(Color.BLACK, 1, 5, .3f, 15, true, true, true, true);
49          setBorder(new CompoundBorder(shadow, getBorder()));
50          initComponents();
51      }
52  
53      /** This method is called from within the constructor to
54       * initialize the form.
55       * WARNING: Do NOT modify this code. The content of this method is
56       * always regenerated by the Form Editor.
57       */
58      private void initComponents() {
59          yesCitizenRb = new JRadioButton("USA", true);
60          yesCitizenRb.addItemListener(this);
61          noCitizenRb = new JRadioButton("Other", false);
62          noCitizenRb.addItemListener(this);
63          specifyCitizenshipTf = new JTextField(20);
64          yesCertificateRb = new JRadioButton("Yes", false);
65          yesCertificateRb.addItemListener(this);
66          noCertificateRb = new JRadioButton("No", true);
67          noCertificateRb.addItemListener(this);
68          yesUnderstandEnglishRb = new JRadioButton("Yes", true);
69          noUnderstandEnglishRb = new JRadioButton("No", false);
70          certificateGradeTf = new JTextField(20);
71          certificateNumberTf = new JTextField(20);
72          certificateIssueDate = new JDateChooser();
73  
74          setLayout(new BorderLayout());
75          add(getCitizenshipPanel(), BorderLayout.NORTH);
76          add(getCertificatePanel(), BorderLayout.CENTER);
77          //On init we must set some default fields as disabled because radio buttons are defaulted as such
78          this.enableCitizenship(false);
79          this.enablePilotCertificate(false);
80      }
81  
82      private JPanel getCitizenshipPanel() {
83          JPanel citizenshipPanel = new JPanel();
84          citizenshipPanel.setLayout(new GridBagLayout());
85  
86          citizenshipPanel.setBorder(BorderFactory.createTitledBorder("Citizenship"));
87          ButtonGroup groupCitizen = new ButtonGroup();
88          groupCitizen.add(yesCitizenRb);
89          groupCitizen.add(noCitizenRb);
90  
91          ButtonGroup groupUnderstandEnglish = new ButtonGroup();
92          groupUnderstandEnglish.add(yesUnderstandEnglishRb);
93          groupUnderstandEnglish.add(noUnderstandEnglishRb);
94  
95          GridBagConstraints gridBagConstraints = new GridBagConstraints();
96          gridBagConstraints.gridx = 0;
97          gridBagConstraints.gridy = 0;
98          gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
99          citizenshipPanel.add(new JLabel("Citizenship"), gridBagConstraints);
100 
101         gridBagConstraints = new GridBagConstraints();
102         gridBagConstraints.gridx = 1;
103         gridBagConstraints.gridy = 0;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
105         citizenshipPanel.add(yesCitizenRb, gridBagConstraints);
106 
107         gridBagConstraints = new GridBagConstraints();
108         gridBagConstraints.gridx = 2;
109         gridBagConstraints.gridy = 0;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         citizenshipPanel.add(noCitizenRb, gridBagConstraints);
112 
113         gridBagConstraints = new GridBagConstraints();
114         gridBagConstraints.gridx = 0;
115         gridBagConstraints.gridy = 1;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117         citizenshipPanel.add(specifyCitizenLabel, gridBagConstraints);
118 
119         gridBagConstraints = new GridBagConstraints();
120         gridBagConstraints.gridx = 1;
121         gridBagConstraints.gridy = 1;
122         gridBagConstraints.gridwidth = 2;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         citizenshipPanel.add(specifyCitizenshipTf, gridBagConstraints);
125 
126         gridBagConstraints = new GridBagConstraints();
127         gridBagConstraints.gridx = 0;
128         gridBagConstraints.gridy = 2;
129         gridBagConstraints.gridwidth = 3;
130         citizenshipPanel.add(new JLabel("Do you read, write and understand English?"), gridBagConstraints);
131 
132         gridBagConstraints = new GridBagConstraints();
133         gridBagConstraints.anchor = GridBagConstraints.WEST;
134         gridBagConstraints.gridx = 3;
135         gridBagConstraints.gridy = 2;
136         citizenshipPanel.add(yesUnderstandEnglishRb, gridBagConstraints);
137 
138         gridBagConstraints = new GridBagConstraints();
139         gridBagConstraints.anchor = GridBagConstraints.WEST;
140         gridBagConstraints.gridx = 4;
141         gridBagConstraints.gridy = 2;
142         citizenshipPanel.add(noUnderstandEnglishRb, gridBagConstraints);
143         return citizenshipPanel;
144     }
145 
146     private JPanel getCertificatePanel() {
147         JPanel certificatePanel = new JPanel();
148         certificatePanel.setLayout(new java.awt.GridBagLayout());
149 
150         certificatePanel.setBorder(BorderFactory.createTitledBorder("Previous Certificates"));
151         ButtonGroup group = new ButtonGroup();
152         group.add(yesCertificateRb);
153         group.add(noCertificateRb);
154         GridBagConstraints gridBagConstraints = new GridBagConstraints();
155         gridBagConstraints.gridx = 2;
156         gridBagConstraints.gridy = 0;
157         certificatePanel.add(yesCertificateRb, gridBagConstraints);
158 
159         gridBagConstraints = new GridBagConstraints();
160         gridBagConstraints.gridx = 3;
161         gridBagConstraints.gridy = 0;
162         certificatePanel.add(noCertificateRb, gridBagConstraints);
163 
164         gridBagConstraints = new GridBagConstraints();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 2;
167         gridBagConstraints.anchor = GridBagConstraints.WEST;
168         certificatePanel.add(pilotGradeLabel, gridBagConstraints);
169 
170         gridBagConstraints = new GridBagConstraints();
171         gridBagConstraints.gridx = 1;
172         gridBagConstraints.gridy = 2;
173         gridBagConstraints.anchor = GridBagConstraints.WEST;
174         certificatePanel.add(certificateGradeTf, gridBagConstraints);
175 
176         gridBagConstraints = new GridBagConstraints();
177         gridBagConstraints.gridx = 0;
178         gridBagConstraints.gridy = 1;
179         gridBagConstraints.anchor = GridBagConstraints.WEST;
180         certificatePanel.add(certificateLabel, gridBagConstraints);
181 
182         gridBagConstraints = new GridBagConstraints();
183         gridBagConstraints.gridx = 1;
184         gridBagConstraints.gridy = 1;
185         gridBagConstraints.anchor = GridBagConstraints.WEST;
186         certificatePanel.add(certificateNumberTf, gridBagConstraints);
187 
188 
189 
190         gridBagConstraints = new GridBagConstraints();
191         gridBagConstraints.gridx = 0;
192         gridBagConstraints.gridy = 3;
193         gridBagConstraints.anchor = GridBagConstraints.WEST;
194         certificatePanel.add(dateIssuedLabel, gridBagConstraints);
195 
196         gridBagConstraints = new GridBagConstraints();
197         gridBagConstraints.gridx = 1;
198         gridBagConstraints.gridy = 3;
199         gridBagConstraints.anchor = GridBagConstraints.WEST;
200         certificatePanel.add(certificateIssueDate, gridBagConstraints);
201 
202         gridBagConstraints = new GridBagConstraints();
203         gridBagConstraints.gridx = 0;
204         gridBagConstraints.gridy = 0;
205         gridBagConstraints.gridwidth = 2;
206         certificatePanel.add(new JLabel("Do you now hold, or have you ever held an FAA Pilot Certificate?"), gridBagConstraints);
207         return certificatePanel;
208     }
209 
210     public void itemStateChanged(ItemEvent evt) {
211         Object item = evt.getItem();
212         if(item.equals(yesCertificateRb)) {
213             this.enablePilotCertificate(true);
214         }
215         if(item.equals(noCertificateRb)) {
216             this.enablePilotCertificate(false);
217         }
218         if(item.equals(yesCitizenRb)) {
219             this.enableCitizenship(false);
220         }
221         if(item.equals(noCitizenRb)) {
222             this.enableCitizenship(true);
223         }
224     }
225 
226     public void loadApplicant(FAA8710ApplicationBO app) {
227         if (StringUtils.trimToNull(app.getCertificateNumber()) != null) {
228             enablePilotCertificate(true);
229             yesCertificateRb.setSelected(true);
230             certificateGradeTf.setText(app.getGradePilotCertificate());
231             certificateNumberTf.setText(app.getCertificateNumber());
232             certificateIssueDate.setDate(app.getCertificateIssued());
233         }
234     }
235 
236     /**
237      * This sets all the necessary fields to be
238      * enabled or disabled based on user selecting
239      * yes a US citizen or no.
240      * @param bVals true enables all the fields
241      */
242     private void enableCitizenship(boolean bVals) {
243         specifyCitizenshipTf.setEnabled(bVals);
244         //enable lable based on user this is for usability only.
245         specifyCitizenLabel.setEnabled(bVals);
246     }
247 
248     /**
249      * This enables or disables all the certificate
250      * fields based on user selecting yes or no on the
251      * form.
252      * @param bVal true enables all the fields
253      */
254     private void enablePilotCertificate(boolean bVal) {
255         certificateGradeTf.setEnabled(bVal);
256         certificateNumberTf.setEnabled(bVal);
257         certificateIssueDate.setEnabled(bVal);
258         //used to enable and disable lables more for usability
259         certificateLabel.setEnabled(bVal);
260         pilotGradeLabel.setEnabled(bVal);
261         dateIssuedLabel.setEnabled(bVal);
262     }
263     /**
264      * Some logic to return if the user selected us
265      * citizen or other country.
266      * @return True if USA and false for other.
267      */
268     public boolean isCitizen() {
269         return yesCitizenRb.isSelected();
270     }
271 
272     /**
273      * If isCitizen is false then get the specified country
274      * of citizen ship.
275      * @return  Specified country of citizenship.
276      */
277     public String specifyCitizenship() {
278         if (!isCitizen()) {
279             return specifyCitizenshipTf.getText();
280         }
281         return "";
282     }
283 
284     /**
285      * Applicant understands english
286      * @return boolean understand english question.
287      */
288     public boolean isUnderstandEnglish() {
289         return yesUnderstandEnglishRb.isSelected();
290     }
291     /**
292      * If the applicant has a previous pilot certificate
293      * return true
294      * @return True has had a pilot certificate, false if none.
295      */
296     public boolean isCertifiedPilot() {
297         return yesCertificateRb.isSelected();
298     }
299 
300     /**
301      * If the applicant has a pilot's license or previous one
302      * isCertifiedPilot() get the certificate grade
303      * @return The grade of the previous license
304      */
305     public String getCertificateGrade() {
306         if (isCertifiedPilot()) {
307             return certificateGradeTf.getText();
308         }
309         return "";
310     }
311 
312     /**
313      * If the applicant has a pilot's license or previous one
314      * isCertifiedPilot() get the certificate number
315      * @return The certificate number
316      */
317     public String getCertificateNumber() {
318         if (isCertifiedPilot()) {
319             return certificateNumberTf.getText();
320         }
321         return "";
322     }
323 
324     /**
325      * If the applicant has a pilot's license or previous one
326      * isCertifiedPilot() get the isssue date of the certificate
327      * @return date previous certificate was issued.
328      */
329     public Date getCertificateIssuedDate() {
330         return certificateIssueDate.getDate();
331     }
332 
333     // Variables declaration - do not modify
334     private JTextField certificateGradeTf;
335     private JTextField certificateNumberTf;
336     private JDateChooser certificateIssueDate;
337     private JRadioButton noCertificateRb;
338     private JRadioButton noCitizenRb;
339     private JTextField specifyCitizenshipTf;
340     private JRadioButton yesCertificateRb;
341     private JRadioButton yesCitizenRb;
342     private JRadioButton yesUnderstandEnglishRb;
343     private JRadioButton noUnderstandEnglishRb;
344     private JLabel certificateLabel = new JLabel("Certificate Number");
345     private JLabel pilotGradeLabel = new JLabel("Grade Pilot Certificate");
346     private JLabel dateIssuedLabel = new JLabel("Date Issued");
347     private JLabel specifyCitizenLabel = new JLabel("Specify");
348     // End of variables declaration
349 
350 }