Example usage for java.util.prefs Preferences get

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

Introduction

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

Prototype

public abstract String get(String key, String def);

Source Link

Document

Returns the value associated with the specified key in this preference node.

Usage

From source file:Main.java

public static boolean contains(Preferences node, String key) {
    return node.get(key, null) != null;
}

From source file:Main.java

public static String containsValue(Preferences node, String value) {
    try {//from w  ww .  j  av a  2 s .c o m
        String[] keys = node.keys();

        for (int i = 0; i < keys.length; i++) {
            if (value.equals(node.get(keys[i], null))) {
                return keys[i];
            }
        }
    } catch (BackingStoreException e) {
    }
    return null;
}

From source file:org.apache.syncope.ide.netbeans.ResourceConnector.java

public static ConnectionParams getConnectionParams() {
    Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class);
    return ConnectionParams.builder().scheme(prefs.get("scheme", "http")).host(prefs.get("host", "localhost"))
            .port(prefs.get("port", "8080")).username(prefs.get("username", StringUtils.EMPTY))
            .password(prefs.get("password", StringUtils.EMPTY)).build();
}

From source file:de.maklerpoint.office.Tags.Tags.java

/**
 * Entfernt den Tag und ldt die Liste neu
 * @param tagName //from ww  w.ja v  a2 s .c  o  m
 */
public static void removeTag(String tagName) {
    Preferences prefs = Preferences.userRoot().node(Tags.class.getName());
    String taglist = prefs.get("tagListe", "Standard,ffentlich,Wichtig,Dienstlich,Persnlich");

    String[] result = taglist.split(",");

    if (result == null) {
        return;
    }

    String[] clean = (String[]) ArrayUtils.removeElement(result, tagName);
    prefs.put("tagListe", ArrayStringTools.arrayToString(clean, ","));

    InitializeTags.loadTags();
}

From source file:de.maklerpoint.office.Tags.Tags.java

/**
 * //  w  w w  . j  a  va 2 s  .c o  m
 * @param tag 
 */
public static void addTag(TagObj tag) {
    Preferences prefs = Preferences.userRoot().node(Tags.class.getName());
    String taglist = prefs.get("tagListe", "Standard,ffentlich,Wichtig,Dienstlich,Persnlich");

    String[] result = taglist.split(",");

    if (result == null) {
        return;
    }

    String[] clean = (String[]) ArrayUtils.add(result, tag.getName());
    prefs.put("tagListe", ArrayStringTools.arrayToString(clean, ","));

    prefs.put("tag" + tag.getName(), tag.getTagColor() + "," + tag.getFontColor());

    InitializeTags.loadTags();
}

From source file:de.maklerpoint.office.Tags.Tags.java

/**
 * /* w  w  w .  j  a  v  a 2s.c  o  m*/
 * @param tag
 * @param oldname 
 */
public static void updateTag(TagObj tag, String oldname) {
    Preferences prefs = Preferences.userRoot().node(Tags.class.getName());
    String taglist = prefs.get("tagListe", "Standard,ffentlich,Wichtig,Dienstlich,Persnlich");

    String[] result = taglist.split(",");

    if (result == null) {
        return;
    }

    boolean contains = ArrayUtils.contains(result, tag.getName());

    if (contains) {
        prefs.put("tag" + tag.getName(), tag.getTagColor() + "," + tag.getFontColor());
        InitializeTags.loadTags();
    } else {
        Tags.removeTag(oldname);
        addTag(tag);
    }
}

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

private static String loadFirstLaunch() {
    Preferences prefs = Preferences.userNodeForPackage(CheckForUpdates.class);

    String firstLaunch = prefs.get(FIRST_LAUNCH, null);
    if (firstLaunch == null) {
        long currentTimeMillis = System.currentTimeMillis();
        firstLaunch = Long.toHexString(currentTimeMillis);
        prefs.put(FIRST_LAUNCH, firstLaunch);
    }/*  w w w . j  a v  a 2  s .c  om*/
    return firstLaunch;

}

From source file:org.streamsource.streamflow.statistic.web.Dao.java

private static void initializeDataSource() {
    Preferences preference = Preferences.userRoot()
            .node("/streamsource/streamflow/StreamflowServer/streamflowds/properties");
    String dbUrl = preference.get("url", "n/a");
    String dbUser = preference.get("username", "n/a");
    String dbPwd = preference.get("password", "n/a");
    String dbDriver = preference.get("driver", "n/a");

    dbVendor = preference.get("dbVendor", "mysql");

    ds = new BasicDataSource();
    ds.setDriverClassName(dbDriver);/*from w  w  w  .ja  v  a  2 s  .c om*/
    ds.setUrl(dbUrl);
    ds.setUsername(dbUser);
    ds.setPassword(dbPwd);

    bDataSourceInitialized = true;
}

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  w  w. jav a 2 s.  c o  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:LookAndFeelPrefs.java

/**
 * Get the desired look and feel from a per-user preference. If the
 * preferences doesn't exist or is unavailable, use the default look and feel.
 * The preference is shared by all classes in the same package as prefsClass.
 *///from w w w.  j a v a  2s . c  om
public static void setPreferredLookAndFeel(Class prefsClass) {
    Preferences prefs = Preferences.userNodeForPackage(prefsClass);
    String defaultLAF = UIManager.getSystemLookAndFeelClassName();
    String laf = prefs.get(PREF_NAME, defaultLAF);
    try {
        UIManager.setLookAndFeel(laf);
    } catch (Exception e) { // ClassNotFound or InstantiationException
        // An exception here is probably caused by a bogus preference.
        // Ignore it silently; the user will make do with the default LAF.
    }
}