|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uic.model.ActionFactory
public class ActionFactory
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", // the name this action can be found under this, "insertContextSlot", // the method called when action is selected "New Context...", // the text to show on menu entries "toolbarButtonGraphics.general.New"); // an icon from the jlfgr-1_0.jar
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 call methods like
enableAction
like this:
actionFactory.enableAction("file_new", false);
You will typically have one actionFactory instance per main window (the window with the menus)
A short example of the formatting of the .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>&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 submenu when it has another menu as parent) 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 as supported by getPopupMenu(java.lang.String)
Actions that are not yet known at writing of the .rc need to be added to the menu without relying on individual action names. It is possible to add a placeholder for any number of actions in the rc file which can then be requested and filled programattically using any UICAction instance you have.
The placeholder should be named in the rc file and takes the format of an
<ActionList name="myname">
element. The element can appear anywhere
where an action can also appear. From your code you can add actions to the menus and
toolbars by filling the actionlist you can request from the ActionFactory:
UICActionList entriesList = af.getActionList("myList"); entriesList.add(anAction);Note that it is no problem to have a ActionList name appear multiple times in your rc file, which makes all actions added to it appear in each of the menus and toolbars you use that name in.
Field Summary | |
---|---|
protected IconFactory |
iconFactory
|
static int |
POLICY_DIRECT
|
static int |
POLICY_DIRECT_MULTITHREADED
|
static int |
POLICY_ONLY_LAST
|
static int |
POLICY_QUEUED
|
Constructor Summary | |
---|---|
ActionFactory()
Empty constructor to create an un-translated ActionFactory. |
|
ActionFactory(TranslationInterface appTranslator)
Create a new ActionFactory where texts from the config file are translated. |
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)
|
UICAction |
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)
|
UICAction |
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,
StatusBar statusBar)
|
void |
build(JFrame parent,
URL url)
|
void |
build(JFrame parent,
URL url,
StatusBar statusBar)
|
void |
build(MainWindow parent,
InputStream is)
Deprecated. use MainWindow.createGui(uic.TranslationInterface, java.lang.String) instead |
void |
build(MainWindow parent,
URL url)
Deprecated. use MainWindow.createGui(uic.TranslationInterface, java.lang.String) instead |
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)
|
JToolBar |
createToolBar(Element toolbar)
|
JToolBar |
createToolBar(String toolbarName)
|
void |
enableAction(String actionName,
boolean on)
set the action to be enabled/disabled. |
void |
enableGroup(String groupName,
boolean on)
Enable action groups. |
UICAction |
getAction(String name)
Return the action registered using the argument name. |
UICActionList |
getActionList(String name)
Return the actionList list of actions that are grouped by argument name. |
IconFactory |
getIconFactory()
|
JPopupMenu |
getPopupMenu(String name)
|
protected JMenu |
getSettingsMenu(JMenuBar parent)
|
void |
init(InputStream is)
|
void |
setAllowToolBarHiding(boolean allow)
Set true to allow the user the option to hide toolbars Set false to not present hiding options to the user Toolbar hiding must also be set on the WindowRepresenter. |
void |
setExecutionPolicy(String actionName,
int policy)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected IconFactory iconFactory
public static final int POLICY_QUEUED
public static final int POLICY_DIRECT
public static final int POLICY_DIRECT_MULTITHREADED
public static final int POLICY_ONLY_LAST
Constructor Detail |
---|
public ActionFactory()
public ActionFactory(TranslationInterface appTranslator)
appTranslator
- the translator used to translate the strings which are
passed in the rc file as 'text' nodes. These are, for instance, the names
of the menus, like "File" and "Edit".Method Detail |
---|
public UICAction addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke, String toolTipText, String whatIsThis)
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 nonekeyStroke
- the keyStroke in the format accepted by javax.swing.KeyStroke.getKeyStroke(String)toolTipText
- the text for tooltips, or null for nonewhatIsThis
- the text for the statusBar.KeyStroke.getKeyStroke(String)
public void addAction(String name, Object targetObject, String targetMethod, String title)
public void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName)
public void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke)
public void addAction(String name, Object targetObject, String targetMethod, String title, String iconBaseName, String keyStroke, String toolTipText)
public void addAction(UICAction action)
public UICAction addSpecialAction(String name, Object targetObject, String targetMethod)
code | Description |
---|---|
file_new | New Document |
file_open | Open Document |
file_save | Save Document |
file_saveas | Save As... |
file_close | Close |
file_quit | Quit (default on Mac and Linux) |
file_exit | Exit (default on Windows) |
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.
NullPointerException
- when name is null.
IllegalArgumentException
- if the name is not a known special action.public UICAction getAction(String name)
name
- the name the action is registered under (file_new for example)
public UICActionList getActionList(String name)
name
- the name the actionList is registered under (file_menu for example)
public void build(MainWindow parent, URL url)
MainWindow.createGui(uic.TranslationInterface, java.lang.String)
instead
public void build(JFrame parent, URL url)
public void build(JFrame parent, URL url, StatusBar statusBar)
public void build(MainWindow parent, InputStream is)
MainWindow.createGui(uic.TranslationInterface, java.lang.String)
instead
public void build(JFrame parent, InputStream is)
public void build(JFrame parent, InputStream is, StatusBar statusBar)
public void build(JFrame parent, StatusBar statusBar)
public void init(InputStream is) throws IOException, JDOMException
IOException
JDOMException
public void buildMenu(JMenuBar parent, URL url) throws IOException, JDOMException
IOException
JDOMException
public void buildMenu(JMenuBar parent, InputStream is) throws JDOMException, IOException
JDOMException
IOException
public void buildMenu(JMenuBar parent, Element menuRoot)
public void buildMenu(JMenuBar parent, Element menuRoot, StatusBar statusBar)
public void buildToolbars(JFrame parent, URL url) throws IOException, JDOMException
IOException
JDOMException
public void buildToolbars(JFrame parent, InputStream is) throws JDOMException, IOException
JDOMException
IOException
public void buildToolbars(JFrame parent, Element documentRoot)
public JToolBar createToolBar(String toolbarName)
toolbarName
- the name of the popup as registred in the resource file with the 'name' attribute.
IllegalStateException
- if this is called on an ActionFactory which did not have one of the
build() flavors called before.public JToolBar createToolBar(Element toolbar)
protected JMenu getSettingsMenu(JMenuBar parent)
public JPopupMenu getPopupMenu(String name)
name
- the name of the popup as registred in the resource file
with the 'name' attribute.
IllegalStateException
- if this is called on an ActionFactory
which did not have one of the build() flavors called before.public void setExecutionPolicy(String actionName, int policy)
public void enableAction(String actionName, boolean on)
actionName
- the key of the action to enable/disableon
- set to enabled when true;public void enableGroup(String groupName, boolean on)
groupName
- the name of the group to enable can be found in the &l;Menu> and <ToolBar> tags which can contain a "name" attribute.public boolean addIconJar(String path)
public boolean addIconRepository(String path)
public IconFactory getIconFactory()
public void setAllowToolBarHiding(boolean allow)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |