Search in sources :

Example 1 with IndexedPropertyChangeEvent

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

the class Test4353056 method propertyChange.

public void propertyChange(PropertyChangeEvent event) {
    Object value = event.getNewValue();
    if (value.equals(event.getOldValue())) {
        throw new Error("new value is equal to old one");
    }
    if (!this.name.equals(event.getPropertyName())) {
        throw new Error("unexpected property name");
    } else if (this.name.equals(COLOR)) {
        if (!value.equals(this.color)) {
            throw new Error("unexpected object value");
        }
    } else if (this.name.equals(BOOLEAN)) {
        if (!value.equals(Boolean.valueOf(this.flag))) {
            throw new Error("unexpected boolean value");
        }
    } else if (this.name.equals(INTEGER)) {
        if (!value.equals(Integer.valueOf(this.value))) {
            throw new Error("unexpected integer value");
        }
    } else {
        throw new Error("unexpected property name");
    }
    if (event instanceof IndexedPropertyChangeEvent) {
        IndexedPropertyChangeEvent ipce = (IndexedPropertyChangeEvent) event;
        if (this.index != ipce.getIndex()) {
            throw new Error("unexpected property index");
        }
    } else {
        throw new Error("unexpected event type");
    }
    System.out.println(this.name + " at " + this.index + " is " + value);
    this.name = null;
    this.index = -1;
}
Also used : IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent)

Example 2 with IndexedPropertyChangeEvent

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

the class Test4498236 method main.

public static void main(String[] args) throws Exception {
    PropertyChangeEvent event = new PropertyChangeEvent("source", null, null, null);
    event.setPropagationId("id");
    test("[propertyName=null; oldValue=null; newValue=null; propagationId=id; source=source]", event);
    test("[propertyName=name; oldValue=old; newValue=new; propagationId=null; source=source]", new PropertyChangeEvent("source", "name", "old", "new"));
    test("[propertyName=array; index=5; oldValue=old; newValue=new; propagationId=null; source=source]", new IndexedPropertyChangeEvent("source", "array", "old", "new", 5));
    FeatureDescriptor fd = new FeatureDescriptor();
    fd.setName("n");
    fd.setDisplayName("dn");
    fd.setShortDescription("sd");
    fd.setPreferred(true);
    fd.setHidden(true);
    fd.setExpert(true);
    fd.setValue("first", "value");
    test("[name=n; displayName=dn; shortDescription=sd; preferred; hidden; expert; values={first=value}]", fd);
    test("[name=String; beanClass=class java.lang.String]", new BeanDescriptor(String.class));
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]", new BeanDescriptor(Object.class, String.class));
    test("[name=Object; beanClass=class java.lang.Object; customizerClass=class java.lang.String]", new BeanDescriptor(Object.class, String.class));
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object)]", new MethodDescriptor(Object.class.getMethod("equals", Object.class)));
    test("[name=equals; method=public boolean java.lang.Object.equals(java.lang.Object); parameterDescriptors={java.beans.ParameterDescriptor[name=null]}]", new MethodDescriptor(Object.class.getMethod("equals", Object.class), new ParameterDescriptor[] { new ParameterDescriptor() }));
    Class type = KeyListener.class;
    String[] names = { "keyTyped", "keyPressed", "keyReleased" };
    Method[] methods = new Method[names.length];
    for (int i = 0; i < names.length; i++) {
        methods[i] = type.getMethod(names[i], KeyEvent.class);
    }
    test("[name=key; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.getKeyListeners(); addListenerMethod=public void Test4498236.addKeyListener(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.removeKeyListener(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "key", type, names[0]));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove"));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor(Test4498236.class, "$$$", type, names, "add", "remove", "get"));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type)));
    test("[name=$$$; inDefaultEventSet; listenerType=interface java.awt.event.KeyListener; getListenerMethod=public java.awt.event.KeyListener Test4498236.get(); addListenerMethod=public void Test4498236.add(java.awt.event.KeyListener); removeListenerMethod=public void Test4498236.remove(java.awt.event.KeyListener)]", new EventSetDescriptor("$$$", type, methods, Test4498236.class.getMethod("add", type), Test4498236.class.getMethod("remove", type), Test4498236.class.getMethod("get")));
    test("[name=value; propertyType=boolean; readMethod=public boolean Test4498236.isValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("value", Test4498236.class));
    test("[name=$$$]", new PropertyDescriptor("$$$", Test4498236.class, null, null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]", new PropertyDescriptor("$$$", Test4498236.class, "getValue", null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("$$$", Test4498236.class, "getValue", "setValue"));
    test("[name=$$$]", new PropertyDescriptor("$$$", null, null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue()]", new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), null));
    test("[name=$$$; propertyType=boolean; readMethod=public boolean Test4498236.getValue(); writeMethod=public void Test4498236.setValue(boolean)]", new PropertyDescriptor("$$$", Test4498236.class.getMethod("getValue"), Test4498236.class.getMethod("setValue", boolean.class)));
    test("[name=index; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("index", Test4498236.class));
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("$$$", Test4498236.class, "getIndex", "setIndex", "getIndex", "setIndex"));
    test("[name=$$$; propertyType=class [I; readMethod=public int[] Test4498236.getIndex(); writeMethod=public void Test4498236.setIndex(int[]); indexedPropertyType=int; indexedReadMethod=public int Test4498236.getIndex(int); indexedWriteMethod=public void Test4498236.setIndex(int,int)]", new IndexedPropertyDescriptor("$$$", Test4498236.class.getMethod("getIndex"), Test4498236.class.getMethod("setIndex", new int[0].getClass()), Test4498236.class.getMethod("getIndex", int.class), Test4498236.class.getMethod("setIndex", int.class, int.class)));
}
Also used : IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) ParameterDescriptor(java.beans.ParameterDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor) KeyEvent(java.awt.event.KeyEvent) FeatureDescriptor(java.beans.FeatureDescriptor) BeanDescriptor(java.beans.BeanDescriptor) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent) KeyListener(java.awt.event.KeyListener) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor)

Example 3 with IndexedPropertyChangeEvent

use of java.beans.IndexedPropertyChangeEvent in project JMRI by JMRI.

the class ConstrainedArbitraryBean method setIndexedProperty.

@Override
public void setIndexedProperty(String key, int index, Object value) {
    try {
        this.fireVetoableChange(new IndexedPropertyChangeEvent(this, key, this.getIndexedProperty(key, index), value, index));
        if (Beans.hasIntrospectedIndexedProperty(this, key)) {
            Beans.setIntrospectedIndexedProperty(this, key, index, value);
        } else {
            Object oldValue = this.arbitraryPropertySupport.getIndexedProperty(key, index);
            this.arbitraryPropertySupport.setIndexedProperty(key, index, value);
            this.fireIndexedPropertyChange(key, index, oldValue, value);
        }
    } catch (PropertyVetoException ex) {
        // use the logger for the implementing class instead of a logger for ConstrainedBean
        LoggerFactory.getLogger(this.getClass().getName()).warn("Property {} change vetoed.", key, ex);
        // fire a property change that does not have the new value to indicate
        // to any other listeners that the property was "reset" back to its
        // orginal value as a result of the veto
        this.fireIndexedPropertyChange(key, index, getProperty(key), getProperty(key));
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent)

Example 4 with IndexedPropertyChangeEvent

use of java.beans.IndexedPropertyChangeEvent in project JMRI by JMRI.

the class ConstrainedBean method setIndexedProperty.

@Override
public void setIndexedProperty(String key, int index, Object value) {
    try {
        this.fireVetoableChange(new IndexedPropertyChangeEvent(this, key, this.getIndexedProperty(key, index), value, index));
        super.setIndexedProperty(key, index, value);
    } catch (PropertyVetoException ex) {
        // use the logger for the implementing class instead of a logger for ConstrainedBean
        LoggerFactory.getLogger(this.getClass().getName()).warn("Property {} change vetoed.", key, ex);
        // fire a property change that does not have the new value to indicate
        // to any other listeners that the property was "reset" back to its
        // orginal value as a result of the veto
        this.fireIndexedPropertyChange(key, index, getProperty(key), getProperty(key));
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) IndexedPropertyChangeEvent(java.beans.IndexedPropertyChangeEvent)

Aggregations

IndexedPropertyChangeEvent (java.beans.IndexedPropertyChangeEvent)4 PropertyVetoException (java.beans.PropertyVetoException)2 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 BeanDescriptor (java.beans.BeanDescriptor)1 EventSetDescriptor (java.beans.EventSetDescriptor)1 FeatureDescriptor (java.beans.FeatureDescriptor)1 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)1 MethodDescriptor (java.beans.MethodDescriptor)1 ParameterDescriptor (java.beans.ParameterDescriptor)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Method (java.lang.reflect.Method)1