Search in sources :

Example 1 with TrainType

use of net.parostroj.timetable.model.TrainType 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 TrainType

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

the class NodeDelegateTypeImpl method getNodeText.

@Override
public String getNodeText(TrainTreeNode trainTreeNode) {
    TrainType type = (TrainType) trainTreeNode.getUserObject();
    LocalizedString desc = type != null ? type.getDesc() : null;
    return type != null ? (desc != null ? desc.translate() : type.getDefaultAbbr()) : "-";
}
Also used : TrainType(net.parostroj.timetable.model.TrainType) LocalizedString(net.parostroj.timetable.model.LocalizedString)

Example 3 with TrainType

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

the class LSTrainType method createTrainType.

public TrainType createTrainType(TrainDiagram diagram) throws LSException {
    TrainType type = diagram.getPartFactory().createTrainType(id);
    type.setAbbr(LocalizedString.fromString(abbr));
    type.setColor(Conversions.convertTextToColor(color));
    type.setDesc(LocalizedString.fromString(desc));
    type.setPlatform(platform);
    type.setCategory(this.convertToCategory(diagram));
    try {
        type.setTrainCompleteNameTemplate(trainCompleteNameTemplate != null ? TextTemplate.createTextTemplate(trainCompleteNameTemplate, TextTemplate.Language.MVEL) : null);
        type.setTrainNameTemplate(trainNameTemplate != null ? TextTemplate.createTextTemplate(trainNameTemplate, TextTemplate.Language.MVEL) : null);
    } catch (GrafikonException e) {
        throw new LSException(e);
    }
    return type;
}
Also used : TrainType(net.parostroj.timetable.model.TrainType) LSException(net.parostroj.timetable.model.ls.LSException)

Example 4 with TrainType

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

the class TrainsFilterDialog method setTrainTypes.

public void setTrainTypes(TrainDiagram diagram, Set<TrainType> types) {
    if (diagram == null)
        return;
    typesPanel.removeAll();
    typesPanel.setLayout(new GridLayout((diagram.getTrainTypes().size() - 1) / COLUMNS + 1, COLUMNS));
    typesList = new LinkedList<Pair<TrainType, JCheckBox>>();
    for (TrainType type : diagram.getTrainTypes()) {
        JCheckBox checkBox = new JCheckBox(type.getDefaultAbbr() + " (" + type.getDesc() + ")");
        typesList.add(new Pair<TrainType, JCheckBox>(type, checkBox));
        checkBox.setSelected(types.contains(type));
        typesPanel.add(checkBox);
    }
    this.pack();
}
Also used : JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) TrainType(net.parostroj.timetable.model.TrainType) Pair(net.parostroj.timetable.utils.Pair)

Example 5 with TrainType

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

the class TrainTypeImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
    // check class
    if (!(o instanceof TrainType))
        return null;
    TrainType importedType = (TrainType) o;
    // check existence
    TrainType checkedType = this.getTrainType(importedType);
    if (checkedType != null) {
        String message = "train type already exists";
        this.addError(importedType, message);
        log.debug("{}: {}", message, checkedType);
        return null;
    }
    // get category
    TrainTypeCategory checkedCategory = this.getTrainTypeCategory(importedType.getCategory());
    if (checkedCategory == null) {
        String message = "category missing: " + importedType.getCategory();
        this.addError(importedType, message);
        log.debug(message);
        return null;
    }
    // create new type
    TrainType type = getDiagram().getPartFactory().createTrainType(this.getId(importedType));
    type.setAbbr(importedType.getAbbr());
    type.setColor(importedType.getColor());
    type.setDesc(importedType.getDesc());
    type.setPlatform(importedType.isPlatform());
    type.setCategory(checkedCategory);
    type.setTrainCompleteNameTemplate(importedType.getTrainCompleteNameTemplate());
    type.setTrainNameTemplate(importedType.getTrainNameTemplate());
    // add to diagram
    this.getDiagram().getTrainTypes().add(type);
    this.addImportedObject(type);
    log.trace("Successfully imported type: {}", type);
    return type;
}
Also used : TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) TrainType(net.parostroj.timetable.model.TrainType)

Aggregations

TrainType (net.parostroj.timetable.model.TrainType)18 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)4 LSException (net.parostroj.timetable.model.ls.LSException)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 Node (net.parostroj.timetable.model.Node)2 Train (net.parostroj.timetable.model.Train)2 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)2 LengthUnit (net.parostroj.timetable.model.units.LengthUnit)2 Pair (net.parostroj.timetable.utils.Pair)2 Color (java.awt.Color)1 GridLayout (java.awt.GridLayout)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 JCheckBox (javax.swing.JCheckBox)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 Attributes (net.parostroj.timetable.model.Attributes)1 CopyFactory (net.parostroj.timetable.model.CopyFactory)1