Geertjan's Blog

  • August 27, 2006

Capturing the Simpsons

Geertjan Wielenga
Product Manager
My first look at the NetBeans Visual Library 2.0 has been quite fun. Here's my personal little "Hello World" sample that I've been playing with and extending:

Whenever you move one of the Simpsons, the connected arrows move along as well. Without any programming on my part! And the drag and drop is completely provided by the library as well. So, here I've moved Homer to the left and, as you can see, the connected arrows have moved too:

The coding is pretty simple. You create an object called a "Scene", add a "LayerWidget", and then put in some "ImageWidgets" and "ConnectionWidgets". It is all very well described in the (work in progress) Visual Library 2.0 API Documentation. For example, here's what a "ConnectionWidget" looks like:

ConnectionWidget connection1 = new ConnectionWidget(scene);
connection1.setSourceAnchor(AnchorFactory.createCircularAnchor(bart, 32));
connection1.setTargetAnchor(AnchorFactory.createCircularAnchor(marge, 32));

Getting started means checking out nbbuild, openide/util, core/external, and graph, exactly as described in the Setup Building Environment document.

There are really LOTS of samples. Seemed like there were about 30 or so, covering all areas of this library. To make my module, I went a slightly roundabout route, that worked nonetheless. After checking out and building as instructed, I opened the graph module's lib folder as a project in the IDE, created an NBM file from it, opened the NBM file outside the IDE, extracted the JAR file, and then created a library wrapper for the JAR file, which I attached to a module suite project. Then I created a functionality module that accesses classes in the library wrapper, after creating a dependency on the library wrapper from within the functionality module. Then I looked for a nice sample (in the examples folder) and pasted it into an Action class that I had generated via the New Action wizard. And then I expanded that sample slightly and ended up with the result that you see above. I then installed the library wrapper module and then the functionality module and accessed the Action class from the menu. And, with that, I had created my first implementation of the Visual Library 2.0.

Postscript: Here's the same motley crew, but this time in a TopComponent integrated in the IDE:

Once I've worked out how to generate code from the above (i.e., depending on who I've dragged and their relative positions, generate appropriate Java code or XML tags), I will provide step by step instructions for how to do all of this.

Join the discussion

Comments ( 8 )
  • Ahmed Mohombe Sunday, August 27, 2006
    Hi Geertjan

    Very nice article :).
    I think however that there would be an improvement to it that would make everybody dead curious:

    - 0. describe the steps in your articles with "numbers" :). This is important to be able to easily follow it :)

    - 1. use from an exising struts based webapplication(there are many struts based projects on sourceforge), the struts-config.xml.

    - 2. read it "in" (with the struts API) or with the helper from the nebeans struts module. to have a graph model from it. The structure fits very simply.

    - 3. display that "model" as a diagram

    It must not be interactive, nor detailed, nor precise - just an example on a concrete theme - like Struts.

    I think it would be the ultimative article to convince everybody to give graph.netbens.org a try :).

    The netbens/struts team would be also more than happy I suppose :). Maybe this would convince them to implement such a page workflow feature in the plug-in (but in a complete manner of course).

    Well, this just an idea :),

  • Geertjan Monday, August 28, 2006
    Nice idea, Ahmed. Right now, I don't know how to read in an XML file and convert it to a graph model. Hoping to find out soon, though.
  • Ahmed Mohombe Monday, August 28, 2006
    Right now, I don't know how to read in an XML file and convert it to a graph model.

    JDOM, or XStream is your friend for reading an XML in any Model (XStream is better when you can control the XML - but you can for your example :) ).

    I don't know the NB graph model, but it should be similar to read in, once you know it. In the case of your example, you must not support every Struts feature from that struts-config.xml, only what looks spectacular: the actions (with names for nodes), forwards and redirects (for arrors), forms for "extra labels" on the arrows or nodes.

  • Geertjan Monday, August 28, 2006
    Here's the related mailing list for graph.netbeans.org:
  • Ahmed Mohombe Monday, August 28, 2006
    Here's the related mailing list for graph.netbeans.org: http://graph.netbeans.org/servlets/SummarizeList?listName=users

    Thank you.

    It doesn't seems to be mapped on Gmane however (many of the other NB lists are - and I'm using them). Would you mind adding it?


    A proper name would be "gmane.comp.java.netbeans.modules.graph"

    You are a NB team memeber so you can("are allowed") add it.

    Thanks in advance,

  • Matthew Cornell Monday, August 28, 2006
    Thanks for your article. There are a number of open source graph libraries already available, including JGraph and (my favorite) JUNG. How does the one you describe compare to them? For example, you may quickly find that a layout algorithm (which places nodes automatically) is crucial. Does the Netbeans one support this?
  • Geertjan Monday, August 28, 2006
    Hi Ahmed, I passed your suggestion on and it should be implemented soon.

    Hi Matthew, not sure about how to answer your questions -- best to join the mailing list and ask there (http://graph.netbeans.org/servlets/SummarizeList?listName=users). I've only being using this library since yesterday, so I don't know very much about it!

  • kaci cob Thursday, November 1, 2007

    you succccccccc

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