Search in sources :

Example 6 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project simplejpa by appoxy.

the class BeansCglib method newInstance.

public static Object newInstance(Class clazz) {
    try {
        BeansCglib interceptor = new BeansCglib();
        Enhancer e = new Enhancer();
        e.setSuperclass(clazz);
        e.setCallback(interceptor);
        Object bean = e.create();
        interceptor.propertySupport = new PropertyChangeSupport(bean);
        return bean;
    } catch (Throwable e) {
        e.printStackTrace();
        throw new Error(e.getMessage());
    }
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 7 with PropertyChangeSupport

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

the class TestPropertyChangeSupport method test.

private static void test(int step, int listeners, int attempts) {
    TestPropertyChangeSupport test = new TestPropertyChangeSupport();
    PropertyChangeSupport pcs = new PropertyChangeSupport(test);
    PropertyChangeEvent eventNull = new PropertyChangeEvent(test, null, null, null);
    PropertyChangeEvent eventName = new PropertyChangeEvent(test, NAME, null, null);
    long time1 = System.currentTimeMillis();
    for (int i = 0; i < listeners; i++) {
        pcs.addPropertyChangeListener(test);
        pcs.addPropertyChangeListener(NAME, test);
    }
    long time2 = System.currentTimeMillis();
    for (int i = 0; i < attempts; i++) {
        pcs.firePropertyChange(eventNull);
        pcs.firePropertyChange(eventName);
    }
    long time3 = System.currentTimeMillis();
    // time of adding the listeners
    time1 = time2 - time1;
    // time of firing the events
    time2 = time3 - time2;
    System.out.println("Step: " + step + "; Listeners: " + listeners + "; Attempts: " + attempts + "; Time (ms): " + time1 + "/" + time2);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport)

Example 8 with PropertyChangeSupport

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

the class Test4092905 method main.

public static void main(String[] args) {
    PropertyChangeSupport pcs = new PropertyChangeSupport(args);
    pcs.addPropertyChangeListener(PUBLIC, new PublicListener());
    pcs.addPropertyChangeListener(PRIVATE, new PrivateListener());
    if (!pcs.hasListeners(PUBLIC)) {
        throw new Error("no public listener");
    }
    if (!pcs.hasListeners(PRIVATE)) {
        throw new Error("no private listener");
    }
    try {
        // serialize into byte array
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream output = new ObjectOutputStream(baos);
        output.writeObject(pcs);
        output.flush();
        // deserialize from byte array
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream input = new ObjectInputStream(bais);
        pcs = (PropertyChangeSupport) input.readObject();
    } catch (Exception exception) {
        throw new Error("unexpected exception", exception);
    }
    if (!pcs.hasListeners(PUBLIC)) {
        throw new Error("no public listener");
    }
    if (pcs.hasListeners(PRIVATE)) {
        throw new Error("unexpected private listener");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PropertyChangeSupport(java.beans.PropertyChangeSupport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with PropertyChangeSupport

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

the class Test4985020 method main.

public static void main(String[] args) {
    PropertyChangeSupport pcs = new PropertyChangeSupport(args);
    VetoableChangeSupport vcs = new VetoableChangeSupport(args);
    Test4985020 listener = new Test4985020();
    //PropertyChangeSupport.addPropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.addPropertyChangeListener(null, listener)");
    try {
        pcs.addPropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.removePropertyChangeListener(null, listener)
    System.out.println("PropertyChangeSupport.removePropertyChangeListener(null, listener)");
    try {
        pcs.removePropertyChangeListener(null, listener);
        pcs.firePropertyChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.getPropertyChangeListeners(null)
    System.out.println("PropertyChangeSupport.getPropertyChangeListeners(null)");
    try {
        PropertyChangeListener[] pcls = pcs.getPropertyChangeListeners(null);
        if (pcls == null) {
            throw new Error("getPropertyChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getPropertyChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null)
    System.out.println("PropertyChangeSupport.hasListeners(null)");
    try {
        pcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //PropertyChangeSupport.hasListeners(null): with a generic listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a generic listener");
    try {
        pcs.addPropertyChangeListener(listener);
        if (!pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    pcs = new PropertyChangeSupport(args);
    //PropertyChangeSupport.hasListeners(null): with a specific listener
    System.out.println("PropertyChangeSupport.hasListeners(null) with a specific listener");
    try {
        pcs.addPropertyChangeListener(NAME, listener);
        if (pcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.addVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.addVetoableChangeListener(null, listener)");
    try {
        vcs.addVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.removeVetoableChangeListener(null, listener)
    System.out.println("VetoableChangeSupport.removeVetoableChangeListener(null, listener)");
    try {
        vcs.removeVetoableChangeListener(null, listener);
        vcs.fireVetoableChange(NAME, null, null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.getVetoableChangeListeners(null)
    System.out.println("VetoableChangeSupport.getVetoableChangeListeners(null)");
    try {
        VetoableChangeListener[] pcls = vcs.getVetoableChangeListeners(null);
        if (pcls == null) {
            throw new Error("getVetoableChangeListener() returned null");
        }
        if (pcls.length != 0) {
            throw new Error("getVetoableChangeListener() did not return an empty array");
        }
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null)
    System.out.println("VetoableChangeSupport.hasListeners(null)");
    try {
        boolean result = vcs.hasListeners(null);
    } catch (Throwable error) {
        print(error);
    }
    //VetoableChangeSupport.hasListeners(null): with a generic listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a generic listener");
    try {
        vcs.addVetoableChangeListener(listener);
        if (!vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned false, but there was a generic listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    // reset
    vcs = new VetoableChangeSupport(args);
    //VetoableChangeSupport.hasListeners(null): with a specific listener
    System.out.println("VetoableChangeSupport.hasListeners(null) with a specific listener");
    try {
        vcs.addVetoableChangeListener(NAME, listener);
        if (vcs.hasListeners(null)) {
            throw new Error("hasListeners(null) returned true, but there were no generic listeners - only a specific listener");
        }
    } catch (Throwable error) {
        print(error);
    }
    if (failed) {
        throw new Error("TEST FAILED");
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) VetoableChangeSupport(java.beans.VetoableChangeSupport) PropertyChangeSupport(java.beans.PropertyChangeSupport) VetoableChangeListener(java.beans.VetoableChangeListener)

Example 10 with PropertyChangeSupport

use of java.beans.PropertyChangeSupport in project tdi-studio-se by Talend.

the class Element method readObject.

// implemented in order to create listeners field
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    listeners = new PropertyChangeSupport(this);
}
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