[sikuli] 299/385: revised the javadocs of the package API
Gilles Filippini
pini at moszumanska.debian.org
Sun Jun 29 19:26:26 UTC 2014
This is an automated email from the git hooks/post-receive script.
pini pushed a commit to tag upstream/1.1.0_beta1
in repository sikuli.
commit 1a8403280cbb5bd45c9a77afa00d6f95dc8639e9
Author: Raimund Hocke <info at its-me-raiman.de>
Date: Tue Feb 25 18:47:33 2014 +0100
revised the javadocs of the package API
---
API/src/main/java/org/sikuli/script/App.java | 121 ++++-
API/src/main/java/org/sikuli/script/Button.java | 9 +-
API/src/main/java/org/sikuli/script/Constants.java | 13 +-
API/src/main/java/org/sikuli/script/Env.java | 5 +-
.../main/java/org/sikuli/script/EventObserver.java | 7 +-
.../main/java/org/sikuli/script/EventSubject.java | 7 +-
.../main/java/org/sikuli/script/FindFailed.java | 44 +-
.../java/org/sikuli/script/FindFailedDialog.java | 9 +-
.../java/org/sikuli/script/FindFailedResponse.java | 7 +-
API/src/main/java/org/sikuli/script/Finder.java | 70 ++-
API/src/main/java/org/sikuli/script/IRobot.java | 10 +-
API/src/main/java/org/sikuli/script/IScreen.java | 8 +-
API/src/main/java/org/sikuli/script/Image.java | 18 +-
API/src/main/java/org/sikuli/script/ImageFind.java | 53 +-
.../main/java/org/sikuli/script/ImageFinder.java | 30 +-
.../main/java/org/sikuli/script/ImageGroup.java | 39 +-
.../main/java/org/sikuli/script/ImageLocator.java | 7 +-
API/src/main/java/org/sikuli/script/ImagePath.java | 2 +-
API/src/main/java/org/sikuli/script/Key.java | 11 +-
.../main/java/org/sikuli/script/KeyModifier.java | 8 +-
API/src/main/java/org/sikuli/script/Location.java | 104 ++--
API/src/main/java/org/sikuli/script/Match.java | 36 +-
API/src/main/java/org/sikuli/script/Mouse.java | 48 +-
.../main/java/org/sikuli/script/ObserveAppear.java | 19 +
.../{SikuliEventChange.java => ObserveChange.java} | 11 +-
.../script/{SikuliEvent.java => ObserveEvent.java} | 64 ++-
.../main/java/org/sikuli/script/ObserveVanish.java | 18 +
API/src/main/java/org/sikuli/script/Observer.java | 600 +++++++++++----------
.../java/org/sikuli/script/ObserverCallBack.java | 49 +-
.../script/{Observer.java => ObserverManager.java} | 140 ++---
.../java/org/sikuli/script/OverlayAnimator.java | 9 +-
.../org/sikuli/script/OverlayCapturePrompt.java | 8 +-
.../sikuli/script/OverlayTransparentWindow.java | 8 +-
API/src/main/java/org/sikuli/script/Pattern.java | 4 +-
API/src/main/java/org/sikuli/script/Region.java | 117 ++--
.../main/java/org/sikuli/script/RobotDesktop.java | 12 +-
.../main/java/org/sikuli/script/RobotRemote.java | 30 +-
API/src/main/java/org/sikuli/script/Screen.java | 40 +-
.../java/org/sikuli/script/ScreenHighlighter.java | 8 +-
.../main/java/org/sikuli/script/ScreenImage.java | 9 +-
.../main/java/org/sikuli/script/ScreenRemote.java | 46 +-
.../main/java/org/sikuli/script/ScreenUnion.java | 13 +-
.../main/java/org/sikuli/script/SikuliEvent.java | 127 +----
.../java/org/sikuli/script/SikuliEventAdapter.java | 12 +-
.../java/org/sikuli/script/SikuliEventAppear.java | 16 -
.../java/org/sikuli/script/SikuliEventManager.java | 356 ------------
.../org/sikuli/script/SikuliEventObserver.java | 13 +-
.../java/org/sikuli/script/SikuliEventVanish.java | 15 -
.../java/org/sikuli/script/SikuliException.java | 7 +-
API/src/main/java/org/sikuli/script/SikuliX.java | 8 +-
.../java/org/sikuli/script/TextRecognizer.java | 12 +-
.../might-be-obsolete}/SikuliAction.java | 4 +-
.../might-be-obsolete}/SikuliActionListener.java | 0
.../might-be-obsolete}/SikuliActionManager.java | 0
Basics/src/main/resources/Lib/sikuli/Region.py | 6 +-
Basics/src/main/resources/Lib/sikuli/Sikuli.py | 32 +-
Basics/src/main/resources/Lib/sikulix.rb | 2 +-
57 files changed, 1212 insertions(+), 1269 deletions(-)
diff --git a/API/src/main/java/org/sikuli/script/App.java b/API/src/main/java/org/sikuli/script/App.java
index 7a7566d..7988caf 100755
--- a/API/src/main/java/org/sikuli/script/App.java
+++ b/API/src/main/java/org/sikuli/script/App.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -25,6 +25,14 @@ import org.sikuli.basics.FileManager;
import org.sikuli.natives.OSUtil;
import org.sikuli.natives.SysUtil;
+/**
+ * App implements features to manage (open, switch to, close) applications
+ * on the system we are running on and
+ * to access their assets like windows
+ *
+ * TAKE CARE: function behavior differs depending on the running system
+ * (cosult the docs for more info)
+ */
public class App {
protected static final OSUtil _osUtil = SysUtil.getOSUtil();
@@ -48,7 +56,13 @@ public class App {
}
}
- public App(String appName) {
+ /**
+ * creates an instance for an app with this name
+ * (nothing done yet)
+ *
+ * @param appName
+ */
+ public App(String appName) {
_appName = appName;
_pid = 0;
}
@@ -58,26 +72,65 @@ public class App {
_pid = pid;
}
- public static App open(String appName) {
+ /**
+ * creates an instance for an app with this name and tries to open it
+ * @param appName
+ * @return the App instance or null on failure
+ */
+ public static App open(String appName) {
return (new App(appName)).open();
}
- public static int close(String appName) {
+ /**
+ * tries to identify a running app with the given name
+ * and then tries to close it
+ * @param appName
+ * @return 0 for success -1 otherwise
+ */
+ public static int close(String appName) {
return _osUtil.closeApp(appName);
}
- public static App focus(String appName) {
+ /**
+ * tries to identify a running app with name and
+ * if not running tries to open it
+ * and tries to make it the foreground application
+ * bringing its topmost window to front
+ * @param appName
+ * @return the App instance or null on failure
+ */
+ public static App focus(String appName) {
return (new App(appName)).focus();
}
+ /**
+ * tries to identify a running app with name and
+ * if not running tries to open it
+ * and tries to make it the foreground application
+ * bringing its window with the given number to front
+ * @param appName
+ * @param num
+ * @return the App instance or null on failure
+ */
public static App focus(String appName, int num) {
return (new App(appName)).focus(num);
}
- public App focus() {
+ /**
+ * tries to make it the foreground application
+ * bringing its topmost window to front
+ * @return the App instance or null on failure
+ */
+ public App focus() {
return focus(0);
}
+ /**
+ * tries to make it the foreground application
+ * bringing its window with the given number to front
+ * @param num
+ * @return the App instance or null on failure
+ */
public App focus(int num) {
Debug.history("App.focus " + this.toString() + " #" + num);
if (_pid != 0) {
@@ -106,7 +159,11 @@ public class App {
return this;
}
- public App open() {
+ /**
+ * tries to open the app defined by this App instance
+ * @return this or null on failure
+ */
+ public App open() {
if (Settings.isWindows() || Settings.isLinux()) {
int pid = _osUtil.openApp(_appName);
_pid = pid;
@@ -125,7 +182,11 @@ public class App {
return this;
}
- public int close() {
+ /**
+ * tries to close the app defined by this App instance
+ * @return this or null on failure
+ */
+ public int close() {
Debug.history("App.close " + this.toString());
if (_pid != 0) {
int ret = _osUtil.closeApp(_pid);
@@ -136,17 +197,36 @@ public class App {
return close(_appName);
}
- public String name() {
+ /**
+ * the app's name as defined by this App instance
+ * @return the name
+ */
+ public String name() {
return _appName;
}
- public Region window() {
+ /**
+ * evaluates the region currently occupied
+ * by the topmost window of this App instance.
+ * The region might not be fully visible, not visible at all
+ * or invalid with respect to the current monitor configuration (outside any screen)
+ * @return the region
+ */
+ public Region window() {
if (_pid != 0) {
return asRegion(_osUtil.getWindow(_pid));
}
return asRegion(_osUtil.getWindow(_appName));
}
+ /**
+ * evaluates the region currently occupied
+ * by the window with the given number of this App instance.
+ * The region might not be fully visible, not visible at all
+ * or invalid with respect to the current monitor configuration (outside any screen)
+ * @param winNum
+ * @return the region
+ */
public Region window(int winNum) {
if (_pid != 0) {
return asRegion(_osUtil.getWindow(_pid, winNum));
@@ -154,11 +234,20 @@ public class App {
return asRegion(_osUtil.getWindow(_appName, winNum));
}
- public static Region focusedWindow() {
+ /**
+ * evaluates the region currently occupied by the systemwide frontmost window
+ * (usually the one that has focus for mouse and keyboard actions)
+ * @return the region
+ */
+ public static Region focusedWindow() {
return asRegion(_osUtil.getFocusedWindow());
}
- public static String getClipboard() {
+ /**
+ * evaluates the current textual content of the system clipboard
+ * @return the textual content
+ */
+ public static String getClipboard() {
Transferable content = Clipboard.getSystemClipboard().getContents(null);
try {
if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) {
@@ -172,7 +261,11 @@ public class App {
return "";
}
- public static void setClipboard(String text) {
+ /**
+ * sets the current textual content of the system clipboard to the given text
+ * @param text
+ */
+ public static void setClipboard(String text) {
Clipboard.putText(Clipboard.PLAIN, Clipboard.UTF8,
Clipboard.BYTE_BUFFER, text);
}
diff --git a/API/src/main/java/org/sikuli/script/Button.java b/API/src/main/java/org/sikuli/script/Button.java
index 0c51ef5..d9f86be 100755
--- a/API/src/main/java/org/sikuli/script/Button.java
+++ b/API/src/main/java/org/sikuli/script/Button.java
@@ -1,15 +1,18 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.awt.event.InputEvent;
+/**
+ * Defines the constants for use with the mouse actions
+ * for the button to use and the wheel direction
+ */
public class Button {
-
public static int LEFT = InputEvent.BUTTON1_MASK;
public static int MIDDLE = InputEvent.BUTTON2_MASK;
public static int RIGHT = InputEvent.BUTTON3_MASK;
diff --git a/API/src/main/java/org/sikuli/script/Constants.java b/API/src/main/java/org/sikuli/script/Constants.java
index 07743c9..24c38c8 100755
--- a/API/src/main/java/org/sikuli/script/Constants.java
+++ b/API/src/main/java/org/sikuli/script/Constants.java
@@ -1,12 +1,19 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * reasonable symbolic constants to be used with Sikuli features
+ */
public class Constants {
- public static double FOREVER = Double.POSITIVE_INFINITY;
+
+ /**
+ * use it for a very long time value
+ */
+ public static double FOREVER = Double.POSITIVE_INFINITY;
}
diff --git a/API/src/main/java/org/sikuli/script/Env.java b/API/src/main/java/org/sikuli/script/Env.java
index ccdc322..1e2333f 100755
--- a/API/src/main/java/org/sikuli/script/Env.java
+++ b/API/src/main/java/org/sikuli/script/Env.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -16,7 +16,6 @@ import org.sikuli.natives.SysUtil;
/**
* features moved to other classes, details below with the methods
- * @author RaiMan
* @deprecated
*/
@Deprecated
diff --git a/API/src/main/java/org/sikuli/script/EventObserver.java b/API/src/main/java/org/sikuli/script/EventObserver.java
index 7fda4da..e130c54 100755
--- a/API/src/main/java/org/sikuli/script/EventObserver.java
+++ b/API/src/main/java/org/sikuli/script/EventObserver.java
@@ -1,11 +1,14 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * INTRENAL USE
+ */
public interface EventObserver {
public void update(EventSubject s);
diff --git a/API/src/main/java/org/sikuli/script/EventSubject.java b/API/src/main/java/org/sikuli/script/EventSubject.java
index 6f18662..727634a 100755
--- a/API/src/main/java/org/sikuli/script/EventSubject.java
+++ b/API/src/main/java/org/sikuli/script/EventSubject.java
@@ -1,11 +1,14 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * INTERNAL USE
+ */
public interface EventSubject {
public void addObserver(EventObserver o);
diff --git a/API/src/main/java/org/sikuli/script/FindFailed.java b/API/src/main/java/org/sikuli/script/FindFailed.java
index c9318c4..a3e8adc 100755
--- a/API/src/main/java/org/sikuli/script/FindFailed.java
+++ b/API/src/main/java/org/sikuli/script/FindFailed.java
@@ -1,20 +1,48 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * implements the SikuliX FindFailed exception class
+ * and defines constants and settings for the feature FindFailedResponse
+ */
public class FindFailed extends SikuliException {
- public static FindFailedResponse defaultFindFailedResponse = FindFailedResponse.ABORT;
- public static final FindFailedResponse PROMPT = FindFailedResponse.PROMPT;
- public static final FindFailedResponse RETRY = FindFailedResponse.RETRY;
- public static final FindFailedResponse SKIP = FindFailedResponse.SKIP;
- public static final FindFailedResponse ABORT = FindFailedResponse.ABORT;
+ /**
+ * default FindFailedResponse is ABORT
+ */
+ public static FindFailedResponse defaultFindFailedResponse = FindFailedResponse.ABORT;
+
+ /**
+ * FindFailedResponse: should display a prompt dialog with the failing image
+ * having the options retry, skip and abort
+ */
+ public static final FindFailedResponse PROMPT = FindFailedResponse.PROMPT;
+
+ /**
+ * FindFailedResponse: should retry the find op on FindFailed
+ */
+ public static final FindFailedResponse RETRY = FindFailedResponse.RETRY;
+
+ /**
+ * FindFailedResponse: should silently continue on FindFailed
+ */
+ public static final FindFailedResponse SKIP = FindFailedResponse.SKIP;
+
+ /**
+ * FindFailedResponse: should abort the SikuliX application
+ */
+ public static final FindFailedResponse ABORT = FindFailedResponse.ABORT;
- public FindFailed(String msg) {
+ /**
+ * the exception
+ * @param msg
+ */
+ public FindFailed(String msg) {
super(msg);
_name = "FindFailed";
}
diff --git a/API/src/main/java/org/sikuli/script/FindFailedDialog.java b/API/src/main/java/org/sikuli/script/FindFailedDialog.java
index 6d22fa3..17fb31b 100755
--- a/API/src/main/java/org/sikuli/script/FindFailedDialog.java
+++ b/API/src/main/java/org/sikuli/script/FindFailedDialog.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -19,6 +19,9 @@ import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
+/**
+ * INTERNAL USE
+ */
class FindFailedDialog extends JDialog implements ActionListener {
JButton retryButton;
@@ -35,7 +38,7 @@ class FindFailedDialog extends JDialog implements ActionListener {
init(target, isCapture);
}
- public void init(Object target, boolean isCapture) {
+ private void init(Object target, boolean isCapture) {
this.isCapture = isCapture;
setModal(true);
JPanel panel = new JPanel();
diff --git a/API/src/main/java/org/sikuli/script/FindFailedResponse.java b/API/src/main/java/org/sikuli/script/FindFailedResponse.java
index d52430a..1625268 100755
--- a/API/src/main/java/org/sikuli/script/FindFailedResponse.java
+++ b/API/src/main/java/org/sikuli/script/FindFailedResponse.java
@@ -1,11 +1,14 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * INTERNAL USE
+ */
public enum FindFailedResponse{
ABORT,
PROMPT,
diff --git a/API/src/main/java/org/sikuli/script/Finder.java b/API/src/main/java/org/sikuli/script/Finder.java
index 259ab07..59a5e7d 100755
--- a/API/src/main/java/org/sikuli/script/Finder.java
+++ b/API/src/main/java/org/sikuli/script/Finder.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -18,6 +18,14 @@ import org.sikuli.natives.FindResults;
import org.sikuli.natives.TARGET_TYPE;
import org.sikuli.natives.Vision;
+/**
+ * implements the process to find one image in another image <br />
+ * this is the historical implementation
+ * based on the C++ JNI access to the native OpenCV libraries<br />
+ * It is being replaced by ImageFinder, that implements the Finder features
+ * completely in Java using the OpenCV newly provided JAVA interface<br />
+ * At time of realisation the Finder API will be redirected to ImageFinder
+ */
public class Finder implements Iterator<Match> {
private Region _region = null;
@@ -26,13 +34,11 @@ public class Finder implements Iterator<Match> {
private FindResults _results = null;
private int _cur_result_i;
private boolean repeating = false;
- private boolean isImageFinder = false;
-//TODO Vision.setParameter("GPU", 1);
static {
FileManager.loadLibrary("VisionProxy");
}
-
+
/**
* Just to force library initialization
*/
@@ -131,7 +137,7 @@ public class Finder implements Iterator<Match> {
}
/**
- * internal use: repeat findX with same Finder
+ * internal use: repeat with same Finder
*/
protected void findRepeat() {
_results = Vision.find(_findInput);
@@ -139,8 +145,10 @@ public class Finder implements Iterator<Match> {
}
/**
- *
+ * do a find op with the given image or the given text in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
* @param imageOrText
+ * @return null. if find setup not possible
*/
public String find(String imageOrText) {
String target = setTargetSmartly(_findInput, imageOrText);
@@ -157,9 +165,10 @@ public class Finder implements Iterator<Match> {
}
/**
- * findX given pattern within the stored image
- *
+ * do a find op with the given pattern in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
* @param aPtn
+ * @return null. if find setup not possible
*/
public String find(Pattern aPtn) {
if (aPtn.isValid()) {
@@ -173,7 +182,13 @@ public class Finder implements Iterator<Match> {
return null;
}
}
-
+
+ /**
+ * do a find op with the given pattern in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
+ * @param img
+ * @return null. if find setup not possible
+ */
public String find(Image img) {
if (img.isValid()) {
_findInput.setTarget(img.getMatNative());
@@ -185,7 +200,13 @@ public class Finder implements Iterator<Match> {
return null;
}
}
-
+
+ /**
+ * do a text find with the given text in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
+ * @param text
+ * @return null. if find setup not possible
+ */
public String findText(String text) {
_findInput.setTarget(TARGET_TYPE.TEXT, text);
_results = Vision.find(_findInput);
@@ -194,7 +215,7 @@ public class Finder implements Iterator<Match> {
}
/**
- * internal use: repeat findX with same Finder
+ * internal use: repeat with same Finder
*/
protected void findAllRepeat() {
Debug timing = new Debug();
@@ -205,8 +226,10 @@ public class Finder implements Iterator<Match> {
}
/**
- *
+ * do a findAll op with the given image or the given text in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
* @param imageOrText
+ * @return null. if find setup not possible
*/
public String findAll(String imageOrText) {
String target = setTargetSmartly(_findInput, imageOrText);
@@ -229,9 +252,10 @@ public class Finder implements Iterator<Match> {
return target;
}
- /**
- *
- * @param aPtn
+ /**
+ * do a find op with the given pattern in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
+ * @return null. if find setup not possible
*/
public String findAll(Pattern aPtn) {
if (aPtn.isValid()) {
@@ -250,6 +274,12 @@ public class Finder implements Iterator<Match> {
}
}
+ /**
+ * do a findAll op with the given image in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
+ * @param imageOrText
+ * @return null. if find setup not possible
+ */
public String findAll(Image img) {
if (img.isValid()) {
_findInput.setTarget(img.getMatNative());
@@ -266,6 +296,12 @@ public class Finder implements Iterator<Match> {
}
}
+ /**
+ * do a findAll op with the given text in the Finder's image
+ * (hasNext() and next() will reveal possible match results)
+ * @param imageOrText
+ * @return null. if find setup not possible
+ */
public String findAllText(String text) {
_findInput.setTarget(TARGET_TYPE.TEXT, text);
_findInput.setFindAll(true);
@@ -339,7 +375,7 @@ public class Finder implements Iterator<Match> {
FindResult fr = _results.get(_cur_result_i++);
Screen parentScreen = null;
if (_region != null) {
- parentScreen = _region.getScreen();
+ parentScreen = _region.getScreen();
}
ret = new Match(fr, parentScreen);
fr.delete();
diff --git a/API/src/main/java/org/sikuli/script/IRobot.java b/API/src/main/java/org/sikuli/script/IRobot.java
index 3ef30e3..05ef13e 100755
--- a/API/src/main/java/org/sikuli/script/IRobot.java
+++ b/API/src/main/java/org/sikuli/script/IRobot.java
@@ -1,14 +1,18 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.awt.Color;
import java.awt.Rectangle;
+/**
+ * INTERNAL USE <br />
+ * function template for (alternative) Robot implementations
+ */
public interface IRobot {
enum KeyMode {
PRESS_ONLY, RELEASE_ONLY, PRESS_RELEASE
@@ -28,7 +32,7 @@ public interface IRobot {
void mouseDown(int buttons);
int mouseUp(int buttons);
void clickStarts();
- void clickEnds();
+ void clickEnds();
void smoothMove(Location dest);
void smoothMove(Location src, Location dest, long ms);
void mouseWheel(int wheelAmt);
diff --git a/API/src/main/java/org/sikuli/script/IScreen.java b/API/src/main/java/org/sikuli/script/IScreen.java
index 8a94cf2..8e08585 100755
--- a/API/src/main/java/org/sikuli/script/IScreen.java
+++ b/API/src/main/java/org/sikuli/script/IScreen.java
@@ -1,13 +1,17 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.awt.Rectangle;
+/**
+ * INTERNAL USE
+ * function template for (alternative) Screen implementations
+ */
public interface IScreen {
public IRobot getRobot();
diff --git a/API/src/main/java/org/sikuli/script/Image.java b/API/src/main/java/org/sikuli/script/Image.java
index 44baa4e..d8f9208 100644
--- a/API/src/main/java/org/sikuli/script/Image.java
+++ b/API/src/main/java/org/sikuli/script/Image.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * added RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -145,7 +145,7 @@ public class Image {
* FOR INTERNAL USE: from IDE - suppresses load error message
*
* @param fName
- * @return
+ * @return this
*/
public static Image createThumbNail(String fName) {
Image img = get(fName, true);
@@ -156,10 +156,10 @@ public class Image {
* FOR INTERNAL USE: see get(String, boolean)
*
* @param fName
- * @return
+ * @return this
*/
- protected static Image get(String fname) {
- return get(fname, false);
+ protected static Image get(String fName) {
+ return get(fName, false);
}
/**
@@ -168,7 +168,7 @@ public class Image {
*
* @param fName
* @param silent true: suppress some error messages
- * @return
+ * @return this
*/
protected static Image get(String fName, boolean silent) {
if (fName == null || fName.isEmpty()) {
@@ -495,7 +495,7 @@ public class Image {
/**
* Get the image's descriptive name
*
- * @return
+ * @return the name
*/
public String getName() {
return imageName;
@@ -679,7 +679,7 @@ public class Image {
* create a sub image from this image
*
* @param part (the constants Region.XXX as used with region.get())
- * @return
+ * @return the sub image
*/
public Image getSub(int part) {
Rectangle r = Region.getRectangle(0, 0, getSize().width, getSize().height, part);
diff --git a/API/src/main/java/org/sikuli/script/ImageFind.java b/API/src/main/java/org/sikuli/script/ImageFind.java
index 700a084..bcafb7e 100644
--- a/API/src/main/java/org/sikuli/script/ImageFind.java
+++ b/API/src/main/java/org/sikuli/script/ImageFind.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
import java.util.ArrayList;
@@ -16,8 +22,13 @@ import org.opencv.imgproc.Imgproc;
import org.sikuli.basics.Debug;
import org.sikuli.basics.Settings;
+/**
+ * UNDER DEVELOPMENT --- SURELY HAS BUGS ;-)
+ * Intended replacement for Finder together with ImageFinder
+ * completely implementing the OpenCV usage on the Java level.
+ */
public class ImageFind implements Iterator<Match>{
-
+
private static String me = "ImageFind";
private static int lvl = 3;
@@ -26,7 +37,7 @@ public class ImageFind implements Iterator<Match>{
}
private ImageFinder owner = null;
-
+
private boolean isValid = false;
private boolean isInnerFind = false;
@@ -62,9 +73,9 @@ public class ImageFind implements Iterator<Match>{
public static int ALL_MAX = 100;
private int allMax = 0;
-
+
private List<Match> matches = Collections.synchronizedList(new ArrayList<Match>());
-
+
private boolean repeating;
private long lastFindTime = 0;
private long lastSearchTime = 0;
@@ -72,23 +83,23 @@ public class ImageFind implements Iterator<Match>{
public ImageFind() {
matches.add(null);
}
-
+
public boolean isValid() {
return true;
}
-
+
public void setIsInnerFind() {
isInnerFind = true;
}
-
+
void setSimilarity(double sim) {
similarity = sim;
}
-
+
public void setFindTimeout(double t) {
waitingTime = t;
}
-
+
public void setFinding(int ftyp) {
finding = ftyp;
}
@@ -96,11 +107,11 @@ public class ImageFind implements Iterator<Match>{
public void setSorted(int styp) {
sorted = styp;
}
-
+
public void setCount(int c) {
count = c;
}
-
+
public List<Match> getMatches() {
return matches;
}
@@ -139,7 +150,7 @@ public class ImageFind implements Iterator<Match>{
return false;
}
if (probe.empty()) {
- probe = Image.createMat(pImage.get());
+ probe = Image.createMat(pImage.get());
}
checkProbe();
if (!owner.isImage()) {
@@ -158,7 +169,7 @@ public class ImageFind implements Iterator<Match>{
}
return isValid;
}
-
+
private void checkProbe() {
MatOfDouble pMean = new MatOfDouble();
MatOfDouble pStdDev = new MatOfDouble();
@@ -187,7 +198,7 @@ public class ImageFind implements Iterator<Match>{
protected ImageFind doFind() {
Debug.enter(me + ": doFind");
- Core.MinMaxLocResult fres = null;
+ Core.MinMaxLocResult fres = null;
repeating = false;
long begin = (new Date()).getTime();
long lap;
@@ -224,11 +235,11 @@ public class ImageFind implements Iterator<Match>{
}
fres = doFindDown(0, 0.0);
if(fres != null && fres.maxVal > similarity - 0.01) {
- set(new Match((int) fres.maxLoc.x + owner.offX, (int) fres.maxLoc.y + owner.offY,
+ set(new Match((int) fres.maxLoc.x + owner.offX, (int) fres.maxLoc.y + owner.offY,
probe.width(), probe.height(), fres.maxVal, null, null));
}
} else {
- log(lvl, "downsampling: success: adjusting match");
+ log(lvl, "downsampling: success: adjusting match");
set(checkFound(fres));
}
lastFindTime = (new Date()).getTime() - lastFindTime;
@@ -258,7 +269,7 @@ public class ImageFind implements Iterator<Match>{
}
return this;
}
-
+
private Match checkFound(Core.MinMaxLocResult res) {
Match match = null;
ImageFinder f;
@@ -282,7 +293,7 @@ public class ImageFind implements Iterator<Match>{
}
return match;
}
-
+
private static Rect getSubMatRect(Mat mat, int x, int y, int w, int h, int margin) {
x = Math.max(0, x - margin);
y = Math.max(0, y - margin);
@@ -307,7 +318,7 @@ public class ImageFind implements Iterator<Match>{
Imgproc.resize(probe, p, sp, 0, 0, Imgproc.INTER_AREA);
dres = doFindMatch(b, p);
log(lvl, "doFindDown: score: %.2f at (%d, %d)", dres.maxVal,
- (int) (dres.maxLoc.x * rfactor), (int) (dres.maxLoc.y * rfactor));
+ (int) (dres.maxLoc.x * rfactor), (int) (dres.maxLoc.y * rfactor));
} else {
dres = doFindMatch(owner.base, probe);
timer.end();
@@ -324,14 +335,14 @@ public class ImageFind implements Iterator<Match>{
level++;
doFindDown(level, factor);
} else {
- dres.maxLoc.x *= rfactor;
+ dres.maxLoc.x *= rfactor;
dres.maxLoc.y *= rfactor;
findDownRes = dres;
}
timer.end();
return null;
}
-
+
private Core.MinMaxLocResult doFindMatch(Mat base, Mat probe) {
Mat res = new Mat();
Mat bi = new Mat();
diff --git a/API/src/main/java/org/sikuli/script/ImageFinder.java b/API/src/main/java/org/sikuli/script/ImageFinder.java
index 9bacbe4..093868b 100644
--- a/API/src/main/java/org/sikuli/script/ImageFinder.java
+++ b/API/src/main/java/org/sikuli/script/ImageFinder.java
@@ -1,21 +1,16 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.Transparency;
-import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-import java.awt.image.ComponentColorModel;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferByte;
-import java.awt.image.SampleModel;
-import java.awt.image.WritableRaster;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.Core;
-import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Size;
@@ -23,6 +18,11 @@ import org.opencv.imgproc.Imgproc;
import org.sikuli.basics.Debug;
import org.sikuli.basics.Settings;
+/**
+ * UNDER DEVELOPMENT --- SURELY HAS BUGS ;-)
+ * Intended replacement for Finder together with ImageFind
+ * completely implementing the OpenCV usage on the Java level.
+ */
public class ImageFinder extends Finder {
private static String me = "ImageFinder";
@@ -97,7 +97,7 @@ public class ImageFinder extends Finder {
public void destroy() {
reset();
}
-
+
public void setIsMultiFinder() {
base = new Mat();
isMultiFinder = true;
@@ -331,7 +331,7 @@ public class ImageFinder extends Finder {
Imgproc.dilate(diff, diff, new Mat());
Mat se = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5,5));
Imgproc.morphologyEx(diff, diff, Imgproc.MORPH_CLOSE, se);
-
+
List<MatOfPoint> points = new ArrayList<MatOfPoint>();
Mat contours = new Mat();
Imgproc.findContours(diff, points, contours, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
@@ -344,7 +344,7 @@ public class ImageFinder extends Finder {
printMatI(contours);
return true;
}
-
+
private static void printMatI(Mat mat) {
int[] data = new int[mat.channels()];
for (int r = 0; r < mat.rows(); r++) {
@@ -352,7 +352,7 @@ public class ImageFinder extends Finder {
mat.get(r, c, data);
log(lvl, "(%d, %d) %s", r, c, Arrays.toString(data));
}
- }
+ }
}
public void setMinChanges(int min) {
diff --git a/API/src/main/java/org/sikuli/script/ImageGroup.java b/API/src/main/java/org/sikuli/script/ImageGroup.java
index f329df1..ffa7570 100644
--- a/API/src/main/java/org/sikuli/script/ImageGroup.java
+++ b/API/src/main/java/org/sikuli/script/ImageGroup.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * added RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -12,8 +12,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
+
/**
+ * UNDER DEVELOPMENT --- SURELY HAS BUGS ;-)
* An ImageGroup object represents images, that are all in the same folder.<br>
* the folder can contain a set of sub folders that can be switched dynamically <br>
* The folder will be found on the image path.<br>
@@ -24,16 +25,16 @@ import java.util.Map;
*/
public class ImageGroup {
- private static Map<String, ImageGroup> imageGroups =
+ private static Map<String, ImageGroup> imageGroups =
Collections.synchronizedMap(new HashMap<String, ImageGroup>());
-
+
private String name;
private URL url;
private String path;
private String subSet;
-
+
private Map<String, int[]> images = Collections.synchronizedMap(new HashMap<String, int[]>());
-
+
private boolean valid;
/**
@@ -42,7 +43,7 @@ public class ImageGroup {
public boolean isValid() {
return valid;
}
-
+
public static ImageGroup open(String name) {
ImageGroup ig = imageGroups.get(name);
if (ig != null && ig.isValid()) {
@@ -54,20 +55,20 @@ public class ImageGroup {
}
return ig;
}
-
+
public static void close(ImageGroup ig) {
ig.images.clear();
//take from ImagePath and purge
}
-
+
private ImageGroup(String name) {
init(name, null);
}
-
+
private ImageGroup(String name, String subSet) {
init(name, subSet);
}
-
+
private void init(String name, String subSet) {
this.name = name;
this.path = locate(name);
@@ -79,20 +80,20 @@ public class ImageGroup {
url = checkURL(path);
imageGroups.put(name, this);
use(subSet);
- }
+ }
}
-
+
private static String locate(String name) {
// find the given folder name on current image path
return null;
- }
+ }
private static URL checkURL(String path) {
// check wether path is an URL-string
URL purl = null;
return purl;
}
-
+
public boolean use(String sub) {
if (sub == null) {
// either no sub folders or use groupname as default sub
@@ -101,8 +102,8 @@ public class ImageGroup {
// save/load imagefacts?
return true;
}
-
- // triggered when lastSeen is stored
+
+ // triggered when lastSeen is stored
protected int[] addImageFacts(Image img, Rectangle r, double score) {
int[] facts = new int[5];
facts[0] = r.x;
@@ -113,7 +114,7 @@ public class ImageGroup {
images.put(img.getName(), facts);
return facts;
}
-
+
public boolean loadImageFacts() {
return true;
}
diff --git a/API/src/main/java/org/sikuli/script/ImageLocator.java b/API/src/main/java/org/sikuli/script/ImageLocator.java
index 6491a34..34c47d4 100755
--- a/API/src/main/java/org/sikuli/script/ImageLocator.java
+++ b/API/src/main/java/org/sikuli/script/ImageLocator.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -22,10 +22,11 @@ import org.sikuli.basics.FileManager;
import org.sikuli.basics.Settings;
/**
- * This class is currently used to locate image files in the filesystem <br>
+ * This class was used to locate image files in the filesystem <br>
* and in the internet (the files are cached locally) <br>
*
* @deprecated will be completely replaced by the classes Image and ImagePath
+ * relevant functions are already redirected as needed
*/
@Deprecated
public class ImageLocator {
diff --git a/API/src/main/java/org/sikuli/script/ImagePath.java b/API/src/main/java/org/sikuli/script/ImagePath.java
index 92e50ce..5dd93d6 100644
--- a/API/src/main/java/org/sikuli/script/ImagePath.java
+++ b/API/src/main/java/org/sikuli/script/ImagePath.java
@@ -71,7 +71,7 @@ public class ImagePath {
/**
* get the list of path entries (as PathEntry)
*
- * @return
+ * @return pathentries
*/
public static List<PathEntry> getPaths() {
return imagePaths;
diff --git a/API/src/main/java/org/sikuli/script/Key.java b/API/src/main/java/org/sikuli/script/Key.java
index c911296..e07df43 100755
--- a/API/src/main/java/org/sikuli/script/Key.java
+++ b/API/src/main/java/org/sikuli/script/Key.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -20,6 +20,13 @@ import org.sikuli.basics.Debug;
import org.sikuli.basics.KeyBoardSetupWindow;
import org.sikuli.basics.Settings;
+/**
+ * this class implements an interface to the Java key system
+ * as represented by java.awt.event.KeyEvent
+ * for the functions Region.type() and Region.write()
+ * by translating key constants for special keys and plain text per character.<br />
+ * for details consult the docs
+ */
public class Key {
static String[] keyVK = new String[] {
diff --git a/API/src/main/java/org/sikuli/script/KeyModifier.java b/API/src/main/java/org/sikuli/script/KeyModifier.java
index 7283a37..8c02585 100755
--- a/API/src/main/java/org/sikuli/script/KeyModifier.java
+++ b/API/src/main/java/org/sikuli/script/KeyModifier.java
@@ -1,13 +1,17 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.awt.event.InputEvent;
+/**
+ * complementing class Key with the constants for the modifier keys<br />
+ * only still there for backward compatibility (is already duplicated in Key)
+ */
public class KeyModifier {
public static final int CTRL = InputEvent.CTRL_MASK;
public static final int SHIFT = InputEvent.SHIFT_MASK;
diff --git a/API/src/main/java/org/sikuli/script/Location.java b/API/src/main/java/org/sikuli/script/Location.java
index 40432df..f1ad9ad 100755
--- a/API/src/main/java/org/sikuli/script/Location.java
+++ b/API/src/main/java/org/sikuli/script/Location.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -12,12 +12,13 @@ import java.awt.Point;
import java.awt.Rectangle;
/**
- * A point like AWT.Point using global coordinates, hence modifications might move location out of
+ * A point like AWT.Point using global coordinates (x, y),
+ * hence modifications might move location out of
* any screen (not checked as is done with region)
*
*/
public class Location implements Comparable<Location>{
-
+
public int x;
public int y;
private Screen otherScreen = null;
@@ -63,15 +64,23 @@ public class Location implements Comparable<Location>{
x = (int) point.x;
y = (int) point.y;
}
-
- public int getX() {
+
+ /**
+ *
+ * @return x value
+ */
+ public int getX() {
return x;
}
- public int getY() {
+ /**
+ *
+ * @return y value
+ */
+ public int getY() {
return y;
}
-
+
/**
* get as AWT point
* @return point
@@ -79,7 +88,7 @@ public class Location implements Comparable<Location>{
public Point getPoint() {
return new Point(x,y);
}
-
+
/**
* sets the coordinates to the given values (moves it)
* @param x
@@ -94,8 +103,8 @@ public class Location implements Comparable<Location>{
/**
* sets the coordinates to the given values (moves it)
- * @param x
- * @param y
+ * @param x might be non-int
+ * @param y might be non-int
* @return self/this
*/
public Location setLocation(double x, double y) {
@@ -105,10 +114,10 @@ public class Location implements Comparable<Location>{
}
/**
- * Returns null, if outside of any screen<br>
- * subsequent actions might crash
+ * Returns null, if outside of any screen and not contained in a non-Desktop Screen instance (e.g. remote screen)<br>
+ * subsequent actions WILL crash if not tested for null return
*
- * @return the screen, that contains the given point.<br>
+ * @return the screen, that contains the given point
*/
public Screen getScreen() {
Rectangle r;
@@ -124,16 +133,32 @@ public class Location implements Comparable<Location>{
Debug.error("Location: outside any screen (%s, %s) - subsequent actions might not work as expected", x, y);
return null;
}
-
+
+ /**
+ * INTERNAL USE
+ * reveals wether the containing screen is a DeskTopScreen or not
+ * @return null if DeskTopScreen
+ */
+ public boolean isOtherScreen() {
+ return (otherScreen != null);
+ }
+
+ /**
+ * INTERNAL USE
+ * identifies the point as being on a non-desktop-screen
+ * @return this
+ */
public Location setOtherScreen(Screen scr) {
otherScreen = scr;
return this;
}
-
- public boolean isOtherScreen() {
- return (otherScreen != null);
- }
-
+
+ /**
+ * INTERNAL USE
+ * identifies the point as being on a non-desktop-screen
+ * if this is true for the given location
+ * @return this
+ */
private Location setOtherScreen(Location loc) {
if (loc.isOtherScreen()) {
setOtherScreen(loc.getScreen());
@@ -155,7 +180,7 @@ public class Location implements Comparable<Location>{
}
/**
- * the offset of given point to this Location
+ * the offset of given point to this Location
*
* @param loc
* @return relative offset
@@ -212,7 +237,7 @@ public class Location implements Comparable<Location>{
y += dy;
return this;
}
-
+
/**
* convenience: like awt point
* @param dx
@@ -337,10 +362,10 @@ public class Location implements Comparable<Location>{
Location n = new Location(screen.getBounds().getLocation());
return new Location(n.x + x - o.x, n.y + y - o.y);
}
-
+
/**
* Move the mouse to this location point
- *
+ *
* @return this
*/
public Location hover() {
@@ -350,7 +375,7 @@ public class Location implements Comparable<Location>{
/**
* Move the mouse to this location point and click left
- *
+ *
* @return this
*/
public Location click() {
@@ -360,7 +385,7 @@ public class Location implements Comparable<Location>{
/**
* Move the mouse to this location point and double click left
- *
+ *
* @return this
*/
public Location doubleClick() {
@@ -370,7 +395,7 @@ public class Location implements Comparable<Location>{
/**
* Move the mouse to this location point and click right
- *
+ *
* @return this
*/
public Location rightClick() {
@@ -387,22 +412,27 @@ public class Location implements Comparable<Location>{
return false;
}
Location that = (Location) oThat;
- return x == that.x && y == that.y;
+ return x == that.x && y == that.y;
}
+ /**
+ * {@inheritDoc}
+ * @param loc
+ * @return -1 if given point is more above and/or left, 1 otherwise (0 is equal)
+ */
@Override
- public int compareTo(Location l) {
- if (equals(l)) {
+ public int compareTo(Location loc) {
+ if (equals(loc)) {
return 0;
}
- if (l.x > x) {
+ if (loc.x > x) {
return 1;
- } else if (l.x == x) {
- if (l.y > y) {
+ } else if (loc.x == x) {
+ if (loc.y > y) {
return 1;
}
}
- return -1;
+ return -1;
}
/**
@@ -411,11 +441,11 @@ public class Location implements Comparable<Location>{
*/
@Override
public String toString() {
- Screen s = getScreen();
- return "L(" + x + "," + y + ")" +
+ Screen s = getScreen();
+ return "L(" + x + "," + y + ")" +
((s == null) ? "" : "@" + s.toStringShort());
}
-
+
/**
*
* @return a shorter description
diff --git a/API/src/main/java/org/sikuli/script/Match.java b/API/src/main/java/org/sikuli/script/Match.java
index 97d8e53..d38b5ee 100755
--- a/API/src/main/java/org/sikuli/script/Match.java
+++ b/API/src/main/java/org/sikuli/script/Match.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -11,11 +11,11 @@ import java.awt.image.BufferedImage;
import org.sikuli.natives.FindResult;
/**
- * holds the result of a findX operation, is itself the region on the screen,
+ * holds the result of a find operation, is itself the region on the screen,
* where the image was found and hence inherits all methods from Region<br>
* attributes:<br> the match score (0 ... 1.0)<br> the click target (e.g.
- * from Pattern)<br> the filename of the used image<br>or the text used for
- * findX text
+ * from Pattern)<br> a ref to the image used for search<br>or the text used for
+ * find text<br />and elapsed times for debugging
*/
public class Match extends Region implements Comparable<Match> {
@@ -25,8 +25,14 @@ public class Match extends Region implements Comparable<Match> {
private String ocrText = null;
private long lastSearchTime;
private long lastFindTime;
-
- public void setTimes(long ftime, long stime) {
+
+ /**
+ * INTERNAL USE
+ * set the elapsed times from search
+ * @param ftime
+ * @param stime
+ */
+ public void setTimes(long ftime, long stime) {
lastFindTime = ftime;
lastSearchTime = stime;
}
@@ -109,6 +115,10 @@ public class Match extends Region implements Comparable<Match> {
return simScore;
}
+ /**
+ * {@inheritDoc}
+ * @return the point defined by target offset (if set) or the center
+ */
@Override
public Location getTarget() {
if (target != null) {
@@ -147,7 +157,7 @@ public class Match extends Region implements Comparable<Match> {
}
/**
- * internal use: set the image filename after finding with success
+ * internal use: set the image after finding with success
* @param img
*/
protected void setImage(Image img) {
@@ -159,7 +169,7 @@ public class Match extends Region implements Comparable<Match> {
/**
* get the image used for searching as in-memory image
- * @return image
+ * @return a buffered image or null
*/
public BufferedImage getImage() {
if (image == null) {
@@ -184,7 +194,13 @@ public class Match extends Region implements Comparable<Match> {
public String getText() {
return ocrText;
}
-
+ /**
+ * first compares score values (<0 means given is higher)<br />
+ * with equal score then coordinates are compared: >0 is:<br />
+ * more left or more above or larger width or larger height in this sequence
+ * @param m
+ * @return
+ */
@Override
public int compareTo(Match m) {
if (simScore != m.simScore) {
diff --git a/API/src/main/java/org/sikuli/script/Mouse.java b/API/src/main/java/org/sikuli/script/Mouse.java
index 8e962cd..7d1df26 100644
--- a/API/src/main/java/org/sikuli/script/Mouse.java
+++ b/API/src/main/java/org/sikuli/script/Mouse.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
import java.awt.MouseInfo;
@@ -53,7 +59,7 @@ public class Mouse {
/**
* To get the one Mouse instance used for synchronisation
- *
+ *
*/
protected static Mouse get() {
if (mouse == null) {
@@ -64,7 +70,7 @@ public class Mouse {
/**
* current setting what to do if mouse is moved outside Sikuli's mouse protection
- *
+ *
*/
public static int getMouseMovedResponse() {
return mouseMovedResponse;
@@ -76,19 +82,19 @@ public class Mouse {
* - Mouse.MouseMovedShow (1) show and ignore it <br>
* - Mouse.MouseMovedPause (2) show it and pause until user says continue <br>
* - Mouse.MouseMovedAction (3) perform a user defined action <br>
- * 2 and 3 not implemented yet, 1 is used <br>
- *
+ * 2 and 3 not implemented yet, 1 is used <br>
+ *
* @param mouseMovedResponse
*/
public static void setMouseMovedResponse(int mouseMovedResponse) {
-//TODO implement 2 and 3
+//TODO implement 2 and 3
Mouse.mouseMovedResponse = Math.max(1, Math.max(0,mouseMovedResponse));
}
/**
* to block the mouse globally <br>
* only the contained mouse methods without owner will be granted
- *
+ *
* @return success
*/
public static boolean block() {
@@ -98,7 +104,7 @@ public class Mouse {
/**
* to block the mouse globally for the given owner <br>
* only the contained mouse methods having the same owner will be granted
- *
+ *
* @return success
*/
public static boolean block(Object owner) {
@@ -112,16 +118,16 @@ public class Mouse {
/**
* free the mouse globally after a block()
- *
+ *
* @return success (false means: not blocked currently)
*/
public static boolean unblock() {
return unblock(null);
}
-
+
/**
* free the mouse globally for this owner after a block(owner)
- *
+ *
* @return success (false means: not blocked currently for this owner)
*/
public static boolean unblock(Object owner) {
@@ -254,7 +260,7 @@ public class Mouse {
/**
* to click (left, right, middle - single or double) at the given location using the given button
* only useable for local screens
- *
+ *
* timing parameters: <br>
* - one value <br>
* < 0 wait before mouse down <br>
@@ -262,10 +268,10 @@ public class Mouse {
* - 2 or 3 values
* 1st wait before mouse down <br>
* 2nd wait after mouse up <br>
- * 3rd inner wait (milli secs, cut to 1000): pause between mouse down and up (Settings.ClickDelay)
- *
+ * 3rd inner wait (milli secs, cut to 1000): pause between mouse down and up (Settings.ClickDelay)
+ *
* wait before and after: > 59 taken as milli secs - < are seconds
- *
+ *
* @param loc where to click
* @param action L,R,M left, right, middle - D means double click
* @param args timing parameters
@@ -380,7 +386,7 @@ public class Mouse {
/**
* move the mouse to the given location (local and remote)
- *
+ *
* @param loc
* @return 1 for success, 0 otherwise
*/
@@ -409,7 +415,7 @@ public class Mouse {
/**
* press and hold the given buttons
- *
+ *
* @param buttons
*/
public static void down(int buttons) {
@@ -422,16 +428,16 @@ public class Mouse {
}
/**
- * release all buttons
- *
+ * release all buttons
+ *
*/
public static void up() {
up(0, null);
}
/**
- * release the given buttons
- *
+ * release the given buttons
+ *
* @param buttons (0 releases all buttons)
*/
public static void up(int buttons) {
@@ -447,7 +453,7 @@ public class Mouse {
/**
* move mouse using mouse wheel in the given direction the given steps <br>
* the result is system dependent
- *
+ *
* @param direction
* @param steps
*/
diff --git a/API/src/main/java/org/sikuli/script/ObserveAppear.java b/API/src/main/java/org/sikuli/script/ObserveAppear.java
new file mode 100755
index 0000000..6ff50a6
--- /dev/null
+++ b/API/src/main/java/org/sikuli/script/ObserveAppear.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
+package org.sikuli.script;
+
+/**
+ * INTERNAL USE
+ */
+public class ObserveAppear extends ObserveEvent {
+
+ public ObserveAppear(Object ptn, Match m, Region r){
+ super(ptn, m, r);
+ type = Type.APPEAR;
+ }
+
+}
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventChange.java b/API/src/main/java/org/sikuli/script/ObserveChange.java
similarity index 62%
rename from API/src/main/java/org/sikuli/script/SikuliEventChange.java
rename to API/src/main/java/org/sikuli/script/ObserveChange.java
index daecc2f..7d7ba39 100755
--- a/API/src/main/java/org/sikuli/script/SikuliEventChange.java
+++ b/API/src/main/java/org/sikuli/script/ObserveChange.java
@@ -1,15 +1,18 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.util.List;
-public class SikuliEventChange extends SikuliEvent {
- public SikuliEventChange(List<Match> results, Region r){
+/**
+ * INTERNAL USE
+ */
+public class ObserveChange extends ObserveEvent {
+ public ObserveChange(List<Match> results, Region r){
type = Type.CHANGE;
setChanges(results);
setRegion(r);
diff --git a/API/src/main/java/org/sikuli/script/SikuliEvent.java b/API/src/main/java/org/sikuli/script/ObserveEvent.java
similarity index 69%
copy from API/src/main/java/org/sikuli/script/SikuliEvent.java
copy to API/src/main/java/org/sikuli/script/ObserveEvent.java
index bd18316..2dd2361 100755
--- a/API/src/main/java/org/sikuli/script/SikuliEvent.java
+++ b/API/src/main/java/org/sikuli/script/ObserveEvent.java
@@ -6,74 +6,80 @@
*/
package org.sikuli.script;
+import java.util.ArrayList;
import java.util.List;
-public class SikuliEvent {
+public class ObserveEvent {
public enum Type {
APPEAR, VANISH, CHANGE, GENERIC
}
-
+
/**
- * the event's type as SikuliEvent.APPEAR, .VANISH, .CHANGE
+ * the event's type as ObserveEvent.APPEAR, .VANISH, .CHANGE
*/
public Type type;
-
+
private Region region = null;
private Match match = null;
private List<Match> changes = null;
private Object pattern = null;
- public SikuliEvent() {
+ public ObserveEvent() {
}
/**
* INTERNAL USE ONLY: creates an observed event
*/
- public SikuliEvent(Object ptn, Match m, Region r) {
- region = r;
- match = m;
- pattern = ptn;
+ public ObserveEvent(Object ptn, Match m, Region r) {
+ init(ptn, m, r);
}
+ private void init(Object ptn, Match m, Region r) {
+ setRegion(r);
+ setMatch(m);
+ setPattern(ptn);
+ }
+
/**
*
- * @return this event's observer's region
+ * @return this event's observer's region
*/
public Region getRegion() {
return region;
}
-
+
protected void setRegion(Region r) {
- region = r;
+ region = new Region(r);
}
/**
*
- * @return the observed match (APEAR, VANISH)
+ * @return the observed match (APEAR, VANISH)
*/
public Match getMatch() {
return match;
}
protected void setMatch(Match m) {
- match = m;
+ match = new Match(m);
}
/**
*
- * @return a list of observed changes as matches (CHANGE)
+ * @return a list of observed changes as matches (CHANGE)
*/
public List<Match> getChanges() {
return changes;
}
protected void setChanges(List<Match> c) {
- changes = c;
+ changes = new ArrayList<Match>();
+ changes.addAll(c);
}
/**
- *
+ *
* @return the used pattern for this event's observing
*/
public Pattern getPattern() {
@@ -84,23 +90,31 @@ public class SikuliEvent {
}
}
+ protected void setPattern(Object p) {
+ if (p.getClass().isInstance("")) {
+ pattern = new Pattern((String) p);
+ } else {
+ pattern = new Pattern((Pattern) p);
+ }
+ }
+
/**
- * tell the observer to repeat this event's observe action immediately
+ * tell the observer to repeat this event's observe action immediately
* after returning from this handler (APPEAR, VANISH)
*/
public void repeat() {
repeat(0);
}
-
+
/**
- * tell the observer to repeat this event's observe action after given time in secs
+ * tell the observer to repeat this event's observe action after given time in secs
* after returning from this handler (APPEAR, VANISH)
* @param secs
*/
public void repeat(long secs) {
- region.getEvtMgr().repeat(type, pattern, match, secs);
+ region.getEvtMgr().repeat(type, pattern, match, secs);
}
-
+
/**
* only for (APPEAR, VANISH)
* @return the number how often this event has already been triggered until now
@@ -110,16 +124,16 @@ public class SikuliEvent {
return 0;
} else {
return region.getEvtMgr().getCount(pattern);
- }
+ }
}
-
+
/**
* stops the observer after returning from the handler
*/
public void stopObserver() {
region.stopObserver();
}
-
+
@Override
public String toString() {
return String.format("SikuliEvent(%s) on %s with %s having last match: %s",
diff --git a/API/src/main/java/org/sikuli/script/ObserveVanish.java b/API/src/main/java/org/sikuli/script/ObserveVanish.java
new file mode 100755
index 0000000..2ed39aa
--- /dev/null
+++ b/API/src/main/java/org/sikuli/script/ObserveVanish.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
+package org.sikuli.script;
+
+/**
+ * INTERNAL USE
+ */
+public class ObserveVanish extends ObserveEvent {
+ public ObserveVanish(Object ptn, Match m, Region r){
+ super(ptn, m, r);
+ type = Type.VANISH;
+ }
+}
+
diff --git a/API/src/main/java/org/sikuli/script/Observer.java b/API/src/main/java/org/sikuli/script/Observer.java
old mode 100644
new mode 100755
index 604fd3b..f594107
--- a/API/src/main/java/org/sikuli/script/Observer.java
+++ b/API/src/main/java/org/sikuli/script/Observer.java
@@ -1,330 +1,360 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import org.sikuli.basics.Settings;
+import org.sikuli.basics.Debug;
+import java.awt.AWTException;
+import java.util.*;
+import org.sikuli.natives.FindInput;
+import org.sikuli.natives.FindResult;
+import org.sikuli.natives.FindResults;
+import org.sikuli.natives.Mat;
+import org.sikuli.natives.Vision;
+/**
+ * INTERNAL USE
+ * implements the observe action for a region and calls the ObserverCallBacks
+ */
public class Observer {
-
- private static class Entry {
-
- private Region region;
- private String name;
- private SikuliEvent.Type type;
- private boolean isActive = true;
- private ObserverCallBack obs;
-
- protected Entry(String name, Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
- this.name = name;
- region = reg;
- this.obs = obs;
- this.type = type;
- }
+
+ protected enum State {
+ FIRST, UNKNOWN, MISSING, APPEARED, VANISHED, REPEAT
}
-
- public static class Event extends SikuliEvent {
- private Entry observer;
- private long time;
-
- public long getTime() {
- return time;
+ private Region _region;
+ private Mat _lastImgMat = null;
+ private org.opencv.core.Mat _lastImageMat = null;
+ private Map<Object, State> _state;
+ private Map<Object, Long> _wait;
+ private Map<Object, Integer> _count;
+ private Map<Object, Match> _lastMatch;
+ private Map<Object, String> _names;
+// private Map<Object, SikuliEventObserver> _appearOb, _vanishOb;
+ private Map<Object, Object> _appearOb, _vanishOb;
+// private Map<Integer, SikuliEventObserver> _changeOb;
+ private Map<Integer, Object> _changeOb;
+ private Map<Integer, Integer> _countc;
+ private Map<Integer, String> _cnames;
+ private int _minChanges;
+ private boolean sthgLeft;
+
+ public Observer(Region region) {
+ _region = region;
+ _state = new HashMap<Object, State>();
+ _wait = new HashMap<Object, Long>();
+ _count = new HashMap<Object, Integer>();
+ _lastMatch = new HashMap<Object, Match>();
+ _names = new HashMap<Object, String>();
+// _appearOb = new HashMap<Object, SikuliEventObserver>();
+// _vanishOb = new HashMap<Object, SikuliEventObserver>();
+// _changeOb = new HashMap<Integer, SikuliEventObserver>();
+ _appearOb = new HashMap<Object, Object>();
+ _vanishOb = new HashMap<Object, Object>();
+ _changeOb = new HashMap<Integer, Object>();
+ _countc = new HashMap<Integer, Integer>();
+ _cnames = new HashMap<Integer, String>();
+ }
+
+ public void initialize() {
+ Debug.log(2, "SikuliEventManager: resetting observe states for " + _region.toStringShort());
+ sthgLeft = true;
+ for (Object ptn : _state.keySet()) {
+ _state.put(ptn, State.FIRST);
+ _count.put(ptn, 0);
+ }
+ for (int n : _changeOb.keySet()) {
+ _countc.put(n, 0);
}
}
-
- private static List<Entry> observers = Collections.synchronizedList(new ArrayList<Entry>());
- private static List<Event> events = Collections.synchronizedList(new ArrayList<Event>());
-
- /**
- * adds an Observer with a callback to the list
- *
- * @param reg the observed region
- * @param obs the callback
- * @param type one off Observer.Type.APPEAR, VANISH, CHANGE, GENERIC
- * @return a unique name derived from time or null if not possible
- */
- public static synchronized String add(Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
- String name = createName();
- if (add(name, reg, obs, type)) return name;
- return null;
+
+ public void setRegion(Region reg) {
+ _region = reg;
}
-
- /**
- * adds an observer to the list having no callback
- *
- * @param reg the observed region
- * @param name a unique name
- * @param type one off Observer.Type.APPEAR, VANISH, CHANGE, GENERIC
- * @return the observers name or null if not possible (duplicate?)
- */
- public static synchronized String add(Region reg, String name, SikuliEvent.Type type) {
- if (add(name, reg, null, type)) {
- return name;
- }
- return null;
+
+ public int getCount(Object ptn) {
+ return _count.get(ptn);
}
-
- /**
- * adds an observer of type GNERIC to the list having no callback
- *
- * @param name a unique name
- * @return the observers name or null if not possible (duplicate?)
- */
- public static synchronized String add(String name) {
- if (add(name, null, null, SikuliEvent.Type.GENERIC)) {
- return name;
+
+ private <PSC> float getSimiliarity(PSC ptn) {
+ float similarity = -1f;
+ if (ptn instanceof Pattern) {
+ similarity = ((Pattern) ptn).getSimilar();
+ }
+ if (similarity < 0) {
+ similarity = (float) Settings.MinSimilarity;
}
- return null;
+ return similarity;
+ }
+
+ public <PSC> void addAppearObserver(PSC ptn, SikuliEventObserver ob, String name) {
+ _appearOb.put(ptn, ob);
+ _state.put(ptn, State.FIRST);
+ _names.put(ptn, name);
+ }
+
+ public <PSC> void removeAppearObserver(PSC ptn) {
+ ObserverManager.remove(_names.get(ptn));
+ _names.remove(ptn);
+ _appearOb.remove(ptn);
+ _state.remove(ptn);
+ }
+
+ public <PSC> void addVanishObserver(PSC ptn, SikuliEventObserver ob, String name) {
+ _vanishOb.put(ptn, ob);
+ _state.put(ptn, State.FIRST);
+ _names.put(ptn, name);
}
-
- private static boolean add(String name, Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
- if (hasName(name, reg)) {
- return false;
+
+ public <PSC> void removeVanishObserver(PSC ptn) {
+ ObserverManager.remove(_names.get(ptn));
+ _names.remove(ptn);
+ _vanishOb.remove(ptn);
+ _state.remove(ptn);
+ }
+
+ private void callAppearObserver(Object ptn, Match m) {
+ ObserveAppear se = new ObserveAppear(ptn, m, _region);
+ Object ao = _appearOb.get(ptn);
+ ObserverManager.addEvent(_names.get(ptn), se);
+ if (ao != null && ao instanceof SikuliEventObserver) {
+ ((SikuliEventObserver)_appearOb.get(ptn)).targetAppeared(se);
}
- return observers.add(new Entry(name, reg, obs, type));
}
-
- private static String createName() {
- String name = null;
- while (null == name) {
- name = "" + new Date().getTime();
- if (!hasName(name, null)) {
- return name;
- } else {
- name = null;
- }
- try {
- Thread.sleep(5);
- } catch(Exception ex) {}
+
+ private void callVanishObserver(Object ptn, Match m) {
+ ObserveVanish se = new ObserveVanish(ptn, m, _region);
+ Object ao = _vanishOb.get(ptn);
+ ObserverManager.addEvent(_names.get(ptn), se);
+ if (ao != null && ao instanceof SikuliEventObserver) {
+ ((SikuliEventObserver)_vanishOb.get(ptn)).targetVanished(se);
}
- return null;
}
-
- private static boolean hasName(String name, Region reg) {
- for (Entry obs : observers) {
- if (name.equals(obs.name)) {
- if (reg != null && reg == obs.region) {
- return true;
+
+ private void checkPatterns(ScreenImage simg) {
+ Finder finder = null;
+ if (Settings.UseImageFinder) {
+ finder = new ImageFinder(_region);
+ ((ImageFinder) finder).setIsMultiFinder();
+ }
+ else {
+ finder = new Finder(simg, _region);
+ }
+ String imgOK;
+ Debug.log(3, "observe: checkPatterns entry: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving());
+ for (Object ptn : _state.keySet()) {
+ if (_state.get(ptn) != State.FIRST &&
+ _state.get(ptn) != State.UNKNOWN &&
+ _state.get(ptn) != State.REPEAT) {
+ continue;
+ }
+ imgOK = null;
+ if (ptn instanceof String) {
+ imgOK = finder.find((String) ptn);
+ Image img = Image.create((String) ptn);
+ if (img.isValid()) {
+ imgOK = finder.find(img);
+ } else if (img.isText()){
+ imgOK = finder.findText((String) ptn);
}
+ } else if (ptn instanceof Pattern) {
+ imgOK = finder.find((Pattern) ptn);
+ } else if (ptn instanceof Image) {
+ imgOK = finder.find((Image) ptn);
}
- }
- return false;
- }
-
- /**
- * remove the observer from the list, a region observer will be stopped <br>
- * registered events for that observer are removed as well
- *
- * @param name name of observer
- * @return success
- */
- public static boolean remove(String name) {
- return remove(null, name);
- }
-
- /**
- * stop and remove all observers registered for this region from the list <br>
- * registered events for those observers are removed as well
- *
- * @return success
- */
- public static boolean remove(Region reg) {
- return remove(reg, null);
- }
-
- /**
- * stop and remove the observer registered for this region from the list <br>
- * registered events for that observer are removed as well
- *
- * @param reg the observed region
- * @param name name of observer
- * @return success
- */
- public static synchronized boolean remove(Region reg, String name) {
- for (Entry obs : observers) {
- if (name != null) {
- if (name.equals(obs.name)) {
- if (reg == null || reg == obs.region) {
- remove(obs);
+ if (null == imgOK) {
+ Debug.error("EventMgr: checkPatterns: Image not valid", ptn);
+ _state.put(ptn, State.MISSING);
+ continue;
+ }
+ if (_state.get(ptn) == State.REPEAT) {
+ Debug.log(3, "repeat: checking");
+ if (_lastMatch.get(ptn).exists(ptn) != null) {
+ if ((new Date()).getTime() > _wait.get(ptn)) {
+ _state.put(ptn, State.APPEARED);
+ Debug.log(3, "repeat: vanish timeout");
+ // time out
+ } else {
+ sthgLeft = true;
}
+ continue; // not vanished within given time or still there
+ } else {
+ _state.put(ptn, State.UNKNOWN);
+ sthgLeft = true;
+ Debug.log(3, "repeat: has vanished");
+ continue; // has vanished, repeat
}
- } else if (reg != null && reg == obs.region) {
- remove(obs);
}
- }
- return true;
- }
-
- private static void remove(Entry obs) {
- if (obs.region != null) {
- obs.region.stopObserver();
- }
- observers.remove(obs);
- for (Event ev:events) {
- if (ev.observer == obs) {
- events.remove(ev);
+ Match m = null;
+ boolean hasMatch = false;
+ if (finder.hasNext()) {
+ m = finder.next();
+ if (m.getScore() >= getSimiliarity(ptn)) {
+ hasMatch = true;
+ _lastMatch.put(ptn, m);
+ }
}
- }
- }
-
- private static Entry get(Region reg, String name) {
- for (Entry obs : observers) {
- if (name != null) {
- if (name.equals(obs.name)) {
- if (reg == null || reg == obs.region) {
- return obs;
+ if (hasMatch) {
+ Debug.log(2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " +
+ m.toStringShort() + " in " + _region.toStringShort());
+ } else if (_state.get(ptn) == State.FIRST) {
+ Debug.log(2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " +
+ "NO" + " in " + _region.toStringShort());
+ _state.put(ptn, State.UNKNOWN);
+ }
+ if (_appearOb.containsKey(ptn)) {
+ if (_state.get(ptn) != State.APPEARED) {
+ if (hasMatch) {
+ _state.put(ptn, State.APPEARED);
+ _count.put(ptn, _count.get(ptn) + 1);
+ callAppearObserver(ptn, m);
+ } else {
+ sthgLeft = true;
+ }
+ }
+ } else if (_vanishOb.containsKey(ptn)) {
+ if (_state.get(ptn) != State.VANISHED) {
+ if (!hasMatch) {
+ _state.put(ptn, State.VANISHED);
+ _count.put(ptn, _count.get(ptn) + 1);
+ callVanishObserver(ptn, _lastMatch.get(ptn));
+ } else {
+ sthgLeft = true;
}
}
- } else if (reg != null && reg == obs.region) {
- return obs;
+ }
+ if (!_region.isObserving()) {
+ break;
}
}
- return null;
- }
-
- /**
- * stop and remove all observers and their registered events
- *
- * @return success
- */
- public static synchronized boolean clear() {
- for (Entry e : observers) {
- remove(e);
- }
- return true;
+ Debug.log(3, "observe: checkPatterns exit: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving());
}
-
- /**
- * are their any events registered
- *
- * @return true if yes
- */
- public static synchronized boolean hasEvents() {
- return events.size() > 0;
+
+ public void repeat(ObserveEvent.Type type, Object pattern, Match match, long secs) {
+ if (type == ObserveEvent.Type.CHANGE) {
+ Debug.error("EventMgr: repeat: CHANGE repeats automatically");
+ } else if (type == ObserveEvent.Type.VANISH) {
+ Debug.error("EventMgr: repeat: not supported for VANISH");
+ } else if (type == ObserveEvent.Type.APPEAR) {
+ _state.put(pattern, State.REPEAT);
+ if (secs <= 0) {
+ secs = (long) _region.getWaitForVanish();
+ }
+ _wait.put(pattern, (new Date()).getTime() + 1000 * secs);
+ Debug.log(2, "EventMgr: repeat: requested for APPEAR: " +
+ pattern.toString() + " at " + match.toStringShort() + " after " + secs + " seconds");
+ sthgLeft = true;
+ }
}
- /**
- * are their any events registered for this region
- *
- * @return true if yes
- */
- public static synchronized boolean hasEvents(Region reg) {
- return hasEvent(reg, null);
+ public void addChangeObserver(int threshold, SikuliEventObserver ob, String name) {
+ _changeOb.put(new Integer(threshold), ob);
+ _minChanges = getMinChanges();
+ _cnames.put(threshold, name);
}
- /**
- * are their any events registered for the observer having this name
- *
- * @return true if yes
- */
- public static synchronized boolean hasEvent(String name) {
- return hasEvent(null, name);
+ public void removeChangeObserver(int threshold) {
+ ObserverManager.remove(_cnames.get(threshold));
+ _names.remove(threshold);
+ _changeOb.remove(new Integer(threshold));
+ _minChanges = getMinChanges();
}
- /**
- * are their any events registered for the region's observer having this name
- *
- * @return true if yes
- */
- public static synchronized boolean hasEvent(Region reg, String name) {
- Entry obs = get(reg, name);
- if (obs == null) {
- return false;
- }
- for (Event ev:events) {
- if (ev.observer == obs) {
- return true;
+ private int getMinChanges() {
+ int min = Integer.MAX_VALUE;
+ for (Integer n : _changeOb.keySet()) {
+ if (n < min) {
+ min = n;
}
}
- return false;
- }
-
- /**
- * add a new event to the list
- *
- * @param name name of event
- * @param pev the event object (SikuliEvent is copied)
- * @return
- */
- public static synchronized long addEvent(String name, Object pev) {
- if (pev instanceof SikuliEvent) {
- Event evt = new Event();
- SikuliEvent event = (SikuliEvent) pev;
- evt.type = event.type;
- evt.changes = event.changes;
- evt.match = event.match;
- evt.pattern = event.pattern;
- evt.region = event.region;
- pev = evt;
- }
- Event ev = (Event) pev;
- ev.observer = get(null, name);
- ev.time = new Date().getTime();
- if (events.add(ev)) {
- return ev.time;
- }
- return 0;
+ return min;
}
- /**
- * remove and return the latest event for the named observer <br>
- * earlier events are removed
- *
- * @param name
- * @return the event or null if none registered
- */
- public static synchronized Event getEvent(String name) {
- return getEvent(name, true);
- }
-
- private static Event getEvent(String name, boolean remove) {
- Entry obs = get(null, name);
- Event event = null;
- if (obs != null) {
- for (Event ev:events) {
- if (ev.observer == obs) {
- if (event == null) {
- event = ev;
- continue;
- }
- if (ev.time > event.time) {
- events.remove(event);
- event = ev;
- }
+ private void callChangeObserver(FindResults results) throws AWTException {
+ for (Integer n : _changeOb.keySet()) {
+ List<Match> changes = new ArrayList<Match>();
+ for (int i = 0; i < results.size(); i++) {
+ FindResult r = results.get(i);
+ if (r.getW() * r.getH() >= n) {
+ changes.add(_region.toGlobalCoord(new Match(r, _region.getScreen())));
+ }
+ }
+ if (changes.size() > 0) {
+ _countc.put(n, _countc.get(n) + 1);
+ ObserveChange se = new ObserveChange(changes, _region);
+ Object ao = _changeOb.get(n);
+ ObserverManager.addEvent(_cnames.get(n), se);
+ if (ao instanceof SikuliEventObserver) {
+ ((SikuliEventObserver)_changeOb.get(n)).targetChanged(se);
}
}
}
- if (null != event && remove) {
- events.remove(event);
- }
- return event;
}
-
- /**
- * remove and return the latest events for that region <br>
- * earlier events are removed
- *
- * @return the array of events or size 0 array if none
- */
- public static synchronized Event[] getEvents(Region reg) {
- List<Event> evts = new ArrayList<Event>();
- for (Entry obs:observers) {
- if (reg == obs.region) evts.add(getEvent(obs.name));
+
+ private void checkChanges(ScreenImage img) {
+ if (Settings.UseImageFinder) {
+ //TODO hack to hide the native call - should be at the top
+ if (_lastImageMat == null) {
+ _lastImageMat = new org.opencv.core.Mat();
+ }
+ if (_lastImageMat.empty()) {
+ _lastImageMat = Image.createMat(img.getImage());
+ return;
+ }
+ ImageFinder f = new ImageFinder(_lastImageMat);
+ f.setMinChanges(_minChanges);
+ org.opencv.core.Mat current = Image.createMat(img.getImage());
+ if (f.hasChanges(current)) {
+ //TODO implement ChangeObserver: processing changes
+ Debug.log(3, "ChangeObserver: processing changes");
+ }
+ _lastImageMat = current;
+ }
+ else {
+ if (_lastImgMat == null) {
+ _lastImgMat = Image.convertBufferedImageToMat(img.getImage());
+ return;
+ }
+ FindInput fin = new FindInput();
+ fin.setSource(_lastImgMat);
+ Mat target = Image.convertBufferedImageToMat(img.getImage());
+ fin.setTarget(target);
+ fin.setSimilarity(_minChanges);
+ FindResults results = Vision.findChanges(fin);
+ try {
+ callChangeObserver(results);
+ } catch (AWTException e) {
+ Debug.error("EventMgr: checkChanges: ", e.getMessage());
+ }
+ _lastImgMat = target;
}
- return evts.toArray(new Event[0]);
}
- /**
- * return the latest events (these are preserved) <br>
- * earlier events for the same observer are removed
- *
- * @return the array of events or size 0 array if none
- */
- public static synchronized Event[] getEvents() {
- List<Event> evts = new ArrayList<Event>();
- for (Entry obs:observers) {
- evts.add(getEvent(obs.name, false));
+ public boolean update(ScreenImage simg) {
+ Debug.log(3, "observe: update entry: sthgLeft: %s obs? %s", sthgLeft, _region.isObserving());
+ boolean ret;
+ ret = sthgLeft;
+ if (sthgLeft) {
+ sthgLeft = false;
+ checkPatterns(simg);
+ if (!_region.isObserving()) {
+ return false;
+ }
+ }
+ if (_region.isObserving()) {
+ ret = sthgLeft;
+ if (_changeOb.size() > 0) {
+ checkChanges(simg);
+ if (!_region.isObserving()) {
+ return false;
+ }
+ ret = true;
+ }
}
- return evts.toArray(new Event[0]);
+ Debug.log(3, "observe: update exit: ret: %s", ret);
+ return ret;
}
-}
+}
\ No newline at end of file
diff --git a/API/src/main/java/org/sikuli/script/ObserverCallBack.java b/API/src/main/java/org/sikuli/script/ObserverCallBack.java
index 433a25e..e2a5481 100644
--- a/API/src/main/java/org/sikuli/script/ObserverCallBack.java
+++ b/API/src/main/java/org/sikuli/script/ObserverCallBack.java
@@ -1,55 +1,42 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+import java.util.EventListener;
+
/**
*
* Use this class to implement call back methods for the Region observers <br>
* onAppear, onVanish and onChange <br>
* by overriding the contained empty methods appeared, vanished and changed
- *
+ *
* example:<br>
* aRegion.onAppear(anImage, <br>
- * new ObserverCallBack() { <br>
+ new ObserverManagerCallBack() { <br>
* <br>
- * appeared(SikuliEvent e) { <br>
- * // do something
- * }
- * }
- * );
- * when the image appears, your above call back appeared() will be called
+ appeared(ObserveEvent e) { <br>
+ // do something
+ }
+ }
+ );
+ when the image appears, your above call back appeared() will be called
+ see ObserveEvent about the features available in the callback function
*/
-public class ObserverCallBack implements SikuliEventObserver {
-
- @Override
- public void targetAppeared(SikuliEventAppear e) {
- appeared(e);
- }
+public class ObserverCallBack implements EventListener {
- @Override
- public void targetVanished(SikuliEventVanish e) {
- vanished(e);
+ public void appeared(ObserveEvent e) {
}
- @Override
- public void targetChanged(SikuliEventChange e) {
- changed(e);
+ public void vanished(ObserveEvent e) {
}
- public void appeared(SikuliEvent e) {
+ public void changed(ObserveEvent e) {
}
- public void vanished(SikuliEvent e) {
- }
-
- public void changed(SikuliEvent e) {
- }
-
- public void happened(Observer.Event e) {
-
+ public void happened(ObserverManager.Event e) {
}
}
diff --git a/API/src/main/java/org/sikuli/script/Observer.java b/API/src/main/java/org/sikuli/script/ObserverManager.java
similarity index 81%
copy from API/src/main/java/org/sikuli/script/Observer.java
copy to API/src/main/java/org/sikuli/script/ObserverManager.java
index 604fd3b..3ef6054 100644
--- a/API/src/main/java/org/sikuli/script/Observer.java
+++ b/API/src/main/java/org/sikuli/script/ObserverManager.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
import java.util.ArrayList;
@@ -5,85 +11,91 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
-public class Observer {
-
+/**
+ * INTERNAL USE
+ * This class implements a container that globally collects
+ * all running observers, thus allowing to stop any observing
+ * on request (e.g. when script or Sikuli app ends)
+ */
+public class ObserverManager {
+
private static class Entry {
-
- private Region region;
- private String name;
- private SikuliEvent.Type type;
- private boolean isActive = true;
- private ObserverCallBack obs;
-
- protected Entry(String name, Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
+
+ private final Region region;
+ private final String name;
+ private final ObserveEvent.Type type;
+ private final boolean isActive = true;
+ private final ObserverCallBack obs;
+
+ protected Entry(String name, Region reg, ObserverCallBack obs, ObserveEvent.Type type) {
this.name = name;
region = reg;
this.obs = obs;
this.type = type;
}
}
-
- public static class Event extends SikuliEvent {
+
+ public static class Event extends ObserveEvent {
private Entry observer;
private long time;
-
+
public long getTime() {
return time;
}
}
-
+
private static List<Entry> observers = Collections.synchronizedList(new ArrayList<Entry>());
private static List<Event> events = Collections.synchronizedList(new ArrayList<Event>());
-
+
/**
- * adds an Observer with a callback to the list
- *
+ * adds an ObserverManager with a callback to the list
+ *
* @param reg the observed region
* @param obs the callback
- * @param type one off Observer.Type.APPEAR, VANISH, CHANGE, GENERIC
+ * @param type one off ObserverManager.Type.APPEAR, VANISH, CHANGE, GENERIC
* @return a unique name derived from time or null if not possible
*/
- public static synchronized String add(Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
+ public static synchronized String add(Region reg, ObserverCallBack obs, ObserveEvent.Type type) {
String name = createName();
if (add(name, reg, obs, type)) return name;
return null;
}
-
+
/**
- * adds an observer to the list having no callback
- *
+ * adds an observer to the list having no callback
+ *
* @param reg the observed region
* @param name a unique name
- * @param type one off Observer.Type.APPEAR, VANISH, CHANGE, GENERIC
+ * @param type one off ObserverManager.Type.APPEAR, VANISH, CHANGE, GENERIC
* @return the observers name or null if not possible (duplicate?)
*/
- public static synchronized String add(Region reg, String name, SikuliEvent.Type type) {
+ public static synchronized String add(Region reg, String name, ObserveEvent.Type type) {
if (add(name, reg, null, type)) {
return name;
}
return null;
}
-
+
/**
- * adds an observer of type GNERIC to the list having no callback
- *
+ * adds an observer of type GNERIC to the list having no callback
+ *
* @param name a unique name
* @return the observers name or null if not possible (duplicate?)
*/
public static synchronized String add(String name) {
- if (add(name, null, null, SikuliEvent.Type.GENERIC)) {
+ if (add(name, null, null, ObserveEvent.Type.GENERIC)) {
return name;
}
return null;
}
-
- private static boolean add(String name, Region reg, ObserverCallBack obs, SikuliEvent.Type type) {
+
+ private static boolean add(String name, Region reg, ObserverCallBack obs, ObserveEvent.Type type) {
if (hasName(name, reg)) {
return false;
}
- return observers.add(new Entry(name, reg, obs, type));
+ return observers.add(new Entry(name, reg, obs, type));
}
-
+
private static String createName() {
String name = null;
while (null == name) {
@@ -99,7 +111,7 @@ public class Observer {
}
return null;
}
-
+
private static boolean hasName(String name, Region reg) {
for (Entry obs : observers) {
if (name.equals(obs.name)) {
@@ -110,18 +122,18 @@ public class Observer {
}
return false;
}
-
+
/**
* remove the observer from the list, a region observer will be stopped <br>
* registered events for that observer are removed as well
- *
+ *
* @param name name of observer
* @return success
*/
public static boolean remove(String name) {
return remove(null, name);
}
-
+
/**
* stop and remove all observers registered for this region from the list <br>
* registered events for those observers are removed as well
@@ -131,11 +143,11 @@ public class Observer {
public static boolean remove(Region reg) {
return remove(reg, null);
}
-
+
/**
* stop and remove the observer registered for this region from the list <br>
* registered events for that observer are removed as well
- *
+ *
* @param reg the observed region
* @param name name of observer
* @return success
@@ -154,7 +166,7 @@ public class Observer {
}
return true;
}
-
+
private static void remove(Entry obs) {
if (obs.region != null) {
obs.region.stopObserver();
@@ -166,7 +178,7 @@ public class Observer {
}
}
}
-
+
private static Entry get(Region reg, String name) {
for (Entry obs : observers) {
if (name != null) {
@@ -181,22 +193,22 @@ public class Observer {
}
return null;
}
-
+
/**
* stop and remove all observers and their registered events
- *
+ *
* @return success
*/
public static synchronized boolean clear() {
for (Entry e : observers) {
remove(e);
- }
+ }
return true;
}
-
+
/**
* are their any events registered
- *
+ *
* @return true if yes
*/
public static synchronized boolean hasEvents() {
@@ -205,7 +217,7 @@ public class Observer {
/**
* are their any events registered for this region
- *
+ *
* @return true if yes
*/
public static synchronized boolean hasEvents(Region reg) {
@@ -214,7 +226,7 @@ public class Observer {
/**
* are their any events registered for the observer having this name
- *
+ *
* @return true if yes
*/
public static synchronized boolean hasEvent(String name) {
@@ -223,7 +235,7 @@ public class Observer {
/**
* are their any events registered for the region's observer having this name
- *
+ *
* @return true if yes
*/
public static synchronized boolean hasEvent(Region reg, String name) {
@@ -238,23 +250,23 @@ public class Observer {
}
return false;
}
-
+
/**
- * add a new event to the list
- *
+ * add a new event to the list
+ *
* @param name name of event
- * @param pev the event object (SikuliEvent is copied)
- * @return
+ * @param pev the event object (ObserveEvent is copied)
+ * @return the time of creation
*/
public static synchronized long addEvent(String name, Object pev) {
- if (pev instanceof SikuliEvent) {
- Event evt = new Event();
- SikuliEvent event = (SikuliEvent) pev;
+ if (pev instanceof ObserveEvent) {
+ ObserveEvent evt = (ObserveEvent) new Event();
+ ObserveEvent event = (ObserveEvent) pev;
evt.type = event.type;
- evt.changes = event.changes;
- evt.match = event.match;
- evt.pattern = event.pattern;
- evt.region = event.region;
+ evt.setChanges(event.getChanges());
+ evt.setMatch(event.getMatch());
+ evt.setPattern(event.getPattern());
+ evt.setRegion(event.getRegion());
pev = evt;
}
Event ev = (Event) pev;
@@ -269,14 +281,14 @@ public class Observer {
/**
* remove and return the latest event for the named observer <br>
* earlier events are removed
- *
+ *
* @param name
* @return the event or null if none registered
*/
public static synchronized Event getEvent(String name) {
return getEvent(name, true);
}
-
+
private static Event getEvent(String name, boolean remove) {
Entry obs = get(null, name);
Event event = null;
@@ -299,7 +311,7 @@ public class Observer {
}
return event;
}
-
+
/**
* remove and return the latest events for that region <br>
* earlier events are removed
@@ -317,7 +329,7 @@ public class Observer {
/**
* return the latest events (these are preserved) <br>
* earlier events for the same observer are removed
- *
+ *
* @return the array of events or size 0 array if none
*/
public static synchronized Event[] getEvents() {
diff --git a/API/src/main/java/org/sikuli/script/OverlayAnimator.java b/API/src/main/java/org/sikuli/script/OverlayAnimator.java
index afc9f11..801248c 100755
--- a/API/src/main/java/org/sikuli/script/OverlayAnimator.java
+++ b/API/src/main/java/org/sikuli/script/OverlayAnimator.java
@@ -1,14 +1,17 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.util.Date;
-
+/**
+ * INTERNAL USE
+ * allows to implement timed animations (e.g. mouse move)
+ */
public interface OverlayAnimator {
public float step();
diff --git a/API/src/main/java/org/sikuli/script/OverlayCapturePrompt.java b/API/src/main/java/org/sikuli/script/OverlayCapturePrompt.java
index 397bc3c..86c97e7 100755
--- a/API/src/main/java/org/sikuli/script/OverlayCapturePrompt.java
+++ b/API/src/main/java/org/sikuli/script/OverlayCapturePrompt.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -13,6 +13,10 @@ import java.awt.event.*;
import java.awt.image.*;
import org.sikuli.natives.SysUtil;
+/**
+ * INTERNAL USE
+ * implements the screen overlay used with the capture feature
+ */
public class OverlayCapturePrompt extends OverlayTransparentWindow implements EventSubject {
static Color _overlayColor = new Color(0F, 0F, 0F, 0.6F);
diff --git a/API/src/main/java/org/sikuli/script/OverlayTransparentWindow.java b/API/src/main/java/org/sikuli/script/OverlayTransparentWindow.java
index b7c790f..38c2c55 100755
--- a/API/src/main/java/org/sikuli/script/OverlayTransparentWindow.java
+++ b/API/src/main/java/org/sikuli/script/OverlayTransparentWindow.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -17,6 +17,10 @@ import java.lang.reflect.Method;
import javax.swing.JFrame;
import javax.swing.JPanel;
+/**
+ * INTERNAL USE
+ * implements a transparent screen overlay for various purposes
+ */
public class OverlayTransparentWindow extends JFrame implements EventSubject {
static Method __setWindowOpacity = null;
diff --git a/API/src/main/java/org/sikuli/script/Pattern.java b/API/src/main/java/org/sikuli/script/Pattern.java
index 8df42d1..6d71bcf 100755
--- a/API/src/main/java/org/sikuli/script/Pattern.java
+++ b/API/src/main/java/org/sikuli/script/Pattern.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
diff --git a/API/src/main/java/org/sikuli/script/Region.java b/API/src/main/java/org/sikuli/script/Region.java
index 9fdd479..335e9ca 100755
--- a/API/src/main/java/org/sikuli/script/Region.java
+++ b/API/src/main/java/org/sikuli/script/Region.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -19,9 +19,8 @@ import org.sikuli.basics.Debug;
import org.sikuli.basics.Settings;
/**
- * A Region always lies completely inside its parent screen
+ * A Region is a rectengular area and lies always completely inside its parent screen
*
- * @author RaiMan
*/
public class Region {
@@ -78,15 +77,15 @@ public class Region {
private float observeScanRate = Settings.ObserveScanRate;
private int waitForVanish = Settings.WaitForVanish;
/**
- * The {@link SikuliEventManager} Singleton instance
+ * The {@link Observer} Singleton instance
*/
- private SikuliEventManager evtMgr = null;
+ private Observer evtMgr = null;
- public SikuliEventManager getEvtMgr() {
+ public Observer getEvtMgr() {
return evtMgr;
}
- public void setEvtMgr(SikuliEventManager em) {
+ public void setEvtMgr(Observer em) {
evtMgr = em;
}
/**
@@ -578,8 +577,8 @@ public class Region {
}
/**
- * used in SikuliEventManager.callChangeObserver, Finder.next to adjust region relative coordinates of matches to
- * screen coordinates
+ * used in Observer.callChangeObserverManager, Finder.next to adjust region relative coordinates of matches to
+ screen coordinates
*
* @param m
* @return the modified match
@@ -2459,10 +2458,10 @@ public class Region {
}
//</editor-fold>
- //<editor-fold defaultstate="collapsed" desc="Observer">
- private SikuliEventManager getEventManager() {
+ //<editor-fold defaultstate="collapsed" desc="ObserverManager">
+ private Observer getEventManager() {
if (evtMgr == null) {
- evtMgr = new SikuliEventManager(this);
+ evtMgr = new Observer(this);
}
return evtMgr;
}
@@ -2476,13 +2475,14 @@ public class Region {
}
/**
- * a subsequently started observer in this region should wait for target
- * and notify the given observer about this event
+ * a subsequently started observer in this region should wait for target
+ * and notify the given observer about this event
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
+ * @param <PSI> Pattern, String or Image
* @param target
* @param observer
- * @return
+ * @return the event's name
*/
public <PSI> String onAppear(PSI target, Object observer) {
return onAppearDo(target, observer);
@@ -2490,25 +2490,30 @@ public class Region {
/**
*INTERNAL USE ONLY: for use with scripting API bridges
+ * @param <PSI> Pattern, String or Image
+ * @param target
+ * @param observer
+ * @return the event's name
*/
public <PSI> String onAppearJ(PSI target, Object observer) {
return onAppearDo(target, observer);
}
private <PSI> String onAppearDo(PSI target, Object observer) {
- String name = Observer.add(this, (ObserverCallBack) observer, SikuliEvent.Type.APPEAR);
+ String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.APPEAR);
getEventManager().addAppearObserver(target, (SikuliEventObserver) observer, name);
return name;
}
/**
- * a subsequently started observer in this region should wait for the target to vanish
- * and notify the given observer about this event
+ * a subsequently started observer in this region should wait for the target to vanish
+ * and notify the given observer about this event
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
+ * @param <PSI> Pattern, String or Image
* @param target
* @param observer
- * @return
+ * @return the event's name
*/
public <PSI> String onVanish(PSI target, Object observer) {
return onVanishDo(target, observer);
@@ -2516,38 +2521,42 @@ public class Region {
/**
*INTERNAL USE ONLY: for use with scripting API bridges
+ * @param <PSI> Pattern, String or Image
+ * @param target
+ * @param observer
+ * @return the event's name
*/
public <PSI> String onVanishJ(PSI target, Object observer) {
return onVanishDo(target, observer);
}
private <PSI> String onVanishDo(PSI target, Object observer) {
- String name = Observer.add(this, (ObserverCallBack) observer, SikuliEvent.Type.VANISH);
+ String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.VANISH);
getEventManager().addVanishObserver(target, (SikuliEventObserver) observer, name);
return name;
}
/**
- * a subsequently started observer in this region should wait for changes in the region
- * and notify the given observer about this event
+ * a subsequently started observer in this region should wait for changes in the region
+ * and notify the given observer about this event
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
* @param threshold minimum size of changes (rectangle threshhold x threshold)
* @param observer
- * @return
+ * @return the event's name
*/
public String onChange(int threshold, Object observer) {
return onChangeDo(threshold, observer);
}
/**
- * a subsequently started observer in this region should wait for changes in the region
+ * a subsequently started observer in this region should wait for changes in the region
* and notify the given observer about this event <br />
* minimum size of changes used: Settings.ObserveMinChangedPixels
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
* @param observer
- * @return
+ * @return the event's name
*/
public String onChange(Object observer) {
return onChangeDo(rows, observer);
@@ -2555,6 +2564,9 @@ public class Region {
/**
*INTERNAL USE ONLY: for use with scripting API bridges
+ * @param minSize
+ * @param observer
+ * @return the event's name
*/
public String onChangeJ(int minSize, Object observer) {
if (minSize == 0) {
@@ -2565,28 +2577,27 @@ public class Region {
}
public String onChangeDo(int threshold, Object observer) {
- String name = Observer.add(this, (ObserverCallBack) observer, SikuliEvent.Type.CHANGE);
+ String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.CHANGE);
getEventManager().addChangeObserver(threshold, (SikuliEventObserver) observer, name);
return name;
}
/**
- * start an observer in this region that runs forever (use stopObserver() in handler)
- * for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
- * @param secs
- * @return
+ * start an observer in this region that runs forever (use stopObserverManager() in handler)
+ for details about the observe event handler: {@link SikuliEventObserver}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
+ * @return false if not possible, true if events have happened
*/
- public void observe() {
- observe(Float.POSITIVE_INFINITY);
+ public boolean observe() {
+ return observe(Float.POSITIVE_INFINITY);
}
/**
* start an observer in this region for the given time
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
* @param secs
- * @return
+ * @return false if not possible, true if events have happened
*/
public boolean observe(double secs) {
return observeDo(secs);
@@ -2594,12 +2605,15 @@ public class Region {
/**
*INTERNAL USE ONLY: for use with scripting API bridges
+ * @param secs
+ * @param bg
+ * @return false if not possible, true if events have happened
*/
- public void observeJ(double secs, boolean bg) {
+ public boolean observeJ(double secs, boolean bg) {
if (bg) {
- observeInBackground(secs);
+ return observeInBackground(secs);
} else {
- observeDo(secs);
+ return observeDo(secs);
}
}
@@ -2608,7 +2622,7 @@ public class Region {
Debug.error("Region: observe: Nothing to observe (Region might be invalid): " + this.toStringShort());
return false;
}
- Observer.getEvents(this);
+ ObserverManager.getEvents(this);
if (observing) {
Debug.error("Region: observe: already running for this region. Only one allowed!");
return false;
@@ -2646,25 +2660,26 @@ public class Region {
Debug.log(2, "Region: observe: observing has ended for " + this.toStringShort());
}
SikuliX.removeRunningObserver(this);
- return Observer.hasEvents(this);
+ return ObserverManager.hasEvents(this);
}
/**
* start an observer in this region for the given time that runs in background
* for details about the observe event handler: {@link SikuliEventObserver}
- * for details about APPEAR/VANISH/CHANGE events: {@link SikuliEvent}
+ * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
* @param secs
- * @return
+ * @return false if not possible, true otherwise
*/
- public void observeInBackground(double secs) {
+ public boolean observeInBackground(double secs) {
if (observing) {
Debug.error("Region: observeInBackground: already running for this region. Only one allowed!");
- return;
+ return false;
}
Debug.log(3, "entering observeInBackground for %f secs", secs);
Thread observeThread = new Thread(new ObserverThread(secs));
observeThread.start();
Debug.log(3, "observeInBackground now running");
+ return true;
}
private class ObserverThread implements Runnable {
@@ -3141,10 +3156,10 @@ public class Region {
* where X-X and X are refrences for special keys and N is an otional repeat factor <br />
* the trailing . ends the special key, a + or - does the same, <br />
* but signals press-and-hold or release additionally.<br />
- * a #Wn. inserts a wait of n millisecs or n secs if n < 60 <br />
+ * a #Wn. inserts a wait of n millisecs or n secs if n < 60 <br />
* for more details and examples consult the docs <br />
* @param text a coded text interpreted as a series of key actions (press/hold/release)
- * @return
+ * @return 0 for success 1 otherwise
*/
public int write(String text) {
Debug.info("Write: " + text);
diff --git a/API/src/main/java/org/sikuli/script/RobotDesktop.java b/API/src/main/java/org/sikuli/script/RobotDesktop.java
index 0e8cfd2..4871d65 100755
--- a/API/src/main/java/org/sikuli/script/RobotDesktop.java
+++ b/API/src/main/java/org/sikuli/script/RobotDesktop.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -20,6 +20,10 @@ import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
+/**
+ * INTERNAL USE
+ * Implemenation of IRobot making a DeskTopRobot using java.awt.Robot
+ */
public class RobotDesktop extends Robot implements IRobot {
final static int MAX_DELAY = 60000;
@@ -32,7 +36,7 @@ public class RobotDesktop extends Robot implements IRobot {
public boolean isRemote() {
return false;
}
-
+
@Override
public Screen getScreen() {
return scr;
@@ -75,7 +79,7 @@ public class RobotDesktop extends Robot implements IRobot {
private void moveMouseAndCheckPos(Location p, Screen s) {
//TODO Why? need to correct double correction of gdLoc (top left of screen grafic area) when not (0,0)
- //Check at initScreens
+ //Check at initScreens
s.getRobot().mouseMove(p.x, p.y);
PointerInfo mp = MouseInfo.getPointerInfo();
Point pc;
diff --git a/API/src/main/java/org/sikuli/script/RobotRemote.java b/API/src/main/java/org/sikuli/script/RobotRemote.java
index 30f8536..1251c6a 100644
--- a/API/src/main/java/org/sikuli/script/RobotRemote.java
+++ b/API/src/main/java/org/sikuli/script/RobotRemote.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
import java.awt.Color;
@@ -10,6 +16,12 @@ import javax.swing.ImageIcon;
import org.sikuli.basics.Debug;
import org.sikuli.basics.Settings;
+/**
+ * INTERNAL USE - UNDER DEVELOPMENT - EXPERIMENTAL
+ * Implemenation of IRobot that redirects actions targeted towards a DesktopRobot
+ * to a remote DesktopRobot that in turn is implemented in the package Sikuli-Remote.
+ * The remote communication is implemented on sockets in the driving ScreenRemote
+ */
public class RobotRemote implements IRobot {
private static int heldButtons = 0;
@@ -59,7 +71,7 @@ public class RobotRemote implements IRobot {
try {
numberScreens = Integer.parseInt(sys.substring(sys.indexOf(" ") + 1));
} catch(Exception ex) {
- log(-1, "could not get remote numberScreens - robot might not be useable: " + sys);
+ log(-1, "could not get remote numberScreens - robot might not be useable: " + sys);
}
}
}
@@ -67,7 +79,7 @@ public class RobotRemote implements IRobot {
public boolean isValid() {
return (scr != null);
}
-
+
@Override
public boolean isRemote() {
return true;
@@ -80,11 +92,11 @@ public class RobotRemote implements IRobot {
public int getNumberScreens() {
return numberScreens;
}
-
+
public Rectangle getBounds() {
return getBounds(0);
}
-
+
public Rectangle getBounds(int screenID) {
return (Rectangle) send("BOUNDS " + screenID);
}
@@ -192,7 +204,7 @@ public class RobotRemote implements IRobot {
Key.toJavaKeyCode(character)[0]);
doType(mode, Key.toJavaKeyCode(character));
}
-
+
@Override
public void typeKey(int key) {
if ("MAC".equals(system)) {
@@ -278,7 +290,7 @@ public class RobotRemote implements IRobot {
typeCommand = null;
clickCommand = mClick;
}
-
+
@Override
public void clickEnds() {
result = (String) send(clickCommand);
@@ -288,14 +300,14 @@ public class RobotRemote implements IRobot {
public Location mousePointer() {
return new Location((Point) send(mouse));
}
-
+
@Override
public void mouseDown(int buttons) {
if (heldButtons != 0) {
heldButtons |= buttons;
} else {
heldButtons = buttons;
- }
+ }
if (clickCommand == null) {
result = (String) send(String.format("%s D%d", mouse, heldButtons));
} else {
@@ -367,7 +379,7 @@ public class RobotRemote implements IRobot {
@Override
public Color getColorAt(int x, int y) {
- throw new UnsupportedOperationException("Not supported yet.");
+ throw new UnsupportedOperationException("Not supported yet.");
}
@Override
diff --git a/API/src/main/java/org/sikuli/script/Screen.java b/API/src/main/java/org/sikuli/script/Screen.java
index 5dcb333..ae9ee54 100755
--- a/API/src/main/java/org/sikuli/script/Screen.java
+++ b/API/src/main/java/org/sikuli/script/Screen.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -41,11 +41,11 @@ public class Screen extends Region implements EventObserver, IScreen {
private static Point lastMousePosition = null;
//<editor-fold defaultstate="collapsed" desc="Initialization">
-
+
static {
initScreens(false);
}
-
+
// private static void initScreens() {
// initScreens(false);
// }
@@ -115,17 +115,32 @@ public class Screen extends Region implements EventObserver, IScreen {
curID = id;
initScreen();
}
-
- public Screen(boolean isScreenUnion) {
+
+ /**
+ * INTERNAL USE
+ * collect all physical screens to one big region<br />
+ * This is under evaluation, wether it really makes sense
+ * @param isScreenUnion
+ */
+ public Screen(boolean isScreenUnion) {
super();
// initScreens();
}
-
+
+ /**
+ * INTERNAL USE
+ * collect all physical screens to one big region<br />
+ * This is under evaluation, wether it really makes sense
+ */
public void setAsScreenUnion() {
oldID = curID;
curID = -1;
}
+ /**
+ * INTERNAL USE
+ * reset from being a screen union to the screen used before
+ */
public void setAsScreen() {
curID = oldID;
}
@@ -213,6 +228,7 @@ public class Screen extends Region implements EventObserver, IScreen {
}
//</editor-fold>
+
//<editor-fold defaultstate="collapsed" desc="getters setters">
protected boolean useFullscreen() {
return false;
@@ -285,6 +301,7 @@ public class Screen extends Region implements EventObserver, IScreen {
/**
*
+ * @return the id
*/
public int getID() {
return curID;
@@ -292,6 +309,7 @@ public class Screen extends Region implements EventObserver, IScreen {
/**
*
+ * @return active GraphicsDevice
*/
public GraphicsDevice getGraphicsDevice() {
return curGD;
@@ -306,7 +324,10 @@ public class Screen extends Region implements EventObserver, IScreen {
public IRobot getRobot() {
return robot;
}
-
+ /**
+ *
+ * @return the screen's rectangle
+ */
@Override
public Rectangle getBounds() {
return curGD.getDefaultConfiguration().getBounds();
@@ -325,7 +346,7 @@ public class Screen extends Region implements EventObserver, IScreen {
public Region newRegion(Location loc, int width, int height) {
return Region.create(loc.copyTo(this), width, height);
}
-
+
protected ScreenImage getLastScreenImageFromScreen() {
return lastScreenImage;
}
@@ -342,6 +363,7 @@ public class Screen extends Region implements EventObserver, IScreen {
}
//</editor-fold>
+
//<editor-fold defaultstate="collapsed" desc="Capture - SelectRegion">
/**
* create a ScreenImage with the physical bounds of this screen
diff --git a/API/src/main/java/org/sikuli/script/ScreenHighlighter.java b/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
index c27b546..1faa7ca 100755
--- a/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
+++ b/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -14,6 +14,10 @@ import java.awt.image.*;
import java.util.HashSet;
import java.util.Set;
+/**
+ * INTERNAL USE
+ * produces and manages the red framed rectangles from Region.highlight()
+ */
public class ScreenHighlighter extends OverlayTransparentWindow implements MouseListener {
static Color _overlayColor = new Color(0F, 0F, 0F, 0.6F);
diff --git a/API/src/main/java/org/sikuli/script/ScreenImage.java b/API/src/main/java/org/sikuli/script/ScreenImage.java
index c9f8b6b..c71df93 100755
--- a/API/src/main/java/org/sikuli/script/ScreenImage.java
+++ b/API/src/main/java/org/sikuli/script/ScreenImage.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -12,15 +12,16 @@ import org.sikuli.basics.Debug;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
-import java.util.*;
import javax.imageio.ImageIO;
/**
+ * CANDIDATE FOR DEPRECATION
+ *
* stores a BufferedImage usually ceated by screen capture,
* the screen rectangle it was taken from and
* the filename, where it is stored as PNG (only if requested)
*
- * @author RaiMan
+ * This will be replaced by Image in the long run
*/
public class ScreenImage {
diff --git a/API/src/main/java/org/sikuli/script/ScreenRemote.java b/API/src/main/java/org/sikuli/script/ScreenRemote.java
index 6c0fadb..edb9c4c 100644
--- a/API/src/main/java/org/sikuli/script/ScreenRemote.java
+++ b/API/src/main/java/org/sikuli/script/ScreenRemote.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
+ * Released under the MIT License.
+ *
+ * modified RaiMan
+ */
package org.sikuli.script;
import java.awt.Rectangle;
@@ -8,6 +14,12 @@ import java.net.Socket;
import org.sikuli.basics.Debug;
import org.sikuli.basics.FileManager;
+/**
+ * UNDER DEVELOPMENT - EXPERIMENTAL
+ * an extension to the DesktopScreen implementation Screen,
+ * that allows to redirect the actions to a remote screen/keyboard/mouse
+ * in conjunction with the package SikuliX-Remote running on the remote system
+ */
public class ScreenRemote extends Screen implements IScreen{
private ObjectInputStream in = null;
@@ -20,19 +32,19 @@ public class ScreenRemote extends Screen implements IScreen{
private String system = "";
private int numberScreens = 0;
private int curID;
-
+
private static void log(int level, String message, Object... args) {
Debug.logx(level, "", "ScreenRemote: " + message, args);
}
-
+
private static void log(String message, Object... args) {
log(3, message, args);
}
-
+
public ScreenRemote(String adr, String p) {
init(adr, p);
}
-
+
private void init(String adr, String p) {
socketValid = true;
rrobot = null;
@@ -73,21 +85,21 @@ public class ScreenRemote extends Screen implements IScreen{
setH(rh);
}
}
-
+
@Override
public String toString() {
return String.format("S(R-%d)[%dx%d]", curID, rw, rh);
}
-
+
@Override
public String toStringShort() {
return toString();
}
-
+
public boolean isValid() {
return (socketValid && socket != null);
}
-
+
public ObjectInputStream getIn() {
return in;
}
@@ -95,7 +107,7 @@ public class ScreenRemote extends Screen implements IScreen{
public OutputStreamWriter getOut() {
return out;
}
-
+
public boolean close(boolean stopServer) {
if (rrobot != null) {
rrobot.cleanup();
@@ -118,11 +130,11 @@ public class ScreenRemote extends Screen implements IScreen{
rrobot = null;
return true;
}
-
+
public boolean close() {
return close(false);
}
-
+
@Override
public IRobot getRobot() {
return rrobot;
@@ -135,7 +147,7 @@ public class ScreenRemote extends Screen implements IScreen{
@Override
public ScreenImage capture() {
- return capture(0, 0, rw, rh);
+ return capture(0, 0, rw, rh);
}
@Override
@@ -152,7 +164,7 @@ public class ScreenRemote extends Screen implements IScreen{
public ScreenImage capture(Region r) {
return capture(r.x, r.y, r.w, r.h);
}
-
+
@Override
public Location newLocation(Location loc) {
return loc.setOtherScreen(this);
@@ -161,7 +173,7 @@ public class ScreenRemote extends Screen implements IScreen{
public Location newLocation(int x, int y) {
return new Location(x, y).setOtherScreen(this);
}
-
+
@Override
public Region newRegion (Location loc, int w, int h) {
return new Region(loc.x, loc.y, w, h, loc.getScreen());
@@ -170,15 +182,15 @@ public class ScreenRemote extends Screen implements IScreen{
public Region newRegion (int x, int y, int w, int h) {
return new Region(x, y, w, h, this);
}
-
+
public Region newRegion (Region r) {
return new Region(r.x, r.y, r.w, r.h, this);
}
-
+
public Region newRegion (Rectangle r) {
return new Region(r.x, r.y, r.width, r.height, this);
}
-
+
public Location mousePointer() {
Location loc = rrobot.mousePointer();
if (loc != null) {
diff --git a/API/src/main/java/org/sikuli/script/ScreenUnion.java b/API/src/main/java/org/sikuli/script/ScreenUnion.java
index 00b7a51..44ae22f 100755
--- a/API/src/main/java/org/sikuli/script/ScreenUnion.java
+++ b/API/src/main/java/org/sikuli/script/ScreenUnion.java
@@ -1,14 +1,21 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import org.sikuli.basics.Debug;
import java.awt.Rectangle;
+/**
+ * CANDIDATE FOR DEPRECATION
+ * INTERNAL USE
+ * An extension of DesktopScreen, that uses all active monitors as one big screen
+ *
+ * TO BE EVALUATED: is this really needed?
+ */
public class ScreenUnion extends Screen {
private Rectangle _bounds;
@@ -39,7 +46,7 @@ public class ScreenUnion extends Screen {
x, y, _x, _y, sr.x, sr.y, sr.width, sr.height);
return 0;
}
-
+
@Override
public Rectangle getBounds() {
if (_bounds == null) {
diff --git a/API/src/main/java/org/sikuli/script/SikuliEvent.java b/API/src/main/java/org/sikuli/script/SikuliEvent.java
old mode 100755
new mode 100644
index bd18316..f523bc6
--- a/API/src/main/java/org/sikuli/script/SikuliEvent.java
+++ b/API/src/main/java/org/sikuli/script/SikuliEvent.java
@@ -1,128 +1,15 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
-package org.sikuli.script;
-
-import java.util.List;
-
-public class SikuliEvent {
-
- public enum Type {
- APPEAR, VANISH, CHANGE, GENERIC
- }
-
- /**
- * the event's type as SikuliEvent.APPEAR, .VANISH, .CHANGE
- */
- public Type type;
-
- private Region region = null;
- private Match match = null;
- private List<Match> changes = null;
- private Object pattern = null;
-
- public SikuliEvent() {
- }
-
- /**
- * INTERNAL USE ONLY: creates an observed event
- */
- public SikuliEvent(Object ptn, Match m, Region r) {
- region = r;
- match = m;
- pattern = ptn;
- }
- /**
- *
- * @return this event's observer's region
- */
- public Region getRegion() {
- return region;
- }
-
- protected void setRegion(Region r) {
- region = r;
- }
-
- /**
- *
- * @return the observed match (APEAR, VANISH)
- */
- public Match getMatch() {
- return match;
- }
-
- protected void setMatch(Match m) {
- match = m;
- }
-
- /**
- *
- * @return a list of observed changes as matches (CHANGE)
- */
- public List<Match> getChanges() {
- return changes;
- }
-
- protected void setChanges(List<Match> c) {
- changes = c;
- }
+package org.sikuli.script;
- /**
- *
- * @return the used pattern for this event's observing
- */
- public Pattern getPattern() {
- if (pattern.getClass().isInstance("")) {
- return (new Pattern((String) pattern));
- } else {
- return (new Pattern((Pattern) pattern));
- }
- }
+/**
+ * CANDIDATE FOR DEPRECATION - ONLY HERE TO BE BACKWARD COMPATIBLE
+ */
+public class SikuliEvent extends ObserveEvent {
- /**
- * tell the observer to repeat this event's observe action immediately
- * after returning from this handler (APPEAR, VANISH)
- */
- public void repeat() {
- repeat(0);
- }
-
- /**
- * tell the observer to repeat this event's observe action after given time in secs
- * after returning from this handler (APPEAR, VANISH)
- * @param secs
- */
- public void repeat(long secs) {
- region.getEvtMgr().repeat(type, pattern, match, secs);
- }
-
- /**
- * only for (APPEAR, VANISH)
- * @return the number how often this event has already been triggered until now
- */
- public int getCount() {
- if (type == Type.CHANGE) {
- return 0;
- } else {
- return region.getEvtMgr().getCount(pattern);
- }
- }
-
- /**
- * stops the observer after returning from the handler
- */
- public void stopObserver() {
- region.stopObserver();
- }
-
- @Override
- public String toString() {
- return String.format("SikuliEvent(%s) on %s with %s having last match: %s",
- type, region, pattern, match);
- }
}
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventAdapter.java b/API/src/main/java/org/sikuli/script/SikuliEventAdapter.java
index 64b7eac..5573dfd 100755
--- a/API/src/main/java/org/sikuli/script/SikuliEventAdapter.java
+++ b/API/src/main/java/org/sikuli/script/SikuliEventAdapter.java
@@ -14,26 +14,26 @@ package org.sikuli.script;
public class SikuliEventAdapter implements SikuliEventObserver {
@Override
- public void targetAppeared(SikuliEventAppear e) {
+ public void targetAppeared(ObserveAppear e) {
appeared(e);
}
@Override
- public void targetVanished(SikuliEventVanish e) {
+ public void targetVanished(ObserveVanish e) {
vanished(e);
}
@Override
- public void targetChanged(SikuliEventChange e) {
+ public void targetChanged(ObserveChange e) {
changed(e);
}
- public void appeared(SikuliEvent e) {
+ public void appeared(ObserveEvent e) {
}
- public void vanished(SikuliEvent e) {
+ public void vanished(ObserveEvent e) {
}
- public void changed(SikuliEvent e) {
+ public void changed(ObserveEvent e) {
}
}
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventAppear.java b/API/src/main/java/org/sikuli/script/SikuliEventAppear.java
deleted file mode 100755
index ac82577..0000000
--- a/API/src/main/java/org/sikuli/script/SikuliEventAppear.java
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Copyright 2010-2013, Sikuli.org
- * Released under the MIT License.
- *
- * modified RaiMan 2013
- */
-package org.sikuli.script;
-
-public class SikuliEventAppear extends SikuliEvent {
-
- public SikuliEventAppear(Object ptn, Match m, Region r){
- super(ptn, m, r);
- type = Type.APPEAR;
- }
-
-}
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventManager.java b/API/src/main/java/org/sikuli/script/SikuliEventManager.java
deleted file mode 100755
index 50e56fd..0000000
--- a/API/src/main/java/org/sikuli/script/SikuliEventManager.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright 2010-2013, Sikuli.org
- * Released under the MIT License.
- *
- * modified RaiMan 2013
- */
-package org.sikuli.script;
-
-import org.sikuli.basics.Settings;
-import org.sikuli.basics.Debug;
-import java.awt.AWTException;
-import java.util.*;
-import org.sikuli.natives.FindInput;
-import org.sikuli.natives.FindResult;
-import org.sikuli.natives.FindResults;
-import org.sikuli.natives.Mat;
-import org.sikuli.natives.Vision;
-
-public class SikuliEventManager {
-
- protected enum State {
- FIRST, UNKNOWN, MISSING, APPEARED, VANISHED, REPEAT
- }
- private Region _region;
- private Mat _lastImgMat = null;
- private org.opencv.core.Mat _lastImageMat = null;
- private Map<Object, State> _state;
- private Map<Object, Long> _wait;
- private Map<Object, Integer> _count;
- private Map<Object, Match> _lastMatch;
- private Map<Object, String> _names;
-// private Map<Object, SikuliEventObserver> _appearOb, _vanishOb;
- private Map<Object, Object> _appearOb, _vanishOb;
-// private Map<Integer, SikuliEventObserver> _changeOb;
- private Map<Integer, Object> _changeOb;
- private Map<Integer, Integer> _countc;
- private Map<Integer, String> _cnames;
- private int _minChanges;
- private boolean sthgLeft;
-
- public SikuliEventManager(Region region) {
- _region = region;
- _state = new HashMap<Object, State>();
- _wait = new HashMap<Object, Long>();
- _count = new HashMap<Object, Integer>();
- _lastMatch = new HashMap<Object, Match>();
- _names = new HashMap<Object, String>();
-// _appearOb = new HashMap<Object, SikuliEventObserver>();
-// _vanishOb = new HashMap<Object, SikuliEventObserver>();
-// _changeOb = new HashMap<Integer, SikuliEventObserver>();
- _appearOb = new HashMap<Object, Object>();
- _vanishOb = new HashMap<Object, Object>();
- _changeOb = new HashMap<Integer, Object>();
- _countc = new HashMap<Integer, Integer>();
- _cnames = new HashMap<Integer, String>();
- }
-
- public void initialize() {
- Debug.log(2, "SikuliEventManager: resetting observe states for " + _region.toStringShort());
- sthgLeft = true;
- for (Object ptn : _state.keySet()) {
- _state.put(ptn, State.FIRST);
- _count.put(ptn, 0);
- }
- for (int n : _changeOb.keySet()) {
- _countc.put(n, 0);
- }
- }
-
- public void setRegion(Region reg) {
- _region = reg;
- }
-
- public int getCount(Object ptn) {
- return _count.get(ptn);
- }
-
- private <PSC> float getSimiliarity(PSC ptn) {
- float similarity = -1f;
- if (ptn instanceof Pattern) {
- similarity = ((Pattern) ptn).getSimilar();
- }
- if (similarity < 0) {
- similarity = (float) Settings.MinSimilarity;
- }
- return similarity;
- }
-
- public <PSC> void addAppearObserver(PSC ptn, SikuliEventObserver ob, String name) {
- _appearOb.put(ptn, ob);
- _state.put(ptn, State.FIRST);
- _names.put(ptn, name);
- }
-
- public <PSC> void removeAppearObserver(PSC ptn) {
- Observer.remove(_names.get(ptn));
- _names.remove(ptn);
- _appearOb.remove(ptn);
- _state.remove(ptn);
- }
-
- public <PSC> void addVanishObserver(PSC ptn, SikuliEventObserver ob, String name) {
- _vanishOb.put(ptn, ob);
- _state.put(ptn, State.FIRST);
- _names.put(ptn, name);
- }
-
- public <PSC> void removeVanishObserver(PSC ptn) {
- Observer.remove(_names.get(ptn));
- _names.remove(ptn);
- _vanishOb.remove(ptn);
- _state.remove(ptn);
- }
-
- private void callAppearObserver(Object ptn, Match m) {
- SikuliEventAppear se = new SikuliEventAppear(ptn, m, _region);
- Object ao = _appearOb.get(ptn);
- Observer.addEvent(_names.get(ptn), se);
- if (ao != null && ao instanceof SikuliEventObserver) {
- ((SikuliEventObserver)_appearOb.get(ptn)).targetAppeared(se);
- }
- }
-
- private void callVanishObserver(Object ptn, Match m) {
- SikuliEventVanish se = new SikuliEventVanish(ptn, m, _region);
- Object ao = _vanishOb.get(ptn);
- Observer.addEvent(_names.get(ptn), se);
- if (ao != null && ao instanceof SikuliEventObserver) {
- ((SikuliEventObserver)_vanishOb.get(ptn)).targetVanished(se);
- }
- }
-
- private void checkPatterns(ScreenImage simg) {
- Finder finder = null;
- if (Settings.UseImageFinder) {
- finder = new ImageFinder(_region);
- ((ImageFinder) finder).setIsMultiFinder();
- }
- else {
- finder = new Finder(simg, _region);
- }
- String imgOK;
- Debug.log(3, "observe: checkPatterns entry: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving());
- for (Object ptn : _state.keySet()) {
- if (_state.get(ptn) != State.FIRST &&
- _state.get(ptn) != State.UNKNOWN &&
- _state.get(ptn) != State.REPEAT) {
- continue;
- }
- imgOK = null;
- if (ptn instanceof String) {
- imgOK = finder.find((String) ptn);
- Image img = Image.create((String) ptn);
- if (img.isValid()) {
- imgOK = finder.find(img);
- } else if (img.isText()){
- imgOK = finder.findText((String) ptn);
- }
- } else if (ptn instanceof Pattern) {
- imgOK = finder.find((Pattern) ptn);
- } else if (ptn instanceof Image) {
- imgOK = finder.find((Image) ptn);
- }
- if (null == imgOK) {
- Debug.error("EventMgr: checkPatterns: Image not valid", ptn);
- _state.put(ptn, State.MISSING);
- continue;
- }
- if (_state.get(ptn) == State.REPEAT) {
- Debug.log(3, "repeat: checking");
- if (_lastMatch.get(ptn).exists(ptn) != null) {
- if ((new Date()).getTime() > _wait.get(ptn)) {
- _state.put(ptn, State.APPEARED);
- Debug.log(3, "repeat: vanish timeout");
- // time out
- } else {
- sthgLeft = true;
- }
- continue; // not vanished within given time or still there
- } else {
- _state.put(ptn, State.UNKNOWN);
- sthgLeft = true;
- Debug.log(3, "repeat: has vanished");
- continue; // has vanished, repeat
- }
- }
- Match m = null;
- boolean hasMatch = false;
- if (finder.hasNext()) {
- m = finder.next();
- if (m.getScore() >= getSimiliarity(ptn)) {
- hasMatch = true;
- _lastMatch.put(ptn, m);
- }
- }
- if (hasMatch) {
- Debug.log(2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " +
- m.toStringShort() + " in " + _region.toStringShort());
- } else if (_state.get(ptn) == State.FIRST) {
- Debug.log(2, "EventMgr: checkPatterns: " + ptn.toString() + " match: " +
- "NO" + " in " + _region.toStringShort());
- _state.put(ptn, State.UNKNOWN);
- }
- if (_appearOb.containsKey(ptn)) {
- if (_state.get(ptn) != State.APPEARED) {
- if (hasMatch) {
- _state.put(ptn, State.APPEARED);
- _count.put(ptn, _count.get(ptn) + 1);
- callAppearObserver(ptn, m);
- } else {
- sthgLeft = true;
- }
- }
- } else if (_vanishOb.containsKey(ptn)) {
- if (_state.get(ptn) != State.VANISHED) {
- if (!hasMatch) {
- _state.put(ptn, State.VANISHED);
- _count.put(ptn, _count.get(ptn) + 1);
- callVanishObserver(ptn, _lastMatch.get(ptn));
- } else {
- sthgLeft = true;
- }
- }
- }
- if (!_region.isObserving()) {
- break;
- }
- }
- Debug.log(3, "observe: checkPatterns exit: sthgLeft: %s isObserving: %s", sthgLeft, _region.isObserving());
- }
-
- public void repeat(SikuliEvent.Type type, Object pattern, Match match, long secs) {
- if (type == SikuliEvent.Type.CHANGE) {
- Debug.error("EventMgr: repeat: CHANGE repeats automatically");
- } else if (type == SikuliEvent.Type.VANISH) {
- Debug.error("EventMgr: repeat: not supported for VANISH");
- } else if (type == SikuliEvent.Type.APPEAR) {
- _state.put(pattern, State.REPEAT);
- if (secs <= 0) {
- secs = (long) _region.getWaitForVanish();
- }
- _wait.put(pattern, (new Date()).getTime() + 1000 * secs);
- Debug.log(2, "EventMgr: repeat: requested for APPEAR: " +
- pattern.toString() + " at " + match.toStringShort() + " after " + secs + " seconds");
- sthgLeft = true;
- }
- }
-
- public void addChangeObserver(int threshold, SikuliEventObserver ob, String name) {
- _changeOb.put(new Integer(threshold), ob);
- _minChanges = getMinChanges();
- _cnames.put(threshold, name);
- }
-
- public void removeChangeObserver(int threshold) {
- Observer.remove(_cnames.get(threshold));
- _names.remove(threshold);
- _changeOb.remove(new Integer(threshold));
- _minChanges = getMinChanges();
- }
-
- private int getMinChanges() {
- int min = Integer.MAX_VALUE;
- for (Integer n : _changeOb.keySet()) {
- if (n < min) {
- min = n;
- }
- }
- return min;
- }
-
- private void callChangeObserver(FindResults results) throws AWTException {
- for (Integer n : _changeOb.keySet()) {
- List<Match> changes = new ArrayList<Match>();
- for (int i = 0; i < results.size(); i++) {
- FindResult r = results.get(i);
- if (r.getW() * r.getH() >= n) {
- changes.add(_region.toGlobalCoord(new Match(r, _region.getScreen())));
- }
- }
- if (changes.size() > 0) {
- _countc.put(n, _countc.get(n) + 1);
- SikuliEventChange se = new SikuliEventChange(changes, _region);
- Object ao = _changeOb.get(n);
- Observer.addEvent(_cnames.get(n), se);
- if (ao instanceof SikuliEventObserver) {
- ((SikuliEventObserver)_changeOb.get(n)).targetChanged(se);
- }
- }
- }
- }
-
- private void checkChanges(ScreenImage img) {
- if (Settings.UseImageFinder) {
- //TODO hack to hide the native call - should be at the top
- if (_lastImageMat == null) {
- _lastImageMat = new org.opencv.core.Mat();
- }
- if (_lastImageMat.empty()) {
- _lastImageMat = Image.createMat(img.getImage());
- return;
- }
- ImageFinder f = new ImageFinder(_lastImageMat);
- f.setMinChanges(_minChanges);
- org.opencv.core.Mat current = Image.createMat(img.getImage());
- if (f.hasChanges(current)) {
- //TODO implement ChangeObserver: processing changes
- Debug.log(3, "ChangeObserver: processing changes");
- }
- _lastImageMat = current;
- }
- else {
- if (_lastImgMat == null) {
- _lastImgMat = Image.convertBufferedImageToMat(img.getImage());
- return;
- }
- FindInput fin = new FindInput();
- fin.setSource(_lastImgMat);
- Mat target = Image.convertBufferedImageToMat(img.getImage());
- fin.setTarget(target);
- fin.setSimilarity(_minChanges);
- FindResults results = Vision.findChanges(fin);
- try {
- callChangeObserver(results);
- } catch (AWTException e) {
- Debug.error("EventMgr: checkChanges: ", e.getMessage());
- }
- _lastImgMat = target;
- }
- }
-
- public boolean update(ScreenImage simg) {
- Debug.log(3, "observe: update entry: sthgLeft: %s obs? %s", sthgLeft, _region.isObserving());
- boolean ret;
- ret = sthgLeft;
- if (sthgLeft) {
- sthgLeft = false;
- checkPatterns(simg);
- if (!_region.isObserving()) {
- return false;
- }
- }
- if (_region.isObserving()) {
- ret = sthgLeft;
- if (_changeOb.size() > 0) {
- checkChanges(simg);
- if (!_region.isObserving()) {
- return false;
- }
- ret = true;
- }
- }
- Debug.log(3, "observe: update exit: ret: %s", ret);
- return ret;
- }
-}
\ No newline at end of file
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventObserver.java b/API/src/main/java/org/sikuli/script/SikuliEventObserver.java
index 4b055c8..2b40b03 100755
--- a/API/src/main/java/org/sikuli/script/SikuliEventObserver.java
+++ b/API/src/main/java/org/sikuli/script/SikuliEventObserver.java
@@ -1,16 +1,19 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
import java.util.*;
+/**
+ * CANDIDATE FOR DEPRECATION - ONLY HERE TO BE BACKWARD COMPATIBLE
+ */
public interface SikuliEventObserver extends EventListener {
- public void targetAppeared(SikuliEventAppear e);
- public void targetVanished(SikuliEventVanish e);
- public void targetChanged(SikuliEventChange e);
+ public void targetAppeared(ObserveAppear e);
+ public void targetVanished(ObserveVanish e);
+ public void targetChanged(ObserveChange e);
}
diff --git a/API/src/main/java/org/sikuli/script/SikuliEventVanish.java b/API/src/main/java/org/sikuli/script/SikuliEventVanish.java
deleted file mode 100755
index eaca739..0000000
--- a/API/src/main/java/org/sikuli/script/SikuliEventVanish.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright 2010-2013, Sikuli.org
- * Released under the MIT License.
- *
- * modified RaiMan 2013
- */
-package org.sikuli.script;
-
-public class SikuliEventVanish extends SikuliEvent {
- public SikuliEventVanish(Object ptn, Match m, Region r){
- super(ptn, m, r);
- type = Type.VANISH;
- }
-}
-
diff --git a/API/src/main/java/org/sikuli/script/SikuliException.java b/API/src/main/java/org/sikuli/script/SikuliException.java
index c84df29..3e3bec0 100755
--- a/API/src/main/java/org/sikuli/script/SikuliException.java
+++ b/API/src/main/java/org/sikuli/script/SikuliException.java
@@ -1,11 +1,14 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
+/**
+ * INTERNAL USE
+ */
public class SikuliException extends Exception {
protected String _name = "SikuliException";
diff --git a/API/src/main/java/org/sikuli/script/SikuliX.java b/API/src/main/java/org/sikuli/script/SikuliX.java
index 2715a74..84c34b9 100644
--- a/API/src/main/java/org/sikuli/script/SikuliX.java
+++ b/API/src/main/java/org/sikuli/script/SikuliX.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * added RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -13,8 +13,8 @@ import org.sikuli.basics.Debug;
import org.sikuli.basics.SikuliScript;
/**
- *
- * @author rhocke
+ * INTERNAL USE
+ * global services for package API
*/
public class SikuliX {
diff --git a/API/src/main/java/org/sikuli/script/TextRecognizer.java b/API/src/main/java/org/sikuli/script/TextRecognizer.java
index f78e32f..48c1b69 100755
--- a/API/src/main/java/org/sikuli/script/TextRecognizer.java
+++ b/API/src/main/java/org/sikuli/script/TextRecognizer.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
@@ -18,7 +18,11 @@ import org.sikuli.natives.OCRWord;
import org.sikuli.natives.OCRWords;
import org.sikuli.natives.Vision;
-// Singleton
+/**
+ * INTERNAL USE
+ *
+ * Will be rewritten for use of Tess4J - Java only implementation
+ */
public class TextRecognizer {
private static TextRecognizer _instance = null;
@@ -32,7 +36,7 @@ public class TextRecognizer {
init();
}
- public void init() {
+ private void init() {
String path;
File fpath = null;
if (Settings.OcrDataPath != null) {
diff --git a/API/src/main/java/org/sikuli/script/SikuliAction.java b/API/src/main/resources/might-be-obsolete/SikuliAction.java
similarity index 95%
rename from API/src/main/java/org/sikuli/script/SikuliAction.java
rename to API/src/main/resources/might-be-obsolete/SikuliAction.java
index d55087e..dfadb9b 100755
--- a/API/src/main/java/org/sikuli/script/SikuliAction.java
+++ b/API/src/main/resources/might-be-obsolete/SikuliAction.java
@@ -1,8 +1,8 @@
/*
- * Copyright 2010-2013, Sikuli.org
+ * Copyright 2010-2014, Sikuli.org, SikuliX.com
* Released under the MIT License.
*
- * modified RaiMan 2013
+ * modified RaiMan
*/
package org.sikuli.script;
diff --git a/API/src/main/java/org/sikuli/script/SikuliActionListener.java b/API/src/main/resources/might-be-obsolete/SikuliActionListener.java
similarity index 100%
rename from API/src/main/java/org/sikuli/script/SikuliActionListener.java
rename to API/src/main/resources/might-be-obsolete/SikuliActionListener.java
diff --git a/API/src/main/java/org/sikuli/script/SikuliActionManager.java b/API/src/main/resources/might-be-obsolete/SikuliActionManager.java
similarity index 100%
rename from API/src/main/java/org/sikuli/script/SikuliActionManager.java
rename to API/src/main/resources/might-be-obsolete/SikuliActionManager.java
diff --git a/Basics/src/main/resources/Lib/sikuli/Region.py b/Basics/src/main/resources/Lib/sikuli/Region.py
index cacd093..d0ec839 100755
--- a/Basics/src/main/resources/Lib/sikuli/Region.py
+++ b/Basics/src/main/resources/Lib/sikuli/Region.py
@@ -65,13 +65,13 @@ class Region(JRegion):
# assures, that in any case the same region object is used
def onAppear(self, target, handler):
class AnonyObserver(ObserverCallBack):
- def targetAppeared(self, event):
+ def appeared(self, event):
handler(event)
return self.onAppearJ(self, target, AnonyObserver())
def onVanish(self, target, handler):
class AnonyObserver(ObserverCallBack):
- def targetVanished(self, event):
+ def vanished(self, event):
handler(event)
return self.onVanishJ(self, target, AnonyObserver())
@@ -85,7 +85,7 @@ class Region(JRegion):
min_size = 0
handler = arg1
class AnonyObserver(ObserverCallBack):
- def targetChanged(self, event):
+ def changed(self, event):
handler(event)
return self.onChangeJ(min_size, AnonyObserver())
diff --git a/Basics/src/main/resources/Lib/sikuli/Sikuli.py b/Basics/src/main/resources/Lib/sikuli/Sikuli.py
index 52e7c98..84aa0d0 100755
--- a/Basics/src/main/resources/Lib/sikuli/Sikuli.py
+++ b/Basics/src/main/resources/Lib/sikuli/Sikuli.py
@@ -24,7 +24,7 @@ from org.sikuli.basics import OS
Debug.log(3, "Jython: sikuli: Sikuli: import Region")
from org.sikuli.script import Region as JRegion
from Region import *
-from org.sikuli.script import Observer
+from org.sikuli.script import ObserveManager
Debug.log(3, "Jython: sikuli: Sikuli: import Screen")
from org.sikuli.script import Screen as JScreen
@@ -82,7 +82,7 @@ from org.sikuli.basics import SikuliX
#
## use instead of print if unicode strings present
# usage: uprint(s1, u1, u2, u3, s3, ...)
-#
+#
def uprint(*args):
for e in args[:-1]:
if isinstance(e, str): print e,
@@ -111,7 +111,7 @@ def load(jar):
sys.path.append(abspath)
return True
return False
-
+
if _load(jar):
return True
path = getBundlePath()
@@ -147,7 +147,7 @@ def getImagePath():
#
def removeImagePath(path):
ImagePath.remove(path)
-
+
##
# reset the image path, so it only contains the bundlepath
#
@@ -170,15 +170,15 @@ def setBundlePath(path):
#
def getBundlePath():
return ImagePath.getBundlePath()
-
+
##
-# return the parent folder of the current bundlepath
-# (usually the folder containing the current script folder.sikuli)
+# return the parent folder of the current bundlepath
+# (usually the folder containing the current script folder.sikuli)
# or None if no bundlepath is defined
#
def getParentPath():
return ImagePath.getBundleParentPath();
-
+
##
# make a valid path by joining the two paths (path2 might be a list)
#
@@ -219,7 +219,7 @@ def input(msg="", default="", title="", hidden=False):
##
# Shows a dialog request to enter text in a multiline text field
# Though not all text might be visible, everything entered is delivered with the returned text
-# The main purpose for this feature is to allow pasting text from somewhere
+# The main purpose for this feature is to allow pasting text from somewhere
# @param msg the message to display.
# @param title the title for the dialog (default: Sikuli input request)
# @param lines the maximum number of lines visible in the text field (default 9)
@@ -260,7 +260,7 @@ def selectRegion(msg=None):
return Region(r)
else:
return None
-
+
##
# set the default screen to given or primary screen
#
@@ -279,7 +279,7 @@ def use(scr = None, remote = False):
if not scr:
SCREEN = Screen()
else:
- SCREEN = scr
+ SCREEN = scr
Debug.log(3, "Jython: requested to use as default region: " + SCREEN.toStringShort())
globals()['SIKULISAVED'] = _exposeAllMethods(SCREEN, globals().get('SIKULISAVED'), theGlobals, None)
theGlobals['SCREEN'] = SCREEN
@@ -347,17 +347,17 @@ def exit(code=0):
# @return Returns the output from the executed command.
def run(cmd):
return SikuliX.run(cmd)
-
+
##
# display some help in interactive mode
def shelp():
SikuliScript.shelp()
-
+
##
# helper functions, that can be used when sorting lists of regions
#
def byDistanceTo(x, y=None):
- """ Method to compare two Region objects by distance of their top left.
+ """ Method to compare two Region objects by distance of their top left.
or a regions top left to the given point by coordinates"""
return DistanceComparator(x, y)
@@ -378,7 +378,7 @@ def horizontalComparator():
return HorizontalComparator().compare
def distanceComparator(x, y=None):
- """ Method to compare two Region objects by distance of their top left.
+ """ Method to compare two Region objects by distance of their top left.
or a regions top left to the given point by coordinates"""
if y is None:
return DistanceComparator(x).compare # x is Region or Location
@@ -422,7 +422,7 @@ def _exposeAllMethods(anyObject, saved, theGlobals, exclude_list):
if name == 'checkWith': Debug.log(3, "%s %s", name, str(dict[name])[1:])
for name in saved:
if name in theGlobals:
- #print "removed:", name
+ #print "removed:", name
theGlobals.pop(name)
return tosave
diff --git a/Basics/src/main/resources/Lib/sikulix.rb b/Basics/src/main/resources/Lib/sikulix.rb
index 8503370..859b80d 100755
--- a/Basics/src/main/resources/Lib/sikulix.rb
+++ b/Basics/src/main/resources/Lib/sikulix.rb
@@ -9,7 +9,7 @@ module SikuliX4Ruby
java_import org.sikuli.script.Region
java_import org.sikuli.script.ScreenUnion
- java_import org.sikuli.script.Observer
+ java_import org.sikuli.script.ObserverManager
java_import org.sikuli.script.ObserverCallBack
java_import org.sikuli.script.Constants
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git
More information about the pkg-java-commits
mailing list