Q’n’D Java Tool

I just wrote a quick and dirty Java/Swing tool. It loads and autodetects DVW sprites from a texture file and allows to reorganize them. This is useful for stupid programmers like me who don’t want to mess around with mspaint.exe or The GIMP but feel the urge to move sprites around for whatever reason. I am planning some improvements like a textual export of the rectangle coordinates and a cool algorithm to align the sprites automatically including batch processing, but for now, manual moving of the sprites is exactly what I wanted.

The autodetection is done using a simple floodfill approach which proved to be sufficient for my test texture. I might find other textures where this approach isn’t enough, therefore I will provide means to apply a dilatation operation on an image and to merge detected rectangles.

A little tool I wrote

While I wrote this tool, I recognized a little problem in the AWT drag and drop framework, java.awt.dnd.DropTargetListener in particular. I used DropTargetListener#dragOver(DropTargetDragEvent) to listen for dragging but found that there was no (direct) way to find out which object was actually dragged (those objects implement java.awt.datatransfer.Transferable).

I was not the first one who stumbled over this, like the entries in Suns bug database showed, and fortunately one suggestion from this page worked for me:

DropTargetDropEvent tempDTDropEvent = new DropTargetDropEvent( dtde.getDropTargetContext(), dtde.getLocation(), 0, 0 );
Transferable dragData = tempDTDropEvent.getTransferable();
MyTransferable trans = (MyTransferable) dragData.getTransferData( MyTransferable.DATA_FLAVOR );

This issue was fixed in Tiger where an appropriate getter for Transferable was added.

Next Article

Game Objects