Example usage for java.util.prefs Preferences getBoolean

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

Introduction

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

Prototype

public abstract boolean getBoolean(String key, boolean def);

Source Link

Document

Returns the boolean value represented by the string associated 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(Main.class);

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

    // Save/*from w w w. j  a  v  a 2 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:org.apache.cayenne.modeler.Main.java

protected File initialProjectFromPreferences() {

    Preferences autoLoadLastProject = Application.getInstance().getPreferencesNode(GeneralPreferences.class,
            "");//from w  w w . ja  v a  2 s  . c  o  m

    if ((autoLoadLastProject != null)
            && autoLoadLastProject.getBoolean(GeneralPreferences.AUTO_LOAD_PROJECT_PREFERENCE, false)) {

        List<String> lastFiles = ModelerPreferences.getLastProjFiles();
        if (!lastFiles.isEmpty()) {
            return new File(lastFiles.get(0));
        }
    }

    return null;
}

From source file:com.github.alexfalappa.nbspringboot.cfgprops.completion.CfgPropsCompletionProvider.java

private void completePropName(SpringBootService sbs, CompletionResultSet completionResultSet, String filter,
        int startOffset, int caretOffset) {
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true);
    final boolean bErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, false);
    long mark = System.currentTimeMillis();
    logger.log(FINER, "Completing property name: {0}", filter);
    for (ConfigurationMetadataProperty propMeta : sbs.queryPropertyMetadata(filter)) {
        if (Utils.isErrorDeprecated(propMeta)) {
            // show error level deprecated props based on pref
            if (bErrorShow) {
                completionResultSet/*from ww w. ja  v a2 s.c  om*/
                        .addItem(new CfgPropCompletionItem(propMeta, sbs, startOffset, caretOffset, bDeprLast));
            }
        } else {
            completionResultSet
                    .addItem(new CfgPropCompletionItem(propMeta, sbs, startOffset, caretOffset, bDeprLast));
        }
    }
    final long elapsed = System.currentTimeMillis() - mark;
    logger.log(FINER, "Property completion of ''{0}'' took: {1} msecs", new Object[] { filter, elapsed });
}

From source file:netbeanstypescript.TSFormatter.java

@Override
public void reformat(Context context, ParserResult pr) {
    final BaseDocument doc = (BaseDocument) context.document();
    JSONObject settings = new JSONObject();
    settings.put("indentSize", IndentUtils.indentLevelSize(doc));
    settings.put("tabSize", IndentUtils.tabSize(doc));
    settings.put("newLineCharacter", "\n");
    settings.put("convertTabsToSpaces", IndentUtils.isExpandTabs(doc));
    settings.put("indentStyle", 2);
    // TODO: The JS editor's settings don't correspond well with ts.FormatCodeSettings.
    // Should probably create a separate text/typescript style preferences dialog, so
    // it's clear to the user what can and can't be changed.
    Preferences jsPrefs = CodeStylePreferences.get(doc, "text/javascript").getPreferences();
    settings.put("insertSpaceAfterCommaDelimiter", jsPrefs.getBoolean("spaceAfterComma", true));
    settings.put("insertSpaceAfterSemicolonInForStatements", jsPrefs.getBoolean("spaceAfterSemi", true));
    settings.put("insertSpaceBeforeAndAfterBinaryOperators", jsPrefs.getBoolean("spaceAroundBinaryOps", true));
    settings.put("insertSpaceAfterKeywordsInControlFlowStatements",
            jsPrefs.getBoolean("spaceBeforeIfParen", true));
    settings.put("insertSpaceAfterFunctionKeywordForAnonymousFunctions",
            jsPrefs.getBoolean("spaceBeforeAnonMethodDeclParen", true));
    settings.put("insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis",
            jsPrefs.getBoolean("spaceWithinParens", false));
    settings.put("insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets",
            jsPrefs.getBoolean("spaceWithinArrayBrackets", false));
    settings.put("insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces",
            jsPrefs.getBoolean("spaceWithinBraces", false));
    settings.put("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces",
            jsPrefs.getBoolean("spaceWithinBraces", false));
    settings.put("insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces",
            jsPrefs.getBoolean("spaceWithinBraces", false));
    settings.put("insertSpaceAfterTypeAssertion",
            // JS doesn't have typecasts...
            CodeStylePreferences.get(doc, "text/x-java").getPreferences().getBoolean("spaceAfterTypeCast",
                    true));/*  w  ww .  j a v a 2s  .c o m*/
    settings.put("placeOpenBraceOnNewLineForFunctions",
            jsPrefs.get("functionDeclBracePlacement", "").startsWith("NEW"));
    settings.put("placeOpenBraceOnNewLineForControlBlocks",
            jsPrefs.get("ifBracePlacement", "").startsWith("NEW"));
    final Object edits = TSService.call("getFormattingEdits", GsfUtilities.findFileObject(doc),
            context.startOffset(), context.endOffset(), settings);
    if (edits == null) {
        return;
    }
    doc.runAtomic(new Runnable() {
        @Override
        public void run() {
            try {
                applyEdits(doc, edits);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    });
}

From source file:com.github.fritaly.dualcommander.UserPreferences.java

public synchronized void init(Preferences preferences) {
    assertNotInitialized();/* w w w.  jav  a2 s  . c o  m*/

    Validate.notNull(preferences, "The given preferences is null");

    this.showHidden = preferences.getBoolean(PROPERTY_SHOW_HIDDEN, false);
    this.editFileCommand = preferences.get(PROPERTY_EDIT_FILE_COMMAND, "edit");
    this.viewFileCommand = preferences.get(PROPERTY_VIEW_FILE_COMMAND, "open");

    // The user preferences can be initialized only once
    this.initialized = true;

    if (logger.isInfoEnabled()) {
        logger.info("Initialized user preferences");
    }
}

From source file:de.thomasbolz.renamer.RenamerGUI.java

private boolean isDisclaimerConfirmed() {
    final Preferences preferences = getPreferences();
    return preferences.getBoolean(DISCLAIMER, false);
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectWizardIterator.java

private void createNbActions(String pkg, String mvnName, FileObject dir) throws IOException {
    // build main class string
    StringBuilder mainClass = new StringBuilder(pkg);
    mainClass.append('.').append(Character.toUpperCase(mvnName.charAt(0))).append(mvnName.substring(1))
            .append("Application");
    // retrieve default options from prefs
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    final boolean bForceColor = prefs.getBoolean(PREF_FORCE_COLOR_OUTPUT, true);
    final boolean bManualRestart = prefs.getBoolean(PREF_MANUAL_RESTART, false);
    final String strVmOpts = Utils.vmOptsFromPrefs();
    // create nbactions.xml from template
    FileObject foTmpl = Templates.getTemplate(wiz);
    new FileBuilder(foTmpl, dir).name("nbactions").param("mainClass", mainClass.toString())
            .param("forceColor", bForceColor).param("manualRestart", bManualRestart).param("vmOpts", strVmOpts)
            .build();/*from   ww w  .  j av  a2  s .co  m*/
}

From source file:ome.formats.importer.util.IniFileLoader.java

/**
 * @return application title//from   w  ww .java2  s . c  o  m
 */
public boolean getForceFileArchiveOn() {
    boolean toReturn = false;
    if (staticPrefs != null) {
        Preferences ui = staticPrefs.node("UI");
        toReturn = ui.getBoolean("forceFileArchiveOn", false);
    }
    return toReturn;
}

From source file:ome.formats.importer.util.IniFileLoader.java

/**
 * @return application title/*  w  w w.  ja  va 2 s.  co m*/
 */
public boolean getStaticDisableHistory() {
    boolean toReturn = false;
    if (staticPrefs != null) {
        Preferences ui = staticPrefs.node("UI");
        toReturn = ui.getBoolean("disableImportHistory", false);
    }
    return toReturn;
}

From source file:ome.formats.importer.util.IniFileLoader.java

/**
 * @return application title/*from   w w  w.  ja  v a2s. c o  m*/
 */
public boolean getStaticDisableUpgradeCheck() {
    boolean toReturn = false;
    if (staticPrefs != null) {
        Preferences general = staticPrefs.node("General");
        toReturn = general.getBoolean("disableUpgradeCheck", false);
    }
    return toReturn;
}