I'm working on some graph visualization using Prefuse, and I want to allow the use to select nodes in the graph by dragging a marquee. In addition, I want to show a tiny black square indicator at the top-left corner of a selected node. The image on the left is what I eventually got.
I wanted to use the Decorator design pattern provided by Prefuse to add the square indicators. Conceptually, the steps are:
- programatically selects a subset of the nodes in the graph
- applies the desired decoration on those subset of nodes
- creates a "focus group", of type "DefaultTupleSet", to the "visualization" object, using the method visualization.addFocusGroup(); you'll need to give this newly created group a name. This group (which is a "tuple set") is precisely the data structure that you use to store the selected nodes
- look at this example on how to create a control that lets you draw the rectangle marquee, which will put the selected nodes into the "focus group" that you created in step 1.
- now comes the nontrivial part -- creating the "decorators", which are objects created to decorate the selected nodes. Programmatically, you call visualization.addDecorators() to create this new group of decorators. Again, you give this decorator group a name.
- creates a layout action to continously relocate the indicator so that it always stay at the top-left of the node
- creates a renderer to render the tiny square. I think we can use a ShapeRenderer instead so this step could be skipped.