use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method autoDispatchTrain.
private void autoDispatchTrain(int index) {
TrainTracker train = ctc.getTrainQueueTable().get(index);
// remove selected train from queue
ctc.getTrainQueueTable().remove(index);
ctc.getDispatchTable().add(train);
sendSignalsButton.setDisable(false);
TrainControllerFactory.start(train.getId());
train.setDispatched(true);
dispatchTable.setItems(ctc.getDispatchTable());
dispatchTable.setItems(ctc.getDispatchTable());
if (ctc.getTrainQueueTable().size() == 0) {
selectedScheduleTable.setItems(FXCollections.observableArrayList());
}
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method connectOthers.
private void connectOthers() {
TableView.TableViewSelectionModel<ScheduleRow> defaultModel = addScheduleTable.getSelectionModel();
// connect the toggle buttons for mode of operation
mode.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle oldToggle, Toggle newToggle) {
if (mode.getSelectedToggle() != null) {
RadioButton btn = (RadioButton) newToggle.getToggleGroup().getSelectedToggle();
changeMode(btn.getText(), defaultModel);
}
}
});
trainQueueTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (trainQueueTable.getSelectionModel().getSelectedItem() != null) {
TrainTracker selected = trainQueueTable.getSelectionModel().getSelectedItem();
selectedScheduleTable.setItems(selected.getSchedule().getStops());
}
});
trackSelect.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
ctc.setLine(newValue);
ctc.makeStationList();
ctc.makeBlockList();
stopColumn.setCellFactory(ComboBoxTableCell.forTableColumn(new DefaultStringConverter(), ctc.getStationList()));
scheduleBlocks.setDisable(false);
setAuthorityBlocks.setDisable(false);
scheduleBlocks.setItems(ctc.getBlockList());
setAuthorityBlocks.setItems(ctc.getBlockList());
// only show trains that are on the selected line
ctc.getTrainQueueTable().clear();
ctc.getDispatchTable().clear();
selectedScheduleTable.setItems(FXCollections.observableArrayList());
TrainTracker item;
ObservableList<TrainTracker> list = ctc.getTrainList();
for (int i = 0; i < list.size(); i++) {
item = list.get(i);
if (item.getLine().equals(newValue)) {
// first, set the queue table
if (!item.isDispatched()) {
ctc.getTrainQueueTable().add(item);
} else {
// then get the dispatch table
ctc.getDispatchTable().add(item);
}
}
}
// then set the user interface
trainQueueTable.setItems(ctc.getTrainQueueTable());
dispatchTable.setItems(ctc.getDispatchTable());
if (ctc.getBlockList().size() > 0) {
scheduleBlocks.setValue(ctc.getBlockList().get(0));
setAuthorityBlocks.setValue(ctc.getBlockList().get(0));
}
} else {
trackSelect.setValue(oldValue);
}
});
maintenanceActions.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue.equals("Select action")) {
maintenanceActions.setValue(oldValue);
} else {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
}
});
maintenanceBlocks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
String action = maintenanceActions.getSelectionModel().getSelectedItem();
String line = maintenanceTracks.getSelectionModel().getSelectedItem();
int blockId = extractBlock();
Block block = Track.getListOfTracks().get(line).getBlock(blockId);
if (action.equals("Toggle switch") && !block.isSwitch()) {
submitMaintenance.setDisable(true);
} else {
submitMaintenance.setDisable(false);
}
});
maintenanceTracks.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!newValue.equals("Select track")) {
trackMaintenance.setLine(newValue);
trackMaintenance.makeBlockList();
maintenanceBlocks.setItems(trackMaintenance.getBlockList());
if (ctc.getBlockList().size() > 0) {
maintenanceBlocks.setValue(trackMaintenance.getBlockList().get(0));
}
} else {
maintenanceTracks.setValue(oldValue);
}
updateMaintenance();
});
trainStatus.setFill(Paint.valueOf("Grey"));
}
use of ctc.model.TrainTracker in project on-track by michaelplazek.
the class CentralTrafficControlController method addTrainToQueue.
private void addTrainToQueue() {
if (trackSelect.getSelectionModel().getSelectedItem().equals("Select track")) {
AlertWindow alert = new AlertWindow();
alert.setTitle("Error Submitting");
alert.setHeader("No Track Selected");
alert.setContent("Please select a track from the " + "Select Track dropdown menu before submitting.");
alert.show();
} else {
// get train stop info
List<String> stopData = new ArrayList<>();
for (ScheduleRow item : addScheduleTable.getItems()) {
stopData.add(stopColumn.getCellData(item));
}
// get train dwell info
List<String> dwellData = new ArrayList<>();
for (ScheduleRow item : addScheduleTable.getItems()) {
dwellData.add(dwellColumn.getCellObservableValue(item).getValue());
}
// get line
String line = trackSelect.getSelectionModel().getSelectedItem();
// create schedule
Schedule schedule = new Schedule(line);
for (int i = 0; i < addScheduleTable.getItems().size(); i++) {
schedule.addStop(new ScheduleRow(stopData.get(i), dwellData.get(i), ""));
}
String name = trainNameField.getText();
String departingTime = departingTimeField.getText();
if (!name.equals("") && departingTime.length() == 8) {
TrainTracker train = new TrainTracker(name, departingTime, line, schedule);
// set the track that is current set
train.setLine(ctc.getLine());
// create item in queue
trainQueueTable.setItems(ctc.getTrainQueueTable());
resetSchedule();
// create train
ctc.addTrain(train);
}
}
}
Aggregations