User Tools

Site Tools


gmtoolcoding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

gmtoolcoding [2012/09/24 17:49]
irian created
gmtoolcoding [2012/09/29 23:40] (current)
irian
Line 2: Line 2:
 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. 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.
  
-...+===== Basics ===== 
 +Your plugin should be a JComponent, as it needs to be displayed inside a Swing JFrameBesides that, you can use whatever you want. 
 + 
 +===== Interface "Plugin" ===== 
 +To tell the GMTool, that your class is a Plugin, you must implement this interfaceIt 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: 
 + 
 +<code>void setResourceProvider(ResourceProvider provider);</code> 
 + 
 +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: 
 + 
 +<code>Resource getResource(Component comp, String type, Set<String> allowedSuffixes);</code> 
 + 
 +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. 
 + 
 +<code>List<Resource> getResources(Component parent, String type, Set<String> allowedSuffixes);</code> 
 + 
 +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: 
 + 
 +<code>List<Resource> getResources();</code> 
 +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). 
 + 
 +<code>void setScenario(Scenario scen);</code> 
 +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: 
 + 
 +<code>List<Resource> getResources(String ofType);</code> 
 +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. 
 + 
 +<code>void clearScenario();</code> 
 +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. 
 + 
 +<code>JComponent getToolBarElement();</code>
gmtoolcoding.1348501798.txt.gz · Last modified: 2012/09/24 17:49 by irian