Search in sources :

Example 1 with TrainTypeCategory

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()));
    }
}
Also used : TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 2 with TrainTypeCategory

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;
}
Also used : XmlAttribute(javax.xml.bind.annotation.XmlAttribute) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Node(net.parostroj.timetable.model.Node) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) XmlType(javax.xml.bind.annotation.XmlType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) XmlElements(javax.xml.bind.annotation.XmlElements) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) LSException(net.parostroj.timetable.model.ls.LSException) EngineClass(net.parostroj.timetable.model.EngineClass) TrainType(net.parostroj.timetable.model.TrainType) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) LineClass(net.parostroj.timetable.model.LineClass) XmlElement(javax.xml.bind.annotation.XmlElement) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) LibraryItem(net.parostroj.timetable.model.library.LibraryItem) LibraryItemType(net.parostroj.timetable.model.library.LibraryItemType) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 3 with TrainTypeCategory

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);
            }
        }
    }
}
Also used : PenaltyTableRow(net.parostroj.timetable.model.PenaltyTableRow) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Example 4 with TrainTypeCategory

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");
    }
}
Also used : TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) LineType(net.parostroj.timetable.model.LineType)

Example 5 with TrainTypeCategory

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;
}
Also used : TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory)

Aggregations

TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)16 TrainType (net.parostroj.timetable.model.TrainType)5 EngineClass (net.parostroj.timetable.model.EngineClass)2 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 ObjectWithId (net.parostroj.timetable.model.ObjectWithId)2 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)2 LSException (net.parostroj.timetable.model.ls.LSException)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlElements (javax.xml.bind.annotation.XmlElements)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 GrafikonException (net.parostroj.timetable.model.GrafikonException)1 LineClass (net.parostroj.timetable.model.LineClass)1