コード例 #1
0
ファイル: Canvas.java プロジェクト: AnthonyCalandra/SwiftSnap
  @Override
  public void mouseReleased(MouseEvent e) {
    // Is there a final point? At this stage, this means a rectangle is constructed.
    if (finalX > 0 && finalY > 0) {
      String dialogMsg = "Would you like to crop the image to the specified size?";
      int doCrop =
          JOptionPane.showConfirmDialog(
              null, dialogMsg, "SwiftSnap", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
      // If the user decides to crop the image using the rectangle...
      if (doCrop == JOptionPane.YES_OPTION) {
        // Crop and save the image.
        Screenshot.crop(new Rectangle(initialX, initialY, finalX - initialX, finalY - initialY));
        Screenshot.save();
        window.destroyWindow();
      }
    }

    // Reset some values and clear the canvas.
    initialX = 0;
    initialY = 0;
    finalX = 0;
    finalY = 0;
    clearCanvas = true;
    repaint();
  }
コード例 #2
0
ファイル: Canvas.java プロジェクト: AnthonyCalandra/SwiftSnap
  @Override
  public void paintComponent(Graphics g) {
    // Set the brush color.
    g.setColor(new Color(255, 0, 0, 128));
    // If the canvas is requested to be cleared, clear the screen.
    if (clearCanvas) {
      g.clearRect(0, 0, totalScreenWidth, totalScreenHeight);
      clearCanvas = false;
    }

    g.drawImage(Screenshot.getLastScreenshot(), 0, 0, this);
    g.setFont(new Font("Arial", Font.PLAIN, 20));
    g.drawString("Set a point and drag your mouse to create a rectangle.", 50, 50);

    // If there is a final (which implies an initial as well) point.
    if (finalX > 0 && finalY > 0) {
      // Get the point to start drawing and the size of the rectangle.
      g.drawRect(initialX, initialY, finalX - initialX, finalY - initialY);
    } else if (initialX > 0 && initialY > 0) { // Initial points set only?
      // Draw the initial point.
      g.fillRect(initialX, initialY, 5, 5);
    }
  }
コード例 #3
0
 @Test
 public void a_failing_screenshot_records_the_error_message() {
   Screenshot screenshot =
       new Screenshot("step_1.png", "Step 1", 800, new AssertionError("Element not found"));
   assertThat(screenshot.getErrorMessage(), is("Element not found"));
 }
コード例 #4
0
 @Test
 public void a_screenshot_without_an_error_message__returns_an_empty_string() {
   Screenshot screenshot = new Screenshot("step_1.png", "Step 1", 800);
   assertThat(screenshot.getErrorMessage(), is(""));
 }