User Tools

Site Tools


GMTool - How to code for it

One of the basic premises for the gmtool was to allow the easy creation of plugins. You still need to code in Java for that, but at least there are many things done automatically (like loading and storing files) that you don't have to care about.


Your plugin should be a JComponent, as it needs to be displayed inside a Swing JFrame. Besides that, you can use whatever you want.

Interface "Plugin"

To tell the GMTool, that your class is a Plugin, you must implement this interface. It has no methods, so your work is done with “implements Plugin”.

Interface "ResourceUser"

If you want to add resources (files), you simply implements the ResourceUser interface. There is only one method:

void setResourceProvider(ResourceProvider provider);

This method will be called by the GMTool after your plugin's constructor was called. It provides you with a ResourceProvider, which you can then use to request Resources, by calling on of these methods:

Resource getResource(Component comp, String type, Set<String> allowedSuffixes);

This method request a single resource of type “type” (you can define the type as you want, it's only used in the scenario) and a set of allowed file suffixes (without the ”.”, for example “xml”). Calling this method will open a file chooser dialog for the user.

List<Resource> getResources(Component parent, String type, Set<String> allowedSuffixes);

The same method, just for more than one resource at a time.

Interface "ScenarioUser"

If you want your data to be saved into the scenario (and loaded with it), implement this interface. There are three methods to implement:

List<Resource> getResources();

This method will be called whenever a scenario is saved. Simply return any resource that should be part of the current scenario (in other words, every resource that should be loaded with the scenario).

void setScenario(Scenario scen);

This method will be called after your plugin's constructor and every time a scenario is loaded. The scenario offers one method, which can be used to get a list of resources:

List<Resource> getResources(String ofType);

Here the type comes into the game again: By giving the same type as before, you can retrieve “your” resources from the scenario to display them properly.

void clearScenario();

This method will be called whenever the scenario is closed and should reset your plugin to the default state.

Interface "ToolbarElementProvider"

Implement this interface if you want to add an element to the toolbar below the plugins (for example, the sound player uses this to provide quick play/stop buttons in the toolbar, so that the user doesn't have to switch to the plugin itself to start the currently selected song or stop the one currently playing).

There is one method to implement, which should simply return the object you want to have added to the toolbar. Personally, I use a JPanel with a titled border (with a line border, 1px, black) for these elements, but that's not a rule.

JComponent getToolBarElement();
gmtoolcoding.txt · Last modified: 2012/09/29 23:40 by irian