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);
}
Aggregations