Example usage for java.util.prefs Preferences userNodeForPackage

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

Introduction

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

Prototype

public static Preferences userNodeForPackage(Class<?> c) 

Source Link

Document

Returns the preference node from the calling user's preference tree that is associated (by convention) with the specified class's package.

Usage

From source file:com.esri.geoevent.test.performance.ui.ProducerController.java

@Override
protected void loadState() {
    Preferences preferences = Preferences.userNodeForPackage(ProducerController.class);
    Protocol selectedProtocol = Protocol.fromValue(preferences.get("protocol", Protocol.TCP.toString()));
    int portNumber = NumberUtils.toInt(preferences.get("port", String.valueOf(DEFAULT_COMMAND_PORT)));
    int serverPortNumber = NumberUtils
            .toInt(preferences.get("serverPort", String.valueOf(DEFAULT_SERVER_PORT)));

    protocol.setValue(selectedProtocol);
    port.setText(String.valueOf(portNumber));
    serverPort.setText(String.valueOf(serverPortNumber));
}

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

public static int getViewerDividerOffset() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        return prefs.getInt(VIEWER_DIVIDER_OFFSET_KEY, DEFAULT_VIEWER_DIVIDER_OFFSET);

    }/*from   w w w . jav a2s.  co m*/
    return DEFAULT_VIEWER_DIVIDER_OFFSET;
}

From source file:corelyzer.data.CRPreferences.java

public CRPreferences() {
    prefs = Preferences.userNodeForPackage(this.getClass());
    initDefaultValues();/*w  w  w.  j a  v  a2 s.  c  o  m*/

    // init default preference values
    String sp = System.getProperty("file.separator");
    config_Directory = System.getProperty("user.home") + sp + ".corelyzer";

    try {
        // Get current working directory
        appStart_Directory = new File(".").getCanonicalPath();
    } catch (IOException e) {
        System.err.println("Cannot get app dir and datastore dir!");
    }

    // don't assume a "My Documents" directory exists - fall back on user.home if needed
    final String homeDir = System.getProperty("user.home");
    final String engDefaultDataDir = "Documents" + sp + "Corelyzer";
    File defaultDataDir = new File(homeDir + sp + engDefaultDataDir);
    if (!defaultDataDir.exists())
        defaultDataDir = new File(homeDir);

    datastore_Directory = defaultDataDir.getAbsolutePath();

    annotation_Directory = datastore_Directory + sp + "Annotations";
    cache_Directory = datastore_Directory + sp + "Caches";
    texBlock_Directory = cache_Directory + sp + "imgblocks_dxt1";
    download_Directory = cache_Directory + sp + "downloads";
    tmp_Directory = cache_Directory + sp + "tmp";

    // UI preferences default
    lockCoreSectionImage = true;

    // Canvas Grid default
    grid_show = false;
    grid_type = 0;
    grid_size = 10.0f;
    grid_thickness = 1;
    grid_r = 0.8f;
    grid_g = 0.8f;
    grid_b = 0.8f;

    // Display preferences default
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    numberOfRows = 1;
    numberOfColumns = 1;
    screenWidth = dim.width;
    screenHeight = dim.height;
    dpix = 72.0f;
    dpiy = 72.0f;
    borderLeft = 1.0f;
    borderRight = 1.0f;
    borderDown = 1.0f;
    borderUp = 1.0f;
    row_offset = 0;
    column_offset = 0;

    // Session history
    sessionHistory = new Vector<String>();

    // Canvas background color
    this.bgcolor = new float[3];
    bgcolor[0] = bgcolor[1] = bgcolor[2] = DEFAULT_BGCOLOR;
}

From source file:com.esri.geoevent.test.performance.ui.ConsumerController.java

@Override
protected void loadState() {
    Preferences preferences = Preferences.userNodeForPackage(ConsumerController.class);
    Protocol selectedProtocol = Protocol.fromValue(preferences.get("protocol", Protocol.TCP.toString()));
    int portNumber = NumberUtils.toInt(preferences.get("port", String.valueOf(DEFAULT_COMMAND_PORT)));
    int serverPortNumber = NumberUtils
            .toInt(preferences.get("serverPort", String.valueOf(DEFAULT_SERVER_PORT)));

    protocol.setValue(selectedProtocol);
    port.setText(String.valueOf(portNumber));
    serverPort.setText(String.valueOf(serverPortNumber));
}

From source file:de.erdesignerng.util.ApplicationPreferences.java

protected ApplicationPreferences() throws BackingStoreException {

    preferences = Preferences.userNodeForPackage(ApplicationPreferences.class);
    List<String> theNames = Arrays.asList(preferences.keys());
    for (String theName : theNames) {

        // Locate the window defaults here
        if (theName.startsWith("window")) {
            windowDefinitions.put(theName, preferences.get(theName, null));
        }/*w  w w  .j a v a  2 s  .  c  om*/
        if (theName.startsWith(LRUPREFIX)) {
            File theFile = new File(preferences.get(theName, ""));
            if ((theFile.exists()) && (!recentlyUsedFiles.contains(theFile))) {
                recentlyUsedFiles.add(theFile);
            }
        }
        if (theName.startsWith(CLASSPATHPREFIX)) {
            File theFile = new File(preferences.get(theName, ""));
            if (theFile.exists()) {
                classpathfiles.add(theFile);
            }
        }

    }

    if (theNames.contains(RPCPREFIX + "DIALECT")) {
        String theDialect = preferences.get(RPCPREFIX + "DIALECT", "");
        String theURL = preferences.get(RPCPREFIX + "URL", "");
        String theUser = preferences.get(RPCPREFIX + "USER", "");
        String theDriver = preferences.get(RPCPREFIX + "DRIVER", "");
        String thePass = preferences.get(RPCPREFIX + "PASS", "");

        repositoryConnection = new ConnectionDescriptor(null, theDialect, theURL, theUser, theDriver, thePass,
                false);
    }

    for (int i = 0; i < 20; i++) {
        if (theNames.contains(LRCPREFIX + "DIALECT_" + i)) {
            String theAlias = preferences.get(LRCPREFIX + "ALIAS_" + i, "");
            String theDialect = preferences.get(LRCPREFIX + "DIALECT_" + i, "");
            String theURL = preferences.get(LRCPREFIX + "URL_" + i, "");
            String theUser = preferences.get(LRCPREFIX + "USER_" + i, "");
            String theDriver = preferences.get(LRCPREFIX + "DRIVER_" + i, "");
            String thePass = preferences.get(LRCPREFIX + "PASS_" + i, "");
            String thePrompt = preferences.get(LRCPREFIX + "PROMPT_" + i, "");
            boolean theBooleanPrompt = false;
            if (StringUtils.isNotEmpty(thePrompt)) {
                theBooleanPrompt = Boolean.parseBoolean(thePrompt);
            }

            ConnectionDescriptor theConnection = new ConnectionDescriptor(theAlias, theDialect, theURL, theUser,
                    theDriver, thePass, theBooleanPrompt);
            if (!recentlyUsedConnections.contains(theConnection)) {
                recentlyUsedConnections.add(theConnection);
            }
        }
    }

    size = 20;
    gridSize = preferences.getInt(GRIDSIZE, 10);
    intelligentLayout = preferences.getBoolean(INTELLIGENTLAYOUT, true);
    automaticRelationAttributePattern = preferences.get(AUTOMATICRELATIONATTRIBUTEPATTERN, "FK_{0}_{1}");
    windowLayout = preferences.getByteArray(LAYOUT, new byte[0]);
    gridWidthAfterReverseEngineering = preferences.getInt(TABLEGRIDWIDTHAFTERREVERSEENGINEERING, 8);
    xmlIndentation = preferences.getInt(XMLINDENTATION, 4);

    onUpdateDefault = CascadeType.fromString(preferences.get(ONUPDATEDEFAULT, CascadeType.NOTHING.toString()));
    onDeleteDefault = CascadeType.fromString(preferences.get(ONDELETEDEFAULT, CascadeType.NOTHING.toString()));

    String theMode = preferences.get(EDITORMODE, null);
    if (theMode == null) {
        editorMode = EditorMode.CLASSIC;
    } else {
        editorMode = EditorMode.valueOf(theMode);
    }
}

From source file:com.ethanruffing.preferenceabstraction.AutoPreferences.java

/**
 * Sets this up for the given class, forcing use of the specified storage
 * system. Defaults to using an XML file if using file-based storage.
 *
 * @param c          The class for which the preferences are to be stored.
 * @param configType The storage system to use for the preferences.
 * @throws ConfigurationException Thrown if an error occurs while loading
 *                                the configuration file.
 *//*w  w  w .j  av a  2  s . c  o m*/
private void setup(Class<?> c, ConfigurationType configType) throws ConfigurationException {
    prefsFor = c;
    this.configType = configType;
    switch (configType) {
    case LOCAL:
        fileConfig = new XMLConfiguration(new File(c.getPackage().getName() + ".xml"));
        fileConfig.setAutoSave(true);
        ((XMLConfiguration) fileConfig).setDelimiterParsingDisabled(true);
    case HOME:
        fileConfig = new XMLConfiguration(
                new File(System.getProperty("user.home"), "." + c.getPackage().getName() + ".xml"));
        fileConfig.setAutoSave(true);
        ((XMLConfiguration) fileConfig).setDelimiterParsingDisabled(true);
        break;
    case SYSTEM:
        prefs = Preferences.userNodeForPackage(c);
        break;
    }
}

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

public static void loadInstance() {
    GUISaveState newInstance = new GUISaveState();
    newInstance.recentFiles = new ArrayList<File>();
    Preferences p = Preferences.userNodeForPackage(GUISaveState.class);

    newInstance.tabSize = p.getInt(TAB_SIZE, 4);

    newInstance.fontSize = p.getFloat(FONT_SIZE, 12.0f);

    newInstance.starterDirectoryForLoadBugs = new File(
            p.get(GUISaveState.STARTERDIRECTORY, SystemProperties.getProperty("user.dir")));

    int prevCommentsSize = p.getInt(GUISaveState.PREVCOMMENTSSIZE, 0);

    for (int x = 0; x < prevCommentsSize; x++) {
        String comment = p.get(GUISaveState.COMMENTKEYS[x], "");
        newInstance.previousComments.add(comment);
    }/*from w  w  w. j  a va 2s.  c  o  m*/

    int size = Math.min(MAXNUMRECENTPROJECTS, p.getInt(GUISaveState.NUMPROJECTS, 0));
    for (int x = 0; x < size; x++) {
        newInstance.addRecentFile(new File(p.get(GUISaveState.RECENTPROJECTKEYS[x], "")));
    }

    int sorterSize = p.getInt(GUISaveState.SORTERTABLELENGTH, -1);
    if (sorterSize != -1) {
        ArrayList<Sortables> sortColumns = new ArrayList<Sortables>();
        String[] sortKeys = GUISaveState.generateSorterKeys(sorterSize);
        for (int x = 0; x < sorterSize; x++) {
            Sortables s = Sortables.getSortableByPrettyName(p.get(sortKeys[x], "*none*"));

            if (s == null) {
                if (MainFrame.GUI2_DEBUG) {
                    System.err.println("Sort order was corrupted, using default sort order");
                }
                newInstance.useDefault = true;
                break;
            }
            sortColumns.add(s);
        }
        if (!newInstance.useDefault) {
            // add in default columns
            Set<Sortables> missingSortColumns = new HashSet<Sortables>(Arrays.asList(DEFAULT_COLUMN_HEADERS));
            missingSortColumns.removeAll(sortColumns);
            sortColumns.addAll(missingSortColumns);
            newInstance.sortColumns = sortColumns.toArray(new Sortables[sortColumns.size()]);
        }
    } else {
        newInstance.useDefault = true;
    }

    newInstance.dockingLayout = p.getByteArray(DOCKINGLAYOUT, new byte[0]);

    String boundsString = p.get(FRAME_BOUNDS, null);
    Rectangle r = new Rectangle(0, 0, 800, 650);
    if (boundsString != null) {
        String[] a = boundsString.split(",", 4);
        if (a.length > 0) {
            try {
                r.x = Math.max(0, Integer.parseInt(a[0]));
            } catch (NumberFormatException nfe) {
                assert true;
            }
        }
        if (a.length > 1) {
            try {
                r.y = Math.max(0, Integer.parseInt(a[1]));
            } catch (NumberFormatException nfe) {
                assert true;
            }
        }
        if (a.length > 2) {
            try {
                r.width = Math.max(40, Integer.parseInt(a[2]));
            } catch (NumberFormatException nfe) {
                assert true;
            }
        }
        if (a.length > 3) {
            try {
                r.height = Math.max(40, Integer.parseInt(a[3]));
            } catch (NumberFormatException nfe) {
                assert true;
            }
        }
    }
    newInstance.frameBounds = r;
    newInstance.extendedWindowState = p.getInt(EXTENDED_WINDOW_STATE, Frame.NORMAL);

    newInstance.splitMain = p.getInt(SPLIT_MAIN, 400);
    newInstance.splitSummary = p.getInt(SPLIT_SUMMARY_NEW, 400);
    newInstance.splitTop = p.getInt(SPLIT_TOP, -1);
    newInstance.splitTreeComments = p.getInt(SPLIT_TREE_COMMENTS, 250);
    newInstance.packagePrefixSegments = p.getInt(PACKAGE_PREFIX_SEGEMENTS, 3);

    String plugins = p.get(CUSTOM_PLUGINS, "");
    if (plugins.length() > 0) {
        for (String s : plugins.split(" ")) {
            try {
                URI u = new URI(s);
                Plugin.addCustomPlugin(u);
                newInstance.customPlugins.add(u);
            } catch (PluginException e) {
                assert true;
            } catch (URISyntaxException e) {
                assert true;
            }
        }
    }

    String enabledPluginsString = p.get(ENABLED_PLUGINS, "");
    String disabledPluginsString = p.get(DISABLED_PLUGINS, "");
    newInstance.enabledPlugins = new ArrayList<String>(Arrays.asList(enabledPluginsString.split(",")));
    newInstance.disabledPlugins = new ArrayList<String>(Arrays.asList(disabledPluginsString.split(",")));

    instance = newInstance;
}

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

public static void setViewerDividerOffset(int offset) {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        prefs.putInt(VIEWER_DIVIDER_OFFSET_KEY, offset);
    }//from  w  w w  . ja  va2  s  .c  o  m
}

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);//  www  .  j a v  a2 s.co  m
        }
        prefs.put("access_token", o.getString("access_token"));
        prefs.put("user_id", o.getString("user_id"));
        prefs.flush();
    }

    return prefs;
}

From source file:org.noroomattheinn.visibletesla.AppContext.java

AppContext(Application app, Stage stage) {
    this.app = app;
    this.stage = stage;
    this.persistentState = Preferences.userNodeForPackage(this.getClass());
    this.inactivityModeListener = null;

    this.inactivityState = new SimpleObjectProperty<>(InactivityType.Awake);
    this.shuttingDown = new SimpleBooleanProperty(false);

    this.lastKnownChargeState = new SimpleObjectProperty<>();
    this.lastKnownDrivingState = new SimpleObjectProperty<>();
    this.lastKnownGUIState = new SimpleObjectProperty<>();
    this.lastKnownHVACState = new SimpleObjectProperty<>();
    this.lastKnownSnapshotState = new SimpleObjectProperty<>();
    this.lastKnownVehicleState = new SimpleObjectProperty<>();
    this.schedulerActivityReport = new SimpleObjectProperty<>();

    this.simulatedUnits = new SimpleObjectProperty<>();
    this.simulatedWheels = new SimpleObjectProperty<>();
    this.simulatedColor = new SimpleObjectProperty<>();
    this.simulatedRoof = new SimpleObjectProperty<>();

    this.prefs = new Prefs(this);

    appFilesFolder = ensureAppFilesFolder();

    establishProxy();// w  w w .  ja va  2s .  c  o m
}