Search in sources :

Example 16 with Train

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

the class ChangedTrainsPanel method addTrainToList.

public void addTrainToList(Train train) {
    // check if the last train is the same ...
    if (listModel.getSize() > 0) {
        int index = listModel.getSize() - 1;
        Train lastTrain = listModel.getIndex(index).getElement();
        if (lastTrain == train) {
            listModel.refreshIndex(index);
            return;
        }
    }
    limitTrains(limit);
    // add to list
    Wrapper<Train> wrapper = Wrapper.getWrapper(train, new TrainWrapperDelegate(TrainWrapperDelegate.Type.NAME_AND_END_NODES_WITH_TIME, train.getDiagram().getTrainsData().getTrainComparator()));
    listModel.addWrapper(wrapper);
    trainsList.ensureIndexIsVisible(listModel.getSize() - 1);
}
Also used : Train(net.parostroj.timetable.model.Train) TrainWrapperDelegate(net.parostroj.timetable.gui.wrappers.TrainWrapperDelegate)

Example 17 with Train

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

the class RemoveWeightsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Component parent = GuiComponentUtils.getTopLevelComponent(e.getSource());
    int result = JOptionPane.showConfirmDialog(parent, ResourceLoader.getString("dialog.confirm.action.progress"), ResourceLoader.getString("menu.special.remove.weights"), JOptionPane.YES_NO_OPTION);
    if (result == JOptionPane.YES_OPTION) {
        // remove weights
        RxActionHandler.getInstance().newExecution("weight_removal", GuiComponentUtils.getTopLevelComponent(e.getSource()), model.get()).onBackground().logTime().setMessage(ResourceLoader.getString("wait.message.recalculate")).split(TrainDiagram::getTrains, 10).addEdtBatchConsumer((context, train) -> {
            train.removeAttribute(Train.ATTR_WEIGHT);
        }).execute();
    }
}
Also used : ApplicationModel(net.parostroj.timetable.gui.ApplicationModel) AbstractAction(javax.swing.AbstractAction) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) RxActionHandler(net.parostroj.timetable.gui.actions.execution.RxActionHandler) JOptionPane(javax.swing.JOptionPane) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Train(net.parostroj.timetable.model.Train) ResourceLoader(net.parostroj.timetable.utils.ResourceLoader) Component(java.awt.Component) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 18 with Train

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

the class WeightFilter method filter.

@Override
public TrainDiagram filter(TrainDiagram diagram, ModelVersion version) throws LSException {
    // fix weight info
    for (Train train : diagram.getTrains()) {
        Integer weight = TrainsHelper.getWeightFromInfoAttribute(train);
        if (weight != null)
            train.setAttribute(Train.ATTR_WEIGHT, weight);
        // remove weight.info attribute
        train.removeAttribute("weight.info");
    }
    return diagram;
}
Also used : Train(net.parostroj.timetable.model.Train)

Example 19 with Train

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

the class ImportModelAction method processImportedObject.

private void processImportedObject(ObjectWithId o, TrainImportConfig trainImportConfig) {
    // if train import -> move to appropriate group
    if (o instanceof Train && trainImportConfig != null) {
        Group destGroup = trainImportConfig.getToGroup();
        ((Train) o).getAttributes().setRemove(Train.ATTR_GROUP, destGroup);
    }
}
Also used : Group(net.parostroj.timetable.model.Group) Train(net.parostroj.timetable.model.Train)

Example 20 with Train

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

Aggregations

Train (net.parostroj.timetable.model.Train)31 TimeInterval (net.parostroj.timetable.model.TimeInterval)8 LinkedList (java.util.LinkedList)5 Node (net.parostroj.timetable.model.Node)5 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)5 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)5 List (java.util.List)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Component (java.awt.Component)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 JOptionPane (javax.swing.JOptionPane)2 TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)2 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 Group (net.parostroj.timetable.model.Group)2 Route (net.parostroj.timetable.model.Route)2