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