JTikZ
A Java AWT/Swing Graphics drop-in replacement that renders to the TikZ/PGF (LA)TEX language.

Motivation

People often write simulations in Java, usually including some visualizations.  It is often desirable to use some of these visualizations as figures in papers.  Using screenshots is obviously not desirable since that would produce a raster image when the original was vector.

JTikZ solves this problem by providing a new class, TikzGraphics2D that extends off of java.awt.Graphics2D. This class can be passed to any component's paint() function and will output human readable TikZ/PGF code that can be cut/pasted into a document.

Example

Java Code

TikZ Output

public void paint(Graphics g) {
    g.drawOval(3, 10, 5, 30);
    g.setColor(Color.RED);
    g.drawLine(1, 2, 3, 4);
    g.setColor(Color.BLUE);
    g.drawString("This is a test!", 3, 10);
    g.setColor(new Color(128, 128, 255, 128));
    g.fillArc(5, 11, 30, 30, 120, 90);
}
\definecolor{color0}{rgb}{1.0,0.0,0.0}
\definecolor{color1}{rgb}{0.0,0.0,1.0}
\definecolor{color2}{rgb}{0.5,0.5,1.0}
\begin{tikzpicture}[yscale=-1]
  \draw (5.5pt, 25.0pt) ellipse (2.5pt and 15.0pt);
  \draw[color0] (1pt, 2pt) -- (3pt, 4pt);
  \node[anchor=south west,text=color1] at (3.0pt, 10.0pt) {This
is a test!};
  \fill[color2,opacity=0.5] (20.0pt, 26.0pt) -- (12.5pt, 13.0pt)
arc (-120:-210:15.0pt and 15.0pt) -- cycle;
\end{tikzpicture}

Current Status & Installation

JTikZ currently supports  lines, shapes/polygons, ellipses, colors, alpha, arcs, curves/splines, and text.

You can download and compile the code as follows:

$ svn co https://jtikz.svn.sourceforge.net/svnroot/jtikz jtikz
$ cd tikz
$ ant jar
$ java -jar lib/example.jar

Support

JTikZ was originally developed and is currently maintained by Evan Sultanik. Bug reports and feature requests can be submitted here. If you would like to contribute to the project, please feel free to contact Evan.



This project is generously hosted by SourceForge:

SourceForge.net Logo