KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > Cursor


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: Cursor.java,v $
11    Revision 1.7 2004/05/06 12:35:21 bobintetley
12    Parity with Swing constants for Binary Compatibility + fixes to JDesktopPane
13
14    Revision 1.6 2004/04/16 10:19:06 dannaab
15    Misc bug fixes, InputMap implementation, preliminary undo support
16
17    Revision 1.5 2004/01/16 09:35:46 bobintetley
18    Full event dispatch thread support!
19
20    Revision 1.4 2003/12/14 09:13:38 bobintetley
21    Added CVS log to source headers
22
23 */

24
25
26 package swingwt.awt;
27
28 import org.eclipse.swt.*;
29
30 import swingwtx.swing.*;
31
32 public class Cursor {
33     
34     protected org.eclipse.swt.graphics.Cursor cursor = null;
35     
36     public static final int DEFAULT_CURSOR = 0;
37     public static final int CROSSHAIR_CURSOR = 1;
38     public static final int TEXT_CURSOR = 2;
39     public static final int WAIT_CURSOR = 3;
40     public static final int SW_RESIZE_CURSOR = 4;
41     public static final int SE_RESIZE_CURSOR = 5;
42     public static final int NW_RESIZE_CURSOR = 6;
43     public static final int NE_RESIZE_CURSOR = 7;
44     public static final int N_RESIZE_CURSOR = 8;
45     public static final int S_RESIZE_CURSOR = 9;
46     public static final int W_RESIZE_CURSOR = 10;
47     public static final int E_RESIZE_CURSOR = 11;
48     public static final int HAND_CURSOR = 12;
49     public static final int MOVE_CURSOR = 13;
50     
51     private static Cursor pre_default = null;
52     private static Cursor pre_crosshair = null;
53     private static Cursor pre_text = null;
54     private static Cursor pre_wait = null;
55     private static Cursor pre_sw = null;
56     private static Cursor pre_se = null;
57     private static Cursor pre_nw = null;
58     private static Cursor pre_ne = null;
59     private static Cursor pre_n = null;
60     private static Cursor pre_s = null;
61     private static Cursor pre_w = null;
62     private static Cursor pre_e = null;
63     private static Cursor pre_hand = null;
64     private static Cursor pre_move = null;
65     
66     private static Object JavaDoc retval = null;
67     private static org.eclipse.swt.graphics.Cursor createSWTCursor(final int type) {
68         SwingUtilities.invokeSync(new Runnable JavaDoc() {
69             public void run() {
70                 retval = new org.eclipse.swt.graphics.Cursor(SwingWTUtils.getDisplay(), type);
71             }
72         });
73         return (org.eclipse.swt.graphics.Cursor) retval;
74     }
75     
76     private static void generatePredefinedCursors() {
77         pre_default = new Cursor(createSWTCursor(SWT.CURSOR_ARROW));
78         pre_crosshair = new Cursor(createSWTCursor(SWT.CURSOR_CROSS));
79         pre_text = new Cursor(createSWTCursor(SWT.CURSOR_IBEAM));
80         pre_wait = new Cursor(createSWTCursor(SWT.CURSOR_WAIT));
81         pre_sw = new Cursor(createSWTCursor(SWT.CURSOR_SIZESW));
82         pre_se = new Cursor(createSWTCursor(SWT.CURSOR_SIZESE));
83         pre_nw = new Cursor(createSWTCursor(SWT.CURSOR_SIZENW));
84         pre_ne = new Cursor(createSWTCursor(SWT.CURSOR_SIZENE));
85         pre_n = new Cursor(createSWTCursor(SWT.CURSOR_SIZEN));
86         pre_s = new Cursor(createSWTCursor(SWT.CURSOR_SIZES));
87         pre_w = new Cursor(createSWTCursor(SWT.CURSOR_SIZEW));
88         pre_e = new Cursor(createSWTCursor(SWT.CURSOR_SIZEE));
89         pre_hand = new Cursor(createSWTCursor(SWT.CURSOR_HAND));
90         pre_move = new Cursor(createSWTCursor(SWT.CURSOR_SIZEALL));
91     }
92     
93     public Cursor(org.eclipse.swt.graphics.Cursor swtCursor) {
94         this.cursor = swtCursor;
95     }
96     
97     public Cursor(int type) {
98         this(Cursor.getPredefinedCursor(type).getSWTCursor());
99     }
100     
101     public static Cursor getPredefinedCursor(int type) {
102         if (pre_default == null) generatePredefinedCursors();
103         Cursor retCursor = null;
104         switch(type) {
105             case(DEFAULT_CURSOR): retCursor = pre_default; break;
106             case(CROSSHAIR_CURSOR): retCursor = pre_crosshair; break;
107             case(TEXT_CURSOR): retCursor = pre_text; break;
108             case(WAIT_CURSOR): retCursor = pre_wait; break;
109             case(SW_RESIZE_CURSOR): retCursor = pre_sw; break;
110             case(SE_RESIZE_CURSOR): retCursor = pre_se; break;
111             case(NW_RESIZE_CURSOR): retCursor = pre_nw; break;
112             case(NE_RESIZE_CURSOR): retCursor = pre_ne; break;
113             case(N_RESIZE_CURSOR): retCursor = pre_n; break;
114             case(S_RESIZE_CURSOR): retCursor = pre_s; break;
115             case(E_RESIZE_CURSOR): retCursor = pre_e; break;
116             case(W_RESIZE_CURSOR): retCursor = pre_w; break;
117             case(HAND_CURSOR): retCursor = pre_hand; break;
118             //case(MOVE_CURSOR): retCursor = pre_move; break; // -- Same as Resize All
119
}
120         return retCursor;
121     }
122
123     public static Cursor getDefaultCursor() {
124         return getPredefinedCursor(DEFAULT_CURSOR);
125     }
126     
127     public org.eclipse.swt.graphics.Cursor getSWTCursor() { return cursor; }
128     
129     /** FIXME: Genuine constants. Does anyone use these??? */
130     public int getType() {
131         return DEFAULT_CURSOR;
132     }
133     
134     /** FIXME: Real names - again I ask, does anyone use this??? */
135     public String JavaDoc getName() {
136         return "Default Cursor";
137     }
138     
139     public void dispose() {
140         cursor.dispose();
141     }
142    
143     protected void finalize() throws Throwable JavaDoc {
144         dispose();
145     }
146 }
147
Popular Tags