Example usage for java.util.prefs Preferences put

List of usage examples for java.util.prefs Preferences put

Introduction

In this page you can find the example usage for java.util.prefs Preferences put.

Prototype

public abstract void put(String key, String value);

Source Link

Document

Associates the specified value with the specified key in this preference node.

Usage

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Set the initial directory preference. This supports opening new file
 * dialogs to a (hopefully) better default in the user's next session.
 * //from   w  w  w. jav a  2 s.co  m
 * @param dir the File for the directory in which file dialogs should open
 */
private static void setInitialDirectory(final File dir) {
    // Store only directories
    final File directory;
    if (dir.isDirectory()) {
        directory = dir;
    } else {
        directory = dir.getParentFile();
    }

    final Preferences preferences = Preferences.userNodeForPackage(SubjectiveFrame.class);
    final String previousPath = preferences.get(INITIAL_DIRECTORY_PREFERENCE_KEY, null);

    if (!directory.toString().equals(previousPath)) {
        preferences.put(INITIAL_DIRECTORY_PREFERENCE_KEY, directory.toString());
    }
}

From source file:PreferenceExample.java

public void setSomeProperties(Preferences p) throws BackingStoreException {
    p.put("fruit", "apple");
    p.put("cost", "1.01");
    p.put("store", "safeway");
}

From source file:com.vaadin.tools.ReportUsage.java

public static void report() {
    long currentTimeMillis = System.currentTimeMillis();
    Preferences prefs = Preferences.userNodeForPackage(ReportUsage.class);
    String lastPing = prefs.get(LAST_PING, "0");
    if (lastPing != null) {
        try {/*w  ww . j a va  2 s .  co m*/
            long lastPingTime = Long.parseLong(lastPing);
            if (currentTimeMillis < lastPingTime + ONE_DAY) {
                return;
            }
        } catch (NumberFormatException e) {
            // error parsing last ping time, ignore and ping
        }
    }

    StringBuilder url = new StringBuilder(QUERY_URL);
    url.append(V_QPARAM);
    url.append(Version.getFullVersion());
    url.append(ID_QPARAM);
    url.append(ANONYMOUS_ID).append(R_QPARAM);

    // TODO add more relevant entry point if feasible
    String entryPoint = COMPILER;

    if (entryPoint != null) {
        url.append(E_QPARAM).append(entryPoint);
    }

    doHttpGet(makeUserAgent(), url.toString());

    prefs.put(LAST_PING, String.valueOf(currentTimeMillis));
}

From source file:org.pentaho.di.core.util.StringPluginProperty.java

/**
 * {@inheritDoc}//from   ww  w . j a  v a  2 s.com
 *
 * @see at.aschauer.commons.pentaho.plugin.PluginProperty#saveToPreferences(java.util.prefs.Preferences)
 */
public void saveToPreferences(final Preferences node) {
    node.put(this.getKey(), this.getValue());
}

From source file:org.pdfsam.ui.DefaultStageService.java

public void save(StageStatus status) {
    Preferences node = Preferences.userRoot().node(STAGE_PATH);
    try {/*from w ww .ja v a  2 s .  c o m*/
        node.put(STAGE_STATUS_KEY, JSON.std.asString(status));
        LOG.trace("Stage status saved {}", status);
    } catch (IOException e) {
        LOG.error("Unable to increment modules usage statistics", e);
    }
}

From source file:com.moss.jdbcdrivers.JdbcConnectionConfig.java

public void saveToPrefs(Preferences node) {
    node.put("url", jdbcUrl);
    node.put("driver", jdbcDriverClassName);
    node.put("logon", logon);
    node.put("password", password);
}

From source file:org.fuin.utils4j.PropertiesFilePreferencesTest.java

/**
 * @testng.test//from   w  w w. ja v  a2s.  c om
 */
public final void testChildConstruction() throws BackingStoreException {
    final File dir = new File(baseDir, "user");
    final File subDir = new File(dir, "abc");
    final File subDir2 = new File(subDir, "def");
    final File file = new File(subDir, PropertiesFilePreferences.FILENAME);
    final File file2 = new File(subDir2, PropertiesFilePreferences.FILENAME);

    final PropertiesFilePreferences root = new PropertiesFilePreferences(dir);

    // Create child node
    final Preferences pref = root.node("abc");
    pref.put("one", "A");
    pref.put("two", "B");
    pref.put("three", "C");

    final Preferences pref2 = pref.node("def");
    pref2.put("four", "4");

    // Flush root to save data to disk
    root.flush();

    Assert.assertTrue(file.exists());
    Assert.assertTrue(file2.exists());
    TestHelper.assertPropertiesEqual(file, ((PropertiesFilePreferences) pref).toProperties());
    TestHelper.assertPropertiesEqual(file2, ((PropertiesFilePreferences) pref2).toProperties());
}

From source file:org.javaswift.cloudie.login.CredentialsStore.java

private void saveCredentials(Preferences node, Credentials cr) {
    node.put("method", String.valueOf(cr.method));
    node.put("authUrl", cr.authUrl);
    node.put("tenantId", cr.tenantId);
    node.put("tenantName", cr.tenantName);
    node.put("username", cr.username);
    node.put("password", String.valueOf(garble(cr.password)));
}

From source file:org.pdfsam.ui.PreferencesRecentWorkspacesServiceTest.java

@Test
public void blankIsNotLoaded() throws BackingStoreException {
    Preferences node = Preferences.userRoot().node(WORKSPACES_PATH);
    node.put("1", EMPTY);
    node.flush();/*from  w  w  w . j a  v a2  s.c  om*/
    PreferencesRecentWorkspacesService newVictim = new PreferencesRecentWorkspacesService();
    assertEquals(0, newVictim.getRecentlyUsedWorkspaces().size());
}

From source file:org.pdfsam.ui.PreferencesRecentWorkspacesServiceTest.java

@Test
public void isSorted() throws BackingStoreException {
    Preferences node = Preferences.userRoot().node(WORKSPACES_PATH);
    node.put("2", "second");
    node.put("3", "third");
    node.put("1", "first");
    node.flush();/*from  w  ww.  j a v a 2s  .  c  o m*/
    PreferencesRecentWorkspacesService newVictim = new PreferencesRecentWorkspacesService();
    List<String> workspaces = newVictim.getRecentlyUsedWorkspaces();
    assertEquals(3, workspaces.size());
    assertEquals("third", workspaces.get(0));
    assertEquals("second", workspaces.get(1));
    assertEquals("first", workspaces.get(2));
}