Latest change: Mon May 17 16:53:53 CEST 2010

Clipping Class for Java

This is a quick&dirty page which I hacked together to give people access to a Java class I wrote which implements clipping of lines to a given rectangle.

It is mainly thought as a workaround for Java Bug ID 4252578.

4252578 was introduced in Java 1.2 and results in a deadlock of the JVM when drawing lines which ending points are far outside the drawing area of a memory image. The VM just eats all of your processor time without anything happening. My customers didn't like that all too much so I implemented the workaround you can find here.

The workaround just implements the necessary clipping itself. This is also helpful for situations where Java does not hang but draws completely wrong lines when the ending points are far outside the drawing area (as it does in all versions).

For my usage (drawing several thousand lines per repaint) I did not observe a noticeable performance penalty. Indeed drawing seems to go faster when I've zoomed deep into my image because most lines are not drawn any longer.

The clipping class does only handle zero width lines and polylines, you'll have to do mork work if you need something else.

This is freeware, provided as is. Use it as you like. No guarantees are given. Use at your own risk!

There are two files, Clipping.java and ClipTest.java. You will only need the first one (16298 Bytes), the second one (4271 Bytes) is thought as an example. The first one runs with Java 1.1, the second one needs Swing. See the comments in the files for more info.

Have fun!

Rammi