Example usage for java.util.prefs PreferenceChangeEvent getKey

List of usage examples for java.util.prefs PreferenceChangeEvent getKey

Introduction

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

Prototype

public String getKey() 

Source Link

Document

Returns the key of the preference that was changed.

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

From source file:Main.java

public void preferenceChange(PreferenceChangeEvent evt) {
    String key = evt.getKey();
    String val = evt.getNewValue();
    if (key.equals(NAMEPREF)) {
        System.out.println(val);
    } else if (key.equals(EMAILPREF)) {
        System.out.println(val);
    }/*from  w w w  .  java 2s. co  m*/
}

From source file:MainClass.java

public void preferenceChange(PreferenceChangeEvent evt) {

    String key = evt.getKey();
    String val = evt.getNewValue();

    if (key.equals(NAMEPREF)) {
        System.out.println(val);
    } else if (key.equals(EMAILPREF)) {
        System.out.println(val);
    } else if (key.equals(AGEPREF)) {
        System.out.println(val);
    } else if (key.equals(PHONEPREF)) {
        System.out.println(val);
    }/*from w  w  w .  j a v  a 2s  .  c o m*/
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

/**
 * Updates the file menu when a value is added to the most recently used list.
 *//*  www .  j a v a2  s . c  o  m*/
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
    if (EditorPreferences.MRU_PREF_KEY.equals(evt.getKey())) {
        buildFileMenu(_fileMenu);
    }
}

From source file:org.apache.cayenne.modeler.ModelerPreferences.java

public void preferenceChange(PreferenceChangeEvent evt) {
    evt.getNode().put(evt.getKey(), evt.getNewValue());
}

From source file:org.apache.cayenne.modeler.preferences.ModelerPreferences.java

@Override
public void preferenceChange(PreferenceChangeEvent evt) {
    evt.getNode().put(evt.getKey(), evt.getNewValue());
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void init() {
    String fileName = String.format("/%s/sync-256px.png", getClass().getPackage().getName().replace(".", "/"));
    ImageIcon imageIcon = new ImageIcon(getClass().getResource(fileName));
    setIconImage(imageIcon.getImage());/*from ww w  . j  av  a2s  .  co m*/

    mOptions.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        String key = evt.getKey();
        if (key.equalsIgnoreCase(ClientOptions.KEY_MENU_ICONS)) {
            loadClientOption(ClientOptionsEvent.MENU_ICONS);
        } else if (key.equalsIgnoreCase(ClientOptions.KEY_FORCE_LOOK_AND_FEEL)
                || key.equalsIgnoreCase(ClientOptions.KEY_LOOK_AND_FEEL)) {
            loadClientOption(ClientOptionsEvent.LOOK_AND_FEEL);
        } else if (key.equalsIgnoreCase(ClientOptions.KEY_ICON_THEME)) {
            mAllActions.stream().forEach((jotaAction) -> {
                jotaAction.updateIcon();
            });
        }
    });

    mActionManager = new ActionManager();
    mActionManager.initActions();

    mTabHolder = new TabHolder();
    add(mTabHolder);
    mTabHolder.initActions();
    mManager.addConnectionListeners(this);

    loadClientOption(ClientOptionsEvent.LOOK_AND_FEEL);
    loadClientOption(ClientOptionsEvent.MENU_ICONS);

    updateWindowTitle();

    try {
        SwingHelper.frameStateRestore(this, 800, 600);
    } catch (BackingStoreException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:se.trixon.jota.server.Server.java

private void intiListeners() {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        notifyClientsShutdown();//from www.j  a  v  a2s.  com
    }));

    mOptions.getPreferences().addPreferenceChangeListener((PreferenceChangeEvent evt) -> {
        HashSet<ClientCallbacks> invalidClientCallbacks = new HashSet<>();

        for (ClientCallbacks clientCallback : mClientCallbacks) {
            switch (evt.getKey()) {
            case ServerOptions.KEY_CRON_ACTIVE: {
                try {
                    clientCallback.onServerEvent(ServerEvent.CRON_CHANGED);
                } catch (RemoteException ex) {
                    //Add invalid reference for removal
                    invalidClientCallbacks.add(clientCallback);
                }
            }
                break;
            }
        }

        invalidClientCallbacks.stream().forEach((invalidClientCallback) -> {
            //Remove invalid reference
            mClientCallbacks.remove(invalidClientCallback);
        });
    });
}