本文整理汇总了Java中java.util.prefs.Preferences.addPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java Preferences.addPreferenceChangeListener方法的具体用法?Java Preferences.addPreferenceChangeListener怎么用?Java Preferences.addPreferenceChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.prefs.Preferences
的用法示例。
在下文中一共展示了Preferences.addPreferenceChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrefs
import java.util.prefs.Preferences; //导入方法依赖的package包/类
private static Preferences getPrefs(boolean shouldClear) {
if (prefs == null) {
synchronized (AppPreferences.class) {
if (prefs == null) {
Preferences p = Preferences.userNodeForPackage(Main.class);
if (shouldClear) {
try {
p.clear();
} catch (BackingStoreException e) {
}
}
myListener = new MyListener();
p.addPreferenceChangeListener(myListener);
prefs = p;
setTemplateFile(convertFile(p.get(TEMPLATE_FILE, null)));
setTemplateType(p.getInt(TEMPLATE_TYPE, TEMPLATE_PLAIN));
}
}
}
return prefs;
}
示例2: testRemoveInInheritedPreferences
import java.util.prefs.Preferences; //导入方法依赖的package包/类
/**
* Exception was thrown, if Inherited preferences observed removal in underlying
* keys and attempted to refire the change.
*/
public void testRemoveInInheritedPreferences() throws Exception {
Preferences stored = new MapPreferences();
Preferences inherited = new MapPreferences();
inherited.putBoolean("toBeRemoved", Boolean.TRUE);
MemoryPreferences mem = MemoryPreferences.getWithInherited(this, inherited, stored);
Preferences test = mem.getPreferences();
PL pl = new PL();
test.addPreferenceChangeListener(pl);
assertTrue(test.getBoolean("toBeRemoved", false));
pl.arm();
// remove from inherited prefs, test should stop listing the key
// and should refire the removed event
inherited.remove("toBeRemoved");
pl.waitEvent();
assertNull(test.get("toBeRemoved", null));
assertEquals(1, pl.changeCount);
assertNull(pl.value);
assertEquals("toBeRemoved", pl.key);
}
示例3: PhotoManagerImpl
import java.util.prefs.Preferences; //导入方法依赖的package包/类
public PhotoManagerImpl() throws ClassNotFoundException {
Preferences prefs = NbPreferences.forModule(PhotoManager.class);
setupDatabase();
setSourceDirs(prefs.get("sourceDirs", ""));
scanSourceDirs();
instanceContent = new InstanceContent();
lookup = new AbstractLookup(instanceContent);
prefs.addPreferenceChangeListener(evt -> {
if (evt.getKey().equals("sourceDirs")) {
setSourceDirs(evt.getNewValue());
scanSourceDirs();
}
});
}
示例4: InheritedPreferences
import java.util.prefs.Preferences; //导入方法依赖的package包/类
public InheritedPreferences(Preferences inherited, Preferences stored) {
super(null, ""); // NOI18N
this.inherited = inherited;
if (!(stored instanceof OverridePreferences)) {
throw new IllegalArgumentException();
}
this.stored = stored;
inherited.addPreferenceChangeListener(this);
}
示例5: setDefaultPreferences
import java.util.prefs.Preferences; //导入方法依赖的package包/类
@Override
public void setDefaultPreferences(Preferences pref) {
if (this.defaultPrefs != null) {
defaultPrefs.removePreferenceChangeListener(weakL);
}
// anomaly: if the local Preference contains 'removedKey' for a preference
// which has been turned to default, it blocks all change propagations.
this.defaultPrefs = pref;
if (pref != null) {
weakL = WeakListeners.create(PreferenceChangeListener.class, this, pref);
pref.addPreferenceChangeListener(weakL);
}
}
示例6: PrefMonitorString
import java.util.prefs.Preferences; //导入方法依赖的package包/类
PrefMonitorString(String name, String dflt) {
super(name);
this.dflt = dflt;
Preferences prefs = AppPreferences.getPrefs();
this.value = prefs.get(name, dflt);
prefs.addPreferenceChangeListener(this);
}
示例7: lazyInit
import java.util.prefs.Preferences; //导入方法依赖的package包/类
private static void lazyInit() {
if (!inited) {
inited = true;
// correctly we should use a proper mime type for the document where the completion runs,
// but at the moment this is enough, because completion settings are mainted globaly for all mime types
// (ie. their the same for all mime types). Also, if using a specific mime type
// this code should hold the prefs instance somewhere, but not in a static field!
Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, settingsListener, prefs));
setCaseSensitive(prefs.getBoolean(SimpleValueNames.COMPLETION_CASE_SENSITIVE, false));
setAutoPopup(prefs.getBoolean(SimpleValueNames.COMPLETION_AUTO_POPUP, false));
}
}
示例8: getPreferences
import java.util.prefs.Preferences; //导入方法依赖的package包/类
private Preferences getPreferences() {
Preferences prefs = prefsCache.get();
if (prefs == null) {
prefs = ProjectUtils.getPreferences(project, MissingModuleProblemsProvider.class, true);
if (prefsCache.compareAndSet(null, prefs)) {
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
}
}
return prefs;
}
示例9: testAddPreferenceChangeListener
import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testAddPreferenceChangeListener() throws BackingStoreException, InterruptedException {
final Preferences pref = getPreferencesNode();
PreferenceChangeListener l = new PreferenceChangeListener() {
public void preferenceChange(PreferenceChangeEvent evt) {
synchronized (TestPreferences.class) {
//assertionerrors cause deadlock here
assertSame(pref, evt.getNode());
assertEquals("key", evt.getKey());
assertEquals(evt.getNewValue(),pref.get(evt.getKey(),null), evt.getNewValue());
TestPreferences.class.notifyAll();
}
}
};
pref.addPreferenceChangeListener(l);
try {
synchronized (TestPreferences.class) {
pref.put("key","AddPreferenceChangeListener");
pref.flush();
TestPreferences.class.wait();
}
synchronized (TestPreferences.class) {
pref.remove("key");
pref.flush();
TestPreferences.class.wait();
}
synchronized (TestPreferences.class) {
pref.put("key","AddPreferenceChangeListener2");
pref.flush();
TestPreferences.class.wait();
}
} finally {
pref.removePreferenceChangeListener(l);
}
}
示例10: PrefMonitorInt
import java.util.prefs.Preferences; //导入方法依赖的package包/类
PrefMonitorInt(String name, int dflt) {
super(name);
this.dflt = dflt;
this.value = dflt;
Preferences prefs = AppPreferences.getPrefs();
set(Integer.valueOf(prefs.getInt(name, dflt)));
prefs.addPreferenceChangeListener(this);
}
示例11: testSeeInheritedEvents
import java.util.prefs.Preferences; //导入方法依赖的package包/类
/**
* Checks that events for values that are not overriden
* are propagated even from the inherited store
*/
public void testSeeInheritedEvents() throws Exception {
Preferences stored = new MapPreferences();
Preferences inherited = new MapPreferences();
inherited.putInt("intValue", 100);
MemoryPreferences mem = MemoryPreferences.getWithInherited(this, inherited, stored);
Preferences test = mem.getPreferences();
PL pl = new PL();
test.addPreferenceChangeListener(pl);
// add
pl.arm();
inherited.put("newValue", "baa");
pl.waitEvent();
assertEquals(1, pl.changeCount);
assertEquals("newValue", pl.key);
assertEquals("baa", pl.value);
// change
pl.arm();
inherited.putInt("intValue", 3);
pl.waitEvent();
assertEquals(2, pl.changeCount);
assertEquals("intValue", pl.key);
assertEquals("3", pl.value);
// remove not inherited
pl.arm();
inherited.remove("newValue");
pl.waitEvent();
assertEquals(3, pl.changeCount);
assertEquals("newValue", pl.key);
assertEquals(null, pl.value);
}
示例12: PrefMonitorDouble
import java.util.prefs.Preferences; //导入方法依赖的package包/类
PrefMonitorDouble(String name, double dflt) {
super(name);
this.dflt = dflt;
this.value = dflt;
Preferences prefs = AppPreferences.getPrefs();
set(Double.valueOf(prefs.getDouble(name, dflt)));
prefs.addPreferenceChangeListener(this);
}
示例13: testEvents142723
import java.util.prefs.Preferences; //导入方法依赖的package包/类
@RandomlyFails
public void testEvents142723() throws Exception {
Preferences prefsA = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
Preferences prefsB = MimeLookup.getLookup(MimePath.parse("text/x-testA")).lookup(Preferences.class);
String key1 = "all-lang-key-" + getName();
prefsA.put(key1, "xyz");
assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null));
// attach listeners
L listenerA = new L();
prefsA.addPreferenceChangeListener(listenerA);
L listenerB = new L();
prefsB.addPreferenceChangeListener(listenerB);
// putting the same value again should not fire an event
prefsA.put(key1, "xyz");
assertEquals("'" + key1 + "' has wrong value", "xyz", prefsA.get(key1, null));
assertEquals("There should be no events from prefsA", 0, listenerA.count);
assertEquals("'" + key1 + "' should inherit the value", "xyz", prefsB.get(key1, null));
assertEquals("There should be no events from prefsB", 0, listenerB.count);
// putting the same value again should not fire an event
prefsB.put(key1, "xyz");
assertEquals("'" + key1 + "' has wrong value in prefsB", "xyz", prefsB.get(key1, null));
assertEquals("There should still be no events from prefsB", 0, listenerB.count);
}
示例14: testEvents1
import java.util.prefs.Preferences; //导入方法依赖的package包/类
public void testEvents1() throws Exception {
Preferences prefsA = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
L listenerA = new L();
prefsA.addPreferenceChangeListener(listenerA);
Preferences prefsB = MimeLookup.getLookup(MimePath.parse("text/x-testA")).lookup(Preferences.class);
L listenerB = new L();
prefsB.addPreferenceChangeListener(listenerB);
assertNotNull("'simple-value-setting-A' should not be null", prefsA.get("simple-value-setting-A", null));
assertNotNull("'simple-value-setting-A' should not be null", prefsB.get("simple-value-setting-A", null));
assertEquals("Wrong value for 'testA-1-setting-1'", "value-of-testA-1-setting-1", prefsB.get("testA-1-setting-1", null));
assertEquals("There should be no A events", 0, listenerA.count);
assertEquals("There should be no B events", 0, listenerB.count);
prefsA.put("simple-value-setting-A", "new-value");
assertEquals("Wrong value for 'simple-value-setting-A'", "new-value", prefsA.get("simple-value-setting-A", null));
assertEquals("The value for 'simple-value-setting-A' was not propagated", "new-value", prefsB.get("simple-value-setting-A", null));
Thread.sleep(500);
assertEquals("Wrong number of A events", 1, listenerA.count);
assertEquals("Wrong setting name in the A event", "simple-value-setting-A", listenerA.lastEvent.getKey());
assertEquals("Wrong setting value in the A event", "new-value", listenerA.lastEvent.getNewValue());
assertSame("Wrong Preferences instance in the A event", prefsA, listenerA.lastEvent.getNode());
assertEquals("Wrong number of B events", 1, listenerB.count);
assertEquals("Wrong setting name in the B event", "simple-value-setting-A", listenerB.lastEvent.getKey());
assertEquals("Wrong setting value in the B event", "new-value", listenerB.lastEvent.getNewValue());
assertSame("Wrong Preferences instance in the B event", prefsB, listenerB.lastEvent.getNode());
}
示例15: testSeeStoredEvents
import java.util.prefs.Preferences; //导入方法依赖的package包/类
/**
* Checks that puts to the direct store is refired
*/
public void testSeeStoredEvents() throws Exception {
Preferences stored = new MapPreferences();
Preferences inherited = new MapPreferences();
inherited.putInt("intValue", 100);
stored.putInt("intValue", 2);
stored.putBoolean("toBeRemoved", Boolean.TRUE);
MemoryPreferences mem = MemoryPreferences.getWithInherited(this, inherited, stored);
Preferences test = mem.getPreferences();
PL pl = new PL();
test.addPreferenceChangeListener(pl);
// add
pl.arm();
stored.put("newValue", "baa");
pl.waitEvent();
assertEquals(1, pl.changeCount);
assertEquals("newValue", pl.key);
assertEquals("baa", pl.value);
// change
pl.arm();
stored.putInt("intValue", 3);
pl.waitEvent();
assertEquals(2, pl.changeCount);
assertEquals("intValue", pl.key);
assertEquals("3", pl.value);
// remove not inherited
pl.arm();
stored.remove("newValue");
pl.waitEvent();
assertEquals(3, pl.changeCount);
assertEquals("newValue", pl.key);
assertEquals(null, pl.value);
// remove inherited
pl.arm();
stored.remove("intValue");
pl.waitEvent();
assertEquals(4, pl.changeCount);
assertEquals("intValue", pl.key);
assertEquals("100", pl.value);
}