Class Element

java.lang.Object
org.sikuli.script.Element
Direct Known Subclasses:
Image, Region

public abstract class Element
extends Object
INTERNAL: An abstract super-class for Region and Image.

BE AWARE: This class cannot be used as such (cannot be instantiated)
... instead use the classes Region or Image as needed

NOTES:
- the classname might change in the future without notice
- the intention is, to have only one implementation for features, that are the same for Region and Image
- the implementation here is ongoing beginning with version 2.0.2 and hence not complete yet
- you might get not-implemented exceptions until complete
  • Field Details

  • Constructor Details

  • Method Details

    • log

      protected static void log​(int level, String message, Object... args)
    • returnThis

      protected Element returnThis()
    • getX

      public int getX()
      Returns:
      x of top left corner
    • getY

      public int getY()
      Returns:
      y of top left corner
    • getW

      public int getW()
      Returns:
      width of region/image
    • getH

      public int getH()
      Returns:
      height of region/image
    • isEmpty

      protected boolean isEmpty()
    • getName

      public String getName()
      INTERNAL: to identify a Region or Image
      Returns:
      the name
    • setName

      public void setName​(String name)
      INTERNAL: to identify a Region or Image
      Parameters:
      name - to be used
    • setImageMissingHandler

      protected void setImageMissingHandler​(Object handler)
    • find

      public <PSI> Match find​(PSI target) throws FindFailed
      finds the given Pattern, String or Image in the region and returns the best match.
      Type Parameters:
      PSI - Pattern, String or Image
      Parameters:
      target - what (PSI) to find in this Region
      Returns:
      If found, the element. null otherwise
      Throws:
      FindFailed - if the Find operation failed
    • text

      public String text()
      tries to read the text in this region/image
      might contain misread characters, NL characters and other stuff, when interpreting contained grafics as text
      Best results: one or more lines of text with no contained grafics
      Returns:
      the text read (utf8 encoded)
    • textLine

      public String textLine()
      get text from this region/image supposing it is one line of text
      Returns:
      the text or empty string
    • textWord

      public String textWord()
      get text from this region/image supposing it is one word
      Returns:
      the text or empty string
    • textChar

      public String textChar()
      get text from this region/image supposing it is one character
      Returns:
      the text or empty string
    • textLines

      public List<String> textLines()
      find text lines in this region/image
      Returns:
      list of strings each representing one line of text
    • textWords

      public List<String> textWords()
      find the words as text in this region/image (top left to bottom right)
      a word is a sequence of detected utf8-characters surrounded by significant background space might contain characters misinterpreted from contained grafics
      Returns:
      list of strings each representing one word
    • findLines

      public List<Match> findLines()
      Find all lines as text (top left to bottom right) in this Region or Image
      Returns:
      a list of text Matches or empty list if not found
    • findWords

      public List<Match> findWords()
      Find all words as text (top left to bottom right)
      Returns:
      a list of text matches
    • findWord

      public Match findWord​(String word)
      Find the first word as text (top left to bottom right) containing the given text
      Parameters:
      word - to be searched
      Returns:
      a text match or null if not found
    • findWords

      public List<Match> findWords​(String word)
      Find all words as text (top left to bottom right) containing the given text
      Parameters:
      word - to be searched
      Returns:
      a list of text matches
    • findLine

      public Match findLine​(String text)
      Find the first line as text (top left to bottom right) containing the given text
      Parameters:
      text - the line should contain
      Returns:
      a text match or null if not found
    • findLines

      public List<Match> findLines​(String text)
      Find all lines as text (top left to bottom right) containing the given text
      Parameters:
      text - the lines should contain
      Returns:
      a list of text matches or empty list if not found
    • findText

      public Match findText​(String text) throws FindFailed
      Throws:
      FindFailed
    • findT

      public Match findT​(String text) throws FindFailed
      Throws:
      FindFailed
    • existsText

      public Match existsText​(String text)
    • existsT

      public Match existsT​(String text)
    • hasText

      public boolean hasText​(String text)
    • hasT

      public boolean hasT​(String text)
    • findAllText

      public List<Match> findAllText​(String text)
    • findAllT

      public List<Match> findAllT​(String text)
    • getImageFromTarget

      public static <PSI> Image getImageFromTarget​(PSI target)
      INTERNAL: get Image from target
      Type Parameters:
      PSI - Pattern, Filename, Image, ScreenImage
      Parameters:
      target - what(PSI) to search
      Returns:
      Image object
    • getBufferedImage

      protected static <SFIRBS> BufferedImage getBufferedImage​(SFIRBS whatEver)
    • getImage

      protected Image getImage()
    • relocate

      protected List<Match> relocate​(List<Match> matches)
    • relocate

      protected Match relocate​(Match match)
    • getLastMatch

      public Match getLastMatch()
      a find operation saves its match on success in this region/image.
      ... unchanged if not successful
      Returns:
      the Match object from last successful find
    • getLastMatches

      public Iterator<Match> getLastMatches()
      a searchAll operation saves its matches on success in this region/image
      ... unchanged if not successful
      Returns:
      a Match-Iterator of matches from last successful searchAll
    • collectLines

      public List<Match> collectLines()
      Deprecated.
      use findLines() instead
      Returns:
      a list of matches
      See Also:
      findLines()
    • collectLinesText

      @Deprecated public List<String> collectLinesText()
      Deprecated.
      use textLines() instead
      Returns:
      a list of lines as strings
      See Also:
      textLines()
    • collectWords

      @Deprecated public List<Match> collectWords()
      Deprecated.
      use findWords() instead
      Returns:
      a list of matches
      See Also:
      findWords()
    • collectWordsText

      @Deprecated public List<String> collectWordsText()
      Deprecated.
      use textWords() instead
      Returns:
      a list of words sa strings
      See Also:
      textWords()