|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uic.model.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", 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>&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.
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 |
protected IconFactory iconFactory
Constructor Detail |
public ActionFactory(TranslationInterface appTranslator)
Method Detail |
public void 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 void addSpecialAction(String name, Object targetObject, String targetMethod)
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.public void build(MainWindow parent, URL url)
public void build(JFrame parent, URL url)
public void build(JFrame parent, URL url, StatusBar statusBar)
public void build(MainWindow parent, InputStream is)
public void build(JFrame parent, InputStream is)
public void build(JFrame parent, InputStream is, StatusBar statusBar)
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 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.protected JComponent buildComponent(String actionName, String componentType, StatusBar statusBar)
actionName
- the name under the action was registered. Must be present.componentType
- the type; is one of "menu", "button", "toolbarbutton"public JComponent createButton(UICAction action)
public static JComponent createButton(UICAction action, TranslationInterface translator)
public static JComponent createButton(UICAction action, TranslationInterface translator, IconFactory iconFactory)
public JComponent createMenuItem(UICAction action)
public static JComponent createMenuItem(UICAction action, TranslationInterface translator)
public static JComponent createMenuItem(UICAction action, TranslationInterface translator, IconFactory iconFactory)
public boolean addIconJar(String path)
public boolean addIconRepository(String path)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |