use of java.util.prefs.BackingStoreException in project BoofCV by lessthanoptimal.
the class OpenWebcamDialog method savePreferences.
public void savePreferences() {
if (selectedCamera == null)
return;
Preferences prefs = Preferences.userRoot().node(getClass().getSimpleName());
prefs.put("camera", selectedCamera.getName());
prefs.putInt("width", width);
prefs.putInt("height", height);
try {
prefs.flush();
} catch (BackingStoreException ignore) {
}
}
use of java.util.prefs.BackingStoreException in project gephi by gephi.
the class MostRecentFilesImpl method store.
protected void store() {
Preferences prefs = getPreferences();
// clear the backing store
try {
prefs.clear();
} catch (BackingStoreException ex) {
}
for (int i = 0; i < mruFileList.size(); i++) {
String str = mruFileList.get(i);
prefs.put(MRU_FILE_LIST_PROPERTY + i, str);
}
}
use of java.util.prefs.BackingStoreException in project robovm by robovm.
the class OldPreferencesTest method testAddNodeChangeListener.
public void testAddNodeChangeListener() throws BackingStoreException {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
pref.addNodeChangeListener(null);
fail();
} catch (NullPointerException expected) {
}
Preferences child1 = null;
MockNodeChangeListener nl = null;
// To get existed node doesn't create the change event
try {
nl = new MockNodeChangeListener();
pref.addNodeChangeListener(nl);
child1 = pref.node("mock1");
nl.waitForEvent(1);
assertEquals(1, nl.getAdded());
nl.reset();
pref.node("mock1");
// There shouldn't be an event, but wait in case one arrives...
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
assertEquals(0, nl.getAdded());
nl.reset();
} finally {
pref.removeNodeChangeListener(nl);
child1.removeNode();
}
// same listener can be added twice, and must be removed twice
try {
nl = new MockNodeChangeListener();
pref.addNodeChangeListener(nl);
pref.addNodeChangeListener(nl);
child1 = pref.node("mock2");
nl.waitForEvent(2);
assertEquals(2, nl.getAdded());
nl.reset();
} finally {
pref.removeNodeChangeListener(nl);
pref.removeNodeChangeListener(nl);
child1.removeNode();
}
// test remove event
try {
nl = new MockNodeChangeListener();
pref.addNodeChangeListener(nl);
child1 = pref.node("mock3");
child1.removeNode();
nl.waitForEvent(2);
assertEquals(1, nl.getRemoved());
nl.reset();
} finally {
pref.removeNodeChangeListener(nl);
}
// test remove event with two listeners
try {
nl = new MockNodeChangeListener();
pref.addNodeChangeListener(nl);
pref.addNodeChangeListener(nl);
child1 = pref.node("mock6");
child1.removeNode();
nl.waitForEvent(4);
assertEquals(2, nl.getRemoved());
nl.reset();
} finally {
pref.removeNodeChangeListener(nl);
pref.removeNodeChangeListener(nl);
}
// test add/remove indirect children, or remove several children at the
// same time
Preferences child3;
try {
nl = new MockNodeChangeListener();
child1 = pref.node("mock4");
child1.addNodeChangeListener(nl);
pref.node("mock4/mock5");
nl.waitForEvent(1);
assertEquals(1, nl.getAdded());
nl.reset();
child3 = pref.node("mock4/mock5/mock6");
// There shouldn't be an event, but wait in case one arrives...
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
assertEquals(0, nl.getAdded());
nl.reset();
child3.removeNode();
// There shouldn't be an event, but wait in case one arrives...
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
assertEquals(0, nl.getRemoved());
nl.reset();
pref.node("mock4/mock7");
nl.waitForEvent(1);
assertEquals(1, nl.getAdded());
nl.reset();
child1.removeNode();
nl.waitForEvent(2);
assertEquals(2, nl.getRemoved());
nl.reset();
} finally {
try {
child1.removeNode();
} catch (Exception ignored) {
}
}
}
use of java.util.prefs.BackingStoreException in project jabref by JabRef.
the class PreferencesMigrations method upgradeStoredCustomEntryTypes.
/**
* Migrate all customized entry types from versions <=3.7
*/
public static void upgradeStoredCustomEntryTypes() {
JabRefPreferences prefs = Globals.prefs;
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
try {
if (mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBTEX_TYPES) || mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) {
// skip further processing as prefs already have been migrated
} else {
LOGGER.info("Migrating old custom entry types.");
CustomEntryTypePreferenceMigration.upgradeStoredCustomEntryTypes(prefs.getDefaultBibDatabaseMode());
}
} catch (BackingStoreException ex) {
LOGGER.error("Migrating old custom entry types failed.", ex);
}
}
use of java.util.prefs.BackingStoreException in project jabref by JabRef.
the class PreferencesMigrations method upgradeLabelPatternToBibtexKeyPattern.
/**
* Migrate LabelPattern configuration from versions <=3.5 to new BibtexKeyPatterns
*/
public static void upgradeLabelPatternToBibtexKeyPattern() {
JabRefPreferences prefs = Globals.prefs;
try {
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
// Migrate default pattern
if (mainPrefsNode.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, null) == null) {
// Check whether old defaultLabelPattern is set
String oldDefault = mainPrefsNode.get("defaultLabelPattern", null);
if (oldDefault != null) {
prefs.put(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, oldDefault);
LOGGER.info("Upgraded old default key generator pattern '" + oldDefault + "' to new version.");
}
}
//Pref node already exists do not migrate from previous version
if (mainPrefsNode.nodeExists(JabRefPreferences.BIBTEX_KEY_PATTERNS_NODE)) {
return;
}
// Check for prefs node for Version 3.3-3.5
if (mainPrefsNode.nodeExists("logic/labelpattern")) {
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelpattern"));
} else if (mainPrefsNode.nodeExists("logic/labelPattern")) {
// node used for version 3.0-3.2
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelPattern"));
} else if (mainPrefsNode.nodeExists("labelPattern")) {
// node used for version <3.0
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("labelPattern"));
}
} catch (BackingStoreException e) {
LOGGER.error("Migrating old bibtexKeyPatterns failed.", e);
}
}
Aggregations