use of trackctrl.model.TrackControllerLineManager in project on-track by michaelplazek.
the class TrackControllerInitializer method parseTrack.
/**
* Searches the Track Model instances and populates TrackControllerLineManagers
* and TrackControllers.
*/
public static void parseTrack() {
HashMap<String, Track> track = Track.getListOfTracks();
TrackControllerLineManager[] lms = new TrackControllerLineManager[2];
// TrackControllerLineManager[] lms = new TrackControllerLineManager[track.size()];
// Create TrackControllerLineManagers
// int i = 0;
// for (Map.Entry<String, Track> entry : track.entrySet()) {
// i++;
// lms[i] = new TrackControllerLineManager(entry.getKey());
// for (String block : entry.getValue().getBlockList()) {
// //add each block to a track controller
//
//
// }
// }
lms[0] = new TrackControllerLineManager("Green");
lms[1] = new TrackControllerLineManager("Red");
// DUMMY DATA
TrackController[] gtc = new TrackController[10];
TrackController[] rtc = new TrackController[10];
for (int i = 0; i < 10; i++) {
gtc[i] = new TrackController(i + 1, 0);
lms[0].addController(gtc[i]);
rtc[i] = new TrackController(i + 1, 0);
lms[1].addController(rtc[i]);
}
}
use of trackctrl.model.TrackControllerLineManager 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 trackctrl.model.TrackControllerLineManager in project on-track by michaelplazek.
the class MainMenuController method initializeTrackControllers.
/**
* This function sets the lines to the initial line values.
*/
private void initializeTrackControllers() {
ObservableList<String> lineList = FXCollections.observableArrayList();
// ObservableList[] ctrlrLists = FXCollections.observableArrayList()[];
HashMap<String, ObservableList> ctrlrLists = new HashMap<>();
lineList.add("Select Line");
for (TrackControllerLineManager lm : TrackControllerLineManager.getLines()) {
lineList.add(lm.getLine());
ObservableList<String> currLineList = FXCollections.observableArrayList();
currLineList.addAll(lm.getObservableListOfIds());
ctrlrLists.put(lm.getLine(), currLineList);
}
trackControllerLineChoiceBox.setItems(lineList);
trackControllerLineChoiceBox.setValue("Select Line");
// Disable invalid operations
trackControllerIdChoiceBox.setDisable(true);
trackControllerButton.setDisable(true);
// Action Event for line selection
trackControllerLineChoiceBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!(trackControllerLineChoiceBox.getSelectionModel().getSelectedItem().equals("Select Line"))) {
// Line Selected, select Id, get proper list
trackControllerIdChoiceBox.setItems(ctrlrLists.get(newValue));
trackControllerIdChoiceBox.setValue((String) ctrlrLists.get(newValue).get(0));
trackControllerIdChoiceBox.setDisable(false);
} else {
trackControllerLineChoiceBox.setValue(oldValue);
}
});
// Action Event for id selection
trackControllerIdChoiceBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (!(trackControllerIdChoiceBox.getSelectionModel().getSelectedItem().equals("Select ID"))) {
// Line Selected, Id selected, enable button
trackControllerButton.setDisable(false);
}
});
}
Aggregations