Search in sources :

Example 31 with LSException

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

the class TrainsNamesLoadFilter method filter.

@Override
public TrainDiagram filter(TrainDiagram diagram, ModelVersion version) throws LSException {
    if (version.getMajorVersion() <= 2 && version.getMinorVersion() < 1) {
        Pair<TrainsDataDto, List<TrainType>> defaultList = DefaultTrainTypeListSource.getDefaultTypeList();
        // add train sort pattern ...
        if (diagram.getTrainsData().getTrainSortPattern() == null)
            diagram.getTrainsData().setTrainSortPattern(defaultList.first.getTrainSortPattern());
        // set default train name templates
        if (diagram.getTrainsData().getTrainNameTemplate() == null)
            diagram.getTrainsData().setTrainNameTemplate(defaultList.first.getTrainNameTemplate());
        if (diagram.getTrainsData().getTrainCompleteNameTemplate() == null)
            diagram.getTrainsData().setTrainCompleteNameTemplate(defaultList.first.getTrainCompleteNameTemplate());
        // do conversion (remove everything but train number) ...
        Pattern conversionPattern = Pattern.compile("\\D+(\\d+.*)");
        // convert name of all trains
        for (Train train : diagram.getTrains()) {
            try {
                Matcher m = conversionPattern.matcher(train.getNumber());
                if (m.matches()) {
                    train.setNumber(m.group(1));
                } else {
                    log.warn("Cannot convert train name. Name doesn't match: {}", train.getNumber());
                }
            } catch (Exception e) {
                log.warn("Cannot convert train name.", e);
            }
        }
    }
    return diagram;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) List(java.util.List) LSException(net.parostroj.timetable.model.ls.LSException)

Example 32 with LSException

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

the class LSSerializerImpl2 method save.

@Override
public void save(Writer writer, TrainDiagram diagram, LSTrainTypeList trainTypeList) throws LSException {
    try {
        LSTransformationData data = new LSTransformationData(trainTypeList);
        LSTrainDiagram lsDiagram = new LSTrainDiagram(diagram, data);
        marshaller.marshal(lsDiagram, writer);
    } catch (JAXBException e) {
        throw new LSException("Cannot save train diagram.", e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) LSException(net.parostroj.timetable.model.ls.LSException)

Example 33 with LSException

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

the class LSSerializerImpl2 method load.

@Override
public TrainDiagram load(Reader reader, LSTrainTypeList trainTypeList) throws LSException {
    try {
        LSTrainDiagram lsDiagram = (LSTrainDiagram) unmarshaller.unmarshal(new NoCloseAllowedReader(reader));
        LSVisitorBuilder builderVisitor = new LSVisitorBuilder(trainTypeList);
        lsDiagram.visit(builderVisitor);
        return builderVisitor.getTrainDiagram();
    } catch (JAXBException e) {
        throw new LSException("Cannot load train diagram.", e);
    }
}
Also used : NoCloseAllowedReader(net.parostroj.timetable.model.save.NoCloseAllowedReader) JAXBException(javax.xml.bind.JAXBException) LSException(net.parostroj.timetable.model.ls.LSException)

Example 34 with LSException

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

the class MainFrame method aboutMenuItemActionPerformed.

private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    // show about dialog
    ResourceBundle aboutBundle = ResourceBundle.getBundle("about");
    LSFileFactory f = LSFileFactory.getInstance();
    LSFile fls = null;
    try {
        fls = f.createForSave();
    } catch (LSException e) {
        log.warn("Cannot create FileLoadSave", e);
    }
    AboutDialog dialog = new AboutDialog(this, true, String.format(aboutBundle.getString("text"), model.getVersionInfo().getVersion(), fls == null ? "-" : fls.getSaveVersion()), getClass().getResource(aboutBundle.getString("image")), true, model.getVersionInfo());
    dialog.setLocationRelativeTo(this);
    dialog.setVisible(true);
    dialog.dispose();
}
Also used : LSFile(net.parostroj.timetable.model.ls.LSFile) LSFileFactory(net.parostroj.timetable.model.ls.LSFileFactory) LSException(net.parostroj.timetable.model.ls.LSException)

Example 35 with LSException

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

the class ExportAction method getSaveModelAction.

public static ModelAction getSaveModelAction(ActionContext context, final File file, final Component parent, final Library library) {
    ModelAction action = new EventDispatchAfterModelAction(context) {

        private String errorMessage;

        @Override
        protected void backgroundAction() {
            setWaitMessage(ResourceLoader.getString("wait.message.savelibrary"));
            setWaitDialogVisible(true);
            long time = System.currentTimeMillis();
            try {
                ModelUtils.saveLibraryData(library, file);
            } catch (LSException e) {
                log.warn("Error saving library.", e);
                errorMessage = ResourceLoader.getString("dialog.error.saving");
            } catch (Exception e) {
                log.warn("Error saving library.", e);
                errorMessage = ResourceLoader.getString("dialog.error.saving");
            } finally {
                log.debug("Saved in {}ms", System.currentTimeMillis() - time);
                setWaitDialogVisible(false);
            }
        }

        @Override
        protected void eventDispatchActionAfter() {
            if (errorMessage != null) {
                GuiComponentUtils.showError(errorMessage + " " + file.getName(), parent);
            }
        }
    };
    return action;
}
Also used : EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction) EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) LSException(net.parostroj.timetable.model.ls.LSException) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

LSException (net.parostroj.timetable.model.ls.LSException)38 IOException (java.io.IOException)8 JAXBException (javax.xml.bind.JAXBException)7 LSFile (net.parostroj.timetable.model.ls.LSFile)7 FileNotFoundException (java.io.FileNotFoundException)6 ZipEntry (java.util.zip.ZipEntry)6 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)6 ZipInputStream (java.util.zip.ZipInputStream)5 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)5 Properties (java.util.Properties)4 TrainType (net.parostroj.timetable.model.TrainType)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)3 Route (net.parostroj.timetable.model.Route)3 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 URL (java.net.URL)2 EngineClass (net.parostroj.timetable.model.EngineClass)2 DiagramChangeSet (net.parostroj.timetable.model.changes.DiagramChangeSet)2