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