Search in sources :

Example 1 with TrainBuilder

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

the class CreateTrainCommand method execute.

@Override
public void execute(ApplicationModel model) {
    TrainBuilder trainBuilder = new TrainBuilder();
    Train train = trainBuilder.createTrain(IdGenerator.getInstance().getId(), number, type, topSpeed, route, time, model.getDiagram(), defaultStop);
    train.setAttribute(Train.ATTR_DIESEL, diesel);
    train.setAttribute(Train.ATTR_ELECTRIC, electric);
    train.setDescription(description);
    if (train.getType() != null && train.getType().getCategory() != null && !train.getType().getCategory().getKey().equals("freight")) {
        train.setAttribute(Train.ATTR_EMPTY, Boolean.TRUE);
    }
    if (showLength) {
        train.setAttribute(Train.ATTR_SHOW_STATION_LENGTH, Boolean.TRUE);
    }
    if (group != null) {
        train.setAttribute(Train.ATTR_GROUP, group);
    }
    if (managedFreight) {
        train.setAttribute(Train.ATTR_MANAGED_FREIGHT, managedFreight);
    }
    // add train to diagram
    model.getDiagram().getTrains().add(train);
}
Also used : TrainBuilder(net.parostroj.timetable.actions.TrainBuilder)

Example 2 with TrainBuilder

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

the class TrainListView method changeRoute.

private void changeRoute() {
    CreateRouteDialog dialog = new CreateRouteDialog();
    dialog.setLocationRelativeTo(menuButton);
    Train oldTrain = model.getSelectedTrain();
    List<Node> result = dialog.showDialog(model.getDiagram(), Arrays.asList(oldTrain.getStartNode(), oldTrain.getEndNode()));
    if (result != null) {
        try {
            RouteBuilder rb = new RouteBuilder();
            Route route = rb.createRoute(null, model.getDiagram().getNet(), result);
            if (route == null) {
                throw new IllegalArgumentException("No route available.");
            }
            TrainBuilder builder = new TrainBuilder();
            model.setSelectedTrain(null);
            this.deleteTrain(oldTrain, oldTrain.getDiagram());
            Train newTrain = builder.createTrain(oldTrain, route);
            model.getDiagram().getTrains().add(newTrain);
            model.setSelectedTrain(newTrain);
        } catch (Exception e) {
            log.warn("Error changing route of the train.", e);
            GuiComponentUtils.showError(ResourceLoader.getString("dialog.error.title") + ": " + e.getMessage(), this);
        }
    }
}
Also used : RouteBuilder(net.parostroj.timetable.actions.RouteBuilder) TrainBuilder(net.parostroj.timetable.actions.TrainBuilder)

Example 3 with TrainBuilder

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

the class CopyTrainPM method writeResult.

private void writeResult() {
    // create copy of the train
    Train train = this.trainRef.get();
    if (train != null) {
        TrainDiagram diagram = train.getDiagram();
        int lTime = this.time.getTime();
        if (lTime == -1) {
            // select midnight if the time is not correct
            lTime = 0;
        }
        TrainBuilder builder = new TrainBuilder();
        String name = this.number.getText();
        Train newTrain = reversed.getBoolean() ? builder.createReverseTrain(IdGenerator.getInstance().getId(), name, lTime, train) : builder.createTrain(IdGenerator.getInstance().getId(), name, lTime, train);
        // add train to diagram
        diagram.getTrains().add(newTrain);
    }
}
Also used : TrainBuilder(net.parostroj.timetable.actions.TrainBuilder) Train(net.parostroj.timetable.model.Train) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Aggregations

TrainBuilder (net.parostroj.timetable.actions.TrainBuilder)3 RouteBuilder (net.parostroj.timetable.actions.RouteBuilder)1 Train (net.parostroj.timetable.model.Train)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1