Class ToggleActionPropertyChangeListener

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener

    class ToggleActionPropertyChangeListener
    extends java.lang.Object
    implements java.beans.PropertyChangeListener
    Added to the Toggle type buttons and menu items so that various components which have been created from a single StateChangeAction can be in synch. This listener is responsible for updating the selected property from the Action to the AbstractButton.

    It guarantees a maximum of 1 instance of ToggleActionPCL to be installed per button (PENDING JW: add test to verify). It removes all ToggleActionPCLs which are targeted to unreachable buttons from the action's listener list.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ref.WeakReference<javax.swing.AbstractButton> buttonRef  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected javax.swing.AbstractButton checkReferent​(javax.swing.Action action)
      Returns the target button to synchronize from the listener.
      boolean isToggling​(javax.swing.AbstractButton button)
      Check if this is already synchronizing the given AbstractButton.
      protected boolean isToggling​(javax.swing.Action action, javax.swing.AbstractButton button)  
      void propertyChange​(java.beans.PropertyChangeEvent evt)  
      protected void releasePCLs​(javax.swing.Action action)
      Removes all ToggleActionPCLs with unreachable target buttons from the Action's PCL-listeners.
      protected boolean shouldAddListener​(javax.swing.Action action, javax.swing.AbstractButton button)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • buttonRef

        private java.lang.ref.WeakReference<javax.swing.AbstractButton> buttonRef
    • Constructor Detail

      • ToggleActionPropertyChangeListener

        public ToggleActionPropertyChangeListener​(javax.swing.Action action,
                                                  javax.swing.AbstractButton button)
    • Method Detail

      • shouldAddListener

        protected boolean shouldAddListener​(javax.swing.Action action,
                                            javax.swing.AbstractButton button)
      • isToggling

        protected boolean isToggling​(javax.swing.Action action,
                                     javax.swing.AbstractButton button)
      • releasePCLs

        protected void releasePCLs​(javax.swing.Action action)
        Removes all ToggleActionPCLs with unreachable target buttons from the Action's PCL-listeners.
        Parameters:
        action - to cleanup.
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • checkReferent

        protected javax.swing.AbstractButton checkReferent​(javax.swing.Action action)
        Returns the target button to synchronize from the listener. Side-effects if the target is no longer reachable: - the internal reference to target is nulled. - if the given action is != null, this listener removes itself from the action's listener list.
        Parameters:
        action - The action this is listening to.
        Returns:
        the target button if it is strongly reachable or null if it is no longer strongly reachable.
      • isToggling

        public boolean isToggling​(javax.swing.AbstractButton button)
        Check if this is already synchronizing the given AbstractButton. This may have the side-effect of releasing the weak reference to the target button.
        Parameters:
        button - must not be null
        Returns:
        true if this target button and the given comp are equal false otherwise.
        Throws:
        java.lang.NullPointerException - if the button is null.