下面列出了怎么用java.beans.VetoableChangeSupport的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener(false);
CheckListener second = new CheckListener(true);
CheckListener third = new CheckListener(false);
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
vcs.addVetoableChangeListener(first);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, true, false);
} catch (PropertyVetoException exception) {
first.validate();
second.validate();
third.validate();
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener(false);
CheckListener second = new CheckListener(true);
CheckListener third = new CheckListener(false);
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
vcs.addVetoableChangeListener(first);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, true, false);
} catch (PropertyVetoException exception) {
first.validate();
second.validate();
third.validate();
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener(false);
CheckListener second = new CheckListener(true);
CheckListener third = new CheckListener(false);
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
vcs.addVetoableChangeListener(first);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, true, false);
} catch (PropertyVetoException exception) {
first.validate();
second.validate();
third.validate();
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener(false);
CheckListener second = new CheckListener(true);
CheckListener third = new CheckListener(false);
VetoableChangeSupport vcs = new VetoableChangeSupport(Test6630275.class);
vcs.addVetoableChangeListener(first);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, true, false);
} catch (PropertyVetoException exception) {
first.validate();
second.validate();
third.validate();
return; // expected exception
}
throw new Error("exception should be thrown");
}
public static void main(String[] args) {
CheckListener first = new CheckListener();
VetoListener second = new VetoListener();
CheckListener third = new CheckListener();
VetoableChangeSupport vcs = new VetoableChangeSupport(Test4425885.class);
vcs.addVetoableChangeListener(PROPERTY, first);
vcs.addVetoableChangeListener(PROPERTY, second);
vcs.addVetoableChangeListener(PROPERTY, third);
try {
vcs.fireVetoableChange(PROPERTY, 0, 1);
} catch (PropertyVetoException exception) {
if (first.odd)
throw new Error("no undo for the first listener", exception);
if (third.odd)
throw new Error("no undo for the third listener", exception);
return; // expected exception
}
throw new Error("exception should be thrown");
}
/**
* Creates a new series with the specified key and description.
*
* @param key the series key (<code>null</code> NOT permitted).
* @param description the series description (<code>null</code> permitted).
*/
protected Series(Comparable key, String description) {
ParamChecks.nullNotPermitted(key, "key");
this.key = key;
this.description = description;
this.listeners = new EventListenerList();
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.vetoableChangeSupport = new VetoableChangeSupport(this);
this.notify = true;
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
/**
* Support for reporting changes for constrained boolean properties. This method can be called
* before a constrained property will be changed and it will send the appropriate
* PropertyChangeEvent to any registered VetoableChangeListeners.
*
* @param propertyName the property whose value has changed
* @param oldValue the property's previous value
* @param newValue the property's new value
* @throws PropertyVetoException if a constrained property change is rejected
*/
protected final void fireVetoableChange(String propertyName,
boolean oldValue,
boolean newValue)
throws PropertyVetoException {
VetoableChangeSupport aVetoSupport = this.vetoSupport;
if (aVetoSupport == null) {
return;
}
aVetoSupport.fireVetoableChange(propertyName, oldValue, newValue);
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
/**
* {@inheritDoc}
*/
@Override
public Object clone() throws CloneNotSupportedException {
AbstractBean result = (AbstractBean) super.clone();
result.pcs = new PropertyChangeSupport(result);
result.vcs = new VetoableChangeSupport(result);
return result;
}
/**
* Creates a new series with the specified key and description.
*
* @param key the series key (<code>null</code> NOT permitted).
* @param description the series description (<code>null</code> permitted).
*/
protected Series(Comparable key, String description) {
ParamChecks.nullNotPermitted(key, "key");
this.key = key;
this.description = description;
this.listeners = new EventListenerList();
this.propertyChangeSupport = new PropertyChangeSupport(this);
this.vetoableChangeSupport = new VetoableChangeSupport(this);
this.notify = true;
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
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);
}
public static void main(String[] args) throws PropertyVetoException {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
VetoableChangeSupport vcs = new VetoableChangeSupport(source);
vcs.addVetoableChangeListener(PROPERTY, one);
vcs.addVetoableChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
vcs.fireVetoableChange(event);
test(one, two, 1); // only one check
vcs.fireVetoableChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes fireVetoableChange(PropertyChangeEvent)
}
public static void main(String[] args) {
try {
new VetoableChangeSupport(null);
} catch (NullPointerException exception) {
return;
}
throw new Error("didn't get expected NullPointerException");
}
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);
}