Class ActionContainerFactory


  • public class ActionContainerFactory
    extends java.lang.Object
    Creates user interface elements based on action ids and lists of action ids. All action ids must represent actions managed by the ActionManager.

    Action Lists

    Use the createXXX(List) methods to construct containers of actions like menu bars, menus, popups and toolbars from actions represented as action ids in a java.util.List. Each element in the action-list can be one of 3 types:
    • action id: corresponds to an action managed by the ActionManager
    • null: indicates a separator should be inserted.
    • java.util.List: represents a submenu. See the note below which describes the configuration of menus.
    • The order of elements in an action-list determines the arrangement of the ui components which are constructed from the action-list.

      For a menu or submenu, the first element in the action-list represents a menu and subsequent elements represent menu items or separators (if null).

      This class can be used as a general component factory which will construct components from Actions if the create<comp>(Action,...) methods are used.

    See Also:
    ActionManager
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Integer,​javax.swing.ButtonGroup> groupMap  
      private javax.swing.ActionMap manager  
      private static java.awt.Insets TOOLBAR_BUTTON_MARGIN
      Standard margin for toolbar buttons to improve their look
    • Constructor Summary

      Constructors 
      Constructor Description
      ActionContainerFactory()
      Constructs an container factory which uses the default ActionManager.
      ActionContainerFactory​(javax.swing.ActionMap manager)
      Constructs an container factory which uses managed actions.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void configureButton​(javax.swing.JToggleButton button, AbstractActionExt a, javax.swing.ButtonGroup group)  
      protected void configureButtonFromExtActionProperties​(javax.swing.AbstractButton button, javax.swing.Action action)
      This method will be called after buttons created from an action.
      protected void configureMenuItemFromExtActionProperties​(javax.swing.JMenuItem menuItem, javax.swing.Action action)
      This method will be called after menu items are created.
      void configureSelectableButton​(javax.swing.AbstractButton button, AbstractActionExt a, javax.swing.ButtonGroup group)
      method to configure a "selectable" button from the given AbstractActionExt.
      javax.swing.AbstractButton createButton​(java.lang.Object id, javax.swing.JComponent container)
      Creates, configures and returns an AbstractButton.
      javax.swing.AbstractButton createButton​(javax.swing.Action action)
      Creates a button based on the attributes of the action.
      javax.swing.AbstractButton createButton​(javax.swing.Action action, javax.swing.JComponent container)
      Creates a button based on the attributes of the action.
      private javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem​(AbstractActionExt a)
      Helper method to add a checkbox menu item.
      javax.swing.JMenu createMenu​(java.lang.Object[] actionIds)
      Creates and returns a menu from a List which represents actions, separators and sub-menus.
      javax.swing.JMenu createMenu​(java.util.List<?> list)
      Creates and returns a menu from a List which represents actions, separators and sub-menus.
      javax.swing.JMenuBar createMenuBar​(java.lang.Object[] actionIds)
      Constructs a menu tree from a list of actions or lists of lists or actions.
      javax.swing.JMenuBar createMenuBar​(java.util.List<?> list)
      Constructs a menu tree from a list of actions or lists of lists or actions.
      private javax.swing.JMenuItem createMenuItem​(java.lang.Object id, javax.swing.JComponent container)
      Creates a menu item based on the attributes of the action element.
      javax.swing.JMenuItem createMenuItem​(javax.swing.Action action)
      Creates a menu item based on the attributes of the action.
      private javax.swing.JMenuItem createMenuItem​(javax.swing.Action action, javax.swing.JComponent container)
      Creates a menu item based on the attributes of the action element.
      javax.swing.JPopupMenu createPopup​(java.lang.Object[] list)
      Constructs a popup menu from an array of action ids.
      javax.swing.JPopupMenu createPopup​(java.util.List<?> list)
      Constructs a popup menu from a list of action ids.
      private javax.swing.JRadioButtonMenuItem createRadioButtonMenuItem​(javax.swing.ButtonGroup group, AbstractActionExt a)
      Helper method to add a radio button menu item.
      private javax.swing.JToggleButton createToggleButton​(AbstractActionExt a)
      Adds and configures a toggle button.
      private javax.swing.JToggleButton createToggleButton​(AbstractActionExt a, javax.swing.ButtonGroup group)
      Adds and configures a toggle button.
      javax.swing.JToolBar createToolBar​(java.lang.Object[] list)
      Constructs a toolbar from an action-list id.
      javax.swing.JToolBar createToolBar​(java.util.List<?> list)
      Constructs a toolbar from an action-list id.
      private javax.swing.Action getAction​(java.lang.Object id)
      Convenience method to get the action from an ActionManager.
      javax.swing.ActionMap getActionManager()
      Gets the ActionManager instance.
      private javax.swing.ButtonGroup getGroup​(java.lang.String groupid, javax.swing.JComponent container)
      Returns the button group corresponding to the groupid
      void setActionManager​(javax.swing.ActionMap manager)
      Sets the ActionManager instance that will be used by this ActionContainerFactory
      • Methods inherited from class java.lang.Object

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

      • TOOLBAR_BUTTON_MARGIN

        private static java.awt.Insets TOOLBAR_BUTTON_MARGIN
        Standard margin for toolbar buttons to improve their look
      • manager

        private javax.swing.ActionMap manager
      • groupMap

        private java.util.Map<java.lang.Integer,​javax.swing.ButtonGroup> groupMap
    • Constructor Detail

      • ActionContainerFactory

        public ActionContainerFactory()
        Constructs an container factory which uses the default ActionManager.
      • ActionContainerFactory

        public ActionContainerFactory​(javax.swing.ActionMap manager)
        Constructs an container factory which uses managed actions.
        Parameters:
        manager - use the actions managed with this manager for constructing ui componenents.
    • Method Detail

      • getActionManager

        public javax.swing.ActionMap getActionManager()
        Gets the ActionManager instance. If the ActionManager has not been explicitly set then the default ActionManager instance will be used.
        Returns:
        the ActionManager used by the ActionContainerFactory.
        See Also:
        setActionManager(javax.swing.ActionMap)
      • setActionManager

        public void setActionManager​(javax.swing.ActionMap manager)
        Sets the ActionManager instance that will be used by this ActionContainerFactory
      • createToolBar

        public javax.swing.JToolBar createToolBar​(java.lang.Object[] list)
        Constructs a toolbar from an action-list id. By convention, the identifier of the main toolbar should be "main-toolbar"
        Parameters:
        list - a list of action ids used to construct the toolbar.
        Returns:
        the toolbar or null
      • createToolBar

        public javax.swing.JToolBar createToolBar​(java.util.List<?> list)
        Constructs a toolbar from an action-list id. By convention, the identifier of the main toolbar should be "main-toolbar"
        Parameters:
        list - a list of action ids used to construct the toolbar.
        Returns:
        the toolbar or null
      • createPopup

        public javax.swing.JPopupMenu createPopup​(java.lang.Object[] list)
        Constructs a popup menu from an array of action ids.
        Parameters:
        list - an array of action ids used to construct the popup.
        Returns:
        the popup or null
      • createPopup

        public javax.swing.JPopupMenu createPopup​(java.util.List<?> list)
        Constructs a popup menu from a list of action ids.
        Parameters:
        list - a list of action ids used to construct the popup.
        Returns:
        the popup or null
      • createMenuBar

        public javax.swing.JMenuBar createMenuBar​(java.lang.Object[] actionIds)
        Constructs a menu tree from a list of actions or lists of lists or actions.
        Parameters:
        actionIds - an array which represents the root item.
        Returns:
        a menu bar which represents the menu bar tree
      • createMenuBar

        public javax.swing.JMenuBar createMenuBar​(java.util.List<?> list)
        Constructs a menu tree from a list of actions or lists of lists or actions.
        Parameters:
        list - a list which represents the root item.
        Returns:
        a menu bar which represents the menu bar tree
      • createMenu

        public javax.swing.JMenu createMenu​(java.lang.Object[] actionIds)
        Creates and returns a menu from a List which represents actions, separators and sub-menus. The menu constructed will have the attributes from the first action in the List. Subsequent actions in the list represent menu items.
        Parameters:
        actionIds - an array of action ids used to construct the menu and menu items. the first element represents the action used for the menu,
        Returns:
        the constructed JMenu or null
      • createMenu

        public javax.swing.JMenu createMenu​(java.util.List<?> list)
        Creates and returns a menu from a List which represents actions, separators and sub-menus. The menu constructed will have the attributes from the first action in the List. Subsequent actions in the list represent menu items.
        Parameters:
        list - a list of action ids used to construct the menu and menu items. the first element represents the action used for the menu,
        Returns:
        the constructed JMenu or null
      • getAction

        private javax.swing.Action getAction​(java.lang.Object id)
        Convenience method to get the action from an ActionManager.
      • getGroup

        private javax.swing.ButtonGroup getGroup​(java.lang.String groupid,
                                                 javax.swing.JComponent container)
        Returns the button group corresponding to the groupid
        Parameters:
        groupid - the value of the groupid attribute for the action element
        container - a container which will further identify the ButtonGroup
      • createMenuItem

        private javax.swing.JMenuItem createMenuItem​(java.lang.Object id,
                                                     javax.swing.JComponent container)
        Creates a menu item based on the attributes of the action element. Will return a JMenuItem, JRadioButtonMenuItem or a JCheckBoxMenuItem depending on the context of the Action.
        Returns:
        a JMenuItem or subclass depending on type.
      • createMenuItem

        private javax.swing.JMenuItem createMenuItem​(javax.swing.Action action,
                                                     javax.swing.JComponent container)
        Creates a menu item based on the attributes of the action element. Will return a JMenuItem, JRadioButtonMenuItem or a JCheckBoxMenuItem depending on the context of the Action.
        Parameters:
        action - a managed Action
        container - the parent container may be null for non-group actions.
        Returns:
        a JMenuItem or subclass depending on type.
      • createMenuItem

        public javax.swing.JMenuItem createMenuItem​(javax.swing.Action action)
        Creates a menu item based on the attributes of the action. Will return a JMenuItem, JRadioButtonMenuItem or a JCheckBoxMenuItem depending on the context of the Action.
        Parameters:
        action - an action used to create the menu item
        Returns:
        a JMenuItem or subclass depending on type.
      • createButton

        public javax.swing.AbstractButton createButton​(java.lang.Object id,
                                                       javax.swing.JComponent container)
        Creates, configures and returns an AbstractButton. The attributes of the action element registered with the ActionManger by the given id. Will return a JButton or a JToggleButton.
        Parameters:
        id - the identifier
        container - the JComponent which parents the group, if any.
        Returns:
        an AbstractButton based on the
      • createButton

        public javax.swing.AbstractButton createButton​(javax.swing.Action action,
                                                       javax.swing.JComponent container)
        Creates a button based on the attributes of the action. If the container parameter is non-null then it will be used to uniquely identify the returned component within a ButtonGroup. If the action doesn't represent a grouped component then this value can be null.
        Parameters:
        action - an action used to create the button
        container - the parent container to uniquely identify grouped components or null
        Returns:
        will return a JButton or a JToggleButton.
      • createButton

        public javax.swing.AbstractButton createButton​(javax.swing.Action action)
        Creates a button based on the attributes of the action.
        Parameters:
        action - an action used to create the button
        Returns:
        will return a JButton or a JToggleButton.
      • createToggleButton

        private javax.swing.JToggleButton createToggleButton​(AbstractActionExt a)
        Adds and configures a toggle button.
        Parameters:
        a - an abstraction of a toggle action.
      • createToggleButton

        private javax.swing.JToggleButton createToggleButton​(AbstractActionExt a,
                                                             javax.swing.ButtonGroup group)
        Adds and configures a toggle button.
        Parameters:
        a - an abstraction of a toggle action.
        group - the group to add the toggle button or null
      • configureButton

        public void configureButton​(javax.swing.JToggleButton button,
                                    AbstractActionExt a,
                                    javax.swing.ButtonGroup group)
        Parameters:
        button -
        a -
        group -
      • configureSelectableButton

        public void configureSelectableButton​(javax.swing.AbstractButton button,
                                              AbstractActionExt a,
                                              javax.swing.ButtonGroup group)
        method to configure a "selectable" button from the given AbstractActionExt. As there is some un-/wiring involved to support synch of the selected property between the action and the button, all config and unconfig (== setting a null action!) should be passed through this method.

        It's up to the client to only pass in button's where selected and/or the group property makes sense. PENDING: the group properties are yet untested. PENDING: think about automated unconfig.

        Parameters:
        button - where selected makes sense
        a -
        group - the button should be added to.
        Throws:
        java.lang.IllegalArgumentException - if the given action doesn't have the state flag set.
      • configureButtonFromExtActionProperties

        protected void configureButtonFromExtActionProperties​(javax.swing.AbstractButton button,
                                                              javax.swing.Action action)
        This method will be called after buttons created from an action. Override for custom configuration.
        Parameters:
        button - the button to be configured
        action - the action used to construct the menu item.
      • configureMenuItemFromExtActionProperties

        protected void configureMenuItemFromExtActionProperties​(javax.swing.JMenuItem menuItem,
                                                                javax.swing.Action action)
        This method will be called after menu items are created. Override for custom configuration.
        Parameters:
        menuItem - the menu item to be configured
        action - the action used to construct the menu item.
      • createCheckBoxMenuItem

        private javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem​(AbstractActionExt a)
        Helper method to add a checkbox menu item.
      • createRadioButtonMenuItem

        private javax.swing.JRadioButtonMenuItem createRadioButtonMenuItem​(javax.swing.ButtonGroup group,
                                                                           AbstractActionExt a)
        Helper method to add a radio button menu item.