1   package org.wcb.gui.forms.e6b;
2   
3   import org.wcb.e6b.TrueAirspeed;
4   import org.wcb.gui.forms.e6b.event.CalculateFormActionListener;
5   
6   import javax.swing.*;
7   import java.awt.*;
8   
9   /**
10   * <small>
11   * <p/>
12   * Copyright (c)  2006  wbogaardt.
13   * This library is free software; you can redistribute it and/or
14   * modify it under the terms of the GNU Lesser General Public
15   * License as published by the Free Software Foundation; either
16   * version 2.1 of the License, or (at your option) any later version.
17   *
18   * This library is distributed in the hope that it will be useful,
19   * but WITHOUT ANY WARRANTY; without even the implied warranty of
20   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21   * Lesser General Public License for more details.
22   *
23   * You should have received a copy of the GNU Lesser General Public
24   * License along with this library; if not, write to the Free Software
25   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26   * <p/>
27   * $File:  $ <br>
28   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Sep 18, 2006 10:29:36 AM $ <br>
29   * </small>
30   *
31   * @author wbogaardt
32   *         Panel to display true airspeed.
33   */
34  
35  public class TrueAirspeedPanel extends JPanel implements ICalculateForm{
36  
37      private JTextField calibratedAirspeed;
38      private JTextField pressureAltitude;
39      private JTextField outsideAirTemp;
40      private JButton calculateButton;
41      private JButton clearButton;
42      private JTextField results;
43  
44      public TrueAirspeedPanel() {
45          setBorder(BorderFactory.createTitledBorder("True Airspeed"));
46          initComponents();
47      }
48  
49      public void clearForm() {
50          calibratedAirspeed.setText("");
51          pressureAltitude.setText("");
52          outsideAirTemp.setText("");
53      }
54  
55      private void initComponents() {
56          calibratedAirspeed = new JTextField(5);
57          pressureAltitude = new JTextField(5);
58          outsideAirTemp = new JTextField(5);
59  
60          calculateButton = new JButton("Calculate True Airspeed");
61          clearButton = new JButton("Clear True Airspeed Values");
62          results = new JTextField(20);
63          calculateButton.addActionListener(new CalculateFormActionListener(this));
64          clearButton.addActionListener(new CalculateFormActionListener(this));
65  
66          setLayout(new GridBagLayout());
67          GridBagConstraints gridBagConstraints;
68  
69          gridBagConstraints = new GridBagConstraints();
70          gridBagConstraints.gridx = 0;
71          gridBagConstraints.gridy = 1;
72          gridBagConstraints.anchor = GridBagConstraints.WEST;
73          add(new JLabel("Calibrated/Indicated Airspeed"), gridBagConstraints);
74  
75          gridBagConstraints = new GridBagConstraints();
76          gridBagConstraints.gridx = 1;
77          gridBagConstraints.gridy = 1;
78          gridBagConstraints.anchor = GridBagConstraints.WEST;
79          add(calibratedAirspeed, gridBagConstraints);
80  
81          gridBagConstraints = new GridBagConstraints();
82          gridBagConstraints.gridx = 0;
83          gridBagConstraints.gridy = 2;
84          gridBagConstraints.anchor = GridBagConstraints.WEST;
85          add(new JLabel("Pressure Altitude"), gridBagConstraints);
86  
87          gridBagConstraints = new GridBagConstraints();
88          gridBagConstraints.gridx = 1;
89          gridBagConstraints.gridy = 2;
90          gridBagConstraints.anchor = GridBagConstraints.WEST;
91          add(pressureAltitude, gridBagConstraints);
92  
93          gridBagConstraints = new GridBagConstraints();
94          gridBagConstraints.gridx = 0;
95          gridBagConstraints.gridy = 3;
96          gridBagConstraints.anchor = GridBagConstraints.WEST;
97          add(new JLabel("Outside Air Temp"), gridBagConstraints);
98  
99          gridBagConstraints = new GridBagConstraints();
100         gridBagConstraints.gridx = 1;
101         gridBagConstraints.gridy = 3;
102         gridBagConstraints.anchor = GridBagConstraints.WEST;
103         add(outsideAirTemp, gridBagConstraints);
104 
105         //standard calculate and reset buttons
106         gridBagConstraints = new GridBagConstraints();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 4;
109         gridBagConstraints.anchor = GridBagConstraints.WEST;
110         add(calculateButton, gridBagConstraints);
111 
112         gridBagConstraints = new GridBagConstraints();
113         gridBagConstraints.gridx = 1;
114         gridBagConstraints.gridy = 4;
115         gridBagConstraints.anchor = GridBagConstraints.WEST;
116         add(clearButton, gridBagConstraints);
117 
118         gridBagConstraints = new GridBagConstraints();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 5;
121         gridBagConstraints.anchor = GridBagConstraints.WEST;
122         add(new JLabel("Calculated True Airspeed ="), gridBagConstraints);
123 
124         gridBagConstraints = new GridBagConstraints();
125         gridBagConstraints.gridx = 1;
126         gridBagConstraints.gridy = 6;
127         gridBagConstraints.anchor = GridBagConstraints.WEST;
128         add(results, gridBagConstraints);
129     }
130 
131     public Integer getPressureAltitude() {
132         int returnValue;
133         try {
134             returnValue = Integer.parseInt(pressureAltitude.getText());
135         } catch (NumberFormatException nfe) {
136             returnValue = 0;
137         }
138         return returnValue;
139     }
140 
141     public void setPressureAltitude(Integer pressureAltitude) {
142         this.pressureAltitude.setText(pressureAltitude + "");
143     }
144 
145     public Integer getOutsideAirTemp() {
146         int returnValue;
147         try {
148             returnValue = Integer.parseInt(outsideAirTemp.getText());
149         } catch (NumberFormatException nfe) {
150             returnValue = 0;
151         }
152         return returnValue;
153     }
154 
155     public void setOutsideAirTemp(Integer outsideAirTemp) {
156         this.outsideAirTemp.setText(outsideAirTemp + "");
157     }
158 
159     public Integer getCalibratedAirspeed() {
160         int returnValue;
161         try {
162             returnValue = Integer.parseInt(calibratedAirspeed.getText());
163         } catch (NumberFormatException nfe) {
164             returnValue = 0;
165         }
166         return returnValue;
167     }
168 
169     public void setCalibratedAirspeed(Integer calibratedAirspeed) {
170         this.calibratedAirspeed.setText(calibratedAirspeed + "");
171     }
172 
173     public void calculateResult() {
174         TrueAirspeed e6b = new TrueAirspeed();
175         e6b.setCalibratedAirspeed(this.getCalibratedAirspeed());
176         e6b.setPressureAltitude(this.getPressureAltitude());
177         e6b.setOutsideAirTemp(this.getOutsideAirTemp());
178         e6b.calculate();
179         results.setText("" + e6b.getTAS());
180     }
181 }