Search in sources :

Example 1 with NodeComparator

use of net.parostroj.timetable.actions.NodeComparator 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 NodeComparator

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

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

use of net.parostroj.timetable.actions.NodeComparator 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)4 NodeComparator (net.parostroj.timetable.actions.NodeComparator)4 Node (net.parostroj.timetable.model.Node)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 GroupSelect (net.parostroj.timetable.gui.components.GroupSelect)1