Package org.sikuli.api

Source Code of org.sikuli.api.DefaultScreenLocation

package org.sikuli.api;

import org.sikuli.api.robot.desktop.DesktopScreen;

import com.google.common.base.Objects;

public class DefaultScreenLocation implements ScreenLocation {

  private int x = 0;
  private int y = 0;
  private Screen screen;


  /**
   * Create a new screen location on a given screen (screenRef)
   * at the coordinate specified by x and y.
   */
  public DefaultScreenLocation(Screen screenRef, int x, int y){
    setX(x);
    setY(y);
    screen = screenRef;
  }

  /**
   * Create a new screen location based on the coordinates. The screen
   * relating to those coordinates will be determined automatically and
   * defaults to screen 0 in case those coordinates are outside of all
   * screens.
   */
  public DefaultScreenLocation(int x, int y) {
    this.x=x;
    this.y=y;
    this.screen= DesktopScreen.getScreenAtCoord(x, y);
    if (this.screen==null) {
      this.screen=new DesktopScreen(0);
    }
  }

  public DefaultScreenLocation(ScreenLocation loc){
    setX(loc.getX());
    setY(loc.getY());
    screen = loc.getScreen();
  }

  public ScreenLocation getRelativeScreenLocation(int xoffset, int yoffset){
    ScreenLocation loc =  new DefaultScreenLocation(screen, getX() + xoffset, getY() + yoffset);
    loc.setScreen(screen);
    return loc;
  }

  public String toString(){
    return Objects.toStringHelper(getClass().getName()).add("x",x).add("y",y)
        .add("screen",screen).toString();
  }

  @Override
  public Screen getScreen() {
    return screen;
  }

  @Override
  public void setScreen(Screen screen) {
    this.screen = screen;
  }

  @Override
  public int getX() {
    return x;
  }

  @Override
  public void setX(int x) {
    this.x = x;
  }

  @Override
  public int getY() {
    return y;
  }

  @Override
  public void setY(int y) {
    this.y = y;
  }
}
TOP

Related Classes of org.sikuli.api.DefaultScreenLocation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.