Search in sources :

Example 6 with PropertyChangeListenerProxy

use of java.beans.PropertyChangeListenerProxy 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 7 with PropertyChangeListenerProxy

use of java.beans.PropertyChangeListenerProxy 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 8 with PropertyChangeListenerProxy

use of java.beans.PropertyChangeListenerProxy 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)

Aggregations

PropertyChangeListenerProxy (java.beans.PropertyChangeListenerProxy)8 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeSupport (java.beans.PropertyChangeSupport)4 PropertyChangeListener (java.beans.PropertyChangeListener)2