类java.beans.VetoableChangeListener源码实例Demo

下面列出了怎么用java.beans.VetoableChangeListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: astor   文件: EventListenerSupportTest.java
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());
}
 
/**
 * 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;
    }
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: BeanContextSupport.java
/**
 * 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);
         }
    };
}
 
源代码4 项目: jdk8u-jdk   文件: TestSerialization.java
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);
}
 
源代码5 项目: astor   文件: EventUtilsTest.java
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());
    }
}
 
源代码6 项目: openjdk-jdk9   文件: JComponentOperator.java
/**
 * 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);
        }
    });
}
 
源代码7 项目: astor   文件: EventListenerSupportTest.java
@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);
}
 
源代码8 项目: netbeans   文件: FileSystem.java
/** 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);
    }
}
 
源代码9 项目: jdk8u-jdk   文件: BeanContextSupport.java
/**
 * 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);
         }
    };
}
 
源代码10 项目: Java8CN   文件: BeanContextSupport.java
/**
 * 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);
         }
    };
}
 
源代码11 项目: astor   文件: EventListenerSupportTest.java
private void addDeregisterListener(final EventListenerSupport<VetoableChangeListener> listenerSupport)
{
    listenerSupport.addListener(new VetoableChangeListener()
    {
        @Override
        public void vetoableChange(PropertyChangeEvent e)
        {
            listenerSupport.removeListener(this);
        }
    });
}
 
源代码12 项目: TencentKona-8   文件: TestSerialization.java
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);
}
 
源代码13 项目: gemfirexd-oss   文件: VetoableChangeMulticaster.java
/**
 * 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;

}
 
源代码14 项目: astor   文件: EventListenerSupportTest.java
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);
    }
 
源代码15 项目: openjdk-8   文件: BeanContextSupport.java
/**
 * 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);
         }
    };
}
 
源代码16 项目: gemfirexd-oss   文件: VetoableChangeMulticaster.java
/**
 * 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;

}
 
源代码17 项目: hottub   文件: TestSerialization.java
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);
}
 
源代码18 项目: astor   文件: EventListenerSupportTest.java
@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);
}
 
源代码19 项目: jdk8u-dev-jdk   文件: BeanContextSupport.java
/**
 * 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);
         }
    };
}
 
源代码20 项目: openjdk-8-source   文件: BeanContextSupport.java
/**
 * 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;
    }
}
 
源代码21 项目: openjdk-jdk8u-backup   文件: TestSerialization.java
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);
}
 
源代码22 项目: netbeans   文件: MultiViewEditorDiscardTest.java
/** Removes veto listener.
 */
@Override
public void removeVetoableChangeListener(VetoableChangeListener l) {
}
 
public synchronized void addVetoableChangeListener(VetoableChangeListener l) {
    assertNull ("This is the first veto listener", vetoL);
    vetoL = l;
}
 
源代码24 项目: netbeans   文件: IONotifier.java
public static void removeVetoableChangeListener(InputOutput io, VetoableChangeListener listener ) {
IONotifier ion = find(io);
if (ion != null)
    ion.removeVetoableChangeListener(listener);
   }
 
源代码25 项目: netbeans   文件: VetoSystemOption.java
/** Remove a veto listener from all instances of this exact class.
* @param list the listener to remove
*/
public final void removeVetoableChangeListener(VetoableChangeListener list) {
    synchronized (getLock()) {
        getVeto().remove(list);
    }
}
 
源代码26 项目: netbeans   文件: CloneableEditor143143Test.java
public void removeVetoableChangeListener(VetoableChangeListener l) {
    assertEquals ("Removing the right veto one", vetoL, l);
    vetoL = null;
}
 
源代码27 项目: MeteoInfo   文件: AbstractBean.java
public final void removeVetoableChangeListener(VetoableChangeListener listener) {
    this.vcs.removeVetoableChangeListener(listener);
}
 
源代码28 项目: netbeans   文件: Deadlock207571Test.java
public void removeVetoableChangeListener(VetoableChangeListener l) {
    assertEquals ("Removing the right veto one", vetoL, l);
    vetoL = null;
}
 
源代码29 项目: astor   文件: EventListenerSupportTest.java
@Test(expected=NullPointerException.class)
public void testRemoveNullListener()
{
    EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
    listenerSupport.removeListener(null);
}
 
源代码30 项目: netbeans   文件: ReloadTest.java
public void removeVetoableChangeListener(VetoableChangeListener l) {
    assertEquals ("Removing the right veto one", vetoL, l);
    vetoL = null;
}
 
 类所在包
 类方法
 同包方法