Search in sources :

Example 1 with ScheduleRow

use of ctc.model.ScheduleRow 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 ScheduleRow

use of ctc.model.ScheduleRow 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 ScheduleRow

use of ctc.model.ScheduleRow in project on-track by michaelplazek.

the class CentralTrafficControlController method resetSchedule.

private void resetSchedule() {
    ObservableList<ScheduleRow> blank = FXCollections.observableArrayList(new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""), new ScheduleRow("", "", ""));
    addScheduleTable.setItems(blank);
    trainNameField.setText("");
    departingTimeField.setText("");
    scheduleBlocks.setValue(ctc.getBlockList().get(0));
}
Also used : ScheduleRow(ctc.model.ScheduleRow)

Example 4 with ScheduleRow

use of ctc.model.ScheduleRow 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"));
}
Also used : ScheduleRow(ctc.model.ScheduleRow) RadioButton(javafx.scene.control.RadioButton) Paint(javafx.scene.paint.Paint) TrainTracker(ctc.model.TrainTracker) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) Toggle(javafx.scene.control.Toggle) Block(trackmodel.model.Block) TableView(javafx.scene.control.TableView)

Example 5 with ScheduleRow

use of ctc.model.ScheduleRow 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

ScheduleRow (ctc.model.ScheduleRow)5 TrainTracker (ctc.model.TrainTracker)4 Paint (javafx.scene.paint.Paint)2 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 Block (trackmodel.model.Block)1