use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.
the class LibraryBuilder method addTrainType.
public LibraryItem addTrainType(String id, LocalizedString desc) {
TrainType type = factory.createTrainType(id);
type.setDesc(desc);
return addImpl(type, LibraryItemType.TRAIN_TYPE);
}
use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.
the class DefaultTrainTypeListSource method getDefaultTypeList.
public static Pair<TrainsDataDto, List<TrainType>> getDefaultTypeList() throws LSException {
try {
LSTrainTypeSerializer serializer = LSTrainTypeSerializer.getLSTrainTypeSerializer(LSSerializer.getLatestVersion());
LSTrainTypeList lsList = serializer.load(new InputStreamReader(DefaultTrainTypeListSource.getDefaultTypesInputStream(), "utf-8"));
return new Pair<TrainsDataDto, List<TrainType>>(lsList.getTrainsData(), lsList.getTrainTypeList());
} catch (UnsupportedEncodingException e) {
throw new LSException("Cannot load default train type list.", e);
}
}
use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.
the class LocalizationFilter method filter.
@Override
public TrainDiagram filter(TrainDiagram diagram, ModelVersion version) throws LSException {
log.debug("Loaded version: {}", version);
this.convertToLocalizedStrings(diagram);
// convert train name templates (common)
diagram.getTrainsData().setTrainNameTemplate(convertForAbbreviation(diagram.getTrainsData().getTrainNameTemplate()));
diagram.getTrainsData().setTrainCompleteNameTemplate(convertForAbbreviation(diagram.getTrainsData().getTrainCompleteNameTemplate()));
// in train types
for (TrainType type : diagram.getTrainTypes()) {
type.setTrainNameTemplate(convertForAbbreviation(type.getTrainNameTemplate()));
type.setTrainCompleteNameTemplate(convertForAbbreviation(type.getTrainCompleteNameTemplate()));
}
return diagram;
}
use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.
the class TrainTypeDialog method updateButtonActionPerformed.
private void updateButtonActionPerformed() {
// update values of a type
TrainType type = trainType;
if (type != null) {
LocalizedString abbr = abbrTextField.getPresentationModel().getCurrentEdit().get();
LocalizedString desc = descTextField.getPresentationModel().getCurrentEdit().get();
// check values ....
if (abbr == null || desc == null) {
GuiComponentUtils.showError("dialog.error.missingvalues", this);
return;
}
type.setAbbr(abbr);
type.setDesc(desc);
type.setPlatform(platformNeededCheckBox.isSelected());
type.getAttributes().setBool(TrainType.ATTR_SHOW_WEIGHT_INFO, showWeightInfoCheckBox.isSelected());
Color c = Conversions.convertTextToColor(colorLabel.getText());
type.setColor(c);
Wrapper<?> categoryWrapper = (Wrapper<?>) brakeComboBox.getSelectedItem();
type.setCategory(categoryWrapper != NONE_CATEGORY ? (TrainTypeCategory) categoryWrapper.getElement() : null);
if (nameTemplateCheckBox.isSelected()) {
try {
type.setTrainNameTemplate(nameTemplateEditBox.getTemplate());
} catch (GrafikonException e) {
GuiComponentUtils.showWarning(e.getMessage(), this);
log.warn(e.getMessage(), e);
return;
}
} else {
type.setTrainNameTemplate(null);
}
if (completeNameTemplateCheckBox.isSelected()) {
try {
type.setTrainCompleteNameTemplate(cNameTemplateEditBox.getTemplate());
} catch (GrafikonException e) {
GuiComponentUtils.showWarning(e.getMessage(), this);
log.warn(e.getMessage(), e);
return;
}
} else {
type.setTrainCompleteNameTemplate(null);
}
type.getAttributes().setRemove(TrainType.ATTR_LINE_TYPE, extractLineType());
type.getAttributes().setRemove(TrainType.ATTR_LINE_WIDTH, extractRatioFromPercentage(lineWidthTextField));
type.getAttributes().setRemove(TrainType.ATTR_LINE_LENGTH, extractRatioFromPercentage(lineLengthTextField));
}
setVisible(false);
}
use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.
the class TrainDiagramBuilder method setTrainType.
public void setTrainType(LSTrainType lsType) throws LSException {
TrainType type = lsType.createTrainType(diagram.getPartFactory(), diagram::getObjectById, diagram.getTrainTypeCategories()::getById);
TrainType foundTrainType = null;
if ((foundTrainType = diagram.getTrainTypes().getById(type.getId())) != null) {
diagram.getTrainTypes().remove(foundTrainType);
}
diagram.getTrainTypes().add(type);
}
Aggregations