Add option to ignore window information exporting
This commit is contained in:
parent
e7824c5553
commit
42714e73e7
@ -384,6 +384,8 @@ PreferencesImporter.chooser.title = Import a Preferences File
|
|||||||
PreferencesOptionPanel.title = Export settings
|
PreferencesOptionPanel.title = Export settings
|
||||||
PreferencesOptionPanel.checkbox.userDirectories = Export user directories
|
PreferencesOptionPanel.checkbox.userDirectories = Export user directories
|
||||||
PreferencesOptionPanel.checkbox.userDirectories.ttip = If checked, user directories (possible sensitive information) will be exported.
|
PreferencesOptionPanel.checkbox.userDirectories.ttip = If checked, user directories (possible sensitive information) will be exported.
|
||||||
|
PreferencesOptionPanel.checkbox.windowInfo = Export window information (position, size\u2026)
|
||||||
|
PreferencesOptionPanel.checkbox.windowInfo.ttip = If checked, window information (position, size\u2026) will be exported.
|
||||||
|
|
||||||
! Welcome dialog
|
! Welcome dialog
|
||||||
welcome.dlg.title = Welcome to OpenRocket
|
welcome.dlg.title = Welcome to OpenRocket
|
||||||
|
@ -82,6 +82,7 @@ public abstract class Preferences implements ChangeSource {
|
|||||||
private static final String SHOW_MARKERS = "ShowMarkers";
|
private static final String SHOW_MARKERS = "ShowMarkers";
|
||||||
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "ShowRocksimFormatWarning";
|
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "ShowRocksimFormatWarning";
|
||||||
private static final String EXPORT_USER_DIRECTORIES = "ExportUserDirectories";
|
private static final String EXPORT_USER_DIRECTORIES = "ExportUserDirectories";
|
||||||
|
private static final String EXPORT_WINDOW_INFORMATION = "ExportWindowInformation";
|
||||||
|
|
||||||
//Preferences related to 3D graphics
|
//Preferences related to 3D graphics
|
||||||
public static final String OPENGL_ENABLED = "OpenGLIsEnabled";
|
public static final String OPENGL_ENABLED = "OpenGLIsEnabled";
|
||||||
@ -242,6 +243,14 @@ public abstract class Preferences implements ChangeSource {
|
|||||||
this.putBoolean(EXPORT_USER_DIRECTORIES, check);
|
this.putBoolean(EXPORT_USER_DIRECTORIES, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean getExportWindowInformation() {
|
||||||
|
return this.getBoolean(EXPORT_WINDOW_INFORMATION, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setExportWindowInformation(boolean check) {
|
||||||
|
this.putBoolean(EXPORT_WINDOW_INFORMATION, check);
|
||||||
|
}
|
||||||
|
|
||||||
public final double getDefaultMach() {
|
public final double getDefaultMach() {
|
||||||
return Application.getPreferences().getChoice(Preferences.DEFAULT_MACH_NUMBER, 0.9, 0.3);
|
return Application.getPreferences().getChoice(Preferences.DEFAULT_MACH_NUMBER, 0.9, 0.3);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ public class PreferencesOptionPanel extends JPanel {
|
|||||||
JPanel panel = new JPanel(new MigLayout("fill, ins 4lp"));
|
JPanel panel = new JPanel(new MigLayout("fill, ins 4lp"));
|
||||||
panel.setBorder(BorderFactory.createTitledBorder(trans.get("PreferencesOptionPanel.title")));
|
panel.setBorder(BorderFactory.createTitledBorder(trans.get("PreferencesOptionPanel.title")));
|
||||||
|
|
||||||
|
// Export user directories
|
||||||
JCheckBox exportUserDirectories = new JCheckBox(trans.get("PreferencesOptionPanel.checkbox.userDirectories"));
|
JCheckBox exportUserDirectories = new JCheckBox(trans.get("PreferencesOptionPanel.checkbox.userDirectories"));
|
||||||
exportUserDirectories.setToolTipText(trans.get("PreferencesOptionPanel.checkbox.userDirectories.ttip"));
|
exportUserDirectories.setToolTipText(trans.get("PreferencesOptionPanel.checkbox.userDirectories.ttip"));
|
||||||
exportUserDirectories.setSelected(prefs.getExportUserDirectories());
|
exportUserDirectories.setSelected(prefs.getExportUserDirectories());
|
||||||
@ -33,7 +34,20 @@ public class PreferencesOptionPanel extends JPanel {
|
|||||||
prefs.setExportUserDirectories(e.getStateChange() == ItemEvent.SELECTED);
|
prefs.setExportUserDirectories(e.getStateChange() == ItemEvent.SELECTED);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(exportUserDirectories, "wrap 10lp");
|
panel.add(exportUserDirectories, "wrap");
|
||||||
|
|
||||||
|
// Export window information (position, size...)
|
||||||
|
JCheckBox exportWindowInfo = new JCheckBox(trans.get("PreferencesOptionPanel.checkbox.windowInfo"));
|
||||||
|
exportWindowInfo.setToolTipText(trans.get("PreferencesOptionPanel.checkbox.windowInfo.ttip"));
|
||||||
|
exportWindowInfo.setSelected(prefs.getExportWindowInformation());
|
||||||
|
exportWindowInfo.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
prefs.setExportWindowInformation(e.getStateChange() == ItemEvent.SELECTED);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(exportWindowInfo, "wrap 10lp");
|
||||||
|
|
||||||
|
|
||||||
this.add(panel, "growx, north");
|
this.add(panel, "growx, north");
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,9 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
import java.util.prefs.BackingStoreException;
|
import java.util.prefs.BackingStoreException;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
@ -38,17 +41,20 @@ public abstract class PreferencesExporter {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(PreferencesExporter.class);
|
private static final Logger log = LoggerFactory.getLogger(PreferencesExporter.class);
|
||||||
private static final net.sf.openrocket.startup.Preferences prefs = Application.getPreferences();
|
private static final net.sf.openrocket.startup.Preferences prefs = Application.getPreferences();
|
||||||
|
|
||||||
private static final String[] userDirectoriesKeysToIgnore; // Preference keys to ignore when exporting user directories (= keys that export user directories)
|
private static final List<String> keysToIgnore = new ArrayList<>(); // Preference keys to ignore when exporting user directories (= keys that export user directories)
|
||||||
private static final String[] prefixKeysToIgnore; // Preference keys to ignore when exporting user directories (= keys that start with these prefixes)
|
private static final List<String> prefixKeysToIgnore = new ArrayList<>(); // Preference keys to ignore when exporting user directories (= keys that start with these prefixes), e.g.
|
||||||
|
private static final List<String> nodesToIgnore = new ArrayList<>(); // Preferences nodes that should not be exported
|
||||||
|
|
||||||
static {
|
static {
|
||||||
userDirectoriesKeysToIgnore = new String[] {
|
if (!prefs.getExportUserDirectories()) {
|
||||||
net.sf.openrocket.startup.Preferences.USER_THRUST_CURVES_KEY,
|
keysToIgnore.add(net.sf.openrocket.startup.Preferences.USER_THRUST_CURVES_KEY);
|
||||||
net.sf.openrocket.startup.Preferences.DEFAULT_DIRECTORY
|
keysToIgnore.add(net.sf.openrocket.startup.Preferences.DEFAULT_DIRECTORY);
|
||||||
};
|
prefixKeysToIgnore.add(MRUDesignFile.MRU_FILE_LIST_PROPERTY);
|
||||||
prefixKeysToIgnore = new String[] {
|
}
|
||||||
MRUDesignFile.MRU_FILE_LIST_PROPERTY
|
|
||||||
};
|
if (!prefs.getExportWindowInformation()) {
|
||||||
|
nodesToIgnore.add(SwingPreferences.NODE_WINDOWS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +70,7 @@ public abstract class PreferencesExporter {
|
|||||||
// The macOS file chooser has an issue where it does not update its size when the accessory is added.
|
// The macOS file chooser has an issue where it does not update its size when the accessory is added.
|
||||||
if (SystemInfo.getPlatform() == SystemInfo.Platform.MAC_OS) {
|
if (SystemInfo.getPlatform() == SystemInfo.Platform.MAC_OS) {
|
||||||
Dimension currentSize = chooser.getPreferredSize();
|
Dimension currentSize = chooser.getPreferredSize();
|
||||||
Dimension newSize = new Dimension((int) (1.25 * currentSize.width), (int) (1.2 * currentSize.height));
|
Dimension newSize = new Dimension((int) (1.35 * currentSize.width), (int) (1.2 * currentSize.height));
|
||||||
chooser.setPreferredSize(newSize);
|
chooser.setPreferredSize(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +95,7 @@ public abstract class PreferencesExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(newFile)) {
|
try (FileOutputStream fos = new FileOutputStream(newFile)) {
|
||||||
if (prefs.getExportUserDirectories()) {
|
if (keysToIgnore.isEmpty() && nodesToIgnore.isEmpty() && prefixKeysToIgnore.isEmpty()) {
|
||||||
// Export all preferences
|
// Export all preferences
|
||||||
preferences.exportSubtree(fos);
|
preferences.exportSubtree(fos);
|
||||||
} else {
|
} else {
|
||||||
@ -115,7 +121,7 @@ public abstract class PreferencesExporter {
|
|||||||
Preferences tempPrefs = root.node(nodeName);
|
Preferences tempPrefs = root.node(nodeName);
|
||||||
|
|
||||||
// Fill in all parameters to the temporary preferences, except for user directories
|
// Fill in all parameters to the temporary preferences, except for user directories
|
||||||
copyFilteredPreferences(preferences, tempPrefs, userDirectoriesKeysToIgnore, prefixKeysToIgnore);
|
copyFilteredPreferences(preferences, tempPrefs, nodesToIgnore, keysToIgnore, prefixKeysToIgnore);
|
||||||
|
|
||||||
// Export the filtered preferences
|
// Export the filtered preferences
|
||||||
try {
|
try {
|
||||||
@ -163,32 +169,23 @@ public abstract class PreferencesExporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyFilteredPreferences(Preferences src, Preferences dest, String[] keysToIgnore, String[] prefixKeysToIgnore) throws BackingStoreException {
|
private static void copyFilteredPreferences(Preferences src, Preferences dest,
|
||||||
|
List<String> nodesToIgnore, List<String> keysToIgnore, List<String> prefixKeysToIgnore) throws BackingStoreException {
|
||||||
for (String key : src.keys()) {
|
for (String key : src.keys()) {
|
||||||
boolean ignoreKey = false;
|
if (keysToIgnore.contains(key)
|
||||||
for (String keyToIgnore : keysToIgnore) {
|
|| prefixKeysToIgnore.stream().anyMatch(key::startsWith)) {
|
||||||
if (key.equals(keyToIgnore)) {
|
continue;
|
||||||
ignoreKey = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!ignoreKey) {
|
|
||||||
for (String prefixKeyToIgnore : prefixKeysToIgnore) {
|
|
||||||
if (key.startsWith(prefixKeyToIgnore)) {
|
|
||||||
ignoreKey = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ignoreKey) {
|
|
||||||
dest.put(key, src.get(key, null));
|
dest.put(key, src.get(key, null));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (String childNodeName : src.childrenNames()) {
|
for (String childNodeName : src.childrenNames()) {
|
||||||
|
if (nodesToIgnore.contains(childNodeName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Preferences srcChild = src.node(childNodeName);
|
Preferences srcChild = src.node(childNodeName);
|
||||||
Preferences destChild = dest.node(childNodeName);
|
Preferences destChild = dest.node(childNodeName);
|
||||||
copyFilteredPreferences(srcChild, destChild, keysToIgnore, prefixKeysToIgnore);
|
copyFilteredPreferences(srcChild, destChild, nodesToIgnore, keysToIgnore, prefixKeysToIgnore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
private static final String SPLIT_CHARACTER = "|";
|
private static final String SPLIT_CHARACTER = "|";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String NODE_WINDOWS = "windows";
|
||||||
|
|
||||||
private static final List<Locale> SUPPORTED_LOCALES;
|
private static final List<Locale> SUPPORTED_LOCALES;
|
||||||
static {
|
static {
|
||||||
List<Locale> list = new ArrayList<Locale>();
|
List<Locale> list = new ArrayList<Locale>();
|
||||||
@ -378,7 +380,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
|
|
||||||
public Point getWindowPosition(Class<?> c) {
|
public Point getWindowPosition(Class<?> c) {
|
||||||
int x, y;
|
int x, y;
|
||||||
String pref = PREFNODE.node("windows").get("position." + c.getCanonicalName(), null);
|
String pref = PREFNODE.node(NODE_WINDOWS).get("position." + c.getCanonicalName(), null);
|
||||||
|
|
||||||
if (pref == null)
|
if (pref == null)
|
||||||
return null;
|
return null;
|
||||||
@ -396,7 +398,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setWindowPosition(Class<?> c, Point p) {
|
public void setWindowPosition(Class<?> c, Point p) {
|
||||||
PREFNODE.node("windows").put("position." + c.getCanonicalName(), "" + p.x + "," + p.y);
|
PREFNODE.node(NODE_WINDOWS).put("position." + c.getCanonicalName(), "" + p.x + "," + p.y);
|
||||||
storeVersion();
|
storeVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +407,7 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
|
|
||||||
public Dimension getWindowSize(Class<?> c) {
|
public Dimension getWindowSize(Class<?> c) {
|
||||||
int x, y;
|
int x, y;
|
||||||
String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
|
String pref = PREFNODE.node(NODE_WINDOWS).get("size." + c.getCanonicalName(), null);
|
||||||
|
|
||||||
if (pref == null)
|
if (pref == null)
|
||||||
return null;
|
return null;
|
||||||
@ -424,17 +426,17 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
|
|
||||||
|
|
||||||
public boolean isWindowMaximized(Class<?> c) {
|
public boolean isWindowMaximized(Class<?> c) {
|
||||||
String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
|
String pref = PREFNODE.node(NODE_WINDOWS).get("size." + c.getCanonicalName(), null);
|
||||||
return "max".equals(pref);
|
return "max".equals(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWindowSize(Class<?> c, Dimension d) {
|
public void setWindowSize(Class<?> c, Dimension d) {
|
||||||
PREFNODE.node("windows").put("size." + c.getCanonicalName(), "" + d.width + "," + d.height);
|
PREFNODE.node(NODE_WINDOWS).put("size." + c.getCanonicalName(), "" + d.width + "," + d.height);
|
||||||
storeVersion();
|
storeVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWindowMaximized(Class<?> c) {
|
public void setWindowMaximized(Class<?> c) {
|
||||||
PREFNODE.node("windows").put("size." + c.getCanonicalName(), "max");
|
PREFNODE.node(NODE_WINDOWS).put("size." + c.getCanonicalName(), "max");
|
||||||
storeVersion();
|
storeVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user