Search in sources :

Example 1 with Pair

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

the class DiagramChangeSetImpl method addChange.

List<Pair<DiagramChange, ChangesTrackerEvent.Type>> addChange(DiagramChange change) {
    // add change
    // look for existing changes
    List<DiagramChange> existing = getChangesForId(change.getObjectId());
    List<Pair<DiagramChange, ChangesTrackerEvent.Type>> returning = new LinkedList<>();
    boolean shouldAdd = true;
    DiagramChange addTo = null;
    if (existing != null) {
        for (DiagramChange ex : existing) {
            // logic
            boolean add = shouldAdd(change, ex);
            if (add && ex.getAction() == Action.MODIFIED && change.getAction() == Action.MODIFIED) {
                addTo = ex;
            }
            shouldAdd &= add;
            if (shouldRemove(change, ex)) {
                changes.remove(ex);
                returning.add(new Pair<>(ex, ChangesTrackerEvent.Type.CHANGE_REMOVED));
            }
        }
    }
    if (shouldAdd) {
        if (addTo == null) {
            changes.add(change);
            returning.add(new Pair<>(change, ChangesTrackerEvent.Type.CHANGE_ADDED));
        } else {
            addTo.setObject(change.getObject());
            if (change.getDescriptions() != null) {
                for (DiagramChangeDescription d : change.getDescriptions()) {
                    addTo.addDescriptionUnique(d);
                }
                returning.add(new Pair<>(addTo, ChangesTrackerEvent.Type.CHANGE_MODIFIED));
            }
        }
    }
    return returning;
}
Also used : ChangesTrackerEvent(net.parostroj.timetable.model.changes.ChangesTrackerEvent) DiagramChangeDescription(net.parostroj.timetable.model.changes.DiagramChangeDescription) DiagramChange(net.parostroj.timetable.model.changes.DiagramChange) LinkedList(java.util.LinkedList) Pair(net.parostroj.timetable.utils.Pair)

Example 2 with Pair

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

the class TrainsFilterDialog method setTrainTypes.

public void setTrainTypes(TrainDiagram diagram, Set<TrainType> types) {
    if (diagram == null)
        return;
    typesPanel.removeAll();
    typesPanel.setLayout(new GridLayout((diagram.getTrainTypes().size() - 1) / COLUMNS + 1, COLUMNS));
    typesList = new LinkedList<Pair<TrainType, JCheckBox>>();
    for (TrainType type : diagram.getTrainTypes()) {
        JCheckBox checkBox = new JCheckBox(type.getDefaultAbbr() + " (" + type.getDesc() + ")");
        typesList.add(new Pair<TrainType, JCheckBox>(type, checkBox));
        checkBox.setSelected(types.contains(type));
        typesPanel.add(checkBox);
    }
    this.pack();
}
Also used : JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) TrainType(net.parostroj.timetable.model.TrainType) Pair(net.parostroj.timetable.utils.Pair)

Example 3 with Pair

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

the class TrainTimetablesExtractor method getConcurrentTrains.

private Pair<Boolean, List<TranslatedString>> getConcurrentTrains(TimeInterval interval) {
    TrainComparator comparator = diagram.getTrainsData().getTrainComparator();
    Node node = interval.getOwnerAsNode();
    TimeInterval toBeChecked = interval;
    Train train = interval.getTrain();
    if (interval.isFirst() && train.getTimeIntervalBefore() != null)
        toBeChecked = train.getTimeIntervalBefore();
    else if (interval.isLast() && train.getTimeIntervalAfter() != null)
        toBeChecked = train.getTimeIntervalAfter();
    Set<TimeInterval> over = node.getOverlappingTimeIntervals(toBeChecked);
    boolean first = true;
    // check if the train is first in the station (start be marked with trapezoid)
    if (!interval.isFirst())
        for (Iterator<TimeInterval> i = over.iterator(); i.hasNext(); ) {
            TimeInterval checked = i.next();
            if (interval.getStart() > checked.getStart() || (interval.getStart() == checked.getStart() && comparator.compare(interval.getTrain(), checked.getTrain()) >= 0)) {
                first = false;
                break;
            }
        }
    if (over.isEmpty()) {
        return null;
    } else {
        List<Train> tTrains = new ArrayList<>(over.size());
        for (TimeInterval ti : over) {
            if (!tTrains.contains(ti.getTrain()))
                tTrains.add(ti.getTrain());
        }
        ElementSort<Train> s = new ElementSort<>(new TrainComparator(node.getDiagram().getTrainsData().getTrainSortPattern()));
        tTrains = s.sort(tTrains);
        List<TranslatedString> result = new LinkedList<>();
        for (Train t : tTrains) {
            result.add(t.getName());
        }
        return new Pair<>(first, result);
    }
}
Also used : TranslatedString(net.parostroj.timetable.model.TranslatedString) TimeInterval(net.parostroj.timetable.model.TimeInterval) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) ElementSort(net.parostroj.timetable.actions.ElementSort) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) TrainComparator(net.parostroj.timetable.actions.TrainComparator) Train(net.parostroj.timetable.model.Train) Pair(net.parostroj.timetable.utils.Pair)

Example 4 with Pair

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

the class TrainRegionCollector method getRectangleForItems.

@Override
public Rectangle getRectangleForItems(List<TimeInterval> items) {
    Iterable<Train> trains = Iterables.transform(items, SelectorUtils.createToTrainFunction());
    Iterable<Train> uniqueTrains = Iterables.filter(trains, SelectorUtils.createUniqueTrainFilter());
    Rectangle result = null;
    for (Train train : uniqueTrains) {
        Collection<Pair<Shape, TimeInterval>> shapes = regions.get(train);
        if (shapes != null) {
            for (Pair<Shape, TimeInterval> pair : shapes) {
                Shape shape = pair.first;
                Rectangle bounds = shape.getBounds();
                if (result == null) {
                    result = bounds;
                } else {
                    result = result.union(bounds);
                }
            }
        }
    }
    return result;
}
Also used : Shape(java.awt.Shape) TimeInterval(net.parostroj.timetable.model.TimeInterval) Rectangle(java.awt.Rectangle) Train(net.parostroj.timetable.model.Train) Pair(net.parostroj.timetable.utils.Pair)

Example 5 with Pair

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

the class PositionsExtractor method getItemStarts.

private List<Pair<TrainsCycleItem, TimeInterval>> getItemStarts(Collection<TrainsCycle> cycles, Integer start) {
    int startingTime = start == null ? 0 : start;
    List<Pair<TrainsCycleItem, TimeInterval>> itemStarts = new ArrayList<>();
    for (TrainsCycle cycle : sortTrainsCycleList(cycles)) {
        TrainsCycleItem sItem = null;
        boolean added = false;
        for (TrainsCycleItem item : cycle) {
            Interval nInterval = IntervalFactory.createInterval(item.getStartTime(), item.getEndTime()).normalize();
            if (nInterval.isOverThreshold(startingTime)) {
                // go through intervals ...
                int lStartTime = startingTime + (startingTime < item.getStartTime() ? TimeInterval.DAY : 0);
                for (TimeInterval interval : Iterables.filter(item.getIntervals(), ModelPredicates::nodeInterval)) {
                    if (interval.isStop() && !interval.isLast() && interval.getEnd() >= lStartTime) {
                        itemStarts.add(new Pair<>(item, interval));
                        added = true;
                        break;
                    }
                }
            }
            if (sItem == null && nInterval.getStart() > startingTime) {
                sItem = item;
            }
        }
        if (!added) {
            if (sItem == null) {
                sItem = cycle.getFirstItem();
            }
            if (sItem != null) {
                itemStarts.add(new Pair<>(sItem, sItem.getFromInterval()));
            }
        }
    }
    return itemStarts;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TimeInterval(net.parostroj.timetable.model.TimeInterval) ArrayList(java.util.ArrayList) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) Pair(net.parostroj.timetable.utils.Pair) Interval(net.parostroj.timetable.model.Interval) TimeInterval(net.parostroj.timetable.model.TimeInterval)

Aggregations

Pair (net.parostroj.timetable.utils.Pair)8 TimeInterval (net.parostroj.timetable.model.TimeInterval)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Train (net.parostroj.timetable.model.Train)2 TrainType (net.parostroj.timetable.model.TrainType)2 BorderLayout (java.awt.BorderLayout)1 GridLayout (java.awt.GridLayout)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 javax.swing (javax.swing)1 JCheckBox (javax.swing.JCheckBox)1 ElementSort (net.parostroj.timetable.actions.ElementSort)1 TrainComparator (net.parostroj.timetable.actions.TrainComparator)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1