use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class NamedBeanTest method testDispose.
public void testDispose() {
NamedBean n = createInstance();
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
Assert.assertEquals("start length", 2, n.getNumPropertyChangeListeners());
n.dispose();
Assert.assertEquals("end length", 0, n.getNumPropertyChangeListeners());
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class AbstractThrottleTest method testRemovePropertyChangeListener.
/**
* Test of removePropertyChangeListener method, of class AbstractThrottle.
*/
public void testRemovePropertyChangeListener() {
PropertyChangeListener l = (PropertyChangeEvent evt) -> {
};
AbstractThrottle instance = new AbstractThrottleImpl();
instance.removePropertyChangeListener(l);
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class JmriJTablePersistenceManagerTest method testStopPersisting.
/**
* Test of stopPersisting method, of class JmriJTablePersistenceManager.
*/
@Test
public void testStopPersisting() {
JmriJTablePersistenceManagerSpy instance = new JmriJTablePersistenceManagerSpy();
JTable table = testTable("test name");
try {
instance.persist(table);
// passes
} catch (NullPointerException ex) {
Assert.fail("threw unexpected NPE");
}
int managers = 0;
int tableListeners = 0;
int columnListeners = 0;
for (PropertyChangeListener listener : table.getPropertyChangeListeners()) {
if (listener.equals(instance)) {
managers++;
}
if (listener.equals(instance.getListener(table))) {
tableListeners++;
}
}
for (PropertyChangeListener listener : table.getColumn("c0").getPropertyChangeListeners()) {
if (listener.equals(instance.getListener(table))) {
columnListeners++;
}
}
Assert.assertEquals(1, managers);
Assert.assertEquals(1, tableListeners);
Assert.assertEquals(1, columnListeners);
try {
instance.stopPersisting(table);
// passes
} catch (NullPointerException ex) {
Assert.fail("threw unexpected NPE");
}
for (PropertyChangeListener listener : table.getColumn("c0").getPropertyChangeListeners()) {
if (listener.equals(instance.getListener(table))) {
columnListeners++;
}
}
managers = 0;
tableListeners = 0;
columnListeners = 0;
for (PropertyChangeListener listener : table.getPropertyChangeListeners()) {
if (listener.equals(instance)) {
managers++;
}
if (listener.equals(instance.getListener(table))) {
tableListeners++;
}
}
for (PropertyChangeListener listener : table.getColumn("c0").getPropertyChangeListeners()) {
if (listener.equals(instance.getListener(table))) {
columnListeners++;
}
}
Assert.assertEquals(0, managers);
Assert.assertEquals(0, tableListeners);
Assert.assertEquals(0, columnListeners);
}
use of java.beans.PropertyChangeListener in project sling by apache.
the class InstallEditorSection method init.
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
serverListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (ISlingLaunchpadServer.PROP_INSTALL_LOCALLY.equals(evt.getPropertyName())) {
quickLocalInstallButton.setSelection((Boolean) evt.getNewValue());
bundleLocalInstallButton.setSelection(!(Boolean) evt.getNewValue());
}
}
};
server.addPropertyChangeListener(serverListener);
launchpadServer = (ISlingLaunchpadServer) server.getAdapter(ISlingLaunchpadServer.class);
if (launchpadServer == null) {
// TODO progress monitor
launchpadServer = (ISlingLaunchpadServer) server.loadAdapter(ISlingLaunchpadServer.class, new NullProgressMonitor());
}
}
use of java.beans.PropertyChangeListener in project sling by apache.
the class Util method setupColumnWidths.
static void setupColumnWidths(final TableColumnModel tcm, final String propertyName) {
PropertyChangeListener pcl = new PropertyChangeListener() {
private final String pclPropName = propertyName;
private final TableColumnModel pclTcm = tcm;
public void propertyChange(PropertyChangeEvent evt) {
if ("width".equals(evt.getPropertyName())) {
int[] colWidths = new int[pclTcm.getColumnCount()];
for (int i = 0; i < colWidths.length; i++) {
colWidths[i] = pclTcm.getColumn(i).getWidth();
}
setPreference(pclPropName, colWidths, true);
}
}
};
int[] colWidths = getPreference(propertyName, new int[0]);
for (int i = 0; i < colWidths.length && i < tcm.getColumnCount(); i++) {
tcm.getColumn(i).setPreferredWidth(colWidths[i]);
}
for (int i = 0; i < tcm.getColumnCount(); i++) {
tcm.getColumn(i).addPropertyChangeListener(pcl);
}
}
Aggregations