gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gzz/modules/pp EventHandling.java PPView2.j...


From: Matti Katila
Subject: [Gzz-commits] gzz/gzz/modules/pp EventHandling.java PPView2.j...
Date: Fri, 20 Dec 2002 13:24:00 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Matti Katila <address@hidden>   02/12/20 13:23:58

Modified files:
        gzz/modules/pp : EventHandling.java PPView2.java demotest.py 
        gzz/modules/pp/vob: VobCSGenerator.java 
Added files:
        gzz/modules/pp : PPMouseEvents.java 
Removed files:
        gzz/modules/pp : PPEvents.java 

Log message:
        Pp-events rework.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/PPMouseEvents.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/EventHandling.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/PPView2.java.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/demotest.py.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/vob/VobCSGenerator.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: gzz/gzz/modules/pp/EventHandling.java
diff -u gzz/gzz/modules/pp/EventHandling.java:1.1 
gzz/gzz/modules/pp/EventHandling.java:1.2
--- gzz/gzz/modules/pp/EventHandling.java:1.1   Thu Dec 19 11:06:20 2002
+++ gzz/gzz/modules/pp/EventHandling.java       Fri Dec 20 13:23:57 2002
@@ -2,6 +2,7 @@
 
 package gzz.modules.pp;
 
+import gzz.view.AbstractViewContext;
 import gzz.vob.VobScene;
 import gzz.util.Pair;
 
@@ -13,7 +14,8 @@
  * STATE: PROTOTYPE
  */
 public class EventHandling {
-    public void pa(String s) { System.out.println(s); }
+    public boolean dbg = false;
+    private void pa(String s) { System.out.println(s); }
     
     // Singleton
        static private EventHandling instance;
@@ -33,73 +35,125 @@
     private Map callers = new TreeMap();
     private Map ev_handlers = new TreeMap();
 
-
-
     private final int MASK  = 10000000;
     private final int CLICK = 20000000;
     private final int DRAG  = 30000000;
 
 
     // give cs.
+    public void onClick(int cs, String key) { onClick(cs, key, null); }
     public void onClick(int cs, String key, Object[] obs) {
        callers.put(""+(cs + CLICK), new Pair(key, obs) );
     }
 
+    public void onDrag(int cs, String key) { onDrag(cs, key, null); }
     public void onDrag(int cs, String key, Object[] obs) {
        callers.put(""+(cs + DRAG), new Pair(key, obs) );
     }
 
+    // give object
     public void assign(String key, Object obs) {
        ev_handlers.put(key, obs);
     }
 
+    /** If someone wants to pass new time the event call
+     */
+    public void passEvent(String key, MouseEvent ev, Object[] obs) {
+       Object ev_h = ev_handlers.get(key);
+       if (ev_h instanceof EventMouseObj) 
+           ((EventMouseObj)ev_h).event(ev, press_state, obs);
+    }
+
+
+    /** Used to clean callers at the beginning of render.
+     */
+    public void cleanCallers() {
+       callers = new TreeMap();
+    }
+
+
 
     
-    private int last_cs = -10;
+    private String last_key = null;
+    private boolean just_pressed = false;
+    private boolean dragging = false;
+    private MousePressState press_state = null;
+    public EventMouseObj when_pressed = null;
+    
 
     public void handleEvent(VobScene vs, MouseEvent ev) {
  
        int cs = vs.getCSAt(0, ev.getX(), ev.getY(), null);
-       pa("cs: " + cs);
+       if (dbg) pa("cs: " + cs);
 
        switch(ev.getID()) {
-       case MouseEvent.MOUSE_CLICKED: {
-           cs += CLICK;
-           pa("mouse click");
-           break;
-       }
        case MouseEvent.MOUSE_PRESSED: {
-           pa("mouse pressed");
+           press_state = new MousePressState(ev.getX(), ev.getY(),
+                                             ev.getModifiers());
+           if (when_pressed != null)
+               when_pressed.event(ev, press_state, null);
+
+           dragging = false;
+           just_pressed = true;
+           if (dbg) pa("mouse pressed");
            break;
        }
-       case MouseEvent.MOUSE_EXITED: {
-           pa("mouse exited");
-           last_cs = -1;
+       case MouseEvent.MOUSE_CLICKED: {
+           dragging = false;
+           just_pressed = false;
+           cs += CLICK;
+           if (dbg) pa("mouse click");
            break;
        }
        case MouseEvent.MOUSE_DRAGGED: {
+           dragging = true;
            cs += DRAG;
-           pa("mouse dragged");
+           if (dbg) pa("mouse dragged");
            break;
        }
+           /*
+             case MouseEvent.MOUSE_EXITED: {
+               if (dbg) pa("mouse exited");
+               break;
+             }
+           */
        };
 
-       pa("cs: " + cs);
        Object pair = callers.get(""+cs);
        if (pair == null) return;
        if (!(pair instanceof Pair)) { throw new Error("NOT PAIR!"); }
 
        String key = (String)((Pair)pair).first;
+       if (just_pressed && dragging) {
+           last_key = key;
+           just_pressed = false;
+       }
 
-       Object ev_h = ev_handlers.get(key);
-       pa("foo: "+ev_h);
-       if (ev_h instanceof EventObj) 
-           ((EventObj)ev_h).event(ev, ( (Object[]) ((Pair)pair).second));
+       if (dbg) pa("key: " + key);
+
+       // event hanlder
+       Object ev_h;
+       if (dragging) ev_h = ev_handlers.get(last_key);
+       else ev_h = ev_handlers.get(key);
+
+       if (ev_h instanceof EventMouseObj) 
+           ((EventMouseObj)ev_h).event(ev, press_state,
+                                            ((Object[]) ((Pair)pair).second));
     }
 
 
-    public interface EventObj {
-       public void event(MouseEvent ev, Object[] obs);
+    public interface EventMouseObj {
+       public void event(MouseEvent ev, MousePressState p_state, Object[] obs);
     }
 
+    public class MousePressState {
+       private int x, y, buttons;
+
+       public MousePressState(int x, int y, int b) {
+           this.x=x; this.y=y; this.buttons=b;
+       }
+       public int getX() { return x; }
+       public int getY() { return y; }
+       public int getButtons() { return buttons; }
+    }
 }
Index: gzz/gzz/modules/pp/PPView2.java
diff -u gzz/gzz/modules/pp/PPView2.java:1.27 
gzz/gzz/modules/pp/PPView2.java:1.28
--- gzz/gzz/modules/pp/PPView2.java:1.27        Thu Dec 19 11:06:20 2002
+++ gzz/gzz/modules/pp/PPView2.java     Fri Dec 20 13:23:57 2002
@@ -42,7 +42,7 @@
     public static Object NEWPAPERKEY = new Object();
 
     private EventHandling ev_handler = EventHandling.i();
-    public PPEvents pp_events;
+    public PPMouseEvents pp_events;
 
 
     // Geometry
@@ -291,22 +291,8 @@
                    -buoyVPWidth/2, -buoyVPHeight/2, 1, 1, 
                    buoyVPWidth, buoyVPHeight);
            vs.activate(frameCS);
-
-
-           float[] bar = { 0,0,0 };
-           float [] foo= new float[3];
-           vs.coords.transformPoints3(frameCS, bar, foo);
-           for (int i=0; i<foo.length; i++) {
-               pa("CS: "+foo[i]);
-           }
-
-           final GLVobCoorder glc = (GLVobCoorder)vs.coords;
-           float[] sqs = new float[2];
-           glc.getSqSize(frameCS, sqs);
-           if (sqs[1] < 5) return;
-           pa("size: Sqs frame: "+sqs[0]+" "+sqs[1]);
-
-
+           ev_handler.onClick(frameCS, "Link CLICK",
+                              new Object[]{ c, connectedFrom});
 
            // XXX Pan
            int[] pan = getCoords(c);
@@ -314,7 +300,6 @@
                    -pan[0]*buoyZoom, -pan[1]*buoyZoom, buoyZoom, buoyZoom);
            vs.matcher.add(buoycs, c2fCS, "C2F");
 
-
            buoyqueue.add(new Runnable() {
                public void run() {
                    buoy_vc.setAccursed(c);
@@ -336,7 +321,7 @@
        this.window = w;
        this.coordinatePlaneView = new CoordinatePlaneView(d.contains, d.pan);
        this.ppactions = ppactions;
-       pp_events = new PPEvents(ppactions);
+       pp_events = new PPMouseEvents(this, ppactions, space);
     }
 
     TextStyle style = GraphicsAPI.getInstance().getTextStyle("Sans", 0, 20);
@@ -351,6 +336,8 @@
            "LineWidth 2\nColor 0 0 0\nEnable TEXTURE_2D");
 
     public void render(VobScene vs, int intoCS, ViewContext context) {
+       ev_handler.cleanCallers();
+
 
        buoy_vc.setCellView(cellview);
 
@@ -386,6 +373,10 @@
                (-mainWidth)/2, -mainHeight/2, 1, 1, 
                mainWidth, mainHeight);
        vs.activate(frameCS);
+       ev_handler.onClick(frameCS, "Click MAINVP",
+                          new Object[]{ new Integer(mainctr), new 
Integer(frameCS)}
+                          );
+       ev_handler.onDrag(frameCS, "Drag MAINVP");
 
        // cell to frame CS
        int c2fCS = vs.coords.ortho(0, 0, 0, 0, 10, 10);
@@ -438,7 +429,7 @@
                      new_paper_button.getHeight(scale) + 
new_paper_button.getDepth(scale));
            vs.activate(new_paper_button_frame);
            vs.map.put(new_paper_button, new_paper_button_cs);
-           ev_handler.onClick(new_paper_button_frame, "Add new paper", null);
+           ev_handler.onClick(new_paper_button_frame, "Add new paper");
 
            // put the "Delete paper" -text
            TextVob delete_paper_button = new TextVob(style, "Tuhoa paperi");
@@ -451,7 +442,7 @@
                      delete_paper_button.getHeight(scale) + 
delete_paper_button.getDepth(scale));
            vs.activate(delete_paper_button_frame);
            vs.map.put(delete_paper_button, delete_paper_button_cs);
-           ev_handler.onClick(delete_paper_button_frame, "Delete paper", null);
+           ev_handler.onClick(delete_paper_button_frame, "Delete paper");
 
 
 
@@ -497,30 +488,23 @@
                    vs.matcher.add(ctr, fr, "frame");
                }
 
-               ((DefaultVobMatcher)vs.matcher).dumpByParent(ctr);
-
 
                //vs.matcher.add(ctr, new Pair(p, null));
                vs.matcher.add(ctr, new Pair(p, p));
-               //vs.matcher.add(ctr, new Pair(p, new Cell(space, 
"dasfdsaffsa")));
-               //vs.matcher.add(ctr, p);
                vs.activate(fr);
+               ev_handler.onClick(fr, "Shortcut link", new Object[]{p});
+
 
                int c2f = vs.coords.ortho(0, 11, 0, 0, 
                                          leftPanelZoom, leftPanelZoom);
                vs.matcher.add(ctr, c2f, "C2F");
 
-               pa(" ctr: "+ctr+
-                  " fr: "+fr+
-                  " c2f: "+c2f);
-
                buoy_vc.setAccursed(p);
                buoy_singlePlane.render(vs, fr, c2f);
                p = p.s(d.d1);
                
                i++;
            }
-           pa("********************************************************");
            //((DefaultVobMatcher)vs.matcher).dumbByParent();
        }
        
@@ -553,6 +537,8 @@
                                    (-linkbuoyVPWidth)/2, -linkbuoyVPHeight/2, 
1, 1, 
                                    linkbuoyVPWidth, linkbuoyVPHeight);
        vs.activate(frameCS);
+       ev_handler.onClick(frameCS, "Assoc link",
+                          new Object[]{otherNote, new Integer(dir)} );
 
        int c2f = vs.coords.ortho(0, 0, 
                                  -linkbuoyZoom*coords[0], 
-linkbuoyZoom*coords[1],
@@ -581,6 +567,7 @@
      */
     public void setCursorToMain(VobScene vs, float x, float y, 
                                AbstractViewContext context, int cs, int vp) {
+       /*
        float[] hit = new float[2];
        int vobcs = vs.coords.getCSAt(cs, x, y, hit);
        if(vobcs < 0) {
@@ -606,9 +593,11 @@
        }
        context.setAccursed((Cell)k);
        context.setCursorOffset(style.getOffsetInText(((Cell)k).t(), 1, 
hit[0]));
+       */
     }
 
     public Pair getMakeLinkOrSetCursor(VobScene vs, float x, float y, 
AbstractViewContext context) {
+       /*
        // First, get the frame that was hit.
        // This gives the "frame" coordsys.
        int cs = vs.coords.getCSAt(0, x, y, null);
@@ -633,6 +622,8 @@
        }
        Pair p = (Pair)key;
        return p;
+       */
+       return null;
     }
 
     /** Set the cursor of the given view context to the clicked point.
@@ -641,6 +632,7 @@
      *                 DefaultVobMatcher.setKeyMap() method.
      */
     public Map setCursorTo(VobScene vs, float x, float y, AbstractViewContext 
context) {
+       /*      
        // First, get the frame that was hit.
        // This gives the "frame" coordsys.
        int cs = vs.coords.getCSAt(0, x, y, null);
@@ -651,7 +643,6 @@
 
 
        if(!"frame".equals(vs.matcher.getKey(cs))) {
-           /*
            try {
                if ("new_paper_button_frame".equals(vs.matcher.getKey(cs)) ) {
                    ppactions.newPaper();
@@ -666,11 +657,10 @@
                    pa("WRONG KEY! "+vs.matcher.getKey(cs));
                }
            } catch (Exception e) { pa(e.getMessage()); }
-           */
-
            return null;
        }
-       
+
+
        // Get its parent
        int vp = ((GLVobCoorder)vs.coords).getParent(cs);
        Object key = vs.matcher.getKey(vp);
@@ -737,7 +727,7 @@
            return r;
        }
 
-
+       
        if 
("BuoyOnCircle".equals(((GLVobCoorder)vs.coords).getCoordSystemStr(vp))) {
 
            pa("Buoy!!!");
@@ -767,6 +757,9 @@
            // Change to paper which has been selected from the left panel.
            ((AbstractViewContext)context).setAccursed((Cell)p.first);
        }
-       return r;
-    }
+
+       return r; 
+       */
+       return null;
+   }
 }
Index: gzz/gzz/modules/pp/demotest.py
diff -u gzz/gzz/modules/pp/demotest.py:1.32 gzz/gzz/modules/pp/demotest.py:1.33
--- gzz/gzz/modules/pp/demotest.py:1.32 Thu Dec 19 11:06:20 2002
+++ gzz/gzz/modules/pp/demotest.py      Fri Dec 20 13:23:57 2002
@@ -170,42 +170,46 @@
        vs.matcher.setKeyMap(self.map)
        self.vs = vs
     def mouse(self, ev):
+        ev_h = self.ppv.pp_events
+        ev_h.vs = self.vs
+        ev_h.context = self.avc
         gzz.modules.pp.EventHandling.i().handleEvent(self.vs, ev);
 
-       if ev.getID() == ev.MOUSE_CLICKED:
-           if self.ppv.showLinkbuoys:
-               p = self.ppv.getMakeLinkOrSetCursor(self.vs, ev.getX(), 
ev.getY(),
-                               self.avc)
-               if p:
-                   if p.first != None:
-                       ppactions.assocNotes(self.avc.getAccursed().getId(), 
-                               -1, p.first.getId())
-                   else:
-                       ppactions.assocNotes(self.avc.getAccursed().getId(), 
-                               1, p.second.getId())
-               self.ppv.showLinkbuoys = 0
-           else:
-               self.map = self.ppv.setCursorTo(self.vs, ev.getX(), ev.getY(), 
self.avc)
-           AbstractUpdateManager.chg()
-       elif ev.getID() == ev.MOUSE_PRESSED:
-           self.press = (ev.getX(), ev.getY())
-           self.pzoom = self.ppv.zoom
-           self.poffset = (self.ppv.panx, self.ppv.pany)
-           self.but = ev.getModifiers()
-       elif ev.getID() == ev.MOUSE_DRAGGED:
-           if self.but == ev.BUTTON3_MASK:
-               self.ppv.zoom = self.pzoom * math.exp(
-                       (self.press[1] - ev.getY())/150.0)
-               print self.ppv.zoom
-           elif self.but == ev.BUTTON1_MASK:
-               self.ppv.panx = self.poffset[0] - (ev.getX() - self.press[0])
-               self.ppv.pany = self.poffset[1] - (ev.getY() - self.press[1])
-           else:
-               return
-           self.ppv.setZoomPan(self.vs)
+       #if ev.getID() == ev.MOUSE_CLICKED:
+       #    if self.ppv.showLinkbuoys:
+       #       p = self.ppv.getMakeLinkOrSetCursor(self.vs, ev.getX(), 
ev.getY(),
+       #                       self.avc)
+       #       if p:
+       #           if p.first != None:
+       #               ppactions.assocNotes(self.avc.getAccursed().getId(), 
+       #                       -1, p.first.getId())
+       #           else:
+       #               ppactions.assocNotes(self.avc.getAccursed().getId(), 
+       #                       1, p.second.getId())
+       #       self.ppv.showLinkbuoys = 0
+       #    else:
+       #       self.map = self.ppv.setCursorTo(self.vs, ev.getX(), ev.getY(), 
self.avc)
+       #    AbstractUpdateManager.chg()
+       #elif ev.getID() == ev.MOUSE_PRESSED:
+       #    self.press = (ev.getX(), ev.getY())
+       #    self.pzoom = self.ppv.zoom
+       #    self.poffset = (self.ppv.panx, self.ppv.pany)
+       #    self.but = ev.getModifiers()
+       #elif ev.getID() == ev.MOUSE_DRAGGED:
+        if ev.getID() == ev.MOUSE_DRAGGED:
+       #    if self.but == ev.BUTTON3_MASK:
+       #       self.ppv.zoom = self.pzoom * math.exp(
+       #               (self.press[1] - ev.getY())/150.0)
+       #       print self.ppv.zoom
+       #    elif self.but == ev.BUTTON1_MASK:
+       #       self.ppv.panx = self.poffset[0] - (ev.getX() - self.press[0])
+       #       self.ppv.pany = self.poffset[1] - (ev.getY() - self.press[1])
+       #    else:
+       #       return
+       #    self.ppv.setZoomPan(self.vs)
            replaceNewScene(self.vs)
-           AbstractUpdateManager.setNoAnimation()
-           AbstractUpdateManager.chg()
+       #    AbstractUpdateManager.setNoAnimation()
+       #    AbstractUpdateManager.chg()
 
 gzz.view.CoordinatePlaneView.dbg = 0
 gzz.view.Cell1DBuoyHook.dbg = 0
Index: gzz/gzz/modules/pp/vob/VobCSGenerator.java
diff -u gzz/gzz/modules/pp/vob/VobCSGenerator.java:1.5 
gzz/gzz/modules/pp/vob/VobCSGenerator.java:1.6
--- gzz/gzz/modules/pp/vob/VobCSGenerator.java:1.5      Thu Dec 12 10:35:03 2002
+++ gzz/gzz/modules/pp/vob/VobCSGenerator.java  Fri Dec 20 13:23:58 2002
@@ -43,7 +43,7 @@
      */
     public VobCSGenerator(VobScene vs, int cs_into, int vob_count, int 
focus_index, float vob_width, float vob_height) {
 
-       pa("Vobeja: "+ vob_count+" focus on: "+ focus_index);
+       if (dbg) pa("Vobeja: "+ vob_count+" focus on: "+ focus_index);
        if ( vob_count == 0) {
            pa("DEBUG: Might be an error - but there are no vob around!");
            return; 



reply via email to

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