com.lightdev.app.shtm

Class AbstractPlugin

public abstract class AbstractPlugin extends Object implements SHTMLPlugin

Base class for plug-ins of application SimplyHTML.

Defines some common methods for reuse in plug-ins. All settings such as dockLocation or activation state of a plug-in are stored persistently in a preferences file with the help of class Prefs. The preferences file is valid for the current user, so each user has own plug-in settings.

Menus are constructed with the help of class DynamicResource. This class needs menu definitions accessible in a .properties file as described in the API docs of DynamicResource. I.e., methods of class AbstractPlugin only work as defined herein when accompanied by such .properties file accordingly.

Author: Ulrich Hilger Light Development http://www.lightdev.com info@lightdev.com published under the terms and conditions of the GNU General Public License, for details see file gpl.txt in the distribution package of this software

See Also: DynamicResource

Field Summary
protected booleanactive
status of plug-in
protected JComponentc
component of this plug-in
protected intdockLocation
current dock location
protected JFrameframe
JFrame for dockLocation=none
protected StringhelpMenuId
the id in the ResourceFile for the help menu of this plug-in
protected JMenuItemhMenu
the help menu provided by this plug-in
protected StringinternalName
the internal name of this plug-in
protected SHTMLPanelImplowner
the owner of this plug in
protected StringpluginMenuId
the id in the ResourceFile for the menu of this plug-in
protected JMenuItempMenu
the plug-in menu provided by this plug-in
protected Preferencesprefs
reference for user preferences for this class
static StringPREFSID_PLUGIN_ACTIVE
constant for active setting in preferences file
static StringPREFSID_PLUGIN_DOCK_LOCATION
constant for dock location setting in preferences file
static TextResourcestextResources
TextResources of plug-in
Constructor Summary
AbstractPlugin()
construct an AbstractPlugin

Constructor may not have parameters so that java.lang.Class.newInstance can be used on it.

Method Summary
protected voidcreateFrame()
create a frame for the component of this plug-in, if it has a JComponent to display.
protected voidcreateFrameAsNeeded(int location)
create, show or hide frame as needed, depending on a given dock location
protected voidcreateHelpMenu()
create the help menu
protected voidcreatePluginMenu()
create the plug-in menu
JComponentgetComponent()
get the component that this plug-in produces, if any
intgetDockLocation()
get the location the component returned by getDockComponent() shall be docked at.
StringgetGUIName()
get the name of the plug-in as it shall appear on a GUI.
JMenuItemgetHelpMenu()
get a menu item providing documentation about this plug-in.
StringgetInternalName()
get the name used internally for this plug-in
SHTMLPanelImplgetOwner()
get the owner of this plug-in
ActiongetOwnerAction(String cmd)
get an action from the resource bundle of the owner of this plug-in
StringgetOwnerResString(String nm)
get a string from the resource bundle of the owner of this plug-in
JMenuItemgetPluginMenu()
get a menu of actions this plug-in provides.
voidinitHelpMenu()
voidinitPlugin(SHTMLPanelImpl owner)
init the plug-in this is called by the PluginManager directly after instantiating the plug-in
voidinitPlugin(SHTMLPanel owner, String internalName, String pluginMenuId, String helpMenuId)
initialize the plugin
booleanisActive()
get the status of the plug-in
voidsetDockLocation(int location)
set the location the component returned by getDockComponent() shall be docked at.
voidsetOwner(SHTMLPanelImpl owner)
set the owner of this plug-in
voidsetStatus(boolean isActive)
set status of plug-in and persistently store setting in a preferences file

Field Detail

active

protected boolean active
status of plug-in

c

protected JComponent c
component of this plug-in

dockLocation

protected int dockLocation
current dock location

frame

protected JFrame frame
JFrame for dockLocation=none

helpMenuId

protected String helpMenuId
the id in the ResourceFile for the help menu of this plug-in

hMenu

protected JMenuItem hMenu
the help menu provided by this plug-in

internalName

protected String internalName
the internal name of this plug-in

owner

protected SHTMLPanelImpl owner
the owner of this plug in

pluginMenuId

protected String pluginMenuId
the id in the ResourceFile for the menu of this plug-in

pMenu

protected JMenuItem pMenu
the plug-in menu provided by this plug-in

prefs

protected Preferences prefs
reference for user preferences for this class

PREFSID_PLUGIN_ACTIVE

public static final String PREFSID_PLUGIN_ACTIVE
constant for active setting in preferences file

PREFSID_PLUGIN_DOCK_LOCATION

public static final String PREFSID_PLUGIN_DOCK_LOCATION
constant for dock location setting in preferences file

textResources

public static TextResources textResources
TextResources of plug-in

Constructor Detail

AbstractPlugin

public AbstractPlugin()
construct an AbstractPlugin

Constructor may not have parameters so that java.lang.Class.newInstance can be used on it.

Method Detail

createFrame

protected void createFrame()
create a frame for the component of this plug-in, if it has a JComponent to display.

createFrameAsNeeded

protected void createFrameAsNeeded(int location)
create, show or hide frame as needed, depending on a given dock location

Parameters: location the dock location of the plug-in, one of DOCK_LOCATION_TOP, DOCK_LOCATION_BOTTOM, DOCK_LOCATION.LEFT, DOCK_LOCATION_RIGHT or DOCK_LOCATION_NONE, if the component shall not dock.

createHelpMenu

protected void createHelpMenu()
create the help menu

createPluginMenu

protected void createPluginMenu()
create the plug-in menu

getComponent

public JComponent getComponent()
get the component that this plug-in produces, if any

Returns: the component produced by this plug-in, or null if none is produced

getDockLocation

public int getDockLocation()
get the location the component returned by getDockComponent() shall be docked at.

Returns: the dock location, one of DOCK_LOCATION_TOP, DOCK_LOCATION_BOTTOM, DOCK_LOCATION.LEFT, DOCK_LOCATION_RIGHT or DOCK_LOCATION_NONE, if the component shall not dock.

getGUIName

public String getGUIName()
get the name of the plug-in as it shall appear on a GUI.

Returns: the name of the plug-in

getHelpMenu

public JMenuItem getHelpMenu()
get a menu item providing documentation about this plug-in.

JMenu is a decendant of JMenuItem so this method may return a single menu item up to a whole structure of submenus in its return value.

Returns: a menu item with help for this plug-in

getInternalName

public String getInternalName()
get the name used internally for this plug-in

Returns: the internal name of this plug-in

getOwner

public SHTMLPanelImpl getOwner()
get the owner of this plug-in

Returns: the owner of this plug-in

getOwnerAction

public Action getOwnerAction(String cmd)
get an action from the resource bundle of the owner of this plug-in

Parameters: cmd the name of the action to get

Returns: the action with the given name or null, if none is found

getOwnerResString

public String getOwnerResString(String nm)
get a string from the resource bundle of the owner of this plug-in

Parameters: nm the name of the string resource to get

Returns: the string with the given name or null, if none is found

getPluginMenu

public JMenuItem getPluginMenu()
get a menu of actions this plug-in provides.

JMenu is a decendant of JMenuItem so this method may return a single menu item up to a whole structure of submenus in its return value.

Returns: the plug-in menu

initHelpMenu

public void initHelpMenu()

initPlugin

public void initPlugin(SHTMLPanelImpl owner)
init the plug-in this is called by the PluginManager directly after instantiating the plug-in

initPlugin

public void initPlugin(SHTMLPanel owner, String internalName, String pluginMenuId, String helpMenuId)
initialize the plugin

Parameters: owner the owner of this plug-in internalName the internal name this plug-in shall have pluginMenuId the id of the plug-in menu in the TextResources, or null if no plugin-in menu is to be created helpMenuId the id of the help menu for this plug-in in the TextResources, or null if no help menu is to be created

isActive

public boolean isActive()
get the status of the plug-in

Returns: true, if activated, false if not

setDockLocation

public void setDockLocation(int location)
set the location the component returned by getDockComponent() shall be docked at. Persistently store setting in a preferences file.

Parameters: location the dock location, one of DOCK_LOCATION_TOP, DOCK_LOCATION_BOTTOM, DOCK_LOCATION.LEFT, DOCK_LOCATION_RIGHT or DOCK_LOCATION_NONE, if the component shall not dock.

setOwner

public void setOwner(SHTMLPanelImpl owner)
set the owner of this plug-in

Parameters: owner the main frame of the instance of SimplyHTML creating the plug-in

setStatus

public void setStatus(boolean isActive)
set status of plug-in and persistently store setting in a preferences file

Parameters: isActive indicates whether or not the plug-in shall be activated