本文整理汇总了Java中java.beans.PropertyChangeSupport.addPropertyChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyChangeSupport.addPropertyChangeListener方法的具体用法?Java PropertyChangeSupport.addPropertyChangeListener怎么用?Java PropertyChangeSupport.addPropertyChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.PropertyChangeSupport
的用法示例。
在下文中一共展示了PropertyChangeSupport.addPropertyChangeListener方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
public static void main(String[] args) {
TestEquals one = new TestEquals(1);
TestEquals two = new TestEquals(2);
Object source = TestEquals.class;
PropertyChangeSupport pcs = new PropertyChangeSupport(source);
pcs.addPropertyChangeListener(PROPERTY, one);
pcs.addPropertyChangeListener(PROPERTY, two);
PropertyChangeEvent event = new PropertyChangeEvent(source, PROPERTY, one, two);
pcs.firePropertyChange(event);
test(one, two, 1); // only one check
pcs.firePropertyChange(PROPERTY, one, two);
test(one, two, 2); // because it invokes firePropertyChange(PropertyChangeEvent)
pcs.fireIndexedPropertyChange(PROPERTY, 1, one, two);
test(one, two, 2); // because it invokes firePropertyChange(PropertyChangeEvent)
}
示例2: FxMapItem
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
public FxMapItem(FxMapModel model, MapData data) {
mapModel = model;
itemData = data;
rect = new Rect();
rectangle = new Rectangle();
label = new Label(itemData.getName());
tooltip = new Tooltip(itemData.getName());
tooltip.setFont(new Font(DEFAULT_TOOLTIP_FONT_SIZE));
mainNode = new Group(rectangle, label);
Tooltip.install(label, tooltip);
applyStyle(model.getStyle());
if (data.hasChildrenData()) {
rectangle.setEffect(new Glow());
}
propertyChangeSupport = new PropertyChangeSupport(FxMapItem.this);
propertyChangeSupport.addPropertyChangeListener(model);
initInteractivity();
}
示例3: addPropertyChangeListener
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
/** Adds the specified property change listener to receive property
* change events from this object.
* @param l the property change listener
*/
public final void addPropertyChangeListener(PropertyChangeListener l) {
boolean noListener;
synchronized (getLock()) {
// System.out.println ("added listener: " + l + " to: " + getClass ()); // NOI18N
PropertyChangeSupport supp = (PropertyChangeSupport) getProperty(PROP_SUPPORT);
if (supp == null) {
// System.out.println ("Creating support"); // NOI18N
putProperty(PROP_SUPPORT, supp = new PropertyChangeSupport(this));
}
noListener = !supp.hasListeners(null);
supp.addPropertyChangeListener(l);
}
if (noListener) {
addNotifySuper = false;
addNotify();
if (!addNotifySuper) {
// [PENDING] theoretical race condition for this warning if listeners are added
// and removed very quickly from two threads, I guess, and addNotify() impl is slow
String msg = "You must call super.addNotify() from " + getClass().getName() + ".addNotify()"; // NOI18N
err.warning(msg);
}
}
}
示例4: setUp
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
source = new Object();
pcs = new PropertyChangeSupport(source);
l = new MockPropertyChangeListener();
pcs.addPropertyChangeListener(l);
}
示例5: ParameterControlPanel
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
/** Builds a new panel around the Object f. Any properties of the Object (defined by matching <code>setX/getX</code> methods)
* are added to the panel. If the object implements {@link HasPropertyTooltips} then a tooltip is added for the property if the
* {@link HasPropertyTooltips#getPropertyTooltip(java.lang.String) } returns a non-null String property.
*
* @param obj the object
*/
public ParameterControlPanel(Object obj) {
setClazz(obj);
initComponents();
String cn = getClazz().getClass().getName();
int lastdot = cn.lastIndexOf('.');
String name = cn.substring(lastdot + 1);
setName(name);
titledBorder = new TitledBorder(name);
titledBorder.getBorderInsets(this).set(1, 1, 1, 1);
setBorder(titledBorder);
normalBorder = titledBorder.getBorder();
redLineBorder = BorderFactory.createLineBorder(Color.red);
addIntrospectedControls();
// add(new JPanel()); // to fill vertical space in GridLayout
add(Box.createVerticalGlue()); // to fill space at bottom - not needed
try {
// when clazz fires a property change event, propertyChangeEvent is called here and we refresh all our controls
Method m=obj.getClass().getMethod("getPropertyChangeSupport", (Class[])null);
support=(PropertyChangeSupport)m.invoke(obj, (Object[]) null);
support.addPropertyChangeListener(this);
} catch (Exception ex) {
}
// if(f instanceof PropertyChangeListener){
// ((PropertyChangeListener)f).getPropertyChangeSupport().addPropertyChangeListener(this);
// }
ToolTipManager.sharedInstance().setDismissDelay(10000); // to show tips
revalidate();
}
示例6: addSupport
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
private void addSupport (AEMonitorInterface aemon){
try{
CypressFX2 fx2 = (CypressFX2)aemon;
PropertyChangeSupport fx2Support = fx2.getSupport();
// propertyChange method in this file deals with these events
if ( !fx2Support.hasListeners("readerStarted") ){
fx2Support.addPropertyChangeListener("readerStarted",this); // when the reader starts running, we get called back to fix device control menu
}
} catch ( Exception e ){
log.warning("couldn't add readerChanged property change to " + getAemonRight());
}
}
示例7: addSupport
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
private void addSupport(AEMonitorInterface aemon) {
try {
CypressFX2 fx2 = (CypressFX2) aemon;
PropertyChangeSupport fx2Support = fx2.getSupport();
// propertyChange method in this file deals with these events
if (!fx2Support.hasListeners("readerStarted")) {
fx2Support.addPropertyChangeListener("readerStarted", this); // when the reader starts running, we get called back to fix device control menu
}
} catch (Exception e) {
log.warning("couldn't add readerChanged property change to " + aemon);
}
}
示例8: FxMapModel
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
public FxMapModel(FxTreeMap treeMap, MapData mapData, double width, double height) {
modelData = mapData;
mapItems = new LinkedList<>();
propertyChangeSupport = new PropertyChangeSupport(FxMapModel.this);
propertyChangeSupport.addPropertyChangeListener(treeMap);
style = new TreeMapStyle();
style.removePropertyChangeListener(FxMapModel.this);
totalArea = width * height;
modelData.getChildrenData().forEach(d -> {
FxMapItem mapItem = new FxMapItem(FxMapModel.this, d);
mapItems.add(mapItem);
});
modelData.addPropertyChangeListener(this::handleModelChange);
}
示例9: main
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
public static void main(String[] args) {
PropertyChangeSupport pcs = new PropertyChangeSupport(TestListeners.class);
pcs.addPropertyChangeListener(new TestListeners(0));
pcs.addPropertyChangeListener(NAME, new TestListeners(2));
pcs.addPropertyChangeListener(new TestListeners(1));
pcs.addPropertyChangeListener(NAME, new PropertyChangeListenerProxy(NAME, new TestListeners(3)));
current = 0;
pcs.firePropertyChange(NAME, 0, 1);
if (current != 4)
throw new Error("Expected 4 listeners, but called " + current);
current = 0;
pcs.firePropertyChange(NONE, 1, 0);
if (current != 2)
throw new Error("Expected 2 listeners, but called " + current);
PropertyChangeListener[] all = pcs.getPropertyChangeListeners();
if (all.length != 4)
throw new Error("Expected 4 listeners, but contained " + all.length);
PropertyChangeListener[] named = pcs.getPropertyChangeListeners(NAME);
if (named.length != 2)
throw new Error("Expected 2 named listeners, but contained " + named.length);
PropertyChangeListener[] other = pcs.getPropertyChangeListeners(NONE);
if (other.length != 0)
throw new Error("Expected 0 other listeners, but contained " + other.length);
pcs.removePropertyChangeListener(new TestListeners(0));
pcs.removePropertyChangeListener(new TestListeners(1));
pcs.removePropertyChangeListener(NAME, new TestListeners(2));
pcs.removePropertyChangeListener(NAME, new PropertyChangeListenerProxy(NAME, new TestListeners(3)));
all = pcs.getPropertyChangeListeners();
if (all.length != 0)
throw new Error("Expected 4 listeners, but contained " + all.length);
named = pcs.getPropertyChangeListeners(NAME);
if (named.length != 0)
throw new Error("Expected 2 named listeners, but contained " + named.length);
other = pcs.getPropertyChangeListeners(NONE);
if (other.length != 0)
throw new Error("Expected 0 other listeners, but contained " + other.length);
}
示例10: main
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
public static void main(String[] args) {
PropertyChangeListener listener = new CustomProxy();
PropertyChangeSupport support = new PropertyChangeSupport(listener);
support.addPropertyChangeListener(listener);
support.addPropertyChangeListener("foo", listener); // cast class exception
}
示例11: create
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
private static PropertyChangeSupport create() {
PropertyChangeSupport pcs = new PropertyChangeSupport(TestSerialization.class);
pcs.addPropertyChangeListener(new TestSerialization(0));
pcs.addPropertyChangeListener(NAME, new TestSerialization(1));
return pcs;
}
示例12: addPropertyChangeListener
import java.beans.PropertyChangeSupport; //导入方法依赖的package包/类
/**
* Adds <code>PropertyChangeListener</code> to a document.
*
* <p>In general, document properties are key-value pairs where both the key
* and the value can be any <code>Object</code>. Contrary to that <code>PropertyChangeListener</code>s
* can only handle named properties that can have an arbitrary value, but have <code>String</code> names.
* Therefore the listenera attached to a document will only ever recieve document
* properties, which keys are of <code>java.lang.String</code> type.
*
* <p>Additionally, the list of document properties that clients can listen on
* is not part of this contract.
*
* @param doc The document to add the listener to.
* @param l The listener to add to the document.
*
* @since 1.35
*/
public static void addPropertyChangeListener(Document doc, PropertyChangeListener l) {
PropertyChangeSupport pcs = (PropertyChangeSupport) doc.getProperty(PropertyChangeSupport.class);
if (pcs != null) {
pcs.addPropertyChangeListener(l);
}
}