Search in sources :

Example 61 with BackingStoreException

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) {
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 62 with BackingStoreException

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);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) NbPreferences(org.openide.util.NbPreferences) Preferences(java.util.prefs.Preferences)

Example 63 with BackingStoreException

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) {
        }
    }
}
Also used : Preferences(java.util.prefs.Preferences) IOException(java.io.IOException) BackingStoreException(java.util.prefs.BackingStoreException)

Example 64 with BackingStoreException

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);
    }
}
Also used : JabRefPreferences(org.jabref.preferences.JabRefPreferences) BackingStoreException(java.util.prefs.BackingStoreException) JabRefPreferences(org.jabref.preferences.JabRefPreferences) Preferences(java.util.prefs.Preferences)

Example 65 with BackingStoreException

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);
    }
}
Also used : JabRefPreferences(org.jabref.preferences.JabRefPreferences) BackingStoreException(java.util.prefs.BackingStoreException) JabRefPreferences(org.jabref.preferences.JabRefPreferences) Preferences(java.util.prefs.Preferences)

Aggregations

BackingStoreException (java.util.prefs.BackingStoreException)112 Preferences (java.util.prefs.Preferences)95 NbPreferences (org.openide.util.NbPreferences)14 File (java.io.File)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)4 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)4 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)4 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)4 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)4 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)4 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)4 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)4 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)4 FileLinkPreferences (org.jabref.logic.layout.format.FileLinkPreferences)4 NameFormatterPreferences (org.jabref.logic.layout.format.NameFormatterPreferences)4 ProxyPreferences (org.jabref.logic.net.ProxyPreferences)4 OpenOfficePreferences (org.jabref.logic.openoffice.OpenOfficePreferences)4 ProtectedTermsPreferences (org.jabref.logic.protectedterms.ProtectedTermsPreferences)4