Sunday, September 26, 2010

blog abandoned

I abandon this blog in favor of this one!
Well... actually this one: this one!

Monday, May 26, 2008

YourSQL and "no document could be created"

After using the smart little mysql browser YourSQL for one year on my mac, suddenly i could'nt start it any more. It gave me a "no document could be created" error.

Digging a bit gave me hints like the one descriped here (get the right compiled version for intel macs). But since it worked for me already, this couldn't and wasn't be the solution...

The problem was...
Java 6.
I recently made it my default java version.
Switching back to java 5 solved the problem and YourSQL worked fine again!

Tuesday, May 6, 2008

Fastest way to copy files

This uses nio and delegates the work to the underlying os. So this should be the fastest way...

 public static void copy(File srcFile, File destFilethrows IOException {
        FileChannel srcChannel = null;
        FileChannel destChannel = null;
        try {
            srcChannel = new FileInputStream(srcFile).getChannel();
            destChannel = new FileOutputStream(destFile).getChannel();
            long size = srcChannel.size();
            destChannel.transferFrom(srcChannel, 0, size);
        finally {
            if (srcChannel != null)
                srcChannel.close();
            if (destChannel != null)
                destChannel.close();
        }
    }

Tuesday, November 6, 2007

move the swing-ing mouse

Yesterday i came across the problem of moving the mouse pointer programatically from within a java swing programm. It was not hard to find how to move the mouse with the Robot class.

new Robot().mouseMove(x, y);

But moving it that way is relative to the screen display and not to the focused awt component. The solution ? Very easy, you just have to know the right utility class ;)

Here's a complete little class:

import java.awt.AWTException;
import java.awt.Component;
import java.awt.Point;
import java.awt.Robot;
import javax.swing.SwingUtilities;

public class MouseMove {
    private Robot _robot;

    public MouseMove() {
        try {
            _robot = new Robot();
        catch (AWTException e) {
            throw new RuntimeException(e);
        }
    }

    public void moveMouse(Point pointOnComponent, Component component) {
        Point pointOnScreen = (PointpointOnComponent.clone();
        SwingUtilities.convertPointToScreen(pointOnScreen, component);
        _robot.mouseMove(pointOnScreen.x, pointOnScreen.y);
    }
}