1   package org.wcb.gui.forms;
2   
3   import org.wcb.model.vo.hibernate.AirportBO;
4   
5   import javax.swing.*;
6   import java.awt.*;
7   
8   /**
9    * <small>
10   * Copyright (c)  2006  wbogaardt.
11   * This library is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU Lesser General Public
13   * License as published by the Free Software Foundation; either
14   * version 2.1 of the License, or (at your option) any later version.
15   *
16   * This library is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   * Lesser General Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser General Public
22   * License along with this library; if not, write to the Free Software
23   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24   * <p/>
25   * $File:  $ <br>
26   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 29, 2006 2:23:05 PM $ <br>
27   * </small>
28   *
29   * @author wbogaardt
30   * @version 1
31   *          Date: Mar 29, 2006
32   *          Time: 2:23:05 PM
33   */
34  
35  public class AirportEntryForm extends JPanel {
36  
37      private JTextField jTextFieldICAO;
38      private JTextField jTextFieldFAACode;
39      private JTextField jTextFieldIATACode;
40      private JTextField jTextFieldName;
41      private JTextField jTextFieldMunicipal;
42      private JTextField jTextFieldStateCounty;
43      private JTextField jTextFieldCountry;
44      private AirportBO oAirport;
45  
46      public AirportEntryForm() {
47          initComponents();
48      }
49  
50      private void initComponents() {
51          GridBagConstraints gridBagConstraints;
52          jTextFieldICAO = new JTextField(5);
53          jTextFieldFAACode = new JTextField(5);
54          jTextFieldIATACode = new JTextField(5);
55          jTextFieldName = new JTextField(5);
56          jTextFieldMunicipal = new JTextField();
57          jTextFieldMunicipal.setPreferredSize(new Dimension(200,18));
58          jTextFieldStateCounty = new JTextField(15);
59          jTextFieldCountry = new JTextField(15);
60  
61          setLayout(new GridBagLayout());
62  
63          gridBagConstraints = new GridBagConstraints();
64          gridBagConstraints.gridwidth = 2;
65          add(new JLabel("Airport"), gridBagConstraints);
66  
67          gridBagConstraints = new GridBagConstraints();
68          gridBagConstraints.gridx = 0;
69          gridBagConstraints.gridy = 1;
70          gridBagConstraints.anchor = GridBagConstraints.EAST;
71          add(new JLabel("ICAO"), gridBagConstraints);
72  
73          gridBagConstraints = new GridBagConstraints();
74          gridBagConstraints.gridx = 1;
75          gridBagConstraints.gridy = 1;
76          gridBagConstraints.anchor = GridBagConstraints.WEST;
77          add(jTextFieldICAO, gridBagConstraints);
78  
79          gridBagConstraints = new GridBagConstraints();
80          gridBagConstraints.gridx = 0;
81          gridBagConstraints.gridy = 2;
82          gridBagConstraints.anchor = GridBagConstraints.EAST;
83          add(new JLabel("FAA Code"), gridBagConstraints);
84  
85          gridBagConstraints = new GridBagConstraints();
86          gridBagConstraints.gridx = 1;
87          gridBagConstraints.gridy = 2;
88          gridBagConstraints.anchor = GridBagConstraints.WEST;
89          add(jTextFieldFAACode, gridBagConstraints);
90  
91          gridBagConstraints = new GridBagConstraints();
92          gridBagConstraints.gridx = 0;
93          gridBagConstraints.gridy = 3;
94          gridBagConstraints.anchor = GridBagConstraints.EAST;
95          add(new JLabel("IATA Code"), gridBagConstraints);
96  
97          gridBagConstraints = new GridBagConstraints();
98          gridBagConstraints.gridx = 1;
99          gridBagConstraints.gridy = 3;
100         gridBagConstraints.anchor = GridBagConstraints.WEST;
101         add(jTextFieldIATACode, gridBagConstraints);
102 
103         gridBagConstraints = new GridBagConstraints();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 4;
106         gridBagConstraints.anchor = GridBagConstraints.EAST;
107         add(new JLabel("Airport Name"), gridBagConstraints);
108 
109         gridBagConstraints = new GridBagConstraints();
110         gridBagConstraints.gridx = 1;
111         gridBagConstraints.gridy = 4;
112         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
113         gridBagConstraints.anchor = GridBagConstraints.WEST;
114         add(jTextFieldName, gridBagConstraints);
115 
116         gridBagConstraints = new GridBagConstraints();
117         gridBagConstraints.gridx = 0;
118         gridBagConstraints.gridy = 5;
119         gridBagConstraints.anchor = GridBagConstraints.EAST;
120         add(new JLabel("City / Municipality"), gridBagConstraints);
121 
122         gridBagConstraints = new GridBagConstraints();
123         gridBagConstraints.gridx = 1;
124         gridBagConstraints.gridy = 5;
125         gridBagConstraints.anchor = GridBagConstraints.WEST;
126         add(jTextFieldMunicipal, gridBagConstraints);
127 
128         gridBagConstraints = new GridBagConstraints();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 6;
131         gridBagConstraints.anchor = GridBagConstraints.EAST;
132         add(new JLabel("State / County"), gridBagConstraints);
133 
134         gridBagConstraints = new GridBagConstraints();
135         gridBagConstraints.gridx = 1;
136         gridBagConstraints.gridy = 6;
137         gridBagConstraints.anchor = GridBagConstraints.WEST;
138         add(jTextFieldStateCounty, gridBagConstraints);
139 
140         gridBagConstraints = new GridBagConstraints();
141         gridBagConstraints.gridx = 0;
142         gridBagConstraints.gridy = 7;
143         gridBagConstraints.anchor = GridBagConstraints.EAST;
144         add(new JLabel("Country"), gridBagConstraints);
145 
146         gridBagConstraints = new GridBagConstraints();
147         gridBagConstraints.gridx = 1;
148         gridBagConstraints.gridy = 7;
149         gridBagConstraints.anchor = GridBagConstraints.WEST;
150         add(jTextFieldCountry, gridBagConstraints);
151 
152     }
153 
154     /**
155      * This marshalls an object to populate
156      * values in the form.
157      * @param airport The object to marshall into the form.
158      */
159     private void marshallToForm(AirportBO airport) {
160         this.setICAO(airport.getIcao());
161         this.setIATACode(airport.getIata());
162         this.setFAACode(airport.getFaa());
163         this.setMunicipal(airport.getMunicipal());
164         this.setStateCounty(airport.getState());
165         this.setName(airport.getName());
166         if (airport.getCountry() != null && !airport.getCountry().equalsIgnoreCase("")) {
167             this.setCountry(airport.getCountry());
168         } else {
169             this.setCountry("USA");
170         }
171     }
172 
173     /**
174      * This marshals airport information from the form
175      * @param airport The inputed object
176      * @return the same object with updated values.
177      */
178     private AirportBO marshallFromForm(AirportBO airport) {
179         airport.setIata(this.getIATACode());
180         airport.setIcao(this.getICAO());
181         airport.setFaa(this.getFAACode());
182         airport.setName(this.getName());
183         airport.setMunicipal(this.getMunicipal());
184         airport.setCountry(this.getCountry());
185         airport.setState(this.getStateCounty());
186         return airport;
187     }
188 
189     /**
190      * Takes the airport information and marshalls
191      * the information into the form for purposes of editing.
192      * If it is a new aiport this would be a new airport value.
193      * @param vAirport airport to marshall into the form.
194      */
195     public void setAirport(AirportBO vAirport) {
196        this.oAirport = vAirport;
197        this.marshallToForm(this.oAirport);
198     }
199 
200     /**
201      * Access to get the form's airport information If the
202      * airport was not set in this class then it is considered a new
203      * airport and will get a new object. If it is not new
204      * then it will be simply remarshalled with the updated data as in the
205      * case of editing a row.
206      * @return the airport value object.
207      */
208     public AirportBO getAirport() {
209         if(oAirport == null) {
210             oAirport = new AirportBO();
211         }
212         return marshallFromForm(oAirport);
213     }
214 
215     /**
216      * The ICAO code for the airport
217      * @return  the code for the airport
218      */
219     public String getICAO() {
220         return jTextFieldICAO.getText();
221     }
222 
223     /**
224      * Set the ICAO code of the airport into the
225      * form.
226      * @param sValue the ICAO Code of the airport
227      */
228     public void setICAO(String sValue) {
229         jTextFieldICAO.setText(sValue);
230     }
231 
232     /**
233      * The FAA code for the airport
234      * @return  the code for the airport
235      */
236     public String getFAACode() {
237         return jTextFieldFAACode.getText();
238     }
239 
240     /**
241      * Set the FAA code of the airport into the
242      * form.
243      * @param sValue the FAA Code of the airport
244      */
245     public void setFAACode(String sValue) {
246         jTextFieldFAACode.setText(sValue);
247     }
248 
249     /**
250      * The IATA code for the airport
251      * @return  the code for the airport
252      */
253     public String getIATACode() {
254         return jTextFieldIATACode.getText();
255     }
256 
257      /**
258      * Set the IATA code of the airport into the
259      * form.
260      * @param sValue the IATA Code of the airport
261      */
262     public void setIATACode(String sValue) {
263         jTextFieldIATACode.setText(sValue);
264     }
265 
266     /**
267      * Get the airport name
268      * @return  Name of the airport
269      */
270     public String getName() {
271         return jTextFieldName.getText();
272     }
273 
274     /**
275      * Set the name for the airport in the form
276      * @param sValue name of the airport
277      */
278     public void setName(String sValue) {
279         jTextFieldName.setText(sValue);
280     }
281 
282     /**
283      * Get the city where airport is located
284      * @return  City name
285      */
286     public String getMunicipal() {
287         return jTextFieldName.getText();
288     }
289       /**
290      * Set the name for the city where airport is located
291      * @param sValue name of the city
292      */
293     public void setMunicipal(String sValue) {
294         jTextFieldMunicipal.setText(sValue);
295     }
296 
297     /**
298      * State where airport is located
299      * @return State/county name
300      */
301     public String getStateCounty() {
302         return jTextFieldStateCounty.getText();
303     }
304 
305     /**
306      * State where airport is located
307      * @param sValue The state.
308      */
309     public void setStateCounty(String sValue) {
310         jTextFieldStateCounty.setText(sValue);
311     }
312 
313     /**
314      * Get the country where airport is located
315      * @return  Country
316      */
317     public String getCountry() {
318         return jTextFieldCountry.getText();
319     }
320 
321     /**
322      * Set the country where airport is located
323      * @param sValue country name
324      */
325     public void setCountry(String sValue) {
326         jTextFieldCountry.setText(sValue);
327     }
328 }