gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] fenfire/org/fenfire demo/buoyoing.py util/Contr...


From: Benja Fallenstein
Subject: [Gzz-commits] fenfire/org/fenfire demo/buoyoing.py util/Contr...
Date: Thu, 19 Jun 2003 11:23:44 -0400

CVSROOT:        /cvsroot/fenfire
Module name:    fenfire
Branch:         
Changes by:     Benja Fallenstein <address@hidden>      03/06/19 11:23:44

Modified files:
        org/fenfire/demo: buoyoing.py 
        org/fenfire/util: ControlBinding.java 

Log message:
        clean

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/demo/buoyoing.py.diff?tr1=1.73&tr2=1.74&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/util/ControlBinding.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: fenfire/org/fenfire/demo/buoyoing.py
diff -u fenfire/org/fenfire/demo/buoyoing.py:1.73 
fenfire/org/fenfire/demo/buoyoing.py:1.74
--- fenfire/org/fenfire/demo/buoyoing.py:1.73   Thu Jun 19 07:57:47 2003
+++ fenfire/org/fenfire/demo/buoyoing.py        Thu Jun 19 11:23:44 2003
@@ -326,23 +326,17 @@
                 FenPDFActions(context, 2), context)
         w.setCursor('default')
 
-class AbstractController(ff.util.ControlBinding.Controller):
-    def controlPoint(self, x,y,scale): pass 
-    def change(self, x,y): pass
-    def set(self, obj, oldVS):
-        self.obj = obj
-        self.oldVS = oldVS
-    
-class MovePanFast(AbstractController):
-    def isChangeAble(self): return 1
+class MovePanFast(ff.util.ControlBinding.AbstractController):
+    def isChangeable(self): return 1
     def change(self, x, y):
         f = self.obj.getFocus()
         fX, fY = f.getPanX(), f.getPanY()
         f.setPan( (fX-x)/f.getZoom(),(fY-y)/f.getZoom())
         self.obj.chgFast(self.oldVS)
 
-class MovePanSlow(AbstractController):
-    def isChangeAble(self): return 0
+class MovePanSlow(ff.util.ControlBinding.AbstractController):
+    def __init__(self): 
ff.util.ControlBinding.AbstractController.__init__(self)
+    def isChangeable(self): return 0
     def controlPoint(self, x, y, scale):
         self.obj.moveToPoint(int(x),int(y), self.oldVS)
         
@@ -353,11 +347,10 @@
         self.context.initMainNodes(mainNodes)
         self.lastIndex = 0
 
-        self.controlMains = ff.util.ControlBinding()
-        c = self.controlMains
-        c.add(MovePanFast(), -1, 'wheel', 7,1)
-        c.add(MovePanFast(), 1, "drag", 1.4, 1)
-        c.add(MovePanSlow(), 1, "click", 1, 1)
+        c = self.controlMains = ff.util.ControlBinding()
+        c.add(MovePanFast(), -1, c.WHEEL, 7,1)
+        c.add(MovePanFast(), 1, c.DRAG, 1.4, 1)
+        c.add(MovePanSlow(), 1, c.CLICK, 1, 1)
 #        c.dbg=1
         self.controls = [ self.controlMains ]
      
Index: fenfire/org/fenfire/util/ControlBinding.java
diff -u fenfire/org/fenfire/util/ControlBinding.java:1.1 
fenfire/org/fenfire/util/ControlBinding.java:1.2
--- fenfire/org/fenfire/util/ControlBinding.java:1.1    Thu Jun 19 07:57:47 2003
+++ fenfire/org/fenfire/util/ControlBinding.java        Thu Jun 19 11:23:44 2003
@@ -11,13 +11,23 @@
     public static boolean dbg = false;
     private static void p(String s) { System.out.println("ControlBinding:: 
"+s); }
 
+    /** A type of event that can be 
+     *  associated with a controller.
+     *  This is a typesafe enumeration.
+     */
+    public static final class Type {
+       private Type() {}
+    }
+
+    public static final Type 
+       CLICK = new Type(),
+       DRAG = new Type(),
+       WHEEL = new Type();
+
+
     static private boolean FAST = true;
     static private boolean ANIMATE = false;
 
-    public ControlBinding() {
-        ; // nothing
-    }
-
     
     // -- Methods to handle events wisely.
 
@@ -47,7 +57,7 @@
                 float scale = e.scale; 
                 if (e.invert) scale *=-1;
                 MouseWheelEvent ev = (MouseWheelEvent)event;
-                if (c.isChangeAble()) {
+                if (c.isChangeable()) {
                     c.change(ev.getWheelRotation()*scale,
                              ev.getWheelRotation()*scale);
                     return FAST;
@@ -67,7 +77,7 @@
                     c.set(forObject, oldVS);
                     float scale = e.scale; 
                     if (e.invert) scale *=-1;
-                    if (c.isChangeAble()) 
+                    if (c.isChangeable()) 
                         throw new Error("Clicks can't be used to measure of 
change.");
                     else c.controlPoint(x, y, scale);
                     return ANIMATE;
@@ -90,7 +100,7 @@
                     c.set(forObject, oldVS);
                     float scale = e.scale; 
                     if (e.invert) scale *=-1;
-                    if (c.isChangeAble()) {
+                    if (c.isChangeable()) {
                         if (lastEvent != null)
                             c.change((lastEvent.getX()-x)*scale,
                                      (lastEvent.getY()-y)*scale 
@@ -108,36 +118,36 @@
             }
         }
 
-        if (dbg) p("No events binded.");
+        if (dbg) p("No events bound.");
         return FAST;
     }
 
 
-    // -- clicks, drags and wheels
-    
-    private ArrayList wheels = new ArrayList();
-    private ArrayList clicks = new ArrayList();
-    private ArrayList drags = new ArrayList();
+    /** Controllers associated with click, drag, and
+     *  wheel events, respectively.
+     */
+    private ArrayList 
+       clicks = new ArrayList(),
+       drags = new ArrayList(),
+       wheels = new ArrayList();
 
 
-    /** For example add(foo, "wheel");
+    /** For example add(foo, WHEEL);
      */
-    public void add(Controller controller, String binding) {
+    public void add(Controller controller, Type binding) {
         add(controller, -1, binding, 1, false);
     }
 
-    /** For example add(foo, 1, "click", ); or
-     * add(bar, 3, "drag");
+    /** For example add(foo, 1, CLICK); or
+     * add(bar, 3, DRAG);
      */
-    public void add(Controller controller, int button, String binding) {
+    public void add(Controller controller, int button, Type binding) {
         add(controller, button, binding, 1, false);
     }
     public void add(Controller controller, int button,
-                    String binding, float scale, boolean invert) {
+                    Type binding, float scale, boolean invert) {
 
-        String bind = binding.toUpperCase();
-
-        if (bind.equals("WHEEL") && button==-1) {
+        if (binding == WHEEL && button==-1) {
             wheels.add(new Event(controller, -1, scale, invert));
             return;
         }
@@ -151,11 +161,11 @@
             throw new Error("No button defined '"+button+"'.");
         }
 
-        if (bind.equals("CLICK")) {
+        if (binding == CLICK) {
             clicks.add(new Event(controller, mask, scale, invert));
-        } else if (bind.equals("DRAG")) {            
+        } else if (binding == DRAG) {            
             drags.add(new Event(controller, mask, scale, invert));
-        } else throw new Error("Unrecognised binding '"+binding+"'.");
+        } else throw new Error("Shouldn't be reached.");
     }
     
     class Event {
@@ -170,19 +180,23 @@
     }    
 
     public interface Controller {
-        boolean isChangeAble();
+        boolean isChangeable();
         void change(float x, float y);
         void controlPoint(float x, float y, float scale);
         void set(Object obj, VobScene oldVS);
     }
 
-    public abstract class AbstractController {
-        public abstract boolean isChangeAble();
+    public static abstract class AbstractController implements Controller {
+       public AbstractController() {}
+        public abstract boolean isChangeable();
 
         public void change(float x, float y) { }
         public void controlPoint(float x, float y, float scale) {}
-        protected Object obj = null;
-        protected VobScene oldVS = null;
+
+       // need to be public to be accessible from Python...
+        public Object obj = null;
+        public VobScene oldVS = null;
+
         public void set(Object obj, VobScene oldVS) { 
             this.obj = obj; 
             this.oldVS = oldVS;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]