private final static String ExportTag = "Export";
private final static String FrameBoundsTag = "Bounds";
private final static String FrameStateTag = "State";
private static void savePrefs() {
Preferences prefs = getPreferences();
ComboFrame active = getActiveFrame();
if (active != null) {
Rectangle bounds = active.getUnmaximizedBounds();
if (bounds != null) {
prefs.putInt(FrameBoundsTag + "X", bounds.x);
prefs.putInt(FrameBoundsTag + "Y", bounds.y);
prefs.putInt(FrameBoundsTag + "W", bounds.width);
prefs.putInt(FrameBoundsTag + "H", bounds.height);
}
int state = active.getExtendedState();
prefs.putInt(FrameStateTag, state);
}
int n;
n = 0;
String key;
for (File file : RecentFiles) {
key = RecentFileTag + n;
String value = file.getAbsolutePath();
prefs.put(key, value);
n++;
}
// Clear out old recent-docs entries:
key = RecentFileTag + n++;
while (prefs.get(key, null) != null) {
prefs.remove(key);
key = RecentFileTag + n++;
}
n = 0;
for (File file : RecentFolders) {
key = RecentFolderTag + n;
String value = file.getAbsolutePath();
prefs.put(key, value);
n++;
}
// Clear out old recent-directories entries:
key = RecentFolderTag + n++;
while (prefs.get(key, null) != null) {
prefs.remove(key);
key = RecentFolderTag + n++;
}
// needed: application events
// (document open, document close, document change)
// The "windows" menu is relying on static references for updates,
// and while the set of current documents should be persisted in prefs,
// a prefs change does not equal a document change, e.g. a new document
// that has never been saved (image import).
n = 0;
for (ComboFrame frame : Current) {
Document doc = frame.getDocument();
if (doc == null) {
continue;
}
File file = doc.getFile();
key = CurrentTag + n;
if (file != null) {
String value = file.getAbsolutePath();
prefs.put(key, value);
n++;
}
}
// Clear out old current-docs entries:
key = CurrentTag + n++;
while (prefs.get(key, null) != null) {
prefs.remove(key);
key = CurrentTag + n++;
}
if (LastOpenPath != null) {
String path = LastOpenPath.getAbsolutePath();
prefs.put(OpenTag, path);
}
if (LastSaveOptions != null) {
// We're remembering the whole SaveOptions object, but
// SaveOptions.getDefaultSaveOptions() is the authoritative
// reposity for sticky options. The LastSaveOptions is only
// used to remember the recent folder.
XmlDocument doc = new XmlDocument(SaveTag);
LastSaveOptions.save(doc.getRoot());
saveXmlPrefs(SaveTag, doc);
}
if (LastPrintLayout != null) {
XmlDocument doc = new XmlDocument(PrintTag);
LastPrintLayout.save(doc.getRoot());
saveXmlPrefs(PrintTag, doc);
}
if (LastExportOptions != null) {
XmlDocument doc = new XmlDocument(ExportTag);
LastExportOptions.write(doc.getRoot());
saveXmlPrefs(ExportTag, doc);
}
try {
prefs.sync();
}
catch (BackingStoreException e) {
showError(LOCALE.get("PrefsWriteError"), e, null);
}
}