Class PluginFactory

java.lang.Object
com.chemaxon.calculations.gui.PluginFactory

@PublicApi public class PluginFactory extends Object
Plugin factroy: responsible for plugin parameter panel and plugin creation and central management.
Since:
Marvin 4.0
  • Field Details

    • DEFAULT_CONFIG_FILE

      public static final String DEFAULT_CONFIG_FILE
      The default config file name.
      See Also:
    • PRELOAD

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public static final String PRELOAD
      Deprecated, for removal: This API element is subject to removal in a future version.
      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:
    • 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:
    • 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:
  • Constructor Details

    • PluginFactory

      public PluginFactory()
      Constructor.
  • Method Details

    • 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 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(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>$$<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. The plugin class name has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

      Note: the second argument was originally an optional name of plugin-specific jar. We no longer use this argument, it is ignored for backward compatibility.

      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().

      The plugin is instantiated from the current CLASSPATH by its name. 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(Properties props) throws PluginException
      Loads plugin data from properties. Format:
       key=$<plugin class name>$$<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. The plugin class name has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

      Note: the second argument was originally an optional name of plugin-specific jar. We no longer use this argument, it is ignored for backward compatibility.

      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().

      The plugin is instantiated from the current CLASSPATH by its name. 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 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)
      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(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