Search in sources :

Example 1 with Schedule

use of ctc.model.Schedule 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);
        }
    }
}
Also used : TrainTracker(ctc.model.TrainTracker) ScheduleRow(ctc.model.ScheduleRow) Schedule(ctc.model.Schedule) ArrayList(java.util.ArrayList) AlertWindow(utils.alerts.AlertWindow) Paint(javafx.scene.paint.Paint)

Aggregations

Schedule (ctc.model.Schedule)1 ScheduleRow (ctc.model.ScheduleRow)1 TrainTracker (ctc.model.TrainTracker)1 ArrayList (java.util.ArrayList)1 Paint (javafx.scene.paint.Paint)1 AlertWindow (utils.alerts.AlertWindow)1