public class VetoableChangeSupport extends Object implements Serializable
PropertyChangeEvent
s听众和派遣他们。您可以使用这个类的一个实例作为您的豆的成员字段,并将这些类型的工作委托给它。的
VetoableChangeListener
可以注册为所有属性或属性指定的名字。
这里是VetoableChangeSupport
用法的一个例子,遵循的规则和建议放在™JavaBeans规范:
public class MyBean {
private final VetoableChangeSupport vcs = new VetoableChangeSupport(this);
public void addVetoableChangeListener(VetoableChangeListener listener) {
this.vcs.addVetoableChangeListener(listener);
}
public void removeVetoableChangeListener(VetoableChangeListener listener) {
this.vcs.removeVetoableChangeListener(listener);
}
private String value;
public String getValue() {
return this.value;
}
public void setValue(String newValue) throws PropertyVetoException {
String oldValue = this.value;
this.vcs.fireVetoableChange("value", oldValue, newValue);
this.value = newValue;
}
[...]
}
一个VetoableChangeSupport
实例是线程安全的。
这个类是可序列化的。当它被序列化将保存(恢复)任何听众本身是可序列化的。任何非序列化的听众会跳过序列化期间。
Constructor and Description |
---|
VetoableChangeSupport(Object sourceBean)
构建了一个
VetoableChangeSupport 对象。
|
Modifier and Type | Method and Description |
---|---|
void |
addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
添加一个特定的属性vetoablechangelistener。
|
void |
addVetoableChangeListener(VetoableChangeListener listener)
添加一个vetoablechangelistener的监听器列表。
|
void |
fireVetoableChange(PropertyChangeEvent event)
向已注册的侦听器发射属性更改事件,以跟踪所有属性或具有指定名称的属性的更新。
|
void |
fireVetoableChange(String propertyName, boolean oldValue, boolean newValue)
向已注册的侦听器报告一个布尔受限属性更新,以跟踪所有属性或具有指定名称的属性的更新。
|
void |
fireVetoableChange(String propertyName, int oldValue, int newValue)
向已注册的侦听器报告一个整数约束的属性更新,以跟踪所有属性或具有指定名称的属性的更新。
|
void |
fireVetoableChange(String propertyName, Object oldValue, Object newValue)
向已注册的已注册的侦听器更新已注册的约束属性更新,以跟踪指定名称的所有属性或属性的更新。
|
VetoableChangeListener[] |
getVetoableChangeListeners()
返回所有的听众都加入到addvetoablechangelistener()的vetoablechangesupport对象数组。
|
VetoableChangeListener[] |
getVetoableChangeListeners(String propertyName)
返回已与已命名的属性关联的所有侦听器的数组。
|
boolean |
hasListeners(String propertyName)
检查是否有特定属性的侦听器,包括所有已注册的属性的侦听器。
|
void |
removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
消除对特定财产vetoablechangelistener。
|
void |
removeVetoableChangeListener(VetoableChangeListener listener)
从列表中删除一个vetoablechangelistener听众。
|
public VetoableChangeSupport(Object sourceBean)
VetoableChangeSupport
对象。
sourceBean
-豆给任何事件源。
public void addVetoableChangeListener(VetoableChangeListener listener)
listener
是空的,没有异常被抛出,不采取行动。
listener
- vetoablechangelistener加以补充
public void removeVetoableChangeListener(VetoableChangeListener listener)
listener
曾不止一次地对同一事件的消息人士补充说,这将是一个较少的时间通知后。如果
listener
是空的,或是不加,不引发异常而不采取行动。
listener
- vetoablechangelistener被删除
public VetoableChangeListener[] getVetoableChangeListeners()
如果一些听众已添加的命名属性,然后返回的数组将是一个vetoablechangelisteners和VetoableChangeListenerProxy
s混合物。如果调用方法是区分听众就必须测试每一个元素是否是一个VetoableChangeListenerProxy
感兴趣,进行铸造,并检查参数。
VetoableChangeListener[] listeners = bean.getVetoableChangeListeners();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof VetoableChangeListenerProxy) {
VetoableChangeListenerProxy proxy =
(VetoableChangeListenerProxy)listeners[i];
if (proxy.getPropertyName().equals("foo")) {
// proxy is a VetoableChangeListener which was associated
// with the property named "foo"
}
}
}
VetoableChangeListeners
说如果没有听众已添加一个空数组
VetoableChangeListenerProxy
public void addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
propertyName
或
listener
是空的,没有异常被抛出,不采取行动。
propertyName
-属性的名字听上。
listener
- vetoablechangelistener加以补充
public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
listener
曾不止一次地对指定的属性相同的事件源补充说,这将是一个较少的时间通知后。如果
propertyName
是空的,没有异常被抛出,不采取行动。如果
listener
是无效的,或者是不添加指定的属性,不引发异常而不采取行动。
propertyName
-房地产,听名字。
listener
- vetoablechangelistener被删除
public VetoableChangeListener[] getVetoableChangeListeners(String propertyName)
propertyName
-物业的听的名字
VetoableChangeListeners
与命名属性关联。如果没有这样的听众已被添加,或者如果
propertyName
为空,则返回一个空数组。
public void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException
任何听众可以抛出一个PropertyVetoException
否决更新。如果一个监听器否决的更新,该方法传递一个新的“撤消”PropertyChangeEvent
,归还给所有的听众,已经证实了这一更新,把PropertyVetoException
又旧的价值。
如果旧值和新值都是相等的和非空值,则不会发射任何事件。
这仅仅是在更一般的fireVetoableChange(PropertyChangeEvent)
方法方便的包装。
propertyName
-这是关于改变物业专业名称
oldValue
-属性的旧值
newValue
-新的属性值
PropertyVetoException
-如果一个听众否决属性更新
public void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException
任何听众可以抛出一个PropertyVetoException
否决更新。如果一个监听器否决的更新,该方法传递一个新的“撤消”PropertyChangeEvent
,归还给所有的听众,已经证实了这一更新,把PropertyVetoException
又旧的价值。
如果旧值和新值是相等的,则不会发射任何事件。
这仅仅是在更一般的fireVetoableChange(String, Object, Object)
方法方便的包装。
propertyName
-这是关于改变物业专业名称
oldValue
-属性的旧值
newValue
-新的属性值
PropertyVetoException
-如果一个听众否决属性更新
public void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException
任何听众可以抛出一个PropertyVetoException
否决更新。如果一个监听器否决的更新,该方法传递一个新的“撤消”PropertyChangeEvent
,归还给所有的听众,已经证实了这一更新,把PropertyVetoException
又旧的价值。
如果旧值和新值是相等的,则不会发射任何事件。
这仅仅是在更一般的fireVetoableChange(String, Object, Object)
方法方便的包装。
propertyName
-这是关于改变物业专业名称
oldValue
-属性的旧值
newValue
-新的属性值
PropertyVetoException
-如果一个听众否决属性更新
public void fireVetoableChange(PropertyChangeEvent event) throws PropertyVetoException
任何听众可以抛出一个PropertyVetoException
否决更新。如果一个监听器否决的更新,该方法传递一个新的“撤消”PropertyChangeEvent
,归还给所有的听众,已经证实了这一更新,把PropertyVetoException
又旧的价值。
如果给定的事件的旧值和新值是相等的和非空值,则不发射任何事件。
event
-
PropertyChangeEvent
被解雇
PropertyVetoException
-如果一个听众否决属性更新
public boolean hasListeners(String propertyName)
propertyName
是空的,只有检查所有性质注册的监听器。
propertyName
-属性名称。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.