Open-Source tool in Java to draw UML Diagram
Have a break with Sukaza
If a Java version of GraphViz/DOT would exist, this would allow to greatly simplify the installation and the use of PlantUML.
Unfortunatly, this does not exist today...
So what about porting GraphViz/DOT to Java ? As GraphViz/DOT is written in C, and as Java syntax is close to C syntax, it is possible to translate the C source of GraphViz to Java source, although this is a large and complex task.
The good news is that we don't need to translate the whole GraphViz sources to Java : this is due to the fact that PlantUML uses only a limited portion of GraphViz. Firstly, only DOT algorithm is used (neato, ... and other are not used). Secondly, the parsing of the DOT language is not need : PlantUML could directly build the diagram in memory without generating DOT language. And thirdly all the drawing code of GraphViz is not needed anymore, since the drawing is done in Java
This translation of DOT to Java is a new project called JDot. This project will not depend on PlantUML : classes will be completely independent of PlantUML and other open source Java projects would be able to use it, if they wish.
The first step is to have a minimal version that compiles and runs.
Some Junit tests have also been written to check that the basic classes and converted C code are working.
You can checkout two projects:
| Project name | Description | URL |
| prejdot | Java project that runs the C preprocessor and generates HTML sources | https://svn.code.sf.net/p/jdot/code/trunk/prejdot/ |
| JDot | The converted version of DOT to Java | https://svn.code.sf.net/p/jdot/code/trunk/jdot/ |
You also have to download graphviz-2.28.0 sources
and put them in the graphviz-2.28.0
directory of prejdot.
Special credit for those two projects that are very usefull for converting C to Java:
import lib.graph.Graph_h.Agraph_t;
import static core.Utils.ARG;
import static core.Utils.asStarChar;
import static lib.graph.Graph.agopen;
import static lib.graph.Graph_h.AGDIGRAPH;
import static lib.graph.Graph_h.aginit;
import static lib.graph.Node.agnode;
public class Main1 {
/**
* Create a empty graph
* @param args
*/
public static void main(String[] args) {
// C version
//
// Agraph_t* G = agopen(name, type);
//
// Java version
Agraph_t G = agopen("name", AGDIGRAPH) ;
Agnode_t n1 = agnode(G, ARG(asStarChar("a")));
Agnode_t n2 = agnode(G, ARG(asStarChar("b")));
}
}
C code and Java code are displayed side by side, to facilitate comparaison and reviews.
First, if you find errors in the conversion or in the methodology, you are welcome to react.
Before going further, we have to write some JUnit tests to validate that
graph creation is working fine.
Then we will have to add an edge to this graph.
And then to run the layout.