37 |
37 |
38 import java.lang.reflect.Field; |
38 import java.lang.reflect.Field; |
39 import java.lang.reflect.Method; |
39 import java.lang.reflect.Method; |
40 import java.lang.reflect.InvocationTargetException; |
40 import java.lang.reflect.InvocationTargetException; |
41 |
41 |
42 import java.util.logging.Logger; |
42 import sun.util.logging.PlatformLogger; |
43 import java.util.logging.Level; |
|
44 |
43 |
45 import java.security.AccessController; |
44 import java.security.AccessController; |
46 import java.security.PrivilegedAction; |
45 import java.security.PrivilegedAction; |
47 |
46 |
48 /** |
47 /** |
76 private static Field fieldVisible; |
75 private static Field fieldVisible; |
77 private static Method methodIsEnabledImpl; |
76 private static Method methodIsEnabledImpl; |
78 private static Method methodGetCursorNoClientCode; |
77 private static Method methodGetCursorNoClientCode; |
79 private static Method methodLocationNoClientCode; |
78 private static Method methodLocationNoClientCode; |
80 |
79 |
81 private static final Logger log = Logger.getLogger("sun.awt.ComponentAccessor"); |
80 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.ComponentAccessor"); |
82 |
81 |
83 private ComponentAccessor() { |
82 private ComponentAccessor() { |
84 } |
83 } |
85 |
84 |
86 static { |
85 static { |
134 |
133 |
135 methodLocationNoClientCode = componentClass.getDeclaredMethod("location_NoClientCode", (Class[]) null); |
134 methodLocationNoClientCode = componentClass.getDeclaredMethod("location_NoClientCode", (Class[]) null); |
136 methodLocationNoClientCode.setAccessible(true); |
135 methodLocationNoClientCode.setAccessible(true); |
137 } |
136 } |
138 catch (NoSuchFieldException e) { |
137 catch (NoSuchFieldException e) { |
139 log.log(Level.FINE, "Unable to initialize ComponentAccessor", e); |
138 log.fine("Unable to initialize ComponentAccessor", e); |
140 } |
139 } |
141 catch (ClassNotFoundException e) { |
140 catch (ClassNotFoundException e) { |
142 log.log(Level.FINE, "Unable to initialize ComponentAccessor", e); |
141 log.fine("Unable to initialize ComponentAccessor", e); |
143 } |
142 } |
144 catch (NoSuchMethodException e) { |
143 catch (NoSuchMethodException e) { |
145 log.log(Level.FINE, "Unable to initialize ComponentAccessor", e); |
144 log.fine("Unable to initialize ComponentAccessor", e); |
146 } |
145 } |
147 // to please javac |
146 // to please javac |
148 return null; |
147 return null; |
149 } |
148 } |
150 }); |
149 }); |
155 try { |
154 try { |
156 fieldX.setInt(c,x); |
155 fieldX.setInt(c,x); |
157 } |
156 } |
158 catch (IllegalAccessException e) |
157 catch (IllegalAccessException e) |
159 { |
158 { |
160 log.log(Level.FINE, "Unable to access the Component object", e); |
159 log.fine("Unable to access the Component object", e); |
161 } |
160 } |
162 } |
161 } |
163 |
162 |
164 public static void setY(Component c, int y) |
163 public static void setY(Component c, int y) |
165 { |
164 { |
166 try { |
165 try { |
167 fieldY.setInt(c,y); |
166 fieldY.setInt(c,y); |
168 } |
167 } |
169 catch (IllegalAccessException e) |
168 catch (IllegalAccessException e) |
170 { |
169 { |
171 log.log(Level.FINE, "Unable to access the Component object", e); |
170 log.fine("Unable to access the Component object", e); |
172 } |
171 } |
173 } |
172 } |
174 |
173 |
175 public static void setWidth(Component c, int width) |
174 public static void setWidth(Component c, int width) |
176 { |
175 { |
177 try { |
176 try { |
178 fieldWidth.setInt(c,width); |
177 fieldWidth.setInt(c,width); |
179 } |
178 } |
180 catch (IllegalAccessException e) |
179 catch (IllegalAccessException e) |
181 { |
180 { |
182 log.log(Level.FINE, "Unable to access the Component object", e); |
181 log.fine("Unable to access the Component object", e); |
183 } |
182 } |
184 } |
183 } |
185 |
184 |
186 public static void setHeight(Component c, int height) |
185 public static void setHeight(Component c, int height) |
187 { |
186 { |
188 try { |
187 try { |
189 fieldHeight.setInt(c,height); |
188 fieldHeight.setInt(c,height); |
190 } |
189 } |
191 catch (IllegalAccessException e) |
190 catch (IllegalAccessException e) |
192 { |
191 { |
193 log.log(Level.FINE, "Unable to access the Component object", e); |
192 log.fine("Unable to access the Component object", e); |
194 } |
193 } |
195 } |
194 } |
196 |
195 |
197 public static void setBounds(Component c, int x, int y, int width, int height) |
196 public static void setBounds(Component c, int x, int y, int width, int height) |
198 { |
197 { |
202 fieldWidth.setInt(c,width); |
201 fieldWidth.setInt(c,width); |
203 fieldHeight.setInt(c,height); |
202 fieldHeight.setInt(c,height); |
204 } |
203 } |
205 catch (IllegalAccessException e) |
204 catch (IllegalAccessException e) |
206 { |
205 { |
207 log.log(Level.FINE, "Unable to access the Component object", e); |
206 log.fine("Unable to access the Component object", e); |
208 } |
207 } |
209 } |
208 } |
210 |
209 |
211 public static int getX(Component c) { |
210 public static int getX(Component c) { |
212 try { |
211 try { |
213 return fieldX.getInt(c); |
212 return fieldX.getInt(c); |
214 } |
213 } |
215 catch (IllegalAccessException e) |
214 catch (IllegalAccessException e) |
216 { |
215 { |
217 log.log(Level.FINE, "Unable to access the Component object", e); |
216 log.fine("Unable to access the Component object", e); |
218 } |
217 } |
219 return 0; |
218 return 0; |
220 } |
219 } |
221 |
220 |
222 public static int getY(Component c) { |
221 public static int getY(Component c) { |
223 try { |
222 try { |
224 return fieldY.getInt(c); |
223 return fieldY.getInt(c); |
225 } |
224 } |
226 catch (IllegalAccessException e) |
225 catch (IllegalAccessException e) |
227 { |
226 { |
228 log.log(Level.FINE, "Unable to access the Component object", e); |
227 log.fine("Unable to access the Component object", e); |
229 } |
228 } |
230 return 0; |
229 return 0; |
231 } |
230 } |
232 |
231 |
233 public static int getWidth(Component c) { |
232 public static int getWidth(Component c) { |
234 try { |
233 try { |
235 return fieldWidth.getInt(c); |
234 return fieldWidth.getInt(c); |
236 } |
235 } |
237 catch (IllegalAccessException e) |
236 catch (IllegalAccessException e) |
238 { |
237 { |
239 log.log(Level.FINE, "Unable to access the Component object", e); |
238 log.fine("Unable to access the Component object", e); |
240 } |
239 } |
241 return 0; |
240 return 0; |
242 } |
241 } |
243 |
242 |
244 public static int getHeight(Component c) { |
243 public static int getHeight(Component c) { |
245 try { |
244 try { |
246 return fieldHeight.getInt(c); |
245 return fieldHeight.getInt(c); |
247 } |
246 } |
248 catch (IllegalAccessException e) |
247 catch (IllegalAccessException e) |
249 { |
248 { |
250 log.log(Level.FINE, "Unable to access the Component object", e); |
249 log.fine("Unable to access the Component object", e); |
251 } |
250 } |
252 return 0; |
251 return 0; |
253 } |
252 } |
254 |
253 |
255 public static boolean getIsPacked(Component c) { |
254 public static boolean getIsPacked(Component c) { |
256 try { |
255 try { |
257 return fieldPacked.getBoolean(c); |
256 return fieldPacked.getBoolean(c); |
258 } |
257 } |
259 catch (IllegalAccessException e) |
258 catch (IllegalAccessException e) |
260 { |
259 { |
261 log.log(Level.FINE, "Unable to access the Component object", e); |
260 log.fine("Unable to access the Component object", e); |
262 } |
261 } |
263 return false; |
262 return false; |
264 } |
263 } |
265 |
264 |
266 public static Container getParent_NoClientCode(Component c) { |
265 public static Container getParent_NoClientCode(Component c) { |
269 try { |
268 try { |
270 parent = (Container) methodGetParentNoClientCode.invoke(c, (Object[]) null); |
269 parent = (Container) methodGetParentNoClientCode.invoke(c, (Object[]) null); |
271 } |
270 } |
272 catch (IllegalAccessException e) |
271 catch (IllegalAccessException e) |
273 { |
272 { |
274 log.log(Level.FINE, "Unable to access the Component object", e); |
273 log.fine("Unable to access the Component object", e); |
275 } |
274 } |
276 catch (InvocationTargetException e) { |
275 catch (InvocationTargetException e) { |
277 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
276 log.fine("Unable to invoke on the Component object", e); |
278 } |
277 } |
279 |
278 |
280 return parent; |
279 return parent; |
281 } |
280 } |
282 |
281 |
286 try { |
285 try { |
287 font = (Font) methodGetFontNoClientCode.invoke(c, (Object[]) null); |
286 font = (Font) methodGetFontNoClientCode.invoke(c, (Object[]) null); |
288 } |
287 } |
289 catch (IllegalAccessException e) |
288 catch (IllegalAccessException e) |
290 { |
289 { |
291 log.log(Level.FINE, "Unable to access the Component object", e); |
290 log.fine("Unable to access the Component object", e); |
292 } |
291 } |
293 catch (InvocationTargetException e) { |
292 catch (InvocationTargetException e) { |
294 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
293 log.fine("Unable to invoke on the Component object", e); |
295 } |
294 } |
296 |
295 |
297 return font; |
296 return font; |
298 } |
297 } |
299 |
298 |
305 args[0] = event; |
304 args[0] = event; |
306 methodProcessEvent.invoke(c,args); |
305 methodProcessEvent.invoke(c,args); |
307 } |
306 } |
308 catch (IllegalAccessException e) |
307 catch (IllegalAccessException e) |
309 { |
308 { |
310 log.log(Level.FINE, "Unable to access the Component object", e); |
309 log.fine("Unable to access the Component object", e); |
311 } |
310 } |
312 catch (InvocationTargetException e) { |
311 catch (InvocationTargetException e) { |
313 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
312 log.fine("Unable to invoke on the Component object", e); |
314 } |
313 } |
315 } |
314 } |
316 |
315 |
317 public static void enableEvents(Component c, long event_mask) { |
316 public static void enableEvents(Component c, long event_mask) { |
318 try { |
317 try { |
320 args[0] = Long.valueOf(event_mask); |
319 args[0] = Long.valueOf(event_mask); |
321 methodEnableEvents.invoke(c,args); |
320 methodEnableEvents.invoke(c,args); |
322 } |
321 } |
323 catch (IllegalAccessException e) |
322 catch (IllegalAccessException e) |
324 { |
323 { |
325 log.log(Level.FINE, "Unable to access the Component object", e); |
324 log.fine("Unable to access the Component object", e); |
326 } |
325 } |
327 catch (InvocationTargetException e) { |
326 catch (InvocationTargetException e) { |
328 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
327 log.fine("Unable to invoke on the Component object", e); |
329 } |
328 } |
330 } |
329 } |
331 |
330 |
332 public static void setParent(Component c, Container parent) |
331 public static void setParent(Component c, Container parent) |
333 { |
332 { |
334 try { |
333 try { |
335 fieldParent.set(c,parent); |
334 fieldParent.set(c,parent); |
336 } |
335 } |
337 catch (IllegalAccessException e) |
336 catch (IllegalAccessException e) |
338 { |
337 { |
339 log.log(Level.FINE, "Unable to access the Component object", e); |
338 log.fine("Unable to access the Component object", e); |
340 } |
339 } |
341 } |
340 } |
342 |
341 |
343 public static Color getForeground(Component c) |
342 public static Color getForeground(Component c) |
344 { |
343 { |
359 try { |
358 try { |
360 color = (Color) fieldBackground.get(c); |
359 color = (Color) fieldBackground.get(c); |
361 } |
360 } |
362 catch (IllegalAccessException e) |
361 catch (IllegalAccessException e) |
363 { |
362 { |
364 log.log(Level.FINE, "Unable to access the Component object", e); |
363 log.fine("Unable to access the Component object", e); |
365 } |
364 } |
366 return color; |
365 return color; |
367 } |
366 } |
368 |
367 |
369 public static void setBackground(Component c, Color color) { |
368 public static void setBackground(Component c, Color color) { |
370 try { |
369 try { |
371 fieldBackground.set(c, color); |
370 fieldBackground.set(c, color); |
372 } |
371 } |
373 catch (IllegalAccessException e) |
372 catch (IllegalAccessException e) |
374 { |
373 { |
375 log.log(Level.FINE, "Unable to access the Component object", e); |
374 log.fine("Unable to access the Component object", e); |
376 } |
375 } |
377 } |
376 } |
378 |
377 |
379 public static Font getFont(Component c) |
378 public static Font getFont(Component c) |
380 { |
379 { |
394 try { |
393 try { |
395 peer = (ComponentPeer)fieldPeer.get(c); |
394 peer = (ComponentPeer)fieldPeer.get(c); |
396 } |
395 } |
397 catch (IllegalAccessException e) |
396 catch (IllegalAccessException e) |
398 { |
397 { |
399 log.log(Level.FINE, "Unable to access the Component object", e); |
398 log.fine("Unable to access the Component object", e); |
400 } |
399 } |
401 return peer; |
400 return peer; |
402 } |
401 } |
403 |
402 |
404 public static void setPeer(Component c, ComponentPeer peer) { |
403 public static void setPeer(Component c, ComponentPeer peer) { |
405 try { |
404 try { |
406 fieldPeer.set(c, peer); |
405 fieldPeer.set(c, peer); |
407 } catch (IllegalAccessException e) |
406 } catch (IllegalAccessException e) |
408 { |
407 { |
409 log.log(Level.FINE, "Unable to access the Component object", e); |
408 log.fine("Unable to access the Component object", e); |
410 } |
409 } |
411 } |
410 } |
412 |
411 |
413 public static boolean getIgnoreRepaint(Component comp) { |
412 public static boolean getIgnoreRepaint(Component comp) { |
414 try { |
413 try { |
415 return fieldIgnoreRepaint.getBoolean(comp); |
414 return fieldIgnoreRepaint.getBoolean(comp); |
416 } |
415 } |
417 catch (IllegalAccessException e) { |
416 catch (IllegalAccessException e) { |
418 log.log(Level.FINE, "Unable to access the Component object", e); |
417 log.fine("Unable to access the Component object", e); |
419 } |
418 } |
420 |
419 |
421 return false; |
420 return false; |
422 } |
421 } |
423 |
422 |
437 try { |
436 try { |
438 enabled = (Boolean) methodIsEnabledImpl.invoke(c, (Object[]) null); |
437 enabled = (Boolean) methodIsEnabledImpl.invoke(c, (Object[]) null); |
439 } |
438 } |
440 catch (IllegalAccessException e) |
439 catch (IllegalAccessException e) |
441 { |
440 { |
442 log.log(Level.FINE, "Unable to access the Component object", e); |
441 log.fine("Unable to access the Component object", e); |
443 } |
442 } |
444 catch (InvocationTargetException e) { |
443 catch (InvocationTargetException e) { |
445 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
444 log.fine("Unable to invoke on the Component object", e); |
446 } |
445 } |
447 return enabled; |
446 return enabled; |
448 } |
447 } |
449 |
448 |
450 public static Cursor getCursor_NoClientCode(Component c) { |
449 public static Cursor getCursor_NoClientCode(Component c) { |
453 try { |
452 try { |
454 cursor = (Cursor) methodGetCursorNoClientCode.invoke(c, (Object[]) null); |
453 cursor = (Cursor) methodGetCursorNoClientCode.invoke(c, (Object[]) null); |
455 } |
454 } |
456 catch (IllegalAccessException e) |
455 catch (IllegalAccessException e) |
457 { |
456 { |
458 log.log(Level.FINE, "Unable to access the Component object", e); |
457 log.fine("Unable to access the Component object", e); |
459 } |
458 } |
460 catch (InvocationTargetException e) { |
459 catch (InvocationTargetException e) { |
461 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
460 log.fine("Unable to invoke on the Component object", e); |
462 } |
461 } |
463 |
462 |
464 return cursor; |
463 return cursor; |
465 } |
464 } |
466 |
465 |
470 try { |
469 try { |
471 loc = (Point) methodLocationNoClientCode.invoke(c, (Object[]) null); |
470 loc = (Point) methodLocationNoClientCode.invoke(c, (Object[]) null); |
472 } |
471 } |
473 catch (IllegalAccessException e) |
472 catch (IllegalAccessException e) |
474 { |
473 { |
475 log.log(Level.FINE, "Unable to access the Component object", e); |
474 log.fine("Unable to access the Component object", e); |
476 } |
475 } |
477 catch (InvocationTargetException e) { |
476 catch (InvocationTargetException e) { |
478 log.log(Level.FINE, "Unable to invoke on the Component object", e); |
477 log.fine("Unable to invoke on the Component object", e); |
479 } |
478 } |
480 |
479 |
481 return loc; |
480 return loc; |
482 } |
481 } |
|
482 |
483 } |
483 } |