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: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));/*from   w  ww. j av  a2s . 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.wwidesigner.gui.StudyModel.java

/**
 * Set study model preferences from application preferences.
 * /*from   w ww . j  ava2  s .co m*/
 * @param newPreferences
 */
public void setPreferences(Preferences newPreferences) {
    double currentTemperature = newPreferences.getDouble(OptimizationPreferences.TEMPERATURE_OPT,
            OptimizationPreferences.DEFAULT_TEMPERATURE);
    double currentPressure = newPreferences.getDouble(OptimizationPreferences.PRESSURE_OPT,
            OptimizationPreferences.DEFAULT_PRESSURE);
    int currentHumidity = newPreferences.getInt(OptimizationPreferences.HUMIDITY_OPT,
            OptimizationPreferences.DEFAULT_HUMIDITY);
    int currentCO2 = newPreferences.getInt(OptimizationPreferences.CO2_FRACTION_OPT,
            OptimizationPreferences.DEFAULT_CO2_FRACTION);
    double xCO2 = currentCO2 * 1.0e-6;
    getParams().setProperties(currentTemperature, currentPressure, currentHumidity, xCO2);
    getParams().printProperties();

    String optimizerPreference = newPreferences.get(OptimizationPreferences.OPTIMIZER_TYPE_OPT,
            OptimizationPreferences.OPT_DEFAULT_NAME);
    if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DEFAULT_NAME)) {
        preferredOptimizerType = null;
    } else if (optimizerPreference.contentEquals(OptimizationPreferences.OPT_DIRECT_NAME)) {
        preferredOptimizerType = BaseObjectiveFunction.OptimizerType.DIRECTOptimizer;
    } else {
        preferredOptimizerType = null;
    }
}

From source file:corelyzer.ui.CorelyzerApp.java

public void pingLaunchTracker() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            // load or create unique user ID
            Preferences sysPrefs = Preferences.userNodeForPackage(CorelyzerApp.class);
            String uuid = sysPrefs.get("uuid", null);
            if (uuid == null) {
                uuid = java.util.UUID.randomUUID().toString();
                sysPrefs.put("uuid", uuid);
            }/* w w  w .j av a 2 s .c o  m*/

            // track launch
            GoogleAnalytics ga = new GoogleAnalytics("UA-88247383-1");
            GoogleAnalyticsResponse response = ga
                    .post(new PageViewHit("http://www.laccore.org", "launch: UUID=" + uuid));
            //            for (NameValuePair kvp : response.getPostedParms()) {
            //               System.out.println("key: " + kvp.getName() + ", value: "+ kvp.getValue());
            //            }
        }
    });
}

From source file:org.domainmath.gui.MainFrame.java

public String getSavedCurrentDir() {

    Preferences pr2 = Preferences.userNodeForPackage(this.getClass());
    return pr2.get("DomainMath_CurrentDir", null);

}

From source file:org.domainmath.gui.MainFrame.java

public void loadPackageAuto() {
    Preferences pr2 = Preferences.userNodeForPackage(this.getClass());
    String packageList = pr2.get("DomainMath_Packages", ";");

    StringTokenizer t = new StringTokenizer(packageList, ";");

    while (t.hasMoreTokens()) {
        MainFrame.octavePanel.evaluate("pkg load " + t.nextToken());
    }/*from   w ww .j  a  v  a  2  s  .c  o m*/

}

From source file:org.domainmath.gui.MainFrame.java

public void setDirComboContent() {
    Preferences pr2 = Preferences.userNodeForPackage(this.getClass());
    String s = pr2.get("DomainMath_CurrentDir", "");
    ArrayList<String> l = new ArrayList<>();
    if (s != null) {
        StringTokenizer t = new StringTokenizer(s, File.pathSeparator);
        while (t.hasMoreTokens()) {

            // System.out.println(t.nextToken());
            l.add(t.nextToken());//from  w ww . j  a v a2 s .  c  om

        }
        System.out.println("Open:" + l);

        File _f;
        for (String st : l) {
            _f = new File(st);
            if (_f.exists()) {
                addDirList(st);
            }
        }
        if (worksDir.exists()) {
            addDirList(worksDir.getAbsolutePath());
            cd(worksDir.getAbsolutePath());
        } else {
            worksDir.mkdir();
            addDirList(worksDir.getAbsolutePath());
            cd(worksDir.getAbsolutePath());
        }

    }
    //    else{
    //        addDirList(worksDir.getAbsolutePath());
    //    }

}

From source file:org.domainmath.gui.MainFrame.java

/**
 * Creates Reference menus/*from w  w  w . j  a  va  2  s.  c  o m*/
 */
public void makeMenu() {
    try {
        Preferences pr = Preferences.userNodeForPackage(this.getClass());
        StringTokenizer t = new StringTokenizer(pr.get("Ref_list", null), "=;");

        while (t.hasMoreTokens()) {
            referenceMenu.add(new DocumentAction(t.nextToken(), t.nextToken()));
        }
    } catch (Exception ex) {
    }
}

From source file:org.domainmath.gui.MainFrame.java

/** 
 * Creates new form MainFrame.//from  w  ww . j  a  v a 2  s  . c o m
 * @param args
 */
public MainFrame(String args[]) {

    // create folders called cache and log.
    cache = new File(System.getProperty("user.dir") + File.separator + "cache");
    logDir = new File(System.getProperty("user.dir") + File.separator + "log");
    worksDir = new File(System.getProperty("user.dir") + File.separator + "works");
    cache.mkdir();
    logDir.mkdir();

    if (!worksDir.exists()) {
        worksDir.mkdir();
    }

    parent_root = cache.getAbsolutePath() + File.separator;
    log_root = logDir.getAbsolutePath() + File.separator;
    preferencesDlg = new PreferencesDlg(this, true);
    layout_file = new File(System.getProperty("user.dir") + File.separator + "layout.ini");
    initComponents();
    new PackageLoader(this);
    new ToolsLoader(this);
    makeMenu();

    setIconImage(icon);
    Preferences pr2 = Preferences.userNodeForPackage(this.getClass());

    setSize(pr2.getInt("Frame_width", 800), pr2.getInt("Frame_height", 600));
    setLocationRelativeTo(null);

    FILE_TAB_INDEX = 0;

    //create octavepanel.
    octavePanel = new OctavePanel(this);
    commandArea = octavePanel.commandArea;

    octavePath = preferencesDlg.getPath();
    startupCmd = preferencesDlg.getStartupCmd();
    wantedToClearText = preferencesDlg.wantedToClearText();
    cmdLineOptions = preferencesDlg.getCmdLineOptions();

    // set up histroy widget.
    histArea = new RSyntaxTextArea();
    histArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_OCTAVE);
    histScrollPane = new RTextScrollPane(histArea);
    histScrollPane.setWheelScrollingEnabled(true);

    workspace = new WorkspacePanel(parent_root + "DomainMath_OctaveVariables.dat", this);
    dbstackPanel = new DbstackPanel(parent_root + "DomainMath_OctaveDbStack.dat", this);

    // create recent files menu.
    recentFileMenu = new RecentFileMenu("RecentFiles", MAX_NUM_RECENT_FILES) {
        @Override
        public void onSelectFile(String filePath, ActionEvent action_event) {
            onRecentFile(filePath, action_event);
        }
    };
    this.fileMenu.add(recentFileMenu, MainFrame.RECENT_MENU_ORDER);

    statusPanel = new StatusPanel();
    fileTab.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    fileTreePanel = new FileTreePanel(this);
    quickHelpPanel = new QuickHelpPanel();
    pathPanel = new PathsPanel(parent_root + "DomainMath_OctavePaths.dat");
    pkgViewPanel = new PkgViewPanel(parent_root + "DomainMath_OctavePackages.dat", this);

    histPanel();
    this.popupTab();

    dir = pr2.get("DomainMath_StartUpDir", System.getProperty("user.dir"));

    if (dir.equals(worksDir.getAbsolutePath())) {
        startupDir = dir;
    } else {
        startupDir = worksDir.getAbsolutePath();
    }

    currentDirFileTab = null;
    fileTabView = new View("Code Editor", null, fileTab);
    pathsView = new View("Set Paths", null, pathPanel);
    pkgView = new View("Packages", null, pkgViewPanel);
    consoleScrollPane = new JScrollPane();
    consoleScrollPane.getVerticalScrollBar().setUnitIncrement(16);
    consoleScrollPane.setViewportView(octavePanel);
    consoleView = new View("Console", null, consoleScrollPane);
    arrayEditorView = new View("Array Editor", null, new ArrayEditorPanel());
    workspaceView = new View("Workspace", null, workspace);
    debuggerView = new View("Debugger", null, this.dbstackPanel);
    filesView = new View("Files", null, fileTreePanel);
    quickHelpView = new View("Quick Help", null, quickHelpPanel);
    createRootWindow();
    setDefaultLayout();

    add(rootWindow, BorderLayout.CENTER);
    add(statusPanel, BorderLayout.PAGE_END);
    dragNDrop();
    debugMarksList = new ArrayList<>();
    breakPointMarksList = new ArrayList<>();
    breakPointList = new ArrayList<>();
    fileTab2 = fileTab;
    if (args != null) {
        openStartUpFiles(args);
    }

}

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

@Deprecated
private void restoreSelectedSearchFilterFromPreferences(Preferences prefs) {
    // restore search filter:
    final String sFilterName = prefs.get(PREFS_KEY_FILTERNAME, null);
    if (sFilterName == null)
        selectDefaultFilter();//  w w  w .ja va  2s . co m
    else
        // find filter by name:
        for (int i = 1; i < getSearchFilterComboBox().getItemCount(); ++i)
            if (((SearchFilter) getSearchFilterComboBox().getItemAt(i)).getName().equals(sFilterName)) {
                getSearchFilterComboBox().setSelectedIndex(i);
                break;
            }
}

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

@Deprecated
private void restoreSelectedSearchResultTemplateFromPreferences(Preferences prefs) {
    // restore search result template:
    final String sTemplateName = prefs.get(PREFS_KEY_SEARCHRESULTTEMPLATENAME, null);
    if (sTemplateName == null)
        searchResultTemplatesController.selectDefaultTemplate();
    else/* w  w w  .ja  v  a  2  s  .  c  o m*/
        // find search result template by name:
        searchResultTemplatesController.setSelectedSearchResultTemplate(sTemplateName);
}