java.beans.VetoableChangeListener Java Examples

The following examples show how to use java.beans.VetoableChangeListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testGetListeners() {
    final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);

    VetoableChangeListener[] listeners = listenerSupport.getListeners();
    assertEquals(0, listeners.length);
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    VetoableChangeListener[] empty = listeners;
    //for fun, show that the same empty instance is used 
    assertSame(empty, listenerSupport.getListeners());

    VetoableChangeListener listener1 = EasyMock.createNiceMock(VetoableChangeListener.class);
    listenerSupport.addListener(listener1);
    assertEquals(1, listenerSupport.getListeners().length);
    VetoableChangeListener listener2 = EasyMock.createNiceMock(VetoableChangeListener.class);
    listenerSupport.addListener(listener2);
    assertEquals(2, listenerSupport.getListeners().length);
    listenerSupport.removeListener(listener1);
    assertEquals(1, listenerSupport.getListeners().length);
    listenerSupport.removeListener(listener2);
    assertSame(empty, listenerSupport.getListeners());
}
 
Example #2
Source File: TestSerialization.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void check(VetoableChangeSupport vcs) {
    VetoableChangeListener[] namedListeners = vcs.getVetoableChangeListeners(NAME);
    check(namedListeners, 1);
    check(namedListeners[0], 1);

    VetoableChangeListener[] allListeners = vcs.getVetoableChangeListeners();
    check(allListeners, 2);
    check(allListeners[0], 0);
    check(allListeners[1], 1, NAME);
}
 
Example #3
Source File: BeanContextSupport.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * protected method called from constructor and readObject to initialize
 * transient state of BeanContextSupport instance.
 *
 * This class uses this method to instantiate inner class listeners used
 * to monitor PropertyChange and VetoableChange events on children.
 *
 * subclasses may envelope this method to add their own initialization
 * behavior
 */

protected synchronized void initialize() {
    children     = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);

    childPCL = new PropertyChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * property changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };

    childVCL = new VetoableChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * vetoable changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
         }
    };
}
 
Example #4
Source File: VetoableChangeMulticaster.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an occurrence of a VetoableChangeListener from the listener list.
 * It removes at most one occurrence of the given listener.
 * If the listener was added multiple times it must be removed
 * mulitple times.
 * This removes a VetoableChangeListener that was registered
 * for all properties, and has no effect if registered for only
 * one or more specified properties.
 *
 * @param listener  The VetoableChangeListener to be removed
 */

public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {

  int newlen = listeners.length-1;
  if (newlen < 0 || listener == null) return;

  // Copy while searching for element to remove

  VetoableChangeListener[] newArray = new VetoableChangeListener[newlen];

  for (int i = 0; i < newlen; ++i) { 
    if (listener.equals(listeners[i])) {
      //  copy remaining and exit
      for (int k = i + 1; k <= newlen; ++k) newArray[k-1] = listeners[k];
      listeners = newArray;
      return;
    }
    else
      newArray[i] = listeners[i];
  }
  
  // special-case last cell
  if (listener.equals(listeners[newlen]))
    listeners = newArray;

}
 
Example #5
Source File: TestSerialization.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void check(VetoableChangeSupport vcs) {
    VetoableChangeListener[] namedListeners = vcs.getVetoableChangeListeners(NAME);
    check(namedListeners, 1);
    check(namedListeners[0], 1);

    VetoableChangeListener[] allListeners = vcs.getVetoableChangeListeners();
    check(allListeners, 2);
    check(allListeners[0], 0);
    check(allListeners[1], 1, NAME);
}
 
Example #6
Source File: BeanContextSupport.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * protected method called from constructor and readObject to initialize
 * transient state of BeanContextSupport instance.
 *
 * This class uses this method to instantiate inner class listeners used
 * to monitor PropertyChange and VetoableChange events on children.
 *
 * subclasses may envelope this method to add their own initialization
 * behavior
 */

protected synchronized void initialize() {
    children     = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);

    childPCL = new PropertyChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * property changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };

    childVCL = new VetoableChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * vetoable changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
         }
    };
}
 
Example #7
Source File: FileSystem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Adds listener for the veto of property change.
* @param listener the listener
*/
public final void addVetoableChangeListener(VetoableChangeListener listener) {
    synchronized (internLock) {
        if (vetoableChangeList == null) {
            vetoableChangeList = new ListenerList<VetoableChangeListener>();
        }

        vetoableChangeList.add(listener);
    }
}
 
Example #8
Source File: BeanContextSupport.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * protected method called from constructor and readObject to initialize
 * transient state of BeanContextSupport instance.
 *
 * This class uses this method to instantiate inner class listeners used
 * to monitor PropertyChange and VetoableChange events on children.
 *
 * subclasses may envelope this method to add their own initialization
 * behavior
 */

protected synchronized void initialize() {
    children     = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);

    childPCL = new PropertyChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * property changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };

    childVCL = new VetoableChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * vetoable changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
         }
    };
}
 
Example #9
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
    EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.addListener(new VetoableChangeListener() {
        
        @Override
        public void vetoableChange(PropertyChangeEvent e) {
        }
    });
    listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));

    //serialize:
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

    objectOutputStream.writeObject(listenerSupport);
    objectOutputStream.close();

    //deserialize:
    @SuppressWarnings("unchecked")
    EventListenerSupport<VetoableChangeListener> deserializedListenerSupport = (EventListenerSupport<VetoableChangeListener>) new ObjectInputStream(
            new ByteArrayInputStream(outputStream.toByteArray())).readObject();

    //make sure we get a listener array back, of the correct component type, and that it contains only the serializable mock
    VetoableChangeListener[] listeners = deserializedListenerSupport.getListeners();
    assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
    assertEquals(1, listeners.length);

    //now verify that the mock still receives events; we can infer that the proxy was correctly reconstituted
    VetoableChangeListener listener = listeners[0];
    PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
    listener.vetoableChange(evt);
    EasyMock.replay(listener);
    deserializedListenerSupport.fire().vetoableChange(evt);
    EasyMock.verify(listener);

    //remove listener and verify we get an empty array of listeners
    deserializedListenerSupport.removeListener(listener);
    assertEquals(0, deserializedListenerSupport.getListeners().length);
}
 
Example #10
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testEventDispatchOrder() throws PropertyVetoException
{
    final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    final List<VetoableChangeListener> calledListeners = new ArrayList<VetoableChangeListener>();

    final VetoableChangeListener listener1 = createListener(calledListeners);
    final VetoableChangeListener listener2 = createListener(calledListeners);
    listenerSupport.addListener(listener1);
    listenerSupport.addListener(listener2);
    listenerSupport.fire().vetoableChange(new PropertyChangeEvent(new Date(), "Day", 4, 5));
    assertEquals(calledListeners.size(), 2);
    assertSame(calledListeners.get(0), listener1);
    assertSame(calledListeners.get(1), listener2);
}
 
Example #11
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSubclassInvocationHandling() throws PropertyVetoException {

        @SuppressWarnings("serial")
        EventListenerSupport<VetoableChangeListener> eventListenerSupport = new EventListenerSupport<VetoableChangeListener>(
                VetoableChangeListener.class) {
            protected java.lang.reflect.InvocationHandler createInvocationHandler() {
                return new ProxyInvocationHandler() {
                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args)
                            throws Throwable {
                        return "vetoableChange".equals(method.getName())
                                && "Hour".equals(((PropertyChangeEvent) args[0]).getPropertyName()) ? null
                                : super.invoke(proxy, method, args);
                    }
                };
            };
        };

        VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
        eventListenerSupport.addListener(listener);
        Object source = new Date();
        PropertyChangeEvent ignore = new PropertyChangeEvent(source, "Hour", 5, 6);
        PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
        listener.vetoableChange(respond);
        EasyMock.replay(listener);
        eventListenerSupport.fire().vetoableChange(ignore);
        eventListenerSupport.fire().vetoableChange(respond);
        EasyMock.verify(listener);
    }
 
Example #12
Source File: JComponentOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps
 * {@code JComponent.removeVetoableChangeListener(VetoableChangeListener)}
 * through queue
 */
public void removeVetoableChangeListener(final VetoableChangeListener vetoableChangeListener) {
    runMapping(new MapVoidAction("removeVetoableChangeListener") {
        @Override
        public void map() {
            ((JComponent) getSource()).removeVetoableChangeListener(vetoableChangeListener);
        }
    });
}
 
Example #13
Source File: BeanContextSupport.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * protected method called from constructor and readObject to initialize
 * transient state of BeanContextSupport instance.
 *
 * This class uses this method to instantiate inner class listeners used
 * to monitor PropertyChange and VetoableChange events on children.
 *
 * subclasses may envelope this method to add their own initialization
 * behavior
 */

protected synchronized void initialize() {
    children     = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);

    childPCL = new PropertyChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * property changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };

    childVCL = new VetoableChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * vetoable changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
         }
    };
}
 
Example #14
Source File: EventUtilsTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testAddEventListenerWithPrivateAddMethod()
{
    final PropertyChangeSource src = new PropertyChangeSource();
    EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class);
    try
    {
        EventUtils.addEventListener(src, VetoableChangeListener.class, listener);
        fail("Should not be allowed to add a listener to an object that doesn't support it.");
    }
    catch (IllegalArgumentException e)
    {
        assertEquals("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".", e.getMessage());
    }
}
 
Example #15
Source File: EventListenerSupportTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void addDeregisterListener(final EventListenerSupport<VetoableChangeListener> listenerSupport)
{
    listenerSupport.addListener(new VetoableChangeListener()
    {
        @Override
        public void vetoableChange(PropertyChangeEvent e)
        {
            listenerSupport.removeListener(this);
        }
    });
}
 
Example #16
Source File: TestSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void check(VetoableChangeSupport vcs) {
    VetoableChangeListener[] namedListeners = vcs.getVetoableChangeListeners(NAME);
    check(namedListeners, 1);
    check(namedListeners[0], 1);

    VetoableChangeListener[] allListeners = vcs.getVetoableChangeListeners();
    check(allListeners, 2);
    check(allListeners[0], 0);
    check(allListeners[1], 1, NAME);
}
 
Example #17
Source File: BeanContextSupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * protected method called from constructor and readObject to initialize
 * transient state of BeanContextSupport instance.
 *
 * This class uses this method to instantiate inner class listeners used
 * to monitor PropertyChange and VetoableChange events on children.
 *
 * subclasses may envelope this method to add their own initialization
 * behavior
 */

protected synchronized void initialize() {
    children     = new HashMap(serializable + 1);
    bcmListeners = new ArrayList(1);

    childPCL = new PropertyChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * property changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void propertyChange(PropertyChangeEvent pce) {
            BeanContextSupport.this.propertyChange(pce);
        }
    };

    childVCL = new VetoableChangeListener() {

        /*
         * this adaptor is used by the BeanContextSupport class to forward
         * vetoable changes from a child to the BeanContext, avoiding
         * accidential serialization of the BeanContext by a badly
         * behaved Serializable child.
         */

        public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
            BeanContextSupport.this.vetoableChange(pce);
         }
    };
}
 
Example #18
Source File: BeanContextSupport.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the VetoableChangeListener
 * (if any) of the specified child
 * @param child the specified child
 * @return the VetoableChangeListener (if any) of the specified child
 */
protected static final VetoableChangeListener getChildVetoableChangeListener(Object child) {
    try {
        return (VetoableChangeListener)child;
    } catch (ClassCastException cce) {
        return null;
    }
}
 
Example #19
Source File: BeanContextSupport.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the VetoableChangeListener
 * (if any) of the specified child
 * @param child the specified child
 * @return the VetoableChangeListener (if any) of the specified child
 */
protected static final VetoableChangeListener getChildVetoableChangeListener(Object child) {
    try {
        return (VetoableChangeListener)child;
    } catch (ClassCastException cce) {
        return null;
    }
}
 
Example #20
Source File: TestSerialization.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void check(VetoableChangeSupport vcs) {
    VetoableChangeListener[] namedListeners = vcs.getVetoableChangeListeners(NAME);
    check(namedListeners, 1);
    check(namedListeners[0], 1);

    VetoableChangeListener[] allListeners = vcs.getVetoableChangeListeners();
    check(allListeners, 2);
    check(allListeners[0], 0);
    check(allListeners[1], 1, NAME);
}
 
Example #21
Source File: VetoableChangeMulticaster.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an occurrence of a VetoableChangeListener from the listener list.
 * It removes at most one occurrence of the given listener.
 * If the listener was added multiple times it must be removed
 * mulitple times.
 * This removes a VetoableChangeListener that was registered
 * for all properties, and has no effect if registered for only
 * one or more specified properties.
 *
 * @param listener  The VetoableChangeListener to be removed
 */

public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {

  int newlen = listeners.length-1;
  if (newlen < 0 || listener == null) return;

  // Copy while searching for element to remove

  VetoableChangeListener[] newArray = new VetoableChangeListener[newlen];

  for (int i = 0; i < newlen; ++i) { 
    if (listener.equals(listeners[i])) {
      //  copy remaining and exit
      for (int k = i + 1; k <= newlen; ++k) newArray[k-1] = listeners[k];
      listeners = newArray;
      return;
    }
    else
      newArray[i] = listeners[i];
  }
  
  // special-case last cell
  if (listener.equals(listeners[newlen]))
    listeners = newArray;

}
 
Example #22
Source File: CloneableEditorSupportDoubleSaveTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void removeVetoableChangeListener(VetoableChangeListener l) {
    assertEquals ("Removing the right veto one", vetoL, l);
    vetoL = null;
}
 
Example #23
Source File: TestListeners.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example #24
Source File: DockDelegate.java    From bigtable-sql with Apache License 2.0 4 votes vote down vote up
public void addVetoableChangeListener(VetoableChangeListener vetoableChangeListener)
{
   //To change body of implemented methods use File | Settings | File Templates.
}
 
Example #25
Source File: EventUtilsTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
protected void addVetoableChangeListener(final VetoableChangeListener listener)
{
    // Do nothing!
}
 
Example #26
Source File: TestListeners.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example #27
Source File: TestListeners.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws PropertyVetoException {
    VetoableChangeSupport vcs = new VetoableChangeSupport(TestListeners.class);
    vcs.addVetoableChangeListener(new TestListeners(0));
    vcs.addVetoableChangeListener(NAME, new TestListeners(2));
    vcs.addVetoableChangeListener(new TestListeners(1));
    vcs.addVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));


    current = 0;
    vcs.fireVetoableChange(NAME, 0, 1);
    if (current != 4)
        throw new Error("Expected 4 listeners, but called " + current);

    current = 0;
    vcs.fireVetoableChange(NONE, 1, 0);
    if (current != 2)
        throw new Error("Expected 2 listeners, but called " + current);


    VetoableChangeListener[] all = vcs.getVetoableChangeListeners();
    if (all.length != 4)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    VetoableChangeListener[] named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 2)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    VetoableChangeListener[] other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);

    vcs.removeVetoableChangeListener(new TestListeners(0));
    vcs.removeVetoableChangeListener(new TestListeners(1));
    vcs.removeVetoableChangeListener(NAME, new TestListeners(2));
    vcs.removeVetoableChangeListener(NAME, new VetoableChangeListenerProxy(NAME, new TestListeners(3)));

    all = vcs.getVetoableChangeListeners();
    if (all.length != 0)
        throw new Error("Expected 4 listeners, but contained " + all.length);

    named = vcs.getVetoableChangeListeners(NAME);
    if (named.length != 0)
        throw new Error("Expected 2 named listeners, but contained " + named.length);

    other = vcs.getVetoableChangeListeners(NONE);
    if (other.length != 0)
        throw new Error("Expected 0 other listeners, but contained " + other.length);
}
 
Example #28
Source File: Test7148143.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    VetoableChangeListener listener = new CustomProxy();
    VetoableChangeSupport support = new VetoableChangeSupport(listener);
    support.addVetoableChangeListener(listener);
    support.addVetoableChangeListener("foo", listener); // cast class exception
}
 
Example #29
Source File: OpenSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Removes veto listener.
 */
public void removeVetoableChangeListener(VetoableChangeListener l) {
    veto ().removeVetoableChangeListener (l);
}
 
Example #30
Source File: MultiViewEditorCloneTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Removes veto listener.
 */
@Override
public void removeVetoableChangeListener(VetoableChangeListener l) {
}