-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlterPathDisplay.java
More file actions
110 lines (88 loc) · 2.16 KB
/
AlterPathDisplay.java
File metadata and controls
110 lines (88 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cas;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.JComboBox;
import Ertsys.*;
public class AlterPathDisplay extends JPanel
{
private List<Aircraft> _aircrafts;
private JTextField txtIdentity;
private JTextField txtTargetHeight;
public JButton btnConfirm;
private JLabel lblError;
public AlterPathDisplay(List<Aircraft> aircrafts)
{
setLayout(new GridLayout(3, 2, 2, 2));
_aircrafts = aircrafts;
add(new JLabel("Identity: "));
txtIdentity = new JTextField();
add(txtIdentity);
add(new JLabel("Target altitude: "));
txtTargetHeight = new JTextField();
add(txtTargetHeight);
btnConfirm = new JButton("Confirm");
add(btnConfirm);
lblError = new JLabel();
lblError.setForeground(Color.RED);
add(lblError);
setBorder(BorderFactory.createLoweredBevelBorder());
}
public void update(List<Aircraft> aircrafts)
{
_aircrafts = aircrafts;
}
public AlterPathPair getDataToAlterPath(CASystem system)
{
String sTargetHeight = txtTargetHeight.getText();
if (sTargetHeight.equals(""))
{
lblError.setText("Enter target height");
return null;
}
double targetHeight;
try
{
targetHeight = Double.parseDouble(sTargetHeight);
}
catch (Exception ex)
{
lblError.setText("Target height must be a real number");
return null;
}
if (targetHeight > 17000.0)
{
lblError.setText("Target height is too high");
return null;
}
if (targetHeight < 0.0)
{
lblError.setText("Target height is too low");
return null;
}
String sIdentity = txtIdentity.getText();
if (sIdentity.equals(""))
{
lblError.setText("Enter aircraft identity");
return null;
}
if (!doesAircraftWithIdentityExist(sIdentity))
{
lblError.setText("Enter valid aircraft identity");
return null;
}
lblError.setText("");
return new AlterPathPair(sIdentity, targetHeight);
}
private boolean doesAircraftWithIdentityExist(String identity)
{
if (_aircrafts != null)
{
for (Aircraft aircraft : _aircrafts)
if (_eSystem._lJavaString(aircraft.identification).equals(identity))
return true;
}
return false;
}
}