 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.plugin;
23 import bsh.Interpreter;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.concurrent.CopyOnWriteArrayList;
41 import nu.xom.Element;
43 import org.apache.log4j.Category;
44 import org.apache.log4j.Logger;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
59 private static final Category
LOG = Logger.getLogger(
Plugin.class);
71 private final List<PluginParameter<G, A, R, ?>>
parameters =
new ArrayList<>();
111 private final Collection<PluginListener>
listeners =
new CopyOnWriteArrayList<>();
166 if (this.code.equals(
code)) {
190 if (parameter.getName().equals(parameterName)) {
212 LOG.warn(
"Cannot create parameter: " + ex.getMessage());
253 listener.parametersChanged();
273 final Element parameterXml =
codec.
toXML(parameter);
278 throw new AssertionError(ex);
306 }
catch (
final IndexOutOfBoundsException ex) {
352 if (this.script ==
script) {
364 if (this.filter ==
filter) {
378 final int index =
parameters.indexOf(pluginParameter);
432 public Iterator<PluginParameter<G, A, R, ?>>
iterator() {
433 return Collections.unmodifiableList(
parameters).iterator();
437 final Interpreter runner =
new Interpreter();
441 }
catch (
final EvalError e) {
442 LOG.warn(
"Evaluation error on (auto-run)" +
name, e);
448 final Interpreter runner =
new Interpreter();
452 }
catch (
final EvalError e) {
453 LOG.warn(
"Evaluation error on (filter)" +
name, e);
454 }
catch (
final ClassCastException e) {
455 LOG.warn(
"Plugin did not return a net.sf.gridarta.model.filter.Filter object" +
name, e);
Converts PluginParameters from or to XML encoding.
Base package of all Gridarta classes.
void setScript(final boolean script)
Sets whether this plugin is a stand-alone plugin.
boolean modified
Whether the plugin contents has been modified since last save.
String getName()
Returns the name of this plugin.
int getParameter(@NotNull final String parameterName)
Returns the index for a plugin parameter name.
void notifyParametersChangedListeners()
Notifies all registered PluginListeners that the parameters have changed.
Interface for listeners interested in PluginParameter related events.
boolean hasParameters()
Returns whether this plugin has at least one parameter.
final List< PluginParameter< G, A, R, ?> > parameters
The PluginParameters for this plugin.
void addPluginParameterListener(@NotNull PluginParameterListener listener)
Adds a listener to be notified.
Plugin< G, A, R > clonePlugin()
Returns a clone copy of this plugin.
Plugin(@NotNull final String name, @NotNull final PluginParameterFactory< G, A, R > pluginParameterFactory)
Creates a new instance.
void newParameter()
Creates a new plugin parameter.
PluginParameter< G, A, R, ?> createParameter(@NotNull final Element parameterNode)
static final String PARAMETER_TYPE
The string representation of this parameter type.
void setCode(@NotNull final String code)
Sets the executable code of this plugin.
Reflects a game object (object on a map).
Makes basic Gridarta classes available to scripts.
void addPluginListener(@NotNull final PluginListener listener)
Adds a PluginListener to be notified about changes.
final PluginParameterCodec< G, A, R > codec
The PluginParameterCodec for converting PluginParameters to or from XML representation.
Node toXML(@NotNull final PluginParameter< G, A, R, ?> pluginParameter)
Returns XML representation for a PluginParameter.
Thrown if a parameter does not exist.
GameObjects are the objects based on Archetypes found on maps.
void addParameter(@NotNull final PluginParameter< G, A, R, ?> pluginParameter)
Adds a plugin parameter to this plugin.
File file
The location to save this plugin to; set to.
void setModified()
Marks this plugin a modified since last save.
void runPlugin(@NotNull final PluginParameters pluginParameters)
Interface for listeners interested in Plugin related events.
final String name
The plugin name.
boolean filter
Whether this plugin is a filter.
String code
The executable code.
Interface for MapArchObjects.
boolean isScript()
Returns whether this plugin is a stand-alone plugin.
void setAutoBoot(final boolean autoBoot)
Sets whether this plugin is run whenever the editor starts.
static final Category LOG
The Logger for printing log messages.
Filter<?, ?> getPluginAsFilter(@NotNull final PluginParameters pluginParameters)
boolean isFilter()
Returns whether this plugin is a filter.
void convertType(@NotNull final PluginParameter< G, A, R, ?> pluginParameter, @NotNull final String newType)
Changes the type of a plugin parameter.
boolean autoBoot
Whether this plugin is run whenever the editor starts.
void removePluginListener(@NotNull final PluginListener listener)
Removes a PluginListener to be notified about changes.
void setFilter(final boolean filter)
Sets whether this plugin is a filter.
void removeParameter(final int index)
Removes a plugin parameter.
The run mode of a plugin plugin.
void setFile(@Nullable final File file)
Sets the location to save this plugin to.
final PluginParameterListener pluginParameterListener
The PluginParameterListener that is attached to all {plugin parameters} to detect changes.
Iterator< PluginParameter< G, A, R, ?> > iterator()
final PluginParameterVisitor< G, A, R, Element > toXML
A PluginParameterVisitor that returns XML representation.
Factory for Plugin Parameters.
boolean isAutoBoot()
Returns whether this plugin is run whenever the editor starts.
final Collection< PluginListener > listeners
The PluginListeners to inform about changes.
final PluginParameterFactory< G, A, R > pluginParameterFactory
The PluginParameterFactory for creating plugin parameters.
File getFile()
Returns the location to save this plugin to.
void removePluginParameterListener(@NotNull PluginParameterListener listener)
Removes a listener to be notified.
A PluginParameter that holds a string value.
void resetModified()
Marks the plugin as unmodified since last save.
PluginParameter< G, A, R, ?> getParameter(final int index)
Returns the PluginParameter at a given index.
boolean script
Whether this plugin is a stand-alone plugin.
String getCode()
Returns the executable code of this plugin.
boolean isModified()
Returns whether the plugin contents have been modified since last save.