Example usage for java.util.prefs PreferenceChangeListener PreferenceChangeListener

List of usage examples for java.util.prefs PreferenceChangeListener PreferenceChangeListener

Introduction

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

Prototype

PreferenceChangeListener

Source Link

Usage

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();
        }//from   w ww . ja v a  2  s.c  o  m
    });
    prefs.put("key", "a string");
    prefs.put("key", "a new string");
    prefs.remove("key");
}

From source file:com.symbian.utils.config.ConfigUtils.java

/**
 * @param aConfigMap/*from   ww  w. j  av a 2s  . c  o m*/
 * @param aPreferenceAddress
 * @param aPreferenceLiterals
 * @throws IOException
 */
protected ConfigUtils(String aPreferenceAddress, String[] aPreferenceLiterals) throws IOException {
    iNodeName = aPreferenceAddress;
    iConfigMap = new HashMap();
    iSavedConfig = new HashMap();
    iPreferenceLiterals = aPreferenceLiterals;

    iPrefrences = Preferences.userRoot().node(iNodeName);
    // if created for the first time, it needs to be flushed.
    try {
        iPrefrences.flush();
    } catch (BackingStoreException lBackingStoreException) {
        LOGGER.warning("Failed to flush the configuration: " + lBackingStoreException.getMessage());
    }
    // Register the listener for prefs changes
    iPrefrences.addPreferenceChangeListener(new PreferenceChangeListener() {
        public void preferenceChange(PreferenceChangeEvent evt) {
            try {
                iPrefrences.flush();
            } catch (BackingStoreException lBackingStoreException) {
                LOGGER.warning("Failed to flush the configuration: " + lBackingStoreException.getMessage());
            }
        }
    });
}

From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java

protected void initialize() {

    httpChunkStream = !IReportManager.getPreferences().getBoolean("jasperserver.preventChunkedRequests", true);

    IReportManager.getPreferences().addPreferenceChangeListener(new PreferenceChangeListener() {

        public void preferenceChange(PreferenceChangeEvent pce) {
            CommonsHTTPSender.this.httpChunkStream = !IReportManager.getPreferences()
                    .getBoolean("jasperserver.preventChunkedRequests", true);
        }//from  w ww . j ava 2s .  c o  m
    });

    MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
    this.clientProperties = CommonsHTTPClientPropertiesFactory.create();
    cm.getParams().setDefaultMaxConnectionsPerHost(clientProperties.getMaximumConnectionsPerHost());
    cm.getParams().setMaxTotalConnections(clientProperties.getMaximumTotalConnections());
    // If defined, set the default timeouts
    // Can be overridden by the MessageContext
    if (this.clientProperties.getDefaultConnectionTimeout() > 0) {
        cm.getParams().setConnectionTimeout(this.clientProperties.getDefaultConnectionTimeout());
    }
    if (this.clientProperties.getDefaultSoTimeout() > 0) {
        cm.getParams().setSoTimeout(this.clientProperties.getDefaultSoTimeout());
    }
    this.connectionManager = cm;
}