From 4cf77bcdc4f51e277351f5b97c5126bf91596d32 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 30 Jan 2024 20:57:22 +0100 Subject: [PATCH] Display error when SVG export failed --- core/resources/l10n/messages.properties | 2 ++ .../gui/configdialog/FinSetConfig.java | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 163318edd..bbdc236a4 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -968,6 +968,8 @@ FinSetConfig.but.Splitfins = Split fins FinSetConfig.but.Splitfins.ttip = Split the fin set into separate fins. FinSetConfig.lbl.exportSVG = Export to SVG FinSetConfig.lbl.exportSVG.ttip = Export the fin profile to an SVG file. +FinSetConfig.errorSVG.title = SVG Export Error +FinSetConfig.errorSVG.msg = An error occurred while exporting the SVG file: %s. FinSetConfig.but.AutoCalc = Calculate automatically FinSetConfig.but.AutoCalc.ttip = Calculates the height and length of the fin tabs, based on
inner tube and centering ring components of the fin's parent component. FinSetConfig.lbl.Through-the-wall = Through-the-wall fin tabs: diff --git a/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java index 66f288d21..16ed11e58 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/FinSetConfig.java @@ -14,9 +14,12 @@ import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SwingUtilities; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.document.OpenRocketDocument; @@ -155,12 +158,18 @@ public abstract class FinSetConfig extends RocketComponentConfig { return; } + ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory()); SVGOptionPanel svgOptions = (SVGOptionPanel) chooser.getAccessory(); prefs.setSVGStrokeColor(svgOptions.getStrokeColor()); prefs.setSVGStrokeWidth(svgOptions.getStrokeWidth()); - FinSetConfig.writeSVGFile((FinSet) component, selectedFile, svgOptions); - ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory()); + try { + FinSetConfig.writeSVGFile((FinSet) component, selectedFile, svgOptions); + } catch (Exception svgErr) { + JOptionPane.showMessageDialog(FinSetConfig.this, + String.format(trans.get("FinSetConfig.errorSVG.msg"), svgErr.getMessage()), + trans.get("FinSetConfig.errorSVG.title"), JOptionPane.ERROR_MESSAGE); + } } } }); @@ -620,16 +629,19 @@ public abstract class FinSetConfig extends RocketComponentConfig { return filletPanel; } - private static boolean writeSVGFile(FinSet finSet, File file, SVGOptionPanel svgOptions) { + /** + * Writes the FinSet object to an SVG file. + * + * @param finSet the FinSet object to write to the SVG file + * @param file the File object representing the SVG file to be written + * @param svgOptions the SVGOptionPanel object containing the options for writing the SVG file + * @throws Exception if there is an error writing the SVG file + */ + private static void writeSVGFile(FinSet finSet, File file, SVGOptionPanel svgOptions) throws ParserConfigurationException, TransformerException { Coordinate[] points = finSet.getFinPointsWithRoot(); - try { - SVGBuilder builder = new SVGBuilder(); - builder.addPath(points, null, svgOptions.getStrokeColor(), svgOptions.getStrokeWidth()); - builder.writeToFile(file); - return true; - } catch (Exception e) { - log.error("Error writing SVG file", e); - return false; - } + + SVGBuilder builder = new SVGBuilder(); + builder.addPath(points, null, svgOptions.getStrokeColor(), svgOptions.getStrokeWidth()); + builder.writeToFile(file); } }