Exemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(350);

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            createAndShowGUI();
          }
        });

    robot.waitForIdle();

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            spane.requestFocus();
            sbar.setValue(sbar.getMaximum());
          }
        });

    robot.waitForIdle();

    Point point = getClickPoint(0.5, 0.5);
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);

    robot.waitForIdle();

    SwingUtilities.invokeAndWait(
        new Runnable() {

          public void run() {
            final int oldValue = sbar.getValue();
            sbar.addAdjustmentListener(
                new AdjustmentListener() {

                  public void adjustmentValueChanged(AdjustmentEvent e) {
                    if (e.getValue() >= oldValue) {
                      passed = false;
                    }
                    do_test = true;
                  }
                });
          }
        });

    robot.waitForIdle();

    point = getClickPoint(0.5, 0.2);
    robot.mouseMove(point.x, point.y);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    if (!do_test || !passed) {
      throw new Exception("The scrollbar moved with incorrect direction");
    }
  }
Exemplo n.º 2
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
Exemplo n.º 3
0
 public void drawTo(Point start, Point end) {
   robot.mouseMove((int) start.getX(), (int) start.getY());
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(100);
   robot.mouseMove((int) end.getX(), (int) end.getY());
   robot.delay(100);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
   robot.delay(100);
 }
Exemplo n.º 4
0
  /**
   * Runs a sample test procedure
   *
   * @param robot the robot attached to the screen device
   */
  public static void runTest(Robot robot) {
    // simulate a space bar press
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a tab key followed by a space
    robot.delay(2000);
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(' ');
    robot.keyRelease(' ');

    // simulate a mouse click over the rightmost button
    robot.delay(2000);
    robot.mouseMove(200, 50);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    // capture the screen and show the resulting image
    robot.delay(2000);
    BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 400, 300));

    ImageFrame frame = new ImageFrame(image);
    frame.setVisible(true);
  }
Exemplo n.º 5
0
  public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(new NimbusLookAndFeel());

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            createAndShowGUI();
          }
        });

    toolkit.realSync();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            Component previewPanel =
                Util.findSubComponent(cc, "javax.swing.colorchooser.DefaultPreviewPanel");
            point = previewPanel.getLocationOnScreen();
          }
        });

    point.translate(5, 5);

    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
  }
  public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }
Exemplo n.º 7
0
  // recenter the mouse using the robot
  public synchronized void recenterMouse() {
    Window w = s.getFullScreenWindow();

    if (robot != null && w.isShowing()) {
      center.x = w.getWidth() / 2;
      center.y = w.getHeight() / 2;

      SwingUtilities.convertPointToScreen(center, w);
      centering = true;
      robot.mouseMove(center.x, center.y);
    }
  }
  public static void main(String s[]) {

    // Getting save directory
    String saveDir;
    if (s.length > 0) {
      saveDir = s[0];
    } else {
      saveDir =
          JOptionPane.showInputDialog(
              null,
              "Please enter directory where "
                  + "the images is/will be saved\n\n"
                  + "Also possible to specifiy as argument 1 when "
                  + "running this program.",
              "l:\\webcamtest");
    }

    String layout = "";
    if (s.length > 1) {
      layout = s[1];
    }

    // Move mouse to the point 5000,5000 px (out of the screen)
    Robot rob;
    try {
      rob = new Robot();
      rob.setAutoDelay(500); // 0,5 s
      rob.mouseMove(5000, 5000);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    // Make the main window
    JFrame frame = new JFrame();
    frame.setAlwaysOnTop(true);
    frame.setTitle(
        "Webcam capture and imagefading - "
            + "Vitenfabrikken Jærmuseet - "
            + "made by Hallvard Nygård - "
            + "Vitenfabrikken.no / Jaermuseet.no");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setUndecorated(true);

    WebcamCaptureAndFadePanel panel = new WebcamCaptureAndFadePanel(saveDir, layout);
    frame.getContentPane().add(panel);
    frame.addKeyListener(panel);
    frame.pack();

    frame.setVisible(true);
  }
  public void ClickingLogic(int Ammount, int delay) {
    robot.mouseMove(var_coordX, var_coordY);
    robot.setAutoDelay(40);
    robot.setAutoWaitForIdle(true);

    for (int i = 0; i < Ammount; i++) {
      // robot.mouseMove(var_coordX,var_coordY); to include or not to include
      robot.delay(delay);
      robot.mousePress(InputEvent.BUTTON1_MASK);
      robot.mouseRelease(InputEvent.BUTTON1_MASK);
      var_ammount++;
      scene_ClickCount.setText(String.valueOf(var_ammount));
    }
  }
Exemplo n.º 10
0
  public static void main(String[] args) throws Exception {

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    Robot robot = new Robot();
    robot.setAutoDelay(20);
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            // just to quickly grab a column model
            JTable table = new JTable(10, 5);
            header = new JTableHeader(table.getColumnModel());
            checkColumn(0, "A");
            JFrame frame = new JFrame("standalone header");
            frame.add(header);
            frame.pack();
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }
        });
    robot.waitForIdle();
    Point point = header.getLocationOnScreen();
    robot.mouseMove(point.x + 3, point.y + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    for (int i = 0; i < header.getWidth() - 3; i++) {
      robot.mouseMove(point.x + i, point.y + 3);
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            TableColumnModel model = header.getColumnModel();
            checkColumn(model.getColumnCount() - 1, "A");
          }
        });
  }
Exemplo n.º 11
0
 private void moveMousePointerOnButton(final JButton button) {
   Application application = ApplicationManager.getApplication();
   if (application != null && application.hasComponent(UISettings.class)) {
     if (button != null && UISettings.getInstance().MOVE_MOUSE_ON_DEFAULT_BUTTON) {
       Point p = button.getLocationOnScreen();
       Rectangle r = button.getBounds();
       try {
         Robot robot = new Robot();
         robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2);
       } catch (AWTException e) {
         LOG.warn(e);
       }
     }
   }
 }
Exemplo n.º 12
0
  // We need in this constructor to pass frame position between JVMs
  public FileListBetweenJVMsTest(
      Point targetFrameLocation, Point dragSourcePoint, int transferredFilesNumber)
      throws InterruptedException {
    TargetFileListFrame targetFrame =
        new TargetFileListFrame(targetFrameLocation, transferredFilesNumber);

    Util.waitForIdle(null);

    final Robot robot = Util.createRobot();

    robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
    sleep(100);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    sleep(100);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    sleep(100);

    Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(), InputEvent.BUTTON1_MASK);
  }
  public static void main(String[] args) throws Exception {
    DatagramSocket serverSocket = new DatagramSocket(8083);
    int count = 0;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int middleOfScreenX = (int) Math.round(screenSize.getWidth() / 2);
    int middleOfScreenY = (int) Math.round(screenSize.getHeight() / 2);

    System.out.println("Server started");
    byte[] receiveData = new byte[128];
    Robot robot = new Robot();
    while (true) {
      DatagramPacket receivedPacket = new DatagramPacket(receiveData, receiveData.length);
      serverSocket.receive(receivedPacket);

      SenderObject senderObject = SenderObject.parseFrom(receivedPacket.getData());
      float y = senderObject.getY();
      float x = senderObject.getX();
      int type = senderObject.getType();
      System.out.println(senderObject.toString());
      // Get the current pointer location.
      Point mousePointer = MouseInfo.getPointerInfo().getLocation();

      // Check if the type is mouse click.
      if (type == 2) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
      }
      // otherwise move the mouse pointer by subtracting to current
      // coordinates. Subtraction, because of the flipped right and left.
      else {
        float curX = mousePointer.x - x;
        float curY = mousePointer.y - y;
        robot.mouseMove(Math.round(curX), Math.round(curY));
      }
    }
  }
Exemplo n.º 14
0
 @Override
 public void operate(Robot robot) {
   robot.mouseMove(x, y);
 }
Exemplo n.º 15
0
 private static void move(Robot robot, int x, int y) {
   robot.mouseMove(x, y);
   LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
 }
Exemplo n.º 16
0
 public void setLocation(Point location) {
   robot.mouseMove((int) location.getX(), (int) location.getY());
 }
Exemplo n.º 17
0
  public static void main(String[] args) throws Throwable {

    sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            test = new TaskbarPositionTest();
          }
        });

    // Use Robot to automate the test
    Robot robot;
    robot = new Robot();
    robot.setAutoDelay(125);

    // 1 - menu
    Util.hitMnemonics(robot, KeyEvent.VK_1);

    toolkit.realSync();
    isPopupOnScreen(menu1.getPopupMenu(), screenBounds);

    // 2 menu with sub menu
    robot.keyPress(KeyEvent.VK_RIGHT);
    robot.keyRelease(KeyEvent.VK_RIGHT);
    Util.hitMnemonics(robot, KeyEvent.VK_S);

    toolkit.realSync();
    isPopupOnScreen(menu2.getPopupMenu(), screenBounds);

    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

    // Focus should go to non editable combo box
    toolkit.realSync();
    Thread.sleep(500);

    robot.keyPress(KeyEvent.VK_DOWN);

    // How do we check combo boxes?

    // Editable combo box
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);

    // combo1.getUI();

    // Popup from Text field
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    // Popup from a mouse click.
    Point pt = new Point(2, 2);
    SwingUtilities.convertPointToScreen(pt, panel);
    robot.mouseMove((int) pt.getX(), (int) pt.getY());
    robot.mousePress(InputEvent.BUTTON3_MASK);
    robot.mouseRelease(InputEvent.BUTTON3_MASK);

    toolkit.realSync();
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            test.setLocation(-30, 100);
            combo1.addPopupMenuListener(new ComboPopupCheckListener());
            combo1.requestFocus();
          }
        });

    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);

    toolkit.realSync();
    Thread.sleep(500);
  }
  void test() {

    robot.waitForIdle();

    if (!text.isFocusOwner()) {
      robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5);
      robot.delay(100);
      robot.mousePress(MouseEvent.BUTTON1_MASK);
      robot.delay(100);
      robot.mouseRelease(MouseEvent.BUTTON1_MASK);

      int iter = 10;
      while (!text.isFocusOwner() && iter-- > 0) {
        robot.delay(200);
      }
      if (iter <= 0) {
        Sysout.println("Test: text field couldn't be focused!");
        return;
      }
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    String charA = text.getText();
    System.err.println("Test: character typed with VK_A: " + charA);

    robot.keyPress(KeyEvent.VK_BACK_SPACE);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_BACK_SPACE);

    robot.waitForIdle();

    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyPress(KeyEvent.VK_CONTROL);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_F);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (jdk.testlibrary.OSInfo.getOSType() == jdk.testlibrary.OSInfo.OSType.MACOSX) {
      robot.keyRelease(KeyEvent.VK_CONTROL);
    }

    robot.waitForIdle();

    String string = text.getText();

    robot.keyPress(KeyEvent.VK_I);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_I);

    robot.waitForIdle();

    Sysout.println("Test: character typed after mnemonic key press: " + text.getText());

    if (!text.getText().equals(string)) {
      throw new RuntimeException("Test failed!");
    }

    robot.keyPress(KeyEvent.VK_A);
    robot.delay(100);
    robot.keyRelease(KeyEvent.VK_A);

    robot.waitForIdle();

    System.err.println("Test: chracter typed with VK_A: " + text.getText());

    if (!charA.equals(text.getText())) {
      throw new RuntimeException("Test failed!");
    }

    Sysout.println("Test passed.");
  }
  public static void main(String[] args) throws Exception {

    if (!OS.contains("mac")) {
      System.out.println("The test is applicable only to Mac OS X. Passed");
      return;
    }

    // Move the mouse out, because it could interfere with the test.
    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    r.mouseMove(0, 0);
    Util.waitForIdle(r);

    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            createAndShowGUI();
          }
        });

    // Move the mouse away from the frame and check the View-base full screen mode
    Util.waitForIdle(r);
    r.mouseMove(500, 500);
    Util.waitForIdle(r);
    mouseEnterCount = 0;
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(frame);
          }
        });
    Util.waitForIdle(r);
    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for view-base full screen. Failed.");
    }
    SwingUtilities.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .setFullScreenWindow(null);
          }
        });

    // Test native full screen support
    Util.waitForIdle(r);
    Point fullScreenButtonPos = frame.getLocation();
    fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
    r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
    mouseEnterCount = 0;

    // Cant use waitForIdle for full screen transition.
    int waitCount = 0;
    while (!windowEnteringFullScreen) {
      r.mousePress(InputEvent.BUTTON1_MASK);
      r.mouseRelease(InputEvent.BUTTON1_MASK);
      Thread.sleep(100);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    waitCount = 0;
    while (!windowEnteredFullScreen) {
      Thread.sleep(200);
      if (waitCount++ > 10) throw new RuntimeException("Can't enter full screen mode. Failed");
    }

    if (mouseEnterCount != 1) {
      throw new RuntimeException("No MouseEntered event for native full screen. Failed.");
    }
  }
Exemplo n.º 20
0
  /**
   * @param args
   * @throws AWTException
   */
  public static void main(String[] args) {
    Robot robot;

    // the size of a square on the board
    int cubeSize = 40;
    // the size of the sample to determine a gem's colour
    int sampleSize = 4;

    // the position of the top left of the board (in screen coordinates)
    int gameLeft = 507;
    int gameTop = 345;

    // game length (in milliseconds)
    long gameLength = 63 * 1000;

    // the maximum number of times (in a row) there can be no moves to make
    long noMoveCutoff = 5;

    // the maximum number of gems to move at the same time
    int maxMovesPerRound = 10;

    // save screenshots to disk
    boolean saveScreenshots = false;

    // the extent of the game board
    Rectangle gameRectangle = new Rectangle(gameLeft, gameTop, cubeSize * 8, cubeSize * 8);

    // the robot will move the mouse and perform clicks
    try {
      robot = new Robot();
    } catch (AWTException e) {
      e.printStackTrace();
      return;
    }

    final GameKeyListener frame = new GameKeyListener("Bejeweled AI Player");

    JOptionPane.showConfirmDialog(frame, "Press yes to start...");

    try {
      Thread.sleep(3500);
    } catch (Exception e) {
    }

    BufferedImage gameScreenshot;
    Board board = new Board(cubeSize, sampleSize);
    Move nextMove;

    // the gem colours are stored in a 2D array
    int[][] boardGems;

    // counts the number of times (in a row) no move has been available
    int noMoveCount = 0;
    // the number of screenshots saved to disk
    int screenshotCount = 0;

    long startTime = System.currentTimeMillis();
    long endTime = startTime + gameLength;

    while (System.currentTimeMillis() < endTime) {
      if (noMoveCount > (noMoveCutoff - 1)) {
        System.out.println(noMoveCutoff + " no-move rounds in a row...exiting!");
        System.exit(0);
        return;
      }

      // take a screenshot of the screen
      gameScreenshot = robot.createScreenCapture(gameRectangle);

      if (saveScreenshots) {
        File outputfile = new File("screenshot" + screenshotCount + ".jpg");
        try {
          ImageIO.write(gameScreenshot, "jpg", outputfile);
          screenshotCount++;
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      // figure out the positions of the gems on the board
      boardGems = board.getBoardGemColors(gameScreenshot);

      try {
        // calculate the best moves to make
        LinkedList<Move> moves = Solver.solve(boardGems);

        if (moves.size() > 0) {
          // Reset no-move counter
          noMoveCount = 0;

          int movesToMake = Math.min(moves.size(), maxMovesPerRound);
          for (int i = 0; i < movesToMake; i++) {
            nextMove = moves.get(i);

            robot.mouseMove(
                gameLeft + cubeSize / 2 + cubeSize * nextMove.x1,
                gameTop + cubeSize / 2 + cubeSize * nextMove.y1);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);

            robot.mouseMove(
                gameLeft + cubeSize / 2 + cubeSize * nextMove.x2,
                gameTop + cubeSize / 2 + cubeSize * nextMove.y2);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
          }
        }
      } catch (NoMoveException e) {
        System.out.println("ERROR: No move.");
        noMoveCount++;
        try {
          Thread.sleep(600);
        } catch (Exception e2) {
        }
      }

      java.awt.EventQueue.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              frame.toFront();
              frame.repaint();
            }
          });

      try {
        // Pause a bit to let the game catch up!
        Thread.sleep(300);
      } catch (Exception e) {
      }
    }

    System.exit(0);
  }
Exemplo n.º 21
0
 public void selectTool(Point2D tool) {
   robot.mouseMove((int) tool.getX(), (int) tool.getY());
   robot.mousePress(InputEvent.BUTTON1_MASK);
   robot.delay(100);
   robot.mouseRelease(InputEvent.BUTTON1_MASK);
 }
Exemplo n.º 22
0
 /**
  * Move the mouse on the screen.
  *
  * @param x x position on the screen
  * @param y y position on the screen
  * @see java.awt.Robot#mouseMove(int x, int y)
  */
 public void mouseMove(int x, int y) {
   robot.mouseMove(x, y);
 }
Exemplo n.º 23
0
  private void test(TestState currentState) throws InterruptedException, InvocationTargetException {

    synchronized (LOCK) {
      this.currentState = currentState;
      System.out.println(this.currentState);

      List list;
      if (currentState.getMultiple()) {
        list = multiple;
      } else {
        list = single;
      }

      Robot r;
      try {
        r = new Robot();
      } catch (AWTException e) {
        throw new RuntimeException(e.getMessage());
      }

      r.delay(10);
      Point loc = this.getLocationOnScreen();

      r.mouseMove(loc.x + 10, loc.y + 10);
      r.mousePress(InputEvent.BUTTON1_MASK);
      r.delay(10);
      r.mouseRelease(InputEvent.BUTTON1_MASK);
      r.delay(10);

      list.requestFocusInWindow();
      LOCK.wait(ACTION_TIMEOUT);
      if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() != list) {
        throw new RuntimeException("Test failed - list isn't focus owner.");
      }

      list.deselect(0);
      list.deselect(1);
      list.deselect(2);
      list.deselect(3);
      list.deselect(4);
      list.deselect(5);
      list.deselect(6);
      list.deselect(7);
      list.deselect(8);

      int selectIndex = 0;
      int visibleIndex = 0;

      if (currentState.getScrollMoved()) {

        if (currentState.getKeyID() == KeyEvent.VK_PAGE_UP
            || currentState.getKeyID() == KeyEvent.VK_HOME) {
          selectIndex = 8;
          visibleIndex = 8;
        } else if (currentState.getKeyID() == KeyEvent.VK_PAGE_DOWN
            || currentState.getKeyID() == KeyEvent.VK_END) {
          selectIndex = 0;
          visibleIndex = 0;
        }

      } else {

        if (currentState.getKeyID() == KeyEvent.VK_PAGE_UP
            || currentState.getKeyID() == KeyEvent.VK_HOME) {

          if (currentState.getSelectedMoved()) {
            selectIndex = 1;
            visibleIndex = 0;
          } else {
            selectIndex = 0;
            visibleIndex = 0;
          }

        } else if (currentState.getKeyID() == KeyEvent.VK_PAGE_DOWN
            || currentState.getKeyID() == KeyEvent.VK_END) {

          if (currentState.getSelectedMoved()) {
            selectIndex = 7;
            visibleIndex = 8;
          } else {
            selectIndex = 8;
            visibleIndex = 8;
          }
        }
      }

      list.select(selectIndex);
      list.makeVisible(visibleIndex);

      r.delay(10);

      if (currentState.getKeyID() == KeyEvent.VK_HOME
          || currentState.getKeyID() == KeyEvent.VK_END) {
        r.keyPress(KeyEvent.VK_CONTROL);
      }

      r.delay(10);
      r.keyPress(currentState.getKeyID());
      r.delay(10);
      r.keyRelease(currentState.getKeyID());
      r.delay(10);

      if (currentState.getKeyID() == KeyEvent.VK_HOME
          || currentState.getKeyID() == KeyEvent.VK_END) {
        r.keyRelease(KeyEvent.VK_CONTROL);
      }

      r.waitForIdle();
      r.delay(200);

      if (currentState.getTemplate() != currentState.getAction())
        throw new RuntimeException("Test failed.");
    }
  }