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.event.ItemListener;
12  import java.awt.event.ItemEvent;
13  import java.awt.*;
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 4 is personal airman information.
42   */
43  
44  public class Step4of8710Wizard extends JXTitlePanel implements ItemListener {
45  
46      public Step4of8710Wizard() {
47          super("Step 4 of 6 - Medical/Physical", 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          weightTf = new JTextField(5);
60          felonyYesRb = new JRadioButton("Yes", false);
61          felonyYesRb.addItemListener(this);
62          felonyNoRb = new JRadioButton("No", true);
63          felonyNoRb.addItemListener(this);
64          heightTf = new JTextField(5);
65          hairCB = new JComboBox();
66          hairCB.setModel(new DefaultComboBoxModel(new String[] {
67                  "Black", "Brown", "Blond","Red", "Gray"}));
68          eyesCB = new JComboBox();
69          eyesCB.setModel(new DefaultComboBoxModel(new String[] {
70                  "Brown", "Light Brown", "Hazel", "Amber", "Green", "Gray", "Blue"}));
71          maleRb = new JRadioButton("Male", true);
72          femaleRb = new JRadioButton("Female", false);
73          yesCertificateRb = new JRadioButton("Yes", false);
74          yesCertificateRb.addItemListener(this);
75          noCertificateRb = new JRadioButton("No", true);
76          noCertificateRb.addItemListener(this);
77          nameOfExaminer = new JTextField(10);
78          medicalClassCertificate = new JTextField(10);
79          dateMedicalIssued = new JDateChooser();
80          dateFinalConviction = new JDateChooser();
81  
82          setLayout(new java.awt.BorderLayout());
83  
84          add(getPhysicalInfoPanel(), java.awt.BorderLayout.CENTER);
85          add(getMedicalCertificatePanel(), java.awt.BorderLayout.NORTH);
86          //On init we must set some default fields as disabled because radio buttons are defaulted as such
87          this.setEnableMedical(false);
88          this.setEnableConviction(false);
89      }
90  
91      private JPanel getMedicalCertificatePanel() {
92          JPanel certificatePanel = new JPanel();
93          certificatePanel.setLayout(new java.awt.GridBagLayout());
94  
95          certificatePanel.setBorder(BorderFactory.createTitledBorder("Medical Certificates"));
96          //group yes and no together as only one at a time can be selected
97          ButtonGroup groupYesNo = new ButtonGroup();
98          groupYesNo.add(yesCertificateRb);
99          groupYesNo.add(noCertificateRb);
100 
101         GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
102         gridBagConstraints.gridx = 2;
103         gridBagConstraints.gridy = 0;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
105         certificatePanel.add(yesCertificateRb, gridBagConstraints);
106 
107         gridBagConstraints = new java.awt.GridBagConstraints();
108         gridBagConstraints.gridx = 3;
109         gridBagConstraints.gridy = 0;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         certificatePanel.add(noCertificateRb, gridBagConstraints);
112 
113         gridBagConstraints = new java.awt.GridBagConstraints();
114         gridBagConstraints.gridx = 0;
115         gridBagConstraints.gridy = 2;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117         certificatePanel.add(nameExaminerLabel, gridBagConstraints);
118 
119 
120         gridBagConstraints = new java.awt.GridBagConstraints();
121         gridBagConstraints.gridx = 1;
122         gridBagConstraints.gridy = 2;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         certificatePanel.add(nameOfExaminer, gridBagConstraints);
125 
126         gridBagConstraints = new java.awt.GridBagConstraints();
127         gridBagConstraints.gridx = 0;
128         gridBagConstraints.gridy = 1;
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
130         certificatePanel.add(classMedicalLabel, gridBagConstraints);
131 
132         gridBagConstraints = new java.awt.GridBagConstraints();
133         gridBagConstraints.gridx = 1;
134         gridBagConstraints.gridy = 1;
135         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
136         certificatePanel.add(medicalClassCertificate, gridBagConstraints);
137 
138         gridBagConstraints = new java.awt.GridBagConstraints();
139         gridBagConstraints.gridx = 0;
140         gridBagConstraints.gridy = 3;
141         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
142         certificatePanel.add(medicalIssueLabel, gridBagConstraints);
143 
144         gridBagConstraints = new java.awt.GridBagConstraints();
145         gridBagConstraints.gridx = 1;
146         gridBagConstraints.gridy = 3;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148         certificatePanel.add(dateMedicalIssued, gridBagConstraints);
149 
150         gridBagConstraints = new java.awt.GridBagConstraints();
151         gridBagConstraints.gridx = 0;
152         gridBagConstraints.gridy = 0;
153         gridBagConstraints.gridwidth = 2;
154         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
155         certificatePanel.add(new JLabel("Do you hold a Medical Certificate?"), gridBagConstraints);
156         return certificatePanel;
157     }
158 
159     private JPanel getPhysicalInfoPanel() {
160         JPanel physicalInfoPanel = new JPanel();
161         physicalInfoPanel.setLayout(new java.awt.GridBagLayout());
162 
163         //group felony yes and no.
164         ButtonGroup felonyGroup = new ButtonGroup();
165         felonyGroup.add(felonyYesRb);
166         felonyGroup.add(felonyNoRb);
167 
168         //Group male and female button
169         ButtonGroup maleFemalGroup = new ButtonGroup();
170         maleFemalGroup.add(maleRb);
171         maleFemalGroup.add(femaleRb);
172 
173         physicalInfoPanel.setBorder(BorderFactory.createTitledBorder("Physical Info"));
174         GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
175         gridBagConstraints.gridx = 2;
176         gridBagConstraints.gridy = 0;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
178         physicalInfoPanel.add(new JLabel("Weight"), gridBagConstraints);
179 
180         gridBagConstraints = new java.awt.GridBagConstraints();
181         gridBagConstraints.gridx = 3;
182         gridBagConstraints.gridy = 0;
183         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
184         physicalInfoPanel.add(weightTf, gridBagConstraints);
185 
186         gridBagConstraints = new java.awt.GridBagConstraints();
187         gridBagConstraints.gridx = 0;
188         gridBagConstraints.gridy = 4;
189         gridBagConstraints.gridwidth = 4;
190         physicalInfoPanel.add(new JLabel("Have you ever been convicted for any Federal or State statues relating to narcotic drugs, marijuana?"), gridBagConstraints);
191 
192         gridBagConstraints = new java.awt.GridBagConstraints();
193         gridBagConstraints.gridx = 4;
194         gridBagConstraints.gridy = 4;
195         physicalInfoPanel.add(felonyYesRb, gridBagConstraints);
196 
197         gridBagConstraints = new java.awt.GridBagConstraints();
198         gridBagConstraints.gridx = 5;
199         gridBagConstraints.gridy = 4;
200         physicalInfoPanel.add(felonyNoRb, gridBagConstraints);
201 
202         gridBagConstraints = new java.awt.GridBagConstraints();
203         gridBagConstraints.gridx = 0;
204         gridBagConstraints.gridy = 0;
205         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206         physicalInfoPanel.add(new JLabel("Height"), gridBagConstraints);
207 
208         gridBagConstraints = new java.awt.GridBagConstraints();
209         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
210         physicalInfoPanel.add(heightTf, gridBagConstraints);
211 
212         gridBagConstraints = new java.awt.GridBagConstraints();
213         gridBagConstraints.gridx = 0;
214         gridBagConstraints.gridy = 1;
215         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
216         physicalInfoPanel.add(new JLabel("Hair"), gridBagConstraints);
217 
218         gridBagConstraints = new java.awt.GridBagConstraints();
219         gridBagConstraints.gridx = 1;
220         gridBagConstraints.gridy = 1;
221         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
222         physicalInfoPanel.add(hairCB, gridBagConstraints);
223 
224         gridBagConstraints = new java.awt.GridBagConstraints();
225         gridBagConstraints.gridx = 0;
226         gridBagConstraints.gridy = 2;
227         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
228         physicalInfoPanel.add(new JLabel("Eyes"), gridBagConstraints);
229 
230         gridBagConstraints = new java.awt.GridBagConstraints();
231         gridBagConstraints.gridx = 1;
232         gridBagConstraints.gridy = 2;
233         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
234         physicalInfoPanel.add(eyesCB, gridBagConstraints);
235 
236         gridBagConstraints = new java.awt.GridBagConstraints();
237         gridBagConstraints.gridx = 0;
238         gridBagConstraints.gridy = 3;
239         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
240         physicalInfoPanel.add(new JLabel("Sex"), gridBagConstraints);
241 
242         gridBagConstraints = new java.awt.GridBagConstraints();
243         gridBagConstraints.gridx = 1;
244         gridBagConstraints.gridy = 3;
245         physicalInfoPanel.add(maleRb, gridBagConstraints);
246 
247         gridBagConstraints = new java.awt.GridBagConstraints();
248         gridBagConstraints.gridx = 2;
249         gridBagConstraints.gridy = 3;
250         physicalInfoPanel.add(femaleRb, gridBagConstraints);
251 
252         gridBagConstraints = new java.awt.GridBagConstraints();
253         gridBagConstraints.gridx = 0;
254         gridBagConstraints.gridy = 5;
255         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
256         physicalInfoPanel.add(felonyDateLabel, gridBagConstraints);
257 
258         gridBagConstraints = new java.awt.GridBagConstraints();
259         gridBagConstraints.gridx = 1;
260         gridBagConstraints.gridy = 5;
261         gridBagConstraints.gridwidth = 3;
262         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
263         physicalInfoPanel.add(dateFinalConviction, gridBagConstraints);
264         return physicalInfoPanel;
265     }
266 
267     public void itemStateChanged(ItemEvent evt) {
268         Object item = evt.getItem();
269         if (item.equals(yesCertificateRb)) {
270             this.setEnableMedical(true);
271         }
272         if (item.equals(noCertificateRb)) {
273             this.setEnableMedical(false);
274         }
275         if (item.equals(felonyYesRb)) {
276             this.setEnableConviction(true);
277         }
278         if (item.equals(felonyNoRb)) {
279             this.setEnableConviction(false);
280         }
281     }
282 
283     public void loadApplicant(FAA8710ApplicationBO app) {
284         if(StringUtils.trimToNull(app.getClassMedicalCertificate()) != null) {
285             yesCertificateRb.setSelected(true);
286             this.setEnableMedical(true);
287             medicalClassCertificate.setText(app.getClassMedicalCertificate());
288             nameOfExaminer.setText(app.getNameMedicalExaminer());
289             dateMedicalIssued.setDate(app.getMedicalIssued());
290         }
291         hairCB.setSelectedItem(app.getHair());
292         eyesCB.setSelectedItem(app.getEyes());
293         this.weightTf.setText(app.getWeight());
294         this.heightTf.setText(app.getHeight());
295         if (app.getSex().equalsIgnoreCase("male")) {
296             maleRb.setSelected(true);
297         } else {
298             femaleRb.setSelected(true);
299         }
300     }
301 
302     /**
303      * One stop method to set or disable the
304      * medical fields
305      * @param bVal true enables fields false disables fields
306      */
307     private void setEnableMedical(boolean bVal) {
308         medicalClassCertificate.setEnabled(bVal);
309         nameOfExaminer.setEnabled(bVal);
310         dateMedicalIssued.setEnabled(bVal);
311         //set the labels to on too for looks.
312         classMedicalLabel.setEnabled(bVal);
313         nameExaminerLabel.setEnabled(bVal);
314         medicalIssueLabel.setEnabled(bVal);
315     }
316 
317     /**
318      * One stop shop to set or disable the
319      * felony conviction fields;
320      * @param bVal
321      */
322     private void setEnableConviction(boolean bVal) {
323         felonyDateLabel.setEnabled(bVal);
324         dateFinalConviction.setEnabled(bVal);
325     }
326 
327     public String getHair() {
328         return (String) hairCB.getSelectedItem();
329     }
330 
331     public String getEyes() {
332         return (String) eyesCB.getSelectedItem();
333     }
334 
335     public String getApplicantHeight() {
336         return heightTf.getText();
337     }
338 
339     public String getWeight() {
340         return weightTf.getText();
341     }
342 
343     public String getSex() {
344         if (maleRb.isSelected()) {
345             return "male";
346         }
347         return "female";
348     }
349 
350     public boolean hasMedical() {
351         return yesCertificateRb.isSelected();
352     }
353 
354     public Date getMedicalIssueDate() {
355         return dateMedicalIssued.getDate();
356     }
357 
358     public String getMedicalClass() {
359         return medicalClassCertificate.getText();
360     }
361 
362     public String getNameOfExaminer() {
363         return nameOfExaminer.getText();
364     }
365 
366     public boolean hasFelony() {
367         return felonyYesRb.isSelected();
368     }
369 
370     public Date getDateFinalConviction() {
371         return dateFinalConviction.getDate();
372     }
373 
374     // Variables declaration - do not modify
375     private JComboBox eyesCB;
376     private JComboBox hairCB;
377     private JTextField heightTf;
378     private JDateChooser dateMedicalIssued;
379     private JRadioButton felonyYesRb;
380     private JRadioButton felonyNoRb;
381     private JRadioButton maleRb;
382     private JRadioButton femaleRb;
383     private JTextField medicalClassCertificate;
384     private JTextField nameOfExaminer;
385     private JRadioButton noCertificateRb;
386     private JTextField weightTf;
387     private JRadioButton yesCertificateRb;
388     private JDateChooser dateFinalConviction;
389     private JLabel nameExaminerLabel = new JLabel("Name of Examiner");
390     private JLabel medicalIssueLabel = new JLabel("Date Issued");
391     private JLabel classMedicalLabel = new JLabel("Class of Certificate");
392     private JLabel felonyDateLabel = new JLabel("Date of Final Conviction");
393     // End of variables declaration
394 
395 }