Search in sources :

Example 1 with TrainTracker

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);
}
Also used : TrainTracker(ctc.model.TrainTracker) ScheduleRow(ctc.model.ScheduleRow) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 2 with TrainTracker

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("", "", "")));
}
Also used : TrainTracker(ctc.model.TrainTracker) ScheduleRow(ctc.model.ScheduleRow) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) AlertWindow(utils.alerts.AlertWindow)

Example 3 with TrainTracker

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());
}
Also used : TrainTracker(ctc.model.TrainTracker) Paint(javafx.scene.paint.Paint)

Example 4 with TrainTracker

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));
}
Also used : TrainTracker(ctc.model.TrainTracker) TrackControllerLineManager(trackctrl.model.TrackControllerLineManager)

Example 5 with TrainTracker

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());
        }
    }
}
Also used : TrainTracker(ctc.model.TrainTracker) Paint(javafx.scene.paint.Paint)

Aggregations

TrainTracker (ctc.model.TrainTracker)8 ScheduleRow (ctc.model.ScheduleRow)4 Paint (javafx.scene.paint.Paint)4 DefaultStringConverter (javafx.util.converter.DefaultStringConverter)2 AlertWindow (utils.alerts.AlertWindow)2 Schedule (ctc.model.Schedule)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RadioButton (javafx.scene.control.RadioButton)1 TableView (javafx.scene.control.TableView)1 Toggle (javafx.scene.control.Toggle)1 TrackControllerLineManager (trackctrl.model.TrackControllerLineManager)1 Block (trackmodel.model.Block)1