use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method openFile.
private void openFile(File file) {
TrainTracker train = new TrainTracker();
BufferedReader br = null;
ObservableList<ScheduleRow> list = FXCollections.observableArrayList();
String line;
String splitBy = ",";
String[] word;
try {
br = new BufferedReader(new FileReader(file));
while ((line = br.readLine()) != null) {
// set line
String[] row = line.split(splitBy);
train.setLine(row[0]);
trackSelect.setValue(row[0]);
// new stop
ScheduleRow trainStop = new ScheduleRow();
// determine station
word = row[1].split(": ");
trainStop.setStop(word[1]);
// determine dwell
trainStop.setDwell(row[2]);
trainStop.setTime("");
// add stop to train
list.add(trainStop);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
addScheduleTable.setItems(list);
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method connectTables.
private void connectTables() {
stopColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("stop"));
dwellColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("dwell"));
selectedDwellColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("dwell"));
selectedStopColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("stop"));
selectedTimeColumn.setCellValueFactory(new PropertyValueFactory<ScheduleRow, String>("time"));
trainColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("id"));
departureColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("departure"));
dispatchTrainColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("id"));
dispatchLocationColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("locationId"));
dispatchAuthorityColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("authority"));
dispatchSpeedColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("speed"));
dispatchPassengersColumn.setCellValueFactory(new PropertyValueFactory<TrainTracker, String>("passengers"));
// set dropdown menu for stations
stopColumn.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), ctc.getStationList()));
stopColumn.setOnEditCommit((TableColumn.CellEditEvent<ScheduleRow, String> t) -> {
((ScheduleRow) t.getTableView().getItems().get(t.getTablePosition().getRow())).setStop(t.getNewValue());
});
dwellColumn.setCellFactory(TextFieldTableCell.<ScheduleRow>forTableColumn());
dwellColumn.setOnEditCommit((TableColumn.CellEditEvent<ScheduleRow, String> t) -> {
String input = t.getNewValue();
if (checkTimeFormat(input) || input.equals("")) {
((ScheduleRow) t.getTableView().getItems().get(t.getTablePosition().getRow())).setDwell(input);
} else {
AlertWindow alert = new AlertWindow();
alert.setTitle("Error Submitting");
alert.setHeader("Please Use Correct Format");
alert.setContent("Please enter the time in the following format: " + "XX:XX:XX");
alert.show();
}
});
addScheduleTable.setItems(FXCollections.observableArrayList(new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", "")));
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method deleteTrainFromQueue.
private void deleteTrainFromQueue() {
TrainTracker selected = trainQueueTable.getSelectionModel().getSelectedItem();
for (int i = 0; i < ctc.getTrainQueueTable().size(); i++) {
if (ctc.getTrainQueueTable().get(i).getId().equals(selected.getId())) {
ctc.getTrainQueueTable().remove(i);
ctc.getTrainList().remove(i);
TrainControllerFactory.delete(selected.getId());
}
}
trainQueueTable.setItems(ctc.getTrainQueueTable());
selectedScheduleTable.setItems(FXCollections.observableArrayList());
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method sendTrackSignals.
private void sendTrackSignals() {
// get selected train
TrainTracker train = dispatchTable.getSelectionModel().getSelectedItem();
// get selected track
String line = trackSelect.getSelectionModel().getSelectedItem();
TrackControllerLineManager control = TrackControllerLineManager.getInstance(line);
// get suggested speed
String speed = suggestedSpeedField.getText();
String authority = setAuthorityBlocks.getSelectionModel().getSelectedItem();
// send speed
control.sendTrackSignals(train.getLocation().getNumber(), Float.parseFloat(speed), Float.parseFloat(authority));
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method dispatchTrain.
private void dispatchTrain() {
// remove selected train from queue
TrainTracker selected = trainQueueTable.getSelectionModel().getSelectedItem();
if (selected != null) {
for (int i = 0; i < ctc.getTrainQueueTable().size(); i++) {
if (ctc.getTrainQueueTable().get(i).getId().equals(selected.getId())) {
ctc.getTrainQueueTable().remove(i);
}
}
ctc.getDispatchTable().add(selected);
sendSignalsButton.setDisable(false);
TrainControllerFactory.start(selected.getId());
selected.setDispatched(true);
dispatchTable.setItems(ctc.getDispatchTable());
if (ctc.getTrainQueueTable().size() == 0) {
selectedScheduleTable.setItems(FXCollections.observableArrayList());
}
}
}
Aggregations