[sikuli] 360/385: made the Mouse-moved-callBack useable, implemented the Event Type GENERIC to accept 3 arbitrary values

Gilles Filippini pini at moszumanska.debian.org
Sun Jun 29 19:26:37 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 89d41c4b20ca925961a9dd9c176b7602367e62f2
Author: Raimund Hocke <rmhdevelop at me.com>
Date:   Thu Apr 17 18:23:48 2014 +0200

    made the Mouse-moved-callBack useable, implemented the Event Type GENERIC to accept 3 arbitrary values
---
 API/src/main/java/org/sikuli/script/Mouse.java     |  3 +-
 .../main/java/org/sikuli/script/ObserveEvent.java  | 54 +++++++++++++++++-----
 2 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/API/src/main/java/org/sikuli/script/Mouse.java b/API/src/main/java/org/sikuli/script/Mouse.java
index bf8ab74..1d76cb0 100644
--- a/API/src/main/java/org/sikuli/script/Mouse.java
+++ b/API/src/main/java/org/sikuli/script/Mouse.java
@@ -10,6 +10,7 @@ import java.awt.MouseInfo;
 import java.awt.Point;
 import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
+import java.util.Date;
 import org.sikuli.basics.Debug;
 import org.sikuli.basics.Settings;
 
@@ -274,7 +275,7 @@ public class Mouse {
 //TODO implement 3
         if (callBack != null) {
           callBack.happened(new ObserveEvent("MouseMoved", ObserveEvent.Type.GENERIC, 
-                  lastPos, null, Region.create(new Location(pos), 1, 1), 0));
+                  lastPos, new Location(pos), null, (new Date()).getTime()));
         }
       }
     }
diff --git a/API/src/main/java/org/sikuli/script/ObserveEvent.java b/API/src/main/java/org/sikuli/script/ObserveEvent.java
index 4b375f9..f84a1ff 100755
--- a/API/src/main/java/org/sikuli/script/ObserveEvent.java
+++ b/API/src/main/java/org/sikuli/script/ObserveEvent.java
@@ -30,6 +30,7 @@ public class ObserveEvent {
   private List<Match> changes = null;
   private long time;
   private String name;
+  private Object[] vals = new Object[] {null, null, null};
 
   protected ObserveEvent() {
   }
@@ -37,18 +38,43 @@ public class ObserveEvent {
   /**
    * INTERNAL USE ONLY: creates an observed event
    */
-  protected ObserveEvent(String name, Type type, Object ptn, Match m, Region r, long now) {
+  protected ObserveEvent(String name, Type type, Object ptn, Object m, Object r, long now) {
     init(name, type, ptn, m, r, now);
   }
 
-	private void init(String name, Type type, Object ptn, Match m, Region r, long now) {
+	private void init(String name, Type type, Object ptn, Object m, Object r, long now) {
     this.name = name;
     this.type = type;
-    setRegion(r);
-    setMatch(m);
-    setPattern(ptn);
     time = now;
+    if (type == Type.GENERIC) {
+      setVals(ptn, m, r);
+    } else {
+      setRegion(r);
+      setMatch(m);
+      setPattern(ptn);
+    }
 	}
+  
+  /**
+   * for type GENERIC: 3 values can be stored in the event 
+   * (the value's type is known by creator and user of getVals as some private protocol) 
+   * @param v1
+   * @param v2
+   * @param v3
+   */
+  protected void setVals(Object v1, Object v2, Object v3) {
+    vals[0] = v1;
+    vals[1] = v2;
+    vals[2] = v3;
+  }
+  
+  /**
+   * for type GENERIC: (the value's type is known by creator and user of getVals as some private protocol)
+   * @return an array with the 3 stored values (might be null)
+   */
+  public Object[] getVals() {
+    return vals;
+  }
 
   /**
    *
@@ -60,14 +86,16 @@ public class ObserveEvent {
 
   /**
    *
-   * @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;
+  protected void setRegion(Object r) {
+    if (r instanceof Region) {
+      region = (Region) r;
+    }
   }
 
   /**
@@ -78,9 +106,9 @@ public class ObserveEvent {
     return match;
   }
 
-  protected void setMatch(Match m) {
-    if (null != m) {
-      match = new Match(m);
+  protected void setMatch(Object m) {
+    if (null != m && m instanceof Match) {
+      match = new Match((Match) m);
     }
   }
 
@@ -123,7 +151,9 @@ public class ObserveEvent {
       if (p.getClass().isInstance("")) {
         pattern = new Pattern((String) p);
       } else {
-        pattern = new Pattern((Pattern) p);
+        if (p instanceof Pattern) {
+          pattern = new Pattern((Pattern) p);
+        }
       }
     }
   }

-- 
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