use of net.parostroj.timetable.model.TextTemplate in project grafikon by jub77.
the class LoadFilter4d18 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 18, 3)) <= 0) {
// adjust complete name templates
TextTemplate template = diagram.getTrainsData().getTrainCompleteNameTemplate();
diagram.getTrainsData().setTrainCompleteNameTemplate(this.adjustDescription(template));
for (TrainType type : diagram.getTrainTypes()) {
template = type.getTrainCompleteNameTemplate();
if (template != null) {
type.setTrainCompleteNameTemplate(this.adjustDescription(template));
}
}
}
if (version.compareTo(new ModelVersion(4, 18, 4)) <= 0) {
// multiple regions allowed per node (even centers)
for (Node node : diagram.getNet().getNodes()) {
Region region = (Region) node.removeAttribute("region");
if (region != null) {
Boolean regionCenter = (Boolean) node.removeAttribute("region.start");
node.setAttribute(Node.ATTR_REGIONS, Collections.singleton(region));
if (regionCenter != null && regionCenter) {
node.setAttribute(Node.ATTR_CENTER_OF_REGIONS, Collections.singleton(region));
}
}
}
}
}
use of net.parostroj.timetable.model.TextTemplate in project grafikon by jub77.
the class TrainTimetablesExtractor method extractRouteInfo.
private void extractRouteInfo(Train train, TrainTimetable timetable) {
TextTemplate routeTemplate = train.getAttribute(Train.ATTR_ROUTE, TextTemplate.class);
if (routeTemplate == null) {
return;
}
String result = routeTemplate.evaluate(TextTemplate.getBinding(train));
timetable.setRouteInfo(new LinkedList<RouteInfoPart>());
// split
String[] splitted = result.split("-");
for (String sPart : splitted) {
sPart = sPart.trim();
timetable.getRouteInfo().add(new RouteInfoPart(sPart, null));
}
}
use of net.parostroj.timetable.model.TextTemplate in project grafikon by jub77.
the class TextItemDialog method okButtonActionPerformed.
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
TextTemplate template = this.convertToTemplate();
this.resultItemModel = new TextItemModel(template, trainTimetableInfoCheckBox.isSelected());
this.setVisible(false);
} catch (GrafikonException e) {
log.error(e.getMessage(), e);
GuiComponentUtils.showError(e.getMessage(), this);
}
}
use of net.parostroj.timetable.model.TextTemplate in project grafikon by jub77.
the class GroovyTemplate method write.
private void write(OutputStream output, OutputParams params, TrainDiagram diagram, Locale locale, Charset outputEncoding) throws OutputException {
try {
Map<String, Object> map = binding.get(diagram, params, locale);
TextTemplate textTemplate = getTextTemplate(params);
if (textTemplate != null) {
textTemplate.evaluate(output, map, outputEncoding.name());
} else {
throw new OutputException("Template missing");
}
binding.postProcess(diagram, params, map);
} catch (OutputException e) {
throw e;
} catch (Exception e) {
throw new OutputException("Error evaluating template", e);
}
}
use of net.parostroj.timetable.model.TextTemplate in project grafikon by jub77.
the class TrainView method updateView.
private void updateView(Train train) {
if (train == null) {
trainTextField.setText(null);
speedTextField.setText(null);
techTimeTextField.setText(null);
speedTextField.setEnabled(false);
} else {
// train type
String name = train.getDefaultCompleteName();
TextTemplate routeTemplate = train.getAttribute(Train.ATTR_ROUTE, TextTemplate.class);
if (routeTemplate != null) {
name = String.format("%s (%s)", name, routeTemplate.evaluate(TextTemplate.getBinding(train)));
}
name = this.addPreviousTrain(name, train);
name = this.addNextTrain(name, train);
trainTextField.setText(name);
// scroll to the beginning - ensure that the start in visible
trainTextField.setCaretPosition(0);
Integer topSpeed = train.getTopSpeed();
speedTextField.setText(topSpeed == null ? "" : Integer.toString(topSpeed));
techTimeTextField.setText(this.createTechTimeString(train));
techTimeTextField.setCaretPosition(0);
speedTextField.setEnabled(true);
}
trainTable.removeEditor();
((TrainTableModel) trainTable.getModel()).setTrain(train);
this.invalidate();
}
Aggregations