uic.model
Class ActionFactory

java.lang.Object
  extended byuic.model.ActionFactory

public class ActionFactory
extends Object

ActionFactory builds actions and keeps them referenced so you can easily enable/disable them. Creating the menu and toolbar parts of a new Gui exitst from two steps; first you have to register all the actions your application supports, and next you have to provide an rc file that contains the structure of the GUI.

Registering actions can be done with addAction or addSpecialAction.

        // in constructor of class extending JFrame
        actionFactory = new ActionFactory();
        actionFactory.addSpecialAction("file_new", this, "fileNewSlot");
        actionFactory.addAction("context_new", this, "insertContextSlot", i18n("new context..."),
            "toolbarButtonGraphics.general.New");

The next step is to build the user interface:

        getContentPane().setLayout(new BorderLayout());
        actionFactory.build(this, getClass().getClassLoader().getResourceAsStream("myapp.rc"));
getContentPane().add(myContentPanel, BorderLayout.CENTER);

And thats it.
If you keep a reference to the actionFactory you will be able to do things like:

        actionFactory.enableAction("file_new", false); 

You will typically have one actionFactory instance per main window (the one with the menu)

The formatting of the file's rc file (the myapp.rc above) is like this:


      <?xml version="1.0" encoding="UTF-8"?>
      <actionfactory name="myapp" version="1">
      <MenuBar>
       <Menu name="edit"><text>&amp;Edit</text>
        <Action name="edit_undo"/>
        <Action name="edit_redo"/>
        <Separator/>
        <Action name="delete_page"/>
       </Menu>
      </MenuBar>
      <ToolBar name="edit_toolbar" position="top"><Text>Edit</Text>
        <Action name="edit_undo"/>
      </ToolBar>
      <Menu name="action_popup">
        <Action name="tools_createtext"/>
        <Action name="tools_createpix"/>
        <Action name="tools_table"/>
        <Action name="tools_kspreadtable"/>
        <Action name="tools_formula"/>
        <Action name="tools_part"/>
      </Menu>
      </actionfactory> 

The tag Menu specifies one menu (or a submen when nested) which can contain Action tags.
The ToolBar tag contains actions which will be placed on a toolbar by that name.
When a Menu is nested below the MenuBar tag it will appear in the menubar of the JFrame, The Menu tags at root level will be popups when they are supported.

Since:
1.2

Field Summary
protected  IconFactory iconFactory
           
 
Constructor Summary
ActionFactory(TranslationInterface appTranslator)
           
 
Method Summary
 void addAction(String name, Object targetObject, String targetMethod, String title)
           
 void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName)
           
 void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke)
           
 void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke, String toolTipText)
           
 void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke, String toolTipText, String whatIsThis)
          Register action with factory.
 void addAction(UICAction action)
           
 boolean addIconJar(String path)
           
 boolean addIconRepository(String path)
           
 void addSpecialAction(String name, Object targetObject, String targetMethod)
          register actions that are predifined.
 void build(JFrame parent, InputStream is)
           
 void build(JFrame parent, InputStream is, StatusBar statusBar)
           
 void build(JFrame parent, URL url)
           
 void build(JFrame parent, URL url, StatusBar statusBar)
           
 void build(MainWindow parent, InputStream is)
           
 void build(MainWindow parent, URL url)
          uses the input file to read actions and menu structure, and build that.
protected  JComponent buildComponent(String actionName, String componentType, StatusBar statusBar)
          Instanciate the new component;
 void buildMenu(JMenuBar parent, Element menuRoot)
           
 void buildMenu(JMenuBar parent, Element menuRoot, StatusBar statusBar)
           
 void buildMenu(JMenuBar parent, InputStream is)
           
 void buildMenu(JMenuBar parent, URL url)
           
 void buildToolbars(JFrame parent, Element documentRoot)
           
 void buildToolbars(JFrame parent, InputStream is)
           
 void buildToolbars(JFrame parent, URL url)
           
 JComponent createButton(UICAction action)
           
static JComponent createButton(UICAction action, TranslationInterface translator)
           
static JComponent createButton(UICAction action, TranslationInterface translator, IconFactory iconFactory)
           
 JComponent createMenuItem(UICAction action)
           
static JComponent createMenuItem(UICAction action, TranslationInterface translator)
           
static JComponent createMenuItem(UICAction action, TranslationInterface translator, IconFactory iconFactory)
           
 void enableAction(String actionName, boolean on)
          set the action to be enabled/disabled.
 void enableGroup(String groupName, boolean on)
          Enable action groups.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iconFactory

protected IconFactory iconFactory
Constructor Detail

ActionFactory

public ActionFactory(TranslationInterface appTranslator)
Method Detail

addAction

public void addAction(String name,
                      Object targetObject,
                      String targetMethod,
                      String title,
                      String iconBaseName,
                      String keyStroke,
                      String toolTipText,
                      String whatIsThis)
Register action with factory.

Parameters:
name - The identifying name of the action, must be unique.
targetObject - The object that contains the method we want to connect to.
targetMethod - the name of the method we want to connect to.
title - the name used on buttons or in a menu entry.
iconBaseName - the basename the new widgets can use to fetch the correct icon, or null if none
keyStroke - the keyStroke in the format accepted by javax.swing.KeyStroke.getKeyStroke(String)
toolTipText - the text for tooltips, or null for none
whatIsThis - the text for the statusBar.
See Also:
KeyStroke.getKeyStroke(String)

addAction

public void addAction(String name,
                      Object targetObject,
                      String targetMethod,
                      String title)

addAction

public void addAction(String name,
                      Object targetObject,
                      String targetMethod,
                      String title,
                      String iconBaseName)

addAction

public void addAction(String name,
                      Object targetObject,
                      String targetMethod,
                      String title,
                      String iconBaseName,
                      String keyStroke)

addAction

public void addAction(String name,
                      Object targetObject,
                      String targetMethod,
                      String title,
                      String iconBaseName,
                      String keyStroke,
                      String toolTipText)

addAction

public void addAction(UICAction action)

addSpecialAction

public void addSpecialAction(String name,
                             Object targetObject,
                             String targetMethod)
register actions that are predifined. A limited set of actions that look and behave the same can be registered without constraining the application of specific settings or translations.

Parameters:
name - action name from the limited set (file_open/file_save etc.)
targetObject - The object that contains the method we want to connect to.
targetMethod - the name of the method we want to connect to.

build

public void build(MainWindow parent,
                  URL url)
uses the input file to read actions and menu structure, and build that.


build

public void build(JFrame parent,
                  URL url)

build

public void build(JFrame parent,
                  URL url,
                  StatusBar statusBar)

build

public void build(MainWindow parent,
                  InputStream is)

build

public void build(JFrame parent,
                  InputStream is)

build

public void build(JFrame parent,
                  InputStream is,
                  StatusBar statusBar)

buildMenu

public void buildMenu(JMenuBar parent,
                      URL url)
               throws IOException,
                      JDOMException
Throws:
IOException
JDOMException

buildMenu

public void buildMenu(JMenuBar parent,
                      InputStream is)
               throws JDOMException,
                      IOException
Throws:
JDOMException
IOException

buildMenu

public void buildMenu(JMenuBar parent,
                      Element menuRoot)

buildMenu

public void buildMenu(JMenuBar parent,
                      Element menuRoot,
                      StatusBar statusBar)

buildToolbars

public void buildToolbars(JFrame parent,
                          URL url)
                   throws IOException,
                          JDOMException
Throws:
IOException
JDOMException

buildToolbars

public void buildToolbars(JFrame parent,
                          InputStream is)
                   throws JDOMException,
                          IOException
Throws:
JDOMException
IOException

buildToolbars

public void buildToolbars(JFrame parent,
                          Element documentRoot)

enableAction

public void enableAction(String actionName,
                         boolean on)
set the action to be enabled/disabled.

Parameters:
actionName - the key of the action to enable/disable
on - set to enabled when true;

enableGroup

public void enableGroup(String groupName,
                        boolean on)
Enable action groups.

Parameters:
groupName - the name of the group to enable can be found in the &l;Menu> and <ToolBar> tags which can contain a "name" attribute.

buildComponent

protected JComponent buildComponent(String actionName,
                                    String componentType,
                                    StatusBar statusBar)
Instanciate the new component;

Parameters:
actionName - the name under the action was registered. Must be present.
componentType - the type; is one of "menu", "button", "toolbarbutton"

createButton

public JComponent createButton(UICAction action)

createButton

public static JComponent createButton(UICAction action,
                                      TranslationInterface translator)

createButton

public static JComponent createButton(UICAction action,
                                      TranslationInterface translator,
                                      IconFactory iconFactory)

createMenuItem

public JComponent createMenuItem(UICAction action)

createMenuItem

public static JComponent createMenuItem(UICAction action,
                                        TranslationInterface translator)

createMenuItem

public static JComponent createMenuItem(UICAction action,
                                        TranslationInterface translator,
                                        IconFactory iconFactory)

addIconJar

public boolean addIconJar(String path)

addIconRepository

public boolean addIconRepository(String path)


Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence