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

RFE: Documentation lacks Info that ButtonModel could perform the task of Action

    XMLWordPrintable

Details

    Description

      Name: jk109818 Date: 04/11/2003


      A DESCRIPTION OF THE REQUEST :
      Buttons that depend on the same action are most likely sharing state. Thus they have to share the same Model as this describes the state of the Button(s). The Model is in control of the Button state and whenever its inner state changes it notifies the button(s) to change their display accordingly. In fact: the ButtonModel API provides most of the functionality of Action _and_ implements the event/listener functionality to publish state changes to its views - which is definitely missing in Action. But this functionality is not emphasized in the API.

      JUSTIFICATION :
      The Action classes do not use the ButtonModel at all, instead they listen to few hard coded properties - and cannot adopt to the variety of button states that appear in applications. The most obvious lack is the ability to share the selection state between two or more buttons, or to change the selection/enabled state dynamically between buttons that share the same action. This can only be achieved with extra effort: the buttons have to share their models as well.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Action is promoted in the API as if it was the one solution to create several buttons at different places sharing the same functionality. In most cases, functionality depends on state, and the user will expect that the buttons that share Action share state, as well. This is not the case.

      The lack of sharing state gets obvious with toggle buttons: selecting one button does not select any other button with the same action. On the other hand - selecting a button(model) does select any other button depending on this model.

      Moreover: Attaching an ActionListener to the ButtonModel implements an actionPerformed method for any button that depends on this model and fires an action performed event whenever one of the buttons gets pressed.

      So why use Action at all? The reason is: ButtonModel does not provide the functionality to store a name and icons. But is this a great drawback?

      The API of ButtonModel states that this Model is used for CheckBoxes and RadioButtons. But actually it is used for any AbstractButton as that one already provides the method getModel(). The API does not document that ButtonModel provides the functionality to share state and action(Performed) between buttons. Neither does the Swing tutorial.

      My conclusion is: Most problems that occurr with Action might well be solved using ButtonModel. But as the documentation (API, Tutorial) does not mention this possibility, and instead pushes the use of Action, the user will most likely decide to use Action, and stumble over its deficiences sooner or later.

      CUSTOMER SUBMITTED WORKAROUND :
      Use ButtonModel in the first place.
      (Review ID: 182878)
      ======================================================================

      Attachments

        Activity

          People

            svioletsunw Scott Violet (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: