List of usage examples for java.util.prefs Preferences node
public abstract Preferences node(String pathName);
From source file:ec.nbdemetra.ui.Installer.java
public static void loadConfig(Collection<?> list, Preferences root) { Parsers.Parser<Config> parser = Config.xmlParser(); for (IConfigurable o : Iterables.filter(list, IConfigurable.class)) { Config current = o.getConfig();/* w w w. j a v a 2 s . co m*/ try { if (root.nodeExists(current.getDomain())) { Preferences domain = root.node(current.getDomain()); Optional<Config> config = InstallerStep.tryGet(domain, current.getName(), parser); if (config.isPresent()) { o.setConfig(config.get()); } } } catch (BackingStoreException ex) { // do nothing? } } }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
public static GraphPanel load(Preferences p, SystemState state, GraphsPanel gps) { DataSampler sampler = (DataSampler) state.getItemByID(DataSampler.ID, StatefulItemClass.WORKFLOW); GraphPanel g = new GraphPanel(state, gps); int ec = p.getInt("enabledCount", 0); for (int i = 0; i < ec; i++) { Preferences gp = p.node("series" + i); String key = gp.get("key", null); if (key == null) { throw new RuntimeException("Null series key"); }/*from w w w . j a v a 2 s . co m*/ int cr = gp.getInt("color.r", 255); int cg = gp.getInt("color.g", 0); int cb = gp.getInt("color.b", 0); g.enable(sampler.getSeries(key), false); g.setColor(key, new Color(cr, cg, cb)); } return g; }
From source file:ome.formats.utests.IniFileLoaderTest.java
@Test public void testDuplicatedSections() throws Exception { FileUtils.writeLines(temporaryFile, Arrays.asList("[Section]", "A=1", "[Section]", "A=2")); Preferences test = new IniFile(temporaryFile, Mode.RW); String a1 = test.node("Section").get("A", "missing"); assertEquals("2", a1); }
From source file:ome.formats.utests.IniFileLoaderTest.java
@Test public void testDuplicatedSections2() throws Exception { FileUtils.writeLines(temporaryFile, Arrays.asList("[Section]", "[Section]", "A=1")); Preferences test = new IniFile(temporaryFile, Mode.RW); String a1 = test.node("Section").get("A", "missing"); assertEquals("1", a1); }
From source file:ome.formats.utests.IniFileLoaderTest.java
@Test public void testFlexReaderServerMapUnix() throws Exception { FileUtils.writeLines(temporaryFile, Arrays.asList("[FlexReaderServerMaps]", "CIA-1=/mnt/path1;/mnt/path2")); Preferences test = new IniFile(temporaryFile, Mode.RW); Preferences maps = test.node("FlexReaderServerMaps"); Map<String, List<String>> parsedMaps = ini.parseFlexMaps(maps); assertEquals(1, parsedMaps.size());/*from www . ja va 2 s .co m*/ List<String> serverPaths = parsedMaps.get("CIA-1"); assertEquals(2, serverPaths.size()); assertEquals("/mnt/path1", serverPaths.get(0)); assertEquals("/mnt/path2", serverPaths.get(1)); }
From source file:ome.formats.utests.IniFileLoaderTest.java
@Test public void testFlexReaderServerMapUNC() throws Exception { FileUtils.writeLines(temporaryFile, Arrays.asList("[FlexReaderServerMaps]", "CIA-1=\\\\\\\\hostname1\\\\path1;\\\\\\\\hostname1\\\\path2")); Preferences test = new IniFile(temporaryFile, Mode.RW); Preferences maps = test.node("FlexReaderServerMaps"); Map<String, List<String>> parsedMaps = ini.parseFlexMaps(maps); assertEquals(1, parsedMaps.size());//from w ww.j a va 2s.c o m List<String> serverPaths = parsedMaps.get("CIA-1"); assertEquals(2, serverPaths.size()); assertEquals("\\\\hostname1\\path1", serverPaths.get(0)); assertEquals("\\\\hostname1\\path2", serverPaths.get(1)); }
From source file:org.kuali.test.ui.components.dialogs.EmailDlg.java
/** * * @return//from ww w . j a v a 2s .c o m */ @Override protected boolean save() { boolean retval = false; boolean oktosave = true; if (StringUtils.isNotBlank(mailHost.getText()) && StringUtils.isNotBlank(subject.getText()) && StringUtils.isNotBlank(fromAddress.getText()) && StringUtils.isNotBlank(toAddresses.getText())) { } else { displayRequiredFieldsMissingAlert("Email Setup", "mail host, subject, from address, to addreses"); oktosave = false; } if (oktosave) { emailSetup.setMailHost(mailHost.getText()); emailSetup.setSubject(subject.getText()); emailSetup.setFromAddress(fromAddress.getText()); emailSetup.setToAddresses(toAddresses.getText()); Preferences proot = Preferences.userRoot(); Preferences node = proot.node(Constants.PREFS_ROOT_NODE); node.put(Constants.LOCAL_RUN_EMAIL, localRunAddress.getText()); try { node.flush(); } catch (BackingStoreException ex) { LOG.warn(ex.toString(), ex); } setSaved(true); getConfiguration().setModified(true); dispose(); retval = true; } return retval; }
From source file:PreferencesTest.java
public PreferencesFrame() { // get position, size, title from preferences Preferences root = Preferences.userRoot(); final Preferences node = root.node("/com/horstmann/corejava"); int left = node.getInt("left", 0); int top = node.getInt("top", 0); int width = node.getInt("width", DEFAULT_WIDTH); int height = node.getInt("height", DEFAULT_HEIGHT); setBounds(left, top, width, height); // if no title given, ask user String title = node.get("title", ""); if (title.equals("")) title = JOptionPane.showInputDialog("Please supply a frame title:"); if (title == null) title = ""; setTitle(title);/*from ww w. j a v a 2 s .c om*/ // set up file chooser that shows XML files final JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); // accept all files ending with .xml chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory(); } public String getDescription() { return "XML files"; } }); // set up menus JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem exportItem = new JMenuItem("Export preferences"); menu.add(exportItem); exportItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { OutputStream out = new FileOutputStream(chooser.getSelectedFile()); node.exportSubtree(out); out.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem importItem = new JMenuItem("Import preferences"); menu.add(importItem); importItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) { try { InputStream in = new FileInputStream(chooser.getSelectedFile()); Preferences.importPreferences(in); in.close(); } catch (Exception e) { e.printStackTrace(); } } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { node.putInt("left", getX()); node.putInt("top", getY()); node.putInt("width", getWidth()); node.putInt("height", getHeight()); node.put("title", getTitle()); System.exit(0); } }); }
From source file:com.diversityarrays.dal.db.TestDalDatabase.java
@SuppressWarnings({ "rawtypes", "unchecked" }) static private DalDatabase createKddartDalDatabase() throws DalDbException { Preferences preferences = Preferences.userNodeForPackage(DalServer.class); DalDbProviderService service = new KddartDalDbProviderService(); Map<Parameter<?>, ParameterValue<?>> parameterValues = new HashMap<Parameter<?>, ParameterValue<?>>(); Preferences serviceNode = preferences.node("service/" + service.getClass().getName()); for (Parameter<?> param : service.getParametersRequired()) { String s = serviceNode.get(param.name, null); try {/*from w w w .ja va 2 s . c om*/ Object value = param.stringToValue(s); parameterValues.put(param, new ParameterValue(param, value)); if (KddartDalDatabase.PARAM_USERNAME.equals(param.name)) { USERNAME = s; } else if (KddartDalDatabase.PARAM_PASSWORD.equals(param.name)) { PASSWORD = s; } } catch (ParameterException e) { Throwable t = e.getCause(); if (t == null) { t = e; } if (t instanceof RuntimeException) { throw ((RuntimeException) t); } throw new RuntimeException(t); } } KddartDalDatabase result = (KddartDalDatabase) service.createDatabase(parameterValues.values(), ClosureUtils.nopClosure(), false); System.out.println(TestDalDatabase.class.getName() + " for KDDart: " + result.getDatabaseName()); result.setAutoSwitchGroupOnLogin(true); return result; }
From source file:org.javaswift.cloudie.login.CredentialsStore.java
/** * deletes the credentials./*w w w.j a va 2 s .com*/ * @param cr the credentials. */ public void delete(Credentials cr) { try { Preferences prefs = Preferences.userNodeForPackage(CredentialsStore.class); prefs.node(cr.toString()).removeNode(); prefs.flush(); } catch (BackingStoreException ex) { throw new RuntimeException(ex); } }