diff --git a/core/src/net/sf/openrocket/document/DecalRegistry.java b/core/src/net/sf/openrocket/document/DecalRegistry.java index 931a4d7e7..5cc2a9418 100644 --- a/core/src/net/sf/openrocket/document/DecalRegistry.java +++ b/core/src/net/sf/openrocket/document/DecalRegistry.java @@ -20,10 +20,6 @@ import java.util.regex.Pattern; import net.sf.openrocket.appearance.DecalImage; import net.sf.openrocket.document.attachments.FileSystemAttachment; -import net.sf.openrocket.gui.watcher.FileWatcher; -import net.sf.openrocket.gui.watcher.WatchEvent; -import net.sf.openrocket.gui.watcher.WatchService; -import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.FileUtils; @@ -52,6 +48,11 @@ public class DecalRegistry { String newName = makeUniqueName(o.getName()); + // Return the old decal if a new one isn't required. + if (newName.equals(o.getName())) { + return original; + } + newDecal.name = newName; registeredDecals.put(newName, newDecal); diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 4b365d206..c7e283a0b 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -234,6 +234,9 @@ public class OpenRocketDocument implements ComponentChangeListener { } public DecalImage makeUniqueDecal(DecalImage img) { + if (countDecalUsage(img) <= 1) { + return img; + } return decalRegistry.makeUniqueImage(img); } diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index 94c424dfb..2976ae413 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -24,6 +24,7 @@ import net.miginfocom.swing.MigLayout; import net.sf.openrocket.appearance.Appearance; import net.sf.openrocket.appearance.AppearanceBuilder; import net.sf.openrocket.appearance.Decal.EdgeMode; +import net.sf.openrocket.appearance.DecalImage; import net.sf.openrocket.appearance.defaults.DefaultAppearance; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.SpinnerEditor; @@ -271,7 +272,8 @@ public class AppearancePanel extends JPanel { @Override public void actionPerformed(ActionEvent e) { try { - editDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage()); + DecalImage newImage = editDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, c, ab.getImage()); + ab.setImage(newImage); } catch (EditDecalHelperException ex) { JOptionPane.showMessageDialog(AppearancePanel.this, ex.getMessage(), "", JOptionPane.ERROR_MESSAGE); } diff --git a/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java b/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java index 0d6f2d074..9483e55dd 100644 --- a/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java +++ b/core/src/net/sf/openrocket/gui/util/EditDecalHelper.java @@ -56,8 +56,19 @@ public class EditDecalHelper { } - public void editDecal(Window parent, OpenRocketDocument doc, RocketComponent component, DecalImage decal) throws EditDecalHelperException { - + /** + * Returns the decal which is edited. The decal edited might be different from the one passed in + * if only a single copy of a decal should be edited. + * + * @param parent + * @param doc + * @param component + * @param decal + * @return + * @throws EditDecalHelperException + */ + public DecalImage editDecal(Window parent, OpenRocketDocument doc, RocketComponent component, DecalImage decal) throws EditDecalHelperException { + boolean sysPrefSet = prefs.isDecalEditorPreferenceSet(); int usageCount = doc.countDecalUsage(decal); @@ -65,14 +76,14 @@ public class EditDecalHelper { if (sysPrefSet && usageCount == 1) { launchEditor(prefs.isDecalEditorPreferenceSystem(), prefs.getDecalEditorCommandLine(), decal); - return; + return decal; } EditDecalDialog dialog = new EditDecalDialog(parent, !sysPrefSet, usageCount); dialog.setVisible(true); if (dialog.isCancel()) { - return; + return decal; } // Do we use the System Preference Editor or from the dialog? @@ -97,6 +108,8 @@ public class EditDecalHelper { launchEditor(useSystemEditor, commandLine, decal); + return decal; + } private static DecalImage makeDecalUnique(OpenRocketDocument doc, RocketComponent component, DecalImage decal) {