List of usage examples for java.util.prefs Preferences put
public abstract void put(String key, String value);
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Save the parent directory for the most recently opened dataset to * preferences//from ww w.ja v a 2s. c o m * * @param lastOpenedDatasetDirectory */ public static void saveLastOpenedDatasetDirectory(File lastOpenedDatasetDirectory) { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); prefs.put(LAST_OPENED_DATASET_LOCATION_PREF_KEY, lastOpenedDatasetDirectory.getAbsolutePath()); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Removes the specified file from the most recently used file list * /*from w ww .j ava2 s. c om*/ * @param filename * The filename to remove */ public static void removeFileFromMRU(String filename) { List<Pair<String, String>> existingFiles = getPreviouslyUsedFiles(); StringBuilder b = new StringBuilder(); for (int i = 0; i < existingFiles.size(); ++i) { Pair<String, String> fileNameTitlePair = existingFiles.get(i); String existingFileName = fileNameTitlePair.getFirst(); if (!existingFileName.equalsIgnoreCase(filename)) { if (b.length() > 0) { b.append(MRU_FILES_SEPARATOR); } b.append(fileNameTitlePair.getFirst() + MRU_ITEM_SEPARATOR + fileNameTitlePair.getSecond()); } } Preferences prefs = Preferences.userNodeForPackage(Intkey.class); prefs.put(MRU_FILES_PREF_KEY, b.toString()); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }
From source file:org.esa.snap.smart.configurator.PerformanceParameters.java
/** * Save the actual configuration//from www .j a v a 2s . co m * * @param confToSave The configuration to save */ synchronized static void saveConfiguration(PerformanceParameters confToSave) throws IOException, BackingStoreException { if (!loadConfiguration().getVMParameters().equals(confToSave.getVMParameters())) { confToSave.vmParameters.save(); } Config configuration = EngineConfig.instance().load(); Preferences preferences = configuration.preferences(); Path cachePath = confToSave.getCachePath(); if (!Files.exists(cachePath)) { Files.createDirectories(cachePath); } if (Files.exists(cachePath)) { preferences.put(SystemUtils.SNAP_CACHE_DIR_PROPERTY_NAME, cachePath.toAbsolutePath().toString()); } else { SystemUtils.LOG.severe("Directory for cache path does not exist"); } JAI ff = JAI.getDefaultInstance(); int parallelism = confToSave.getNbThreads(); //int defaultTileSize = confToSave.getDefaultTileSize(); int jaiCacheSize = confToSave.getCacheSize(); String tileWidth = confToSave.getTileWidth(); String tileHeight = confToSave.getTileHeight(); preferences.putInt(SystemUtils.SNAP_PARALLELISM_PROPERTY_NAME, parallelism); /*if(tileWidth == null) { preferences.remove(SYSPROP_READER_TILE_WIDTH); } else { preferences.put(SYSPROP_READER_TILE_WIDTH,tileWidth); } if(tileHeight == null) { preferences.remove(SYSPROP_READER_TILE_HEIGHT); } else { preferences.put(SYSPROP_READER_TILE_HEIGHT,tileHeight); }*/ preferences.putInt(PROPERTY_JAI_CACHE_SIZE, jaiCacheSize); preferences.flush(); // effective change of jai parameters JAIUtils.setDefaultTileCacheCapacity(jaiCacheSize); JAI.getDefaultInstance().getTileScheduler().setParallelism(parallelism); }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Adds the supplied filename to the top of the most recently used files. * /*w w w. j a va 2 s. c om*/ * @param filename */ public static void addFileToMRU(String filename, String title, List<Pair<String, String>> existingFiles) { // Strip any RTF formatting, and characters used as separators in the MRU text from the title. title = RTFUtils.stripFormatting(title); title = title.replace(MRU_ITEM_SEPARATOR, " "); title = title.replace(MRU_FILES_SEPARATOR, " "); Queue<String> q = new LinkedList<String>(); String newFilePathAndTitle; if (StringUtils.isEmpty(title)) { newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + filename; } else { newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + title; } q.add(newFilePathAndTitle); if (existingFiles != null) { for (Pair<String, String> existingFile : existingFiles) { String existingFilePathAndTitle = existingFile.getFirst() + MRU_ITEM_SEPARATOR + existingFile.getSecond(); if (!q.contains(existingFilePathAndTitle)) { q.add(existingFilePathAndTitle); } } } StringBuilder b = new StringBuilder(); for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) { if (i > 0) { b.append(MRU_FILES_SEPARATOR); } b.append(q.poll()); } Preferences prefs = Preferences.userNodeForPackage(Intkey.class); prefs.put(MRU_FILES_PREF_KEY, b.toString()); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
public static void setPreferredLookAndFeel(String lookAndFeelName) { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); if (prefs != null) { prefs.put(LOOK_AND_FEEL_KEY, lookAndFeelName); try {/*from w ww .j a va 2s . co m*/ prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } } }
From source file:com.mirth.connect.client.ui.components.rsta.MirthRSyntaxTextArea.java
public static void updateKeyStrokePreferences(Preferences userPreferences) { MirthInputMap.getInstance().update(rstaPreferences.getKeyStrokeMap()); userPreferences.put(PREFERENCES_KEYSTROKES, rstaPreferences.getKeyStrokesJSON()); }
From source file:kindleclippings.quizlet.QuizletSync.java
public static Preferences getPrefs() throws IOException, URISyntaxException, InterruptedException, JSONException, BackingStoreException { Preferences prefs = Preferences.userNodeForPackage(QuizletSync.class); String token = prefs.get("access_token", null); if (token == null) { JSONObject o = GetAccessToken.oauthDance(); if (o == null) { JOptionPane.showMessageDialog(null, "Failed authorization to access Quizlet", "QuizletSync", JOptionPane.ERROR_MESSAGE); System.exit(0);/*from w w w. j av a 2s. co m*/ } prefs.put("access_token", o.getString("access_token")); prefs.put("user_id", o.getString("user_id")); prefs.flush(); } return prefs; }
From source file:org.mbs3.juniuploader.gui.frmMain.java
public static void addUploadLocation(String url) { Preferences sites = prefs.node(prefs.absolutePath() + "/sites"); for (int i = 0; i < uploadLocations.getSize(); i++) { UploadSite ptr = (UploadSite) uploadLocations.getElementAt(i); if (url.equals(ptr.getUrl())) { return; }// w ww . jav a 2 s .c o m } sites.put(url, url); UploadSite toAdd = new UploadSite(url); uploadLocations.addElement(toAdd); }
From source file:com.vaadin.integration.maven.wscdn.CvalChecker.java
static void cacheLicenseInfo(CvalInfo info) { if (info != null) { Preferences p = Preferences.userNodeForPackage(CvalInfo.class); if (info.toString().length() > Preferences.MAX_VALUE_LENGTH) { // This should never happen since MAX_VALUE_LENGTH is big // enough. // But server could eventually send a very big message, so we // discard it in cache and would use hard-coded messages. info.setMessage(null);//w ww .ja v a 2s. c om } p.put(info.getProduct().getName(), info.toString()); } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Save the dataset index to preferences. * /*from w w w . j a v a2 s .c om*/ * @param datasetIndexList * The dataset index - a list of dataset description, dataset * path value pairs */ public static void writeDatasetIndex(List<Pair<String, String>> datasetIndexList) { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); List<List<String>> listToSerialize = new ArrayList<List<String>>(); for (Pair<String, String> datasetInfoPair : datasetIndexList) { listToSerialize.add(Arrays.asList(datasetInfoPair.getFirst(), datasetInfoPair.getSecond())); } String jsonList = JSONSerializer.toJSON(listToSerialize).toString(); prefs.put(DATASET_INDEX_PREF_KEY, jsonList); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }