Java Code Examples for org.sikuli.script.Region#create()

The following examples show how to use org.sikuli.script.Region#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorRegionButton.java    From SikuliX1 with MIT License 6 votes vote down vote up
private BufferedImage getRegionImage(int x, int y, int w, int h) {
  Region region = Region.create(x, y, w, h);
  IScreen _screen = region.getScreen();
  ScreenImage simg = _screen.capture();
  int scr_w = simg.w, scr_h = simg.h;
  int max_h = 80; // FIXME: put max_h in UserPreferences
  float scale = (float) max_h / scr_h;
  scr_w *= scale;
  scr_h *= scale;
  BufferedImage screen = new BufferedImage(scr_w, scr_h, BufferedImage.TYPE_INT_RGB);
  Graphics2D screen_g2d = screen.createGraphics();
  try {
    screen_g2d.drawImage(simg.getBufferedImage(), 0, 0, scr_w, scr_h, null);
    int sx = (int) ((x - simg.x) * scale), sy = (int) ((y - simg.y) * scale),
            sw = (int) (w * scale), sh = (int) (h * scale);
    screen_g2d.setColor(new Color(255, 0, 0, 150));
    screen_g2d.fillRect(sx, sy, sw, sh);
  } catch (RasterFormatException e) {
    Debug.error(me + "getRegionImage: Problem making image\n%s", e.getMessage());
  }
  screen_g2d.dispose();
  return screen;
}
 
Example 2
Source File: PropertyEditor.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private List<Shape> getMatchesList() {
    List<Shape> rMatches = new ArrayList<>();
    try {
        Iterator<?> it = getMatches();
        if (it != null) {
            Region sRegion = Region.create(shapes.get(0).getBounds());
            while (it.hasNext()) {
                Object region = it.next();
                Shape rx = ((Region) region).getRect();
                if (sRegion != null && sRegion.getRect().contains(rx.getBounds())) {
                    rMatches.add(rx);
                }
            }
        }

    } catch (FindFailed | IOException | NullPointerException ex) {
        Logger.getLogger(PropertyEditor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return rMatches;
}
 
Example 3
Source File: SxCircle.java    From SikuliX1 with MIT License 5 votes vote down vote up
private void init(Region region) {
  if (region != null) {
    targetRegion = region;
  } else {
    Debug.log(2, "SikuliGuideRectangle: targetRegion is given as null");
    targetRegion = Region.create(0, 0, 2*stroke, 2*stroke);
  }
  setColor(Color.RED);
}
 
Example 4
Source File: SxRectangle.java    From SikuliX1 with MIT License 5 votes vote down vote up
private void init(Region region) {
  if (region != null) {
    targetRegion = region;
  } else {
    Debug.log(2, "SikuliGuideRectangle: targetRegion is given as null");
    targetRegion = Region.create(0, 0, 2*stroke, 2*stroke);
  }
  setColor(Color.RED);
}
 
Example 5
Source File: DragAndDrop.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
/**
 * Drag and drop to the given location
 */
@Action(object = ObjectType.IMAGE, 
		desc =" Drag an image [<Object>] and drop it in a user-defined region [<Data>]", 
		input =InputType.YES)
public void imgDragandDropAt() {

    try {
        int x = Integer.valueOf(Data.split(",", -1)[0]), y = Integer
                .valueOf(Data.split(",", -1)[1]), width = Integer
                .valueOf(Data.split(",", -1)[2]), height = Integer
                .valueOf(Data.split(",", -1)[3]);
        target = findTarget(imageObjectGroup, Flag.SET_OFFSET, Flag.MATCH_ONLY);
        droptarget = Region.create(x, y, width, height);

        if (target != null) {
            if (SCREEN.dragDrop(target, droptarget) == 1) {
                Report.updateTestLog(Action,
                        "Draged image " + ObjectName + " and Dropped at given location", Status.DONE);
                return;
            }
        }
        Report.updateTestLog(Action,
                ObjectName
                + (imageObjectGroup.isLeaf() ? ExceptionType.Empty_Group : ExceptionType.Not_Found_on_Screen),
                Status.FAIL);
    } catch (Exception ex) {
        Report.updateTestLog(Action,
                ex.getMessage(), Status.DEBUG);
        Logger.getLogger(DragAndDrop.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example 6
Source File: Visual.java    From SikuliX1 with MIT License 4 votes vote down vote up
public Region getRegion() {
  return Region.create(getBounds());
}
 
Example 7
Source File: VNCScreen.java    From SikuliX1 with MIT License 4 votes vote down vote up
public Region newRegion(int x, int y, int w, int h) {
  Region reg = Region.create(x, y, w, h, this);
  reg.setOtherScreen(this);
  return reg;
}