From 7db0c17c56814b1d40c8d7e030ea53f47f54a6db Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Tue, 26 Mar 2013 22:24:21 -0500 Subject: [PATCH] Added some localized messages when exporting and editing decals. --- core/resources/l10n/messages.properties | 5 +- .../sf/openrocket/gui/ExportDecalDialog.java | 16 ++++--- .../gui/configdialog/AppearancePanel.java | 9 ++-- .../openrocket/gui/util/EditDecalHelper.java | 46 ++++++++++++++++--- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 2980b7436..c27143c6e 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1782,6 +1782,7 @@ DecalModel.lbl.choose = From file... ! Export Decal Dialog ExportDecalDialog.title = Export Decal ExportDecalDialog.decalList.lbl = Decal +ExportDecalDialog.exception = Unable to write decal to file ''{0}'' ! Component Preset Chooser Dialog ComponentPresetChooserDialog.title = Choose component preset @@ -1829,7 +1830,9 @@ EditDecalDialog.lbl.cmdline = Command Line EditDecalDialog.lbl.cmdline.help = The filename will be subsituted for ''%%'' EditDecalDialog.lbl.always = Always use these settings EditDecalDialog.btn.chooser = Select Graphics Editor Program - +EditDecalHelper.createFileException = Cannot create temporary file {0} +EditDecalHelper.launchSystemEditorException = Cannot launch system graphics editor +EditDecalHelper.launchCustomEditorException = Cannot launch graphics editor with command ''{0}'' MotorConfigurationPanel.lbl.motorMounts = Motor mounts: MotorConfigurationPanel.lbl.motorConfiguration = Motor configurations: diff --git a/core/src/net/sf/openrocket/gui/ExportDecalDialog.java b/core/src/net/sf/openrocket/gui/ExportDecalDialog.java index 931b9b57a..2f8714df2 100644 --- a/core/src/net/sf/openrocket/gui/ExportDecalDialog.java +++ b/core/src/net/sf/openrocket/gui/ExportDecalDialog.java @@ -5,21 +5,23 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; +import java.text.MessageFormat; import java.util.Collection; 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 net.miginfocom.swing.MigLayout; import net.sf.openrocket.appearance.DecalImage; import net.sf.openrocket.document.OpenRocketDocument; +import net.sf.openrocket.gui.util.FileHelper; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; -import net.sf.openrocket.util.BugException; public class ExportDecalDialog extends JDialog { @@ -60,12 +62,14 @@ public class ExportDecalDialog extends JDialog { } else if (command.equals(JFileChooser.APPROVE_SELECTION)) { // Here we copy the bits out. - // FIXME - confirm overwrite? DecalImage selectedDecal = (DecalImage) decalComboBox.getSelectedItem(); File selectedFile = chooser.getSelectedFile(); - export(selectedDecal, selectedFile); - ExportDecalDialog.this.dispose(); + if (FileHelper.confirmWrite(selectedFile, ExportDecalDialog.this)) { + export(selectedDecal, selectedFile); + // If the user doesn't confirm over write, then leave this dialog open. + ExportDecalDialog.this.dispose(); + } } } }); @@ -80,8 +84,8 @@ public class ExportDecalDialog extends JDialog { try { decal.exportImage(selectedFile, false); } catch (IOException iex) { - // FIXME - probably want a simple user dialog here since FileIO is not really a bug. - throw new BugException(iex); + String message = MessageFormat.format(trans.get("ExportDecalDialog.exception"), selectedFile.getAbsoluteFile()); + JOptionPane.showMessageDialog(this, message, "", JOptionPane.ERROR_MESSAGE); } } } diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index b88b3b661..c099e9e0c 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -3,7 +3,6 @@ package net.sf.openrocket.gui.configdialog; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.IOException; import java.lang.reflect.Method; import java.util.EventObject; @@ -13,6 +12,7 @@ import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JSlider; @@ -37,6 +37,7 @@ import net.sf.openrocket.gui.components.StyledLabel.Style; import net.sf.openrocket.gui.components.UnitSelector; import net.sf.openrocket.gui.util.ColorConversion; import net.sf.openrocket.gui.util.EditDecalHelper; +import net.sf.openrocket.gui.util.EditDecalHelper.EditDecalHelperException; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -44,7 +45,6 @@ import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.GeneralUnit; import net.sf.openrocket.unit.Unit; import net.sf.openrocket.unit.UnitGroup; -import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.LineStyle; import net.sf.openrocket.util.StateChangeListener; @@ -253,8 +253,8 @@ public class AppearancePanel extends JPanel { public void actionPerformed(ActionEvent e) { try { EditDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage()); - } catch (IOException ex) { - throw new BugException(ex); + } catch (EditDecalHelperException ex) { + JOptionPane.showMessageDialog(AppearancePanel.this, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE); } } @@ -344,5 +344,4 @@ public class AppearancePanel extends JPanel { } - } diff --git a/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java b/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java index d58a28b33..1ad3c7338 100644 --- a/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java +++ b/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java @@ -4,16 +4,28 @@ import java.awt.Desktop; import java.awt.Window; import java.io.File; import java.io.IOException; +import java.text.MessageFormat; import net.sf.openrocket.appearance.AppearanceBuilder; import net.sf.openrocket.appearance.DecalImage; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.dialogs.EditDecalDialog; +import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; public class EditDecalHelper { + public static class EditDecalHelperException extends Exception { + + public EditDecalHelperException(String message, Throwable cause) { + super(message, cause); + } + + } + + private static final Translator trans = Application.getTranslator(); + // FIXME - need to have a specific set of localizable exceptions come out of this instead of generic IOException; // perhaps - unable to create file, // unable to open system editor @@ -21,7 +33,7 @@ public class EditDecalHelper { private static final SwingPreferences prefs = ((SwingPreferences) Application.getPreferences()); - public static void editDecal(Window parent, OpenRocketDocument doc, RocketComponent component, DecalImage decal) throws IOException { + public static void editDecal(Window parent, OpenRocketDocument doc, RocketComponent component, DecalImage decal) throws EditDecalHelperException { boolean sysPrefSet = prefs.isDecalEditorPreferenceSet(); int usageCount = doc.countDecalUsage(decal); @@ -76,7 +88,7 @@ public class EditDecalHelper { return newImage; } - private static void launchEditor(boolean useSystemEditor, String commandTemplate, DecalImage decal) throws IOException { + private static void launchEditor(boolean useSystemEditor, String commandTemplate, DecalImage decal) throws EditDecalHelperException { String decalId = decal.getName(); // Create Temp File. @@ -85,13 +97,29 @@ public class EditDecalHelper { if (dotlocation > 0 && dotlocation < decalId.length()) { extension = decalId.substring(dotlocation); } - File tmpFile = File.createTempFile("OR_graphics", extension); + File tmpFile = null; - decal.exportImage(tmpFile, true); + try { + tmpFile = File.createTempFile("OR_graphics", extension); + } catch (IOException ioex) { + String message = MessageFormat.format(trans.get("EditDecalHelper.createFileException"), tmpFile.getAbsoluteFile()); + throw new EditDecalHelperException(message, ioex); + } + + try { + decal.exportImage(tmpFile, true); + } catch (IOException ioex) { + String message = MessageFormat.format(trans.get("EditDecalHelper.createFileException"), tmpFile.getAbsoluteFile()); + throw new EditDecalHelperException(message, ioex); + } if (useSystemEditor) { - Desktop.getDesktop().edit(tmpFile); + try { + Desktop.getDesktop().edit(tmpFile); + } catch (IOException ioex) { + throw new EditDecalHelperException(trans.get("EditDecalHelper.launchSystemEditorException"), ioex); + } } else { String filename = tmpFile.getAbsolutePath(); @@ -103,9 +131,13 @@ public class EditDecalHelper { command = commandTemplate + " " + filename; } - Runtime.getRuntime().exec(command); + try { + Runtime.getRuntime().exec(command); + } catch (IOException ioex) { + String message = MessageFormat.format(trans.get("EditDecalHelper.launchCustomEditorException"), command); + throw new EditDecalHelperException(message, ioex); + } } } - }