Search in sources :

Example 66 with PropertyChangeListener

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());
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) NamedBean(jmri.NamedBean) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 67 with PropertyChangeListener

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);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 68 with PropertyChangeListener

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);
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) JTable(javax.swing.JTable) Test(org.junit.Test)

Example 69 with PropertyChangeListener

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());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 70 with PropertyChangeListener

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);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) TableColumnModel(javax.swing.table.TableColumnModel)

Aggregations

PropertyChangeListener (java.beans.PropertyChangeListener)152 PropertyChangeEvent (java.beans.PropertyChangeEvent)124 ActionEvent (java.awt.event.ActionEvent)16 ActionListener (java.awt.event.ActionListener)15 JPanel (javax.swing.JPanel)15 ArrayList (java.util.ArrayList)11 BorderLayout (java.awt.BorderLayout)10 JButton (javax.swing.JButton)9 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Composite (org.eclipse.swt.widgets.Composite)9 IOException (java.io.IOException)8 JLabel (javax.swing.JLabel)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Dimension (java.awt.Dimension)6 FlowLayout (java.awt.FlowLayout)6 PropertyChangeSupport (java.beans.PropertyChangeSupport)6 File (java.io.File)6 BoxLayout (javax.swing.BoxLayout)6