-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimaryFlightDisplayGUI.java
More file actions
237 lines (187 loc) · 7.29 KB
/
PrimaryFlightDisplayGUI.java
File metadata and controls
237 lines (187 loc) · 7.29 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package base;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import logging.LogEngine;
import recorder.FlightRecorder;
import java.util.ArrayList;
public class PrimaryFlightDisplayGUI extends Application {
private ComboBox<String> batteryComboBox;
private TableView tableView;
private ArrayList<PrimaryFlightDisplayEntry> dataList;
private ObservableList data;
//battery
private PrimaryFlightDisplayEntry batteryEntry;
public static void main(String... args) {
LogEngine.instance.init();
FlightRecorder.instance.startup();
FlightRecorder.instance.init();
Application.launch(args);
FlightRecorder.instance.shutdown();
LogEngine.instance.close();
}
public void start(Stage primaryStage) {
primaryStage.setTitle("A380 - Primary Flight Display");
Airplane airplane = new Airplane();
airplane.build();
Cockpit cockpit = new Cockpit(airplane);
HBox hBox = new HBox();
hBox.setPadding(new Insets(15, 12, 15, 12));
hBox.setSpacing(10);
hBox.setStyle("-fx-background-color: #336699;");
Button startupButton = new Button("Startup");
startupButton.setPrefSize(75, 20);
startupButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.startup();
update();
}
});
Button taxiButton = new Button("Taxi");
taxiButton.setPrefSize(75, 20);
taxiButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.taxi();
update();
}
});
Button takeoffButton = new Button("TakeOff");
takeoffButton.setPrefSize(75, 20);
takeoffButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.takeoff();
update();
}
});
Button climbingButton = new Button("Climbing");
climbingButton.setPrefSize(75, 20);
climbingButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.climbing();
update();
}
});
Button rightTurnButton = new Button("R-Turn");
rightTurnButton.setPrefSize(75, 20);
rightTurnButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.rightTurn();
update();
}
});
Button leftTurnButton = new Button("L-Turn");
leftTurnButton.setPrefSize(75, 20);
leftTurnButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.leftTurn();
update();
}
});
Button descentButton = new Button("Descent");
descentButton.setPrefSize(75, 20);
descentButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.descent();
update();
}
});
Button landingButton = new Button("Landing");
landingButton.setPrefSize(75, 20);
landingButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.landing();
update();
}
});
Button shutdownButton = new Button("Shutdown");
shutdownButton.setPrefSize(75, 20);
shutdownButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cockpit.shutdown();
update();
}
});
hBox.getChildren().addAll(startupButton, taxiButton, takeoffButton, climbingButton, rightTurnButton,
leftTurnButton, descentButton, landingButton, shutdownButton);
TabPane tabPane = new TabPane();
Tab visualTab = new Tab();
visualTab.setText("Visual");
visualTab.setContent(buildVisualView());
tabPane.getTabs().add(visualTab);
Tab tableTab = new Tab();
tableTab.setText("Table");
buildTableView();
tableTab.setContent(tableView);
tabPane.getTabs().add(tableTab);
VBox vbox = new VBox(20);
vbox.setPadding(new Insets(25, 25, 25, 25));
vbox.getChildren().addAll(hBox, tabPane);
Scene scene = new Scene(vbox, 850, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
public GridPane buildVisualView() {
GridPane gridPane = new GridPane();
gridPane.setMinSize(400, 200);
gridPane.setPadding(new Insets(10, 10, 10, 10));
gridPane.setVgap(5);
gridPane.setHgap(10);
gridPane.setAlignment(Pos.BASELINE_LEFT);
// --- insert section: begin
//battery
Label batteryStatusLabel = new Label("BatteryStatus : ");
gridPane.add(batteryStatusLabel, 6, 0);
batteryComboBox = new ComboBox<>();
batteryComboBox.getItems().addAll("0", "50","100");
batteryComboBox.setValue("0");
batteryComboBox.setEditable(false);
gridPane.add(batteryComboBox, 7, 0);
return gridPane;
}
public void buildTableView() {
tableView = new TableView();
data = getInitialTableData();
tableView.setItems(data);
TableColumn attributeColumn = new TableColumn("attribute");
attributeColumn.setCellValueFactory(new PropertyValueFactory("attribute"));
TableColumn valueColumn = new TableColumn("value");
valueColumn.setCellValueFactory(new PropertyValueFactory("value"));
tableView.getColumns().setAll(attributeColumn, valueColumn);
tableView.setPrefWidth(450);
tableView.setPrefHeight(450);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
public void setBatteryStatus(int percentage) {
batteryComboBox.getItems().addAll(Integer.toString(percentage));
batteryComboBox.setValue(Integer.toString(percentage));
batteryComboBox.setEditable(false);
}
private void initData() {
dataList = new ArrayList<>();
// battery
batteryEntry = new PrimaryFlightDisplayEntry("BatteryStatus", Integer.toString(PrimaryFlightDisplay.instance.percentage));
dataList.add(batteryEntry);
}
private ObservableList getInitialTableData() {
initData();
data = FXCollections.observableList(dataList);
return data;
}
public void update() {
//battery
batteryEntry.setValue(Integer.toString(PrimaryFlightDisplay.instance.percentage));
setBatteryStatus(PrimaryFlightDisplay.instance.percentage);
tableView.refresh();
}
}