Class JMTToolBar

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants
Direct Known Subclasses:
ComponentBar

public class JMTToolBar extends JToolBar

Name: JMTToolbar

Description: A generic toolbar with many enhancements to be used by JMT. Image name can be stored inside Action or explicitly inserted. Pressed, rollover and selected (toggled) buttons requires images with the appropriate suffixes.

Date: 30/gen/07 Time: 10:44:05

Version:
1.0
Author:
Bertoli Marco
See Also:
  • Field Details

  • Constructor Details

    • JMTToolBar

      public JMTToolBar(ImageLoader loader)
      Builds a new toolbar
      Parameters:
      loader - component used to load images
  • Method Details

    • addButton

      public JButton addButton(Action action, String iconName)
      Adds a new button to this toolbar.
      Parameters:
      action - action associated to the button
      iconName - image to be displayed on the button. If null the image from the action is used. If this is reset too, the name is displayed.
      Returns:
      created button
    • addButton

      public JButton addButton(AbstractJMTAction action)
      Adds a new button to this toolbar.
      Parameters:
      action - action associated to the button
      Returns:
      created button
    • addToggleButton

      public JToggleButton addToggleButton(AbstractJMTAction action, String iconName, int group)
      Adds a new button toggle to this toolbar.
      Parameters:
      action - action associated to the button
      iconName - image to be displayed on the button. If null the image from the action is used. If this is reset too, the name is displayed.
      group - identifier of button group. Each button belonging to the same group cannot be pressed together. Groups are created here, if group is less than zero means no grouping.
      Returns:
      created button
    • addToggleButton

      public JToggleButton addToggleButton(AbstractJMTAction action, String iconName)
      Adds a new button toggle to this toolbar. This button has no group.
      Parameters:
      action - action associated to the button
      iconName - image to be displayed on the button. If null the image from the action is used. If this is reset too, the name is displayed.
      Returns:
      created button
    • addToggleButton

      public JToggleButton addToggleButton(AbstractJMTAction action, int group)
      Adds a new button toggle to this toolbar.
      Parameters:
      action - action associated to the button
      group - identifier of button group. Each button belonging to the same group cannot be pressed together. Groups are created here, if group is less than zero means no grouping.
      Returns:
      created button
    • addToggleButton

      public JToggleButton addToggleButton(AbstractJMTAction action)
      Adds a new button toggle to this toolbar. This button has no group.
      Parameters:
      action - action associated to the button
      Returns:
      created button
    • addGenericButton

      public AbstractButton addGenericButton(AbstractJMTAction action)
      Adds a button deriving all properties from specified action
      Parameters:
      action - action associated to the button
      Returns:
      created button
    • removeButton

      public AbstractButton removeButton(AbstractJMTAction action)
      Removes any type of button (including toggle ones) from this toolbar
      Parameters:
      action - action of the button to be removed
      Returns:
      removed button
    • addSeparator

      public void addSeparator()
      Overrides:
      addSeparator in class JToolBar
    • getButtonGroup

      public JMTButtonGroup getButtonGroup(int group)
      Returns a button group
      Parameters:
      group - identifier of button group
      Returns:
      the button group or null if it does not exists
    • getButton

      public AbstractButton getButton(AbstractJMTAction action)
      Returns a button, given its name
      Parameters:
      action - action of the button to be returned
      Returns:
      found button
    • enableButtonGroup

      public void enableButtonGroup(int group, boolean value)
      Enables or disables every button of a button group
      Parameters:
      group - group to be enabled or disabled
      value - true to enable the group, false to disable it.
    • clearButtonGroupSelection

      public void clearButtonGroupSelection(int group)
      Clears selection of a button group
      Parameters:
      group - group to be deselected
    • clickButton

      public void clickButton(AbstractJMTAction action)
      Clicks a given button
      Parameters:
      action - action of the button to be clicked
    • getAllButtons

      public HashSet<AbstractButton> getAllButtons()
      Returns all buttons inside this toolbar
      Returns:
      a set with all buttons
    • enableButtons

      public void enableButtons(boolean enable)
      Enables or disables all buttons of this toolbar
      Parameters:
      enable - true to enable every button, false to disable them
    • populateToolbar

      public ArrayList<JComponent> populateToolbar(Collection<AbstractJMTAction> abstractJMTactions)
      Populates this toolbar reading all properties from specified actions. null values are used to add a separator.
      Parameters:
      abstractJMTactions - a collection of AbstractJMTAction with all actions to be added
      Returns:
      an ArrayList with all added objects (each element is instanceof AbstractButton)
      See Also:
    • populateToolbar

      public ArrayList<AbstractButton> populateToolbar(AbstractJMTAction[] abstractJMTactions)
      Populates this toolbar reading all properties from specified actions. null values are used to add a separator.
      Parameters:
      abstractJMTactions - an array of AbstractJMTAction with all actions to be added
      Returns:
      an ArrayList with all added objects (each element is instanceof AbstractButton)
      See Also:
    • getOrCreateGroup

      protected JMTButtonGroup getOrCreateGroup(int group)
      Returns a button group if present, otherwise creates and adds it.
      Parameters:
      group - group to be get
      Returns:
      created group