Search in sources :

Example 11 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class StationTimetablesExtractor method createRow.

private StationTimetableRow createRow(TimeInterval interval) {
    TimeInterval from = interval.getTrain().getInterval(interval, -1);
    TimeInterval to = interval.getTrain().getInterval(interval, 1);
    String fromNodeName = TransformUtil.getFromAbbr(interval);
    String toNodeName = TransformUtil.getToAbbr(interval);
    String endNodeName = (interval.isLast() || interval.isTechnological()) ? null : interval.getTrain().getEndNode().getAbbr();
    String fromTime = (from == null && !interval.isTechnological()) ? null : converter.convertIntToXml(interval.getStart());
    String toTime = (to == null && !interval.isTechnological()) ? null : converter.convertIntToXml(interval.getEnd());
    StationTimetableRow row = new StationTimetableRow(interval.getTrain().getName(), fromNodeName, fromTime, toNodeName, toTime, endNodeName, interval.getTrack().getNumber());
    row.setStop(interval.getLength());
    this.addOtherData(interval, row);
    row.setRef(interval);
    return row;
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) TranslatedString(net.parostroj.timetable.model.TranslatedString)

Example 12 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class TrainRegionCollector method getItemsForPoint.

@Override
public List<TimeInterval> getItemsForPoint(int x, int y, int radius) {
    Rectangle2D cursor = new Rectangle2D.Double(x - radius, y - radius, radius * 2, radius * 2);
    LinkedList<TimeInterval> list = new LinkedList<>();
    for (Train train : regions.keySet()) {
        for (Pair<Shape, TimeInterval> pair : regions.get(train)) {
            if (pair.first.intersects(cursor) && !list.contains(pair.second)) {
                TimeInterval interval = pair.second;
                if (interval.isNodeOwner()) {
                    list.addFirst(interval);
                } else {
                    list.add(interval);
                }
            }
        }
    }
    return list;
}
Also used : Shape(java.awt.Shape) TimeInterval(net.parostroj.timetable.model.TimeInterval) Rectangle2D(java.awt.geom.Rectangle2D) Train(net.parostroj.timetable.model.Train)

Example 13 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval 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 14 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval 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)

Example 15 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class FreightDestinationPanel method addFreightTrainsFromNode.

private void addFreightTrainsFromNode(DataModel model, Node node, FreightAnalyser analyser) {
    Locale locale = Locale.getDefault();
    List<TimeInterval> intervalsFrom = analyser.getFreightIntervalsFrom(node);
    List<Tuple<String>> trains = intervalsFrom.stream().map(i -> new Tuple<>(util.intervalToString(diagram, i, locale), util.freightListToString(analyser.getConnectionStrategy().getFreightToNodes(i), locale).stream().collect(Collectors.joining(", ")))).collect(Collectors.toList());
    model.addLinesWithEmpty(trains);
}
Also used : Locale(java.util.Locale) TableColumnModel(javax.swing.table.TableColumnModel) OutputFreightUtil(net.parostroj.timetable.output2.util.OutputFreightUtil) TableCellRenderer(javax.swing.table.TableCellRenderer) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) TimeInterval(net.parostroj.timetable.model.TimeInterval) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) Locale(java.util.Locale) AbstractTableModel(javax.swing.table.AbstractTableModel) NodeFreight(net.parostroj.timetable.model.freight.NodeFreight) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) Collator(java.text.Collator) FlowLayout(java.awt.FlowLayout) ItemEvent(java.awt.event.ItemEvent) JButton(javax.swing.JButton) WrapperListModel(net.parostroj.timetable.gui.wrappers.WrapperListModel) Collection(java.util.Collection) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) List(java.util.List) GuiIcon(net.parostroj.timetable.gui.utils.GuiIcon) Tuple(net.parostroj.timetable.utils.Tuple) JTable(javax.swing.JTable) RxActionHandler(net.parostroj.timetable.gui.actions.execution.RxActionHandler) Comparator(java.util.Comparator) FreightAnalyser(net.parostroj.timetable.model.freight.FreightAnalyser) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) JPanel(javax.swing.JPanel) TimeInterval(net.parostroj.timetable.model.TimeInterval) Tuple(net.parostroj.timetable.utils.Tuple)

Aggregations

TimeInterval (net.parostroj.timetable.model.TimeInterval)26 Train (net.parostroj.timetable.model.Train)9 ArrayList (java.util.ArrayList)6 Node (net.parostroj.timetable.model.Node)6 List (java.util.List)5 LinkedList (java.util.LinkedList)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 Component (java.awt.Component)3 Collection (java.util.Collection)3 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Pair (net.parostroj.timetable.utils.Pair)3 BorderLayout (java.awt.BorderLayout)2 FlowLayout (java.awt.FlowLayout)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 ItemEvent (java.awt.event.ItemEvent)2 Collator (java.text.Collator)2