Download this file

CursorManager.java    60 lines (49 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
}