Search in sources :

Example 1 with TextTemplate

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));
                }
            }
        }
    }
}
Also used : Node(net.parostroj.timetable.model.Node) Region(net.parostroj.timetable.model.Region) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) TrainType(net.parostroj.timetable.model.TrainType) TextTemplate(net.parostroj.timetable.model.TextTemplate)

Example 2 with TextTemplate

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));
    }
}
Also used : TranslatedString(net.parostroj.timetable.model.TranslatedString) TextTemplate(net.parostroj.timetable.model.TextTemplate)

Example 3 with TextTemplate

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);
    }
}
Also used : GrafikonException(net.parostroj.timetable.model.GrafikonException) TextTemplate(net.parostroj.timetable.model.TextTemplate)

Example 4 with TextTemplate

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);
    }
}
Also used : OutputException(net.parostroj.timetable.output2.OutputException) TextTemplate(net.parostroj.timetable.model.TextTemplate) OutputException(net.parostroj.timetable.output2.OutputException)

Example 5 with TextTemplate

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();
}
Also used : TextTemplate(net.parostroj.timetable.model.TextTemplate)

Aggregations

TextTemplate (net.parostroj.timetable.model.TextTemplate)5 GrafikonException (net.parostroj.timetable.model.GrafikonException)1 Node (net.parostroj.timetable.model.Node)1 Region (net.parostroj.timetable.model.Region)1 TrainType (net.parostroj.timetable.model.TrainType)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)1 OutputException (net.parostroj.timetable.output2.OutputException)1