Search in sources :

Example 6 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class Property method addListener.

static void addListener(final Object source, final String propertyName, final Object listener) {
    final PropertyChangeListener propertyChangeListener = getPropertyChangeListener(listener);
    if (propertyChangeListener != null) {
        if (source != null) {
            final PropertyChangeSupport propertyChangeSupport = propertyChangeSupport(source);
            if (propertyChangeSupport == null) {
                if (source instanceof JComponent) {
                    final JComponent component = (JComponent) source;
                    component.addPropertyChangeListener(propertyName, propertyChangeListener);
                }
            } else {
                propertyChangeSupport.addPropertyChangeListener(propertyName, propertyChangeListener);
            }
        }
    }
}
Also used : WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) JComponent(javax.swing.JComponent)

Example 7 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class Property method addListener.

static void addListener(final Object source, final Object listener) {
    if (source != null) {
        final PropertyChangeListener propertyChangeListener = getPropertyChangeListener(listener);
        if (propertyChangeListener != null) {
            final PropertyChangeSupport propertyChangeSupport = propertyChangeSupport(source);
            if (propertyChangeSupport == null) {
                if (source instanceof JComponent) {
                    final JComponent component = (JComponent) source;
                    component.addPropertyChangeListener(propertyChangeListener);
                }
            } else {
                propertyChangeSupport.addPropertyChangeListener(propertyChangeListener);
            }
        }
    }
}
Also used : WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) JComponent(javax.swing.JComponent)

Example 8 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class AbstractLayer method delete.

@Override
public void delete() {
    this.deleted = true;
    setExists(false);
    this.beanPropertyListener = null;
    final ProjectFrame projectFrame = ProjectFrame.get(this);
    if (projectFrame != null) {
        projectFrame.removeBottomTab(this);
    }
    firePropertyChange("deleted", false, true);
    final LayerGroup layerGroup = getLayerGroup();
    if (layerGroup != null) {
        layerGroup.removeLayer(this);
        this.layerGroup = new EmptyReference<>();
    }
    this.eventsEnabled.closeable(false);
    final PropertyChangeSupport propertyChangeSupport = this.propertyChangeSupport;
    if (propertyChangeSupport != null) {
        Property.removeAllListeners(propertyChangeSupport);
        this.propertyChangeSupport = null;
    }
    if (this.renderer != null) {
        this.renderer.setLayer(null);
    }
}
Also used : PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) ProjectFrame(com.revolsys.swing.map.ProjectFrame)

Example 9 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class Property method removeListener.

static void removeListener(final Object source, final String propertyName, final Object listener) {
    if (listener instanceof PropertyChangeListener) {
        final PropertyChangeListener propertyChangeListener = (PropertyChangeListener) listener;
        final PropertyChangeSupport propertyChangeSupport = propertyChangeSupport(source);
        if (propertyChangeSupport != null) {
            for (final PropertyChangeListener otherListener : propertyChangeSupport.getPropertyChangeListeners()) {
                if (otherListener instanceof PropertyChangeListenerProxy) {
                    final PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) otherListener;
                    final PropertyChangeListener proxyListener = proxy.getListener();
                    final String proxyPropertyName = proxy.getPropertyName();
                    if (proxyListener instanceof WeakPropertyChangeListener) {
                        final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) proxyListener;
                        final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
                        if (listenerReference == null) {
                            propertyChangeSupport.removePropertyChangeListener(proxyPropertyName, weakListener);
                        } else if (proxyPropertyName.equals(propertyName)) {
                            if (listenerReference == propertyChangeListener) {
                                propertyChangeSupport.removePropertyChangeListener(propertyName, weakListener);
                            }
                        }
                    } else if (propertyChangeListener.equals(proxyListener)) {
                        if (proxyPropertyName.equals(propertyName)) {
                            propertyChangeSupport.removePropertyChangeListener(propertyName, propertyChangeListener);
                        }
                    }
                } else if (otherListener instanceof WeakPropertyChangeListener) {
                    final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) otherListener;
                    final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
                    if (listenerReference == null) {
                        propertyChangeSupport.removePropertyChangeListener(weakListener);
                    }
                }
            }
        }
        if (source instanceof Component) {
            final Component component = (Component) source;
            for (final PropertyChangeListener otherListener : component.getPropertyChangeListeners()) {
                if (otherListener.equals(propertyChangeListener)) {
                    component.removePropertyChangeListener(propertyName, propertyChangeListener);
                } else if (otherListener instanceof WeakPropertyChangeListener) {
                    final WeakPropertyChangeListener weakListener = (WeakPropertyChangeListener) otherListener;
                    final PropertyChangeListener listenerReference = weakListener.getPropertyChangeListener();
                    if (listenerReference == null || listenerReference.equals(propertyChangeListener)) {
                        component.removePropertyChangeListener(propertyName, propertyChangeListener);
                    }
                }
            }
        }
    }
}
Also used : WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) JComponent(javax.swing.JComponent) Component(java.awt.Component) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Example 10 with PropertyChangeSupport

use of com.revolsys.beans.PropertyChangeSupport in project com.revolsys.open by revolsys.

the class Property method removeAllListeners.

static void removeAllListeners(final Object object) {
    if (object instanceof Component) {
        final Component component = (Component) object;
        removeAllListeners(component);
    }
    if (object instanceof PropertyChangeSupportProxy) {
        final PropertyChangeSupportProxy proxy = (PropertyChangeSupportProxy) object;
        final PropertyChangeSupport propertyChangeSupport = proxy.getPropertyChangeSupport();
        for (final PropertyChangeListener listener : propertyChangeSupport.getPropertyChangeListeners()) {
            if (listener instanceof PropertyChangeListenerProxy) {
                final PropertyChangeListenerProxy listenerProxy = (PropertyChangeListenerProxy) listener;
                final String propertyName = listenerProxy.getPropertyName();
                propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
            }
            propertyChangeSupport.removePropertyChangeListener(listener);
        }
    }
}
Also used : WeakPropertyChangeListener(com.revolsys.beans.WeakPropertyChangeListener) ProxyPropertyChangeListener(com.revolsys.beans.ProxyPropertyChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyChangeSupportProxy(com.revolsys.beans.PropertyChangeSupportProxy) PropertyChangeSupport(com.revolsys.beans.PropertyChangeSupport) JComponent(javax.swing.JComponent) Component(java.awt.Component) PropertyChangeListenerProxy(java.beans.PropertyChangeListenerProxy)

Aggregations

PropertyChangeSupport (com.revolsys.beans.PropertyChangeSupport)12 PropertyChangeSupportProxy (com.revolsys.beans.PropertyChangeSupportProxy)5 ProxyPropertyChangeListener (com.revolsys.beans.ProxyPropertyChangeListener)5 WeakPropertyChangeListener (com.revolsys.beans.WeakPropertyChangeListener)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 JComponent (javax.swing.JComponent)5 Component (java.awt.Component)3 PropertyChangeListenerProxy (java.beans.PropertyChangeListenerProxy)3 BeanPropertyListener (com.revolsys.swing.listener.BeanPropertyListener)1 ProjectFrame (com.revolsys.swing.map.ProjectFrame)1 ThreadBooleanValue (com.revolsys.value.ThreadBooleanValue)1 Path (java.nio.file.Path)1