Search in sources :

Example 11 with TrainTypeCategory

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

Example 12 with TrainTypeCategory

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

Example 13 with TrainTypeCategory

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

Example 14 with TrainTypeCategory

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

Example 15 with TrainTypeCategory

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);
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) GrafikonException(net.parostroj.timetable.model.GrafikonException) Color(java.awt.Color) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) TrainType(net.parostroj.timetable.model.TrainType) LocalizedString(net.parostroj.timetable.model.LocalizedString)

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