private void testShapesTool() {
    window.toggleButton("Shapes Tool Button").click();
    randomAltClick();

    setupEffectsDialog();
    boolean stokeSettingsSetup = false;

    for (ShapeType shapeType : ShapeType.values()) {
      window.comboBox("shapeTypeCB").selectItem(shapeType.toString());
      for (ShapesAction shapesAction : ShapesAction.values()) {
        window.comboBox("actionCB").selectItem(shapesAction.toString());
        window.pressAndReleaseKeys(KeyEvent.VK_R);

        if (shapesAction == ShapesAction.STROKE) { // stroke settings will be enabled here
          if (!stokeSettingsSetup) {
            setupStrokeSettingsDialog();
            stokeSettingsSetup = true;
          }
        }

        moveRandom();
        dragRandom();

        if (shapesAction == ShapesAction.SELECTION
            || shapesAction == ShapesAction.SELECTION_FROM_STROKE) {
          keyboardDeselect();
        }
      }
    }

    keyboardUndoRedo();
    keyboardUndo();
  }
 private void testMouseWheelZooming() {
   window.pressKey(VK_CONTROL);
   ImageComponent c = ImageComponents.getActiveIC();
   robot.rotateMouseWheel(c, 2);
   robot.rotateMouseWheel(c, -2);
   window.releaseKey(VK_CONTROL);
 }
  private void testClone(boolean aligned, boolean sampleAllLayers, int startX) {
    if (aligned) {
      window.checkBox("alignedCB").check();
    } else {
      window.checkBox("alignedCB").uncheck();
    }

    if (sampleAllLayers) {
      window.checkBox("sampleAllLayersCB").check();
    } else {
      window.checkBox("sampleAllLayersCB").uncheck();
    }

    move(300, 300);

    altClick();

    move(startX, 300);
    for (int i = 1; i <= 5; i++) {
      int x = startX + i * 10;
      drag(x, 300);
      drag(x, 400);
    }
    keyboardUndoRedo();
  }
 @Test
 public void should_Find_Frame_Before_Given_Timeout_Expires() {
   clickLaunchFrameButton();
   FrameFixture found =
       WindowFinder.findFrame(matcher).withTimeout(500, MILLISECONDS).using(robot);
   assertThat(found.target()).isInstanceOf(WindowToLaunch.class);
 }
  private void testColorPickerTool() {
    window.toggleButton("Color Picker Tool Button").click();
    randomAltClick();

    move(300, 300);
    window.click();
    drag(400, 400);
  }
 private void shiftMoveClickRandom() {
   window.pressKey(VK_SHIFT);
   int x = 200 + random.nextInt(400);
   int y = 200 + random.nextInt(400);
   move(x, y);
   click();
   window.releaseKey(VK_SHIFT);
 }
  private void testPaintBucketTool() {
    window.toggleButton("Paint Bucket Tool Button").click();
    randomAltClick();

    move(300, 300);
    window.click();

    keyboardUndoRedo();
    keyboardUndo();
  }
  private void testBrushStrokes() {
    randomAltClick();

    for (BrushType brushType : BrushType.values()) {
      window.comboBox("brushTypeSelector").selectItem(brushType.toString());
      for (Symmetry symmetry : Symmetry.values()) {
        window.comboBox("symmetrySelector").selectItem(symmetry.toString());
        window.pressAndReleaseKeys(KeyEvent.VK_R);
        moveRandom();
        dragRandom();
      }
    }
    keyboardUndoRedo();
  }
  private void testHandTool() {
    window.toggleButton("Hand Tool Button").click();
    randomAltClick();

    moveRandom();
    dragRandom();
  }
  private void testMoveTool() {
    window.toggleButton("Move Tool Button").click();
    testMoveToolImpl(false);
    testMoveToolImpl(true);

    keyboardNudge();
    keyboardUndo();
  }
  private void testCloneTool() {
    window.toggleButton("Clone Stamp Tool Button").click();

    testClone(false, false, 100);
    testClone(false, true, 200);
    testClone(true, false, 300);
    testClone(true, true, 400);
  }
 private void keyboardRedo() {
   // press Ctrl-Shift-Z
   window
       .pressKey(VK_CONTROL)
       .pressKey(VK_SHIFT)
       .pressKey(VK_Z)
       .releaseKey(VK_Z)
       .releaseKey(VK_SHIFT)
       .releaseKey(VK_CONTROL);
 }
  private void testSmudgeTool() {
    window.toggleButton("Smudge Tool Button").click();
    randomAltClick();

    for (int i = 0; i < 3; i++) {
      randomClick();
      shiftMoveClickRandom();
      moveRandom();
      dragRandom();
    }
  }
 @Test
 public void shoulFindOkButton() {
   GenericTypeMatcher<JButton> textMatcher =
       new GenericTypeMatcher<JButton>(JButton.class) {
         @Override
         protected boolean isMatching(JButton button) {
           return "OK".equals(button.getText());
         }
       };
   window.button(textMatcher).requireVisible();
 }
  private void testZoomTool() {
    window.toggleButton("Zoom Tool Button").click();
    move(300, 300);

    click();
    click();
    altClick();
    altClick();

    testMouseWheelZooming();
    testControlPlusMinusZooming();
  }
  private void testSelectionToolAndMenus() {
    window.toggleButton("Selection Tool Button").click();
    randomAltClick();

    move(200, 200);
    drag(400, 400);
    keyboardNudge();
    keyboardUndo();

    // window.button("brushTraceButton").click();
    findButtonByText(window, "Stroke with Current Brush").click();

    keyboardDeselect();
    keyboardUndo(); // keyboardUndo deselection
    keyboardUndo(); // keyboardUndo tracing
    window.comboBox("selectionTypeCombo").selectItem("Ellipse");
    move(200, 200);
    drag(400, 400);
    window.comboBox("selectionInteractionCombo").selectItem("Add");
    move(400, 200);
    drag(500, 300);

    // window.button("eraserTraceButton").click();
    findButtonByText(window, "Stroke with Current Eraser").click();

    // crop from this selection tool
    findButtonByText(window, "Crop").click();
    keyboardUndo();

    // crop from the menu
    runMenuCommand("Crop");
    keyboardUndo();

    testSelectionModifyMenu();

    runMenuCommand("Invert Selection");
    runMenuCommand("Stroke with Current Brush");
    runMenuCommand("Stroke with Current Eraser");
    runMenuCommand("Deselect");
  }
 @Override
 protected void onSetUp() {
   JFrame frame =
       GuiActionRunner.execute(
           new GuiQuery<JFrame>() {
             @Override
             protected JFrame executeInEDT() {
               return new TableFrame();
             }
           });
   window = new FrameFixture(robot(), frame);
   window.show();
 }
  private void testSelectionModifyMenu() {
    window.toggleButton("Selection Tool Button").click();
    randomAltClick();

    move(200, 200);
    drag(400, 400);

    runMenuCommand("Modify...");
    DialogFixture dialog = findDialogByTitle("Modify Selection");

    findButtonByText(dialog, "Change!").click();
    findButtonByText(dialog, "Change!").click();
    findButtonByText(dialog, "Close").click();

    keyboardUndoRedo();
    keyboardUndo();
  }
  private void testCropTool() {
    window.toggleButton("Crop Tool Button").click();
    move(200, 200);
    drag(400, 400);
    drag(450, 450);
    move(200, 200);
    drag(150, 150);
    sleep(1, SECONDS);

    keyboardNudge();
    keyboardUndo();

    randomAltClick(); // must be at the end, otherwise it tries to start a rectangle

    findButtonByText(window, "Crop").click();

    keyboardUndoRedo();
    keyboardUndo();
  }
  private void testEditMenu() {
    keyboardInvert();
    runMenuCommand("Repeat Invert");
    runMenuCommand("Undo Invert");
    runMenuCommand("Redo Invert");
    testFilterWithDialog("Fade Invert", Randomize.NO, ShowOriginal.YES);

    // select for crop
    window.toggleButton("Selection Tool Button").click();
    move(200, 200);
    drag(400, 400);
    runMenuCommand("Crop");
    keyboardUndo();
    keyboardDeselect();

    testCopyPaste();

    testResize();
    testRotateFlip();

    testFilterWithDialog("Transform Layer...", Randomize.YES, ShowOriginal.YES);

    testPreferences();
  }
  private void testGradientTool() {
    window.toggleButton("Gradient Tool Button").click();
    randomAltClick();

    for (GradientType gradientType : GradientType.values()) {
      window.comboBox("gradientTypeSelector").selectItem(gradientType.toString());
      for (String cycleMethod : GradientTool.CYCLE_METHODS) {
        window.comboBox("gradientCycleMethodSelector").selectItem(cycleMethod);
        GradientColorType[] gradientColorTypes = GradientColorType.values();
        for (GradientColorType colorType : gradientColorTypes) {
          window.comboBox("gradientColorTypeSelector").selectItem(colorType.toString());
          window.checkBox("gradientInvert").uncheck();
          move(200, 200);
          drag(400, 400);
          window.checkBox("gradientInvert").check();
          move(200, 200);
          drag(400, 400);
        }
      }
    }
    keyboardUndoRedo();
  }
 private void keyboardNudge() {
   // TODO for some reason the shift is not detected
   window.pressKey(VK_SHIFT).pressKey(VK_RIGHT).releaseKey(VK_RIGHT).releaseKey(VK_SHIFT);
 }
 private void pressCtrlNumpadPlus() {
   window.pressKey(VK_CONTROL).pressKey(VK_ADD).releaseKey(VK_ADD).releaseKey(VK_CONTROL);
 }
 private void pressCtrlMinus() {
   window.pressKey(VK_CONTROL).pressKey(VK_MINUS).releaseKey(VK_MINUS).releaseKey(VK_CONTROL);
 }
 private void testBrushTool() {
   window.toggleButton("Brush Tool Button").click();
   testBrushStrokes();
 }
 private void keyboardUndo() {
   // press Ctrl-Z
   window.pressKey(VK_CONTROL).pressKey(VK_Z).releaseKey(VK_Z).releaseKey(VK_CONTROL);
 }
 private void keyboardInvert() {
   // press Ctrl-I
   window.pressKey(VK_CONTROL).pressKey(VK_I).releaseKey(VK_I).releaseKey(VK_CONTROL);
 }
 private void keyboardDeselect() {
   // press Ctrl-D
   window.pressKey(VK_CONTROL).pressKey(VK_D).releaseKey(VK_D).releaseKey(VK_CONTROL);
 }
 private void keyboardActualPixels() {
   // press Ctrl-0
   window.pressKey(VK_CONTROL).pressKey(VK_0).releaseKey(VK_0).releaseKey(VK_CONTROL);
 }
 private void altDrag(int x, int y) {
   window.pressKey(VK_ALT);
   drag(x, y);
   window.releaseKey(VK_ALT);
 }