Java - SWT Diagrams

Back to: Gabor Cselle Homepage > Writings

com.gaborcselle.swt.Diagram

Gabor Cselle (mail at gaborcselle dot com) and Erol Koç, August 10, 2005

This is is a diagramming class for SWT and Java 1.5. It produces simple diagrams such as the one below. Also, it resizes nicely when the object containing it is resized.


This illustration explains all the parameters you can set and objects you can draw:

Javadoc

The Javadoc contains a more information about the class:

Source Code Download

All source code can be found here:

The example from the screenshot above is also contained in the download: it's the class com.gaborcselle.swt.DiagramTest. To run it in Eclipse, make sure the SWT jars (org.eclipse.swt_3.X.X.jar and org.eclipse.swt.<PLATFORM>_3.X.X.jar) are included in 'Project > Properties > Build Path / Libraries'. Then launch the application by right-clicking on DiagramTest in the Package Explorer and choosing 'Run As > SWT Application'.

How to Extend It

Feel free to expand the class with any more objects you need to draw onto the diagram. To do this, create a new ContentX() inner class that extends ContentObject and stores information about the object. Then, create a paintX() method to paint the object onto the GC. Add the new class you created into paintObjects() so it gets painted when a PaintEvent occurs. Finally, create a drawX() method for the user to call.

License

Creative Commons License
Java Persistent Queue by Gabor Cselle is licensed under a Creative Commons Attribution 3.0 Unported License.

Questions? Comments? Found an Error?

Contact the authors at mail at gaborcselle dot com.