Search in sources :

Example 1 with AbstractEventVisitor

use of net.parostroj.timetable.visitors.AbstractEventVisitor in project grafikon by jub77.

the class TrainRegionCollector method processEvent.

@Override
public void processEvent(Event event) {
    AbstractEventVisitor visitor = new AbstractEventVisitor() {

        @Override
        public void visitDiagramEvent(Event event) {
            switch(event.getType()) {
                case ADDED:
                    if (event.getObject() instanceof Train) {
                        newTrain((Train) event.getObject());
                    }
                    break;
                case REMOVED:
                    if (event.getObject() instanceof Train) {
                        deleteTrain((Train) event.getObject());
                    }
                    break;
                default:
                    break;
            }
        }

        @Override
        public void visitTrainEvent(Event event) {
            switch(event.getType()) {
                case SPECIAL:
                    modifiedTrain((Train) event.getSource());
                    break;
                case ATTRIBUTE:
                    if (event.getAttributeChange().checkName(Train.ATTR_MANAGED_FREIGHT, Train.ATTR_TECHNOLOGICAL_BEFORE, Train.ATTR_TECHNOLOGICAL_AFTER)) {
                        modifiedTrain((Train) event.getSource());
                    }
                    break;
                default:
                    break;
            }
        }
    };
    EventProcessing.visit(event, visitor);
}
Also used : AbstractEventVisitor(net.parostroj.timetable.visitors.AbstractEventVisitor) Event(net.parostroj.timetable.model.events.Event) Train(net.parostroj.timetable.model.Train)

Aggregations

Train (net.parostroj.timetable.model.Train)1 Event (net.parostroj.timetable.model.events.Event)1 AbstractEventVisitor (net.parostroj.timetable.visitors.AbstractEventVisitor)1