當前位置: 首頁>>代碼示例>>Java>>正文


Java Preferences類代碼示例

本文整理匯總了Java中java.util.prefs.Preferences的典型用法代碼示例。如果您正苦於以下問題:Java Preferences類的具體用法?Java Preferences怎麽用?Java Preferences使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Preferences類屬於java.util.prefs包,在下文中一共展示了Preferences類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: storeProfilingSettings

import java.util.prefs.Preferences; //導入依賴的package包/類
private void storeProfilingSettings(ProfilingSettings settings) {
    Preferences pref = getPreferences();
    
    pref.putInt(ProfilingSettings.PROP_SAMPLING_FREQUENCY, settings.getSamplingFrequency());
    pref.putInt(ProfilingSettings.PROP_CPU_PROFILING_TYPE, settings.getCPUProfilingType());
    pref.putInt(ProfilingSettings.PROP_SAMPLING_INTERVAL, settings.getSamplingInterval());
    pref.putBoolean(ProfilingSettings.PROP_EXCLUDE_WAIT_TIME, settings.getExcludeWaitTime());
    pref.putBoolean(ProfilingSettings.PROP_INSTRUMENT_SPAWNED_THREADS, settings.getInstrumentSpawnedThreads());
    pref.putInt(ProfilingSettings.PROP_N_PROFILED_THREADS_LIMIT, settings.getNProfiledThreadsLimit());
    pref.putInt(ProfilingSettings.PROP_INSTR_SCHEME, settings.getInstrScheme());
    pref.putBoolean(ProfilingSettings.PROP_INSTRUMENT_METHOD_INVOKE, settings.getInstrumentMethodInvoke());
    pref.putBoolean(ProfilingSettings.PROP_INSTRUMENT_GETTER_SETTER_METHODS, settings.getInstrumentGetterSetterMethods());
    pref.putBoolean(ProfilingSettings.PROP_INSTRUMENT_EMPTY_METHODS, settings.getInstrumentEmptyMethods());
    
    pref.putInt(ProfilingSettings.PROP_OBJ_ALLOC_STACK_SAMPLING_INTERVAL, settings.getAllocTrackEvery());
    pref.putBoolean(ProfilingSettings.PROP_RUN_GC_ON_GET_RESULTS_IN_MEMORY_PROFILING, settings.getRunGCOnGetResultsInMemoryProfiling());
    
    pref.putBoolean(ProfilingSettings.PROP_THREADS_SAMPLING_ENABLED, settings.getThreadsSamplingEnabled());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ProfilerIDESettings.java

示例2: checkContains

import java.util.prefs.Preferences; //導入依賴的package包/類
private void checkContains(Preferences prefs, String[] tree, String prefsId) throws BackingStoreException {
    for(String s : tree) {
        int equalIdx = s.lastIndexOf('=');
        assertTrue(equalIdx != -1);
        String value = s.substring(equalIdx + 1);

        String key;
        String nodePath;
        int slashIdx = s.lastIndexOf('/', equalIdx);
        if (slashIdx != -1) {
            key = s.substring(slashIdx + 1, equalIdx);
            nodePath = s.substring(0, slashIdx);
        } else {
            key = s.substring(0, equalIdx);
            nodePath = "";
        }

        assertTrue(prefsId + " doesn't contain node '" + nodePath + "'", prefs.nodeExists(nodePath));
        Preferences node = prefs.node(nodePath);

        String realValue = node.get(key, null);
        assertNotNull(prefsId + ", '" + nodePath + "' node doesn't contain key '" + key + "'", realValue);
        assertEquals(prefsId + ", '" + nodePath + "' node, '" + key + "' contains wrong value", value, realValue);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ProxyPreferencesImplTest.java

示例3: setImages

import java.util.prefs.Preferences; //導入依賴的package包/類
private void setImages() {
    Preferences preferences = Preferences.userNodeForPackage(Player.class);

    volDown.setGraphic(volDownImage);
    volUp.setGraphic(volUpImage);
    previous.setGraphic(previousImage);
    play.setGraphic(playImage);
    next.setGraphic(nextImage);

    final boolean isShuffleMode = preferences.getBoolean("ShuffleMode", false);
    shuffle.setGraphic(isShuffleMode ? shufflePressedImage : shuffleImage);

    final boolean isLoopMode = preferences.getBoolean("LoopMode", false);
    loop.setGraphic(isLoopMode ? loopPressedImage: loopImage);

    volSlider.valueChangingProperty().addListener(rootController.volumeUpdated(volSlider));
}
 
開發者ID:jakemanning,項目名稱:boomer-tuner,代碼行數:18,代碼來源:RootView.java

示例4: promptToDelete

import java.util.prefs.Preferences; //導入依賴的package包/類
private boolean promptToDelete(Preferences prefs) {
    Object result = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation(
            NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.msg_clear_keys"),
            NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.title_clear_keys"),
            NotifyDescriptor.OK_CANCEL_OPTION));
    if (result == NotifyDescriptor.OK_OPTION) {
        try {
            LOG.log(Level.FINE, "agreed to delete stored passwords: {0}", Arrays.asList(prefs.keys()));
            prefs.clear();
            return testSampleKey(prefs);
        } catch (BackingStoreException x) {
            LOG.log(Level.INFO, null, x);
        }
    } else {
        LOG.fine("refused to delete stored passwords");
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:FallbackProvider.java

示例5: storeListData

import java.util.prefs.Preferences; //導入依賴的package包/類
@Override
protected void storeListData(final JList list, final String optionID, final Preferences node) {
    StringBuilder sb = null;
    for (int i = 0; i < list.getModel().getSize(); i++) {
        if (sb == null) {
            sb = new StringBuilder();
        } else {
            sb.append(';');
        }
        if (classMembersOrder.equals(optionID)) {
            Element e = (Element) list.getModel().getElementAt(i);
            if (e.isStatic)
                sb.append("STATIC "); //NOI18N
            sb.append(e.kind.name());
        } else {
            Visibility v = (Visibility) list.getModel().getElementAt(i);
            sb.append(v.kind);
        }
    }
    String value = sb != null ? sb.toString() : ""; //NOI18N
    if (getDefaultAsString(optionID).equals(value))
        node.remove(optionID);
    else
        node.put(optionID, value);            
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:FmtCodeGeneration.java

示例6: generateRow

import java.util.prefs.Preferences; //導入依賴的package包/類
private void generateRow(int rowIndex) {
    Preferences prefs = userRoot().node("General");
    if (!prefs.getBoolean("generate", true))
        return;
    assert (rowIndex < proofData.size());
    ProofRow row = proofData.getRow(rowIndex);
    Rule rule = row.getRule();
    if (rule == null || rule.hasCompleteInfo() == false || row.getFormula() != null) {
        return;
    }
    Formula generated = null;
    try {
        generated = rule.generateFormula(proofData, rowIndex);
    } catch (VerificationInputException e) {
        return;
    }
    if (generated == null)
        return;
    row.setFormula(generated);
    for (ProofListener listener : this.listeners) {
        listener.rowUpdated(generated.toString(), true, rowIndex + 1);
    }
}
 
開發者ID:nonilole,項目名稱:Conan,代碼行數:24,代碼來源:Proof.java

示例7: initProjectPreferences

import java.util.prefs.Preferences; //導入依賴的package包/類
private void initProjectPreferences(final FileObject file) {
    ProjectManager.mutex().postReadRequest(new Runnable() {
        public @Override void run() {
            Preferences projectRoot = findProjectPreferences(file);
            if (projectRoot != null) {
                synchronized (Csp.this) {
                    Preferences allLangCodeStyle = projectRoot.node(NODE_CODE_STYLE);
                    Preferences p = allLangCodeStyle.node(PROJECT_PROFILE);

                    // determine if we are using code style preferences from the project
                    String usedProfile = allLangCodeStyle.get(PROP_USED_PROFILE, DEFAULT_PROFILE);
                    useProject = PROJECT_PROFILE.equals(usedProfile);
                    projectPrefs = Csp.this.mimeType == null ?
                        p :
                        new ProxyPreferences(projectRoot.node(Csp.this.mimeType).node(NODE_CODE_STYLE).node(PROJECT_PROFILE), p);

                    // listen on changes
                    allLangCodeStyle.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, switchTrakcer, allLangCodeStyle));
                }
            }
        }
    });
    LOG.fine("file '" + filePath + "' (" + mimeType + ") is using " + (useProject ? "project" : "global") + " Preferences; doc=" + s2s(refDoc == null ? null : refDoc.get())); //NOI18N
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ProjectAwareCodeStylePreferences.java

示例8: testInheritedEventsMasked

import java.util.prefs.Preferences; //導入依賴的package包/類
/** 
 * Checks that modifications to the ihnerited store are not fired if
 * the local store overrides
 */
public void testInheritedEventsMasked() throws Exception {
    Preferences stored = new MapPreferences();
    Preferences inherited = new MapPreferences();
    
    inherited.putInt("intValue", 100);
    stored.putInt("intValue", 10);

    MemoryPreferences mem = MemoryPreferences.getWithInherited(this, inherited, stored);
    Preferences test = mem.getPreferences();
    
    PL pl = new PL();
    test.addPreferenceChangeListener(pl);
    
    // change
    pl.arm();
    inherited.putInt("intValue", 3);
    pl.waitEvent();
    assertEquals(0, pl.changeCount);
    
    // remove not inherited
    pl.arm();
    inherited.remove("intValue");
    pl.waitEvent();
    assertEquals(0, pl.changeCount);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:ProxyPreferencesImplTest.java

示例9: createBooleanOption

import java.util.prefs.Preferences; //導入依賴的package包/類
private JComponent createBooleanOption(OptionDescriptor option, Preferences prefs)  {
    JCheckBox checkBox = new JCheckBox();

    org.openide.awt.Mnemonics.setLocalizedText(checkBox, option.displayName);
    checkBox.setToolTipText(option.tooltip);
    checkBox.addActionListener(new ActionListenerImpl(option.preferencesKey, prefs));

    checkBox.setSelected(prefs.getBoolean(option.preferencesKey, 
            Boolean.TRUE == option.defaultValue));
    prefs.putBoolean(option.preferencesKey, checkBox.isSelected());
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridheight = 1;
    constraints.gridwidth = 2;
    constraints.gridx = 0;
    constraints.gridy = row++;
    constraints.weightx = 0;
    constraints.weighty = 0;

    add(checkBox, constraints);
    return checkBox;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ReflectiveCustomizerProvider.java

示例10: indexerProfileNode

import java.util.prefs.Preferences; //導入依賴的package包/類
private Preferences indexerProfileNode(SourceIndexerFactory srcFactory) {
    String nn = srcFactory.getIndexerName();
    if (nn.length() >= Preferences.MAX_NAME_LENGTH) {
        // such long nodes are constructer e.g. from class names
        int i = nn.lastIndexOf('.');
        if (i >= 0) {
            nn = nn.substring(i + 1);
        }
        if (nn.length() < 3 || nn.length() >= Preferences.MAX_NAME_LENGTH) {
            String hashCode = Integer.toHexString(nn.hashCode());
            // attempt to derive +- unique node name
            nn = srcFactory.getClass().getSimpleName() + "_" + hashCode; // NOI18N
        }
    }
    return NbPreferences.forModule(srcFactory.getClass()).node("RepositoryUpdater"). // NOI18N
            node(nn);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:RepositoryUpdater.java

示例11: getStoredProperties

import java.util.prefs.Preferences; //導入依賴的package包/類
private Properties getStoredProperties() {
    return AccessController
            .doPrivileged((PrivilegedAction<Properties>) () -> {
                Properties p = new Properties();
                String notePath = "/com/sun/media/sound/softsynthesizer";
                try {
                    Preferences prefroot = Preferences.userRoot();
                    if (prefroot.nodeExists(notePath)) {
                        Preferences prefs = prefroot.node(notePath);
                        String[] prefs_keys = prefs.keys();
                        for (String prefs_key : prefs_keys) {
                            String val = prefs.get(prefs_key, null);
                            if (val != null) {
                                p.setProperty(prefs_key, val);
                            }
                        }
                    }
                } catch (final BackingStoreException ignored) {
                }
                return p;
            });
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:SoftSynthesizer.java

示例12: testFlushTree1

import java.util.prefs.Preferences; //導入依賴的package包/類
public void testFlushTree1() throws BackingStoreException {
    String [] origTree = new String [] {
        "CodeStyle/profile=GLOBAL",
    };
    String [] newTree = new String [] {
        "CodeStyle/text/x-java/tab-size=2",
        "CodeStyle/text/x-java/override-global-settings=true",
        "CodeStyle/text/x-java/expand-tabs=true",
        "CodeStyle/profile=PROJECT",
    };

    Preferences orig = Preferences.userRoot().node(getName());
    write(orig, origTree);
    checkContains(orig, origTree, "Orig");
    checkNotContains(orig, newTree, "Orig");
    
    Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig);
    checkEquals("Test should be the same as Orig", orig, test);
    
    write(test, newTree);
    checkContains(test, newTree, "Test");

    test.flush();
    checkEquals("Test didn't flush to Orig", test, orig);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ProxyPreferencesImplTest.java

示例13: SideBar

import java.util.prefs.Preferences; //導入依賴的package包/類
public SideBar(Document forDocument) {
    super(new BorderLayout());
    this.forDocument = forDocument;
    add(new BreadCrumbComponent(), BorderLayout.CENTER);

    JButton closeButton = CloseButtonFactory.createBigCloseButton();

    add(closeButton, BorderLayout.EAST);
    
    prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
    
    closeButton.addActionListener(new ActionListener() {
        @Override public void actionPerformed(ActionEvent e) {
            prefs.putBoolean(KEY_BREADCRUMBS, false);
        }
    });
    
    setBorder(new SeparatorBorder());
    preferenceChange(null);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:SideBarFactoryImpl.java

示例14: CategorySupport

import java.util.prefs.Preferences; //導入依賴的package包/類
protected CategorySupport(Preferences preferences, String id, JPanel panel, String previewText, String[]... forcedOptions) {
    this.preferences = preferences;
    this.id = id;
    this.panel = panel;
    this.previewText = previewText != null ? previewText : NbBundle.getMessage(CategorySupport.class, "SAMPLE_Default"); //NOI18N

    // Scan the panel for its components
    scan(panel, components);

    // Initialize the preview preferences
    Preferences forcedPrefs = new PreviewPreferences();
    for (String[] option : forcedOptions) {
        forcedPrefs.put( option[0], option[1]);
    }
    this.previewPrefs = new ProxyPreferences(forcedPrefs, preferences);

    // Load and hook up all the components
    loadFrom(preferences);
    addListeners();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:CategorySupport.java

示例15: testFieldFix208072d

import java.util.prefs.Preferences; //導入依賴的package包/類
public void testFieldFix208072d() throws Exception {
    Preferences prefs = CodeStylePreferences.get((FileObject) null, JavacParser.MIME_TYPE).getPreferences();
    prefs.put("classMembersOrder", "STATIC_INIT;STATIC METHOD;INSTANCE_INIT;CONSTRUCTOR;METHOD;STATIC CLASS;CLASS;STATIC FIELD;FIELD");
    prefs.put("classMemberInsertionPoint", "LAST_IN_CATEGORY");
    performFixTest("package test;\n" +
                   "import java.util.logging.Level;\n" +
                   "import java.util.logging.Logger;\n" +
                   "public class Test {\n" +
                   "     static {\n" +
                   "         int ii = |1 + 2 * 3|;\n" +
                   "     }\n" +
                   "     private static final int II = 0;\n" +
                   "}\n",
                   ("package test;\n" +
                    "import java.util.logging.Level;\n" +
                    "import java.util.logging.Logger;\n" +
                    "public class Test {\n" +
                   "     private static int ZZ = 1 + 2 * 3;\n" +
                   "     static {\n" +
                   "         int ii = ZZ;\n" +
                   "     }\n" +
                   "     private static final int II = 0;\n" +
                    "}\n").replaceAll("[ \t\n]+", " "),
                   new DialogDisplayerImpl2("ZZ", IntroduceFieldPanel.INIT_FIELD, false, EnumSet.<Modifier>of(Modifier.PRIVATE), false, true),
                   5, 2);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:IntroduceHintTest.java


注:本文中的java.util.prefs.Preferences類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。