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));
}
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);
}
}
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());
}
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();
}
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();
}
Aggregations