1   package org.wcb.gui.forms;
2   
3   import org.wcb.model.vo.LogImportVO;
4   import org.wcb.gui.component.WaveButton;
5   
6   import javax.swing.*;
7   import java.awt.*;
8   import java.awt.event.ActionListener;
9   import java.awt.event.ActionEvent;
10  
11  /**
12   * <small>
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: Apr 13, 2006 9:28:50 AM $ <br>
30   * </small>
31   *
32   * @author wbogaardt
33   * @version 1
34   *          Date: Apr 13, 2006
35   *          Time: 9:28:50 AM
36   */
37  
38  public class CSVDataImportSelectForm extends JPanel implements ActionListener {
39  
40      private JButton jButtonExport;
41      private JButton jButtonExportAll;
42      private JButton jButtonRevertAll;
43      private JButton jButtonRevert;
44      private JList jListLeftside;
45      private JList jListRightside;
46      private DefaultListModel leftsideOptionModel;
47      private DefaultListModel rightsideOptionModel;
48  
49      public CSVDataImportSelectForm() {
50          this.initComponents();
51      }
52  
53      private void initComponents() {
54          GridBagConstraints gridBagConstraints;
55          JScrollPane jScrollPane1 = new JScrollPane();
56          leftsideOptionModel = new DefaultListModel();
57          leftsideOptionModel.addElement("ENTRY");
58          leftsideOptionModel.addElement("REGISTRATION");
59          leftsideOptionModel.addElement("FROM");
60          leftsideOptionModel.addElement("ROUTE");
61          leftsideOptionModel.addElement("TO");
62          leftsideOptionModel.addElement("DURATION");
63          leftsideOptionModel.addElement("PIC");
64          leftsideOptionModel.addElement("SIC");
65          leftsideOptionModel.addElement("XCOUNTRY");
66          leftsideOptionModel.addElement("INSTRUCTING");
67          leftsideOptionModel.addElement("SAFETY PILOT");
68          leftsideOptionModel.addElement("DUAL RECEIVED");
69          leftsideOptionModel.addElement("SOLO");
70          leftsideOptionModel.addElement("#TAKEOFFS");
71          leftsideOptionModel.addElement("#LANDINGS");
72          leftsideOptionModel.addElement("#NIGHT TAKEOFFS");
73          leftsideOptionModel.addElement("#NIGHT LANDINGS");
74          leftsideOptionModel.addElement("APPROACHES");
75          leftsideOptionModel.addElement("NIGHT DURATION");
76          leftsideOptionModel.addElement("ACTUAL IMC");
77          leftsideOptionModel.addElement("SIMULATED IMC");
78          leftsideOptionModel.addElement("FLIGHT SIMULATOR");
79  
80          jListLeftside = new JList(leftsideOptionModel);
81          jListLeftside.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
82          JScrollPane jScrollPane2 = new JScrollPane();
83          rightsideOptionModel = new DefaultListModel();
84          jListRightside = new JList(rightsideOptionModel);
85          jListRightside.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
86          jButtonExport = new WaveButton(">");
87          jButtonExportAll = new WaveButton(">>");
88          jButtonRevert = new WaveButton("<");
89          jButtonRevertAll = new WaveButton("<<");
90          jButtonExport.addActionListener(this);
91          jButtonRevert.addActionListener(this);
92          jButtonExportAll.addActionListener(this);
93          jButtonRevertAll.addActionListener(this);
94  
95          setLayout(new GridBagLayout());
96  
97          jScrollPane1.setViewportView(jListLeftside);
98          gridBagConstraints = new GridBagConstraints();
99          gridBagConstraints.gridx = 0;
100         gridBagConstraints.gridy = 0;
101         gridBagConstraints.gridheight = 4;
102         add(jScrollPane1, gridBagConstraints);
103 
104         gridBagConstraints = new GridBagConstraints();
105         gridBagConstraints.gridx = 1;
106         gridBagConstraints.gridy = 0;
107         gridBagConstraints.anchor = GridBagConstraints.SOUTH;
108         add(jButtonExport, gridBagConstraints);
109 
110         gridBagConstraints = new GridBagConstraints();
111         gridBagConstraints.gridx = 1;
112         gridBagConstraints.gridy = 1;
113         add(jButtonExportAll, gridBagConstraints);
114 
115         gridBagConstraints = new GridBagConstraints();
116         gridBagConstraints.gridx = 1;
117         gridBagConstraints.gridy = 2;
118         add(jButtonRevertAll, gridBagConstraints);
119 
120         gridBagConstraints = new GridBagConstraints();
121         gridBagConstraints.gridx = 1;
122         gridBagConstraints.gridy = 3;
123         gridBagConstraints.anchor = GridBagConstraints.NORTH;
124         add(jButtonRevert, gridBagConstraints);
125 
126         jScrollPane2.setViewportView(jListRightside);
127         gridBagConstraints = new GridBagConstraints();
128         gridBagConstraints.gridx = 2;
129         gridBagConstraints.gridy = 0;
130         gridBagConstraints.gridheight = 4;
131         add(jScrollPane2, gridBagConstraints);
132 
133 
134     }
135 
136     public void actionPerformed(ActionEvent evt) {
137         Object src = evt.getSource();
138         if(src.equals(jButtonExport)) {
139             int idx = jListLeftside.getSelectedIndex();
140             rightsideOptionModel.addElement(jListLeftside.getSelectedValue());
141             leftsideOptionModel.remove(idx);
142         }
143         if(src.equals(jButtonExportAll)) {
144             DefaultListModel model = (DefaultListModel) jListLeftside.getModel();
145             int size = model.getSize();
146             for(int idx = 0; idx < size; idx++) {
147                 rightsideOptionModel.addElement(model.getElementAt(0));
148                 leftsideOptionModel.remove(0);
149             }
150         }
151         if(src.equals(jButtonRevertAll)) {
152             DefaultListModel model = (DefaultListModel) jListRightside.getModel();
153             int size = model.getSize();
154             for(int idx = 0; idx < size; idx++) {
155                 leftsideOptionModel.addElement(model.getElementAt(0));
156                 rightsideOptionModel.remove(0);
157             }
158         }
159         if(src.equals(jButtonRevert)) {
160             int idx = jListRightside.getSelectedIndex();
161             leftsideOptionModel.addElement(jListRightside.getSelectedValue());
162             rightsideOptionModel.remove(idx);
163         }
164     }
165 
166     public LogImportVO getValueObject() {
167         LogImportVO returnValue = new LogImportVO();
168         for (int i = 0; i < rightsideOptionModel.getSize(); i++) {
169             String value = (String) rightsideOptionModel.get(i);
170             if(value.equalsIgnoreCase("ENTRY")) {
171                 returnValue.setEntryDatePosition(i);
172             }
173             if(value.equalsIgnoreCase("REGISTRATION")) {
174                 returnValue.setRegistrationPosition(i);
175             }
176             if(value.equalsIgnoreCase("FROM")) {
177                 returnValue.setFAAFromPosition(i);
178             }
179             if(value.equalsIgnoreCase("ROUTE")) {
180                 returnValue.setViaPosition(i);
181             }
182             if(value.equalsIgnoreCase("TO")) {
183                 returnValue.setFAAToPosition(i);
184             }
185             if(value.equalsIgnoreCase("DURATION")) {
186                 returnValue.setFlightDurationPosition(i);
187             }
188             if(value.equalsIgnoreCase("PIC")) {
189                 returnValue.setPICPosition(i);
190             }
191             if(value.equalsIgnoreCase("SIC")) {
192                 returnValue.setSICPosition(i);
193             }
194             if(value.equalsIgnoreCase("XCOUNTRY")) {
195                 returnValue.setCrossCountryPosition(i);
196             }
197             if(value.equalsIgnoreCase("INSTRUCTING")) {
198                 returnValue.setFlightInstructingPosition(i);
199             }
200             if(value.equalsIgnoreCase("SAFETY PILOT")) {
201                 returnValue.setSafetyPilotPosition(i);
202             }
203             if(value.equalsIgnoreCase("DUAL RECEIVED")) {
204                 returnValue.setDualReceivedPosition(i);
205             }
206             if(value.equalsIgnoreCase("SOLO")) {
207                 returnValue.setSoloPosition(i);
208             }
209             if(value.equalsIgnoreCase("#TAKEOFFS")) {
210                 returnValue.setDayTakoffPosition(i);
211             }
212             if(value.equalsIgnoreCase("#LANDINGS")) {
213                 returnValue.setDayLandingPosition(i);
214             }
215             if(value.equalsIgnoreCase("#NIGHT TAKEOFFS")) {
216                 returnValue.setNightTakeoffPosition(i);
217             }
218             if(value.equalsIgnoreCase("#NIGHT LANDINGS")) {
219                 returnValue.setNightLandingPosition(i);
220             }
221             if(value.equalsIgnoreCase("APPROACHES")) {
222                 returnValue.setInstrumentApproachesPosition(i);
223             }
224             if(value.equalsIgnoreCase("NIGHT DURATION")) {
225                 returnValue.setConditionNightPosition(i);
226             }
227             if(value.equalsIgnoreCase("ACTUAL IMC")) {
228                 returnValue.setActualIMCPosition(i);
229             }
230             if(value.equalsIgnoreCase("SIMULATED IMC")) {
231                 returnValue.setSimulatedIMCPosition(i);
232             }
233             if(value.equalsIgnoreCase("FLIGHT SIMULATOR")) {
234                 returnValue.setFlightSimPosition(i);
235             }
236         }
237         return returnValue;
238     }
239 }