- すべての実装されたインタフェース:
Serializable
- 直系の既知のサブクラス:
SwingPropertyChangeSupport
PropertyChangeEvent
をそれらにディスパッチします。 このクラスのインスタンスをBeanのメンバー・フィールドとして使用し、こうした種類の処理をそれに委譲できます。 PropertyChangeListener
は、すべてのプロパティまたは名前で指定されたプロパティに対して登録できます。
次に、JavaBeans仕様に記載されているルールおよび推奨事項に従ったPropertyChangeSupport
の使用例を示します:
public class MyBean { private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener listener) { this.pcs.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { this.pcs.removePropertyChangeListener(listener); } private String value; public String getValue() { return this.value; } public void setValue(String newValue) { String oldValue = this.value; this.value = newValue; this.pcs.firePropertyChange("value", oldValue, newValue); } [...] }
PropertyChangeSupport
インスタンスはスレッドセーフです。
このクラスは直列化可能です。 直列化した場合、直列化可能なリスナーが保存および復元されます。 直列化の際、直列化可能でないリスナーはスキップされます。
- 導入されたバージョン:
- 1.1
- 関連項目:
-
コンストラクタのサマリー
-
メソッドのサマリー
修飾子と型メソッド説明void
PropertyChangeListenerをリスナー・リストに追加します。void
addPropertyChangeListener
(String propertyName, PropertyChangeListener listener) 特定のプロパティのPropertyChangeListenerを追加します。void
fireIndexedPropertyChange
(String propertyName, int index, boolean oldValue, boolean newValue) 登録されているリスナーにboolean型のインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
fireIndexedPropertyChange
(String propertyName, int index, int oldValue, int newValue) 登録されているリスナーに整数型のインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
fireIndexedPropertyChange
(String propertyName, int index, Object oldValue, Object newValue) 登録されているリスナーにインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
登録されているリスナーにプロパティ変更イベントをトリガーして、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
firePropertyChange
(String propertyName, boolean oldValue, boolean newValue) 登録されているリスナーにboolean型のバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
firePropertyChange
(String propertyName, int oldValue, int newValue) 登録されているリスナーに整数型のバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。void
firePropertyChange
(String propertyName, Object oldValue, Object newValue) 登録されているリスナーにバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。addPropertyChangeListener()によってPropertyChangeSupportオブジェクトに追加されたすべてのリスナーの配列を返します。getPropertyChangeListeners
(String propertyName) 指定されたプロパティに関連付けられているすべてのリスナーの配列を返します。boolean
hasListeners
(String propertyName) 特定のプロパティにリスナーがあるかどうかを判定します。あらゆるプロパティに登録されたリスナーが含まれます。void
PropertyChangeListenerをリスナー・リストから削除します。void
removePropertyChangeListener
(String propertyName, PropertyChangeListener listener) 特定のプロパティのPropertyChangeListenerを削除します。
-
コンストラクタの詳細
-
PropertyChangeSupport
public PropertyChangeSupport(Object sourceBean) PropertyChangeSupport
オブジェクトを構築します。- パラメータ:
sourceBean
- すべてのイベントのソースとして指定されるBean。
-
-
メソッドの詳細
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener) PropertyChangeListenerをリスナー・リストに追加します。 リスナーは、すべてのプロパティに対して登録されます。 同じリスナー・オブジェクトを複数回追加でき、追加した回数だけリスナー・オブジェクトが呼び出されます。listener
がnullの場合、例外はスローされず、何も処理は行われません。- パラメータ:
listener
- 追加されるPropertyChangeListener
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener) PropertyChangeListenerをリスナー・リストから削除します。 すべてのプロパティで登録されたPropertyChangeListenerを削除します。 同じイベント・ソースにlistener
が2回以上追加された場合は、削除された後に1回少ない通知が行われます。listener
がnullの場合、または追加されなかった場合、例外はスローされず、何も処理は行われません。- パラメータ:
listener
- 削除されるPropertyChangeListener
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()addPropertyChangeListener()によってPropertyChangeSupportオブジェクトに追加されたすべてのリスナーの配列を返します。指定されたプロパティによって追加されたリスナーがある場合、PropertyChangeListenerと
PropertyChangeListenerProxy
からなる配列が返されます。 リスナーの識別に関係している呼出し元メソッドは、個々の要素をテストしてPropertyChangeListenerProxy
であるかどうかの確認、キャスト、パラメータの確認を行う必要があります。PropertyChangeListener[] listeners = bean.getPropertyChangeListeners(); for (int i = 0; i < listeners.length; i++) { if (listeners[i] instanceof PropertyChangeListenerProxy) { PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listeners[i]; if (proxy.getPropertyName().equals("foo")) { // proxy is a PropertyChangeListener which was associated // with the property named "foo" } } }
- 戻り値:
- 追加されたすべての
PropertyChangeListeners
、リスナーが追加されていない場合は空の配列 - 導入されたバージョン:
- 1.4
- 関連項目:
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) 特定のプロパティのPropertyChangeListenerを追加します。 リスナーが呼び出されるのは、firePropertyChangeの呼出しにより、その特定のプロパティが指定されたときだけです。 同じリスナー・オブジェクトを複数回追加できます。 各プロパティでは、リスナーがそのプロパティに追加された回数だけリスナーが呼び出されます。propertyName
またはlistener
がnullの場合、例外はスローされず、何も処理は行われません。- パラメータ:
propertyName
- 待機しているプロパティの名前。listener
- 追加されるPropertyChangeListener- 導入されたバージョン:
- 1.2
-
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) 特定のプロパティのPropertyChangeListenerを削除します。 指定したプロパティの同じイベント・ソースにlistener
が2回以上追加された場合は、削除されたあとに1回少ない通知が行われます。propertyName
がnullの場合、例外はスローされず、何も処理は行われません。listener
がnullの場合、または指定されたプロパティに追加されなかった場合、例外はスローされず、何も処理は行われません。- パラメータ:
propertyName
- 待機していたプロパティの名前。listener
- 削除されるPropertyChangeListener- 導入されたバージョン:
- 1.2
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) 指定されたプロパティに関連付けられているすべてのリスナーの配列を返します。- パラメータ:
propertyName
- 待機しているプロパティの名前- 戻り値:
- 名前付きプロパティに関連付けられているすべての
PropertyChangeListeners
。 このようなリスナーが追加されていない場合、またはpropertyName
がnullの場合は、空の配列が返されます。 - 導入されたバージョン:
- 1.4
-
firePropertyChange
登録されているリスナーにバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しく、nullでない場合、イベントはトリガーされません。
これは、より一般的な
firePropertyChange(PropertyChangeEvent)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名oldValue
- プロパティの古い値newValue
- プロパティの新しい値
-
firePropertyChange
public void firePropertyChange(String propertyName, int oldValue, int newValue) 登録されているリスナーに整数型のバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しい場合、イベントはトリガーされません。
これは、より一般的な
firePropertyChange(String, Object, Object)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名oldValue
- プロパティの古い値newValue
- プロパティの新しい値- 導入されたバージョン:
- 1.2
-
firePropertyChange
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) 登録されているリスナーにboolean型のバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しい場合、イベントはトリガーされません。
これは、より一般的な
firePropertyChange(String, Object, Object)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名oldValue
- プロパティの古い値newValue
- プロパティの新しい値- 導入されたバージョン:
- 1.2
-
firePropertyChange
public void firePropertyChange(PropertyChangeEvent event) 登録されているリスナーにプロパティ変更イベントをトリガーして、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。指定されたイベントの以前の値と新しい値が等しくてnullでない場合、イベントはトリガーされません。
- パラメータ:
event
- トリガーされるPropertyChangeEvent
- 導入されたバージョン:
- 1.2
-
fireIndexedPropertyChange
public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) 登録されているリスナーにインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しく、nullでない場合、イベントはトリガーされません。
これは、より一般的な
firePropertyChange(PropertyChangeEvent)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名index
- 変更されたプロパティ要素のインデックスoldValue
- プロパティの古い値newValue
- プロパティの新しい値- 導入されたバージョン:
- 1.5
-
fireIndexedPropertyChange
public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) 登録されているリスナーに整数型のインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しい場合、イベントはトリガーされません。
これは、より一般的な
fireIndexedPropertyChange(String, int, Object, Object)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名index
- 変更されたプロパティ要素のインデックスoldValue
- プロパティの古い値newValue
- プロパティの新しい値- 導入されたバージョン:
- 1.5
-
fireIndexedPropertyChange
public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) 登録されているリスナーにboolean型のインデックス付きバウンド・プロパティの更新を報告して、すべてのプロパティまたは指定された名前を持つプロパティの更新を追跡します。古い値と新しい値が等しい場合、イベントはトリガーされません。
これは、より一般的な
fireIndexedPropertyChange(String, int, Object, Object)
メソッドの簡易ラッパーにすぎません。- パラメータ:
propertyName
- 変更されたプロパティのプログラム名index
- 変更されたプロパティ要素のインデックスoldValue
- プロパティの古い値newValue
- プロパティの新しい値- 導入されたバージョン:
- 1.5
-
hasListeners
public boolean hasListeners(String propertyName) 特定のプロパティにリスナーがあるかどうかを判定します。あらゆるプロパティに登録されたリスナーが含まれます。propertyName
がnullの場合は、すべてのプロパティに登録されているリスナーのみがチェックされます。- パラメータ:
propertyName
- プロパティ名。- 戻り値:
- 指定したプロパティに1つ以上のリスナーがある場合はtrue
- 導入されたバージョン:
- 1.2
-