package cologne.eck.all_peas.gui;
import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.net.URL;
import javax.swing.ImageIcon;
public class CursorManager {
private static final Cursor DEFAULT_CURSOR =
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
private static Cursor waitCursor = null;
public static Cursor getWaitCursor(){
if (waitCursor == null) {
Image cursorImage = null;
try {
// get resource from jar
URL cursorUrl = CursorManager.class.getResource("/resources/wait_cursor.png");
// get image from resource
cursorImage = new ImageIcon(cursorUrl).getImage();
} catch (Exception e) {
// for PeaFactory
// get image from file
cursorImage = new ImageIcon("resources" + File.separator + "wait_cursor.png").getImage();
}
try{
// create cursor
waitCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
// this does not work:
// new Point((int)win.getLocation().getX(),(int) win.getLocation().getY()),
new Point(0,0),
"wait_cursor");
} catch (Exception e) {
System.out.println("CursorManager: "
+ e.toString() + ", " + e.getMessage()
+ "\nset default wait cursor");
// set predefined wait cursor instead
waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
}
}
return waitCursor;
}
/**
* @return the defaultCursor
*/
public static Cursor getDefaultCursor() {
return DEFAULT_CURSOR;
}
}