Search in sources :

Example 1 with ElementSort

use of net.parostroj.timetable.actions.ElementSort in project grafikon by jub77.

the class CreateTrainView method updateView.

public void updateView(Group selectedGroup) {
    this.createTrainCommand = null;
    DefaultComboBoxModel<Node> fromModel = new DefaultComboBoxModel<>();
    DefaultComboBoxModel<Node> toModel = new DefaultComboBoxModel<>();
    Collection<Node> v = diagram.getNet().getNodes();
    ElementSort<Node> sort = new ElementSort<>(new NodeComparator());
    List<Node> list = sort.sort(v);
    for (Node node : list) {
        if (node.getType() != NodeType.SIGNAL) {
            fromModel.addElement(node);
            toModel.addElement(node);
        }
    }
    fromComboBox.setModel(fromModel);
    toComboBox.setModel(toModel);
    // model for train types
    typeComboBox.setModel(new DefaultComboBoxModel<>(diagram.getTrainTypes().toArray(new TrainType[0])));
    typeComboBox.addItem(NO_TYPE);
    // reset through nodes
    throughNodes = new ArrayList<>();
    throughTextField.setText(throughNodes.toString());
    // update groups
    groupComboBox.updateGroups(diagram, new GroupSelect(selectedGroup != null ? GroupSelect.Type.GROUP : GroupSelect.Type.NONE, selectedGroup));
}
Also used : NodeComparator(net.parostroj.timetable.actions.NodeComparator) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ElementSort(net.parostroj.timetable.actions.ElementSort) GroupSelect(net.parostroj.timetable.gui.components.GroupSelect)

Example 2 with ElementSort

use of net.parostroj.timetable.actions.ElementSort 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 3 with ElementSort

use of net.parostroj.timetable.actions.ElementSort in project grafikon by jub77.

the class CreateRouteDialog method setValues.

private void setValues(TrainDiagram diagram, List<? extends RouteSegment<?>> route) {
    ElementSort<Node> sort = new ElementSort<Node>(new NodeComparator());
    availableNodes = sort.sort(diagram.getNet().getNodes());
    fromComboBox.removeAllItems();
    toComboBox.removeAllItems();
    for (Wrapper<Node> w : Wrapper.getWrapperList(availableNodes)) {
        fromComboBox.addItem(w);
        toComboBox.addItem(w);
    }
    throughNodes = new LinkedList<Node>();
    if (route != null && route.size() >= 2) {
        fromComboBox.setSelectedItem(Wrapper.getWrapper(route.get(0)));
        toComboBox.setSelectedItem(Wrapper.getWrapper(route.get(route.size() - 1)));
        for (int i = 1; i < route.size() - 1; i++) {
            RouteSegment<?> segment = route.get(i);
            if (segment.isNode()) {
                throughNodes.add(segment.asNode());
            }
        }
    }
    throughTextField.setText(throughNodes.toString());
}
Also used : NodeComparator(net.parostroj.timetable.actions.NodeComparator) Node(net.parostroj.timetable.model.Node) ElementSort(net.parostroj.timetable.actions.ElementSort)

Example 4 with ElementSort

use of net.parostroj.timetable.actions.ElementSort in project grafikon by jub77.

the class ThroughNodesDialog method setNodes.

/**
 * sets list of nodes.
 *
 * @param nodes list of nodes
 */
public void setNodes(List<Node> nodes, Collection<Node> allNodes) {
    this.nodes = nodes;
    // update values for nodes
    ElementSort<Node> sort = new ElementSort<Node>(new NodeComparator());
    List<Node> sorted = sort.sort(allNodes);
    nodeComboBox.removeAllItems();
    for (Node node : sorted) {
        nodeComboBox.addItem(node);
    }
    // update list
    nodeModel = new WrapperListModel<Node>(false);
    for (Node n : nodes) {
        nodeModel.addWrapper(Wrapper.getWrapper(n));
    }
    nodeList.setModel(nodeModel);
    this.pack();
}
Also used : NodeComparator(net.parostroj.timetable.actions.NodeComparator) Node(net.parostroj.timetable.model.Node) ElementSort(net.parostroj.timetable.actions.ElementSort)

Example 5 with ElementSort

use of net.parostroj.timetable.actions.ElementSort in project grafikon by jub77.

the class SelectNodesDialog method setNodes.

public void setNodes(Set<Node> nodes) {
    List<Node> sortedNodes = (new ElementSort<Node>(new NodeComparator())).sort(nodes);
    nodesComboBox.removeAllItems();
    for (Node node : sortedNodes) {
        nodesComboBox.addItem(node);
    }
    nodesComboBox.setSelectedIndex(0);
    this.selectedNode = null;
    this.pack();
}
Also used : NodeComparator(net.parostroj.timetable.actions.NodeComparator) Node(net.parostroj.timetable.model.Node) ElementSort(net.parostroj.timetable.actions.ElementSort)

Aggregations

ElementSort (net.parostroj.timetable.actions.ElementSort)5 NodeComparator (net.parostroj.timetable.actions.NodeComparator)4 Node (net.parostroj.timetable.model.Node)4 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 TrainComparator (net.parostroj.timetable.actions.TrainComparator)1 GroupSelect (net.parostroj.timetable.gui.components.GroupSelect)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Train (net.parostroj.timetable.model.Train)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1 Pair (net.parostroj.timetable.utils.Pair)1