Search in sources :

Example 11 with TrainType

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

Example 12 with TrainType

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TrainType(net.parostroj.timetable.model.TrainType) LSException(net.parostroj.timetable.model.ls.LSException) Pair(net.parostroj.timetable.utils.Pair)

Example 13 with TrainType

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

Example 14 with TrainType

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);
}
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)

Example 15 with TrainType

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

Aggregations

TrainType (net.parostroj.timetable.model.TrainType)18 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)4 LSException (net.parostroj.timetable.model.ls.LSException)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 Node (net.parostroj.timetable.model.Node)2 Train (net.parostroj.timetable.model.Train)2 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)2 LengthUnit (net.parostroj.timetable.model.units.LengthUnit)2 Pair (net.parostroj.timetable.utils.Pair)2 Color (java.awt.Color)1 GridLayout (java.awt.GridLayout)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 JCheckBox (javax.swing.JCheckBox)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 Attributes (net.parostroj.timetable.model.Attributes)1 CopyFactory (net.parostroj.timetable.model.CopyFactory)1