Search in sources :

Example 16 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project robovm by robovm.

the class PropertyChangeSupportTest method testEventsFilteredByProxies.

public void testEventsFilteredByProxies() {
    Object bean = new Object();
    PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
    PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);
    PropertyChangeEvent eventC = new PropertyChangeEvent(bean, "c", false, true);
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog all = new EventLog();
    support.addPropertyChangeListener(all);
    EventLog proxiedA = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));
    EventLog addA = new EventLog();
    support.addPropertyChangeListener("a", addA);
    EventLog addAProxiedB = new EventLog();
    support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
    EventLog proxiedAB = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("b", proxiedAB)));
    EventLog proxiedAA = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("a", proxiedAA)));
    EventLog proxiedAAC = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("c", proxiedAAC))));
    support.firePropertyChange(eventA);
    support.firePropertyChange(eventB);
    support.firePropertyChange(eventC);
    assertEquals(Arrays.asList(eventA, eventB, eventC), all.log);
    assertEquals(Arrays.asList(eventA), proxiedA.log);
    assertEquals(Arrays.asList(eventA), addA.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), addAProxiedB.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAB.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(eventA), proxiedAA.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAAC.log);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Example 17 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project robovm by robovm.

the class PropertyChangeSupportTest method testAddingOneListenerTwice.

public void testAddingOneListenerTwice() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog log = new EventLog();
    support.addPropertyChangeListener("a", log);
    support.addPropertyChangeListener(log);
    support.addPropertyChangeListener(log);
    support.addPropertyChangeListener("a", log);
    PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
    PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);
    support.firePropertyChange(eventA);
    support.firePropertyChange(eventB);
    assertEquals(Arrays.asList(eventA, eventA, eventA, eventA, eventB, eventB), log.log);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 18 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project robovm by robovm.

the class PropertyChangeSupportTest method testAddingAProxy.

public void testAddingAProxy() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    PropertyChangeListener listener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
        }
    };
    PropertyChangeListenerProxy proxy = new PropertyChangeListenerProxy("a", listener);
    support.addPropertyChangeListener("b", proxy);
    // this proxy sets us up to receive 'b' events
    PropertyChangeListenerProxy p1 = (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
    assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
    assertEquals("b", p1.getPropertyName());
    // this proxy sets us up to receive 'a' events
    PropertyChangeListenerProxy p2 = (PropertyChangeListenerProxy) p1.getListener();
    assertEquals(PropertyChangeListenerProxy.class, p2.getClass());
    assertEquals("a", p2.getPropertyName());
    assertEquals(listener, p2.getListener());
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(java.beans.PropertyChangeSupport) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Example 19 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project robovm by robovm.

the class PropertyChangeSupportTest method testRemoveWithProxies.

/**
     * Test that we need to do our own equals() work to manually unwrap an
     * arbitrary number of proxies.
     */
public void testRemoveWithProxies() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog all = new EventLog();
    support.addPropertyChangeListener(all);
    assertEquals(1, support.getPropertyChangeListeners().length);
    EventLog proxiedA = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));
    assertEquals(2, support.getPropertyChangeListeners().length);
    EventLog addA = new EventLog();
    support.addPropertyChangeListener("a", addA);
    assertEquals(3, support.getPropertyChangeListeners().length);
    EventLog addAProxiedB = new EventLog();
    support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
    assertEquals(4, support.getPropertyChangeListeners().length);
    EventLog proxiedAB = new EventLog();
    PropertyChangeListenerProxy proxyAB = new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("b", proxiedAB));
    support.addPropertyChangeListener(proxyAB);
    assertEquals(5, support.getPropertyChangeListeners().length);
    EventLog proxiedAAC = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("c", proxiedAAC))));
    assertEquals(6, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(all);
    assertEquals(5, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener("a", proxiedA);
    assertEquals(4, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", addA));
    assertEquals(3, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
    assertEquals(2, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(proxyAB);
    assertEquals(1, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(proxiedAAC);
    support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedAAC));
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("c", proxiedAAC));
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("c", new PropertyChangeListenerProxy("a", proxiedAAC)));
    assertEquals(1, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("c", proxiedAAC)));
    assertEquals(0, support.getPropertyChangeListeners().length);
}
Also used : PropertyChangeSupport(java.beans.PropertyChangeSupport) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Example 20 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project jdk8u_jdk by JetBrains.

the class Component method firePropertyChange.

/**
     * Support for reporting bound property changes for integer properties.
     * This method can be called when a bound property has changed and it will
     * send the appropriate PropertyChangeEvent to any registered
     * PropertyChangeListeners.
     *
     * @param propertyName the property whose value has changed
     * @param oldValue the property's previous value
     * @param newValue the property's new value
     * @since 1.4
     */
protected void firePropertyChange(String propertyName, int oldValue, int newValue) {
    PropertyChangeSupport changeSupport = this.changeSupport;
    if (changeSupport == null || oldValue == newValue) {
        return;
    }
    changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
Also used : PropertyChangeSupport(java.beans.PropertyChangeSupport)

Aggregations

PropertyChangeSupport (java.beans.PropertyChangeSupport)22 PropertyChangeEvent (java.beans.PropertyChangeEvent)10 PropertyChangeListener (java.beans.PropertyChangeListener)6 PropertyChangeListenerProxy (java.beans.PropertyChangeListenerProxy)4 HttpResponse (com.microsoft.azure.hdinsight.sdk.common.HttpResponse)2 IOException (java.io.IOException)2 UISettings (com.intellij.ide.ui.UISettings)1 UISettingsListener (com.intellij.ide.ui.UISettingsListener)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 Server (com.nimbusbase.nimbusbase.Server)1 SystemTray (java.awt.SystemTray)1 TrayIcon (java.awt.TrayIcon)1 Window (java.awt.Window)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 InvocationEvent (java.awt.event.InvocationEvent)1 VetoableChangeListener (java.beans.VetoableChangeListener)1 VetoableChangeSupport (java.beans.VetoableChangeSupport)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1