com.levigo.util.swing.action
Class BasicMenuComponentFactory

java.lang.Object
  extended by com.levigo.util.swing.action.BasicMenuComponentFactory
All Implemented Interfaces:
MenuComponentFactory, NamedMenuComponentFactory

public class BasicMenuComponentFactory
extends Object
implements NamedMenuComponentFactory

BasicMenuComponentFactory provides base functionality for menu component factories

Author:
Carolin Köhler
See Also:
MenuComponentFactory, DefaultMenuComponentFactory

Field Summary
protected static String CHECKBOX_MENU
          type of the menu is checkbox - it used in the file of actions definition in the parameter menuType
protected  com.levigo.util.preferences.PropertiesPreferenceStore compositionLookupProperties
          Instance of the property file.
protected static String ENDSUB
          End submenu [Format:{EndSubMenu}]
protected static String EXTERNAL_ACTION
          An externally defined action.
protected  String factoryName
          Name of this command factory, usually the properties file name.
protected static String ICON_MENU
          type of the menu is an menu with icon decorated icons - it used in the file of actions definition in the parameter menuType
protected static String MNEMONICKEY
          Parameter of the MnemonicKey in the menu components properties file
protected static String RADIOBUTTON_MENU
          type of the menu is radioButton - it used in the file of actions definition in the parameter menuType
protected static String SELECTED_MENU
          type of the menu is radioButton - it used in the file of actions definition in the parameter menuState
protected static String SEPARATOR
          Separator [Format:{separator}]
protected static String STARTSUB
          Start submenu [Format:{StartSubmenu=NameofSubmenu}]
protected static String SUBMENU_ACTION
          Parameter of the action in the property file to which a submenu should be attached to
protected static String SUBMENUVARIABLE
          Submenu [Format:{$submenu keyOfName}]
protected static String TEXT
          Parameter of the submenu text in the property file
protected static String VARIABLE
          Variable [Format:{$nameOfVariable}]
protected static String VISIBILITY_CHECKBOX_MENU
          type of the menu is radioButton - it used in the file of actions definition in the parameter menuType
protected static String VISIBILITY_MENU
          type of the menu item is a Item which is visible only if it is enabled - it used in the file of actions definition in the parameter menuState
protected static String VISIBILITY_RADIOBUTTON_MENU
          type of the menu is radioButton - it used in the file of actions definition in the parameter menuType
 
Fields inherited from interface com.levigo.util.swing.action.MenuComponentFactory
ACTIONS, CONTEXT_MENU_ACTIONS, MENU_ACTIONS, TOOLBAR_ACTIONS
 
Constructor Summary
protected BasicMenuComponentFactory(InputStream propertyInputStream, String factoryName)
          Constructor, reads a property list (key and element pairs) from the given input stream and fills up the contained compositionLookupProperties.
protected BasicMenuComponentFactory(String propertiesFileName)
          Constructor invokes a loading of the property file.
 
Method Summary
protected  Action adaptAdditionalAction(String metaInfo, Context context, Action additionalAction)
          Read settings for external actions from the action properties file.
 void clearLookupProperties()
          Clears the lookup properties.
protected  JComponent doCreateComponentForAction(Action action)
          Create a beautiful button to carry an action in a toolbar.
protected  JPopupMenu doCreateContextMenu(String key, Collection<String> actionNameCollection, Context context, Action[] additionalActions)
          Creates the context menu from the informations inside the collection.
protected  JMenu doCreateMenu(String key, Collection<String> actionNameCollection, Context context, Action[] additionalActions)
          Creates the menu from the informations inside the collection.
protected  JMenuBar doCreateMenuBar(String key, Collection<String> actionNameCollection, Context context, Action[] additionalActions)
          Creates the menu from the informations inside the collection.
protected  JToolBar doCreateToolbar(Collection<String> actionNameCollection, Context context, Action[] additionalActions)
          Creates the toolbar from the informations inside the collection.
protected  JToolBar doCreateToolbar(String key, Collection<String> actionNameCollection, Context context, Action[] additionalActions)
          Creates the toolbar from the informations inside the collection.
protected  ActionFactory getActionFactory(String key)
          Returns an action factory for given resource key.
 Collection<String> getActions(String key)
          Create all currently available action names(!) for the given template key.
 Collection<String> getActionsForType(String key, String type)
          Create a collection of all currently available action names(!) for the given template key and action structure type.
 Collection<CommandAction> getCommandActions(String key, Context context)
          Create all currently available command actions for the given template key.
 JPopupMenu getContextMenu(String key, Context context)
          Create a JPopupMenu for the given template key or context name.
 JPopupMenu getContextMenu(String key, Context context, Action[] additionalActions)
          Create a JPopupMenu for the given template key or context name.
 String getFactoryName()
          Returns the name of this factory, usually its properties file name.
 String getLookupProperty(String key)
          Allows an application to request lookup properties programmatically.
 JMenu getMenu(String key, Context context)
          Create a JMenu for the given template key or context name.
 JMenu getMenu(String key, Context context, Action[] additionalActions)
          Create a JMenu for the given template key or context name.
 JMenuBar getMenuBar(String key, Context context)
          Create a JMenuBar for the given template key or context name.
protected  MenuComponentFactory getMenuFactory(String key)
           
protected  Collection<String> getStructureOfActionNames(String key, String type)
          Separate the actions for the specific key of the component and typ of query and puts them into the collection.
 JToolBar getToolbar(String key, Context context)
          Create a JToolbar for the given template key or context name.
 JToolBar getToolbar(String key, Context context, Action[] additionalActions)
          Create a JToolbar for the given template key or context name.
protected  void loadProperties(InputStream is)
          Reads a property list (key and element pairs) from the input stream and fills the embedded compositionLookupProperties.
protected  void loadProperties(String propertiesFileName)
          Load the data from the propertyFile.
 void putLookupProperty(String key, String value)
          Deprecated. use setLookupProperty(String, String) instead
 void removeLookupProperty(String key)
          Removes the value for given key.
protected  void setFactoryName(String factoryName)
          Changes the name of this factory.
 void setLookupProperty(String key, String value)
          Allows an application to overwrite or set lookup properties programmatically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHECKBOX_MENU

protected static final String CHECKBOX_MENU
type of the menu is checkbox - it used in the file of actions definition in the parameter menuType

See Also:
Constant Field Values

VISIBILITY_CHECKBOX_MENU

protected static final String VISIBILITY_CHECKBOX_MENU
type of the menu is radioButton - it used in the file of actions definition in the parameter menuType

See Also:
Constant Field Values

VISIBILITY_RADIOBUTTON_MENU

protected static final String VISIBILITY_RADIOBUTTON_MENU
type of the menu is radioButton - it used in the file of actions definition in the parameter menuType

See Also:
Constant Field Values

RADIOBUTTON_MENU

protected static final String RADIOBUTTON_MENU
type of the menu is radioButton - it used in the file of actions definition in the parameter menuType

See Also:
Constant Field Values

ICON_MENU

protected static final String ICON_MENU
type of the menu is an menu with icon decorated icons - it used in the file of actions definition in the parameter menuType

See Also:
Constant Field Values

VISIBILITY_MENU

protected static final String VISIBILITY_MENU
type of the menu item is a Item which is visible only if it is enabled - it used in the file of actions definition in the parameter menuState

See Also:
Constant Field Values

SELECTED_MENU

protected static final String SELECTED_MENU
type of the menu is radioButton - it used in the file of actions definition in the parameter menuState

See Also:
Constant Field Values

TEXT

protected static final String TEXT
Parameter of the submenu text in the property file

See Also:
Constant Field Values

SUBMENU_ACTION

protected static final String SUBMENU_ACTION
Parameter of the action in the property file to which a submenu should be attached to

See Also:
Constant Field Values

MNEMONICKEY

protected static final String MNEMONICKEY
Parameter of the MnemonicKey in the menu components properties file

See Also:
Constant Field Values

SEPARATOR

protected static final String SEPARATOR
Separator [Format:{separator}]

See Also:
Constant Field Values

SUBMENUVARIABLE

protected static final String SUBMENUVARIABLE
Submenu [Format:{$submenu keyOfName}]

See Also:
Constant Field Values

VARIABLE

protected static final String VARIABLE
Variable [Format:{$nameOfVariable}]

See Also:
Constant Field Values

EXTERNAL_ACTION

protected static final String EXTERNAL_ACTION
An externally defined action. Action names starting with this character will NOT be looked up in the action properties file.

See Also:
Constant Field Values

STARTSUB

protected static final String STARTSUB
Start submenu [Format:{StartSubmenu=NameofSubmenu}]

See Also:
Constant Field Values

ENDSUB

protected static final String ENDSUB
End submenu [Format:{EndSubMenu}]

See Also:
Constant Field Values

compositionLookupProperties

protected com.levigo.util.preferences.PropertiesPreferenceStore compositionLookupProperties
Instance of the property file. From this file are the menu structures read


factoryName

protected String factoryName
Name of this command factory, usually the properties file name. In plugin context, this name could be any descriptive text.

Constructor Detail

BasicMenuComponentFactory

protected BasicMenuComponentFactory(String propertiesFileName)
                             throws Exception
Constructor invokes a loading of the property file.

Parameters:
propertiesFileName - for which should be factory created
Throws:
Exception
See Also:
Object.Object()

BasicMenuComponentFactory

protected BasicMenuComponentFactory(InputStream propertyInputStream,
                                    String factoryName)
                             throws Exception
Constructor, reads a property list (key and element pairs) from the given input stream and fills up the contained compositionLookupProperties.

Parameters:
propertyInputStream - the input stream to read the command properties
factoryName - name of this factory
Throws:
Exception
See Also:
Properties
Method Detail

getToolbar

public JToolBar getToolbar(String key,
                           Context context)
Create a JToolbar for the given template key or context name.

Specified by:
getToolbar in interface MenuComponentFactory
Parameters:
key - of the toolbar which should be created
context - for the actions in the toolbar. Actions in the toolbar belong then in this context.

Returns:
Created toolbar
See Also:
MenuComponentFactory.getToolbar(String, Context)

getToolbar

public JToolBar getToolbar(String key,
                           Context context,
                           Action[] additionalActions)
Create a JToolbar for the given template key or context name. Additional actions NOT defined in the properties file can be specified with the parameter additionalActions.

Specified by:
getToolbar in interface MenuComponentFactory
See Also:
MenuComponentFactory.getToolbar(String, Context)

getMenu

public JMenu getMenu(String key,
                     Context context)
Create a JMenu for the given template key or context name.

Specified by:
getMenu in interface MenuComponentFactory
Parameters:
key - of the menu which should be created
context - for the actions in the menu. Actions in the menu belong then in this context.

Returns:
Created menu
See Also:
MenuComponentFactory.getMenu(String, Context)

getMenu

public JMenu getMenu(String key,
                     Context context,
                     Action[] additionalActions)
Create a JMenu for the given template key or context name.

Specified by:
getMenu in interface MenuComponentFactory
See Also:
MenuComponentFactory.getMenu(String, Context)

getContextMenu

public JPopupMenu getContextMenu(String key,
                                 Context context)
Create a JPopupMenu for the given template key or context name.

Specified by:
getContextMenu in interface MenuComponentFactory
Parameters:
key - of the context menu which should be created
context - for the actions in the context menu. Actions in the context menu belong then in this context.

Returns:
Created context menu
See Also:
MenuComponentFactory.getContextMenu(String, Context)

getContextMenu

public JPopupMenu getContextMenu(String key,
                                 Context context,
                                 Action[] additionalActions)
Create a JPopupMenu for the given template key or context name.

Specified by:
getContextMenu in interface MenuComponentFactory
See Also:
MenuComponentFactory.getContextMenu(String, Context)

getActionFactory

protected ActionFactory getActionFactory(String key)
Returns an action factory for given resource key.

Parameters:
key - identifier of the action factory
Returns:
action factory or null

getActions

public Collection<String> getActions(String key)
Create all currently available action names(!) for the given template key. Attention: This is just a collection of action names (as strings), not real action object instances.

Specified by:
getActions in interface MenuComponentFactory
Parameters:
key - template key
Returns:
Collection of the actions names
See Also:
MenuComponentFactory.getActions(String)

getActionsForType

public Collection<String> getActionsForType(String key,
                                            String type)
Description copied from interface: MenuComponentFactory
Create a collection of all currently available action names(!) for the given template key and action structure type. The returning object is just a collection of action names (as Strings), not the real action objects.

Specified by:
getActionsForType in interface MenuComponentFactory
Parameters:
key - template key
type - structure type like MenuComponentFactoryMenuComponentFactory.ACTIONS, MenuComponentFactoryMenuComponentFactory.CONTEXT_MENU_ACTIONS,MenuComponentFactoryMenuComponentFactory.MENU_ACTIONS,MenuComponentFactoryMenuComponentFactory.TOOLBAR_ACTIONS
Returns:
Collection of the actions names
See Also:
MenuComponentFactory.getActionsForType(java.lang.String, java.lang.String)

getCommandActions

public Collection<CommandAction> getCommandActions(String key,
                                                   Context context)
Create all currently available command actions for the given template key.

Specified by:
getCommandActions in interface MenuComponentFactory
Parameters:
context - the returned actions refer to this context.
key - template key for action structure
Returns:
Collection of created and available command actions for the given template key
See Also:
MenuComponentFactory.getActions(String)

doCreateToolbar

protected JToolBar doCreateToolbar(Collection<String> actionNameCollection,
                                   Context context,
                                   Action[] additionalActions)
Creates the toolbar from the informations inside the collection. The informations can contain the metadata like:

SEPARATOR STARTSUB ENDSUB

Submenus are separated in the toolbar with the separators.

Parameters:
actionNameCollection - collection of the names of actions and informations about structure of the toolbar.
context - context for the actions in the toolbar.
additionalActions - additional actions to add to the created toolbar
Returns:
created toolbar

doCreateToolbar

protected JToolBar doCreateToolbar(String key,
                                   Collection<String> actionNameCollection,
                                   Context context,
                                   Action[] additionalActions)
Creates the toolbar from the informations inside the collection. The informations can contain the metadata like:

SEPARATOR STARTSUB ENDSUB

Submenus are separated in the toolbar with the separators.

Parameters:
key - of the component which has the menu
actionNameCollection - collection of the names of actions and informations about structure of the toolbar.
context - context for the actions in the toolbar.
additionalActions - additional actions to add to the created toolbar
Returns:
created toolbar

adaptAdditionalAction

protected Action adaptAdditionalAction(String metaInfo,
                                       Context context,
                                       Action additionalAction)
Read settings for external actions from the action properties file. If there is a configuration for this action, wrap the action and return its values. If a value is not available, return the value of the original additionalAction. In either case the action of the additionalAction is invoked.
If there is no configuration, just use the original additionalAction.

Parameters:
context -
additionalAction -
metaInfo -
Returns:
See Also:
Associating Text Actions With Menus and Buttons
"Generally, you should not modify Action objects you get from editor kits. If you do, the changes affect all text components in your program."

doCreateComponentForAction

protected JComponent doCreateComponentForAction(Action action)
Create a beautiful button to carry an action in a toolbar.

Returns:
a button component for given action

doCreateMenu

protected JMenu doCreateMenu(String key,
                             Collection<String> actionNameCollection,
                             Context context,
                             Action[] additionalActions)
Creates the menu from the informations inside the collection. The informations can contain the metadata like:

SEPARATOR STARTSUB ENDSUB

It is possible to set the type of the menu then the specified type is created. These parameters have to be written in the definition of action!

CHECKBOX_MENU
VISIBILITY_CHECKBOX_MENU
RADIOBUTTON_MENU
VISIBILITY_RADIOBUTTON_MENU
VISIBILITY_MENU

Default state:
SELECTED_MENU

Parameters:
actionNameCollection - collection of the names of actions and informations about structure of the menu.
context - context for the actions in the menu.
additionalActions - additional actions to add to the menu
Returns:
created menu

doCreateContextMenu

protected JPopupMenu doCreateContextMenu(String key,
                                         Collection<String> actionNameCollection,
                                         Context context,
                                         Action[] additionalActions)
Creates the context menu from the informations inside the collection. The informations can contain the metadata like:

SEPARATOR STARTSUB ENDSUB

It is possible to set the type of the menu then the specified type is created. These parameters have to be written in the definition of action!

CHECKBOX_MENU
VISIBILITY_CHECKBOX_MENU
RADIOBUTTON_MENU
VISIBILITY_RADIOBUTTON_MENU
VISIBILITY_MENU

Default state:
SELECTED_MENU

Parameters:
key -
actionNameCollection - collection of the names of actions and informations about structure of the context menu.
context - context for the actions in the menu.
additionalActions - additional actions to add to the menu
Returns:
created context menu

getMenuFactory

protected MenuComponentFactory getMenuFactory(String key)

getStructureOfActionNames

protected Collection<String> getStructureOfActionNames(String key,
                                                       String type)
Separate the actions for the specific key of the component and typ of query and puts them into the collection. The string of the action names and the key words is read from the property file. The file can contain these key words:

SUBMENUVARIABLE VARIABLE SEPARATOR

It is possible to add more menus into one another through the VARIABLE.

Parameters:
key - of the component which has the menu
type - of the query. There are these possibilities:

MenuComponentFactory.ACTIONS MenuComponentFactory.MENU_ACTIONS MenuComponentFactory.CONTEXT_MENU_ACTIONS MenuComponentFactory.TOOLBAR_ACTIONS

Returns:
Collection of the names of actions for the key. Colection can contain keywords like:

SEPARATOR STARTSUB ENDSUB

See Also:
MenuComponentFactory.ACTIONS, MenuComponentFactory.MENU_ACTIONS, MenuComponentFactory.CONTEXT_MENU_ACTIONS, MenuComponentFactory.TOOLBAR_ACTIONS, SEPARATOR, STARTSUB, ENDSUB

loadProperties

protected void loadProperties(String propertiesFileName)
                       throws IOException
Load the data from the propertyFile. It is called automatically from the constructor. The file contains informations about the structure of the menus.

Parameters:
propertiesFileName - from which should be the informations read
Throws:
IOException - - the file not found

loadProperties

protected void loadProperties(InputStream is)
                       throws IOException
Reads a property list (key and element pairs) from the input stream and fills the embedded compositionLookupProperties.

Throws:
IOException

getMenuBar

public JMenuBar getMenuBar(String key,
                           Context context)
Description copied from interface: MenuComponentFactory
Create a JMenuBar for the given template key or context name.

Specified by:
getMenuBar in interface MenuComponentFactory
Parameters:
key -
context -

doCreateMenuBar

protected JMenuBar doCreateMenuBar(String key,
                                   Collection<String> actionNameCollection,
                                   Context context,
                                   Action[] additionalActions)
Creates the menu from the informations inside the collection. The informations can contain the metadata like:

SEPARATOR STARTSUB ENDSUB

It is possible to set the type of the menu then the specified type is created. These parameters have to be written in the definition of action!

CHECKBOX_MENU
VISIBILITY_CHECKBOX_MENU
RADIOBUTTON_MENU
VISIBILITY_RADIOBUTTON_MENU
VISIBILITY_MENU

Default state:
SELECTED_MENU

Parameters:
actionNameCollection - collection of the names of actions and informations about structure of the menu.
context - context for the actions in the menu.
additionalActions - additional actions to add to the menu
Returns:
created menu

putLookupProperty

@Deprecated
public void putLookupProperty(String key,
                                         String value)
Deprecated. use setLookupProperty(String, String) instead

Allows an application to overwrite or set lookup properties programmatically. This is useful if some of the properties are not yet known in advance from the menucomponents.properties file.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.

setLookupProperty

public void setLookupProperty(String key,
                              String value)
Allows an application to overwrite or set lookup properties programmatically. This is useful if some of the properties are not yet known in advance from its properties resource.

Parameters:
key -
value - The value of the given key, null if the key is not mapped to any value.

removeLookupProperty

public void removeLookupProperty(String key)
Removes the value for given key.

Parameters:
key -

clearLookupProperties

public void clearLookupProperties()
Clears the lookup properties.


getLookupProperty

public String getLookupProperty(String key)
Allows an application to request lookup properties programmatically.

Parameters:
key - The key to look up
Returns:
value The value of the given key, null if the key is not mapped to any value.
Throws:
NullPointerException - if the key is null.

getFactoryName

public String getFactoryName()
Returns the name of this factory, usually its properties file name. In plugin context, this name could be any descriptive text.

Specified by:
getFactoryName in interface NamedMenuComponentFactory
Returns:
name

setFactoryName

protected void setFactoryName(String factoryName)
Changes the name of this factory. The name is usually its properties file name. In plugin context, this name could be any descriptive text.

Parameters:
factoryName - the new factory name


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.