Open-Source tool in Java to draw UML Diagram

The context

PlantUML is using GraphViz/DOT to compute node positionning for every UML diagrams (except Sequence Diagram). The fact that DOT computes automatically the position of node is a key feature, and algorithms implemented in DOT usually give very good result. However, there are some drawbacks of using DOT : the computation is done by an external program (dot.exe on Windows, dot on linux), and that means that : Another way of using DOT would be to use it as a library, and to link it with PlantUML using JNI (Java Native Interface) but that would not be perfect thought.

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 project

You will find here some information about how to translate C to Java.

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
JDot The converted version of DOT to Java

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")));

As you can see, this is really minimal. To do so, the following translation have been done.

C code and Java code are displayed side by side, to facilitate comparaison and reviews.

Package H files C files

Next steps

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.

Support This ProjectOffer 250 Mo!Follow PlantUML on TwitterPlantUML on Google Reader