Class SwingActionManager

  • All Implemented Interfaces:
    net.sf.jguiraffe.gui.builder.action.ActionManager

    public class SwingActionManager
    extends Object
    implements net.sf.jguiraffe.gui.builder.action.ActionManager

    The Swing specific implementation of the ActionManager interface.

    This class implements the ActionManager methods in a way that correctly initialized Swing objects (like Actions and JMenus) are created.

    Version:
    $Id: SwingActionManager.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addMenuSeparator​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, Object menu)
      Adds a separator to the given menu.
      protected void addToMenu​(Object parent, JMenuItem item)
      Adds a menu item to a parent menu.
      void addToolBarSeparator​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, Object toolBar)
      Adds a separator to the given tool bar.
      protected void addToToolbar​(Object parent, AbstractButton button)
      Adds a tool button to the parent bar.
      net.sf.jguiraffe.gui.builder.action.FormAction createAction​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, net.sf.jguiraffe.gui.builder.action.ActionData actionData)
      Creates an action object.
      Object createMenu​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, Object menu, net.sf.jguiraffe.gui.builder.components.tags.TextIconData data, Object parent)
      Creates a menu based on the given data.
      Object createMenuBar​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder)
      Creates a menu bar.
      net.sf.jguiraffe.gui.forms.ComponentHandler<?> createMenuItem​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, net.sf.jguiraffe.gui.builder.action.ActionData actionData, boolean checked, Object parent)
      Creates a menu item based on the passed in data object.
      Object createMenuItem​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, net.sf.jguiraffe.gui.builder.action.FormAction formAction, boolean checked, Object parent)
      Creates a menu item based on the given action.
      Object createToolbar​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder)
      Creates a tool bar object.
      net.sf.jguiraffe.gui.forms.ComponentHandler<?> createToolbarButton​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, net.sf.jguiraffe.gui.builder.action.ActionData data, boolean checked, Object parent)
      Creates a toolbar button based on the passed in action data object and returns a component handler for it.
      Object createToolbarButton​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder, net.sf.jguiraffe.gui.builder.action.FormAction formAction, boolean checked, Object parent)
      Creates a toolbar button based on the given action.
      void registerPopupMenuHandler​(Object component, net.sf.jguiraffe.gui.builder.action.PopupMenuHandler handler, net.sf.jguiraffe.gui.builder.components.ComponentBuilderData compData)
      Associates a PopupMenuHandler with a UI component.
    • Constructor Detail

      • SwingActionManager

        public SwingActionManager()
    • Method Detail

      • createAction

        public net.sf.jguiraffe.gui.builder.action.FormAction createAction​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                                                           net.sf.jguiraffe.gui.builder.action.ActionData actionData)
                                                                    throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates an action object. The returned object will also implement Swing's Action interface.
        Specified by:
        createAction in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        actionData - the properties of the new action
        Returns:
        the newly created action
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createMenuItem

        public Object createMenuItem​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                     net.sf.jguiraffe.gui.builder.action.FormAction formAction,
                                     boolean checked,
                                     Object parent)
                              throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a menu item based on the given action. Depending on the checked argument either a JMenuItem or a JCheckBoxMenuItem object will be returned.
        Specified by:
        createMenuItem in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        formAction - the action to associate with the menu item; this object must implement Swing's Action interface
        checked - the checked flag
        parent - the parent menu; this must be an instance of JMenu
        Returns:
        the new menu item
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createMenuItem

        public net.sf.jguiraffe.gui.forms.ComponentHandler<?> createMenuItem​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                                                             net.sf.jguiraffe.gui.builder.action.ActionData actionData,
                                                                             boolean checked,
                                                                             Object parent)
                                                                      throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a menu item based on the passed in data object. Depending on the checked argument either a JMenuItem or a JCheckBoxMenuItem object will be returned.
        Specified by:
        createMenuItem in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        actionData - the action data object
        checked - the checked flag
        parent - the parent menu; this must be an instance of JMenu
        Returns:
        the new menu item
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createMenuBar

        public Object createMenuBar​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder)
                             throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a menu bar. This implementation will return a new JMenuBar object.
        Specified by:
        createMenuBar in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        Returns:
        the new menu bar
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createMenu

        public Object createMenu​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                 Object menu,
                                 net.sf.jguiraffe.gui.builder.components.tags.TextIconData data,
                                 Object parent)
                          throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a menu based on the given data. The return value will be a JMenu object.
        Specified by:
        createMenu in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        menu - the menu object (null in the creation phase, a not null JMenu instance in the initialization phase)
        data - the data for the new menu
        parent - the menu's parent (a menu bar or a menu)
        Returns:
        the new menu
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs, i.e. if the parent is undefined
      • createToolbar

        public Object createToolbar​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder)
                             throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a tool bar object. This implementation returns a JToolBar object.
        Specified by:
        createToolbar in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        Returns:
        the new tool bar
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createToolbarButton

        public Object createToolbarButton​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                          net.sf.jguiraffe.gui.builder.action.FormAction formAction,
                                          boolean checked,
                                          Object parent)
                                   throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a toolbar button based on the given action. Depending on the checked argument either a JButton or a JToggleButton object will be returned.
        Specified by:
        createToolbarButton in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        formAction - the action to associate with the menu item; this object must implement Swing's Action interface
        checked - the checked flag
        parent - the parent toolbar; this must be an instance of JToolBar
        Returns:
        the new tool button
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • createToolbarButton

        public net.sf.jguiraffe.gui.forms.ComponentHandler<?> createToolbarButton​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                                                                  net.sf.jguiraffe.gui.builder.action.ActionData data,
                                                                                  boolean checked,
                                                                                  Object parent)
                                                                           throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Creates a toolbar button based on the passed in action data object and returns a component handler for it. Depending on the checked argument either a JButton or a JToggleButton object will be created.
        Specified by:
        createToolbarButton in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        data - the action data object with the properties for the tool button
        checked - the checked flag
        parent - the parent toolbar; this must be an instance of JToolBar
        Returns:
        a component handler for the new tool button
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • addMenuSeparator

        public void addMenuSeparator​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                     Object menu)
                              throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Adds a separator to the given menu. The passed in menu must be an instance of JMenu.
        Specified by:
        addMenuSeparator in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        menu - the menu
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • addToolBarSeparator

        public void addToolBarSeparator​(net.sf.jguiraffe.gui.builder.action.ActionBuilder actionBuilder,
                                        Object toolBar)
                                 throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Adds a separator to the given tool bar. The passed in object must be an instance of JToolBar.
        Specified by:
        addToolBarSeparator in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        actionBuilder - the action builder
        toolBar - the tool bar
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
      • registerPopupMenuHandler

        public void registerPopupMenuHandler​(Object component,
                                             net.sf.jguiraffe.gui.builder.action.PopupMenuHandler handler,
                                             net.sf.jguiraffe.gui.builder.components.ComponentBuilderData compData)
                                      throws net.sf.jguiraffe.gui.builder.action.FormActionException
        Associates a PopupMenuHandler with a UI component. This implementation expects that the passed in object is derived from java.awt.Component. It registers a special mouse listener at this component that is looking for gestures triggering a popup menu. When such a gesture is detected the PopupMenuHandler object is invoked.
        Specified by:
        registerPopupMenuHandler in interface net.sf.jguiraffe.gui.builder.action.ActionManager
        Parameters:
        component - the component
        handler - the handler to register
        compData - the component builder data object
        Throws:
        net.sf.jguiraffe.gui.builder.action.FormActionException - if an error occurs
        IllegalArgumentException - if a required parameter is missing
      • addToMenu

        protected void addToMenu​(Object parent,
                                 JMenuItem item)
        Adds a menu item to a parent menu. The menu must be an instance of JMenu or JPopupMenu.
        Parameters:
        parent - the parent menu
        item - the item to add
      • addToToolbar

        protected void addToToolbar​(Object parent,
                                    AbstractButton button)
        Adds a tool button to the parent bar. The bar must be an instance of JToolBar.
        Parameters:
        parent - the parent tool bar
        button - the button to add