home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- import java.awt.image.BufferedImage;
- import java.awt.image.DataBufferInt;
- import java.awt.image.DirectColorModel;
- import java.awt.image.Raster;
- import java.awt.image.WritableRaster;
- import java.awt.peer.RobotPeer;
- import java.lang.reflect.InvocationTargetException;
- import java.util.Hashtable;
- import sun.awt.SunToolkit;
-
- public class Robot {
- private static final int MAX_DELAY = 60000;
- private RobotPeer peer;
- private SunToolkit sunToolkit;
- private boolean isAutoWaitForIdle = false;
- private int autoDelay = 0;
- private static AWTPermission readDisplayPixelsPermission = null;
- private static AWTPermission createRobotPermission = null;
- private static final int LEGAL_BUTTON_MASK = 28;
- private DirectColorModel screenCapCM = null;
- // $FF: synthetic field
- static Class class$java$awt$Robot;
-
- public Robot() throws AWTException {
- this.checkRobotAllowed();
- this.sunToolkit = (SunToolkit)Toolkit.getDefaultToolkit();
- this.peer = this.sunToolkit.createRobot(this, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
- }
-
- public Robot(GraphicsDevice var1) throws AWTException {
- this.checkIsScreenDevice(var1);
- this.checkRobotAllowed();
- this.sunToolkit = (SunToolkit)Toolkit.getDefaultToolkit();
- this.peer = this.sunToolkit.createRobot(this, var1);
- }
-
- private void checkRobotAllowed() {
- Class var1 = class$java$awt$Robot == null ? (class$java$awt$Robot = class$("java.awt.Robot")) : class$java$awt$Robot;
- synchronized(var1) {
- SecurityManager var2 = System.getSecurityManager();
- AWTPermission var3 = null;
- if (var2 != null) {
- if (var3 == null) {
- var3 = new AWTPermission("createRobot");
- }
-
- var2.checkPermission(var3);
- }
-
- }
- }
-
- private void checkIsScreenDevice(GraphicsDevice var1) {
- if (var1 == null || var1.getType() != 0) {
- throw new IllegalArgumentException("not a valid screen device");
- }
- }
-
- public synchronized void mouseMove(int var1, int var2) {
- this.peer.mouseMove(var1, var2);
- this.afterEvent();
- }
-
- public synchronized void mousePress(int var1) {
- this.checkButtonsArgument(var1);
- this.peer.mousePress(var1);
- this.afterEvent();
- }
-
- public synchronized void mouseRelease(int var1) {
- this.checkButtonsArgument(var1);
- this.peer.mouseRelease(var1);
- this.afterEvent();
- }
-
- private void checkButtonsArgument(int var1) {
- if ((var1 | 28) != 28) {
- throw new IllegalArgumentException("Invalid combination of button flags");
- }
- }
-
- public synchronized void keyPress(int var1) {
- this.checkKeycodeArgument(var1);
- this.peer.keyPress(var1);
- this.afterEvent();
- }
-
- public synchronized void keyRelease(int var1) {
- this.checkKeycodeArgument(var1);
- this.peer.keyRelease(var1);
- this.afterEvent();
- }
-
- private void checkKeycodeArgument(int var1) {
- if (var1 == 0) {
- throw new IllegalArgumentException("Invalid key code");
- }
- }
-
- public synchronized Color getPixelColor(int var1, int var2) {
- Color var3 = new Color(this.peer.getRGBPixel(var1, var2));
- return var3;
- }
-
- public synchronized BufferedImage createScreenCapture(Rectangle var1) {
- checkScreenCaptureAllowed();
- checkValidRect(var1);
- if (this.screenCapCM == null) {
- this.screenCapCM = new DirectColorModel(24, 16711680, 65280, 255);
- }
-
- int[] var6 = new int[3];
- int[] var5 = this.peer.getRGBPixels(var1);
- DataBufferInt var3 = new DataBufferInt(var5, var5.length);
- var6[0] = this.screenCapCM.getRedMask();
- var6[1] = this.screenCapCM.getGreenMask();
- var6[2] = this.screenCapCM.getBlueMask();
- WritableRaster var4 = Raster.createPackedRaster(var3, var1.width, var1.height, var1.width, var6, (Point)null);
- BufferedImage var2 = new BufferedImage(this.screenCapCM, var4, false, (Hashtable)null);
- return var2;
- }
-
- private static void checkValidRect(Rectangle var0) {
- if (var0.width <= 0 || var0.height <= 0) {
- throw new IllegalArgumentException("Rectangle width and height must be > 0");
- }
- }
-
- private static void checkScreenCaptureAllowed() {
- Class var0 = class$java$awt$Robot == null ? (class$java$awt$Robot = class$("java.awt.Robot")) : class$java$awt$Robot;
- synchronized(var0) {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- if (readDisplayPixelsPermission == null) {
- readDisplayPixelsPermission = new AWTPermission("readDisplayPixels");
- }
-
- var1.checkPermission(readDisplayPixelsPermission);
- }
-
- }
- }
-
- private void afterEvent() {
- this.autoWaitForIdle();
- this.autoDelay();
- }
-
- public synchronized boolean isAutoWaitForIdle() {
- return this.isAutoWaitForIdle;
- }
-
- public synchronized void setAutoWaitForIdle(boolean var1) {
- this.isAutoWaitForIdle = var1;
- }
-
- private void autoWaitForIdle() {
- if (this.isAutoWaitForIdle) {
- this.waitForIdle();
- }
-
- }
-
- public synchronized int getAutoDelay() {
- return this.autoDelay;
- }
-
- public synchronized void setAutoDelay(int var1) {
- this.checkDelayArgument(var1);
- this.autoDelay = var1;
- }
-
- private void autoDelay() {
- this.delay(this.autoDelay);
- }
-
- public synchronized void delay(int var1) {
- this.checkDelayArgument(var1);
-
- try {
- Thread.sleep((long)var1);
- } catch (InterruptedException var3) {
- ((Throwable)var3).printStackTrace();
- }
-
- }
-
- private void checkDelayArgument(int var1) {
- if (var1 < 0 || var1 > 60000) {
- throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
- }
- }
-
- public synchronized void waitForIdle() {
- this.checkNotDispatchThread();
-
- try {
- this.sunToolkit.flushPendingEvents();
- EventQueue.invokeAndWait(new 1(this));
- } catch (InterruptedException var3) {
- System.err.println("Robot.waitForIdle, non-fatal exception caught:");
- ((Throwable)var3).printStackTrace();
- } catch (InvocationTargetException var4) {
- System.err.println("Robot.waitForIdle, non-fatal exception caught:");
- var4.printStackTrace();
- }
-
- }
-
- private void checkNotDispatchThread() {
- if (EventQueue.isDispatchThread()) {
- throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread");
- }
- }
-
- public synchronized String toString() {
- String var1 = "autoDelay = " + this.getAutoDelay() + ", " + "autoWaitForIdle = " + this.isAutoWaitForIdle();
- return this.getClass().getName() + "[ " + var1 + " ]";
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
- }
- }
-