X

Geertjan's Blog

  • January 29, 2011

Interactive Data Visualization/Analysis Tool Migration to the NetBeans Platform

Geertjan Wielenga
Product Manager
NDVis is a free tool for neuroscientists. It provides an interactive data visualization and analysis tool for large multidimensional databases:

NDVis is currently used in neuroscience classes at Emory University and in ongoing research projects at Brandeis University and abroad.

I've been in touch with its main developer, John Langton from VisiTrend, who is interested in moving some of his tools to the NetBeans Platform. From my side, the easiest one to get started with was NDVis, since it is available in the open source.

I've taken the first steps, ending up with this GUI:

The remaining step, which could be quite complex, involves integrating the Database Explorer from the NetBeans Platform into the tool, the first steps of which have already been taken, as you can see above. The advantages will be many, e.g., all the tools are visible in the UI (instead of accessible via small dialogs, as is the case in the original) and almost all the db-related code in the original can, ultimately, simply be deleted, since the Database Explorer from NetBeans IDE can be reused, as seen above. Plus, the end users will have an SQL Editor, in addition to the visualization tool, which can't be a bad thing either.

Getting to the above application from scratch is fairly trivial:

  1. Create a new "Module Suite" application, since you need several NetBeans IDE modules, e.g., the Database Explorer and built-in MYSQL support.

  2. Create a module called "NDVisCore" and copy all the packages from the original application into that module. In this first stage of porting, we'll simply have everything from the original inside this one module. Once everything is working as before, we'll start splitting code out to other modules.

  3. Create a library wrapper module for the "javasim.jar" in the sources of the original application and set a dependency on it from NDVisCore.

  4. Create a new module named "NDVisBranding", make sure to include a layer.xml file, and use it to hide as much of the menu items and toolbar buttons that you don't need.

  5. In "NDVisCore", set dependencies on Window System API, Lookup API, Utilities API, UI Utilities API, and an implementation dependency on Database Explorer (since we'll need an implementation class from this package, to get to the node we need in the Database Explorer).

  6. Change the class signature of the "NDVis" JFrame to the following:
    @TopComponent.Registration(mode="editor",openAtStartup=true)
    @TopComponent.Description(preferredID="NDVis")
    public class NDVis extends TopComponent implements ChangeListener {

    Now you'll need to tweak the code very slightly, e.g., remove "pack()", since you're using a TopComponent rather than a JFrame. Do the same at the end of the next step.

  7. Change the class signature of the "ColorMapper" JFrame to the following:
    @TopComponent.Registration(mode = "output", openAtStartup = true)
    @TopComponent.Description(preferredID = "ColorMapper")
    public class ColorMapper extends TopComponent implements MapColorListener,
    MonitoringINF {
  8. Annotate the "AddNewImageAction" as follows:
    @ActionID(category="NDVisActions",id="com.visitrend.ndvis.actions.AddNewImageAction")
    @ActionRegistration(displayName="Add New Image")
    @ActionReference(path="Menu/File")
    public class AddNewImageAction extends AbstractAction {
  9. Annotate the "OpenQueryAction" as follows:
    @ActionID(category="NDVisActions",id="com.visitrend.ndvis.acolormapper.actions.OpenQueryAction")
    @ActionRegistration(displayName="Open Query")
    @ActionReference(path="Menu/File")
    public class OpenQueryAction extends AbstractAction {
  10. Both the Actions above are, interestingly enough, "conditional actions" in terms of the NetBeans Platform, e.g., the "OpenQueryAction" is defined like this:
    public class OpenQueryAction extends AbstractAction {
    private ColorMapper colmap;
    public OpenQueryAction(ColorMapper colmap) {
    super("Open Query");
    this.colmap = colmap;
    }
    ...
    ...
    ...

    So, in the constructor of the "ColorMapper" class, you need to put the ColorMapper into its own Lookup:

    associateLookup(Lookups.singleton(this));

    That will enable the "OpenQueryAction", which needs a "ColorMapper" in the Lookup in order to become enabled. A similar piece of code is needed in the "NDVis" class, to enable the "Add New Image" action.

Now I'm figuring out how to hook the database connection into the correct part of the code to allow the color analyzer to be run correctly, using the queries created in the Color Mapper. Then the final step will be to put the various Actions into the main menubar of the application.

The nice thing about the new annotation-based registration techniques is how it allows you to change very little of the original classes in order to integrate them into the NetBeans Platform. Just annotate a few classes, hook the Lookup code into the correct places, enable the modules you need, hide items you don't need via the layer, and then you're mostly done.

Join the discussion

Comments ( 2 )
  • Jaroslav Tulach Wednesday, February 2, 2011

    I have to say the @annotations seem to be even more handy than I expected. I am amazed that the originally existing action already was "context sensitive" and that you can achieve all of this with a bunch of annotations and single line change.


  • Geertjan Wielenga Wednesday, February 2, 2011

    Yup, you're better than you think. :-)


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.