/[fenfire]/fenfire/org/fenfire/util/ControlBinding.java
ViewVC logotype

Diff of /fenfire/org/fenfire/util/ControlBinding.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by mudyc, Thu Jun 19 11:57:47 2003 UTC revision 1.2 by benja, Thu Jun 19 15:23:44 2003 UTC
# Line 11  public class ControlBinding { Line 11  public class ControlBinding {
11      public static boolean dbg = false;      public static boolean dbg = false;
12      private static void p(String s) { System.out.println("ControlBinding:: "+s); }      private static void p(String s) { System.out.println("ControlBinding:: "+s); }
13    
14        /** A type of event that can be
15         *  associated with a controller.
16         *  This is a typesafe enumeration.
17         */
18        public static final class Type {
19            private Type() {}
20        }
21    
22        public static final Type
23            CLICK = new Type(),
24            DRAG = new Type(),
25            WHEEL = new Type();
26    
27    
28      static private boolean FAST = true;      static private boolean FAST = true;
29      static private boolean ANIMATE = false;      static private boolean ANIMATE = false;
30    
     public ControlBinding() {  
         ; // nothing  
     }  
   
31            
32      // -- Methods to handle events wisely.      // -- Methods to handle events wisely.
33    
# Line 47  public class ControlBinding { Line 57  public class ControlBinding {
57                  float scale = e.scale;                  float scale = e.scale;
58                  if (e.invert) scale *=-1;                  if (e.invert) scale *=-1;
59                  MouseWheelEvent ev = (MouseWheelEvent)event;                  MouseWheelEvent ev = (MouseWheelEvent)event;
60                  if (c.isChangeAble()) {                  if (c.isChangeable()) {
61                      c.change(ev.getWheelRotation()*scale,                      c.change(ev.getWheelRotation()*scale,
62                               ev.getWheelRotation()*scale);                               ev.getWheelRotation()*scale);
63                      return FAST;                      return FAST;
# Line 67  public class ControlBinding { Line 77  public class ControlBinding {
77                      c.set(forObject, oldVS);                      c.set(forObject, oldVS);
78                      float scale = e.scale;                      float scale = e.scale;
79                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
80                      if (c.isChangeAble())                      if (c.isChangeable())
81                          throw new Error("Clicks can't be used to measure of change.");                          throw new Error("Clicks can't be used to measure of change.");
82                      else c.controlPoint(x, y, scale);                      else c.controlPoint(x, y, scale);
83                      return ANIMATE;                      return ANIMATE;
# Line 90  public class ControlBinding { Line 100  public class ControlBinding {
100                      c.set(forObject, oldVS);                      c.set(forObject, oldVS);
101                      float scale = e.scale;                      float scale = e.scale;
102                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
103                      if (c.isChangeAble()) {                      if (c.isChangeable()) {
104                          if (lastEvent != null)                          if (lastEvent != null)
105                              c.change((lastEvent.getX()-x)*scale,                              c.change((lastEvent.getX()-x)*scale,
106                                       (lastEvent.getY()-y)*scale                                       (lastEvent.getY()-y)*scale
# Line 108  public class ControlBinding { Line 118  public class ControlBinding {
118              }              }
119          }          }
120    
121          if (dbg) p("No events binded.");          if (dbg) p("No events bound.");
122          return FAST;          return FAST;
123      }      }
124    
125    
126      // -- clicks, drags and wheels      /** Controllers associated with click, drag, and
127             *  wheel events, respectively.
128      private ArrayList wheels = new ArrayList();       */
129      private ArrayList clicks = new ArrayList();      private ArrayList
130      private ArrayList drags = new ArrayList();          clicks = new ArrayList(),
131            drags = new ArrayList(),
132            wheels = new ArrayList();
133    
134    
135      /** For example add(foo, "wheel");      /** For example add(foo, WHEEL);
136       */       */
137      public void add(Controller controller, String binding) {      public void add(Controller controller, Type binding) {
138          add(controller, -1, binding, 1, false);          add(controller, -1, binding, 1, false);
139      }      }
140    
141      /** For example add(foo, 1, "click", ); or      /** For example add(foo, 1, CLICK); or
142       * add(bar, 3, "drag");       * add(bar, 3, DRAG);
143       */       */
144      public void add(Controller controller, int button, String binding) {      public void add(Controller controller, int button, Type binding) {
145          add(controller, button, binding, 1, false);          add(controller, button, binding, 1, false);
146      }      }
147      public void add(Controller controller, int button,      public void add(Controller controller, int button,
148                      String binding, float scale, boolean invert) {                      Type binding, float scale, boolean invert) {
149    
150          String bind = binding.toUpperCase();          if (binding == WHEEL && button==-1) {
   
         if (bind.equals("WHEEL") && button==-1) {  
151              wheels.add(new Event(controller, -1, scale, invert));              wheels.add(new Event(controller, -1, scale, invert));
152              return;              return;
153          }          }
# Line 151  public class ControlBinding { Line 161  public class ControlBinding {
161              throw new Error("No button defined '"+button+"'.");              throw new Error("No button defined '"+button+"'.");
162          }          }
163    
164          if (bind.equals("CLICK")) {          if (binding == CLICK) {
165              clicks.add(new Event(controller, mask, scale, invert));              clicks.add(new Event(controller, mask, scale, invert));
166          } else if (bind.equals("DRAG")) {                      } else if (binding == DRAG) {            
167              drags.add(new Event(controller, mask, scale, invert));              drags.add(new Event(controller, mask, scale, invert));
168          } else throw new Error("Unrecognised binding '"+binding+"'.");          } else throw new Error("Shouldn't be reached.");
169      }      }
170            
171      class Event {      class Event {
# Line 170  public class ControlBinding { Line 180  public class ControlBinding {
180      }          }    
181    
182      public interface Controller {      public interface Controller {
183          boolean isChangeAble();          boolean isChangeable();
184          void change(float x, float y);          void change(float x, float y);
185          void controlPoint(float x, float y, float scale);          void controlPoint(float x, float y, float scale);
186          void set(Object obj, VobScene oldVS);          void set(Object obj, VobScene oldVS);
187      }      }
188    
189      public abstract class AbstractController {      public static abstract class AbstractController implements Controller {
190          public abstract boolean isChangeAble();          public AbstractController() {}
191            public abstract boolean isChangeable();
192    
193          public void change(float x, float y) { }          public void change(float x, float y) { }
194          public void controlPoint(float x, float y, float scale) {}          public void controlPoint(float x, float y, float scale) {}
195          protected Object obj = null;  
196          protected VobScene oldVS = null;          // need to be public to be accessible from Python...
197            public Object obj = null;
198            public VobScene oldVS = null;
199    
200          public void set(Object obj, VobScene oldVS) {          public void set(Object obj, VobScene oldVS) {
201              this.obj = obj;              this.obj = obj;
202              this.oldVS = oldVS;              this.oldVS = oldVS;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26