use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class LSPenaltyTableHelper method fillPenaltyTable.
/**
* fills default values to penalty table.
*
* @param categories categories
*/
public static void fillPenaltyTable(List<TrainTypeCategory> categories) {
// passenger and freight categories
TrainTypeCategory pCat = createCategory("passenger");
TrainTypeCategory fCat = createCategory("freight");
categories.add(pCat);
categories.add(fCat);
for (LSPenaltyTableItem item : getLSPenaltyTable().getItemList()) {
TrainTypeCategory cat = item.getType() == LSSBType.FREIGHT ? fCat : pCat;
// upper limit decreased by one - backward compatibility with new implementation
cat.addRow(cat.createPenaltyTableRow(item.getUpperLimit() - 1, item.getSpeedingPenalty(), item.getBrakingPenalty()));
}
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class LSLibraryItem method createLibraryItem.
public LibraryItem createLibraryItem(LibraryBuilder libraryBuilder) throws LSException {
LibraryItemType type = LibraryItemType.valueOf(getType());
ObjectWithId object = null;
switch(type) {
case ENGINE_CLASS:
object = ((LSEngineClass) getObject()).createEngineClass(id -> {
ObjectWithId foundObject = libraryBuilder.getObjectById(id);
return foundObject instanceof LineClass ? (LineClass) foundObject : null;
});
break;
case LINE_CLASS:
object = ((LSLineClass) getObject()).createLineClass();
break;
case NODE:
object = ((LSNode) getObject()).createNode(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
break;
case OUTPUT_TEMPLATE:
object = ((LSOutputTemplate) getObject()).createOutputTemplate(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById);
break;
case TRAIN_TYPE:
object = ((LSTrainType) getObject()).createTrainType(libraryBuilder.getPartFactory(), libraryBuilder::getObjectById, id -> {
ObjectWithId foundObject = libraryBuilder.getObjectById(id);
return foundObject instanceof TrainTypeCategory ? (TrainTypeCategory) foundObject : null;
});
break;
case TRAIN_TYPE_CATEGORY:
object = ((LSTrainTypeCategory) getObject()).createTrainTypeCategory();
break;
}
LibraryItem item = libraryBuilder.addObject(object);
item.getAttributes().add(this.getAttributes().createAttributes(libraryBuilder::getObjectById));
return item;
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class TrainTypesCategoriesDialog method newButtonActionPerformed.
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
TrainTypesCategoriesNewDialog dialog = new TrainTypesCategoriesNewDialog(this);
dialog.setLocationRelativeTo(this);
dialog.setVisible(diagram);
if (dialog.getNewCategory() != null) {
TrainTypeCategory category = dialog.getNewCategory();
listModel.addTrainTypeCategory(category);
if (dialog.getTemplateCategory() != null) {
TrainTypeCategory template = dialog.getTemplateCategory();
// copy
List<PenaltyTableRow> tRows = template.getPenaltyRows();
for (PenaltyTableRow tRow : tRows) {
PenaltyTableRow row = category.createPenaltyTableRow(tRow.getSpeed(), tRow.getAcceleration(), tRow.getDeceleration());
category.addRow(row);
}
}
}
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class TrainTypeDialog method updateValuesForTrainType.
private void updateValuesForTrainType(TrainType selected, TrainDiagram diagram) {
// update categories
brakeComboBox.removeAllItems();
brakeComboBox.addItem(NONE_CATEGORY);
for (TrainTypeCategory category : diagram.getTrainTypeCategories()) {
brakeComboBox.addItem(Wrapper.getWrapper(category));
}
if (selected != null) {
abbrTextField.getPresentationModel().init(selected.getAbbr(), diagram.getLocales());
descTextField.getPresentationModel().init(selected.getDesc(), diagram.getLocales());
colorLabel.setText(Conversions.convertColorToText(selected.getColor()));
colorLabel.setForeground(selected.getColor());
TrainTypeCategory category = selected.getCategory();
brakeComboBox.setSelectedItem(category != null ? Wrapper.getWrapper(category) : NONE_CATEGORY);
nameTemplateCheckBox.setSelected(selected.getTrainNameTemplate() != null);
nameTemplateEditBox.setEnabled(selected.getTrainNameTemplate() != null);
nameTemplateEditBox.setTemplate(selected.getTrainNameTemplate() == null ? selected.getDiagram().getTrainsData().getTrainNameTemplate() : selected.getTrainNameTemplate());
completeNameTemplateCheckBox.setSelected(selected.getTrainCompleteNameTemplate() != null);
cNameTemplateEditBox.setEnabled(selected.getTrainCompleteNameTemplate() != null);
cNameTemplateEditBox.setTemplate(selected.getTrainCompleteNameTemplate() == null ? selected.getDiagram().getTrainsData().getTrainCompleteNameTemplate() : selected.getTrainCompleteNameTemplate());
platformNeededCheckBox.setSelected(selected.isPlatform());
showWeightInfoCheckBox.setSelected(selected.getAttributes().getBool(TrainType.ATTR_SHOW_WEIGHT_INFO));
// line information
Integer lineTypeInt = selected.getAttributes().get(TrainType.ATTR_LINE_TYPE, Integer.class);
LineType lineType = LineType.valueOf(lineTypeInt);
lineTypeComboBox.setSelectedIndex(lineType.ordinal());
lineWidthTextField.setText(Integer.toString(this.convertDoubleValueToPercent(selected, TrainType.ATTR_LINE_WIDTH)));
lineLengthTextField.setText(Integer.toString(this.convertDoubleValueToPercent(selected, TrainType.ATTR_LINE_LENGTH)));
} else {
abbrTextField.getPresentationModel().init(LocalizedString.fromString(""), diagram.getLocales());
descTextField.getPresentationModel().init(LocalizedString.fromString(""), diagram.getLocales());
colorLabel.setText("0x000000");
colorLabel.setForeground(Color.BLACK);
brakeComboBox.setSelectedItem(NONE_CATEGORY);
nameTemplateCheckBox.setSelected(false);
nameTemplateEditBox.setTemplate(diagram.getTrainsData().getTrainNameTemplate());
nameTemplateEditBox.setEnabled(false);
completeNameTemplateCheckBox.setSelected(false);
cNameTemplateEditBox.setTemplate(diagram.getTrainsData().getTrainCompleteNameTemplate());
cNameTemplateEditBox.setEnabled(false);
platformNeededCheckBox.setSelected(false);
showWeightInfoCheckBox.setSelected(false);
lineTypeComboBox.setSelectedIndex(0);
lineWidthTextField.setText("100");
lineLengthTextField.setText("100");
}
}
use of net.parostroj.timetable.model.TrainTypeCategory in project grafikon by jub77.
the class TrainTypeCategoryImport method importObjectImpl.
@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
// check class
if (!(o instanceof TrainTypeCategory))
return null;
TrainTypeCategory importedCategory = (TrainTypeCategory) o;
// check existence
TrainTypeCategory checkedCategory = this.getTrainTypeCategory(importedCategory);
if (checkedCategory != null) {
String message = "train type category already exists";
this.addError(importedCategory, message);
log.debug("{}: {}", message, checkedCategory);
return null;
}
// create new category
TrainTypeCategory category = copyFactory.copy(importedCategory, this.getId(importedCategory));
// add to diagram
this.getDiagram().getTrainTypeCategories().add(category);
this.addImportedObject(category);
log.trace("Successfully imported train type category: {}", category);
return category;
}
Aggregations