Misc. code cleanups. LogFormatter_root excludes_49026_base_5 milestone11_root navigation_root_feb082007 retouche_merge_root vw_unstable_datasource_0313_1
authorjglick@netbeans.org
Wed, 07 Feb 2007 19:39:17 +0000
changeset 256fcf62f077d1d
parent 255 f7f17a37e8d1
child 257 39b4385536e7
Misc. code cleanups.
openide.util/src/org/openide/util/actions/CallbackSystemAction.java
     1.1 --- a/openide.util/src/org/openide/util/actions/CallbackSystemAction.java	Wed Feb 07 19:29:02 2007 +0000
     1.2 +++ b/openide.util/src/org/openide/util/actions/CallbackSystemAction.java	Wed Feb 07 19:39:17 2007 +0000
     1.3 @@ -13,7 +13,7 @@
     1.4   * "Portions Copyrighted [year] [name of copyright owner]"
     1.5   *
     1.6   * The Original Software is NetBeans. The Initial Developer of the Original
     1.7 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
     1.8 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
     1.9   * Microsystems, Inc. All Rights Reserved.
    1.10   */
    1.11  
    1.12 @@ -28,7 +28,8 @@
    1.13  import java.lang.ref.Reference;
    1.14  import java.lang.ref.WeakReference;
    1.15  import java.util.ArrayList;
    1.16 -import java.util.Iterator;
    1.17 +import java.util.Collection;
    1.18 +import java.util.Collections;
    1.19  import java.util.List;
    1.20  import java.util.logging.Level;
    1.21  import java.util.logging.Logger;
    1.22 @@ -125,7 +126,7 @@
    1.23      /** Updates the enabled state by checking performer and ActionMap
    1.24       */
    1.25      private void updateEnabled() {
    1.26 -        javax.swing.Action action = GlobalManager.getDefault().findGlobalAction(
    1.27 +        Action action = GlobalManager.getDefault().findGlobalAction(
    1.28                  getActionMapKey(), getSurviveFocusChange()
    1.29              );
    1.30  
    1.31 @@ -436,7 +437,7 @@
    1.32       * and updates the state of the action according to it.
    1.33       */
    1.34      private static final class ActionDelegateListener extends WeakReference<CallbackSystemAction> implements PropertyChangeListener {
    1.35 -        private WeakReference delegate;
    1.36 +        private Reference<Action> delegate;
    1.37  
    1.38          public ActionDelegateListener(CallbackSystemAction c, Action delegate) {
    1.39              super(c);
    1.40 @@ -445,10 +446,10 @@
    1.41          }
    1.42  
    1.43          public void clear() {
    1.44 -            javax.swing.Action a;
    1.45 +            Action a;
    1.46  
    1.47 -            WeakReference d = delegate;
    1.48 -            a = (d == null) ? null : (javax.swing.Action) d.get();
    1.49 +            Reference<Action> d = delegate;
    1.50 +            a = d == null ? null : d.get();
    1.51  
    1.52              if (a == null) {
    1.53                  return;
    1.54 @@ -459,14 +460,14 @@
    1.55              a.removePropertyChangeListener(this);
    1.56          }
    1.57  
    1.58 -        public void attach(javax.swing.Action action) {
    1.59 -            WeakReference d = delegate;
    1.60 +        public void attach(Action action) {
    1.61 +            Reference<Action> d = delegate;
    1.62  
    1.63              if ((d != null) && (d.get() == action)) {
    1.64                  return;
    1.65              }
    1.66  
    1.67 -            Action prev = (Action) d.get();
    1.68 +            Action prev = d.get();
    1.69  
    1.70              // reattaches to different action
    1.71              if (prev != null) {
    1.72 @@ -479,7 +480,7 @@
    1.73  
    1.74          public void propertyChange(java.beans.PropertyChangeEvent evt) {
    1.75              synchronized (LISTENER) {
    1.76 -                WeakReference d = delegate;
    1.77 +                Reference<Action> d = delegate;
    1.78  
    1.79                  if ((d == null) || (d.get() == null)) {
    1.80                      return;
    1.81 @@ -516,7 +517,7 @@
    1.82          private PropertyChangeListener weakL;
    1.83  
    1.84          /** last action we were listening to */
    1.85 -        private WeakReference lastRef;
    1.86 +        private Reference<Action> lastRef;
    1.87  
    1.88          public DelegateAction(CallbackSystemAction a, Lookup actionContext) {
    1.89              this.delegate = a;
    1.90 @@ -536,7 +537,7 @@
    1.91          /** Invoked when an action occurs.
    1.92           */
    1.93          public void actionPerformed(final java.awt.event.ActionEvent e) {
    1.94 -            final javax.swing.Action a = findAction();
    1.95 +            final Action a = findAction();
    1.96  
    1.97              if (a != null) {
    1.98                  org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable run;
    1.99 @@ -570,14 +571,14 @@
   1.100          }
   1.101  
   1.102          public boolean isEnabled() {
   1.103 -            javax.swing.Action a = findAction();
   1.104 +            Action a = findAction();
   1.105  
   1.106              if (a == null) {
   1.107                  a = delegate;
   1.108              }
   1.109  
   1.110              // 40915 - hold last action weakly
   1.111 -            javax.swing.Action last = (lastRef == null) ? null : (javax.swing.Action) lastRef.get();
   1.112 +            Action last = lastRef == null ? null : lastRef.get();
   1.113  
   1.114              if (a != last) {
   1.115                  if (last != null) {
   1.116 @@ -625,16 +626,13 @@
   1.117          /*** Finds an action that we should delegate to
   1.118           * @return the action or null
   1.119           */
   1.120 -        private javax.swing.Action findAction() {
   1.121 -            java.util.Collection c = (result != null) ? result.allInstances() : java.util.Collections.EMPTY_LIST;
   1.122 +        private Action findAction() {
   1.123 +            Collection<? extends ActionMap> c = result != null ? result.allInstances() : Collections.<ActionMap>emptySet();
   1.124  
   1.125              if (!c.isEmpty()) {
   1.126                  Object key = delegate.getActionMapKey();
   1.127 -
   1.128 -                for (Iterator it = c.iterator(); it.hasNext();) {
   1.129 -                    javax.swing.ActionMap map = (javax.swing.ActionMap) it.next();
   1.130 -                    javax.swing.Action action = map.get(key);
   1.131 -
   1.132 +                for (ActionMap map : c) {
   1.133 +                    Action action = map.get(key);
   1.134                      if (action != null) {
   1.135                          return action;
   1.136                      }
   1.137 @@ -683,7 +681,7 @@
   1.138          }
   1.139  
   1.140          protected void finalize() {
   1.141 -            javax.swing.Action last = (lastRef == null) ? null : (javax.swing.Action) lastRef.get();
   1.142 +            Action last = lastRef == null ? null : lastRef.get();
   1.143  
   1.144              if (last != null) {
   1.145                  last.removePropertyChangeListener(weakL);