Java Code Examples for java.util.prefs.Preferences#get()

The following examples show how to use java.util.prefs.Preferences#get() . 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: RequireJsPreferences.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static String get(final Project project, Property<? extends Object> property) {
    if (project == null) {
        return null;
    }
    Preferences preferences = getPreferences(project);
    // get default value lazyly since it can do anything...
    String value = preferences.get(property.getKey(), DEFAULT_VALUE);
    if (DEFAULT_VALUE.equals(value)) {
        Object defaultValue = property.getDefaultValue();
        if (defaultValue == null) {
            return null;
        }
        return defaultValue.toString();
    }
    if (!StringUtils.hasText(value)) {
        return null;
    }
    return value;
}
 
Example 2
Source File: SourceJavadocByHash.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static @CheckForNull File[] find(@NonNull URL root, boolean javadoc) {
    String k = root.toString();
    Preferences n = node(javadoc);
    String v = n.get(k, null);
    if (v == null) {
        return null;
    }
    String[] split = StringUtils.split(v, "||");
    List<File> toRet = new ArrayList<File>();
    for (String vv : split) {
        File f = FileUtilities.convertStringToFile(vv);
        if (f.isFile()) {
            toRet.add(f);
        } else {
            //what do we do when one of the possibly more files is gone?
            //in most cases we are dealing with exactly one file, so keep the
            //previous behaviour of removing it.
            n.remove(k);
        }
    }
    return toRet.toArray(new File[0]);
}
 
Example 3
Source File: PreferencesPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
public void load(@Nonnull final Preferences preferences) {
  this.config.loadFrom(preferences);
  loadFrom(this.config, preferences);
  this.changeNotificationAllowed = false;
  try {
    // Common behaviour options
    this.checkBoxShowHiddenFiles.setSelected(preferences.getBoolean("showHiddenFiles", true)); //NOI18N
    this.checkboxTrimTopicText.setSelected(preferences.getBoolean("trimTopicText", false)); //NOI18N
    this.checkboxUseInsideBrowser.setSelected(preferences.getBoolean("useInsideBrowser", false)); //NOI18N
    this.checkboxRelativePathsForFilesInTheProject.setSelected(preferences.getBoolean("makeRelativePathToProject", true)); //NOI18N
    this.checkBoxUnfoldCollapsedTarget.setSelected(preferences.getBoolean("unfoldCollapsedTarget", true)); //NOI18N
    this.checkBoxCopyColorInfoToNewAllowed.setSelected(preferences.getBoolean("copyColorInfoToNewChildAllowed", true)); //NOI18N
    this.checkBoxKnowledgeFolderAutogenerationAllowed.setSelected(preferences.getBoolean(PREFERENCE_KEY_KNOWLEDGEFOLDER_ALLOWED, false));

    // third part options
    final String pathToGraphViz = preferences.get("plantuml.dotpath", null);
    this.textFieldPathToGraphvizDot.setText(pathToGraphViz == null ? "" : pathToGraphViz);

    // Metrics
    this.checkboxMetricsAllowed.setSelected(MetricsService.getInstance().isEnabled());
  } finally {
    this.changeNotificationAllowed = true;
  }
}
 
Example 4
Source File: ProxyPreferencesImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 5
Source File: CheckUserPrefLater.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
    String result = prefs.get("Check", null);
    if ((result == null) || !(result.equals("Success")))
        throw new RuntimeException("User pref not stored!");
    prefs.remove("Check");
    prefs.flush();
}
 
Example 6
Source File: OptionRecorder.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
private static FE4OptionBundle loadFE4Options() {
	Preferences prefs = Preferences.userRoot().node(OptionRecorder.class.getName());
	String jsonString = prefs.get(SettingsKey + FE4Suffix, null);
	if (jsonString != null) {
		Gson gson = new Gson();
		FE4OptionBundle loadedOptions = gson.fromJson(jsonString, FE4OptionBundle.class);
		return FE4OptionBundleVersion != loadedOptions.version ? null : loadedOptions;
	}
	
	return null;
}
 
Example 7
Source File: BrowseButton.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    Preferences prefs = Preferences.userRoot().node(Fawe.class.getName());
    String lastUsed = prefs.get("LAST_USED_FOLDER", null);
    final File lastFile = lastUsed == null ? null : new File(lastUsed).getParentFile();
    browse(lastFile);
}
 
Example 8
Source File: Setting.java    From amidst with GNU General Public License v3.0 5 votes vote down vote up
public static <T extends Enum<T>> Setting<T> createEnum(Preferences preferences, String key, T defaultValue) {
	Class<T> enumType = defaultValue.getDeclaringClass();
	return new SettingBase<>(defaultValue, value -> {
		String stored = preferences.get(key, null);
		try {
			return stored == null ? value : Enum.valueOf(enumType, stored);
		} catch (IllegalArgumentException e) {
			return value;
		}
	}, value -> preferences.put(key, value.name()));
}
 
Example 9
Source File: DefaultGuiBridgeImpl.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
@Override
public HashMap<String, String> getSpatialToolboxPreferencesMap() {
    Preferences preferences = Preferences.userRoot().node(PreferencesHandler.PREFS_NODE_NAME);
    String debug = preferences.get(DEBUG_KEY, "false");
    String heap = preferences.get(HEAP_KEY, "64");

    HashMap<String, String> prefsMap = new HashMap<>();
    prefsMap.put(DEBUG_KEY, debug);
    prefsMap.put(HEAP_KEY, heap);

    return prefsMap;
}
 
Example 10
Source File: UserPreferences.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Restores the window size, position and state if possible. Tracks the
 * window size, position and state.
 * 
 * @param window
 */
public static void track(Window window) {
  Preferences prefs = node().node("Windows");

  String bounds = prefs.get(window.getName() + ".bounds", null);
  if (bounds != null) {
    Rectangle rect =
      (Rectangle)ConverterRegistry.instance().convert(
        Rectangle.class,
        bounds);
    window.setBounds(rect);
  }

  window.addComponentListener(windowDimension);
}
 
Example 11
Source File: PreferencesHandler.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle the last set path preference.
 * 
 * @return the last set path or the user home.
 */
public static File getLastFile() {
    Preferences preferences = Preferences.userRoot().node(PREFS_NODE_NAME);

    String userHome = System.getProperty("user.home");
    String lastPath = preferences.get(LAST_PATH, userHome);
    File file = new File(lastPath);
    if (!file.exists()) {
        return new File(userHome);
    }
    return file;
}
 
Example 12
Source File: RunUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Pair<String, JavaPlatform> getActivePlatform(Project project) {
    Preferences prefs = NbGradleProject.getPreferences(project, false);
    String platformId = prefs.get(PROP_JDK_PLATFORM, null);
    if (platformId == null) {
        GradleBaseProject gbp = GradleBaseProject.get(project);
        platformId = gbp != null ? gbp.getNetBeansProperty(PROP_JDK_PLATFORM) : null;
    }
    return getActivePlatform(platformId);
}
 
Example 13
Source File: DisplayPrefs.java    From openccg with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** 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 14
Source File: CheckUserPrefLater.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
    String result = prefs.get("Check", null);
    if ((result == null) || !(result.equals("Success")))
        throw new RuntimeException("User pref not stored!");
    prefs.remove("Check");
    prefs.flush();
}
 
Example 15
Source File: NotificationFilter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void load(Preferences prefs, String prefix) throws BackingStoreException {
    name = prefs.get(prefix + "_name", "Filter"); //NOI18N //NOI18N
    if (prefs.getBoolean(prefix + "_types", false)) { //NOI18N
        categoryFilter = new CategoryFilter();
        categoryFilter.load(prefs, prefix + "_types"); //NOI18N
    } else {
        categoryFilter = null;
    }
}
 
Example 16
Source File: WSUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String getOriginalWsdlUrl(Project prj, String id, boolean forService) {
    Preferences prefs = ProjectUtils.getPreferences(prj, MavenWebService.class, true);
    if (prefs != null) {
        // remember original WSDL URL for service
        if (forService) {
            return prefs.get(MavenWebService.SERVICE_PREFIX+id, null);
        } else {
            return prefs.get(MavenWebService.CLIENT_PREFIX+id, null);
        }
    }
    return null;
}
 
Example 17
Source File: Setting.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
public static Setting<String> createString(Preferences preferences, String key, @NotNull String defaultValue) {
	return new SettingBase<>(
		defaultValue,
		value -> preferences.get(key, value),
		value -> preferences.put(key, value));
}
 
Example 18
Source File: ToolTipManagerEx.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Dimension getDefaultToolTipSize() {
    Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    String size = prefs.get(SimpleValueNames.JAVADOC_PREFERRED_SIZE, null);
    Dimension dim = size == null ? null : parseDimension(size);
    return dim != null ? dim : new Dimension(500,300);
}
 
Example 19
Source File: JValueFactory.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create a renderer matching a key in a prefs node.
 */
public static JValue createJValue(Preferences node, String key) {
  try {
    String type = null;
    if(node instanceof ExtPreferences) {
      type = ((ExtPreferences)node).getProperty(key, ExtPreferences.PROP_TYPE, null);
    }

    if(type == null) {
      type = node.get(JValue.TYPE_PREFIX + key, "");
    }

    if(type == null || "".equals(type)) {
      String val  = node.get(key, "");
      if(JValueBoolean.isBoolean(val)) {
        type = ExtPreferences.TYPE_BOOLEAN;
      } else if(JValueInteger.isInteger(val)) {
        type = ExtPreferences.TYPE_INT;
      } else if(JValueColor.isColor(val)) {
        type = ExtPreferences.TYPE_COLOR;
      } else {
        type = ExtPreferences.TYPE_STRING;
      }
    }
    if(ExtPreferences.TYPE_STRING.equals(type)) {
      return new JValueString(node, key);
    } else if(ExtPreferences.TYPE_COLOR.equals(type)) {
      return new JValueColor(node, key);
    } else if(ExtPreferences.TYPE_BOOLEAN.equals(type)) {
      return new JValueBoolean(node, key);
    } else if(ExtPreferences.TYPE_INT.equals(type)) {
      return new JValueInteger(node, key);
    } else if(ExtPreferences.TYPE_DOUBLE.equals(type)) {
      return new JValueDouble(node, key);
    } else if(ExtPreferences.TYPE_LONG.equals(type)) {
      return new JValueLong(node, key);
    } else {
      // Activator.log.warn("Node " + node.absolutePath() + "/" + key + ", unknown type=" + type + ", using string");
      return new JValueString(node, key);
    }
  } catch (Exception e) {
    throw new RuntimeException("Failed to create jvalue from" + node + ", key=" + key, e);
  }
}
 
Example 20
Source File: CreateJREPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@CheckForNull
private static File getEJDKHome() {
    final Preferences prefs = NbPreferences.forModule(CreateJREPanel.class);
    final String path = prefs.get(KEY_EJDK, null);
    return path == null ? null : new File(path);
}