1106 action = a;
1107 if (oldValue!=null) {
1108 removeActionListener(oldValue);
1109 oldValue.removePropertyChangeListener(actionPropertyChangeListener);
1110 actionPropertyChangeListener = null;
1111 }
1112 configurePropertiesFromAction(action);
1113 if (action!=null) {
1114 // Don't add if it is already a listener
1115 if (!isListener(ActionListener.class, action)) {
1116 addActionListener(action);
1117 }
1118 // Reverse linkage:
1119 actionPropertyChangeListener = createActionPropertyChangeListener(action);
1120 action.addPropertyChangeListener(actionPropertyChangeListener);
1121 }
1122 firePropertyChange("action", oldValue, action);
1123 }
1124 }
1125
1126 private boolean isListener(Class c, ActionListener a) {
1127 boolean isListener = false;
1128 Object[] listeners = listenerList.getListenerList();
1129 for (int i = listeners.length-2; i>=0; i-=2) {
1130 if (listeners[i]==c && listeners[i+1]==a) {
1131 isListener=true;
1132 }
1133 }
1134 return isListener;
1135 }
1136
1137 /**
1138 * Returns the currently set <code>Action</code> for this
1139 * <code>ActionEvent</code> source, or <code>null</code>
1140 * if no <code>Action</code> is set.
1141 *
1142 * @return the <code>Action</code> for this <code>ActionEvent</code>
1143 * source, or <code>null</code>
1144 * @since 1.3
1145 * @see Action
1146 * @see #setAction
|
1106 action = a;
1107 if (oldValue!=null) {
1108 removeActionListener(oldValue);
1109 oldValue.removePropertyChangeListener(actionPropertyChangeListener);
1110 actionPropertyChangeListener = null;
1111 }
1112 configurePropertiesFromAction(action);
1113 if (action!=null) {
1114 // Don't add if it is already a listener
1115 if (!isListener(ActionListener.class, action)) {
1116 addActionListener(action);
1117 }
1118 // Reverse linkage:
1119 actionPropertyChangeListener = createActionPropertyChangeListener(action);
1120 action.addPropertyChangeListener(actionPropertyChangeListener);
1121 }
1122 firePropertyChange("action", oldValue, action);
1123 }
1124 }
1125
1126 private boolean isListener(Class<?> c, ActionListener a) {
1127 boolean isListener = false;
1128 Object[] listeners = listenerList.getListenerList();
1129 for (int i = listeners.length-2; i>=0; i-=2) {
1130 if (listeners[i]==c && listeners[i+1]==a) {
1131 isListener=true;
1132 }
1133 }
1134 return isListener;
1135 }
1136
1137 /**
1138 * Returns the currently set <code>Action</code> for this
1139 * <code>ActionEvent</code> source, or <code>null</code>
1140 * if no <code>Action</code> is set.
1141 *
1142 * @return the <code>Action</code> for this <code>ActionEvent</code>
1143 * source, or <code>null</code>
1144 * @since 1.3
1145 * @see Action
1146 * @see #setAction
|