Package org.sikuli.script
Class Element
- java.lang.Object
-
- org.sikuli.script.Element
-
public abstract class Element extends Object
INTERNAL: An abstract super-class forRegionandImage.
BE AWARE: This class cannot be used as such (cannot be instantiated)
NOTES:
... instead use the classes Region or Image as needed
- 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 Summary
Fields Modifier and Type Field Description inthHeight of the Region/Imageprotected ObjectimageMissingHandlerprotected longlastFindTimeprotected MatchlastMatchThe last foundMatchin the Regionprotected Iterator<Match>lastMatchesThe last foundMatches in the Regionprotected longlastSearchTimeprotected longlastSearchTimeRepeatprotected static intlogLevelintwWidth of the Region/ImageintxX-coordinate of the Region (ignored for Image)intyY-coordinate of the Region (ignored for Image)
-
Constructor Summary
Constructors Constructor Description Element()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<Match>collectLines()Deprecated.use findLines() insteadList<String>collectLinesText()Deprecated.use textLines() insteadList<Match>collectWords()Deprecated.use findWords() insteadList<String>collectWordsText()Deprecated.use textWords() insteadMatchexistsT(String text)MatchexistsText(String text)<PSI> Matchfind(PSI target)finds the given Pattern, String or Image in the region and returns the best match.List<Match>findAllT(String text)List<Match>findAllText(String text)MatchfindLine(String text)Find the first line as text (top left to bottom right) containing the given textList<Match>findLines()List<Match>findLines(String text)Find all lines as text (top left to bottom right) containing the given textMatchfindT(String text)MatchfindText(String text)MatchfindWord(String word)Find the first word as text (top left to bottom right) containing the given textList<Match>findWords()Find all words as text (top left to bottom right)List<Match>findWords(String word)Find all words as text (top left to bottom right) containing the given textprotected static <SFIRBS> BufferedImagegetBufferedImage(SFIRBS whatEver)intgetH()protected ImagegetImage()static <PSI> ImagegetImageFromTarget(PSI target)INTERNAL: get Image from targetMatchgetLastMatch()a find operation saves its match on success in this region/image.Iterator<Match>getLastMatches()a searchAll operation saves its matches on success in this region/image
... unchanged if not successfulStringgetName()INTERNAL: to identify a Region or ImageintgetW()intgetX()intgetY()booleanhasT(String text)booleanhasText(String text)protected booleanisEmpty()protected static voidlog(int level, String message, Object... args)protected List<Match>relocate(List<Match> matches)protected Matchrelocate(Match match)protected ElementreturnThis()protected voidsetImageMissingHandler(Object handler)voidsetName(String name)INTERNAL: to identify a Region or ImageStringtext()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 graficsStringtextChar()get text from this region/image supposing it is one characterStringtextLine()get text from this region/image supposing it is one line of textList<String>textLines()find text lines in this region/imageStringtextWord()get text from this region/image supposing it is one wordList<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
-
-
-
Field Detail
-
logLevel
protected static final int logLevel
- See Also:
- Constant Field Values
-
x
public int x
X-coordinate of the Region (ignored for Image)
-
y
public int y
Y-coordinate of the Region (ignored for Image)
-
w
public int w
Width of the Region/Image
-
h
public int h
Height of the Region/Image
-
imageMissingHandler
protected Object imageMissingHandler
-
lastSearchTime
protected long lastSearchTime
-
lastFindTime
protected long lastFindTime
-
lastSearchTimeRepeat
protected long lastSearchTimeRepeat
-
-
Method Detail
-
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
-
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
-
hasText
public boolean hasText(String text)
-
hasT
public boolean hasT(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()
-
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()
-
-