List of usage examples for java.util.prefs Preferences get
public abstract String get(String key, String def);
From source file:com.nbt.TreeFrame.java
private void restoreFile() { Preferences prefs = getPreferences(); String pathname = prefs.get(KEY_FILE, null); if (pathname != null) { File file = new File(pathname); doImport(file);//from w w w .j a v a 2s . c o m } }
From source file:com.nbt.TreeFrame.java
protected JFileChooser createFileChooser() { JFileChooser fc = new JFileChooser(); fc.setFileHidingEnabled(false);// w ww. ja va 2s . c o m fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); String description = "named binary tag"; FileFilter filter = new FileNameExtensionFilter(description, "mcr", "dat", "dat_old"); fc.setFileFilter(filter); Preferences prefs = getPreferences(); String exportFile = prefs.get(KEY_FILE, null); if (exportFile == null) { File cwd = new File("."); fc.setCurrentDirectory(cwd); } else { File selectedFile = new File(exportFile); fc.setSelectedFile(selectedFile); } return fc; }
From source file:org.docx4all.ui.menu.FileMenu.java
@Action public void openFile(ActionEvent actionEvent) { Preferences prefs = Preferences.userNodeForPackage(getClass()); WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); ResourceMap rm = editor.getContext().getResourceMap(WordMLEditor.class); String lastFileUri = prefs.get(Constants.LAST_OPENED_FILE, Constants.EMPTY_STRING); FileObject dir = null;//from ww w . j a v a2s . c om if (lastFileUri.length() > 0) { try { dir = VFSUtils.getFileSystemManager().resolveFile(lastFileUri).getParent(); } catch (FileSystemException exc) { dir = null; } } VFSJFileChooser chooser = createFileChooser(rm, dir, Constants.DOCX_STRING); RETURN_TYPE returnVal = chooser.showOpenDialog((Component) actionEvent.getSource()); if (returnVal == RETURN_TYPE.APPROVE) { FileObject file = getSelectedFile(chooser, Constants.DOCX_STRING); if (file != null) { lastFileUri = file.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, lastFileUri); if (file.getName().getScheme().equals(("file"))) { prefs.put(Constants.LAST_OPENED_LOCAL_FILE, lastFileUri); } PreferenceUtil.flush(prefs); log.info("\n\n Opening " + VFSUtils.getFriendlyName(lastFileUri)); editor.createInternalFrame(file); } } }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Description of the Method//from w ww.j a va 2 s . c om * * @param context Description of the Parameter * @return Description of the Return Value */ private String retrieveFileLibraryLocation(ServletContext context) { String dir = ApplicationPrefs.getRealPath(context); try { if (dir == null) { dir = node; } // Read from Preferences LOG.info("Java preferences key: " + dir); Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class); // Check "dir" prefs first, based on the installed directory of this webapp String fileLibrary = null; if (dir.length() <= Preferences.MAX_KEY_LENGTH) { fileLibrary = javaPrefs.get(dir, null); } else { fileLibrary = javaPrefs.get(dir.substring(dir.length() - Preferences.MAX_KEY_LENGTH), null); } boolean doSave = false; // Preferences not found if (fileLibrary == null) { // Check in the current dir of the webapp for a pointer to the properties // NOTE: Some containers return null for getRealPath() String realPath = ApplicationPrefs.getRealPath(context); if (realPath != null) { fileLibrary = realPath + "WEB-INF" + fs + "fileLibrary" + fs; doSave = true; } } // See if properties exist if (fileLibrary != null) { File propertyFile = new File(fileLibrary + "build.properties"); if (propertyFile.exists()) { if (doSave) { saveFileLibraryLocation(dir, fileLibrary); } return fileLibrary; } } } catch (Exception e) { LOG.error("ApplicationPrefs", e); e.printStackTrace(System.out); } return null; }
From source file:main.UIController.java
public Time calculateSunset(Calendar calendar, String city, String country, boolean useCacheSunset) { Time time = null;/* www . j ava 2 s. c om*/ boolean useCache = useCacheSunset; Preferences data = this.getCurrentPreferences(); if (!useCache) { String place = this.makeLocationString(city, country); if (place.length() > 0) { GeoAddressStandardizer st = new GeoAddressStandardizer(Config.getGoogleMapsApiKey(), Config.getRateLimitInterval()); HttpClientParams params = st.getHttpClientParams(); params.setSoTimeout(Config.getConnectionTimeout()); st.setHttpClientParams(params); Location location = null; try { GeoCoordinate geo = st.standardizeToGeoCoordinate(place); double latitude = geo.getLatitude(); double longitude = geo.getLongitude(); location = new Location(Double.toString(latitude), Double.toString(longitude)); String timezone = data.get(FIELD_TIMEZONE, DEF_TIMEZONE); SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, timezone); String sunset = calculator.getOfficialSunsetForDate(calendar) + ":00"; data.put(FIELD_CACHE_SUNSET, sunset); time = Time.valueOf(sunset); } catch (GeoException e) { useCache = true; } } else { useCache = true; } } if (useCache) { String cacheSunset = data.get(FIELD_CACHE_SUNSET, DEF_CACHE_SUNSET); if (!cacheSunset.isEmpty()) { time = Time.valueOf(cacheSunset); } } return time; }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Returns the pathname string of the default folder. * //from www.jav a 2 s. c om * @return See above. */ public static String getDefaultFolderAsString() { Preferences prefs = Preferences.userNodeForPackage(UIUtilities.class); if (prefs == null) return null; return prefs.get(DEFAULT_FOLDER, null); }
From source file:net.sf.jabref.JabRefPreferences.java
/** * Fetches key patterns from preferences. * The implementation doesn't cache the results * * @return LabelPattern containing all keys. Returned LabelPattern has no parent *///from ww w.ja v a 2 s.co m public GlobalLabelPattern getKeyPattern() { keyPattern = new GlobalLabelPattern(); Preferences pre = Preferences.userNodeForPackage(GlobalLabelPattern.class); try { String[] keys = pre.keys(); if (keys.length > 0) { for (String key : keys) { keyPattern.addLabelPattern(key, pre.get(key, null)); } } } catch (BackingStoreException ex) { LOGGER.info("BackingStoreException in JabRefPreferences.getKeyPattern", ex); } return keyPattern; }
From source file:org.docx4all.ui.menu.FileMenu.java
@Action public void newFile() { Preferences prefs = Preferences.userNodeForPackage(getClass()); WordMLEditor editor = WordMLEditor.getInstance(WordMLEditor.class); FileObject fo = null;/*ww w . j a va 2s . com*/ try { //Prepare the new file name StringBuffer newFile = new StringBuffer(); newFile.append(editor.getUntitledFileName()); newFile.append(++_untitledFileNumber); newFile.append(".docx"); //put new file in same directory as last opened local file's. //if there isn't last opened local file, put it in the //swing file chooser's default directory. String lastFile = prefs.get(Constants.LAST_OPENED_LOCAL_FILE, Constants.EMPTY_STRING); if (lastFile.length() == 0) { fo = VFSUtils.getFileSystemManager() .toFileObject(FileSystemView.getFileSystemView().getDefaultDirectory()); } else { fo = VFSUtils.getFileSystemManager().resolveFile(lastFile).getParent(); } fo = fo.resolveFile(newFile.toString()); } catch (FileSystemException exc) { exc.printStackTrace(); ResourceMap rm = editor.getContext().getResourceMap(getClass()); String title = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.text"); String message = rm.getString(FileMenu.NEW_FILE_ACTION_NAME + ".Action.errorMessage"); editor.showMessageDialog(title, message, JOptionPane.INFORMATION_MESSAGE); return; } editor.createInternalFrame(fo); }
From source file:com.adito.server.DefaultAditoServerFactory.java
void copyNode(Preferences from, Preferences to) throws BackingStoreException { String[] keys = from.keys();/*from w w w.j a va 2s .com*/ for (String key : keys) { to.put(key, from.get(key, "")); } String childNodes[] = from.childrenNames(); for (String childNode : childNodes) { Preferences cn = from.node(childNode); Preferences tn = to.node(childNode); copyNode(cn, tn); } }
From source file:com.adito.server.Main.java
void copyNode(Preferences from, Preferences to) throws BackingStoreException { String[] keys = from.keys();/*from ww w. j ava 2 s .c om*/ for (int i = 0; i < keys.length; i++) { to.put(keys[i], from.get(keys[i], "")); } String childNodes[] = from.childrenNames(); for (int i = 0; i < childNodes.length; i++) { Preferences cn = from.node(childNodes[i]); Preferences tn = to.node(childNodes[i]); copyNode(cn, tn); } }