use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class LibraryBuilder method importTrainType.
public LibraryItem importTrainType(TrainType trainType) {
TrainType trainTypeCopy = copyFactory.copy(trainType, trainType.getId());
// TODO fix train name template reference
if (trainType.getCategory() != null) {
ObjectWithId category = this.getObjectById(trainType.getCategory().getId());
if (category == null) {
if (config.isAddMissing()) {
LibraryItem categoryItem = this.importTrainTypeCategory(trainType.getCategory());
category = categoryItem.getObject();
} else {
throw new IllegalArgumentException("Train type category missing from library: " + trainType.getCategory());
}
} else if (!(category instanceof TrainTypeCategory)) {
throw new IllegalArgumentException("Wrong type of category: " + category);
}
trainTypeCopy.setCategory((TrainTypeCategory) category);
}
return addImpl(trainTypeCopy, LibraryItemType.TRAIN_TYPE);
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class LibraryBuilder method addTrainTypeCategory.
public LibraryItem addTrainTypeCategory(String id, LocalizedString name, String key) {
TrainTypeCategory category = factory.createTrainTypeCategory(id);
category.setKey(key);
category.setName(name);
return addImpl(category, LibraryItemType.TRAIN_TYPE_CATEGORY);
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class TrainTypesCategoriesNewDialog method setVisible.
public void setVisible(TrainDiagram diagram) {
templateComboBox.removeAllItems();
templateComboBox.addItem(new Wrapper<>(noneCategory));
for (TrainTypeCategory cat : diagram.getTrainTypeCategories()) {
templateComboBox.addItem(new Wrapper<>(cat));
}
templateComboBox.setMaximumRowCount(Math.min(10, templateComboBox.getItemCount()));
nameTextField.setText("");
keyTextField.setSelectedItem("passenger");
newCategory = null;
templateCategory = null;
setVisible(true);
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class TrainTypesCategoriesNewDialog method createResult.
protected boolean createResult() {
String name = nameTextField.getText().trim();
String key = ((String) keyTextField.getSelectedItem()).trim();
if (name.equals("") || key.equals("")) {
return false;
} else {
newCategory = new TrainTypeCategory(IdGenerator.getInstance().getId());
newCategory.setKey(key);
newCategory.setName(LocalizedString.fromString(name));
TrainTypeCategory template = (TrainTypeCategory) ((Wrapper<?>) templateComboBox.getSelectedItem()).getElement();
if (template != noneCategory) {
templateCategory = template;
}
return true;
}
}
use of net.parostroj.timetable.model.TrainTypeCategory 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);
}
Aggregations