summaryrefslogtreecommitdiff
path: root/NET/worlds/console/Cursor.java
blob: d9038816052bb3d624bbdbf6ee5befd46eddf7f5 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*     */ package NET.worlds.console;
/*     */ 
/*     */ import NET.worlds.network.URL;
/*     */ import NET.worlds.scape.BGLoaded;
/*     */ import NET.worlds.scape.BackgroundLoader;
/*     */ import NET.worlds.scape.NoSuchPropertyException;
/*     */ import NET.worlds.scape.Pilot;
/*     */ import NET.worlds.scape.Property;
/*     */ import NET.worlds.scape.Restorer;
/*     */ import NET.worlds.scape.Room;
/*     */ import NET.worlds.scape.Saver;
/*     */ import NET.worlds.scape.SuperRoot;
/*     */ import NET.worlds.scape.TooNewException;
/*     */ import NET.worlds.scape.URLPropertyEditor;
/*     */ import java.io.IOException;
/*     */ import java.text.MessageFormat;
/*     */ import java.util.Enumeration;
/*     */ import java.util.Hashtable;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Cursor
/*     */   extends SuperRoot
/*     */   implements BGLoaded
/*     */ {
/*  44 */   private URL url = URL.make("system:DEFAULT_CURSOR");
/*     */   
/*     */ 
/*     */ 
/*     */   private int hCursor;
/*     */   
/*     */ 
/*     */ 
/*     */   private static Cursor active;
/*     */   
/*     */ 
/*     */ 
/*     */   private static Hashtable<URL, Comparable> sysCursors;
/*     */   
/*     */ 
/*     */   private static int defaultCursor;
/*     */   
/*     */ 
/*     */ 
/*     */   private static URL addCursor(String javaName, String win32Name)
/*     */   {
/*  65 */     URL url = URL.make("system:" + javaName);
/*  66 */     sysCursors.put(url, win32Name);
/*  67 */     return url;
/*     */   }
/*     */   
/*     */   static
/*     */   {
/*  54 */     sysCursors = new Hashtable();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  72 */     defaultCursor = retrieveSystemCursor(addCursor("DEFAULT_CURSOR", 
/*  73 */       "IDC_ARROW"));
/*  74 */     assert (defaultCursor != 0);
/*     */     
/*  76 */     addCursor("CROSSHAIR_CURSOR", "IDC_CROSS");
/*  77 */     addCursor("TEXT_CURSOR", "IDC_IBEAM");
/*  78 */     addCursor("WAIT_CURSOR", "IDC_WAIT");
/*  79 */     addCursor("NE_RESIZE_CURSOR", "IDC_SIZENESW");
/*  80 */     addCursor("SW_RESIZE_CURSOR", "IDC_SIZENESW");
/*  81 */     addCursor("NW_RESIZE_CURSOR", "IDC_SIZENWSE");
/*  82 */     addCursor("SE_RESIZE_CURSOR", "IDC_SIZENWSE");
/*  83 */     addCursor("N_RESIZE_CURSOR", "IDC_SIZENS");
/*  84 */     addCursor("S_RESIZE_CURSOR", "IDC_SIZENS");
/*  85 */     addCursor("W_RESIZE_CURSOR", "IDC_SIZEWE");
/*  86 */     addCursor("E_RESIZE_CURSOR", "IDC_SIZEWE");
/*  87 */     addCursor("HAND_CURSOR", "IDC_UPARROW");
/*  88 */     addCursor("MOVE_CURSOR", "IDC_SIZEALL");
/*  89 */     addCursor("CANNOT_CURSOR", "IDC_NO");
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public Cursor(URL url)
/*     */   {
/* 113 */     setURL(url);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void setURL(URL url)
/*     */   {
/* 124 */     this.url = url;
/* 125 */     if (!url.unalias().startsWith("system:")) {
/* 126 */       BackgroundLoader.get(this, url);
/*     */     } else {
/* 128 */       activate();
/*     */     }
/*     */   }
/*     */   
/*     */   public static Cursor getActive() {
/* 133 */     return active;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void activate()
/*     */   {
/* 142 */     SuperRoot owner = getOwner();
/*     */     
/* 144 */     if ((owner != null) && (owner == Console.getActive())) {
/* 145 */       int sysCurs = retrieveSystemCursor(this.url);
/*     */       
/* 147 */       if (sysCurs != 0) {
/* 148 */         Window.setCursor(sysCurs);
/* 149 */         maybeDestroyCursor();
/* 150 */         this.hCursor = sysCurs;
/* 151 */       } else if (this.hCursor != 0) {
/* 152 */         Window.setCursor(this.hCursor);
/*     */       }
/*     */       
/* 155 */       active = this;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void deactivate()
/*     */   {
/* 165 */     if (active == this)
/*     */     {
/*     */ 
/*     */ 
/* 169 */       active = null;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public URL getURL()
/*     */   {
/* 177 */     return this.url;
/*     */   }
/*     */   
/*     */   public static Enumeration<URL> getSysCursorURLs()
/*     */   {
/* 182 */     return sysCursors.keys();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static int retrieveSystemCursor(URL url)
/*     */   {
/* 208 */     int handle = 0;
/* 209 */     Object c = sysCursors.get(url);
/* 210 */     if (c != null)
/* 211 */       if ((c instanceof String)) {
/* 212 */         handle = loadSystemCursor((String)c);
/* 213 */         sysCursors.put(url, new Integer(handle));
/*     */       } else {
/* 215 */         handle = ((Integer)c).intValue();
/*     */       }
/* 217 */     return handle;
/*     */   }
/*     */   
/*     */   private void maybeDestroyCursor()
/*     */   {
/* 222 */     if (this.hCursor != 0) {
/* 223 */       if (!sysCursors.contains(new Integer(this.hCursor)))
/* 224 */         destroyCursor(this.hCursor);
/* 225 */       this.hCursor = 0;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public Object asyncBackgroundLoad(String localName, URL remoteName)
/*     */   {
/* 232 */     deactivate();
/* 233 */     maybeDestroyCursor();
/*     */     
/*     */ 
/* 236 */     if (localName == null) {
/* 237 */       return null;
/*     */     }
/* 239 */     if ((this.hCursor = loadCursor(localName)) != 0)
/* 240 */       activate();
/* 241 */     return null;
/*     */   }
/*     */   
/*     */   public boolean syncBackgroundLoad(Object obj, URL remoteURL) {
/* 245 */     if (this.hCursor == 0) {
/* 246 */       Object[] arguments = { new String(this.url) };
/* 247 */       Console.println(MessageFormat.format(
/* 248 */         Console.message("Load-cursor"), arguments));
/*     */     }
/* 250 */     return false;
/*     */   }
/*     */   
/*     */   public Room getBackgroundLoadRoom() {
/* 254 */     SuperRoot owner = getOwner();
/* 255 */     if ((owner == null) || (!(owner instanceof Console))) {
/* 256 */       return null;
/*     */     }
/* 258 */     return ((Console)owner).getPilot().getRoom();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public Object properties(int index, int offset, int mode, Object value)
/*     */     throws NoSuchPropertyException
/*     */   {
/* 266 */     Object ret = null;
/*     */     
/* 268 */     switch (index - offset) {
/*     */     case 0: 
/* 270 */       if (mode == 0) {
/* 271 */         ret = URLPropertyEditor.make(new Property(this, index, "File"), 
/* 272 */           "cur;ani", getSysCursorURLs());
/* 273 */       } else if (mode == 1) {
/* 274 */         ret = getURL();
/* 275 */       } else if (mode == 2)
/* 276 */         setURL((URL)value);
/* 277 */       break;
/*     */     
/*     */     default: 
/* 280 */       ret = super.properties(index, offset + 1, mode, value);
/*     */     }
/* 282 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/* 287 */   private static Object classCookie = new Object();
/*     */   
/*     */   public void saveState(Saver s) throws IOException
/*     */   {
/* 291 */     s.saveVersion(1, classCookie);
/* 292 */     super.saveState(s);
/*     */     
/* 294 */     URL.save(s, this.url);
/*     */   }
/*     */   
/*     */   public void restoreState(Restorer r) throws IOException, TooNewException
/*     */   {
/* 299 */     switch (r.restoreVersion(classCookie)) {
/*     */     case 0: 
/* 301 */       r.restoreMaybeNull();
/*     */       
/*     */ 
/* 304 */       String s = r.restoreString();
/* 305 */       if ((s.endsWith(".cur")) || (s.endsWith(".ani"))) {
/* 306 */         setURL(URL.restore(r, s, null));
/*     */       } else {
/* 308 */         setURL(URL.make("system:" + this.url));
/*     */       }
/* 310 */       break;
/*     */     
/*     */     case 1: 
/* 313 */       super.restoreState(r);
/* 314 */       setURL(URL.restore(r));
/* 315 */       break;
/*     */     
/*     */     default: 
/* 318 */       throw new TooNewException();
/*     */     }
/*     */   }
/*     */   
/*     */   public Cursor() {}
/*     */   
/*     */   public static native int getSystemCursorWidth();
/*     */   
/*     */   public static native int getSystemCursorHeight();
/*     */   
/*     */   public static native int getSystemCursorDepth();
/*     */   
/*     */   private static native int loadCursor(String paramString);
/*     */   
/*     */   private static native int loadSystemCursor(String paramString);
/*     */   
/*     */   private static native void destroyCursor(int paramInt);
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\Cursor.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */