public void dispose() { getRGBPixelsMethodParam = null; Method method = getRGBPixelsMethod; try { if (method != null) { getRGBPixelsMethod = null; method.setAccessible(false); } } finally { try { Class<?>[] tailSig = new Class<?>[0]; peer.getClass().getDeclaredMethod("dispose", tailSig).invoke(peer, (Object[]) tailSig); } catch (IllegalArgumentException e) { LLog.e(e); } catch (SecurityException e) { LLog.e(e); } catch (IllegalAccessException e) { LLog.e(e); } catch (InvocationTargetException e) { LLog.e(e); } catch (NoSuchMethodException e) { LLog.e(e); } } }
public void mouseMove(int x, int y, int ox, int oy) { // Appears that peer does not require inverse scaling // when attempting to move the mouse /* int[] initialScale = new int[2]; Rectangle bounds = _getScreenBounds(device, initialScale); if (initialScale[0] != bounds.width || initialScale[1] != bounds.height) { x = Math.round(((float)initialScale[0])/((float)bounds.width)*((float)x)); y = Math.round(((float)initialScale[1])/((float)bounds.height)*((float)y)); } */ x += ox; y += oy; peer.mouseMove(x, y); }
public DirectRobot(GraphicsDevice device) throws AWTException { if (device == null) { device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); } robot = new Robot(device); ArrayList<Exception> exceptions = new ArrayList<Exception>(); this.device = device; Toolkit toolkit = Toolkit.getDefaultToolkit(); peer = ((ComponentFactory) toolkit).createRobot(null, device); Class<?> peerClass = peer.getClass(); Method method = null; int methodType = -1; Object methodParam = null; try { method = peerClass.getDeclaredMethod( "getRGBPixels", new Class<?>[] {Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, int[].class}); methodType = 0; } catch (SecurityException e) { exceptions.add(e); } catch (NoSuchMethodException e) { exceptions.add(e); } if (methodType < 0) { try { method = peerClass.getDeclaredMethod( "getScreenPixels", new Class<?>[] {Rectangle.class, int[].class}); methodType = 1; } catch (SecurityException e) { exceptions.add(e); } catch (NoSuchMethodException e) { exceptions.add(e); } } if (methodType < 0) { try { method = peerClass.getDeclaredMethod( "getScreenPixels", new Class<?>[] {Integer.TYPE, Rectangle.class, int[].class}); methodType = 2; GraphicsDevice[] devices = getScreenDevices(); int count = devices.length; for (int i = 0; i < count; i++) { if (device.equals(devices[i])) { methodParam = Integer.valueOf(i); break; } } } catch (SecurityException e) { exceptions.add(e); } catch (NoSuchMethodException e) { exceptions.add(e); } } if (methodType < 0) { try { boolean accessibleChanged = false; method = peerClass.getDeclaredMethod( "getRGBPixelsImpl", new Class<?>[] { Class.forName("sun.awt.X11GraphicsConfig"), Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, int[].class }); Field field = peerClass.getDeclaredField("xgc"); try { if (!field.isAccessible()) { field.setAccessible(true); accessibleChanged = true; } methodParam = field.get(peer); methodType = 3; } catch (IllegalArgumentException e) { exceptions.add(e); } catch (IllegalAccessException e) { exceptions.add(e); } finally { if (accessibleChanged) { field.setAccessible(false); } } } catch (SecurityException e) { exceptions.add(e); } catch (NoSuchFieldException e) { exceptions.add(e); } catch (NoSuchMethodException e) { exceptions.add(e); } catch (ClassNotFoundException e) { exceptions.add(e); } } if (methodType >= 0 && method != null && (methodType <= 1 || methodParam != null)) { if (DEBUG) LLog.i(String.format("Method type = %d", methodType)); getRGBPixelsMethod = method; getRGBPixelsMethodType = methodType; getRGBPixelsMethodParam = methodParam; } else { if (DEBUG) { for (Exception e : exceptions) { e.printStackTrace(); } } exceptions.clear(); exceptions = null; if (DEBUG) { LLog.w( String.format( "WARNING: Failed to acquire direct method for grabbing pixels, please post this on the main thread!\n\n%s\n\n", peer.getClass().getName())); try { Method[] methods = peer.getClass().getDeclaredMethods(); for (Method method1 : methods) { LLog.w(method1 + "\n"); } LLog.w("\n"); } catch (Exception e) { LLog.e(e); } } throw new RuntimeException("No supported method for getting pixels"); } }
public int[] getRGBPixels(Rectangle bounds) { return peer.getRGBPixels(bounds); }
public int getRGBPixel(int x, int y) { return peer.getRGBPixel(x, y); }
public void keyRelease(int keycode) { peer.keyRelease(keycode); }
public void keyPress(int keycode) { peer.keyPress(keycode); }
public void mouseWheel(int wheelAmount) { peer.mouseWheel(wheelAmount); }
public void mouseRelease(int buttonID) { peer.mouseRelease(buttonID); }
public void mousePress(int buttonID) { peer.mousePress(buttonID); }