Search in sources :

Example 6 with TrainType

use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.

the class TrainTypesDialog method copy.

@Override
protected TrainType copy(String name, TrainType item) {
    CopyFactory copyFactory = new CopyFactory(element.getPartFactory());
    TrainType copiedType = copyFactory.copy(item, element.getPartFactory().createId());
    copiedType.setDesc(LocalizedString.fromString(name));
    return copiedType;
}
Also used : CopyFactory(net.parostroj.timetable.model.CopyFactory) TrainType(net.parostroj.timetable.model.TrainType)

Example 7 with TrainType

use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.

the class TrainTypesDialog method createNew.

@Override
protected TrainType createNew(String name) {
    TrainType newType = element.getPartFactory().createTrainType(element.getPartFactory().createId());
    newType.setDesc(LocalizedString.fromString(name));
    newType.setAbbr(LocalizedString.fromString(name));
    newType.setColor(Color.BLACK);
    return newType;
}
Also used : TrainType(net.parostroj.timetable.model.TrainType)

Example 8 with TrainType

use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.

the class FileLoadSaveImpl method save.

@Override
public void save(TrainDiagram diagram, ZipOutputStream zipOutput) throws LSException {
    try {
        // save metadata
        zipOutput.putNextEntry(new ZipEntry(METADATA));
        this.createMetadata(METADATA_KEY_MODEL_VERSION).store(zipOutput, null);
        FileLoadSaveAttachments attachments = new FileLoadSaveAttachments(DATA_ATTACHMENTS);
        // increase save version (increment by one)
        diagram.setSaveVersion(diagram.getSaveVersion() + 1);
        // update save timestamp
        diagram.setSaveTimestamp(new Date());
        // save train diagram
        this.save(zipOutput, DATA_TRAIN_DIAGRAM, new LSTrainDiagram(diagram));
        // save net
        this.save(zipOutput, DATA_NET, new LSNet(diagram.getNet()));
        int cnt = 0;
        // save train type categories
        for (TrainTypeCategory category : diagram.getTrainTypeCategories()) {
            this.save(zipOutput, this.createEntryName(DATA_TRAIN_TYPE_CATEGORIES, "xml", cnt++), new LSTrainTypeCategory(category));
        }
        cnt = 0;
        // save routes
        for (Route route : diagram.getRoutes()) {
            this.save(zipOutput, this.createEntryName(DATA_ROUTES, "xml", cnt++), new LSRoute(route));
        }
        cnt = 0;
        // save train types
        for (TrainType trainType : diagram.getTrainTypes()) {
            this.save(zipOutput, this.createEntryName(DATA_TRAIN_TYPES, "xml", cnt++), new LSTrainType(trainType));
        }
        cnt = 0;
        // save trains
        for (Train train : diagram.getTrains()) {
            this.save(zipOutput, this.createEntryName(DATA_TRAINS, "xml", cnt++), new LSTrain(train));
        }
        cnt = 0;
        // save engine classes
        for (EngineClass engineClass : diagram.getEngineClasses()) {
            this.save(zipOutput, this.createEntryName(DATA_ENGINE_CLASSES, "xml", cnt++), new LSEngineClass(engineClass));
        }
        cnt = 0;
        // save text items
        for (TextItem item : diagram.getTextItems()) {
            this.save(zipOutput, this.createEntryName(DATA_TEXT_ITEMS, "xml", cnt++), new LSTextItem(item));
        }
        cnt = 0;
        // save output templates
        for (OutputTemplate template : diagram.getOutputTemplates()) {
            LSOutputTemplate lsOutputTemplate = Boolean.TRUE.equals(properties.get("inline.output.template.attachments")) ? new LSOutputTemplate(template) : new LSOutputTemplate(template, attachments);
            this.save(zipOutput, this.createEntryName(DATA_OUTPUT_TEMPLATES, "xml", cnt++), lsOutputTemplate);
        }
        cnt = 0;
        // save diagram change sets
        for (String version : diagram.getChangesTracker().getVersions()) {
            DiagramChangeSet set = diagram.getChangesTracker().getChangeSet(version);
            if (!set.getChanges().isEmpty())
                this.save(zipOutput, this.createEntryName(DATA_CHANGES, "xml", cnt++), new LSDiagramChangeSet(set));
        }
        cnt = 0;
        // save trains cycles
        for (TrainsCycle cycle : diagram.getCycles()) {
            this.save(zipOutput, this.createEntryName(DATA_TRAINS_CYCLES, "xml", cnt++), new LSTrainsCycle(cycle));
        }
        cnt = 0;
        // save outputs
        for (Output output : diagram.getOutputs()) {
            this.save(zipOutput, this.createEntryName(DATA_OUTPUTS, "xml", cnt++), new LSOutput(output));
        }
        // save images
        cnt = 0;
        FileLoadSaveImages saveImages = new FileLoadSaveImages(DATA_IMAGES);
        for (TimetableImage image : diagram.getImages()) {
            this.save(zipOutput, createEntryName(DATA_IMAGES, "xml", cnt++), new LSImage(image));
            saveImages.saveTimetableImage(image, zipOutput);
        }
        // save attachments
        attachments.save(zipOutput);
        // save freight net
        this.save(zipOutput, FREIGHT_NET, new LSFreightNet(diagram.getFreightNet()));
    } catch (IOException ex) {
        throw new LSException(ex);
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TextItem(net.parostroj.timetable.model.TextItem) ZipEntry(java.util.zip.ZipEntry) Output(net.parostroj.timetable.model.Output) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) TrainType(net.parostroj.timetable.model.TrainType) Route(net.parostroj.timetable.model.Route) TimetableImage(net.parostroj.timetable.model.TimetableImage) DiagramChangeSet(net.parostroj.timetable.model.changes.DiagramChangeSet) IOException(java.io.IOException) Date(java.util.Date) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) EngineClass(net.parostroj.timetable.model.EngineClass) Train(net.parostroj.timetable.model.Train) LSException(net.parostroj.timetable.model.ls.LSException)

Example 9 with TrainType

use of net.parostroj.timetable.model.TrainType in project grafikon by jub77.

the class ChildrenDelegateTypesImpl method addChildNode.

@Override
public int addChildNode(TrainTreeNode node, TrainTreeNode newChildNode) {
    TrainType newType = this.getTypeFromNode(newChildNode);
    if (newType != null) {
        TrainDiagram diagram = newType.getDiagram();
        for (int i = 0; i < node.getChildCount(); i++) {
            TrainTreeNode childNode = (TrainTreeNode) node.getChildAt(i);
            if (this.compareTypes(diagram, this.getTypeFromNode(newChildNode), this.getTypeFromNode(childNode)) < 0) {
                node.insert(newChildNode, i);
                return i;
            }
        }
    }
    node.add(newChildNode);
    return node.getChildCount() - 1;
}
Also used : TrainType(net.parostroj.timetable.model.TrainType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 10 with TrainType

use of net.parostroj.timetable.model.TrainType 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)

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