FloodGrapher was made with the idea in mind that many robot authors could use it to make useful graphing tools for their own robots. I'd also simply ask other robocoders to write modules to use data files from their robots, both as a way of "giving back" to the Robocode community and as an excercise in the part of Java that most Robocoders don't see - writing user interface software using Swing.
The first thing you should do to write a FileFormat plugin for FloodGrapher is to evaluate the data colleced by your robot to see if it is appropriate. Here are a some things that should probably be true for you to pursue this:
For each segmentation axis your robot has, you will probably need a seperate GrapherSegmentation object. Note, however, that some of these may have already been written, or one may have been written that requires only slight modification for you to use it. These should implement the interface GrapherSegmentation. GrapherSegmentation has three methods:
public String getName(); public void addSelectionWidget(GraphControlWindow window); public boolean accept(int index);
The getName() method is primarily for labeling purposes. The first major thing you have to do is addSelectionWidget(), which is where you write the UI for this segmentation.
You should also keep a reference to the components that the user will be using for input for this segmentation, and you should only ever have one set of GUI components per GrapherSegmentation object. The grapher should only call this method once on each object, but if it were to call it again, you should add the same components again. Let's look at an example implementation, taken from class kawigi.tools.AccelerationGSegmentation:
First, I create a JPanel to put my UI on:
JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(new JLabel("Accl:"));
Now, if I haven't already created a selection widget, I do here, using a JComboBox (selectBox has been declared as a member variable):
if (selectBox == null) { selectBox = new JComboBox(); selectBox.addItem("All Segments"); selectBox.addItem("Accelerating"); selectBox.addItem("Decelerating"); selectBox.addItem("Constant"); selectBox.addItem("Accl or Const"); selectBox.addItem("Decl or Const"); selectBox.addItem("Decl or Accl"); }
I want the graph to update when the value of the Select box is changed, so I add the GraphControlWindow as a listener to it. Then I add the JComboBox to the JPanel, and the JPanel to the window.
selectBox.addItemListener(window); panel.add(selectBox); window.getContentPane().add(panel);
For more elaborate examples of setting up the GUI, you can look at the other packaged GrapherSegmentation implementations.
The last method is accept, which is where you "read" what your GUI components say and return true if the given index should be shown. Going back to the example of AccelerationGSegmentation:
public boolean accept(int index) { if (selectBox.getSelectedItem().equals("All Segments")) return true; if (index == 0) return ((String)selectBox.getSelectedItem()).indexOf("Const") >= 0; if (index == 1) return ((String)selectBox.getSelectedItem()).indexOf("Acc") >= 0; if (index == 2) return ((String)selectBox.getSelectedItem()).indexOf("Dec") >= 0; //shouldn't reach here: return false; }
Note that in this case, I can just look at the strings of the segments selected. In this segmentation, 0 means "roughly constant speed," 1 means "accelerating" and 2 means "decelerating."
Once you have all your GrapherSegmentations implemented, you can write your FileFormat class. This interface has two methods:
public SegmentedData getData(File datafile) throws IOException, InvalidFileException; public String getFormatName();
The format name should just be the "friendly" name of this format, for instance, "FloodMini 1.4 Format". getDataa() should create a new SegmentedData object. The main features of this object is that it has requires an object called "stats", which should be a multi-dimensional non-jagged array of doubles. It should also have a Scheme, which is basically an aggregation of all the GrapherSegmentation implementations you should have already written. Basically, read your stats from the given file, convert it into a multi-dimensional array of doubles. Create a Scheme object, and call add() on the scheme for each segmentation axis you use, in order.
Once you have this written, you should be able to configure it into the FloodGrapher utility on the PluginManager panel. Just hit the "add" button under the list of File Formats and type in the FloodScript expression that creates your object. If your class has a constructor with no parameters, this should just be the full name of the class (<package>.<class name>). Otherwise, you will need to see how to call constructors with parameters on the FloodScript help page.