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