Search in sources :

Example 1 with IntervalSelectionMessage

use of net.parostroj.timetable.gui.utils.IntervalSelectionMessage in project grafikon by jub77.

the class TrainView method setModel.

public void setModel(final ApplicationModel model) {
    this.model = model;
    this.updateView(model.getSelectedTrain());
    this.model.addListener(this);
    ((TrainTableModel) trainTable.getModel()).setModel(model);
    model.getMediator().addColleague(message -> {
        IntervalSelectionMessage ism = (IntervalSelectionMessage) message;
        if (ism.getInterval() != null) {
            TimeInterval interval = ism.getInterval();
            Train trainForInterval = interval.getTrain();
            if (trainForInterval.getTimeIntervalBefore() == interval) {
                interval = trainForInterval.getFirstInterval();
            } else if (trainForInterval.getTimeIntervalAfter() == interval) {
                interval = trainForInterval.getLastInterval();
            }
            if (trainForInterval != TrainView.this.train) {
                updateView(trainForInterval);
            }
            int row = interval.getTrain().getTimeIntervalList().indexOf(interval);
            int column = TrainTableColumn.getIndex(trainTable.getColumnModel(), interval.isNodeOwner() ? TrainTableColumn.STOP : TrainTableColumn.SPEED_LIMIT);
            trainTable.setRowSelectionInterval(row, row);
            if (column != -1) {
                trainTable.setColumnSelectionInterval(column, column);
            }
            Rectangle rect = trainTable.getCellRect(row, 0, true);
            trainTable.scrollRectToVisible(rect);
            Component topLevelComponent = GuiComponentUtils.getTopLevelComponent(TrainView.this);
            if (topLevelComponent.hasFocus()) {
                trainTable.requestFocus();
            }
        }
    }, IntervalSelectionMessage.class);
    model.getMediator().addColleague(new GTEventsReceiverColleague() {

        @Override
        public void processTrainEvent(Event event) {
            Train selectedTrain = model.getSelectedTrain();
            if (event.getSource() == selectedTrain) {
                updateView(selectedTrain);
            }
        }
    }, Event.class);
}
Also used : IntervalSelectionMessage(net.parostroj.timetable.gui.utils.IntervalSelectionMessage) TimeInterval(net.parostroj.timetable.model.TimeInterval) GTEventsReceiverColleague(net.parostroj.timetable.mediator.GTEventsReceiverColleague) Rectangle(java.awt.Rectangle) Component(java.awt.Component) Train(net.parostroj.timetable.model.Train)

Aggregations

Component (java.awt.Component)1 Rectangle (java.awt.Rectangle)1 IntervalSelectionMessage (net.parostroj.timetable.gui.utils.IntervalSelectionMessage)1 GTEventsReceiverColleague (net.parostroj.timetable.mediator.GTEventsReceiverColleague)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Train (net.parostroj.timetable.model.Train)1