List of usage examples for java.util.prefs Preferences userNodeForPackage
public static Preferences userNodeForPackage(Class<?> c)
From source file:LookAndFeelPrefs.java
/** * Create a menu of radio buttons listing the available Look and Feels. When * the user selects one, change the component hierarchy under frame to the new * LAF, and store the new selection as the current preference for the package * containing class c./*from w ww.j a v a 2 s .c o m*/ */ public static JMenu createLookAndFeelMenu(final Class prefsClass, final ActionListener listener) { // Create the menu final JMenu plafmenu = new JMenu("Look and Feel"); // Create an object used for radio button mutual exclusion ButtonGroup radiogroup = new ButtonGroup(); // Look up the available look and feels UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels(); // Find out which one is currently used String currentLAFName = UIManager.getLookAndFeel().getClass().getName(); // Loop through the plafs, and add a menu item for each one for (int i = 0; i < plafs.length; i++) { String plafName = plafs[i].getName(); final String plafClassName = plafs[i].getClassName(); // Create the menu item final JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName)); item.setSelected(plafClassName.equals(currentLAFName)); // Tell the menu item what to do when it is selected item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // Set the new look and feel try { UIManager.setLookAndFeel(plafClassName); } catch (UnsupportedLookAndFeelException e) { // Sometimes a Look-and-Feel is installed but not // supported, as in the Windows LaF on Linux platforms. JOptionPane.showMessageDialog(plafmenu, "The selected Look-and-Feel is " + "not supported on this platform.", "Unsupported Look And Feel", JOptionPane.ERROR_MESSAGE); item.setEnabled(false); } catch (Exception e) { // ClassNotFound or Instantiation item.setEnabled(false); // shouldn't happen } // Make the selection persistent by storing it in prefs. Preferences p = Preferences.userNodeForPackage(prefsClass); p.put(PREF_NAME, plafClassName); // Invoke the supplied action listener so the calling // application can update its components to the new LAF // Reuse the event that was passed here. listener.actionPerformed(event); } }); // Only allow one menu item to be selected at once radiogroup.add(item); } return plafmenu; }
From source file:codeswarm.repository.svn.SVNHistory.java
/** * looks up the cache. Stops proceeding if a cached version for this * repository was found.//w ww . j a va 2s.com * @param pRevision the latest repository revision. * @return false if a cached version was found, true if the history shall * be fetched from repository. */ public boolean handleFetchingLatestRepositoryRevision(Long pRevision) { long revision = pRevision.longValue(); Preferences p = Preferences.userNodeForPackage(SVNHistory.class); long l = p.getLong(Integer.toString(this.url.hashCode()), -1l); if (l == revision) { if (logger.isDebugEnabled()) { logger.debug("skip fetching " + String.valueOf(l) + " (latest revision is " + revision + ") for " + this.url); } return false; } else { if (logger.isDebugEnabled()) { logger.debug("proceed fetching (latest revision is " + String.valueOf(pRevision) + " , cached revision is " + String.valueOf(l) + " for repository " + this.url); } Preferences.userNodeForPackage(SVNHistory.class).putLong(Integer.toString(this.url.hashCode()), revision); try { Preferences.userNodeForPackage(SVNHistory.class).flush(); } catch (BackingStoreException ex) { logger.error(null, ex); } } if (logger.isDebugEnabled()) { logger.debug("fetching until revision " + revision); } return true; }
From source file:net.sf.ginp.setup.SetupManagerImpl.java
/** * @see net.sf.ginp.setup.SetupManager#deleteConfiguration(java.net.URL) *///from w w w. ja v a 2 s . c om public final void deleteConfiguration(final URL configUrl) { Preferences preferences = Preferences.userNodeForPackage(SetupManagerImpl.class); preferences.remove(configUrl.toExternalForm()); try { preferences.flush(); } catch (BackingStoreException e) { log.error("No big deal if we couldn't delete", e); } }
From source file:au.org.ala.delta.editor.EditorPreferences.java
/** * Adds the supplied filename to the top of the most recently used files. * /*from w w w.ja v a2s.c o m*/ * @param filename */ public static void addFileToMRU(String filename) { Queue<String> q = new LinkedList<String>(); q.add(filename); String[] existingFiles = getPreviouslyUsedFiles(); if (existingFiles != null) { for (String existingFile : existingFiles) { if (!q.contains(existingFile)) { q.add(existingFile); } } } StringBuilder b = new StringBuilder(); for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) { if (i > 0) { b.append(MRU_SEPARATOR); } b.append(q.poll()); } Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class); prefs.put(MRU_PREF_KEY, b.toString()); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }
From source file:io.github.moosbusch.lumpi.application.spi.AbstractLumpiApplicationContext.java
public AbstractLumpiApplicationContext( LumpiApplication<? extends LumpiApplicationContext, ? extends BindableWindow> application) { this.pca = new PropertyChangeAwareAdapter(this); this.hostFrame = new HostFrame(application); this.options = new Options(Preferences.userNodeForPackage(application.getClass())); this.components = new HashSet<>(); init(application);/* w ww.java 2s . c om*/ }
From source file:org.pentaho.di.core.util.AbstractStepMeta.java
/** * Read properties from preferences.//from ww w. ja v a 2s.c om */ public void readFromPreferences() { final Preferences node = Preferences.userNodeForPackage(this.getClass()); this.getProperties().walk(new ReadFromPreferences(node)); }
From source file:au.org.ala.delta.editor.EditorPreferences.java
public static String getImportFileFilter() { Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class); if (prefs != null) { return prefs.get(IMPORT_FILE_FILTER_KEY, DEFAULT_IMPORT_FILE_FILTER); }/*from ww w .java 2 s. co m*/ return DEFAULT_IMPORT_FILE_FILTER; }
From source file:org.jamocha.gui.JamochaGui.java
private void saveState(final Stage primaryStage) { final Preferences userPrefs = Preferences.userNodeForPackage(getClass()); userPrefs.putDouble("stage.x", primaryStage.getX()); userPrefs.putDouble("stage.y", primaryStage.getY()); userPrefs.putDouble("stage.width", primaryStage.getWidth()); userPrefs.putDouble("stage.height", primaryStage.getHeight()); }
From source file:org.docx4all.ui.main.WordMLApplet.java
private void openLocalFile(WordMLEditor editor, String urlParam) { ResourceMap rm = editor.getContext().getResourceMap(WordMLEditor.class); String localFileUrl = urlParam; if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { if (urlParam.startsWith("file:///")) { ;//pass } else {//from ww w .ja va2 s. c o m localFileUrl = "file:///" + urlParam.substring(7); } } String errMsg = null; try { FileObject fo = VFSUtils.getFileSystemManager().resolveFile(urlParam); if (fo.exists()) { Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); localFileUrl = fo.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, localFileUrl); prefs.put(Constants.LAST_OPENED_LOCAL_FILE, localFileUrl); PreferenceUtil.flush(prefs); log.info("\n\n Opening " + urlParam); editor.createInternalFrame(fo); } else { errMsg = rm.getString("Application.applet.initialisation.file.not.found.message", urlParam); } } catch (FileSystemException exc) { exc.printStackTrace(); errMsg = rm.getString("Application.applet.initialisation.file.io.error.message", urlParam); } if (errMsg != null) { String title = rm.getString("Application.applet.initialisation.Action.text"); editor.showMessageDialog(title, errMsg, JOptionPane.ERROR_MESSAGE); } }
From source file:com.mirth.connect.client.ui.ExportChannelLibrariesDialog.java
private void initComponents(Channel channel) { label1 = new JLabel(" The following code template libraries are linked to this channel:"); label1.setIcon(UIManager.getIcon("OptionPane.questionIcon")); librariesTextPane = new JTextPane(); librariesTextPane.setContentType("text/html"); HTMLEditorKit editorKit = new HTMLEditorKit(); StyleSheet styleSheet = editorKit.getStyleSheet(); styleSheet.addRule(".export-channel-libraries-dialog {font-family:\"Tahoma\";font-size:11;text-align:top}"); librariesTextPane.setEditorKit(editorKit); librariesTextPane.setEditable(false); librariesTextPane.setBackground(getBackground()); librariesTextPane.setBorder(null);//from w w w. ja v a 2s .c o m StringBuilder librariesText = new StringBuilder("<html><ul class=\"export-channel-libraries-dialog\">"); for (CodeTemplateLibrary library : PlatformUI.MIRTH_FRAME.codeTemplatePanel.getCachedCodeTemplateLibraries() .values()) { if (library.getEnabledChannelIds().contains(channel.getId()) || (library.isIncludeNewChannels() && !library.getDisabledChannelIds().contains(channel.getId()))) { librariesText.append("<li>").append(StringEscapeUtils.escapeHtml4(library.getName())) .append("</li>"); } } librariesText.append("</ul></html>"); librariesTextPane.setText(librariesText.toString()); librariesTextPane.setCaretPosition(0); librariesScrollPane = new JScrollPane(librariesTextPane); label2 = new JLabel("Do you wish to include these libraries in the channel export?"); alwaysChooseCheckBox = new JCheckBox( "Always choose this option by default in the future (may be changed in the Administrator settings)"); yesButton = new JButton("Yes"); yesButton.setMnemonic('Y'); yesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.YES_OPTION; if (alwaysChooseCheckBox.isSelected()) { Preferences.userNodeForPackage(Mirth.class).putBoolean("exportChannelCodeTemplateLibraries", true); } dispose(); } }); noButton = new JButton("No"); noButton.setMnemonic('N'); noButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.NO_OPTION; if (alwaysChooseCheckBox.isSelected()) { Preferences.userNodeForPackage(Mirth.class).putBoolean("exportChannelCodeTemplateLibraries", false); } dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.setMnemonic('C'); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { result = JOptionPane.CANCEL_OPTION; dispose(); } }); }