WIP
This commit is contained in:
parent
8de28fd35e
commit
3e2aec6e3e
@ -122,6 +122,7 @@ FileHelper.RASAERO_DESIGN_FILTER = RASAero designs (*.CDX1)
|
|||||||
FileHelper.OPEN_ROCKET_COMPONENT_FILTER = OpenRocket presets (*.orc)
|
FileHelper.OPEN_ROCKET_COMPONENT_FILTER = OpenRocket presets (*.orc)
|
||||||
FileHelper.PNG_FILTER = PNG image (*.png)
|
FileHelper.PNG_FILTER = PNG image (*.png)
|
||||||
FileHelper.IMAGES = Image files
|
FileHelper.IMAGES = Image files
|
||||||
|
FileHelper.XML_FILTER = XML files (*.xml)
|
||||||
|
|
||||||
|
|
||||||
! About Dialog
|
! About Dialog
|
||||||
@ -290,8 +291,12 @@ pref.dlg.tab.Simulation = Simulation
|
|||||||
pref.dlg.tab.Launch = Launch
|
pref.dlg.tab.Launch = Launch
|
||||||
pref.dlg.tab.Miscellaneousoptions = Miscellaneous options
|
pref.dlg.tab.Miscellaneousoptions = Miscellaneous options
|
||||||
pref.dlg.lbl.RockSimWarning = Show warning when saving in RockSim format
|
pref.dlg.lbl.RockSimWarning = Show warning when saving in RockSim format
|
||||||
pref.dlg.but.clearCachedPreferences = Reset all preferences
|
pref.dlg.but.resetAllPreferences = Reset all preferences
|
||||||
pref.dlg.but.clearCachedPreferences.ttip = Reset all the preferences, including cached preferences (UI settings, recent files, etc.)
|
pref.dlg.but.resetAllPreferences.ttip = Reset all the preferences, including cached preferences (UI settings, recent files, etc.)
|
||||||
|
pref.dlg.but.exportPreferences = Export preferences
|
||||||
|
pref.dlg.but.exportPreferences.ttip = Export all your OpenRocket preferences to an external file
|
||||||
|
pref.dlg.but.importPreferences = Import preferences
|
||||||
|
pref.dlg.but.importPreferences.ttip = Import new OpenRocket preferences from an external file
|
||||||
pref.dlg.clearCachedPreferences.title = Reset preferences?
|
pref.dlg.clearCachedPreferences.title = Reset preferences?
|
||||||
pref.dlg.clearCachedPreferences.message = Are you sure you want to reset all your preferences?
|
pref.dlg.clearCachedPreferences.message = Are you sure you want to reset all your preferences?
|
||||||
|
|
||||||
@ -372,6 +377,10 @@ generalprefs.lbl.language = Interface language
|
|||||||
generalprefs.languages.default = System default
|
generalprefs.languages.default = System default
|
||||||
generalprefs.lbl.languageEffect = The language will change the next time you start OpenRocket.
|
generalprefs.lbl.languageEffect = The language will change the next time you start OpenRocket.
|
||||||
|
|
||||||
|
PreferencesExporter.chooser.title = Export the Preferences File
|
||||||
|
|
||||||
|
PreferencesImporter.chooser.title = Import a Preferences File
|
||||||
|
|
||||||
! Welcome dialog
|
! Welcome dialog
|
||||||
welcome.dlg.title = Welcome to OpenRocket
|
welcome.dlg.title = Welcome to OpenRocket
|
||||||
welcome.dlg.lbl.thankYou = Thank you for downloading OpenRocket
|
welcome.dlg.lbl.thankYou = Thank you for downloading OpenRocket
|
||||||
|
@ -276,8 +276,8 @@ pref.dlg.tab.Simulation = محاكاة
|
|||||||
pref.dlg.tab.Launch = إطلاق
|
pref.dlg.tab.Launch = إطلاق
|
||||||
pref.dlg.tab.Miscellaneousoptions = الخيارات المتنوعة
|
pref.dlg.tab.Miscellaneousoptions = الخيارات المتنوعة
|
||||||
pref.dlg.lbl.RockSimWarning = إظهار تحذير عند الحفظ بتنسيق روكسيم
|
pref.dlg.lbl.RockSimWarning = إظهار تحذير عند الحفظ بتنسيق روكسيم
|
||||||
pref.dlg.but.clearCachedPreferences = إعادة تعيين كل التفضيلات
|
pref.dlg.but.resetAllPreferences = إعادة تعيين كل التفضيلات
|
||||||
pref.dlg.but.clearCachedPreferences.ttip = (إعدادات واجهة المستخدم والملفات الحديثة وما إلى ذلك)إعادة تعيين جميع التفضيلات ، بما في ذلك التفضيلات المخزنة مؤقتًا
|
pref.dlg.but.resetAllPreferences.ttip = (إعدادات واجهة المستخدم والملفات الحديثة وما إلى ذلك)إعادة تعيين جميع التفضيلات ، بما في ذلك التفضيلات المخزنة مؤقتًا
|
||||||
pref.dlg.clearCachedPreferences.title = هل تريد إعادة تعيين التفضيلات؟
|
pref.dlg.clearCachedPreferences.title = هل تريد إعادة تعيين التفضيلات؟
|
||||||
pref.dlg.clearCachedPreferences.message = هل أنت متأكد أنك تريد إعادة تعيين كل تفضيلاتك؟
|
pref.dlg.clearCachedPreferences.message = هل أنت متأكد أنك تريد إعادة تعيين كل تفضيلاتك؟
|
||||||
|
|
||||||
|
@ -277,8 +277,8 @@ pref.dlg.tab.Simulation = Simulatie
|
|||||||
pref.dlg.tab.Launch = Lanceer
|
pref.dlg.tab.Launch = Lanceer
|
||||||
pref.dlg.tab.Miscellaneousoptions = Diverse opties
|
pref.dlg.tab.Miscellaneousoptions = Diverse opties
|
||||||
pref.dlg.lbl.RockSimWarning = Toon waarschuwingen bij opslaan in RockSim-formaat
|
pref.dlg.lbl.RockSimWarning = Toon waarschuwingen bij opslaan in RockSim-formaat
|
||||||
pref.dlg.but.clearCachedPreferences = Alle voorkeuren opnieuw instellen
|
pref.dlg.but.resetAllPreferences = Alle voorkeuren opnieuw instellen
|
||||||
pref.dlg.but.clearCachedPreferences.ttip = Alle voorkeuren opnieuw instellen, inclusief voorkeuren in de cache (UI-instellingen, recente bestanden, enz.)
|
pref.dlg.but.resetAllPreferences.ttip = Alle voorkeuren opnieuw instellen, inclusief voorkeuren in de cache (UI-instellingen, recente bestanden, enz.)
|
||||||
pref.dlg.clearCachedPreferences.title = Voorkeuren opnieuw instellen?
|
pref.dlg.clearCachedPreferences.title = Voorkeuren opnieuw instellen?
|
||||||
pref.dlg.clearCachedPreferences.message = Bent u zeker dat u al uw voorkeuren opnieuw wilt instellen?
|
pref.dlg.clearCachedPreferences.message = Bent u zeker dat u al uw voorkeuren opnieuw wilt instellen?
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JProgressBar;
|
import javax.swing.JProgressBar;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
@ -35,6 +36,8 @@ import net.sf.openrocket.gui.dialogs.UpdateInfoDialog;
|
|||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.gui.util.SimpleFileFilter;
|
import net.sf.openrocket.gui.util.SimpleFileFilter;
|
||||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
|
import net.sf.openrocket.gui.util.PreferencesExporter;
|
||||||
|
import net.sf.openrocket.gui.util.PreferencesImporter;
|
||||||
import net.sf.openrocket.l10n.L10N;
|
import net.sf.openrocket.l10n.L10N;
|
||||||
import net.sf.openrocket.logging.Markers;
|
import net.sf.openrocket.logging.Markers;
|
||||||
import net.sf.openrocket.startup.Preferences;
|
import net.sf.openrocket.startup.Preferences;
|
||||||
@ -46,7 +49,7 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class GeneralPreferencesPanel extends PreferencesPanel {
|
public class GeneralPreferencesPanel extends PreferencesPanel {
|
||||||
|
|
||||||
public GeneralPreferencesPanel(JDialog parent) {
|
public GeneralPreferencesPanel(PreferencesDialog parent) {
|
||||||
super(parent, new MigLayout("fillx, ins 30lp n n n"));
|
super(parent, new MigLayout("fillx, ins 30lp n n n"));
|
||||||
|
|
||||||
|
|
||||||
@ -240,10 +243,41 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
|
|||||||
});
|
});
|
||||||
this.add(rocksimWarningDialogBox,"spanx, wrap");
|
this.add(rocksimWarningDialogBox,"spanx, wrap");
|
||||||
|
|
||||||
//// Clear cached preferences
|
// Preference buttons
|
||||||
final JButton clearCachedPreferences = new SelectColorButton(trans.get("pref.dlg.but.clearCachedPreferences"));
|
JPanel buttonPanel = new JPanel(new MigLayout("fillx, ins 0"));
|
||||||
clearCachedPreferences.setToolTipText(trans.get("pref.dlg.but.clearCachedPreferences.ttip"));
|
|
||||||
clearCachedPreferences.addActionListener(new ActionListener() {
|
//// Export preferences
|
||||||
|
final JButton exportPreferences = new SelectColorButton(trans.get("pref.dlg.but.exportPreferences"));
|
||||||
|
exportPreferences.setToolTipText(trans.get("pref.dlg.but.exportPreferences.ttip"));
|
||||||
|
exportPreferences.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PreferencesExporter.exportPreferences(parent, preferences.getPreferences());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonPanel.add(exportPreferences);
|
||||||
|
|
||||||
|
//// Import preferences
|
||||||
|
final JButton importPreferences = new SelectColorButton(trans.get("pref.dlg.but.importPreferences"));
|
||||||
|
importPreferences.setToolTipText(trans.get("pref.dlg.but.importPreferences.ttip"));
|
||||||
|
importPreferences.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PreferencesImporter.importPreferences(parent);
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PreferencesDialog.showPreferences(parent.getParentFrame()); // Refresh the preferences dialog
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonPanel.add(importPreferences);
|
||||||
|
|
||||||
|
//// Reset all preferences
|
||||||
|
final JButton resetAllPreferences = new SelectColorButton(trans.get("pref.dlg.but.resetAllPreferences"));
|
||||||
|
resetAllPreferences.setToolTipText(trans.get("pref.dlg.but.resetAllPreferences.ttip"));
|
||||||
|
resetAllPreferences.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int resultYesNo = JOptionPane.showConfirmDialog(parent, trans.get("pref.dlg.clearCachedPreferences.message"),
|
int resultYesNo = JOptionPane.showConfirmDialog(parent, trans.get("pref.dlg.clearCachedPreferences.message"),
|
||||||
@ -253,8 +287,9 @@ public class GeneralPreferencesPanel extends PreferencesPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(clearCachedPreferences, "spanx, pushy, bottom, wrap");
|
buttonPanel.add(resetAllPreferences, "pushx, right, wrap");
|
||||||
|
|
||||||
|
this.add(buttonPanel, "spanx, growx, pushy, bottom, wrap");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,11 +33,15 @@ public class PreferencesDialog extends JDialog {
|
|||||||
private final SwingPreferences preferences = (SwingPreferences) Application
|
private final SwingPreferences preferences = (SwingPreferences) Application
|
||||||
.getPreferences();
|
.getPreferences();
|
||||||
|
|
||||||
|
private BasicFrame parentFrame;
|
||||||
|
|
||||||
private PreferencesDialog(BasicFrame parent) {
|
private PreferencesDialog(BasicFrame parent) {
|
||||||
// // Preferences
|
// // Preferences
|
||||||
super(parent, trans.get("pref.dlg.title.Preferences"),
|
super(parent, trans.get("pref.dlg.title.Preferences"),
|
||||||
Dialog.ModalityType.APPLICATION_MODAL);
|
Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
this.parentFrame = parent;
|
||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill, gap unrel", "[grow]",
|
JPanel panel = new JPanel(new MigLayout("fill, gap unrel", "[grow]",
|
||||||
"[grow][]"));
|
"[grow][]"));
|
||||||
|
|
||||||
@ -104,6 +108,10 @@ public class PreferencesDialog extends JDialog {
|
|||||||
GUIUtil.setDisposableDialogOptions(this, close);
|
GUIUtil.setDisposableDialogOptions(this, close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BasicFrame getParentFrame() {
|
||||||
|
return parentFrame;
|
||||||
|
}
|
||||||
|
|
||||||
// ////// Singleton implementation ////////
|
// ////// Singleton implementation ////////
|
||||||
|
|
||||||
private static PreferencesDialog dialog = null;
|
private static PreferencesDialog dialog = null;
|
||||||
|
@ -64,6 +64,10 @@ public final class FileHelper {
|
|||||||
public static final FileFilter PNG_FILTER =
|
public static final FileFilter PNG_FILTER =
|
||||||
new SimpleFileFilter(trans.get("FileHelper.PNG_FILTER"), ".png");
|
new SimpleFileFilter(trans.get("FileHelper.PNG_FILTER"), ".png");
|
||||||
|
|
||||||
|
/** File filter for XML files (*.xml) */
|
||||||
|
public static final FileFilter XML_FILTER =
|
||||||
|
new SimpleFileFilter(trans.get("FileHelper.XML_FILTER"), ".xml");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package net.sf.openrocket.gui.util;
|
||||||
|
|
||||||
|
import net.sf.openrocket.gui.widgets.SaveFileChooser;
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.prefs.BackingStoreException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
public abstract class PreferencesExporter {
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PreferencesExporter.class);
|
||||||
|
|
||||||
|
public static boolean exportPreferences(Window parent, Preferences preferences) {
|
||||||
|
JFileChooser chooser = new SaveFileChooser();
|
||||||
|
chooser.setDialogTitle(trans.get("PreferencesExporter.chooser.title"));
|
||||||
|
chooser.setAcceptAllFileFilterUsed(false);
|
||||||
|
chooser.setFileFilter(FileHelper.XML_FILTER);
|
||||||
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: add storageoptions to choose whether to export user directories or not (default to not)
|
||||||
|
|
||||||
|
|
||||||
|
//// Ensures No Problems When Choosing File
|
||||||
|
if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION) {
|
||||||
|
log.info("Cancelled export of preferences.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
|
||||||
|
|
||||||
|
File file = chooser.getSelectedFile();
|
||||||
|
if (file == null) {
|
||||||
|
log.info("No file selected to export preferences to.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = FileHelper.forceExtension(file, "xml");
|
||||||
|
if (!FileHelper.confirmWrite(file, parent)) {
|
||||||
|
log.info("Cancelled export of preferences.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||||
|
preferences.exportSubtree(fos);
|
||||||
|
log.info("Preferences exported successfully.");
|
||||||
|
} catch (IOException | BackingStoreException e) {
|
||||||
|
log.warn("Error while importing preferences: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.sf.openrocket.gui.util;
|
||||||
|
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.prefs.InvalidPreferencesFormatException;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
public abstract class PreferencesImporter {
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PreferencesImporter.class);
|
||||||
|
|
||||||
|
public static boolean importPreferences(Window parent) {
|
||||||
|
final JFileChooser chooser = new JFileChooser();
|
||||||
|
chooser.setDialogTitle(trans.get("PreferencesImporter.chooser.title"));
|
||||||
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||||
|
chooser.setFileFilter(FileHelper.XML_FILTER);
|
||||||
|
chooser.setAcceptAllFileFilterUsed(false);
|
||||||
|
|
||||||
|
int returnVal = chooser.showOpenDialog(parent);
|
||||||
|
if (returnVal != JFileChooser.APPROVE_OPTION) {
|
||||||
|
log.info("Cancelled import of preferences.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
|
||||||
|
|
||||||
|
File importFile = chooser.getSelectedFile();
|
||||||
|
try (FileInputStream fis = new FileInputStream(importFile)) {
|
||||||
|
|
||||||
|
// TODO: don't import user directories?
|
||||||
|
|
||||||
|
Preferences.importPreferences(fis);
|
||||||
|
log.info("Preferences imported successfully.");
|
||||||
|
} catch (IOException | InvalidPreferencesFormatException e) {
|
||||||
|
log.warn("Error while importing preferences: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -93,6 +93,10 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
|||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
|
public Preferences getPreferences() {
|
||||||
|
return PREFNODE;
|
||||||
|
}
|
||||||
|
|
||||||
public void clearPreferences() {
|
public void clearPreferences() {
|
||||||
try {
|
try {
|
||||||
Preferences root = Preferences.userRoot();
|
Preferences root = Preferences.userRoot();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user