Package com.chemaxon.calculations.gui
Class PluginFactory
- java.lang.Object
-
- com.chemaxon.calculations.gui.PluginFactory
-
- Direct Known Subclasses:
PluginFactory
@PublicAPI public class PluginFactory extends Object
Plugin factroy: responsible for plugin parameter panel and plugin creation and central management.- Since:
- Marvin 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
PluginFactory.PluginRecord
Stores plugin data.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_CONFIG_FILE
The default config file name.static String
NOPARAMS
No parameter panel sign in property file: if present then no parameter panel belongs to the plugin.static String
PRELOAD
Deprecated.Not used.static String
SEPARATOR
Menuitem separator in Tools menu: if present then separator will be added to the Tools menu after the plugin menuitem.
-
Constructor Summary
Constructors Constructor Description PluginFactory()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ParameterPanelHandler
createDefaultParameterPanel(Class pluginClass, String cl, Component parent)
static ParameterPanelHandler
createDefaultParameterPanel(String cl, 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.String
getGroup(int index)
Gets the menu group for a plugin.char
getGroupMnemonic(int index)
Gets the group mnemonic for a plugin.String
getKey(int index)
Gets the menu key for a plugin.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(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)
Returnstrue
if plugin has parameter panel,false
otherwise.boolean
isOptionsPaneLoaded(int index)
Returnstrue
is options pane is loaded for plugin,false
otherwise.void
load()
Loads default property file.void
load(String file, String alterfile)
Loads plugin data from property file.void
load(Properties props)
Loads plugin data from properties.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(ActionListener okActionListener)
Sets the "OK" button pressed action listener.void
setParentComponent(Component parent)
Sets the parent component - this is used to set options panes positions.
-
-
-
Field Detail
-
DEFAULT_CONFIG_FILE
public static final String DEFAULT_CONFIG_FILE
The default config file name.- See Also:
- Constant Field Values
-
PRELOAD
@Deprecated public static final 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 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 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
-
-
Method Detail
-
setOKActionListener
public void setOKActionListener(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(Component parent)
Sets the parent component - this is used to set options panes positions.- Parameters:
parent
- is parent component
-
createDefaultParameterPanel
public static ParameterPanelHandler createDefaultParameterPanel(String cl, Component parent) throws PluginException
Creates default parameter panel based on XML config. This is aParameterPanel
object based on the<plugin class name>Parameters.xml
configuration XML read fromCalculatorPlugin.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). Returnsnull
(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(Class pluginClass, String cl, Component parent) throws PluginException
- Throws:
PluginException
-
load
public void load() throws PluginException
Loads default property file.- Throws:
PluginException
-
load
public void load(String file, 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:
- 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, - otherwise the plugin should be created to fetch its specific parameter panel
by
plugin.getParameterPanel()
.
$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 inplugin.getParameterPanel()
.Creating the plugin:
- 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.
- 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.
- Parameters:
file
- is the config file name as resource, relative to the CLASSPATHalterfile
- 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
- First a configuration XML is searched in the CLASSPATH.
Its name is generated from the plugin class name without the package name:
-
load
public void load(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:
- 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, - otherwise the plugin should be created to fetch its specific parameter panel
by
plugin.getParameterPanel()
.
$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 inplugin.getParameterPanel()
.Creating the plugin:
- 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.
- 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.
- Parameters:
props
- is the property object storing the plugin configuration- Throws:
PluginException
- on error
- First a configuration XML is searched in the CLASSPATH.
Its name is generated from the plugin class name without the package name:
-
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 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 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 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)
Returnstrue
if plugin has parameter panel,false
otherwise.- Returns:
- whether plugin has parameter panel
-
isOptionsPaneLoaded
public boolean isOptionsPaneLoaded(int index)
Returnstrue
is options pane is loaded for plugin,false
otherwise.- Returns:
- whether potions pane is loaded for plugin
-
getPluginIndex
public int getPluginIndex(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
-
-