Search in sources :

Example 1 with BackingStoreException

use of java.util.prefs.BackingStoreException in project jmonkeyengine by jMonkeyEngine.

the class TestCustomAppSettings method testPreferenceSettings.

/**
     * Tests preference based AppSettings.
     */
private static void testPreferenceSettings() {
    AppSettings settings = new AppSettings(false);
    settings.putBoolean("TestBool", true);
    settings.putInteger("TestInt", 123);
    settings.putString("TestStr", "HelloWorld");
    settings.putFloat("TestFloat", 123.567f);
    // Objects not supported by preferences
    settings.put("TestObj", new Mesh());
    try {
        settings.save(APPSETTINGS_KEY);
    } catch (BackingStoreException ex) {
        ex.printStackTrace();
    }
    AppSettings loadedSettings = new AppSettings(false);
    try {
        loadedSettings.load(APPSETTINGS_KEY);
    } catch (BackingStoreException ex) {
        ex.printStackTrace();
    }
    assertEqual(loadedSettings.getBoolean("TestBool"), true);
    assertEqual(loadedSettings.getInteger("TestInt"), 123);
    assertEqual(loadedSettings.getString("TestStr"), "HelloWorld");
    assertEqual(loadedSettings.get("TestFloat"), 123.567f);
}
Also used : AppSettings(com.jme3.system.AppSettings) BackingStoreException(java.util.prefs.BackingStoreException) Mesh(com.jme3.scene.Mesh)

Example 2 with BackingStoreException

use of java.util.prefs.BackingStoreException in project robovm by robovm.

the class OldPreferencesTest method testAddPreferenceChangeListener.

public void testAddPreferenceChangeListener() throws Exception {
    Preferences pref = Preferences.userNodeForPackage(Preferences.class);
    MockPreferenceChangeListener pl = null;
    try {
        pref.addPreferenceChangeListener(null);
        fail();
    } catch (NullPointerException expected) {
    }
    // To get existed node doesn't create the change event
    try {
        pl = new MockPreferenceChangeListener();
        pref.addPreferenceChangeListener(pl);
        pref.putInt("mock1", 123);
        pl.waitForEvent(1);
        assertEquals(1, pl.getChanged());
        pref.putLong("long_key", Long.MAX_VALUE);
        pl.waitForEvent(2);
        assertEquals(2, pl.getChanged());
        pl.reset();
        try {
            pref.clear();
            pl.waitForEvent(2);
            assertEquals(2, pl.getChanged());
        } catch (BackingStoreException bse) {
            pl.reset();
            fail("BackingStoreException is thrown");
        }
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    //child1.removeNode();
    }
    // same listener can be added twice, and must be removed twice
    try {
        pl = new MockPreferenceChangeListener();
        pref.addPreferenceChangeListener(pl);
        pref.addPreferenceChangeListener(pl);
        pref.putFloat("float_key", Float.MIN_VALUE);
        pl.waitForEvent(2);
        assertEquals(2, pl.getChanged());
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
        pref.removePreferenceChangeListener(pl);
    }
    // test remove event
    try {
        pl = new MockPreferenceChangeListener();
        pref.addPreferenceChangeListener(pl);
        pref.putDouble("double_key", Double.MAX_VALUE);
        pl.waitForEvent(1);
        assertEquals(1, pl.getChanged());
        try {
            pref.clear();
            pl.waitForEvent(3);
            assertEquals(3, pl.getChanged());
        } catch (BackingStoreException bse) {
            fail("BackingStoreException is thrown");
        }
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
    }
    // test remove event with two listeners
    try {
        pl = new MockPreferenceChangeListener();
        pref.addPreferenceChangeListener(pl);
        pref.addPreferenceChangeListener(pl);
        pref.putByteArray("byte_array_key", new byte[] { 1, 2, 3 });
        try {
            pref.clear();
            pl.waitForEvent(4);
            assertEquals(4, pl.getChanged());
        } catch (BackingStoreException bse) {
            fail("BackingStoreException is thrown");
        }
        pl.reset();
    } finally {
        pref.removePreferenceChangeListener(pl);
        pref.removePreferenceChangeListener(pl);
    }
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences)

Example 3 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class JmriPreferencesProviderTest method testGetPreferences.

/**
     * Test of getPreferences method, of class JmriPreferencesProvider.
     * @throws java.io.IOException
     */
public void testGetPreferences() throws IOException {
    String id = Long.toString((new Date()).getTime());
    Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
    Class<?> clazz = this.getClass();
    Preferences shared = JmriPreferencesProvider.getPreferences(project, clazz, true);
    Preferences privat = JmriPreferencesProvider.getPreferences(project, clazz, false);
    assertNotNull(shared);
    assertNotNull(privat);
    assertNotSame(shared, privat);
    try {
        assertEquals(shared.keys().length, 0);
    } catch (BackingStoreException ex) {
        assertNotNull(ex);
    }
    try {
        assertEquals(privat.keys().length, 0);
    } catch (BackingStoreException ex) {
        assertNotNull(ex);
    }
    FileUtil.delete(project.getPath());
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences) File(java.io.File) Date(java.util.Date) Profile(jmri.profile.Profile)

Example 4 with BackingStoreException

use of java.util.prefs.BackingStoreException in project JMRI by JMRI.

the class JmriPreferencesProviderTest method testIsFirstUse.

/**
     * Test of isFirstUse method, of class JmriPreferencesProvider.
     * @throws java.io.IOException
     */
public void testIsFirstUse() throws IOException {
    String id = Long.toString((new Date()).getTime());
    Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
    JmriPreferencesProvider shared = JmriPreferencesProvider.findProvider(project.getPath(), true);
    assertEquals(shared.isFirstUse(), true);
    Preferences prefs = shared.getPreferences(this.getClass());
    prefs.put("test", "test");
    try {
        // force write
        prefs.flush();
    } catch (BackingStoreException ex) {
        assertNull(ex);
    }
    shared = new JmriPreferencesProvider(project.getPath(), true);
    assertEquals(shared.isFirstUse(), false);
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences) File(java.io.File) Date(java.util.Date) Profile(jmri.profile.Profile)

Example 5 with BackingStoreException

use of java.util.prefs.BackingStoreException in project jabref by JabRef.

the class ArgumentProcessor method resetPreferences.

private void resetPreferences(String value) {
    if ("all".equals(value.trim())) {
        try {
            System.out.println(Localization.lang("Setting all preferences to default values."));
            Globals.prefs.clear();
            new SharedDatabasePreferences().clear();
        } catch (BackingStoreException e) {
            System.err.println(Localization.lang("Unable to clear preferences."));
            LOGGER.error("Unable to clear preferences", e);
        }
    } else {
        String[] keys = value.split(",");
        for (String key : keys) {
            if (Globals.prefs.hasKey(key.trim())) {
                System.out.println(Localization.lang("Resetting preference key '%0'", key.trim()));
                Globals.prefs.clear(key.trim());
            } else {
                System.out.println(Localization.lang("Unknown preference key '%0'", key.trim()));
            }
        }
    }
}
Also used : SharedDatabasePreferences(org.jabref.shared.prefs.SharedDatabasePreferences) BackingStoreException(java.util.prefs.BackingStoreException)

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