chemaxon.marvin.plugin
Class PluginFactory

java.lang.Object
  extended by chemaxon.marvin.plugin.PluginFactory

public class PluginFactory
extends java.lang.Object

Plugin factroy: responsible for plugin parameter panel and plugin creation and central management.

Since:
Marvin 4.0
Author:
Nora Mate, Zsolt Mohacsi

Nested Class Summary
 class PluginFactory.PluginRecord
          Stores plugin data.
 
Field Summary
static java.lang.String DEFAULT_CONFIG_FILE
          The default config file name.
static java.lang.String NOPARAMS
          No parameter panel sign in property file: if present then no parameter panel belongs to the plugin.
static java.lang.String PRELOAD
          Deprecated. Not used.
static java.lang.String SEPARATOR
          Menuitem separator in Tools menu: if present then separator will be added to the Tools menu after the plugin menuitem.
 
Constructor Summary
PluginFactory()
          Constructor.
 
Method Summary
static ParameterPanelHandler createDefaultParameterPanel(java.lang.Class pluginClass, java.lang.String cl, java.awt.Component parent)
           
static ParameterPanelHandler createDefaultParameterPanel(java.lang.String cl, java.awt.Component parent)
          Creates default parameter panel based on XML config.
 int getCount()
          Returns the number of plugin records.
 CalculatorPluginDisplay getDisplay(int index)
          Gets a display object, loads it if needed.
 java.lang.String getGroup(int index)
          Gets the menu group for a plugin.
 char getGroupMnemonic(int index)
          Gets the group mnemonic for a plugin.
 java.lang.String getKey(int index)
          Gets the menu key for a plugin.
 java.lang.String getMenu(int index)
          Gets the menu string for a plugin.
 char getMnemonic(int index)
          Gets the menu mnemonic for a plugin.
 OptionsPane getOptionsPane(int index)
          Gets the options pane for a plugin, loads it if needed.
 ParameterPanelHandler getParameterPanel(int index)
          Gets the parameter panel for a plugin, loads it if needed.
 CalculatorPlugin getPlugin(int index)
          Gets a plugin, loads it if needed.
 int getPluginIndex(java.lang.String key)
          Gets a plugin index from record key.
 boolean getSeparator(int index)
          Gets if a separator is required after the plugin menuitem in the Tools menu.
 boolean hasParameters(int index)
          Returns true if plugin has parameter panel, false otherwise.
 boolean isOptionsPaneLoaded(int index)
          Returns true is options pane is loaded for plugin, false otherwise.
 void load()
          Loads default property file.
 void load(java.util.Properties props)
          Loads plugin data from properties.
 void load(java.lang.String file, java.lang.String alterfile)
          Loads plugin data from property file.
 void saveParameterSettings()
          Saves plugin parameter settings to file $HOME/chemaxon/<plugin class name>Parameters.properties (Windows), or $HOME/.chemaxon/<plugin class name>Parameters.properties (UNIX / Linux).
 void setOKActionListener(java.awt.event.ActionListener okActionListener)
          Sets the "OK" button pressed action listener.
 void setParentComponent(java.awt.Component parent)
          Sets the parent component - this is used to set options panes positions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONFIG_FILE

public static final java.lang.String DEFAULT_CONFIG_FILE
The default config file name.

See Also:
Constant Field Values

PRELOAD

public static final java.lang.String PRELOAD
Deprecated. Not used.
Preload sign in property file: if present then the plugin loader and the plugin should be preloaded, otherwise both are loaded when first used.

See Also:
Constant Field Values

NOPARAMS

public static final java.lang.String NOPARAMS
No parameter panel sign in property file: if present then no parameter panel belongs to the plugin.

See Also:
Constant Field Values

SEPARATOR

public static final java.lang.String SEPARATOR
Menuitem separator in Tools menu: if present then separator will be added to the Tools menu after the plugin menuitem.

See Also:
Constant Field Values
Constructor Detail

PluginFactory

public PluginFactory()
Constructor.

Method Detail

setOKActionListener

public void setOKActionListener(java.awt.event.ActionListener okActionListener)
Sets the "OK" button pressed action listener. If set, the factory generates option pane with "OK" button, setting the "OK" button action command to "plugin_" and adds this action listener to the button.

Parameters:
okActionListener - is the "OK" button pressed action listener

setParentComponent

public void setParentComponent(java.awt.Component parent)
Sets the parent component - this is used to set options panes positions.

Parameters:
parent - is parent component

createDefaultParameterPanel

public static ParameterPanelHandler createDefaultParameterPanel(java.lang.String cl,
                                                                java.awt.Component parent)
                                                         throws PluginException
Creates default parameter panel based on XML config. This is a ParameterPanel object based on the <plugin class name>Parameters.xml configuration XML read from CalculatorPlugin.PLUGIN_DIR, with user parameter settings read from $HOME/chemaxon/<plugin class name>Parameters.properties (Windows), or $HOME/.chemaxon/<plugin class name>Parameters.properties (UNIX / Linux). Returns null (no paramter panel for this plugin) if the configuration XML is not found.

Parameters:
cl - the full plugin class name
Returns:
the parameter panel, or null if no XML config file found
Throws:
PluginException

createDefaultParameterPanel

public static ParameterPanelHandler createDefaultParameterPanel(java.lang.Class pluginClass,
                                                                java.lang.String cl,
                                                                java.awt.Component parent)
                                                         throws PluginException
Throws:
PluginException

load

public void load()
          throws PluginException
Loads default property file.

Throws:
PluginException

load

public void load(java.lang.String file,
                 java.lang.String alterfile)
          throws PluginException
Loads plugin data from property file. There is a line for each plugin in the property file according to the following syntax:
 key=$<plugin class name>$<plugin JAR URL>$<menu>$<mnemonics>$<group>$<groupmnemonic>$<NOPARAMS>
 
The first character in the value (after the '=' sign) is the delimiter - can be any ASCII character that does not occur in the value string. The '$' character is appropriate in most cases. Plugins will be sorted by key. At least one of the plugin class name and the plugin JAR has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

Creating the plugin parameter panel:

  1. First a configuration XML is searched in the CLASSPATH. Its name is generated from the plugin class name without the package name: <plugin name>Parameters.xml. If this file is found then a generic parameter panel is generated,
  2. otherwise the plugin should be created to fetch its specific parameter panel by plugin.getParameterPanel().
Initial parameter values in the parameter panel are set from $HOME/chemaxon/<plugin name>Parameters.properties (Windows) or $HOME/.chemaxon/<plugin name>Parameters.properties (UNIX / Linux) if exists, otherwise default initial values are set from the configuration XML or in plugin.getParameterPanel().

Creating the plugin:

  1. If the plugin class name is specified then first the plugin is attempted to be instantiated from the current CLASSPATH. Continue with next step on failure.
  2. If the plugin JAR is specified then the plugin is instantiated from the JAR. If the plugin class name is not specified then it is read from the Plugin-Class attribute of the JAR manifest.
Plugin and parameter panels are created as needed.

Parameters:
file - is the config file name as resource, relative to the CLASSPATH
alterfile - the optional config file name as resource, relative to the CLASSPATH, set it to null to prefer the default config file
Throws:
PluginException - on error

load

public void load(java.util.Properties props)
          throws PluginException
Loads plugin data from properties. Format:
 key=$<plugin class name>$<plugin JAR URL>$<menu>$<mnemonics>$<group>$<groupmnemonic>$<NOPARAMS>
 
The first character in the value (after the '=' sign) is the delimiter - can be any ASCII character that does not occur in the value string. The '$' character is appropriate in most cases. Plugins will be sorted by key. At least one of the plugin class name and the plugin JAR has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

Creating the plugin parameter panel:

  1. First a configuration XML is searched in the CLASSPATH. Its name is generated from the plugin class name without the package name: plugin/<plugin name>Parameters.xml. If this file is found then a generic parameter panel is generated,
  2. otherwise the plugin should be created to fetch its specific parameter panel by plugin.getParameterPanel().
Initial parameter values in the parameter panel are set from $HOME/chemaxon/<plugin name>Parameters.properties (Windows) or $HOME/.chemaxon/<plugin name>Parameters.properties (UNIX / Linux) if exists, otherwise default initial values are set from the configuration XML or in plugin.getParameterPanel().

Creating the plugin:

  1. If the plugin class name is specified then first the plugin is attempted to be instantiated from the current CLASSPATH. Continue with next step on failure.
  2. If the plugin JAR is specified then the plugin is instantiated from the JAR. If the plugin class name is not specified then it is read from the Plugin-Class attribute of the JAR manifest.
Plugin and parameter panels are created as needed.

Parameters:
props - is the property object storing the plugin configuration
Throws:
PluginException - on error

saveParameterSettings

public void saveParameterSettings()
Saves plugin parameter settings to file $HOME/chemaxon/<plugin class name>Parameters.properties (Windows), or $HOME/.chemaxon/<plugin class name>Parameters.properties (UNIX / Linux).


getCount

public int getCount()
Returns the number of plugin records.

Returns:
the number of plugin records

getMenu

public java.lang.String getMenu(int index)
Gets the menu string for a plugin.

Parameters:
index - is the plugin record index
Returns:
the plugin menu string

getKey

public java.lang.String getKey(int index)
Gets the menu key for a plugin.

Parameters:
index - is the plugin record index
Returns:
the menu key

getMnemonic

public char getMnemonic(int index)
Gets the menu mnemonic for a plugin.

Parameters:
index - is the plugin record index
Returns:
the menu mnemonic

getGroup

public java.lang.String getGroup(int index)
Gets the menu group for a plugin.

Parameters:
index - is the plugin record index
Returns:
the menu group

getGroupMnemonic

public char getGroupMnemonic(int index)
Gets the group mnemonic for a plugin.

Parameters:
index - is the plugin record index
Returns:
the menu mnemonic

getSeparator

public boolean getSeparator(int index)
Gets if a separator is required after the plugin menuitem in the Tools menu.

Parameters:
index - is the plugin record index
Returns:
true if separator is needed, false otherwise
Since:
Marvin 5.4

getParameterPanel

public ParameterPanelHandler getParameterPanel(int index)
                                        throws PluginException
Gets the parameter panel for a plugin, loads it if needed.

Parameters:
index - is the plugin record index
Returns:
the parameter panel
Throws:
PluginException - on error

getOptionsPane

public OptionsPane getOptionsPane(int index)
                           throws PluginException
Gets the options pane for a plugin, loads it if needed.

Parameters:
index - is the plugin record index
Returns:
the options pane
Throws:
PluginException - on error

getPlugin

public CalculatorPlugin getPlugin(int index)
                           throws PluginException
Gets a plugin, loads it if needed.

Parameters:
index - is the plugin record index
Returns:
the plugin
Throws:
PluginException - on error

getDisplay

public CalculatorPluginDisplay getDisplay(int index)
                                   throws PluginException
Gets a display object, loads it if needed.

Parameters:
index - is the plugin record index
Returns:
the display object
Throws:
PluginException - on error

hasParameters

public boolean hasParameters(int index)
Returns true if plugin has parameter panel, false otherwise.

Returns:
whether plugin has parameter panel

isOptionsPaneLoaded

public boolean isOptionsPaneLoaded(int index)
Returns true is options pane is loaded for plugin, false otherwise.

Returns:
whether potions pane is loaded for plugin

getPluginIndex

public int getPluginIndex(java.lang.String key)
Gets a plugin index from record key.

Parameters:
key - is the plugin record key
Returns:
the plugin record index, or -1 for non-existent key