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:com.projity.util.VersionUtils.java

public static boolean versionCheck(boolean warnIfBad) {
    String version = VersionUtils.getVersion();
    if (version == null) // for running in debugger
        version = "0";
    Preferences pref = Preferences.userNodeForPackage(VersionUtils.class);
    String localVersion = pref.get("Angel Falls Version", "unknown");
    boolean updated = !localVersion.equals(version);
    String javaVersion = System.getProperty("java.version");
    log.info("Angel Falls Version: " + version + " local version " + localVersion + " updated=" + updated
            + " java version=" + javaVersion);

    pref.put("JavaVersion", javaVersion);

    if (updated) {
        Environment.setUpdated(true);
        pref.put("PODVersion", version);
        try {/*from w  ww  . j  a  v a 2 s  . c  om*/
            pref.flush();
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }

        if (warnIfBad && Environment.isApplet()) {
            if (javaVersion.equals("1.6.0_09") || javaVersion.equals("1.6.0_08")
                    || javaVersion.equals("1.6.0_07") || javaVersion.equals("1.6.0_06")
                    || javaVersion.equals("1.6.0_05") || javaVersion.equals("1.6.0_04")) {
                Environment.setNeedToRestart(true);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        Alert.error(Messages.getString("Error.restart"));
                    }
                });
            }
        }
    } else {
        try {
            pref.flush();
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }
    }
    return updated;
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

public static String getPreferredLookAndFeel() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        return prefs.get(LOOK_AND_FEEL_KEY, DEFAULT_LOOK_AND_FEEL);
    }/*from   w  ww .j  a va 2s  .  co m*/
    return DEFAULT_LOOK_AND_FEEL;
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

public static String getImportFileFilter() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        return prefs.get(IMPORT_FILE_FILTER_KEY, DEFAULT_IMPORT_FILE_FILTER);
    }/*from   w  ww. j a v a  2 s . c  om*/

    return DEFAULT_IMPORT_FILE_FILTER;
}

From source file:kindleclippings.quizlet.QuizletSync.java

public static Preferences getPrefs()
        throws IOException, URISyntaxException, InterruptedException, JSONException, BackingStoreException {
    Preferences prefs = Preferences.userNodeForPackage(QuizletSync.class);

    String token = prefs.get("access_token", null);
    if (token == null) {
        JSONObject o = GetAccessToken.oauthDance();
        if (o == null) {
            JOptionPane.showMessageDialog(null, "Failed authorization to access Quizlet", "QuizletSync",
                    JOptionPane.ERROR_MESSAGE);
            System.exit(0);/*from   www  . j a va  2  s.  c o  m*/
        }
        prefs.put("access_token", o.getString("access_token"));
        prefs.put("user_id", o.getString("user_id"));
        prefs.flush();
    }

    return prefs;
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

public static EditorAdvanceMode getEditorAdvanceMode() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        String mode = prefs.get(ADVANCE_MODE_KEY, DEFAULT_EDITOR_ADVANCE_MODE.toString());
        return EditorAdvanceMode.valueOf(mode);
    }/*from  w  w  w  .  j  a v  a  2 s . c o  m*/
    return DEFAULT_EDITOR_ADVANCE_MODE;
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

/**
 * @return An array of the most recently used filenames
 *//* w  w w.  ja  va  2 s.com*/
public static String[] getPreviouslyUsedFiles() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        String mru = prefs.get(MRU_PREF_KEY, "");
        if (!StringUtils.isEmpty(mru)) {
            return mru.split(MRU_SEPARATOR);
        }
    }

    return null;
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

public static Font getPreferredFont() {

    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        String font = prefs.get(FONT_KEY, null);
        if (font != null) {
            return Font.decode(font);
        }/*from   w ww.  j  a v  a 2s.c o  m*/
    }
    return null;
}

From source file:PrefsUtil.java

/**
 * Gets a List from the preferences, starting with "0", then "1" etc
 *//*from  ww w.ja v  a  2s . c  o  m*/
public static List getList(Preferences preferences) {
    if (preferences == null) {
        throw new IllegalArgumentException("Preferences not set.");
    }

    List list = new ArrayList();

    for (int index = 0; index < 1000; index++) {
        String value = preferences.get("" + index, null);
        if (value == null)
            break;
        //System.out.println( ""+index+ " " + value );
        list.add(value);
    }

    return list;
}

From source file:de.tbuchloh.kiskis.gui.common.Application.java

/**
 * @param prefs//from  www  . ja  v  a 2 s .  c o m
 *            the preferences object to load the program from
 * @return a list with Program-objects
 */
public static List<Program> loadPrograms(final Preferences prefs) {
    final List<Program> allProgs = new ArrayList<Program>();
    final Preferences n = prefs.node(Settings.K_URL_ALLPROGS_NODE);
    String[] progs;
    try {
        progs = n.childrenNames();
    } catch (final BackingStoreException e) {
        throw new Error(e);
    }
    for (final String prog : progs) {
        final Preferences child = n.node(prog);
        final String prefix = child.get(Settings.K_URL_PROG_PREFIX, null);
        final String cmd = child.get(Settings.K_URL_PROG_CMD, null);
        if (prefix == null || cmd == null) {
            LOG.error("The application " //$NON-NLS-1$
                    + prog + " is not specified correctly!"); //$NON-NLS-1$
            continue;
        }
        LOG.debug("command: " + cmd + " for prefix " + prefix); //$NON-NLS-1$ //$NON-NLS-2$
        allProgs.add(new Program(prefix, cmd));
    }

    if (progs.length == 0) {
        allProgs.add(new Program("http", DEFAULT_BROWSER + " " + URL_KEY));
    }
    return allProgs;
}

From source file:PrefsUtil.java

/**
 * Gets a Map from the preferences.//from   w ww .j  av a 2s .co m
 */
public static Map getMap(Preferences preferences) {
    if (preferences == null) {
        throw new IllegalArgumentException("Preferences not set.");
    }

    Map map = new HashMap();

    try {
        String[] keys = preferences.keys();

        for (int index = 0; index < keys.length; index++) {
            map.put(keys[index], preferences.get(keys[index], null));
        }
    } catch (BackingStoreException bse) {
        bse.printStackTrace();
    }

    return map;
}