570 action = a;
571 if (oldValue!=null) {
572 removeActionListener(oldValue);
573 oldValue.removePropertyChangeListener(actionPropertyChangeListener);
574 actionPropertyChangeListener = null;
575 }
576 configurePropertiesFromAction(action);
577 if (action!=null) {
578 // Don't add if it is already a listener
579 if (!isListener(ActionListener.class, action)) {
580 addActionListener(action);
581 }
582 // Reverse linkage:
583 actionPropertyChangeListener = createActionPropertyChangeListener(action);
584 action.addPropertyChangeListener(actionPropertyChangeListener);
585 }
586 firePropertyChange("action", oldValue, action);
587 }
588 }
589
590 private boolean isListener(Class c, ActionListener a) {
591 boolean isListener = false;
592 Object[] listeners = listenerList.getListenerList();
593 for (int i = listeners.length-2; i>=0; i-=2) {
594 if (listeners[i]==c && listeners[i+1]==a) {
595 isListener=true;
596 }
597 }
598 return isListener;
599 }
600
601 /**
602 * Returns the currently set <code>Action</code> for this
603 * <code>ActionEvent</code> source, or <code>null</code>
604 * if no <code>Action</code> is set.
605 *
606 * @return the <code>Action</code> for this <code>ActionEvent</code> source,
607 * or <code>null</code>
608 * @since 1.3
609 * @see Action
610 * @see #setAction
|
570 action = a;
571 if (oldValue!=null) {
572 removeActionListener(oldValue);
573 oldValue.removePropertyChangeListener(actionPropertyChangeListener);
574 actionPropertyChangeListener = null;
575 }
576 configurePropertiesFromAction(action);
577 if (action!=null) {
578 // Don't add if it is already a listener
579 if (!isListener(ActionListener.class, action)) {
580 addActionListener(action);
581 }
582 // Reverse linkage:
583 actionPropertyChangeListener = createActionPropertyChangeListener(action);
584 action.addPropertyChangeListener(actionPropertyChangeListener);
585 }
586 firePropertyChange("action", oldValue, action);
587 }
588 }
589
590 private boolean isListener(Class<?> c, ActionListener a) {
591 boolean isListener = false;
592 Object[] listeners = listenerList.getListenerList();
593 for (int i = listeners.length-2; i>=0; i-=2) {
594 if (listeners[i]==c && listeners[i+1]==a) {
595 isListener=true;
596 }
597 }
598 return isListener;
599 }
600
601 /**
602 * Returns the currently set <code>Action</code> for this
603 * <code>ActionEvent</code> source, or <code>null</code>
604 * if no <code>Action</code> is set.
605 *
606 * @return the <code>Action</code> for this <code>ActionEvent</code> source,
607 * or <code>null</code>
608 * @since 1.3
609 * @see Action
610 * @see #setAction
|