Example usage for java.util.prefs Preferences putFloat

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

Introduction

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

Prototype

public abstract void putFloat(String key, float value);

Source Link

Document

Associates a string representing the specified float value with the specified key in this preference node.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    // Save some values
    prefs.put("myString", "a string"); // String
    prefs.putBoolean("myBoolean", true); // boolean
    prefs.putInt("myInt", 123); // int
    prefs.putLong("myLong", 123L); // long
    prefs.putFloat("myFloat", 12.3F); // float
    prefs.putDouble("myDouble", 12.3); // double
    byte[] bytes = new byte[10];
    prefs.putByteArray("myByteArray", bytes); // byte[]

    // Export the node to a file
    prefs.exportNode(new FileOutputStream("output.xml"));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    // Save some values
    prefs.put("myString", "a string"); // String
    prefs.putBoolean("myBoolean", true); // boolean
    prefs.putInt("myInt", 123); // int
    prefs.putLong("myLong", 123L); // long

    // Save some values in the parent node
    prefs = prefs.parent();//from   ww w. ja v  a 2s  .c  o m
    prefs.putFloat("myFloat", 12.3F); // float
    prefs.putDouble("myDouble", 12.3); // double
    byte[] bytes = new byte[10];
    prefs.putByteArray("myByteArray", bytes); // byte[]

    prefs.exportSubtree(new FileOutputStream("output.xml"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);

    // Preference key name
    final String PREF_NAME = "name_of_preference";

    // Save/* ww w  .  ja v a2  s.c  o m*/
    prefs.put(PREF_NAME, "a string"); // String
    prefs.putBoolean(PREF_NAME, true); // boolean
    prefs.putInt(PREF_NAME, 123); // int
    prefs.putLong(PREF_NAME, 123L); // long
    prefs.putFloat(PREF_NAME, 12.3F); // float
    prefs.putDouble(PREF_NAME, 12.3); // double
    byte[] bytes = new byte[1024];
    prefs.putByteArray(PREF_NAME, bytes); // byte[]

    // Retrieve
    String s = prefs.get(PREF_NAME, "a string"); // String
    boolean b = prefs.getBoolean(PREF_NAME, true); // boolean
    int i = prefs.getInt(PREF_NAME, 123); // int
    long l = prefs.getLong(PREF_NAME, 123L); // long
    float f = prefs.getFloat(PREF_NAME, 12.3F); // float
    double d = prefs.getDouble(PREF_NAME, 12.3); // double
    bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[]
}

From source file:edu.umd.cs.findbugs.gui2.GUISaveState.java

public void save() {
    Preferences p = Preferences.userNodeForPackage(GUISaveState.class);

    p.putInt(TAB_SIZE, tabSize);/*ww w .j a v a 2  s  . c o  m*/

    p.putFloat(FONT_SIZE, fontSize);

    try {
        p.put(STARTERDIRECTORY, starterDirectoryForLoadBugs.getCanonicalPath());
    } catch (IOException e) {
        Debug.println(e);
    }
    int sorterLength = MainFrame.getInstance().getSorter().getColumnCount();
    ArrayList<Sortables> sortables = MainFrame.getInstance().getSorter().getOrder();
    p.putInt(GUISaveState.SORTERTABLELENGTH, sorterLength);

    String[] sorterKeys = GUISaveState.generateSorterKeys(sorterLength);
    for (int x = 0; x < sorterKeys.length; x++) {
        p.put(sorterKeys[x], sortables.get(x).prettyName);
    }

    p.putInt(GUISaveState.PREVCOMMENTSSIZE, previousComments.size());

    for (int x = 0; x < previousComments.size(); x++) {
        String comment = previousComments.get(x);
        p.put(GUISaveState.COMMENTKEYS[x], comment);
    }

    int size = recentFiles.size();
    while (recentFiles.size() > MAXNUMRECENTPROJECTS) {
        recentFiles.remove(0);
    }

    p.putInt(GUISaveState.NUMPROJECTS, Math.min(size, MAXNUMRECENTPROJECTS));
    for (int x = 0; x < Math.min(size, MAXNUMRECENTPROJECTS); x++) {
        File file = recentFiles.get(x);
        p.put(GUISaveState.RECENTPROJECTKEYS[x], file.getAbsolutePath());
    }

    p.putByteArray(DOCKINGLAYOUT, dockingLayout);

    p.put(FRAME_BOUNDS,
            frameBounds.x + "," + frameBounds.y + "," + frameBounds.width + "," + frameBounds.height);
    p.putInt(EXTENDED_WINDOW_STATE, extendedWindowState);

    p.putInt(SPLIT_MAIN, splitMain);
    p.putDouble(SPLIT_SUMMARY_NEW, splitSummary);
    p.putInt(SPLIT_TOP, splitTop);
    p.putInt(SPLIT_TREE_COMMENTS, splitTreeComments);
    p.putInt(PACKAGE_PREFIX_SEGEMENTS, packagePrefixSegments);

    p.put(ENABLED_PLUGINS, StringUtils.join(enabledPlugins, ','));
    p.put(DISABLED_PLUGINS, StringUtils.join(disabledPlugins, ','));
    p.put(CUSTOM_PLUGINS, StringUtils.join(customPlugins, ' '));
}