[sikuli] 301/385: ongoing: getting observe to work

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 b7f95c3ede90398d935940ced4f1aede0bf43dd8
Author: Raimund Hocke <rmhdevelop at me.com>
Date:   Wed Feb 26 08:36:02 2014 +0100

    ongoing: getting observe to work
---
 API/src/main/java/org/sikuli/script/Observer.java  | 30 +++++++++---------
 .../java/org/sikuli/script/ObserverCallBack.java   |  4 +--
 API/src/main/java/org/sikuli/script/Observing.java | 18 +++++------
 API/src/main/java/org/sikuli/script/Region.java    | 36 +++++++++++-----------
 Basics/src/main/resources/Lib/sikuli/Region.py     |  2 +-
 Basics/src/main/resources/Lib/sikuli/Sikuli.py     |  2 +-
 Basics/src/main/resources/Lib/sikulix.rb           |  2 +-
 7 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/API/src/main/java/org/sikuli/script/Observer.java b/API/src/main/java/org/sikuli/script/Observer.java
index f594107..c2e1c88 100755
--- a/API/src/main/java/org/sikuli/script/Observer.java
+++ b/API/src/main/java/org/sikuli/script/Observer.java
@@ -90,27 +90,27 @@ public class Observer {
     return similarity;
   }
 
-  public <PSC> void addAppearObserver(PSC ptn, SikuliEventObserver ob, String name) {
+  public <PSC> void addAppearObserver(PSC ptn, ObserverCallBack 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));
+    Observing.remove(_names.get(ptn));
     _names.remove(ptn);
     _appearOb.remove(ptn);
     _state.remove(ptn);
   }
 
-  public <PSC> void addVanishObserver(PSC ptn, SikuliEventObserver ob, String name) {
+  public <PSC> void addVanishObserver(PSC ptn, ObserverCallBack ob, String name) {
     _vanishOb.put(ptn, ob);
     _state.put(ptn, State.FIRST);
     _names.put(ptn, name);
   }
 
   public <PSC> void removeVanishObserver(PSC ptn) {
-    ObserverManager.remove(_names.get(ptn));
+    Observing.remove(_names.get(ptn));
     _names.remove(ptn);
     _vanishOb.remove(ptn);
     _state.remove(ptn);
@@ -119,18 +119,18 @@ public class Observer {
   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);
+    Observing.addEvent(_names.get(ptn), se);
+    if (ao != null && ao instanceof ObserverCallBack) {
+      ((ObserverCallBack)_appearOb.get(ptn)).appeared(se);
     }
   }
 
   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);
+    Observing.addEvent(_names.get(ptn), se);
+    if (ao != null && ao instanceof ObserverCallBack) {
+      ((ObserverCallBack)_vanishOb.get(ptn)).vanished(se);
     }
   }
 
@@ -250,14 +250,14 @@ public class Observer {
     }
   }
 
-  public void addChangeObserver(int threshold, SikuliEventObserver ob, String name) {
+  public void addChangeObserver(int threshold, ObserverCallBack ob, String name) {
     _changeOb.put(new Integer(threshold), ob);
     _minChanges = getMinChanges();
     _cnames.put(threshold, name);
   }
 
   public void removeChangeObserver(int threshold) {
-    ObserverManager.remove(_cnames.get(threshold));
+    Observing.remove(_cnames.get(threshold));
     _names.remove(threshold);
     _changeOb.remove(new Integer(threshold));
     _minChanges = getMinChanges();
@@ -286,9 +286,9 @@ public class Observer {
         _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);
+        Observing.addEvent(_cnames.get(n), se);
+        if (ao instanceof ObserverCallBack) {
+          ((ObserverCallBack)_changeOb.get(n)).changed(se);
         }
       }
     }
diff --git a/API/src/main/java/org/sikuli/script/ObserverCallBack.java b/API/src/main/java/org/sikuli/script/ObserverCallBack.java
index e2a5481..ae4362e 100644
--- a/API/src/main/java/org/sikuli/script/ObserverCallBack.java
+++ b/API/src/main/java/org/sikuli/script/ObserverCallBack.java
@@ -16,7 +16,7 @@ import java.util.EventListener;
  *
  * example:<br>
  * aRegion.onAppear(anImage, <br>
-   new ObserverManagerCallBack() { <br>
+   new ObservingCallBack() { <br>
  *     <br>
      appeared(ObserveEvent e) { <br>
        // do something
@@ -37,6 +37,6 @@ public class ObserverCallBack implements EventListener {
   public void changed(ObserveEvent e) {
   }
 
-  public void happened(ObserverManager.Event e) {
+  public void happened(Observing.Event e) {
   }
 }
diff --git a/API/src/main/java/org/sikuli/script/Observing.java b/API/src/main/java/org/sikuli/script/Observing.java
index 3ef6054..37bd0dd 100644
--- a/API/src/main/java/org/sikuli/script/Observing.java
+++ b/API/src/main/java/org/sikuli/script/Observing.java
@@ -12,12 +12,10 @@ import java.util.Date;
 import java.util.List;
 
 /**
- * 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)
+ * all running observations.<br />
  */
-public class ObserverManager {
+public class Observing {
 
   private static class Entry {
 
@@ -48,16 +46,18 @@ public class ObserverManager {
   private static List<Event> events = Collections.synchronizedList(new ArrayList<Event>());
 
   /**
-   * adds an ObserverManager with a callback to the list
+   * adds an observer with a callback to the list
    *
    * @param reg the observed region
    * @param obs the callback
-   * @param type one off ObserverManager.Type.APPEAR, VANISH, CHANGE, GENERIC
+   * @param type one off ObserveEvent.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, ObserveEvent.Type type) {
     String name = createName();
-    if (add(name, reg, obs, type)) return name;
+    if (add(name, reg, obs, type)) {
+      return name;
+    }
     return null;
   }
 
@@ -66,7 +66,7 @@ public class ObserverManager {
    *
    * @param reg the observed region
    * @param name a unique name
-   * @param type one off ObserverManager.Type.APPEAR, VANISH, CHANGE, GENERIC
+   * @param type one off Observing.Type.APPEAR, VANISH, CHANGE, GENERIC
    * @return the observers name or null if not possible (duplicate?)
    */
   public static synchronized String add(Region reg, String name, ObserveEvent.Type type) {
@@ -77,7 +77,7 @@ public class ObserverManager {
   }
 
   /**
-   * adds an observer of type GNERIC to the list having no callback
+   * adds an observer of type GENERIC to the list having no callback
    *
    * @param name a unique name
    * @return the observers name or null if not possible (duplicate?)
diff --git a/API/src/main/java/org/sikuli/script/Region.java b/API/src/main/java/org/sikuli/script/Region.java
index 335e9ca..83f5b93 100755
--- a/API/src/main/java/org/sikuli/script/Region.java
+++ b/API/src/main/java/org/sikuli/script/Region.java
@@ -577,7 +577,7 @@ public class Region {
   }
 
   /**
-   * used in Observer.callChangeObserverManager, Finder.next to adjust region relative coordinates of matches to
+   * used in Observer.callChangeObserving, Finder.next to adjust region relative coordinates of matches to
  screen coordinates
    *
    * @param m
@@ -2458,7 +2458,7 @@ public class Region {
   }
   //</editor-fold>
 
-  //<editor-fold defaultstate="collapsed" desc="ObserverManager">
+  //<editor-fold defaultstate="collapsed" desc="Observing">
   private Observer getEventManager() {
     if (evtMgr == null) {
       evtMgr = new Observer(this);
@@ -2477,7 +2477,7 @@ public class Region {
   /**
    * 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 the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
 	 * @param <PSI> Pattern, String or Image
    * @param target
@@ -2500,15 +2500,15 @@ public class Region {
 	}
 
   private <PSI> String onAppearDo(PSI target, Object observer) {
-    String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.APPEAR);
-    getEventManager().addAppearObserver(target, (SikuliEventObserver) observer, name);
+    String name = Observing.add(this, (ObserverCallBack) observer, ObserveEvent.Type.APPEAR);
+    getEventManager().addAppearObserver(target, (ObserverCallBack) 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
-   * for details about the observe event handler: {@link SikuliEventObserver}
+   * for details about the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
 	 * @param <PSI> Pattern, String or Image
    * @param target
@@ -2531,15 +2531,15 @@ public class Region {
 	}
 
   private <PSI> String onVanishDo(PSI target, Object observer) {
-    String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.VANISH);
-    getEventManager().addVanishObserver(target, (SikuliEventObserver) observer, name);
+    String name = Observing.add(this, (ObserverCallBack) observer, ObserveEvent.Type.VANISH);
+    getEventManager().addVanishObserver(target, (ObserverCallBack) 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
-   * for details about the observe event handler: {@link SikuliEventObserver}
+   * for details about the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
    * @param threshold minimum size of changes (rectangle threshhold x threshold)
    * @param observer
@@ -2553,7 +2553,7 @@ public class 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 the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
    * @param observer
    * @return the event's name
@@ -2577,14 +2577,14 @@ public class Region {
   }
 
   public String onChangeDo(int threshold, Object observer) {
-    String name = ObserverManager.add(this, (ObserverCallBack) observer, ObserveEvent.Type.CHANGE);
-    getEventManager().addChangeObserver(threshold, (SikuliEventObserver) observer, name);
+    String name = Observing.add(this, (ObserverCallBack) observer, ObserveEvent.Type.CHANGE);
+    getEventManager().addChangeObserver(threshold, (ObserverCallBack) observer, name);
     return name;
   }
 
   /**
-   * start an observer in this region that runs forever (use stopObserverManager() in handler)
- for details about the observe event handler: {@link SikuliEventObserver}
+   * start an observer in this region that runs forever (use stopObserving() in handler)
+ for details about the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
 	 * @return false if not possible, true if events have happened
    */
@@ -2594,7 +2594,7 @@ public class Region {
 
   /**
    * start an observer in this region for the given time
-   * for details about the observe event handler: {@link SikuliEventObserver}
+   * for details about the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
    * @param secs
    * @return false if not possible, true if events have happened
@@ -2622,7 +2622,7 @@ public class Region {
       Debug.error("Region: observe: Nothing to observe (Region might be invalid): " + this.toStringShort());
       return false;
     }
-    ObserverManager.getEvents(this);
+    Observing.getEvents(this);
     if (observing) {
       Debug.error("Region: observe: already running for this region. Only one allowed!");
       return false;
@@ -2660,12 +2660,12 @@ public class Region {
       Debug.log(2, "Region: observe: observing has ended for " + this.toStringShort());
     }
     SikuliX.removeRunningObserver(this);
-    return ObserverManager.hasEvents(this);
+    return Observing.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 the observe event handler: {@link ObserverCallBack}
    * for details about APPEAR/VANISH/CHANGE events: {@link ObserveEvent}
    * @param secs
    * @return false if not possible, true otherwise
diff --git a/Basics/src/main/resources/Lib/sikuli/Region.py b/Basics/src/main/resources/Lib/sikuli/Region.py
index d0ec839..18ac074 100755
--- a/Basics/src/main/resources/Lib/sikuli/Region.py
+++ b/Basics/src/main/resources/Lib/sikuli/Region.py
@@ -67,7 +67,7 @@ class Region(JRegion):
         class AnonyObserver(ObserverCallBack):
             def appeared(self, event):
                 handler(event)
-        return self.onAppearJ(self, target, AnonyObserver())
+        return self.onAppearJ(target, AnonyObserver())
 
     def onVanish(self, target, handler):
         class AnonyObserver(ObserverCallBack):
diff --git a/Basics/src/main/resources/Lib/sikuli/Sikuli.py b/Basics/src/main/resources/Lib/sikuli/Sikuli.py
index 84aa0d0..b81a18c 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 ObserveManager
+from org.sikuli.script import Observing
 
 Debug.log(3, "Jython: sikuli: Sikuli: import Screen")
 from org.sikuli.script import Screen as JScreen
diff --git a/Basics/src/main/resources/Lib/sikulix.rb b/Basics/src/main/resources/Lib/sikulix.rb
index 859b80d..04f0e61 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.ObserverManager
+  java_import org.sikuli.script.Observing
   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