SRJRCFrames
v0.1.296

de.schwarzrot.ui.action.support
Class ApplicationCommandFactory

java.lang.Object
  extended by de.schwarzrot.ui.action.support.ApplicationCommandFactory

public class ApplicationCommandFactory
extends Object

a factory to generate action related UI elements like menues, menuebars, toolbars. General menubar creation is implemented by contract. The application defines some enums, that serve as key in message lookup and translation, as well as finding related icons, ...

To allow general processing, the name of the enum consists of several parts. Divider is the '_' (underscore).

sample:

 private enum Command {
      FILE_NEW,
      SEP_FILE_0,
      FILE_READ,
      FILE_WRITE,
      SEP_FILE_1,
      FILE_EXIT,
      VIEW_DETAIL,
      SEP_VIEW_0,
      VIEW_SPECIAL,
      EDIT_RENAME,
      EDIT_TAG,
      EDIT_SPLIT,
      EDIT_JOIN,
      SEP_EDIT_0,        
      EDIT_PREFERENCES,
      EXTRA_SCAN,
      EXTRA_SWITCH_SUB
  };
 
The last enum entry consists of 3 parts: EXTRA, wich is recognized as menue identifier (menu-name of menubar). The second part SWITCH is the simple name of the menue action (but the action identifier is the entire enum name). The last part SUB signals, that this menueitem will be a submenu.

Another special entry is i.e. SEP_FILE_0, where the first part SEP signals the creation of a separator. So the second part FILE is the menue identifier, where the separator should be added to. To allow multiple separators in command definitions, a suffix may be added. Its value is to keep enum entries unique, the suffix is not evaluated at all.

The items will be processed in the given order, so different orders in different situations could be fulfilled by the use of EnumSet.

The creation of submenus is performed by a call to ActionHandler.createSubMenu(<i>Enum&lt;?&gt; cmd</i>), so dynamic menus could be created, as well as static submenus. The default implementation of createSubMenu returns null.

The ActionHandler is a class to hold and handle Actions, as well as to provide access to actions by name. All ActionHandlers are related and able to find a given Action, even if it was defined in an unknown, but active Handler. For this reason - naturally - the handler names must be unique - as well as the application identifiers.

The Desktop class is responsable for the main menue and the handling of active applications. To fulfill that job, the application has a public accessor to the default ActionHandler ActionHandler getActionHandler. The ActionHandler itself gives access to its implemented ActionCommands by the getter Enum&lt;?&gt;[] getCommands().

Author:
Reinhard Mantey
See Also:
AbstractDesktop, Application, ActionHandler

Constructor Summary
ApplicationCommandFactory(ActionHandler[] handlers)
           
 
Method Summary
protected  JMenu buildMenu(JMenu menu, String name, Enum<?>[] commands)
           
protected  JPopupMenu buildPopup(JPopupMenu pm, String name, Enum<?>[] commands)
           
 JButton createButton(String appID, Enum<?> cmd)
           
 JMenuItem createCheckBoxMenuItem(String appID, Enum<?> cmd)
           
 JMenuItem createContextMenuItem(String appID, Enum<?> cmd, Object context)
           
 JMenu createMenu(Enum<?> cmd)
           
 JMenu createMenu(String key)
           
 JMenu createMenu(String name, Enum<?>[] commands)
           
 JMenu createMenu(String name, Enum<?>[][] cmdList)
           
 JMenu createMenu(String appID, String menuID)
           
 JMenu createMenu(String name, String[] commands)
           
 JMenuBar createMenuBar()
           
 JMenuBar createMenuBar(JMenuBar menuBar, String name, Enum<?>[] commands)
           
 JMenuItem createMenuItem(String appID, Enum<?> cmd)
           
 JMenuItem createMenuItem(String appID, String actionKey)
           
protected  void createMenus(JMenuBar menuBar, String name, Enum<?>[] commands)
           
 JPopupMenu createPopup(String name, Enum<?>[] commands)
           
 JPopupMenu createPopup(String name, Enum<?>[][] cmdList)
           
 JMenuItem createRadioButtonMenuItem(String appID, Enum<?> cmd)
           
protected  JMenu createSubMenu(Enum<?> cmd)
           
protected  JMenu createSubMenu(String cmd)
           
 JToolBar createToolBar()
           
 JToolBar createToolBar(int orientation)
           
protected  void createToolBar(JToolBar tb, String appID, Enum<?>[] commands, int orientation)
           
 JToolBar createToolBar(String appID, Enum<?>[] commands)
           
 JToolBar createToolBar(String appID, Enum<?>[] commands, int orientation)
           
 JButton createToolBarButton(String appID, Enum<?> cmd, int orientation)
           
 JButton createToolBarButton(String appID, String cmd, int orientation)
           
protected  AbstractAction findAction(Enum<?> cmd)
           
protected  AbstractAction findAction(String itemID)
           
protected  AbstractAction findAction(String appID, Enum<?> cmd)
           
protected  AbstractAction findAction(String appID, String cmd)
           
 ActionHandler[] getHandlers()
           
 void setupAppIcon(JToggleButton ai, String name)
           
protected  void validateMenu(JMenu menu)
           
protected  void validateMenuBar(JMenuBar mb)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationCommandFactory

public ApplicationCommandFactory(ActionHandler[] handlers)
Method Detail

createButton

public JButton createButton(String appID,
                            Enum<?> cmd)

createCheckBoxMenuItem

public JMenuItem createCheckBoxMenuItem(String appID,
                                        Enum<?> cmd)

createContextMenuItem

public JMenuItem createContextMenuItem(String appID,
                                       Enum<?> cmd,
                                       Object context)

createMenu

public JMenu createMenu(Enum<?> cmd)

createMenu

public JMenu createMenu(String key)

createMenu

public JMenu createMenu(String name,
                        Enum<?>[] commands)

createMenu

public JMenu createMenu(String name,
                        Enum<?>[][] cmdList)

createMenu

public JMenu createMenu(String appID,
                        String menuID)

createMenu

public JMenu createMenu(String name,
                        String[] commands)

createMenuBar

public JMenuBar createMenuBar()

createMenuBar

public JMenuBar createMenuBar(JMenuBar menuBar,
                              String name,
                              Enum<?>[] commands)

createMenuItem

public JMenuItem createMenuItem(String appID,
                                Enum<?> cmd)

createMenuItem

public JMenuItem createMenuItem(String appID,
                                String actionKey)

createPopup

public JPopupMenu createPopup(String name,
                              Enum<?>[] commands)

createPopup

public JPopupMenu createPopup(String name,
                              Enum<?>[][] cmdList)

createRadioButtonMenuItem

public JMenuItem createRadioButtonMenuItem(String appID,
                                           Enum<?> cmd)

createToolBar

public JToolBar createToolBar()

createToolBar

public JToolBar createToolBar(int orientation)

createToolBar

public JToolBar createToolBar(String appID,
                              Enum<?>[] commands)

createToolBar

public JToolBar createToolBar(String appID,
                              Enum<?>[] commands,
                              int orientation)

createToolBarButton

public JButton createToolBarButton(String appID,
                                   Enum<?> cmd,
                                   int orientation)

createToolBarButton

public JButton createToolBarButton(String appID,
                                   String cmd,
                                   int orientation)

getHandlers

public final ActionHandler[] getHandlers()

setupAppIcon

public void setupAppIcon(JToggleButton ai,
                         String name)

buildMenu

protected JMenu buildMenu(JMenu menu,
                          String name,
                          Enum<?>[] commands)

buildPopup

protected JPopupMenu buildPopup(JPopupMenu pm,
                                String name,
                                Enum<?>[] commands)

createMenus

protected void createMenus(JMenuBar menuBar,
                           String name,
                           Enum<?>[] commands)

createSubMenu

protected JMenu createSubMenu(Enum<?> cmd)

createSubMenu

protected JMenu createSubMenu(String cmd)

createToolBar

protected void createToolBar(JToolBar tb,
                             String appID,
                             Enum<?>[] commands,
                             int orientation)

findAction

protected AbstractAction findAction(Enum<?> cmd)

findAction

protected AbstractAction findAction(String itemID)

findAction

protected AbstractAction findAction(String appID,
                                    Enum<?> cmd)

findAction

protected AbstractAction findAction(String appID,
                                    String cmd)

validateMenu

protected void validateMenu(JMenu menu)

validateMenuBar

protected void validateMenuBar(JMenuBar mb)

SRJRCFrames
v0.1.296

hosted at
Find SRJRCFrames at SourceForge.net. Fast, secure and free:
           Open Source Software download
Submit a bug or request a feature

SRJRCFrames is published according to the GNU General Public License
Copyright 2005-2012 Reinhard Mantey - some rights reserved.