Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jflight/awt/AddLocDialog.java


1   /*
2   Project name:   JFlight
3   Hosted at:   www.sourceforge.net
4   Homepage:       jflight.sourceforge.net
5   Licence:        GNU General Public Licence (GPL)
6   Filename:       AddLocDialog.java
7   Package:  jflight.awt
8    */
9   
10  package jflight.awt;
11  
12  import java.awt.*;
13  import java.awt.event.*;
14  import java.util.*;
15  import java.awt.*;
16  
17  import jflight.tools.*;
18  import jflight.flightbook.*;
19  import jflight.model.*;
20  import jflight.tools.*;
21  
22  /**
23   * Dialog to add a new location to the flightbook.
24   *
25   *
26   * @since          JDK1.1.x
27   * @author         R?diger Bien, Guido Scholz
28   *
29   * CVS-section:
30   * @file_version   $Revision: 1.10 $
31   *
32   */
33  
34  public class AddLocDialog extends Dialog {
35      private ResourceBundle strRes = null;
36      // added:
37      private FlightBook fbk;
38      private Vector wptBuf;
39      BorderLayout BasisBorderLayout = new BorderLayout();
40      Panel TopPanel = new Panel();
41      TextField LocationTextField = new TextField();
42      Label LandingLabel = new Label();
43      Panel LeftPanel = new Panel();
44      Panel RightPanel = new Panel();
45      BorderLayout TopBorderLayout = new BorderLayout();
46      Label LocationLabel = new Label();
47      Choice LandingChoice = new Choice();
48      Choice StartChoice = new Choice();
49      GridLayout RightGridLayout = new GridLayout();
50      Label StartLabel = new Label();
51      GridLayout LeftGridLayout = new GridLayout();
52      Panel BottomPanel = new Panel();
53      Button cancelButton = new Button();
54      GridLayout ButtonGridLayout = new GridLayout();
55      FlowLayout ButtomFlowLayout = new FlowLayout();
56      Button okButton = new Button();
57      Panel ButtonPanel = new Panel();
58      
59      public AddLocDialog(Frame owner) {
60          super(owner, true);
61          enableEvents(AWTEvent.WINDOW_EVENT_MASK);
62          strRes = ((JFlightFrame) owner).strRes;
63          try  {
64              jbInit();
65              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
66              // setLocation(screenSize.width/4,screenSize.height/4);
67              setVisible(false);
68          }
69          catch (Exception e) {
70              e.printStackTrace();
71          }
72      }
73      
74      public void setData(FlightBook afbk, Vector awptBuf) {
75          int i;
76          Wpt wpt;
77          this.fbk = afbk;
78          this.wptBuf = awptBuf;
79          for (i=0; i<wptBuf.size(); i++) {
80              wpt = (Wpt) wptBuf.elementAt(i);
81              StartChoice.addItem(wpt.getName() + " (" + wpt.getComment() + ") ");
82              LandingChoice.addItem(wpt.getName() + " (" + wpt.getComment() + ") ");
83          }
84      }
85      
86      private void jbInit() throws Exception {
87          //this.setSize(new Dimension(431, 138));
88          this.setTitle(strRes.getString("AddLocation"));
89          this.setLayout(BasisBorderLayout);
90          BasisBorderLayout.setHgap(5);
91          BasisBorderLayout.setVgap(5);
92          TopPanel.setLayout(TopBorderLayout);
93          if( new SysParams().getScreenType() == SysParams.PDA ) {
94              LocationTextField.setColumns(40);
95          } else {
96              LocationTextField.setColumns(20);
97          }
98          LandingLabel.setText(strRes.getString("LandingPlace"));
99          LeftPanel.setLayout(LeftGridLayout);
100         RightPanel.setLayout(RightGridLayout);
101         LocationLabel.setText(strRes.getString("LocationName"));
102         RightGridLayout.setRows(3);
103         RightGridLayout.setHgap(5);
104         RightGridLayout.setVgap(5);
105         StartLabel.setText(strRes.getString("Start"));
106         LeftGridLayout.setRows(3);
107         LeftGridLayout.setHgap(5);
108         LeftGridLayout.setVgap(5);
109         BottomPanel.setLayout(ButtomFlowLayout);
110         cancelButton.setLabel(strRes.getString("Cancel"));
111         cancelButton.addActionListener(new java.awt.event.ActionListener() {
112             public void actionPerformed(ActionEvent e) {
113                 cancelButton_actionPerformed(e);
114             }
115         });
116         ButtonGridLayout.setHgap(5);
117         ButtonGridLayout.setVgap(5);
118         okButton.setLabel(strRes.getString("OK"));
119         okButton.addActionListener(new java.awt.event.ActionListener() {
120             public void actionPerformed(ActionEvent e) {
121                 okButton_actionPerformed(e);
122             }
123         });
124         ButtonPanel.setLayout(ButtonGridLayout);
125         this.add(TopPanel, BorderLayout.CENTER);
126         TopPanel.add(LeftPanel, BorderLayout.WEST);
127         LeftPanel.add(LocationLabel, null);
128         LeftPanel.add(StartLabel, null);
129         LeftPanel.add(LandingLabel, null);
130         TopPanel.add(RightPanel, BorderLayout.CENTER);
131         RightPanel.add(LocationTextField, null);
132         RightPanel.add(StartChoice, null);
133         RightPanel.add(LandingChoice, null);
134         this.add(BottomPanel, BorderLayout.SOUTH);
135         BottomPanel.add(ButtonPanel, null);
136         ButtonPanel.add(okButton, null);
137         ButtonPanel.add(cancelButton, null);
138         pack();
139         Dimension frameSize = this.getSize();
140         Dimension frameLocation;
141         SysParams sP = new SysParams();
142         
143         frameSize = sP.getSize(frameSize);
144         frameLocation = sP.getLocation(frameSize);
145         
146         this.setLocation(frameLocation.width, frameLocation.height);
147         this.setSize(frameSize);
148     }
149     
150     void okButton_actionPerformed(ActionEvent e) {
151         String start, landing;
152         int i;
153         Wpt wpt;
154         
155         i = StartChoice.getSelectedIndex();
156         wpt = (Wpt) wptBuf.elementAt(i);
157         start = wpt.getName();
158         i = LandingChoice.getSelectedIndex();
159         wpt = (Wpt) wptBuf.elementAt(i);
160         landing = wpt.getName();
161         FlightLocation fL = new FlightLocation(LocationTextField.getText(),start,landing);
162         fbk.addFlightLocation(fL);
163         cancel();
164     }
165     
166     void cancelButton_actionPerformed(ActionEvent e) {
167         cancel();
168     }
169     
170     protected void processWindowEvent(WindowEvent e) {
171         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
172             cancel();
173         }
174         super.processWindowEvent(e);
175     }
176     
177     void cancel() {
178         dispose();
179     }
180     
181 }
182