src/share/classes/sun/awt/ComponentAccessor.java

Print this page




  53  *
  54  * @author Bino George
  55  */
  56 
  57 
  58 public class ComponentAccessor
  59 {
  60     private static Class componentClass;
  61     private static Field fieldX;
  62     private static Field fieldY;
  63     private static Field fieldWidth;
  64     private static Field fieldHeight;
  65     private static Method methodGetParentNoClientCode;
  66     private static Method methodGetFontNoClientCode;
  67     private static Method methodProcessEvent;
  68     private static Method methodEnableEvents;
  69     private static Field fieldParent;
  70     private static Field fieldBackground;
  71     private static Field fieldForeground;
  72     private static Field fieldFont;
  73     private static Field fieldPacked;
  74     private static Field fieldIgnoreRepaint;
  75     private static Field fieldPeer;
  76     private static Field fieldVisible;
  77     private static Method methodIsEnabledImpl;
  78     private static Method methodGetCursorNoClientCode;
  79     private static Method methodLocationNoClientCode;
  80 
  81     private static final Logger log = Logger.getLogger("sun.awt.ComponentAccessor");
  82 
  83     private ComponentAccessor() {
  84     }
  85 
  86     static {
  87         AccessController.doPrivileged( new PrivilegedAction() {
  88                 public Object run() {
  89                     try {
  90                         componentClass = Class.forName("java.awt.Component");
  91                         fieldX  = componentClass.getDeclaredField("x");
  92                         fieldX.setAccessible(true);
  93                         fieldY  = componentClass.getDeclaredField("y");


  98                         fieldHeight.setAccessible(true);
  99                         fieldForeground  = componentClass.getDeclaredField("foreground");
 100                         fieldForeground.setAccessible(true);
 101                         fieldBackground  = componentClass.getDeclaredField("background");
 102                         fieldBackground.setAccessible(true);
 103                         fieldFont = componentClass.getDeclaredField("font");
 104                         fieldFont.setAccessible(true);
 105                         methodGetParentNoClientCode = componentClass.getDeclaredMethod("getParent_NoClientCode", (Class[]) null);
 106                         methodGetParentNoClientCode.setAccessible(true);
 107                         methodGetFontNoClientCode = componentClass.getDeclaredMethod("getFont_NoClientCode", (Class[]) null);
 108                         methodGetFontNoClientCode.setAccessible(true);
 109                         Class[] argTypes = { AWTEvent.class };
 110                         methodProcessEvent = componentClass.getDeclaredMethod("processEvent",argTypes);
 111                         methodProcessEvent.setAccessible(true);
 112                         Class[] argTypesForMethodEnableEvents = { Long.TYPE };
 113                         methodEnableEvents = componentClass.getDeclaredMethod("enableEvents",argTypesForMethodEnableEvents);
 114                         methodEnableEvents.setAccessible(true);
 115 
 116                         fieldParent  = componentClass.getDeclaredField("parent");
 117                         fieldParent.setAccessible(true);
 118                         fieldPacked = componentClass.getDeclaredField("isPacked");
 119                         fieldPacked.setAccessible(true);
 120                         fieldIgnoreRepaint = componentClass.getDeclaredField("ignoreRepaint");
 121                         fieldIgnoreRepaint.setAccessible(true);
 122 
 123                         fieldPeer = componentClass.getDeclaredField("peer");
 124                         fieldPeer.setAccessible(true);
 125 
 126                         fieldVisible = componentClass.getDeclaredField("visible");
 127                         fieldVisible.setAccessible(true);
 128 
 129                         methodIsEnabledImpl = componentClass.getDeclaredMethod("isEnabledImpl", (Class[]) null);
 130                         methodIsEnabledImpl.setAccessible(true);
 131 
 132                         methodGetCursorNoClientCode = componentClass.getDeclaredMethod("getCursor_NoClientCode", (Class[]) null);
 133                         methodGetCursorNoClientCode.setAccessible(true);
 134 
 135                         methodLocationNoClientCode = componentClass.getDeclaredMethod("location_NoClientCode", (Class[]) null);
 136                         methodLocationNoClientCode.setAccessible(true);
 137                     }
 138                     catch (NoSuchFieldException e) {
 139                         log.log(Level.FINE, "Unable to initialize ComponentAccessor", e);


 235             return fieldWidth.getInt(c);
 236         }
 237         catch (IllegalAccessException e)
 238         {
 239             log.log(Level.FINE, "Unable to access the Component object", e);
 240         }
 241         return 0;
 242     }
 243 
 244     public static int getHeight(Component c) {
 245         try {
 246             return fieldHeight.getInt(c);
 247         }
 248         catch (IllegalAccessException e)
 249         {
 250             log.log(Level.FINE, "Unable to access the Component object", e);
 251         }
 252         return 0;
 253     }
 254 
 255     public static boolean getIsPacked(Component c) {
 256         try {
 257             return fieldPacked.getBoolean(c);
 258         }
 259         catch (IllegalAccessException e)
 260         {
 261             log.log(Level.FINE, "Unable to access the Component object", e);
 262         }
 263         return false;
 264     }
 265 
 266     public static Container getParent_NoClientCode(Component c) {
 267         Container parent=null;
 268 
 269         try {
 270             parent = (Container) methodGetParentNoClientCode.invoke(c, (Object[]) null);
 271         }
 272         catch (IllegalAccessException e)
 273         {
 274             log.log(Level.FINE, "Unable to access the Component object", e);
 275         }
 276         catch (InvocationTargetException e) {
 277             log.log(Level.FINE, "Unable to invoke on the Component object", e);
 278         }
 279 
 280         return parent;
 281     }
 282 
 283     public static Font getFont_NoClientCode(Component c) {
 284         Font font=null;
 285 




  53  *
  54  * @author Bino George
  55  */
  56 
  57 
  58 public class ComponentAccessor
  59 {
  60     private static Class componentClass;
  61     private static Field fieldX;
  62     private static Field fieldY;
  63     private static Field fieldWidth;
  64     private static Field fieldHeight;
  65     private static Method methodGetParentNoClientCode;
  66     private static Method methodGetFontNoClientCode;
  67     private static Method methodProcessEvent;
  68     private static Method methodEnableEvents;
  69     private static Field fieldParent;
  70     private static Field fieldBackground;
  71     private static Field fieldForeground;
  72     private static Field fieldFont;

  73     private static Field fieldIgnoreRepaint;
  74     private static Field fieldPeer;
  75     private static Field fieldVisible;
  76     private static Method methodIsEnabledImpl;
  77     private static Method methodGetCursorNoClientCode;
  78     private static Method methodLocationNoClientCode;
  79 
  80     private static final Logger log = Logger.getLogger("sun.awt.ComponentAccessor");
  81 
  82     private ComponentAccessor() {
  83     }
  84 
  85     static {
  86         AccessController.doPrivileged( new PrivilegedAction() {
  87                 public Object run() {
  88                     try {
  89                         componentClass = Class.forName("java.awt.Component");
  90                         fieldX  = componentClass.getDeclaredField("x");
  91                         fieldX.setAccessible(true);
  92                         fieldY  = componentClass.getDeclaredField("y");


  97                         fieldHeight.setAccessible(true);
  98                         fieldForeground  = componentClass.getDeclaredField("foreground");
  99                         fieldForeground.setAccessible(true);
 100                         fieldBackground  = componentClass.getDeclaredField("background");
 101                         fieldBackground.setAccessible(true);
 102                         fieldFont = componentClass.getDeclaredField("font");
 103                         fieldFont.setAccessible(true);
 104                         methodGetParentNoClientCode = componentClass.getDeclaredMethod("getParent_NoClientCode", (Class[]) null);
 105                         methodGetParentNoClientCode.setAccessible(true);
 106                         methodGetFontNoClientCode = componentClass.getDeclaredMethod("getFont_NoClientCode", (Class[]) null);
 107                         methodGetFontNoClientCode.setAccessible(true);
 108                         Class[] argTypes = { AWTEvent.class };
 109                         methodProcessEvent = componentClass.getDeclaredMethod("processEvent",argTypes);
 110                         methodProcessEvent.setAccessible(true);
 111                         Class[] argTypesForMethodEnableEvents = { Long.TYPE };
 112                         methodEnableEvents = componentClass.getDeclaredMethod("enableEvents",argTypesForMethodEnableEvents);
 113                         methodEnableEvents.setAccessible(true);
 114 
 115                         fieldParent  = componentClass.getDeclaredField("parent");
 116                         fieldParent.setAccessible(true);


 117                         fieldIgnoreRepaint = componentClass.getDeclaredField("ignoreRepaint");
 118                         fieldIgnoreRepaint.setAccessible(true);
 119 
 120                         fieldPeer = componentClass.getDeclaredField("peer");
 121                         fieldPeer.setAccessible(true);
 122 
 123                         fieldVisible = componentClass.getDeclaredField("visible");
 124                         fieldVisible.setAccessible(true);
 125 
 126                         methodIsEnabledImpl = componentClass.getDeclaredMethod("isEnabledImpl", (Class[]) null);
 127                         methodIsEnabledImpl.setAccessible(true);
 128 
 129                         methodGetCursorNoClientCode = componentClass.getDeclaredMethod("getCursor_NoClientCode", (Class[]) null);
 130                         methodGetCursorNoClientCode.setAccessible(true);
 131 
 132                         methodLocationNoClientCode = componentClass.getDeclaredMethod("location_NoClientCode", (Class[]) null);
 133                         methodLocationNoClientCode.setAccessible(true);
 134                     }
 135                     catch (NoSuchFieldException e) {
 136                         log.log(Level.FINE, "Unable to initialize ComponentAccessor", e);


 232             return fieldWidth.getInt(c);
 233         }
 234         catch (IllegalAccessException e)
 235         {
 236             log.log(Level.FINE, "Unable to access the Component object", e);
 237         }
 238         return 0;
 239     }
 240 
 241     public static int getHeight(Component c) {
 242         try {
 243             return fieldHeight.getInt(c);
 244         }
 245         catch (IllegalAccessException e)
 246         {
 247             log.log(Level.FINE, "Unable to access the Component object", e);
 248         }
 249         return 0;
 250     }
 251 











 252     public static Container getParent_NoClientCode(Component c) {
 253         Container parent=null;
 254 
 255         try {
 256             parent = (Container) methodGetParentNoClientCode.invoke(c, (Object[]) null);
 257         }
 258         catch (IllegalAccessException e)
 259         {
 260             log.log(Level.FINE, "Unable to access the Component object", e);
 261         }
 262         catch (InvocationTargetException e) {
 263             log.log(Level.FINE, "Unable to invoke on the Component object", e);
 264         }
 265 
 266         return parent;
 267     }
 268 
 269     public static Font getFont_NoClientCode(Component c) {
 270         Font font=null;
 271