Example usage for java.util.prefs Preferences remove

List of usage examples for java.util.prefs Preferences remove

Introduction

In this page you can find the example usage for java.util.prefs Preferences remove.

Prototype

public abstract void remove(String key);

Source Link

Document

Removes the value associated with the specified key in this preference node, if any.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Get the user preference node for java.lang
    Preferences prefs = Preferences.userNodeForPackage(String.class);

    // Remove a preference in the node
    final String PREF_NAME = "name_of_preference";
    prefs.remove(PREF_NAME);

    // Remove all preferences in the node

    prefs.clear();//  w w  w . jav  a 2s  . co  m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Preferences prefs = Preferences.userNodeForPackage(String.class);

    prefs.addPreferenceChangeListener(new PreferenceChangeListener() {
        public void preferenceChange(PreferenceChangeEvent evt) {

            Preferences node = evt.getNode();
            String key = evt.getKey();
            String newValue = evt.getNewValue();
        }/* ww w.  j  a  v a 2s  .  c  o  m*/
    });
    prefs.put("key", "a string");
    prefs.put("key", "a new string");
    prefs.remove("key");
}

From source file:com.vaadin.integration.maven.wscdn.CvalChecker.java

static void deleteCache(String productName) {
    Preferences p = Preferences.userNodeForPackage(CvalInfo.class);
    p.remove(productName);
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

public static List<Pair<String, String>> getPreviouslyUsedFiles() {
    List<Pair<String, String>> retList = new ArrayList<Pair<String, String>>();

    Preferences prefs = Preferences.userNodeForPackage(Intkey.class);
    if (prefs != null) {
        try {// w  w w .j ava 2s .c  o m
            String mru = prefs.get(MRU_FILES_PREF_KEY, "");
            if (!StringUtils.isEmpty(mru)) {
                String[] mruFiles = mru.split(MRU_FILES_SEPARATOR);
                for (String mruFile : mruFiles) {
                    String[] mruFileItems = mruFile.split(MRU_ITEM_SEPARATOR);
                    retList.add(new Pair<String, String>(mruFileItems[0], mruFileItems[1]));
                }
            }
        } catch (Exception e) {
            // An error occurred. Clear the most recently used files list and return an empty list.

            prefs.remove(MRU_FILES_PREF_KEY);
            try {
                prefs.sync();
            } catch (BackingStoreException bse) {
                throw new RuntimeException(bse);
            }
            return Collections.EMPTY_LIST;
        }
    }

    return retList;
}

From source file:de.ailis.oneinstance.OneInstance.java

/**
 * Unregisters this instance of the application. If this is the first
 * instance then the server is closed and the port is removed from
 * the preferences. If this is not the first instance then this method
 * does nothing.//from  ww w.j a v  a2s. c  om
 * 
 * This method should be called when the application exits. But it is
 * not a requirement. When you don't do this then the port number will
 * stay in the preferences so on next start of the application this port
 * number must be validated. So by calling this method on application exit
 * you just save the time for this port validation.
 * 
 * @param mainClass
 *            The main class of the application. Must not be null.
 *            This is used as the user node key for the preferences.
 */
public void unregister(Class<?> mainClass) {
    if (mainClass == null)
        throw new IllegalArgumentException("mainClass must be set");

    // Nothing to do when no server socket is present
    if (this.server == null)
        return;

    // Close the server socket
    this.server.stop();
    this.server = null;

    // Remove the port from the preferences
    Preferences prefs = Preferences.userNodeForPackage(mainClass);
    prefs.remove(PORT_KEY);
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error(e.toString(), e);
    }
}

From source file:net.sf.ginp.setup.SetupManagerImpl.java

/**
 * @see net.sf.ginp.setup.SetupManager#deleteConfiguration(java.net.URL)
 *//*from  ww  w. jav  a 2s .com*/
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:org.apache.cayenne.pref.CayennePreferenceEditor.java

public void save() {
    cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).save();

    if (restartRequired) {
        restart();/*from  w  w  w.j a v  a  2  s  . co  m*/
    }

    // update boolean preferences
    Iterator it = changedBooleanPreferences.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        Preferences pref = (Preferences) entry.getKey();
        Map<String, Boolean> map = (Map<String, Boolean>) entry.getValue();

        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry en = (Map.Entry) iterator.next();
            String key = (String) en.getKey();
            Boolean value = (Boolean) en.getValue();

            pref.putBoolean(key, value);
        }
    }

    // update string preferences
    Iterator iter = changedPreferences.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        Preferences pref = (Preferences) entry.getKey();
        Map<String, String> map = (Map<String, String>) entry.getValue();

        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry en = (Map.Entry) iterator.next();
            String key = (String) en.getKey();
            String value = (String) en.getValue();

            pref.put(key, value);
        }
    }

    // remove string preferences
    Iterator iterator = removedPreferences.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = (Map.Entry) iterator.next();
        Preferences pref = (Preferences) entry.getKey();
        Map<String, String> map = (Map<String, String>) entry.getValue();

        Iterator itRem = map.entrySet().iterator();
        while (itRem.hasNext()) {
            Map.Entry en = (Map.Entry) itRem.next();
            String key = (String) en.getKey();
            pref.remove(key);
        }
    }

    // remove preferences node
    Iterator<Preferences> iteratorNode = removedNode.iterator();
    while (iteratorNode.hasNext()) {
        Preferences pref = iteratorNode.next();
        try {
            pref.removeNode();
        } catch (BackingStoreException e) {
            logger.warn("Error removing preferences");
        }
    }

    Application.getInstance().initClassLoader();
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void rootRightClickAction(final MouseEvent evt) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem refreshItem = new JMenuItem("Refresh Templates");
    JMenuItem resetConnectionItem = new JMenuItem("Reset Connection");
    menu.add(refreshItem);//ww w. java 2  s . co  m
    menu.add(resetConnectionItem);

    refreshItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            // simulate close and open to refresh the tree
            componentClosed();
            componentOpened();
        }
    });

    resetConnectionItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent evt) {
            ServerDetailsView serverDetails = getRefreshServerDetails();
            // set previous preferences
            Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class);
            serverDetails.setDetails(prefs.get("scheme", "http"), prefs.get("host", "localhost"),
                    prefs.get("port", "8080"), prefs.get("username", StringUtils.EMPTY),
                    prefs.get("password", StringUtils.EMPTY));
            // reset connection preferences
            prefs.remove("scheme");
            prefs.remove("host");
            prefs.remove("port");
            prefs.remove("username");
            prefs.remove("password");
            serverDetails.setVisible(true);
        }
    });
    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

From source file:org.broad.igv.DirectoryManager.java

private static File getIgvDirectoryOverride() {
    Preferences userPrefs = null;
    File override = null;//from ww w .  ja  v  a2s.c o  m
    try {
        // See if an override location has been specified.  This is stored with the Java Preferences API
        userPrefs = Preferences.userNodeForPackage(Globals.class);
        String userDir = userPrefs.get(IGV_DIR_USERPREF, null);
        if (userDir != null) {
            override = new File(userDir);
            if (!override.exists()) {
                override = null;
                userPrefs.remove(IGV_DIR_USERPREF);
            }
        }
    } catch (Exception e) {
        userPrefs.remove(IGV_DIR_USERPREF);
        override = null;
        System.err.println("Error creating user directory");
        e.printStackTrace();
    }
    return override;
}

From source file:org.mbs3.juniuploader.gui.frmMain.java

public static void removeUploadLocation(String url)
// TODO: Make this preferences aware
{
    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())) {
            uploadLocations.removeElementAt(i);
            i--;//from w  w w.  j  a  v a  2  s. co  m
            sites.remove(url);
        }
    }
}