 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.plugin;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.Iterator;
29 import java.util.TreeMap;
30 import java.util.concurrent.CopyOnWriteArrayList;
35 import nu.xom.Document;
36 import nu.xom.Element;
37 import nu.xom.ParsingException;
38 import nu.xom.Serializer;
39 import org.apache.log4j.Category;
40 import org.apache.log4j.Logger;
41 import org.jetbrains.annotations.NotNull;
42 import org.jetbrains.annotations.Nullable;
43 import org.xml.sax.SAXException;
64 private final Map<String, Plugin<G, A, R>>
plugins =
new TreeMap<>();
71 private final Collection<PluginModelListener<G, A, R>>
listeners =
new CopyOnWriteArrayList<>();
89 final Iterator<Plugin<G, A, R>>
it =
plugins.values().iterator();
92 while (
it.hasNext() && i-- >= 0) {
95 return i >= 0 ? null : m;
105 if (
plugins.containsKey(plugin.getName())) {
109 plugins.put(plugin.getName(), plugin);
118 }
catch (
final IOException ex) {
119 LOG.warn(
"can't load plugin: " + ex.getMessage());
120 }
catch (
final ParsingException | SAXException ex) {
121 LOG.warn(
"can't parse plugin: " + ex.getMessage());
126 if (!
plugins.containsKey(plugin.getName())) {
127 throw new IllegalArgumentException(
"plugin does not exist: " + plugin.getName());
132 plugins.remove(plugin.getName());
142 try (FileOutputStream fos =
new FileOutputStream(file)) {
144 final Document d =
new Document(root);
145 final Serializer serializer =
new Serializer(fos,
"UTF-8");
146 serializer.setIndent(2);
173 listener.pluginCreated(plugin);
183 listener.pluginDeleted(plugin);
193 listener.pluginRegistered(plugin);
203 listener.pluginUnregistered(plugin);
210 return Collections.unmodifiableCollection(
plugins.values()).iterator();
222 return addPlugin(plugin) ? plugin :
null;
Element toXML(@NotNull final Plugin< G, A, R > plugin)
Converts a Plugin instance to XML representation.
Plugin< G, A, R > newPlugin(@NotNull final String name, @NotNull final String code)
Base package of all Gridarta classes.
void addPluginModelListener(@NotNull final PluginModelListener< G, A, R > listener)
Adds a listener to be informed of changes.
void removePlugin(@NotNull final Plugin< G, A, R > plugin)
void removePluginModelListener(@NotNull final PluginModelListener< G, A, R > listener)
Removes a listener to be informed of changes.
Utility class for loading plugins.
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > Plugin< G, A, R > loadXML(@NotNull final PluginModelParser< G, A, R > pluginModelParser, @NotNull final File file)
boolean addPlugin(@NotNull final Plugin< G, A, R > plugin)
Add a new plugin.
final Collection< PluginModelListener< G, A, R > > listeners
The PluginModelListeners to inform of changes.
static final Category LOG
The Logger for printing log messages.
void setCode(@NotNull final String code)
Sets the executable code of this plugin.
Reflects a game object (object on a map).
Iterator< Plugin< G, A, R > > iterator()
void firePluginUnregisteredEvent(@NotNull final Plugin< G, A, R > plugin)
Notifies all listeners about an unregistered plugin.
GameObjects are the objects based on Archetypes found on maps.
final Map< String, Plugin< G, A, R > > plugins
final PluginModelParser< G, A, R > pluginModelParser
void reRegister(@NotNull final Plugin< G, A, R > plugin)
Interface for MapArchObjects.
Plugin< G, A, R > getPlugin(@NotNull final String name)
void savePlugin(@NotNull final Plugin< G, A, R > plugin, @NotNull final File file)
Saves a plugin to a given file.
PluginModel(@NotNull final PluginParameterFactory< G, A, R > pluginParameterFactory, @NotNull final PluginModelParser< G, A, R > pluginModelParser)
Plugin< G, A, R > getPlugin(final int index)
void addPlugin(@NotNull final File file)
void firePluginCreatedEvent(@NotNull final Plugin< G, A, R > plugin)
Notify all listeners about an added plugin.
final PluginParameterFactory< G, A, R > pluginParameterFactory
void firePluginRegisteredEvent(@NotNull final Plugin< G, A, R > plugin)
Notifies all listeners about a registered plugin.
Factory for Plugin Parameters.
void firePluginDeletedEvent(@NotNull final Plugin< G, A, R > plugin)
Notifies all listeners about a removed plugin.
This document describes some hints and requirements for general development on the CrossfireEditor If you plan to make changes to the editor code or setup please read the following and keep it in derived from a basic editor application called Gridder by Pasi Ker�nen so please communicate with best through the cf devel mailing before considering any fundamental changes About code DO NOT USE TABS No matter what Java development platform you are please configure insert indent Tabs are displayed totally different in every editor and there are millions of different editors out there The insertion of tabs in the source code is messing up the syntax formatting in a way that is UNREPAIRABLE Apart from please keep code indentation accurate This is not just good it helps to keep code readable and in that way dramatically decreases the chance for overlooked bugs Everyone is welcomed to correct indentation errors wherever they are spotted Before you start to do this please double check that your editor is really configured to insert spaces Line feeds may be checked in either in windows or in unix linux style All reasonable text and java editors can deal with both linefeed formats Converting line feeds is but in this case please make sure that only linefeed characters are changed and nothing else is affected Due to the platform independent nature of the editor has the potential to run on almost any given operating system the build process differs greatly between systems as well as java environments In the several people have attempted to add build scripts along with structural changes to optimize the setup on one particular system environment which has led to conflict Please do *not *attempt to change the structure or any directories for the mere purpose of improving a build process or performance in a java environment Build scripts may be placed in the root it would be especially fine if it is just one or two files but the latter is not required Please excuse me for placing such restriction I and many users of the editor greatly appreciate build scripts We just had some real troubles over this issue in the past and I don t want to have them repeated the editor has relatively high performance requirements I ve spent a lot of extra work to keep everything as fast and memory efficient as possible when you add new data fields or calculations in the archetype please make sure they are as efficient as possible and worth both the time and space they consume Now don t be afraid too much No development would be possible without adding calculations and data at all Just bear in mind unlike for many other open source performance does make a difference for the CrossfireEditor The for as many systems as possible In case you are unexperienced with java and note that the graphics look different on every and with every font They also have different sizes proportions and behave different A seemingly trivial and effectless change can wreck havoc for the same GUI run on another system please don t be totally afraid of it