1   package org.wcb.gui.dialog;
2   
3   import org.wcb.gui.forms.LogbookEntryForm;
4   import org.wcb.gui.forms.AirportTableDisplayForm;
5   import org.wcb.gui.component.JCloudPane;
6   import org.wcb.gui.util.UIHelper;
7   
8   import javax.swing.*;
9   import java.awt.*;
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: Mar 29, 2006 4:03:35 PM $ <br>
30   * </small>
31   *
32   * @author wbogaardt
33   * @version 1
34   *          Date: Mar 29, 2006
35   *          Time: 4:03:35 PM
36   */
37  
38  public class AirportTableDisplayDialog extends JDialog {
39  
40      private AirportTableDisplayForm form;
41      private LogbookEntryForm parentCallingForm;
42      private boolean bToFrom;
43  
44      public AirportTableDisplayDialog() {
45          super.setTitle("Pilot's Log");
46          super.setModal(true);
47          form = new AirportTableDisplayForm(this, false);
48          initComponents();
49      }
50  
51      public AirportTableDisplayDialog(JComponent parent) {
52          super.setTitle("Pilot's Log");
53          super.setModal(true);
54          if (parent instanceof LogbookEntryForm)
55          {
56              parentCallingForm = (LogbookEntryForm) parent;
57          }
58          form = new AirportTableDisplayForm(this, true);
59          initComponents();
60      }
61  
62      /**
63       * Sets the dialog up to be able to respond to a to or from value
64       * true = to value. false = from value for populationg the logbook entry form.
65       * @param bVal
66       */
67      public void setToFrom(boolean bVal) {
68          this.bToFrom = bVal;
69      }
70  
71      public boolean getToFrom() {
72          return this.bToFrom;
73      }
74  
75      /**
76       * Init the componets in the dialog
77       */
78      private void initComponents() {
79          getContentPane().setLayout(new BorderLayout());
80          JCloudPane prettyUp = new JCloudPane();
81          prettyUp.add(form);
82          getContentPane().add(prettyUp, BorderLayout.CENTER);
83          pack();
84          UIHelper.centerDialogToScreen(this);
85      }
86  
87       /**
88       * Allows public access to refresh form table model.
89       */
90      public void refresh() {
91          form.refresh();
92      }
93  
94      public void fireAirportSelected() {
95          if (parentCallingForm != null) {
96              if (getToFrom())
97              {
98                  parentCallingForm.setToAirport(form.getSelectedRow());
99              }
100             if (!getToFrom())
101             {
102                 parentCallingForm.setFromAirport(form.getSelectedRow());
103             }
104         }
105         dispose();
106     }
107 }