Search in sources :

Example 1 with GTEventsReceiverColleague

use of net.parostroj.timetable.mediator.GTEventsReceiverColleague 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)

Example 2 with GTEventsReceiverColleague

use of net.parostroj.timetable.mediator.GTEventsReceiverColleague in project grafikon by jub77.

the class FloatingWindowsFactory method createTimeIntervalsTrainsChanged.

private static FloatingWindow createTimeIntervalsTrainsChanged(final Frame frame, final Mediator mediator, final ApplicationModel model) {
    final ChangedTrainsPanel panel = new ChangedTrainsPanel();
    panel.addTrainSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                JList<?> list = (JList<?>) e.getSource();
                Wrapper<?> wrapper = (Wrapper<?>) list.getSelectedValue();
                if (wrapper != null) {
                    if (wrapper.getElement() != model.getSelectedTrain()) {
                        model.setSelectedTrain((Train) wrapper.getElement());
                    }
                }
            }
        }
    });
    final FloatingWindow dialog = new FloatingDialog(frame, panel, "dialog.trainchanged.title", "changed.trains");
    mediator.addColleague(new GTEventsReceiverColleague() {

        @Override
        public void processTrainEvent(Event event) {
            if (!dialog.isVisible())
                return;
            if (event.getType() == Event.Type.SPECIAL && event.getData() instanceof SpecialTrainTimeIntervalList) {
                panel.addTrainToList((Train) event.getSource());
            }
        }
    }, Event.class);
    mediator.addColleague(new ApplicationGTEventColleague() {

        @Override
        public void processApplicationEvent(ApplicationModelEvent event) {
            if (event.getType() == ApplicationModelEventType.SET_DIAGRAM_CHANGED) {
                panel.clearTrainList();
            }
        }
    }, ApplicationModelEvent.class);
    return dialog;
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) GTEventsReceiverColleague(net.parostroj.timetable.mediator.GTEventsReceiverColleague) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JList(javax.swing.JList)

Example 3 with GTEventsReceiverColleague

use of net.parostroj.timetable.mediator.GTEventsReceiverColleague in project grafikon by jub77.

the class CirculationPane method setModel.

public void setModel(ApplicationModel model) {
    this.delegate = new TCDelegate(model) {

        private TCDetailsViewDialog editDialog;

        @Override
        public void showEditDialog(JComponent component) {
            if (editDialog == null) {
                editDialog = new TCDetailsViewDialog(GuiComponentUtils.getWindow(component), true);
            }
            editDialog.setLocationRelativeTo(component);
            editDialog.updateValues(this, diagram);
            editDialog.setVisible(true);
        }

        @Override
        public TrainsCycleType getType() {
            return type;
        }

        @Override
        public void handleEvent(Action action, TrainsCycle cycle, Train train) {
            if (action == Action.DIAGRAM_CHANGE) {
                diagram = delegate.getTrainDiagram();
                updateTypes();
                this.fireEvent(Action.REFRESH, null);
            }
        }
    };
    trainsCyclesPane.setModel(this.delegate, new TrainColorChooser() {

        @Override
        public Color getIntervalColor(TimeInterval interval) {
            if (!interval.getTrain().isCovered(type, interval)) {
                return Color.black;
            } else {
                return Color.gray;
            }
        }
    });
    model.getMediator().addColleague(new GTEventsReceiverColleague() {

        @Override
        public void processTrainDiagramEvent(Event event) {
            if (event.getType() == Event.Type.ADDED && event.getObject() instanceof TrainsCycleType) {
                Wrapper<TrainsCycleType> wrapper = new Wrapper<>((TrainsCycleType) event.getObject());
                typesComboBox.addItem(wrapper);
                typesComboBox.setSelectedItem(wrapper);
            } else if (event.getType() == Event.Type.REMOVED && event.getObject() instanceof TrainsCycleType) {
                typesComboBox.removeItem(new Wrapper<>((TrainsCycleType) event.getObject()));
            }
        }
    });
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) GTEventsReceiverColleague(net.parostroj.timetable.mediator.GTEventsReceiverColleague) TCDelegate(net.parostroj.timetable.gui.views.TCDelegate) Color(java.awt.Color) JComponent(javax.swing.JComponent) TrainColorChooser(net.parostroj.timetable.output2.gt.TrainColorChooser) Event(net.parostroj.timetable.model.events.Event) ItemEvent(java.awt.event.ItemEvent) TCDetailsViewDialog(net.parostroj.timetable.gui.dialogs.TCDetailsViewDialog)

Aggregations

GTEventsReceiverColleague (net.parostroj.timetable.mediator.GTEventsReceiverColleague)3 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)2 Color (java.awt.Color)1 Component (java.awt.Component)1 Rectangle (java.awt.Rectangle)1 ItemEvent (java.awt.event.ItemEvent)1 JComponent (javax.swing.JComponent)1 JList (javax.swing.JList)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 TCDetailsViewDialog (net.parostroj.timetable.gui.dialogs.TCDetailsViewDialog)1 IntervalSelectionMessage (net.parostroj.timetable.gui.utils.IntervalSelectionMessage)1 TCDelegate (net.parostroj.timetable.gui.views.TCDelegate)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Train (net.parostroj.timetable.model.Train)1 Event (net.parostroj.timetable.model.events.Event)1 TrainColorChooser (net.parostroj.timetable.output2.gt.TrainColorChooser)1