當前位置: 首頁>>代碼示例>>Java>>正文


Java Preferences.addPreferenceChangeListener方法代碼示例

本文整理匯總了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;
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:23,代碼來源:AppPreferences.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:ProxyPreferencesImplTest.java

示例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();
        }
    });
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:17,代碼來源:PhotoManagerImpl.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:InheritedPreferences.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:DefaultFoldingOptions.java

示例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);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:8,代碼來源:PrefMonitorString.java

示例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));
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:GsfCompletionProvider.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:MissingModuleProblemsProvider.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:TestPreferences.java

示例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);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:9,代碼來源:PrefMonitorInt.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:41,代碼來源:ProxyPreferencesImplTest.java

示例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);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:9,代碼來源:PrefMonitorDouble.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:PreferencesTest.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:PreferencesTest.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:50,代碼來源:ProxyPreferencesImplTest.java


注:本文中的java.util.prefs.Preferences.addPreferenceChangeListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。