Fix issue where edited decal was lost when the appearance was modified
again.
This commit is contained in:
parent
e6c2181c11
commit
1398fe0794
@ -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);
|
||||
|
@ -234,6 +234,9 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
|
||||
public DecalImage makeUniqueDecal(DecalImage img) {
|
||||
if (countDecalUsage(img) <= 1) {
|
||||
return img;
|
||||
}
|
||||
return decalRegistry.makeUniqueImage(img);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -56,7 +56,18 @@ 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user