com.levigo.util.swing.action
Class BasicActionFactory

java.lang.Object
  extended by com.levigo.util.swing.action.BasicActionFactory
All Implemented Interfaces:
ActionFactory, NamedActionFactory

public class BasicActionFactory
extends Object
implements NamedActionFactory

BasicActionFactory provides base functionality for action factories

Author:
Carolin Köhler
See Also:
ActionFactory, DefaultActionFactory

Field Summary
protected  com.levigo.util.preferences.PropertiesPreferenceStore actionLookupProperties
          Instance of the property file.
protected static String COMMANDS
          Key word for the property: commands for the action
protected static List<String> EMPTY_STRING_LIST
           
protected  String factoryName
          Name of this action factory, usually the properties file name.
protected static Field[] fields
          All key event identifiers used to generate keystrokes.
static String INPUT_MAP
          The key used for storing the keystrokes for the action in an InputMap (referenced by an ActionMap) used for a menu or button.
protected static String VISIBLE
          Key word for the property if the action is visible
 
Constructor Summary
protected BasicActionFactory()
          Default constructor
protected BasicActionFactory(InputStream propertyInputStream, String factoryName)
          Constructor, reads a property list (key and element pairs) from the given input stream and fills up the contained actionLookupProperties.
protected BasicActionFactory(String propertiesFileName)
          Constructor invokes a loading of the property file and creates the icon manager.
 
Method Summary
 void clearLookupProperties()
          Clears the lookup properties.
 CommandAction getAction(Context context, String key)
          Default constructor using the settings of the actions.properties file.
protected  CommandAction getAction(Context context, String key, boolean ignoreEmptyCommands)
          Default constructor using the settings of the actions.properties file.
 CommandAction getAction(Context context, String key, String name, String commands, String shortDescription, String longDescription, Icon smallIcon, Icon largeIcon, String actionCommandKey, KeyStroke acceleratorKey, int mnemonicKey, HashMap<String,Object> otherParameters)
          Settings for the icons, texts etc.
protected  CommandAction getAction(Context context, String key, String name, String commands, String shortDescription, String longDescription, Icon smallIcon, Icon largeIcon, String actionCommandKey, KeyStroke acceleratorKey, int mnemonicKey, HashMap<String,Object> otherParameters, boolean ignoreEmptyCommands)
          Settings for the icons, texts etc.
protected  CommandFactory getCommandFactory(String key)
           
 String getFactoryName()
          Returns the name of this factory, usually its properties file name.
protected  IconManager getIconManager(String key)
          Finds the IconManager to use for the specified key.
protected static int getKeyEventIdentifier(NamedActionFactory caller, String keyAsString)
          Find the key stroke or key mask identifier (defined in either KeyEvent or InputEvent) for the given name and returns it.
protected  KeyStroke getKeyStroke(String keyString)
          Creates a Keystroke by the given key information, e.g.
 String getLookupProperty(String key)
          Allows an application to request lookup properties programmatically.
protected  HashMap<String,Object> getMoreParameters(String key)
          Method returns the Map of the keys and values which are not recognized in AbstractAction.
protected  Collection<String> getParameters(String key)
          Method returns all parameters for the key.
protected  void loadProperties(InputStream is)
          Reads a property list (key and element pairs) from the input stream and fills the embedded actionLookupProperties.
protected  void loadProperties(String propertyFileName)
          The method loads the property file.
 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

fields

protected static Field[] fields
All key event identifiers used to generate keystrokes.


INPUT_MAP

public static final String INPUT_MAP
The key used for storing the keystrokes for the action in an InputMap (referenced by an ActionMap) used for a menu or button.

See Also:
Constant Field Values

VISIBLE

protected static final String VISIBLE
Key word for the property if the action is visible

See Also:
Constant Field Values

COMMANDS

protected static final String COMMANDS
Key word for the property: commands for the action

See Also:
Constant Field Values

EMPTY_STRING_LIST

protected static final List<String> EMPTY_STRING_LIST

actionLookupProperties

protected com.levigo.util.preferences.PropertiesPreferenceStore actionLookupProperties
Instance of the property file. From this file are read the informations about actions


factoryName

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

Constructor Detail

BasicActionFactory

protected BasicActionFactory(String propertiesFileName)
                      throws Exception
Constructor invokes a loading of the property file and creates the icon manager.

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

BasicActionFactory

protected BasicActionFactory(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 actionLookupProperties.

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

BasicActionFactory

protected BasicActionFactory()
Default constructor

Method Detail

getIconManager

protected IconManager getIconManager(String key)
Finds the IconManager to use for the specified key.


getAction

public CommandAction getAction(Context context,
                               String key,
                               String name,
                               String commands,
                               String shortDescription,
                               String longDescription,
                               Icon smallIcon,
                               Icon largeIcon,
                               String actionCommandKey,
                               KeyStroke acceleratorKey,
                               int mnemonicKey,
                               HashMap<String,Object> otherParameters)
Settings for the icons, texts etc. in the action.properties file can be overwritten.

Default command factory is DefaultCommandFactory

Specified by:
getAction in interface ActionFactory
Parameters:
context - belongs to the context
key - key of the commandAction
name - value for Action.NAME
commands - all commands of the commandAction
shortDescription - value for Action.SHORT_DESCRIPTION
longDescription - value for Action.LONG_DESCRIPTION
smallIcon - value for Action.SMALL_ICON
largeIcon - value for Action.LARGE_ICON_KEY
actionCommandKey - value for Action.ACTION_COMMAND_KEY
acceleratorKey - value for Action.ACCELERATOR_KEY
mnemonicKey - value for Action.MNEMONIC_KEY
otherParameters - other parameters which will be added to the action (can be null)
Returns:
created CommandAction
See Also:
ActionFactory.getAction(com.levigo.util.swing.action.Context, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.swing.Icon, javax.swing.Icon, java.lang.String, javax.swing.KeyStroke, int, java.util.HashMap)

getAction

protected CommandAction getAction(Context context,
                                  String key,
                                  String name,
                                  String commands,
                                  String shortDescription,
                                  String longDescription,
                                  Icon smallIcon,
                                  Icon largeIcon,
                                  String actionCommandKey,
                                  KeyStroke acceleratorKey,
                                  int mnemonicKey,
                                  HashMap<String,Object> otherParameters,
                                  boolean ignoreEmptyCommands)
Settings for the icons, texts etc. in the action.properties file can be overwritten.

Default command factory is DefaultCommandFactory

See Also:
ActionFactory.getAction(com.levigo.util.swing.action.Context, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.swing.Icon, javax.swing.Icon, java.lang.String, javax.swing.KeyStroke, int, java.util.HashMap)

getParameters

protected Collection<String> getParameters(String key)
Method returns all parameters for the key. This method is called fairly often, therefore it is optimized a bit.

Parameters:
key - to read the parameters
Returns:
Collection of the parameters for the key

getMoreParameters

protected HashMap<String,Object> getMoreParameters(String key)
Method returns the Map of the keys and values which are not recognized in AbstractAction.

Parameters:
key - for the parameters
Returns:
HashMap of the not recognized parameters

loadProperties

protected void loadProperties(String propertyFileName)
                       throws IOException
The method loads the property file. It is called from the constructor. As name of the file is default used the parameter DEFAULT_PROPERTIES_FILE}

Parameters:
propertyFileName - The name of the file from which should be the informations read
Throws:
IOException

loadProperties

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

Throws:
IOException

getKeyStroke

protected final KeyStroke getKeyStroke(String keyString)
Creates a Keystroke by the given key information, e.g. for accelerator keys or keystrokes used in an InputMap. Each keystroke is defined by a key and a combination of modifiers. Their values are read from the properties file.

The "virtual key" constants defined in java.awt.event.KeyEvent can be used to specify the key. For example:

The modifier constants are defined java.awt.Event. To specify a modifier use any combination of: Define a keystroke in the properties file like the following examples:

Hint:
A KeyStroke consist always of only one key and any combination of modifiers. If more than one key are defined in the given keyString, only the first key will be accepted. Fully rewrited 03-12-19, Carolin Köhler.

Parameters:
keyString - key information to be translated into a keystroke
Returns:
KeyStroke the keystroke defined by given keystring or null if keyinformation contains no valid description

getKeyEventIdentifier

protected static int getKeyEventIdentifier(NamedActionFactory caller,
                                           String keyAsString)
Find the key stroke or key mask identifier (defined in either KeyEvent or InputEvent) for the given name and returns it.

Parameters:
keyAsString - The name of the identifier as a String
Returns:
The int value of the key stroke or key mask identifier (defined in either KeyEvent or InputEvent)

getAction

public CommandAction getAction(Context context,
                               String key)
Default constructor using the settings of the actions.properties file. Key is used as the action's name.

Default command factory is DefaultCommandFactory

Specified by:
getAction in interface ActionFactory
Parameters:
context - belongs to the context
key - key of the commandAction
Returns:
created CommandAction
See Also:
ActionFactory.getAction(Context, String)

getAction

protected CommandAction getAction(Context context,
                                  String key,
                                  boolean ignoreEmptyCommands)
Default constructor using the settings of the actions.properties file. Key is used as the action's name.

Default command factory is DefaultCommandFactory

See Also:
ActionFactory.getAction(Context, String)

getCommandFactory

protected CommandFactory getCommandFactory(String key)

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 action.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 (e.g. MyAction.commands or MyAction.ShortDescription)
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 NamedActionFactory
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.