java.util.prefs.Preferences Java Examples
The following examples show how to use
java.util.prefs.Preferences.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarginallyCleverPreferencesHelper.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
/** * @param args command line arguments. */ @SuppressWarnings("deprecation") public static void main(String[] args) throws BackingStoreException { final Preferences machinesPreferenceNode = PreferencesHelper.getPreferenceNode(PreferencesHelper.MakelangeloPreferenceKey.MACHINES); Log.message("node name: "+ machinesPreferenceNode.name()); final boolean wereThereCommandLineArguments = args.length > 0; if (wereThereCommandLineArguments) { final boolean wasSaveFileFlagFound = wasSearchKeyFoundInArray(SAVE_FILE_FLAG, args); if (wasSaveFileFlagFound) { final File preferencesFile = MarginallyCleverPreferencesFileFactory.getXmlPreferencesFile(); try (final OutputStream fileOutputStream = new FileOutputStream(preferencesFile)) { PreferencesHelper.getPreferenceNode(PreferencesHelper.MakelangeloPreferenceKey.LEGACY_MAKELANGELO_ROOT).exportSubtree(fileOutputStream); } catch (IOException e) { Log.error(e.getMessage()); } } final boolean wasPurgeFlagFound = wasSearchKeyFoundInArray(PURGE_FLAG, args); if (wasPurgeFlagFound) { final String[] childrenPreferenceNodeNames = machinesPreferenceNode.childrenNames(); purgeMachineNamesThatAreLessThanZero(machinesPreferenceNode, childrenPreferenceNodeNames); } } }
Example #2
Source File: ProjectDefaultHtmlSourceVersionController.java From netbeans with Apache License 2.0 | 6 votes |
private static HtmlVersion findHtmlVersion(Project project, String namespace, boolean xhtml) { Preferences prefs = ProjectUtils.getPreferences(project, HtmlSourceVersionController.class, true); String publicId = prefs.get(getPropertyKey(xhtml), null); if (publicId == null) { return null; } //no-public id versions if(xhtml && publicId.equals(HtmlVersion.XHTML5.name())) { return HtmlVersion.XHTML5; } else if(!xhtml && publicId.equals(HtmlVersion.HTML5.name())) { return HtmlVersion.HTML5; } try { return HtmlVersion.find(publicId, namespace); } catch (IllegalArgumentException e) { //no-op } return null; }
Example #3
Source File: HistorySettings.java From netbeans with Apache License 2.0 | 6 votes |
private static void migrate() { // migrate pre 7.2 settings String prevPath = "org/netbeans/modules/localhistory"; // NOI18N try { if(!NbPreferences.root().nodeExists(prevPath)) { return; } Preferences prev = NbPreferences.root().node(prevPath); Preferences cur = NbPreferences.forModule(HistorySettings.class); String[] keys = prev.keys(); for (String key : keys) { String value = prev.get(key, null); if(value != null && cur.get(key, null) == null) { cur.put(key, value); } } prev.removeNode(); } catch (BackingStoreException ex) { Exceptions.printStackTrace(ex); } }
Example #4
Source File: RepositoryRegistry.java From netbeans with Apache License 2.0 | 6 votes |
private String[] getRepoIds(Preferences preferences, String repoId) { String[] keys = null; try { keys = preferences.keys(); } catch (BackingStoreException ex) { BugtrackingManager.LOG.log(Level.SEVERE, null, ex); } if (keys == null || keys.length == 0) { return new String[0]; } List<String> ret = new ArrayList<String>(); for (String key : keys) { if (key.startsWith(repoId)) { ret.add(key.substring(repoId.length())); } } return ret.toArray(new String[ret.size()]); }
Example #5
Source File: ShapefileAssistantPage1.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setAcceptAllFileFilterUsed(false); final FileNameExtensionFilter shapefileFilter = new FileNameExtensionFilter("ESRI Shapefile", "shp"); fileChooser.addChoosableFileFilter(shapefileFilter); fileChooser.setFileFilter(shapefileFilter); File lastDir = getLastDirectory(); fileChooser.setCurrentDirectory(lastDir); LayerSourcePageContext pageContext = getContext(); fileChooser.showOpenDialog(pageContext.getWindow()); if (fileChooser.getSelectedFile() != null) { String filePath = fileChooser.getSelectedFile().getPath(); fileHistoryModel.setSelectedItem(filePath); Preferences preferences = SnapApp.getDefault().getPreferences(); preferences.put(PROPERTY_LAST_DIR, fileChooser.getCurrentDirectory().getAbsolutePath()); pageContext.updateState(); } }
Example #6
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
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); } }
Example #7
Source File: ApplicationPreferenceKeys.java From constellation with Apache License 2.0 | 6 votes |
/** * A directory where the webserver can write files to emulate REST requests. * * @param prefs Application preferences. * * @return The rest directory. */ public static String getRESTDir(final Preferences prefs) { String restDir = prefs.get(REST_DIR, "").trim(); if (restDir.isEmpty()) { final RestDirectory rdir = Lookup.getDefault().lookup(RestDirectory.class); restDir = rdir.getRESTDirectory().toString(); } final File f = new File(restDir); if (!f.exists()) { if (!f.mkdirs()) { // TODO: warn the user. } } else if (!f.isDirectory()) { // TODO: warn the user. } return restDir; }
Example #8
Source File: TaskFilter.java From netbeans with Apache License 2.0 | 6 votes |
void load( Preferences prefs, String prefix ) throws BackingStoreException { name = prefs.get( prefix+"_name", "Filter" ); //NOI18N //NOI18N if( prefs.getBoolean( prefix+"_types", false ) ) { //NOI18N types = new TypesFilter(); types.load( prefs, prefix+"_types" ); //NOI18N } else { types = null; } if( prefs.getBoolean( prefix+"_keywords", false ) ) { //NOI18N keywords = new KeywordsFilter(); keywords.load( prefs, prefix+"_keywords" ); //NOI18N } else { keywords = null; } }
Example #9
Source File: Whyline.java From whyline with MIT License | 6 votes |
private static String loadPreferences() { UI.class.getName(); // Load the preferences, if there are any. Preferences userPrefs = getPreferences(); // If no preference is set, use the current working directory. String WHYLINE_HOME = userPrefs.get(WHYLINE_HOME_PATH_KEY, System.getProperty("user.dir") + File.separatorChar + "whyline" + File.separatorChar); // Now store the preference, in case it wasn't stored before userPrefs.put(WHYLINE_HOME_PATH_KEY, WHYLINE_HOME); try { userPrefs.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } return WHYLINE_HOME; }
Example #10
Source File: MarkOccurencesPanel.java From netbeans with Apache License 2.0 | 6 votes |
public void store( ) { Preferences node = MarkOccurencesSettings.getCurrentNode(); for (javax.swing.JCheckBox box : boxes) { boolean value = box.isSelected(); boolean original = node.getBoolean(box.getActionCommand(), DEFAULT_VALUE); if (value != original) { node.putBoolean(box.getActionCommand(), value); } } try { node.flush(); } catch (BackingStoreException ex) { Exceptions.printStackTrace(ex); } changed = false; }
Example #11
Source File: ProjectHintSettingPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void settingsFileLocationChanged() { if (projectSettings.hasLocation()) { final ToolPreferences toolPreferencesFin = toolPreferences = projectSettings.preferencesFrom(settingsFileLocation); perProjectPreferences = new MimeType2Preferences() { @Override public Preferences getPreferences(String mimeType) { return toolPreferencesFin.getPreferences(ProjectSettings.HINTS_TOOL_ID, mimeType); } }; } else { perProjectPreferences = new MimeType2Preferences() { @Override public Preferences getPreferences(String mimeType) { return projectSettings.getProjectSettings(mimeType); } }; } }
Example #12
Source File: PreferencesDialog.java From halfnes with GNU General Public License v3.0 | 6 votes |
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed // if ("OK".equals(evt.getActionCommand())) { //here we go... save everything and hide the window Preferences prefs = PrefsSingleton.get(); prefs.putBoolean("soundEnable", jCheckSoundEnable.isSelected()); prefs.putBoolean("soundFiltering", jCheckSoundFiltering.isSelected()); prefs.putBoolean("maintainAspect", jCheckMaintainAspect.isSelected()); prefs.putBoolean("TVEmulation", jCheckBoxNTSC.isSelected()); prefs.putBoolean("Sleep", jCheckBoxSleep.isSelected()); screenScaling = (Integer) (jSpinnerScale.getModel().getValue()); prefs.putBoolean("smoothScaling", jCheckBoxSmoothVideo.isSelected()); prefs.putBoolean("showScope", jCheckBoxShowScope.isSelected()); prefs.putBoolean("ntView", jCheckBoxNTView.isSelected()); prefs.putInt("screenScaling", screenScaling); prefs.putInt("sampleRate", Integer.parseInt(jSampleRateBox.getSelectedItem().toString())); prefs.putInt("outputvol", volumeSlider.getValue()); prefs.putInt("region", jRegionBox.getSelectedIndex()); try { prefs.flush(); } catch (BackingStoreException ex) { Logger.getLogger(PreferencesDialog.class.getName()).log(Level.SEVERE, null, ex); } okClicked = true; this.setVisible(false); // } }
Example #13
Source File: EndmemberFormModel.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void ensureDefaultDirSet() { if (!Files.exists(defaultEndmemberDir)) { Path sourceDirPath = ResourceInstaller.findModuleCodeBasePath(SpectralUnmixingDialog.class).resolve("auxdata"); final ResourceInstaller resourceInstaller = new ResourceInstaller(sourceDirPath, defaultEndmemberDir); try { resourceInstaller.install(".*", com.bc.ceres.core.ProgressMonitor.NULL); } catch (IOException e) { // failed, so what } } final String key = DiagramGraphIO.DIAGRAM_GRAPH_IO_LAST_DIR_KEY; final Preferences preferences = Config.instance().preferences(); if (preferences.get(key, null) == null) { preferences.put(key, defaultEndmemberDir.toAbsolutePath().toString()); } }
Example #14
Source File: CodeStyleOperation.java From editorconfig-netbeans with MIT License | 6 votes |
protected boolean operate(String simpleValueName, boolean value) { boolean codeStyleChangeNeeded = false; Preferences codeStyle = CodeStylePreferences.get(file, file.getMIMEType()).getPreferences(); boolean currentValue = codeStyle.getBoolean(simpleValueName, false); LOG.log(Level.INFO, "\u00ac Current value: {0}", currentValue); LOG.log(Level.INFO, "\u00ac New value: {0}", value); if (currentValue == value) { LOG.log(Level.INFO, "\u00ac No change needed"); } else { codeStyle.putBoolean(simpleValueName, value); codeStyleChangeNeeded = true; LOG.log(Level.INFO, "\u00ac Changing value from \"{0}\" to \"{1}\"", new Object[]{currentValue, value}); } return codeStyleChangeNeeded; }
Example #15
Source File: ProxyPreferencesTest.java From netbeans with Apache License 2.0 | 6 votes |
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); } }
Example #16
Source File: ExecutableInputMethodManager.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void writePreferredInputMethod(String path, String descriptorName) { if (userRoot != null) { Preferences node = userRoot.node(path); // record it if (descriptorName != null) { node.put(descriptorKey, descriptorName); } else { node.remove(descriptorKey); } } }
Example #17
Source File: CategorySupport.java From netbeans with Apache License 2.0 | 5 votes |
protected String[] keysSpi() throws BackingStoreException { Set<String> keys = new HashSet<String>(); for(Preferences p : delegates) { keys.addAll(Arrays.asList(p.keys())); } return keys.toArray(new String[ keys.size() ]); }
Example #18
Source File: JavadocHint.java From netbeans with Apache License 2.0 | 5 votes |
@Hint(id = "error-in-javadoc", category = "JavaDoc", description = "#DESC_ERROR_IN_JAVADOC_HINT", displayName = "#DN_ERROR_IN_JAVADOC_HINT", hintKind = Hint.Kind.INSPECTION, severity = Severity.WARNING, customizerProvider = JavadocHint.CustomizerProviderImplError.class) @TriggerTreeKind({Kind.METHOD, Kind.ANNOTATION_TYPE, Kind.CLASS, Kind.ENUM, Kind.INTERFACE, Kind.VARIABLE}) public static List<ErrorDescription> errorHint(final HintContext ctx) { Preferences pref = ctx.getPreferences(); boolean correctJavadocForNonPublic = pref.getBoolean(AVAILABILITY_KEY + false, false); CompilationInfo javac = ctx.getInfo(); Boolean publiclyAccessible = AccessibilityQuery.isPubliclyAccessible(javac.getFileObject().getParent()); boolean isPubliclyA11e = publiclyAccessible == null ? true : publiclyAccessible; if (!isPubliclyA11e && !correctJavadocForNonPublic) { return null; } if (javac.getElements().getTypeElement("java.lang.Object") == null) { // NOI18N // broken java platform return Collections.<ErrorDescription>emptyList(); } TreePath path = ctx.getPath(); { Document doc = null; try { doc = javac.getDocument(); } catch (IOException e) { Exceptions.printStackTrace(e); } if (doc != null && isGuarded(path.getLeaf(), javac, doc)) { return null; } } Access access = Access.resolve(pref.get(SCOPE_KEY, SCOPE_DEFAULT)); Analyzer a = new Analyzer(javac, path, access, ctx); return a.analyze(); }
Example #19
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if( errorTree.getSelectionPath() == null ) return; Object o = getUserObject(errorTree.getSelectionPath()); if ( o instanceof POMErrorFixBase ) { POMErrorFixBase hint = (POMErrorFixBase) o; Preferences p = getPreferences4Modification(hint); if(hint.getConfiguration().getSeverity(p) != null && severityComboBox.equals( e.getSource() ) ) hint.getConfiguration().setSeverity(p, index2severity(severityComboBox.getSelectedIndex())); } }
Example #20
Source File: DisplayPrefs.java From openccg with GNU Lesser General Public License v2.1 | 5 votes |
/** Constructor sets initial prefs from current user prefs. */ public DisplayPrefs() { Preferences prefs = Preferences.userNodeForPackage(TextCCG.class); showFeats = prefs.getBoolean(TextCCG.SHOW_FEATURES, false); showSem = prefs.getBoolean(TextCCG.SHOW_SEMANTICS, false); featsToShow = prefs.get(TextCCG.FEATURES_TO_SHOW, ""); }
Example #21
Source File: InputContext.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example #22
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSyncTree1() 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.sync(); checkContains(orig, origTree, "Orig"); checkNotContains(orig, newTree, "Orig"); checkContains(test, origTree, "Test"); checkNotContains(test, newTree, "Test"); }
Example #23
Source File: SQLHistoryDlg.java From bigtable-sql with Apache License 2.0 | 5 votes |
private void onWindowClosed() { Dimension size = getSize(); Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_WIDTH, size.width); Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_HEIGHT, size.height); Preferences.userRoot().putInt(PREF_KEY_SQL_HISTORY_DLG_DIV_LOC, splSpilt.getDividerLocation()); }
Example #24
Source File: PrefMonitorInt.java From Logisim with GNU General Public License v3.0 | 5 votes |
PrefMonitorInt(String name, int dflt) { super(name); this.dflt = dflt; this.value = dflt; Preferences prefs = AppPreferences.getPrefs(); set(Integer.valueOf(prefs.getInt(name, dflt))); prefs.addPreferenceChangeListener(this); }
Example #25
Source File: SearchDependencyCustomizer.java From netbeans with Apache License 2.0 | 5 votes |
/** Creates new form SearchDependencyCustomizer */ public SearchDependencyCustomizer(Preferences p) { this.p = p; initComponents(); boolean b = p.getBoolean(SearchClassDependencyHint.OPTION_DIALOG, true); if (b) { jrOptionDialog.setSelected(true); }else{ jrOptionInplace.setSelected(true); } p.putBoolean(SearchClassDependencyHint.OPTION_DIALOG, jrOptionDialog.isSelected()); }
Example #26
Source File: ShellOptions.java From netbeans with Apache License 2.0 | 5 votes |
private Preferences prefs() { if (prefs != null) { return prefs; } prefs = NbPreferences.forModule(ShellOptions.class); return prefs; }
Example #27
Source File: ReporterPreferencesManager.java From nextreports-designer with Apache License 2.0 | 5 votes |
public Rectangle loadBoundsForWindow(Class cls) { if (userName == null) { throw new IllegalStateException(NO_USERNAME_MSG); } Preferences prefs = Preferences.userNodeForPackage(cls).node(userName); return (Rectangle) bytes2Object(prefs.getByteArray(getKey(cls, BOUNDS_KEY), null)); }
Example #28
Source File: PreferencesTest.java From netbeans with Apache License 2.0 | 5 votes |
@RandomlyFails public void testEvents142723() throws Exception { Preferences prefsA = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class); Preferences prefsB = MimeLookup.getLookup(MimePath.parse("text/x-testA")).lookup(Preferences.class); String key1 = "all-lang-key-" + getName(); prefsA.put(key1, "xyz"); assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null)); // attach listeners L listenerA = new L(); prefsA.addPreferenceChangeListener(listenerA); L listenerB = new L(); prefsB.addPreferenceChangeListener(listenerB); // putting the same value again should not fire an event prefsA.put(key1, "xyz"); assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null)); assertEquals("There should be no events from prefsA", 0, listenerA.count); assertEquals("'" + key1 + "' should inherit the value", "xyz", prefsB.get(key1, null)); assertEquals("There should be no events from prefsB", 0, listenerB.count); // putting the same value again should not fire an event prefsB.put(key1, "xyz"); assertEquals("'" + key1 + "' has wrong value in prefsB", "xyz", prefsB.get(key1, null)); assertEquals("There should still be no events from prefsB", 0, listenerB.count); }
Example #29
Source File: ReindenterTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testLineIndentationBeforeHalfIndentedDoWhileBlock() throws Exception { Preferences preferences = MimeLookup.getLookup(JavaTokenId.language().mimeType()).lookup(Preferences.class); preferences.put("otherBracePlacement", CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name()); try { performLineIndentationTest("package t;\npublic class T {\n public void op() {\n do\n| {\n }\n}\n", "package t;\npublic class T {\n public void op() {\n do\n {\n }\n}\n"); } finally { preferences.remove("otherBracePlacement"); } }
Example #30
Source File: HugoPane.java From Lipi with MIT License | 5 votes |
public HugoPane() { super(); bindFxml(); setupGui(); String autoOpen = Preferences.userNodeForPackage(view.wizard.WelcomeWizard.class).get("auto_open", "false"); if (autoOpen.equals("true")) { autoOpenCheckBox.setSelected(true); } }