JGraph X is the next generation of Java Swing Diagramming Library, factoring in 7 years of architectural improvements into a clean, concise design...
See the rest of the quote in jgraphx homepage
This is an example on using jgraphx as a plugin to the biocep workbench, we are just going to integrate the hello world example from jgraphx as a view of the workbench. I am hoping people will find this useful and more ideas will come later. Here is a screenshot:
As you might guess from the screenshot, this is not really useful and does not do anything apart from being able to move things around. jgraphx has more examples, and apparently you can use any swing component as a renderer to a graph vertex, so there is no limit to what can be achieved ...
The project looks like this:
. |-- build.properties |-- build.xml |-- descriptor.xml |-- lib | |-- dt.jar | |-- jaxx-runtime.jar | |-- jaxx-swing.jar | |-- jaxxc.jar | `-- jgraphx.jar `-- src `-- com `-- addictedtor `-- workbench `-- plugin `-- jgraphx `-- HelloWorld.java 7 directories, 9 files
and the build.*
files looks pretty much the same as in this previous tutorial, except this time we won't use jaxx for the user interface because the swing is not a pain when it comes to hello world. The HelloWorld.java
file looks like this:
1 package com.addictedtor.workbench.plugin.jgraphx ; 2 3 import com.mxgraph.swing.mxGraphComponent; 4 import com.mxgraph.view.mxGraph; 5 6 import org.kchine.r.workbench.RGui; 7 import java.awt.BorderLayout ; 8 import javax.swing.JPanel ; 9 10 public class HelloWorld extends JPanel { 11 12 private RGui rgui ; 13 14 public HelloWorld(RGui rgui){ 15 super( new BorderLayout() ) ; 16 this.rgui = rgui ; 17 18 mxGraph graph = new mxGraph(); 19 Object parent = graph.getDefaultParent(); 20 21 graph.getModel().beginUpdate(); 22 try { 23 Object v1 = graph.insertVertex(parent, null, "Hello", 24 20, 20, 80, 30); 25 Object v2 = graph.insertVertex(parent, null, "World!", 26 240, 150, 80, 30); 27 graph.insertEdge(parent, null, "Edge", v1, v2); 28 } finally { 29 graph.getModel().endUpdate(); 30 } 31 32 add(new mxGraphComponent(graph), BorderLayout.CENTER ); 33 } 34 35 }
Here is the source of the plugin and a zip you can deploy in your RWorkbench
directory to start dragging around.