home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / awt / Robot.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.8 KB  |  232 lines

  1. package java.awt;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.awt.image.DataBufferInt;
  5. import java.awt.image.DirectColorModel;
  6. import java.awt.image.Raster;
  7. import java.awt.image.WritableRaster;
  8. import java.awt.peer.RobotPeer;
  9. import java.lang.reflect.InvocationTargetException;
  10. import java.util.Hashtable;
  11. import sun.awt.SunToolkit;
  12.  
  13. public class Robot {
  14.    private static final int MAX_DELAY = 60000;
  15.    private RobotPeer peer;
  16.    private SunToolkit sunToolkit;
  17.    private boolean isAutoWaitForIdle = false;
  18.    private int autoDelay = 0;
  19.    private static AWTPermission readDisplayPixelsPermission = null;
  20.    private static AWTPermission createRobotPermission = null;
  21.    private static final int LEGAL_BUTTON_MASK = 28;
  22.    private DirectColorModel screenCapCM = null;
  23.    // $FF: synthetic field
  24.    static Class class$java$awt$Robot;
  25.  
  26.    public Robot() throws AWTException {
  27.       this.checkRobotAllowed();
  28.       this.sunToolkit = (SunToolkit)Toolkit.getDefaultToolkit();
  29.       this.peer = this.sunToolkit.createRobot(this, GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
  30.    }
  31.  
  32.    public Robot(GraphicsDevice var1) throws AWTException {
  33.       this.checkIsScreenDevice(var1);
  34.       this.checkRobotAllowed();
  35.       this.sunToolkit = (SunToolkit)Toolkit.getDefaultToolkit();
  36.       this.peer = this.sunToolkit.createRobot(this, var1);
  37.    }
  38.  
  39.    private void checkRobotAllowed() {
  40.       Class var1 = class$java$awt$Robot == null ? (class$java$awt$Robot = class$("java.awt.Robot")) : class$java$awt$Robot;
  41.       synchronized(var1) {
  42.          SecurityManager var2 = System.getSecurityManager();
  43.          AWTPermission var3 = null;
  44.          if (var2 != null) {
  45.             if (var3 == null) {
  46.                var3 = new AWTPermission("createRobot");
  47.             }
  48.  
  49.             var2.checkPermission(var3);
  50.          }
  51.  
  52.       }
  53.    }
  54.  
  55.    private void checkIsScreenDevice(GraphicsDevice var1) {
  56.       if (var1 == null || var1.getType() != 0) {
  57.          throw new IllegalArgumentException("not a valid screen device");
  58.       }
  59.    }
  60.  
  61.    public synchronized void mouseMove(int var1, int var2) {
  62.       this.peer.mouseMove(var1, var2);
  63.       this.afterEvent();
  64.    }
  65.  
  66.    public synchronized void mousePress(int var1) {
  67.       this.checkButtonsArgument(var1);
  68.       this.peer.mousePress(var1);
  69.       this.afterEvent();
  70.    }
  71.  
  72.    public synchronized void mouseRelease(int var1) {
  73.       this.checkButtonsArgument(var1);
  74.       this.peer.mouseRelease(var1);
  75.       this.afterEvent();
  76.    }
  77.  
  78.    private void checkButtonsArgument(int var1) {
  79.       if ((var1 | 28) != 28) {
  80.          throw new IllegalArgumentException("Invalid combination of button flags");
  81.       }
  82.    }
  83.  
  84.    public synchronized void keyPress(int var1) {
  85.       this.checkKeycodeArgument(var1);
  86.       this.peer.keyPress(var1);
  87.       this.afterEvent();
  88.    }
  89.  
  90.    public synchronized void keyRelease(int var1) {
  91.       this.checkKeycodeArgument(var1);
  92.       this.peer.keyRelease(var1);
  93.       this.afterEvent();
  94.    }
  95.  
  96.    private void checkKeycodeArgument(int var1) {
  97.       if (var1 == 0) {
  98.          throw new IllegalArgumentException("Invalid key code");
  99.       }
  100.    }
  101.  
  102.    public synchronized Color getPixelColor(int var1, int var2) {
  103.       Color var3 = new Color(this.peer.getRGBPixel(var1, var2));
  104.       return var3;
  105.    }
  106.  
  107.    public synchronized BufferedImage createScreenCapture(Rectangle var1) {
  108.       checkScreenCaptureAllowed();
  109.       checkValidRect(var1);
  110.       if (this.screenCapCM == null) {
  111.          this.screenCapCM = new DirectColorModel(24, 16711680, 65280, 255);
  112.       }
  113.  
  114.       int[] var6 = new int[3];
  115.       int[] var5 = this.peer.getRGBPixels(var1);
  116.       DataBufferInt var3 = new DataBufferInt(var5, var5.length);
  117.       var6[0] = this.screenCapCM.getRedMask();
  118.       var6[1] = this.screenCapCM.getGreenMask();
  119.       var6[2] = this.screenCapCM.getBlueMask();
  120.       WritableRaster var4 = Raster.createPackedRaster(var3, var1.width, var1.height, var1.width, var6, (Point)null);
  121.       BufferedImage var2 = new BufferedImage(this.screenCapCM, var4, false, (Hashtable)null);
  122.       return var2;
  123.    }
  124.  
  125.    private static void checkValidRect(Rectangle var0) {
  126.       if (var0.width <= 0 || var0.height <= 0) {
  127.          throw new IllegalArgumentException("Rectangle width and height must be > 0");
  128.       }
  129.    }
  130.  
  131.    private static void checkScreenCaptureAllowed() {
  132.       Class var0 = class$java$awt$Robot == null ? (class$java$awt$Robot = class$("java.awt.Robot")) : class$java$awt$Robot;
  133.       synchronized(var0) {
  134.          SecurityManager var1 = System.getSecurityManager();
  135.          if (var1 != null) {
  136.             if (readDisplayPixelsPermission == null) {
  137.                readDisplayPixelsPermission = new AWTPermission("readDisplayPixels");
  138.             }
  139.  
  140.             var1.checkPermission(readDisplayPixelsPermission);
  141.          }
  142.  
  143.       }
  144.    }
  145.  
  146.    private void afterEvent() {
  147.       this.autoWaitForIdle();
  148.       this.autoDelay();
  149.    }
  150.  
  151.    public synchronized boolean isAutoWaitForIdle() {
  152.       return this.isAutoWaitForIdle;
  153.    }
  154.  
  155.    public synchronized void setAutoWaitForIdle(boolean var1) {
  156.       this.isAutoWaitForIdle = var1;
  157.    }
  158.  
  159.    private void autoWaitForIdle() {
  160.       if (this.isAutoWaitForIdle) {
  161.          this.waitForIdle();
  162.       }
  163.  
  164.    }
  165.  
  166.    public synchronized int getAutoDelay() {
  167.       return this.autoDelay;
  168.    }
  169.  
  170.    public synchronized void setAutoDelay(int var1) {
  171.       this.checkDelayArgument(var1);
  172.       this.autoDelay = var1;
  173.    }
  174.  
  175.    private void autoDelay() {
  176.       this.delay(this.autoDelay);
  177.    }
  178.  
  179.    public synchronized void delay(int var1) {
  180.       this.checkDelayArgument(var1);
  181.  
  182.       try {
  183.          Thread.sleep((long)var1);
  184.       } catch (InterruptedException var3) {
  185.          ((Throwable)var3).printStackTrace();
  186.       }
  187.  
  188.    }
  189.  
  190.    private void checkDelayArgument(int var1) {
  191.       if (var1 < 0 || var1 > 60000) {
  192.          throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
  193.       }
  194.    }
  195.  
  196.    public synchronized void waitForIdle() {
  197.       this.checkNotDispatchThread();
  198.  
  199.       try {
  200.          this.sunToolkit.flushPendingEvents();
  201.          EventQueue.invokeAndWait(new 1(this));
  202.       } catch (InterruptedException var3) {
  203.          System.err.println("Robot.waitForIdle, non-fatal exception caught:");
  204.          ((Throwable)var3).printStackTrace();
  205.       } catch (InvocationTargetException var4) {
  206.          System.err.println("Robot.waitForIdle, non-fatal exception caught:");
  207.          var4.printStackTrace();
  208.       }
  209.  
  210.    }
  211.  
  212.    private void checkNotDispatchThread() {
  213.       if (EventQueue.isDispatchThread()) {
  214.          throw new IllegalThreadStateException("Cannot call method from the event dispatcher thread");
  215.       }
  216.    }
  217.  
  218.    public synchronized String toString() {
  219.       String var1 = "autoDelay = " + this.getAutoDelay() + ", " + "autoWaitForIdle = " + this.isAutoWaitForIdle();
  220.       return this.getClass().getName() + "[ " + var1 + " ]";
  221.    }
  222.  
  223.    // $FF: synthetic method
  224.    static Class class$(String var0) {
  225.       try {
  226.          return Class.forName(var0);
  227.       } catch (ClassNotFoundException var2) {
  228.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  229.       }
  230.    }
  231. }
  232.