Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4133141

Extend Action interface to handle toggles

XMLWordPrintable

    • b53
    • generic, x86
    • generic, linux, linux_redhat_7.2, windows_95, windows_98, windows_nt, windows_2000, windows_xp

      Name: rk38400 Date: 04/28/98


      I really like the Action interface (in fact, I'd
      implemented it myself in a previous version of my
      system) - but what about toggles? I'd like to be
      able to define a ToggleAction that has an on/off
      state. When I add it to a JToolbar, I'd get a
      JToggleButton. When I add it to a JMenu, I'd get
      a JCheckboxMenuItem. Setting its state to be on via
      the menuitem would cause the appearance of the
      JToggleButton to change automatically, etc.
      The same idea could probably be extended to encompass
      JRadioButton/JRadioButtonMenuItem pairs...
      (Review ID: 29188)
      ======================================================================

      Name: krT82822 Date: 01/24/2000


      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

      Why does the new method "JToolBar.CreateActionComponent" return a JButton?
      Because of this, it's not possible to create a JToggleButton for the action.

      Suggestion: CreateActionComponent should return a JAbstractButton or, even
      better, a Component (since buttons aren't the only thing usually visible in a
      toolbar, and for example ComboBoxes could be associated with an action as well).
      (Review ID: 100282)
      ======================================================================

      Name: krC82822 Date: 11/02/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      Right now Action and AbstractAction provides support for creating several
      controls with a common behaviour and with their enabled state synchronized, but
      there is no way to have several toggle buttons synchronized in such a way. I
      think it could be interesting to add ToggleAction and AbstractToggleAction, so
      we could have several toggle buttons with their selected state synchronized.
      The additional classes could be something like this:

      package javax.swing;

      public interface ToggleAction extends Action
        {
        boolean isSelected( );
        void setSelected( boolean selected );
        }
        


      package javax.swing;

      import java.io.Serializable;
      import java.awt.event.*;

      public abstract class AbstractToggleAction extends AbstractAction
      implements ToggleAction, Cloneable, Serializable
        {
        protected boolean selected = false;

        public AbstractToggleAction( )
          { super( ); }

        public AbstractToggleAction( String name )
          { super( name ); }

        public AbstractToggleAction( String name, Icon icon )
          { super( name, icon ); }

        public Object clone( )
          {
          AbstractToggleAction copy = null;
          try
            {
            copy = (AbstractToggleAction) super.clone( );
            copy.selected = this.selected;
            }
          catch( CloneNotSupportedException exc )
            {}
          return copy;
          }

        public boolean isSelected( )
          { return selected; }

        public void setSelected( boolean selected )
          {
          if( this.selected != selected )
            {
            this.selected = selected;
            firePropertyChange( "selected", new Boolean( !this.selected ), new Boolean
      ( this.selected ) );
            }
          }
          
        public void actionPerformed( ActionEvent e )
          {
          Object source = e.getSource( );
          if( source instanceof AbstractButton )
            {
            AbstractButton button = (AbstractButton) source;
            setSelected( button.isSelected( ) );
            }
          }
        }

      This classes could be used adding a setToggleAction method to JToggleButton and
      JCheckboxMenuItem.
      (Review ID: 111728)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: