Search in sources :

Example 16 with TrainDiagram

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

the class TrainsCycleValidator method validate.

@Override
public boolean validate(Event event) {
    boolean validated = false;
    if (event.getSource() instanceof TrainsCycle) {
        validated = handleTrainsCycleEvent(event);
    }
    if (event.getSource() instanceof TrainDiagram && event.getObject() instanceof TrainsCycle && event.getType() == Event.Type.REMOVED) {
        TrainsCycle deleted = (TrainsCycle) event.getObject();
        // handle sequence of circulations
        if (deleted.isPartOfSequence()) {
            deleted.removeFromSequence();
        }
        validated = true;
    }
    return validated;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 17 with TrainDiagram

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

the class ImportAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    final Component parent = GuiComponentUtils.getTopLevelComponent(event.getSource());
    ActionContext context = new ActionContext(parent);
    ActionHandler handler = ActionHandler.getInstance();
    context.setAttribute("fileType", supportLibrary ? FileChooserFactory.Type.GTM_GTML : FileChooserFactory.Type.GTM);
    context.setAttribute("diagramImport", model.getDiagram());
    handler.execute(new OpenFileModelAction(context));
    handler.execute(new SelectLoadAction(context));
    handler.execute(new LoadDiagramModelAction(context));
    handler.execute(new LoadLibraryModelAction(context));
    handler.execute(new EventDispatchModelAction(context) {

        @Override
        protected void eventDispatchAction() {
            TrainDiagram diagram = (TrainDiagram) context.getAttribute("diagram");
            boolean cancelled = false;
            Predicate<ObjectWithId> filter = null;
            if (trainImport) {
                groupDialog.setLocationRelativeTo(parent);
                groupDialog.showDialog(diagram, null, model.getDiagram(), null);
                if (groupDialog.isSelected()) {
                    final Group group = groupDialog.getSelectedFrom();
                    filter = new TrainGroupFilter(group);
                } else {
                    cancelled = !groupDialog.isSelected();
                }
            }
            context.setAttribute("trainFilter", filter);
            context.setCancelled(cancelled);
            if (trainImport) {
                context.setAttribute("trainImport", new ImportModelAction.TrainImportConfig(groupDialog.isRemoveExistingTrains(), groupDialog.getSelectedFrom(), groupDialog.getSelectedTo()));
            }
        }
    });
    handler.execute(new ImportSelectionModelAction(context));
    handler.execute(new ImportModelAction(context));
}
Also used : Group(net.parostroj.timetable.model.Group) TrainGroupFilter(net.parostroj.timetable.gui.actions.impl.ImportSelectionModelAction.TrainGroupFilter) LoadDiagramModelAction(net.parostroj.timetable.gui.actions.impl.LoadDiagramModelAction) ImportSelectionModelAction(net.parostroj.timetable.gui.actions.impl.ImportSelectionModelAction) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext) OpenFileModelAction(net.parostroj.timetable.gui.actions.impl.OpenFileModelAction) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Predicate(com.google.common.base.Predicate) ImportModelAction(net.parostroj.timetable.gui.actions.execution.ImportModelAction) EventDispatchModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchModelAction) SelectLoadAction(net.parostroj.timetable.gui.actions.impl.SelectLoadAction) LoadLibraryModelAction(net.parostroj.timetable.gui.actions.impl.LoadLibraryModelAction) Component(java.awt.Component) ActionHandler(net.parostroj.timetable.gui.actions.execution.ActionHandler)

Example 18 with TrainDiagram

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

the class OutputPM method operationCreate.

@Operation(path = "create")
public boolean operationCreate() {
    TrainDiagram diagram = diagramRef != null ? diagramRef.get() : null;
    if (diagram != null) {
        newOutput = diagram.getPartFactory().createOutput(IdGenerator.getInstance().getId());
        newOutput.setName(LocalizedString.fromString(name.getCurrentEdit().get().translate()));
        newOutput.setTemplate(templates.getValue());
        newOutput.setLocale(locale.getValue());
        newOutput.setKey(key.getText());
    }
    return true;
}
Also used : TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Operation(org.beanfabrics.support.Operation)

Example 19 with TrainDiagram

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

the class LoadSave method loadTrainDiagram.

private TrainDiagram loadTrainDiagram(ModelVersion modelVersion, Properties metadata, Reader reader, LSTrainTypeList types) throws LSException, IOException {
    LSSerializer serializer = LSSerializer.getLSSerializer(modelVersion);
    TrainDiagram diagram = serializer.load(reader, types);
    for (TrainDiagramFilter filter : loadFilters) {
        diagram = filter.filter(diagram, modelVersion);
    }
    (new AfterLoadCheck()).check(diagram);
    return diagram;
}
Also used : AfterLoadCheck(net.parostroj.timetable.actions.AfterLoadCheck) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 20 with TrainDiagram

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

the class CopyTrainPM method writeResult.

private void writeResult() {
    // create copy of the train
    Train train = this.trainRef.get();
    if (train != null) {
        TrainDiagram diagram = train.getDiagram();
        int lTime = this.time.getTime();
        if (lTime == -1) {
            // select midnight if the time is not correct
            lTime = 0;
        }
        TrainBuilder builder = new TrainBuilder();
        String name = this.number.getText();
        Train newTrain = reversed.getBoolean() ? builder.createReverseTrain(IdGenerator.getInstance().getId(), name, lTime, train) : builder.createTrain(IdGenerator.getInstance().getId(), name, lTime, train);
        // add train to diagram
        diagram.getTrains().add(newTrain);
    }
}
Also used : TrainBuilder(net.parostroj.timetable.actions.TrainBuilder) Train(net.parostroj.timetable.model.Train) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Aggregations

TrainDiagram (net.parostroj.timetable.model.TrainDiagram)23 LSException (net.parostroj.timetable.model.ls.LSException)5 IOException (java.io.IOException)4 Train (net.parostroj.timetable.model.Train)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)3 Component (java.awt.Component)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipEntry (java.util.zip.ZipEntry)2 JOptionPane (javax.swing.JOptionPane)2 AfterLoadCheck (net.parostroj.timetable.actions.AfterLoadCheck)2 ExportImportSelection (net.parostroj.timetable.gui.components.ExportImportSelection)2 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 Library (net.parostroj.timetable.model.library.Library)2 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)2 Predicate (com.google.common.base.Predicate)1