Package net.sf.gridarta.plugin
Class Plugin<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
- java.lang.Object
-
- net.sf.gridarta.plugin.Plugin<G,A,R>
-
- All Implemented Interfaces:
java.lang.Iterable<PluginParameter<G,A,R,?>>
public class Plugin<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.Object implements java.lang.Iterable<PluginParameter<G,A,R,?>>
Model for plugins.
-
-
Constructor Summary
Constructors Constructor Description Plugin(@NotNull java.lang.String name, @NotNull PluginParameterFactory<G,A,R> pluginParameterFactory)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParameter(@NotNull PluginParameter<G,A,R,?> pluginParameter)Adds a plugin parameter to this plugin.voidaddPluginListener(@NotNull PluginListener listener)Adds aPluginListenerto be notified about changes.@NotNull Plugin<G,A,R>clonePlugin()Returns a clone copy of this plugin.voidconvertType(@NotNull PluginParameter<G,A,R,?> pluginParameter, @NotNull java.lang.String newType)Changes the type of a plugin parameter.@NotNull java.lang.StringgetCode()Returns the executable code of this plugin.@Nullable java.io.FilegetFile()Returns the location to save this plugin to.@NotNull java.lang.StringgetName()Returns the name of this plugin.PluginParameter<G,A,R,?>getParameter(int index)Returns thePluginParameterat a given index.intgetParameter(@NotNull java.lang.String parameterName)Returns the index for a plugin parameter name.@Nullable Filter<?,?>getPluginAsFilter(@NotNull PluginParameters pluginParameters)booleanhasParameters()Returns whether this plugin has at least one parameter.booleanisAutoBoot()Returns whether this plugin is run whenever the editor starts.booleanisFilter()Returns whether this plugin is a filter.booleanisModified()Returns whether the plugin contents have been modified since last save.booleanisScript()Returns whether this plugin is a stand-alone plugin.@NotNull java.util.Iterator<PluginParameter<G,A,R,?>>iterator()voidnewParameter()Creates a new plugin parameter.voidremoveParameter(int index)Removes a plugin parameter.voidremovePluginListener(@NotNull PluginListener listener)Removes aPluginListenerto be notified about changes.voidresetModified()Marks the plugin as unmodified since last save.voidrunPlugin(@NotNull PluginParameters pluginParameters)voidsetAutoBoot(boolean autoBoot)Sets whether this plugin is run whenever the editor starts.voidsetCode(@NotNull java.lang.String code)Sets the executable code of this plugin.voidsetFile(@Nullable java.io.File file)Sets the location to save this plugin to.voidsetFilter(boolean filter)Sets whether this plugin is a filter.voidsetScript(boolean script)Sets whether this plugin is a stand-alone plugin.@NotNull java.lang.StringtoString()@NotNull nu.xom.NodetoXML(@NotNull PluginParameter<G,A,R,?> pluginParameter)Returns XML representation for aPluginParameter.
-
-
-
Constructor Detail
-
Plugin
public Plugin(@NotNull @NotNull java.lang.String name, @NotNull @NotNull PluginParameterFactory<G,A,R> pluginParameterFactory)Creates a new instance.- Parameters:
name- the plugin namepluginParameterFactory- the plugin parameter factory for creating plugin parameters
-
-
Method Detail
-
getName
@NotNull public @NotNull java.lang.String getName()
Returns the name of this plugin.- Returns:
- the name of this plugin
-
getCode
@NotNull public @NotNull java.lang.String getCode()
Returns the executable code of this plugin.- Returns:
- the executable code of this plugin
-
setCode
public void setCode(@NotNull @NotNull java.lang.String code)Sets the executable code of this plugin.- Parameters:
code- the executable code of this plugin
-
hasParameters
public boolean hasParameters()
Returns whether this plugin has at least one parameter.- Returns:
- whether this plugin has at least one parameter
-
getParameter
public int getParameter(@NotNull @NotNull java.lang.String parameterName)Returns the index for a plugin parameter name.- Parameters:
parameterName- the plugin parameter name- Returns:
- the index or
-1if the parameter name does not exist
-
toString
@NotNull public @NotNull java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
newParameter
public void newParameter()
Creates a new plugin parameter.
-
removeParameter
public void removeParameter(int index)
Removes a plugin parameter.- Parameters:
index- the plugin parameter's index
-
addPluginListener
public void addPluginListener(@NotNull @NotNull PluginListener listener)Adds aPluginListenerto be notified about changes.- Parameters:
listener- the change listener
-
removePluginListener
public void removePluginListener(@NotNull @NotNull PluginListener listener)Removes aPluginListenerto be notified about changes.- Parameters:
listener- the change listener
-
clonePlugin
@NotNull public @NotNull Plugin<G,A,R> clonePlugin()
Returns a clone copy of this plugin. The copy include name, executable code, type and a clone of each parameter. The change listeners are not copied.- Returns:
- a clone of this plugin
-
addParameter
public void addParameter(@NotNull @NotNull PluginParameter<G,A,R,?> pluginParameter)Adds a plugin parameter to this plugin.- Parameters:
pluginParameter- the plugin parameter to add
-
getParameter
public PluginParameter<G,A,R,?> getParameter(int index) throws NoSuchParameterException
Returns thePluginParameterat a given index.- Parameters:
index- the index of parameter to return; must be between0andgetParametersCount()- Returns:
- the plugin parameter
- Throws:
NoSuchParameterException- if the index is invalid
-
isAutoBoot
public boolean isAutoBoot()
Returns whether this plugin is run whenever the editor starts.- Returns:
- whether this plugin is run whenever the editor starts
-
isScript
public boolean isScript()
Returns whether this plugin is a stand-alone plugin.- Returns:
- whether this plugin is a stand-alone plugin
-
isFilter
public boolean isFilter()
Returns whether this plugin is a filter.- Returns:
- whether this plugin is a filter
-
setAutoBoot
public void setAutoBoot(boolean autoBoot)
Sets whether this plugin is run whenever the editor starts.- Parameters:
autoBoot- whether this plugin is run whenever the editor starts
-
setScript
public void setScript(boolean script)
Sets whether this plugin is a stand-alone plugin.- Parameters:
script- whether this plugin is a stand-alone plugin
-
setFilter
public void setFilter(boolean filter)
Sets whether this plugin is a filter.- Parameters:
filter- whether this plugin is a filter
-
convertType
public void convertType(@NotNull @NotNull PluginParameter<G,A,R,?> pluginParameter, @NotNull @NotNull java.lang.String newType) throws NoSuchParameterExceptionChanges the type of a plugin parameter.- Parameters:
pluginParameter- the plugin parameternewType- the new type- Throws:
NoSuchParameterException- if the index is invalid
-
isModified
public boolean isModified()
Returns whether the plugin contents have been modified since last save.- Returns:
- whether the plugin contents have been modified since last save
-
resetModified
public void resetModified()
Marks the plugin as unmodified since last save.
-
getFile
@Nullable public @Nullable java.io.File getFile()
Returns the location to save this plugin to.- Returns:
- the location to save to, or
nullif the plugin has no associated location
-
setFile
public void setFile(@Nullable @Nullable java.io.File file)Sets the location to save this plugin to.- Parameters:
file- the save location ornull
-
iterator
@NotNull public @NotNull java.util.Iterator<PluginParameter<G,A,R,?>> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<G extends GameObject<G,A,R>>
-
runPlugin
public void runPlugin(@NotNull @NotNull PluginParameters pluginParameters)
-
getPluginAsFilter
@Nullable public @Nullable Filter<?,?> getPluginAsFilter(@NotNull @NotNull PluginParameters pluginParameters)
-
toXML
@NotNull public @NotNull nu.xom.Node toXML(@NotNull @NotNull PluginParameter<G,A,R,?> pluginParameter)Returns XML representation for aPluginParameter.- Parameters:
pluginParameter- the plugin parameter- Returns:
- the plugin parameter in XML representation
-
-