Search in sources :

Example 1 with TimeInterval

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

the class NodeTimetableByTracksWriter method writeNodeTimetable.

/**
 * writes node timetable.
 *
 * @param node node
 * @param str appendable
 */
public void writeNodeTimetable(Node node, Appendable str) throws IOException {
    TimeConverter c = node.getDiagram().getTimeConverter();
    str.append("Node: ");
    str.append(node.getName()).append('\n');
    List<NodeTrack> tracks = node.getTracks();
    for (NodeTrack track : tracks) {
        str.append("Track: " + track.getNumber()).append('\n');
        for (TimeInterval interval : track.getTimeIntervalList()) {
            try (Formatter f = new Formatter(str)) {
                f.format("%1$-20s", interval.getTrain().getDefaultCompleteName());
                str.append(c.convertIntToText(interval.getStart(), true));
                str.append(" ").append(c.convertIntToText(interval.getEnd(), true)).append("\n");
                f.flush();
            }
        }
    }
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) TimeInterval(net.parostroj.timetable.model.TimeInterval) Formatter(java.util.Formatter) TimeConverter(net.parostroj.timetable.model.TimeConverter)

Example 2 with TimeInterval

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

the class TrainTimetableWriter method writeTrainTimetable.

/**
 * writes train timetable.
 *
 * @param train train
 * @param str appendable
 */
public void writeTrainTimetable(Train train, Appendable str) throws IOException {
    TimeConverter c = train.getDiagram().getTimeConverter();
    str.append("Train: ");
    str.append(train.getDefaultCompleteName()).append('\n');
    for (TimeInterval time : train.getNodeIntervals()) {
        Node node = time.getOwnerAsNode();
        @SuppressWarnings("resource") Formatter f = new Formatter(str);
        f.format("%1$-20s", node.getName());
        if (time.isFirst() || !time.isStop()) {
            str.append("      ").append(c.convertIntToText(time.getEnd(), true)).append("\n");
        } else if (time.isLast()) {
            str.append(c.convertIntToText(time.getStart(), true)).append("\n");
        } else if (time.isStop()) {
            str.append(c.convertIntToText(time.getStart(), true)).append(" ");
            str.append(c.convertIntToText(time.getEnd(), true)).append("\n");
        } else {
            str.append('\n');
        }
        f.flush();
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) Formatter(java.util.Formatter) Node(net.parostroj.timetable.model.Node) TimeConverter(net.parostroj.timetable.model.TimeConverter)

Example 3 with TimeInterval

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

the class PreviousNextTrainValidator method checkTrainIntervals.

private void checkTrainIntervals(Event event, Train currentTrain) {
    if (event.getType() == Type.SPECIAL && event.getData() instanceof SpecialTrainTimeIntervalList) {
        SpecialTrainTimeIntervalList list = (SpecialTrainTimeIntervalList) event.getData();
        if (list.getType() == SpecialTrainTimeIntervalList.Type.TRACK) {
            int changed = list.getChanged();
            if (currentTrain.getPreviousJoinedTrain() != null && changed == 0) {
                TimeInterval source = currentTrain.getFirstInterval();
                TimeInterval dest = currentTrain.getPreviousJoinedTrain().getLastInterval();
                checkAndUpdateTrack(source, dest);
            } else if (currentTrain.getNextJoinedTrain() != null && changed == currentTrain.getTimeIntervalList().size() - 1) {
                TimeInterval source = currentTrain.getLastInterval();
                TimeInterval dest = currentTrain.getNextJoinedTrain().getFirstInterval();
                checkAndUpdateTrack(source, dest);
            }
        }
        if (currentTrain.getNextJoinedTrain() != null) {
            checkAndUpdateNextTrainStart(currentTrain);
            checkAndUpdateTimeAfter(currentTrain);
        }
        if (currentTrain.getPreviousJoinedTrain() != null) {
            checkAndUpdateTimeAfter(currentTrain.getPreviousJoinedTrain());
        }
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) SpecialTrainTimeIntervalList(net.parostroj.timetable.model.events.SpecialTrainTimeIntervalList)

Example 4 with TimeInterval

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

the class TrainDiagramBuilder method setFreightNet.

public void setFreightNet(LSFreightNet lsFreightNet) throws LSException {
    FreightNet net = lsFreightNet.createFreightNet(diagram);
    this.diagram.setFreightNet(net);
    for (LSFreightConnection lsConnection : lsFreightNet.getConnections()) {
        Train from = diagram.getTrains().getById(lsConnection.getTrainFrom());
        Train to = diagram.getTrains().getById(lsConnection.getTrainTo());
        TimeInterval iFrom = from.getIntervalById(lsConnection.getIntervalFrom());
        TimeInterval iTo = to.getIntervalById(lsConnection.getIntervalTo());
        FNConnection connection = diagram.getFreightNet().addConnection(iFrom, iTo);
        connection.merge(lsConnection.getAttributes().createAttributes(diagram::getObjectById));
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) Train(net.parostroj.timetable.model.Train) FNConnection(net.parostroj.timetable.model.FNConnection) FreightNet(net.parostroj.timetable.model.FreightNet)

Example 5 with TimeInterval

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

the class FreightNetPane2 method updateInfo.

private void updateInfo() {
    StringBuilder builder = new StringBuilder();
    FNConnection conn = selector.getSelectedConnection();
    TimeInterval from = conn != null ? conn.getFrom() : connection.first;
    TimeInterval to = conn != null ? conn.getTo() : connection.second;
    if (from != null) {
        builder.append(from.getOwnerAsNode().getAbbr()).append(": ");
        builder.append(getIntervalInfo(from, true));
    }
    if (to != null) {
        builder.append(" -> ").append(getIntervalInfo(to, false));
    }
    infoTextField.setText(builder.toString());
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) FNConnection(net.parostroj.timetable.model.FNConnection)

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