1   package org.wcb.gui.forms;
2   
3   import org.wcb.gui.forms.e6b.*;
4   
5   import javax.swing.*;
6   import javax.swing.event.ListSelectionListener;
7   import javax.swing.event.ListSelectionEvent;
8   import java.awt.*;
9   
10  /**
11   * <small>
12   * <p/>
13   * Copyright (c)  2006  wbogaardt.
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2.1 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27   * <p/>
28   * $File:  $ <br>
29   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Sep 18, 2006 9:58:53 AM $ <br>
30   * </small>
31   *
32   * @author wbogaardt
33   *         Visual portion of the E6b calculator.
34   */
35  
36  public class E6BForm extends JPanel implements ListSelectionListener {
37  
38      private JList selectionList;
39      private DefaultListModel listModel;
40      private JPanel displayPanel;
41      private JPanel airspeedPanel1;
42      private JPanel unknownXwindPanel2;
43      private JPanel xWindCorrectionPanel3;
44      private JPanel hdgGroundSpeedPanel4;
45      private JPanel wcaForCoursePanel5;
46      private JPanel pressureAltPanel6;
47      private JPanel densityAltPanel7;
48      private DistanceCalculationPanel distanceCalcPanel8;
49      private JPanel weightBalancePanel9;
50      private JPanel fahrenheitConversionPanel10;
51      private JPanel celsiusConversionPanel11;
52  
53      public E6BForm() {
54          initComponents();
55      }
56  
57      private void initComponents() {
58  
59          listModel = new DefaultListModel();
60          listModel.addElement("True Airspeed");
61          listModel.addElement("Unknown Wind Direction");
62          listModel.addElement("Runway Crosswinds");
63          listModel.addElement("Wind Correction Angle(Course)");
64          listModel.addElement("Wind Correction Angle(Heading)");
65          listModel.addElement("Pressure Altitude");
66          listModel.addElement("Density Altitude");
67          listModel.addElement("Distance Calculator");
68          listModel.addElement("Weight and Balance");
69          listModel.addElement("Fahrenheit to Celsius");
70          listModel.addElement("Celsius to Fahrenheit");
71          selectionList = new JList(listModel);
72          selectionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
73          selectionList.setSelectedIndex(0);
74          selectionList.setVisibleRowCount(5);
75          selectionList.addListSelectionListener(this);
76          JScrollPane listScrollPane = new JScrollPane(selectionList);
77  
78          this.initializePanels();
79          displayPanel = new JPanel(new CardLayout());
80          displayPanel.add(airspeedPanel1, "True Airspeed");
81          displayPanel.add(unknownXwindPanel2, "Unknown Wind Direction");
82          displayPanel.add(xWindCorrectionPanel3, "Runway Crosswinds");
83          displayPanel.add(hdgGroundSpeedPanel4, "Wind Correction Angle(Course)");
84          displayPanel.add(wcaForCoursePanel5, "Wind Correction Angle(Heading)");
85          displayPanel.add(pressureAltPanel6, "Pressure Altitude");
86          displayPanel.add(densityAltPanel7, "Density Altitude");
87          displayPanel.add(distanceCalcPanel8,"Distance Calculator");
88          displayPanel.add(weightBalancePanel9, "Weight and Balance");
89          displayPanel.add(fahrenheitConversionPanel10,"Fahrenheit to Celsius");
90          displayPanel.add(celsiusConversionPanel11, "Celsius to Fahrenheit");
91          //Layout
92          setLayout(new GridBagLayout());
93          GridBagConstraints gridBagConstraints = new GridBagConstraints();
94          gridBagConstraints.anchor = GridBagConstraints.WEST;
95          add(new JLabel("Select Calculator:"), gridBagConstraints);
96  
97          gridBagConstraints.fill = GridBagConstraints.BOTH;
98          gridBagConstraints.gridx = 0;
99          gridBagConstraints.gridy = 1;
100         gridBagConstraints.insets = new Insets(3, 3, 3, 3);
101         add(listScrollPane, gridBagConstraints);
102 
103         gridBagConstraints = new GridBagConstraints();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 2;
106         gridBagConstraints.anchor = GridBagConstraints.WEST;
107         add(displayPanel, gridBagConstraints);
108     }
109 
110     private void initializePanels() {
111         airspeedPanel1 = new TrueAirspeedPanel();
112         unknownXwindPanel2 = new UnknownXwindPanel();
113         xWindCorrectionPanel3 = new RunwayXWindPanel();
114         hdgGroundSpeedPanel4 = new HeadingGroundspeedPanel();
115         wcaForCoursePanel5 = new WCACoursePanel();
116         pressureAltPanel6 = new PressureAltitudePanel();
117         densityAltPanel7 = new DensityAltitudePanel();
118         distanceCalcPanel8 = new DistanceCalculationPanel();
119         weightBalancePanel9 = new JPanel();
120         weightBalancePanel9.setBorder(BorderFactory.createTitledBorder("Weight And Balance"));
121         fahrenheitConversionPanel10 = new FahrenheitConversionPanel();
122         celsiusConversionPanel11 = new CelsiusConversionPanel();
123     }
124 
125     //This method is required by ListSelectionListener.
126     public void valueChanged(ListSelectionEvent e) {
127         if (!e.getValueIsAdjusting()) {
128             CardLayout cl = (CardLayout) displayPanel.getLayout();
129             if (selectionList.getSelectedIndex() != -1) {
130                 cl.show(displayPanel, (String) selectionList.getSelectedValue());
131             }
132         }
133     }
134 }