Search in sources :

Example 36 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project felix by apache.

the class Activator method firePropertyChangedEvent.

public void firePropertyChangedEvent(String name, Object oldValue, Object newValue) {
    // System.out.println("[Gui Activator] fire PCE("+name+","+oldValue+","+newValue+")");
    PropertyChangeEvent event = null;
    // Guaranteed to return a non-null array
    Object[] listeners = m_listenerList.getListenerList();
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == PropertyChangeListener.class) {
            // Lazily create the event:
            if (event == null) {
                event = new PropertyChangeEvent(this, name, oldValue, newValue);
            }
            ((PropertyChangeListener) listeners[i + 1]).propertyChange(event);
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 37 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project felix by apache.

the class Activator method firePropertyChangedEvent.

protected void firePropertyChangedEvent(String name, Object oldValue, Object newValue) {
    PropertyChangeEvent event = null;
    // Guaranteed to return a non-null array
    Object[] listeners = m_listenerList.getListenerList();
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == PropertyChangeListener.class) {
            // Lazily create the event:
            if (event == null) {
                event = new PropertyChangeEvent(this, name, oldValue, newValue);
            }
            ((PropertyChangeListener) listeners[i + 1]).propertyChange(event);
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 38 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project felix by apache.

the class ClockDevice method update.

/**
 */
public void update() {
    Clock clock = Clock.getInstance();
    Calendar cal = clock.getCalendar();
    Date date = cal.getTime();
    UPnPStateVariable variable = timerService.getStateVariable("Time");
    notifier.propertyChange(new PropertyChangeEvent(variable, "Time", null, date));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) Calendar(java.util.Calendar) UPnPStateVariable(org.osgi.service.upnp.UPnPStateVariable) Date(java.util.Date)

Example 39 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project jdk8u_jdk by JetBrains.

the class BeanContextChildSupport method setBeanContext.

/**
     * Sets the <code>BeanContext</code> for
     * this <code>BeanContextChildSupport</code>.
     * @param bc the new value to be assigned to the <code>BeanContext</code>
     * property
     * @throws PropertyVetoException if the change is rejected
     */
public synchronized void setBeanContext(BeanContext bc) throws PropertyVetoException {
    if (bc == beanContext)
        return;
    BeanContext oldValue = beanContext;
    BeanContext newValue = bc;
    if (!rejectedSetBCOnce) {
        if (rejectedSetBCOnce = !validatePendingSetBeanContext(bc)) {
            throw new PropertyVetoException("setBeanContext() change rejected:", new PropertyChangeEvent(beanContextChildPeer, "beanContext", oldValue, newValue));
        }
        try {
            fireVetoableChange("beanContext", oldValue, newValue);
        } catch (PropertyVetoException pve) {
            rejectedSetBCOnce = true;
            // re-throw
            throw pve;
        }
    }
    if (beanContext != null)
        releaseBeanContextResources();
    beanContext = newValue;
    rejectedSetBCOnce = false;
    firePropertyChange("beanContext", oldValue, newValue);
    if (beanContext != null)
        initializeBeanContextResources();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 40 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project jabref by JabRef.

the class JTextFieldChangeListenerUtil method addChangeListener.

/**
     * Installs a listener to receive notification when the text of any
     * {@code JTextComponent} is changed. Internally, it installs a
     * {@link DocumentListener} on the text component's {@link Document},
     * and a {@link PropertyChangeListener} on the text component to detect
     * if the {@code Document} itself is replaced.
     *
     * Taken from
     *
     * @param text any text component, such as a {@link JTextField}
     *        or {@link JTextArea}
     * @param changeListener a listener to receive {@link ChangeEvent}s
     *        when the text is changed; the source object for the events
     *        will be the text component
     * @throws NullPointerException if either parameter is null
     */
public static void addChangeListener(JTextComponent text, ChangeListener changeListener) {
    Objects.requireNonNull(text);
    Objects.requireNonNull(changeListener);
    DocumentListener dl = new DocumentListener() {

        private int lastChange;

        private int lastNotifiedChange;

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            lastChange++;
            SwingUtilities.invokeLater(() -> {
                if (lastNotifiedChange != lastChange) {
                    lastNotifiedChange = lastChange;
                    changeListener.stateChanged(new ChangeEvent(text));
                }
            });
        }
    };
    text.addPropertyChangeListener("document", (PropertyChangeEvent e) -> {
        Document d1 = (Document) e.getOldValue();
        Document d2 = (Document) e.getNewValue();
        if (d1 != null) {
            d1.removeDocumentListener(dl);
        }
        if (d2 != null) {
            d2.addDocumentListener(dl);
        }
        dl.changedUpdate(null);
    });
    Document d = text.getDocument();
    if (d != null) {
        d.addDocumentListener(dl);
    }
}
Also used : DocumentListener(javax.swing.event.DocumentListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)574 PropertyChangeListener (java.beans.PropertyChangeListener)349 ActionEvent (java.awt.event.ActionEvent)42 JPanel (javax.swing.JPanel)36 ActionListener (java.awt.event.ActionListener)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)31 PropertyVetoException (java.beans.PropertyVetoException)24 JLabel (javax.swing.JLabel)24 File (java.io.File)23 BorderLayout (java.awt.BorderLayout)22 List (java.util.List)21 IOException (java.io.IOException)19 Dimension (java.awt.Dimension)16 ChangeEvent (javax.swing.event.ChangeEvent)15 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13 JScrollPane (javax.swing.JScrollPane)12 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)12