1 |
/* Cursor.java -- Mouse pointer class |
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation |
|
Copyright (C) 1999 Free Software Foundation, Inc. |
|
2 |
|
|
3 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
4 |
|
|
33 |
*/ |
*/ |
34 |
public class Cursor implements java.io.Serializable |
public class Cursor implements java.io.Serializable |
35 |
{ |
{ |
36 |
|
/** |
|
/* |
|
|
* Static Variables |
|
|
*/ |
|
|
|
|
|
/** |
|
37 |
* Constant for the system default cursor type |
* Constant for the system default cursor type |
38 |
*/ |
*/ |
39 |
public static final int DEFAULT_CURSOR = 0; |
public static final int DEFAULT_CURSOR = 0; |
40 |
|
|
41 |
/** |
/** |
42 |
* Constant for a cross-hair cursor. |
* Constant for a cross-hair cursor. |
43 |
*/ |
*/ |
44 |
public static final int CROSSHAIR_CURSOR = 1; |
public static final int CROSSHAIR_CURSOR = 1; |
45 |
|
|
46 |
/** |
/** |
47 |
* Constant for a cursor over a text field. |
* Constant for a cursor over a text field. |
48 |
*/ |
*/ |
49 |
public static final int TEXT_CURSOR = 2; |
public static final int TEXT_CURSOR = 2; |
50 |
|
|
51 |
/** |
/** |
52 |
* Constant for a cursor to display while waiting for an action to complete. |
* Constant for a cursor to display while waiting for an action to complete. |
53 |
*/ |
*/ |
54 |
public static final int WAIT_CURSOR = 3; |
public static final int WAIT_CURSOR = 3; |
55 |
|
|
56 |
/** |
/** |
57 |
* Cursor used over SW corner of window decorations. |
* Cursor used over SW corner of window decorations. |
58 |
*/ |
*/ |
59 |
public static final int SW_RESIZE_CURSOR = 4; |
public static final int SW_RESIZE_CURSOR = 4; |
60 |
|
|
61 |
/** |
/** |
62 |
* Cursor used over SE corner of window decorations. |
* Cursor used over SE corner of window decorations. |
63 |
*/ |
*/ |
64 |
public static final int SE_RESIZE_CURSOR = 5; |
public static final int SE_RESIZE_CURSOR = 5; |
65 |
|
|
66 |
/** |
/** |
67 |
* Cursor used over NW corner of window decorations. |
* Cursor used over NW corner of window decorations. |
68 |
*/ |
*/ |
69 |
public static final int NW_RESIZE_CURSOR = 6; |
public static final int NW_RESIZE_CURSOR = 6; |
70 |
|
|
71 |
/** |
/** |
72 |
* Cursor used over NE corner of window decorations. |
* Cursor used over NE corner of window decorations. |
73 |
*/ |
*/ |
74 |
public static final int NE_RESIZE_CURSOR = 7; |
public static final int NE_RESIZE_CURSOR = 7; |
75 |
|
|
76 |
/** |
/** |
77 |
* Cursor used over N edge of window decorations. |
* Cursor used over N edge of window decorations. |
78 |
*/ |
*/ |
79 |
public static final int N_RESIZE_CURSOR = 8; |
public static final int N_RESIZE_CURSOR = 8; |
80 |
|
|
81 |
/** |
/** |
82 |
* Cursor used over S edge of window decorations. |
* Cursor used over S edge of window decorations. |
83 |
*/ |
*/ |
84 |
public static final int S_RESIZE_CURSOR = 9; |
public static final int S_RESIZE_CURSOR = 9; |
85 |
|
|
86 |
/** |
/** |
87 |
* Cursor used over E edge of window decorations. |
* Cursor used over W edge of window decorations. |
88 |
*/ |
*/ |
89 |
public static final int E_RESIZE_CURSOR = 10; |
public static final int W_RESIZE_CURSOR = 10; |
90 |
|
|
91 |
/** |
/** |
92 |
* Cursor used over W edge of window decorations. |
* Cursor used over E edge of window decorations. |
93 |
*/ |
*/ |
94 |
public static final int W_RESIZE_CURSOR = 11; |
public static final int E_RESIZE_CURSOR = 11; |
95 |
|
|
96 |
/** |
/** |
97 |
* Constant for a hand cursor. |
* Constant for a hand cursor. |
98 |
*/ |
*/ |
99 |
public static final int HAND_CURSOR = 12; |
public static final int HAND_CURSOR = 12; |
100 |
|
|
101 |
/** |
/** |
102 |
* Constant for a cursor used during window move operations. |
* Constant for a cursor used during window move operations. |
103 |
*/ |
*/ |
104 |
public static final int MOVE_CURSOR = 13; |
public static final int MOVE_CURSOR = 13; |
|
|
|
|
// Serialization constant |
|
|
private static final long serialVersionUID = 8028237497568985504L; |
|
105 |
|
|
106 |
/*************************************************************************/ |
public static final int CUSTOM_CURSOR = 0xFFFFFFFF; |
107 |
|
|
108 |
/* |
private static final int PREDEFINED_COUNT = 14; |
|
* Instance Variables |
|
|
*/ |
|
109 |
|
|
110 |
/** |
protected static Cursor[] predefined = new Cursor[PREDEFINED_COUNT]; |
111 |
* @serial The numeric id of this cursor. |
protected String name; |
|
*/ |
|
|
private int type; |
|
112 |
|
|
113 |
/*************************************************************************/ |
/** |
114 |
|
* @serial The numeric id of this cursor. |
115 |
/* |
*/ |
116 |
* Static Methods |
int type; |
117 |
*/ |
|
118 |
|
/** |
119 |
/** |
* Initializes a new instance of <code>Cursor</code> with the specified |
120 |
* Returns an instance of the system default cursor type. |
* type. |
121 |
* |
* |
122 |
* @return The system default cursor. |
* @param type The cursor type. |
123 |
*/ |
*/ |
124 |
public static Cursor |
public Cursor(int type) |
125 |
getDefaultCursor() |
{ |
126 |
{ |
if (type < 0 || type >= PREDEFINED_COUNT) |
127 |
return(new Cursor(DEFAULT_CURSOR)); |
throw new IllegalArgumentException ("invalid cursor " + type); |
128 |
|
this.type = type; |
129 |
|
// FIXME: lookup and set name? |
130 |
|
} |
131 |
|
|
132 |
|
/** This constructor is used internally only. |
133 |
|
* Application code should call Toolkit.createCustomCursor(). |
134 |
|
*/ |
135 |
|
protected Cursor(String name) |
136 |
|
{ |
137 |
|
this.name = name; |
138 |
|
this.type = CUSTOM_CURSOR; |
139 |
|
} |
140 |
|
|
141 |
|
/** |
142 |
|
* Returns an instance of <code>Cursor</code> for one of the specified |
143 |
|
* predetermined types. |
144 |
|
* |
145 |
|
* @param type The type contant from this class. |
146 |
|
* |
147 |
|
* @return The requested predefined cursor. |
148 |
|
* |
149 |
|
* @exception IllegalArgumentException If the constant is not one of the |
150 |
|
* predefined cursor type constants from this class. |
151 |
|
*/ |
152 |
|
public static Cursor getPredefinedCursor(int type) |
153 |
|
{ |
154 |
|
if (type < 0 || type >= PREDEFINED_COUNT) |
155 |
|
throw new IllegalArgumentException ("invalid cursor " + type); |
156 |
|
if (predefined[type] == null) |
157 |
|
predefined[type] = new Cursor(type); |
158 |
|
return predefined[type]; |
159 |
|
} |
160 |
|
|
161 |
|
public static Cursor getSystemCustomCursor(String name) |
162 |
|
throws AWTException |
163 |
|
{ |
164 |
|
// FIXME |
165 |
|
return null; |
166 |
|
} |
167 |
|
|
168 |
|
/** |
169 |
|
* Returns an instance of the system default cursor type. |
170 |
|
* |
171 |
|
* @return The system default cursor. |
172 |
|
*/ |
173 |
|
public static Cursor getDefaultCursor() |
174 |
|
{ |
175 |
|
return getPredefinedCursor(DEFAULT_CURSOR); |
176 |
|
} |
177 |
|
|
178 |
|
/** |
179 |
|
* Returns the numeric type identifier for this cursor. |
180 |
|
* |
181 |
|
* @return The cursor id. |
182 |
|
*/ |
183 |
|
public int getType() |
184 |
|
{ |
185 |
|
return type; |
186 |
|
} |
187 |
|
|
188 |
|
public String getName() |
189 |
|
{ |
190 |
|
return name; |
191 |
|
} |
192 |
|
|
193 |
|
public String toString() |
194 |
|
{ |
195 |
|
return (this.getClass() + "[" + getName() + "]"); |
196 |
|
} |
197 |
} |
} |
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* Returns an instance of <code>Cursor</code> for one of the specified |
|
|
* predetermined types. |
|
|
* |
|
|
* @param type The type contant from this class. |
|
|
* |
|
|
* @return The requested predefined cursor. |
|
|
* |
|
|
* @exception IllegalArgumentException If the constant is not one of the |
|
|
* predefined cursor type constants from this class. |
|
|
*/ |
|
|
public static Cursor |
|
|
getPredefinedCursor(int type) throws IllegalArgumentException |
|
|
{ |
|
|
if ((type < DEFAULT_CURSOR) || (type > MOVE_CURSOR)) |
|
|
throw new IllegalArgumentException("Bad predefined cursor type: " + type); |
|
|
|
|
|
return(new Cursor(type)); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Constructors |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* Initializes a new instance of <code>Cursor</code> with the specified |
|
|
* type. |
|
|
* |
|
|
* @param type The cursor type. |
|
|
*/ |
|
|
public |
|
|
Cursor(int type) |
|
|
{ |
|
|
this.type = type; |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* Instance Variables |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* Returns the numeric type identifier for this cursor. |
|
|
* |
|
|
* @return The cursor id. |
|
|
*/ |
|
|
public int |
|
|
getType() |
|
|
{ |
|
|
return(type); |
|
|
} |
|
|
|
|
|
} // class Cursor |
|
|
|
|