gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/lava gzz/loom/Cursor.java gzz/loom/Loom.jav...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava gzz/loom/Cursor.java gzz/loom/Loom.jav...
Date: Sun, 23 Feb 2003 18:44:56 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      03/02/23 18:44:56

Modified files:
        lava/gzz/loom  : Cursor.java Loom.java 
        lava/test/gzz/loom: Cursor.test SimpleView.test 

Log message:
        fix

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/loom/Cursor.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/loom/Loom.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/loom/Cursor.test.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/loom/SimpleView.test.diff?tr1=1.14&tr2=1.15&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/loom/Cursor.java
diff -u gzz/lava/gzz/loom/Cursor.java:1.7 gzz/lava/gzz/loom/Cursor.java:1.8
--- gzz/lava/gzz/loom/Cursor.java:1.7   Sun Feb 23 18:00:54 2003
+++ gzz/lava/gzz/loom/Cursor.java       Sun Feb 23 18:44:56 2003
@@ -36,6 +36,7 @@
 public class Cursor {
 
     public Resource focus;
+    public int dir;
     public RDFNode rotation;
 
     /** The comparator used to order the nodes in the graph.
@@ -47,13 +48,14 @@
        this.order = order;
     }
 
-    public Cursor(Comparator order, Resource focus, RDFNode rotation) {
+    public Cursor(Comparator order, Resource focus, int dir, RDFNode rotation) 
{
        this(order);
-       set(focus, rotation);
+       set(focus, dir, rotation);
     }
 
-    public void set(Resource focus, RDFNode rotation) {
+    public void set(Resource focus, int dir, RDFNode rotation) {
        this.focus = focus;
+       this.dir = dir;
        this.rotation = rotation;
     }
 
@@ -65,10 +67,8 @@
     public int getRotationIndex() {
        if(rotation == null)
            return 0;
-       else if(getConnections(1).contains(rotation))
-           return getConnections(1).headSet(rotation).size();
-       else if(getConnections(-1).contains(rotation))
-           return getConnections(-1).headSet(rotation).size();
+       else if(getConnections(dir).contains(rotation))
+           return getConnections(dir).headSet(rotation).size();
        else
            return 0;
     }
@@ -103,31 +103,45 @@
     /** Rotate the view up or down.
      *  This moves the rotation of the cursor one step up or down. XXX
      */
-    public void rotate(int dir) {
+    public void rotate(int rdir) {
        SortedSet 
            neg = getConnections(-1),
            pos = getConnections(1);
 
+       if(rotation == null) {
+           if(pos.size() > 0) {
+               rotation = (RDFNode)pos.iterator().next();
+               dir = 1;
+           } else if(neg.size() > 0) {
+               rotation = (RDFNode)neg.iterator().next();
+               dir = -1;
+           } else
+               return;
+       }
+
        int i = getRotationIndex();
 
-       if(dir < 0) i--;
+       if(rdir < 0) i--;
        else i++;
 
        if(i < 0) return;
-       if(i >= getConnections(-1).size() &&
-          i >= getConnections(1).size()) return;
+       if(i >= neg.size() && i >= pos.size()) return;
 
        List l;
-       if(pos.contains(rotation)) {
+       if(dir > 0) {
            if(pos.size() > i)
                l = new ArrayList(pos);
-           else
+           else {
                l = new ArrayList(neg);
+               dir = -1;
+           }
        } else {
            if(neg.size() > i)
                l = new ArrayList(neg);
-           else
+           else {
                l = new ArrayList(pos);
+               dir = 1;
+           }
        }
 
        rotation = (RDFNode)l.get(i);
@@ -135,8 +149,8 @@
 
     /** Move left/right. XXX
      */ 
-    public void move(int dir) {
-       Iterator iter = getConnections(dir).iterator();
+    public void move(int mdir) {
+       Iterator iter = getConnections(mdir).iterator();
        int n = getRotationIndex();
        for(int i=0; i<n; i++) if(iter.hasNext()) iter.next();
        if(!iter.hasNext())
@@ -144,5 +158,6 @@
            return;
        rotation = focus;
        focus = (Resource)iter.next();
+       dir = -mdir;
     }
 }
Index: gzz/lava/gzz/loom/Loom.java
diff -u gzz/lava/gzz/loom/Loom.java:1.7 gzz/lava/gzz/loom/Loom.java:1.8
--- gzz/lava/gzz/loom/Loom.java:1.7     Sun Feb 23 15:43:40 2003
+++ gzz/lava/gzz/loom/Loom.java Sun Feb 23 18:44:56 2003
@@ -61,7 +61,7 @@
                }
            };
        final Cursor cursor = 
-           new Cursor(order, stmt.getSubject(), stmt.getObject());
+           new Cursor(order, stmt.getSubject(), 1, stmt.getObject());
 
        final Vob bg = new RectBgVob();
        final TextStyle style = api.getTextStyle("Serif", 0, 12);
Index: gzz/lava/test/gzz/loom/Cursor.test
diff -u gzz/lava/test/gzz/loom/Cursor.test:1.6 
gzz/lava/test/gzz/loom/Cursor.test:1.7
--- gzz/lava/test/gzz/loom/Cursor.test:1.6      Sun Feb 23 18:13:04 2003
+++ gzz/lava/test/gzz/loom/Cursor.test  Sun Feb 23 18:44:56 2003
@@ -49,31 +49,28 @@
 def testGetConnections():
     n[6].addProperty(p, n[1])
     
-    c.set(n[0], n[1])
+    c.set(n[0], 1, n[1])
     assert list(c.getConnections(1)) == [n[1]]
     assert list(c.getConnections(-1)) == []
 
-    c.set(n[1], n[2])
+    c.set(n[1], 1, n[2])
     assert list(c.getConnections(1)) == [n[2]]
     assert list(c.getConnections(-1)) == [n[0], n[6]]
 
-    c.set(n[2], n[3])
+    c.set(n[2], 1, n[3])
     assert list(c.getConnections(1)) == n[3:]
     assert list(c.getConnections(-1)) == [n[1]]
 
-    c.set(n[6], n[1])
+    c.set(n[6], 1, n[1])
     assert list(c.getConnections(1)) == [n[1]]
     assert list(c.getConnections(-1)) == [n[2]]
 
 
 def testConnectedTwoWays():
-    """
-    fail: *
-    """
     n[5].addProperty(p, n[0])
     n[5].addProperty(p, n[2])
 
-    c.set(n[2], n[5])
+    c.set(n[2], 1, n[5])
     c.move(1)
     assert c.getRotationIndex() == 0
 
@@ -82,16 +79,16 @@
 
 
 def testRotationIndex():
-    c.set(n[1], n[2])
+    c.set(n[1], 1, n[2])
     assert c.getRotationIndex() == 0
 
-    c.set(n[2], n[5])
+    c.set(n[2], 1, n[5])
     assert c.getRotationIndex() == 2
 
-    c.set(n[2], n[9])
+    c.set(n[2], 1, n[9])
     assert c.getRotationIndex() == 6
 
-    c.set(n[4], None)
+    c.set(n[4], 0, None)
     assert c.getRotationIndex() == 0
 
 
@@ -99,7 +96,7 @@
     n[4].addProperty(p, n[5])
     n[6].addProperty(p, n[5])
 
-    c.set(n[5], n[4])
+    c.set(n[5], -1, n[4])
 
     assert c.getRotationIndex() == 1
     c.rotate(-1)
@@ -115,7 +112,7 @@
     assert c.getRotationIndex() == 2
     assert c.rotation == n[6]
 
-    c.set(n[5], None)
+    c.set(n[5], 0, None)
 
     assert c.getRotationIndex() == 0
     c.rotate(-1)
@@ -124,7 +121,7 @@
     assert c.getRotationIndex() == 1
     assert c.rotation == n[4]
 
-    c.set(n[5], None)
+    c.set(n[5], 0, None)
     c.rotate(1)
     assert c.getRotationIndex() == 1
     assert c.rotation == n[4]
@@ -134,15 +131,15 @@
     
 
 def testRotateMove():
-    c.set(n[2], n[5])
+    c.set(n[2], 1, n[5])
     c.rotate(1)
-    assert c.focus == n[2] and c.rotation == n[6]
+    assert c.focus == n[2] and c.rotation == n[6] and c.dir == 1
     c.rotate(1)
-    assert c.focus == n[2] and c.rotation == n[7]
+    assert c.focus == n[2] and c.rotation == n[7] and c.dir == 1
     c.rotate(-1)
-    assert c.focus == n[2] and c.rotation == n[6]
+    assert c.focus == n[2] and c.rotation == n[6] and c.dir == 1
 
-    c.set(n[2], n[9])
+    c.set(n[2], 1, n[9])
     c.rotate(1)
     assert c.focus == n[2] and c.rotation == n[9]
     c.rotate(-1)
@@ -152,35 +149,52 @@
     c.rotate(1)
     assert c.focus == n[2] and c.rotation == n[9]
 
-    c.set(n[2], n[1])
-    assert c.getRotationIndex() == 0
+    c.set(n[2], -1, n[1])
+    assert c.getRotationIndex() == 0 and c.dir == -1
     c.rotate(1)
-    assert c.getRotationIndex() == 1
+    assert c.getRotationIndex() == 1 and c.dir == 1
     c.rotate(1)
-    assert c.getRotationIndex() == 2
+    assert c.getRotationIndex() == 2 and c.dir == 1
+    c.move(-1)
+    assert c.focus == n[2] and c.getRotationIndex() == 2 and \
+           c.dir == 1
     c.move(1)
-    assert c.focus == n[5] and c.rotation == n[2]
+    assert c.focus == n[5] and c.rotation == n[2] and c.dir == -1
 
-    c.set(n[2], n[3])
+    c.set(n[2], 1, n[3])
     c.rotate(-1)
-    assert c.focus == n[2] and c.rotation == n[3]
+    assert c.focus == n[2] and c.rotation == n[3] and c.dir == 1
 
     c.move(-1)
-    assert c.focus == n[1] and c.rotation == n[2]
+    assert c.focus == n[1] and c.rotation == n[2] and c.dir == 1
     c.move(-1)
-    assert c.focus == n[0] and c.rotation == n[1]
+    assert c.focus == n[0] and c.rotation == n[1] and c.dir == 1
     c.move(1)
-    assert c.focus == n[1] and c.rotation == n[0]
+    assert c.focus == n[1] and c.rotation == n[0] and c.dir == -1
     c.move(1)
-    assert c.focus == n[2] and c.rotation == n[1]
+    assert c.focus == n[2] and c.rotation == n[1] and c.dir == -1
 
 
     # if we cannot move there, we remain where we are:
 
-    c.set(n[2], n[7])
+    c.set(n[2], 1, n[7])
     c.move(-1)
-    assert c.focus == n[2] and c.rotation == n[7]
+    assert c.focus == n[2] and c.rotation == n[7] and c.dir == 1
 
-    c.set(n[0], n[1])
+    c.set(n[0], 1, n[1])
     c.move(-1)
-    assert c.focus == n[0] and c.rotation == n[1]
+    assert c.focus == n[0] and c.rotation == n[1] and c.dir == 1
+
+
+def testRotationChangesDir():
+    n[7].addProperty(p, n[1])
+
+    c.set(n[2], -1, n[1])
+    assert c.getRotationIndex() == 0 and c.dir == -1
+    c.rotate(1)
+    assert c.getRotationIndex() == 1 and c.dir == 1
+
+    c.set(n[1], 1, n[2])
+    assert c.getRotationIndex() == 0 and c.dir == 1
+    c.rotate(1)
+    assert c.getRotationIndex() == 1 and c.dir == -1
Index: gzz/lava/test/gzz/loom/SimpleView.test
diff -u gzz/lava/test/gzz/loom/SimpleView.test:1.14 
gzz/lava/test/gzz/loom/SimpleView.test:1.15
--- gzz/lava/test/gzz/loom/SimpleView.test:1.14 Sun Feb 23 15:19:10 2003
+++ gzz/lava/test/gzz/loom/SimpleView.test      Sun Feb 23 18:44:56 2003
@@ -50,7 +50,7 @@
     r.addProperty(p, t)
 
     vs = getvs()
-    cursor = gzz.loom.Cursor(Cmp(), r, None)
+    cursor = gzz.loom.Cursor(Cmp(), r, 0, None)
     view.render(vs, 0, cursor)
 
     cs_r, cs_s, cs_t, cs_u, cs_v = [vs.matcher.getCS(0, x)
@@ -74,7 +74,7 @@
     w.addProperty(p, r)
 
     vs = getvs()
-    cursor = gzz.loom.Cursor(Cmp(), r, s)
+    cursor = gzz.loom.Cursor(Cmp(), r, 1, s)
     view.render(vs, 0, cursor)
 
     cs_r, cs_s, cs_t, cs_u, cs_v, cs_w = \




reply via email to

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