rewrite to use java.beans.PropertyChangeSupport to deal with BLD200209300100
authorttran@netbeans.org
Fri, 27 Sep 2002 15:56:47 +0000
changeset 2621a8faa3a64741
parent 2620 ab32edf0e133
child 2622 1d6975e5b700
rewrite to use java.beans.PropertyChangeSupport to deal with
PropertyChange{Event,Listener}
vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java
     1.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java	Fri Sep 27 12:50:22 2002 +0000
     1.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java	Fri Sep 27 15:56:47 2002 +0000
     1.3 @@ -1337,12 +1337,11 @@
     1.4      private final static class SharedPasswords extends Object {
     1.5          
     1.6          private HashMap passwords;
     1.7 -        private HashSet listeners;
     1.8 +        private PropertyChangeSupport changeSupport;
     1.9          private static SharedPasswords instance;
    1.10          
    1.11          private SharedPasswords() {
    1.12              passwords = new HashMap();
    1.13 -            listeners = new HashSet();
    1.14          }
    1.15          
    1.16          public static SharedPasswords getInstance() {
    1.17 @@ -1374,26 +1373,24 @@
    1.18          }
    1.19          
    1.20          private void firePropertyChange(Object key, Object oldPass, Object newPass) {
    1.21 -            PropertyChangeEvent event = new PropertyChangeEvent(key, "password", oldPass, newPass);
    1.22 -            HashSet l;
    1.23 -            synchronized (listeners) {
    1.24 -                l = new HashSet(listeners);
    1.25 -            }
    1.26 -            for (Iterator it = l.iterator(); it.hasNext(); ) {
    1.27 -                ((PropertyChangeListener) it.next()).propertyChange(event);
    1.28 +            if (changeSupport != null) {
    1.29 +                PropertyChangeEvent event = new PropertyChangeEvent(key, "password", oldPass, newPass);
    1.30 +                changeSupport.firePropertyChange(event);
    1.31              }
    1.32          }
    1.33 +
    1.34          
    1.35          public void addPropertyChangeListener(PropertyChangeListener l) {
    1.36 -            synchronized (listeners) {
    1.37 -                listeners.add(l);
    1.38 +            synchronized (this) {
    1.39 +                if (changeSupport == null)
    1.40 +                    changeSupport = new PropertyChangeSupport(this);
    1.41              }
    1.42 +            changeSupport.addPropertyChangeListener(l);
    1.43          }
    1.44          
    1.45          public void removePropertyChangeListener(PropertyChangeListener l) {
    1.46 -            synchronized (listeners) {
    1.47 -                listeners.remove(l);
    1.48 -            }
    1.49 +            if (changeSupport != null)
    1.50 +                changeSupport.removePropertyChangeListener(l);
    1.51          }
    1.52      }
    1.53