gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] loom/org/fenfire/loom SundewWheelView.java View...


From: Asko Soukka
Subject: [Gzz-commits] loom/org/fenfire/loom SundewWheelView.java View...
Date: Wed, 09 Apr 2003 08:18:20 -0400

CVSROOT:        /cvsroot/loom
Module name:    loom
Changes by:     Asko Soukka <address@hidden>    03/04/09 08:18:20

Modified files:
        org/fenfire/loom: SundewWheelView.java ViewSettings.test 
                          WheelView.java 

Log message:
        WheelView obsession

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/SundewWheelView.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/ViewSettings.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/WheelView.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text

Patches:
Index: loom/org/fenfire/loom/SundewWheelView.java
diff -u loom/org/fenfire/loom/SundewWheelView.java:1.1 
loom/org/fenfire/loom/SundewWheelView.java:1.2
--- loom/org/fenfire/loom/SundewWheelView.java:1.1      Sun Apr  6 19:43:48 2003
+++ loom/org/fenfire/loom/SundewWheelView.java  Wed Apr  9 08:18:20 2003
@@ -37,65 +37,78 @@
  */
 public class SundewWheelView extends WheelView {
 
-    public static boolean dbg = false;
+    public static boolean dbg = true;
     private static void p(String s) { System.out.println(s); }
 
     public SundewWheelView(NodeView nodeView) {
        super(nodeView);
 
        radius = (sizex + gapx) * 2;
-       depth = 2;
+       maxDepth = 2;
     }
 
-    protected void renderDepth(VobScene sc, int into, Cursor c, Resource focus,
-                           Pair current, Collection nodes, int dir, double 
cura,
-                           double rota, float r, int focusCs, int depth, int 
midx,
-                           int midy) {
-       RDFNode newFocus = (RDFNode)current.first;
-       if (newFocus != null && newFocus instanceof Resource) {
-           Vector removal = new Vector();
-           Pair focusPair = new Pair(focus, (Property)current.second);
-           removal.add(focusPair);
-
+    protected void renderDepth(VobScene sc, int into, int focusCs,
+                              Cursor c, Pair focus, Pair oldFocus,
+                              int dir, double cura, double rota,
+                              float r, int midx, int midy, int depth) {
+       if (((RDFNode)focus.first) instanceof Resource) {
+           oldFocus = new Pair(oldFocus.first, focus.second);
+           
            Collection posNodes, negNodes;
+
            if (dir > 0) {
-               posNodes = getNodes(c, (Resource)newFocus, 1);
-               negNodes = getNodes(c, (Resource)newFocus, -1, removal);
+               posNodes = getNodes(c, (Resource)focus.first, 1);
+               negNodes = getNodes(c, (Resource)focus.first, -1);
            } else {
-               posNodes = getNodes(c, (Resource)newFocus, 1, removal);
-               negNodes = getNodes(c, (Resource)newFocus, -1);
-           }
+               posNodes = getNodes(c, (Resource)focus.first, 1);
+               negNodes = getNodes(c, (Resource)focus.first, -1);
+           }    
                    
-           double posRota = getRotationAngle(c, (Resource)newFocus, posNodes,
-                                             Math.PI, depth-1);
-           double negRota = getRotationAngle(c, (Resource)newFocus, negNodes,
-                                             Math.PI, depth-1);
+           double posRota = getRotationAngle(c, (Resource)focus.first, 
posNodes,
+                                             Math.PI, depth);
+           double negRota = getRotationAngle(c, (Resource)focus.first, 
negNodes,
+                                             Math.PI, depth);
 
            double newRota = (posRota < negRota) ? posRota : negRota;
            if (posRota < 0) newRota = negRota;
            else if (negRota < 0) newRota = posRota;
-
-           int position = (posNodes.size() > negNodes.size()) ?
-               posNodes.size() / 2: negNodes.size() / 2;
-
+           
            int x = midx+x(cura, r);
            int y = midy+y(cura, r);
 
-           renderSomewardConnections(sc, into, c, (Resource)newFocus, posNodes,
-                                     position, 1, newRota/2, newRota,
-                                     r/2, focusCs, depth-1, x, y);
-
-           renderSomewardConnections(sc, into, c, (Resource)newFocus, negNodes,
-                                     position, -1, Math.PI+newRota/2, newRota,
-                                     r/2, focusCs, depth-1, x, y);
+           if (depth == maxDepth) r = gapx + sizex;
+           else r = r/2;
+
+           Cursor curPosition = new Cursor(c.getSubjectOrder(), 
c.getObjectOrder(),
+                                           c.getStatementSelector(), c.names,
+                                           (Resource)focus.first, dir*-1,
+                                           (RDFNode)oldFocus.first);
+           int posPosition = curPosition.getRotationIndex(1);
+           int negPosition = curPosition.getRotationIndex(-1);
+           
+           if (dir > 0) {
+               renderSomewardConnections(sc, into, focusCs, c, focus, null,
+                                         posNodes, posPosition, 1, 0, newRota,
+                                         r, x, y,  depth);
+               renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
+                                         negNodes, negPosition, -1, Math.PI, 
newRota,
+                                         r, x, y, depth);
+           } else {
+               renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
+                                         posNodes, posPosition, 1, 0, newRota,
+                                         r, x, y,  depth);
+               renderSomewardConnections(sc, into, focusCs, c, focus, null,
+                                         negNodes, negPosition, -1, Math.PI, 
newRota,
+                                         r, x, y, depth);
+           }
        }
     }
-
-    private int x(double angle, float radius) {
+    
+    protected int x(double angle, float radius) {
         return (int)(Math.cos(angle) * radius);
     }
 
-    private int y(double angle, float radius) {
-        return (int)(Math.sin(angle) * radius);
+    protected int y(double angle, float radius) {
+        return (int)(Math.sin(angle) * radius * 0.75);
     }
 }
Index: loom/org/fenfire/loom/ViewSettings.test
diff -u loom/org/fenfire/loom/ViewSettings.test:1.1 
loom/org/fenfire/loom/ViewSettings.test:1.2
--- loom/org/fenfire/loom/ViewSettings.test:1.1 Mon Mar 31 17:41:23 2003
+++ loom/org/fenfire/loom/ViewSettings.test     Wed Apr  9 08:18:20 2003
@@ -32,8 +32,16 @@
     assert s.getViewIndex() == 1
     assert s.isSimpleView()
     s.changeView(1)
+    assert isinstance(s.getView(), org.fenfire.loom.SundewWheelView)
+    assert s.getViewIndex() == 2
+    assert s.isWheelView()
+    s.changeView(1)
     assert isinstance(s.getView(), org.fenfire.loom.WheelView)
     assert s.getViewIndex() == 0
+    assert s.isWheelView()
+    s.changeView(-1)
+    assert isinstance(s.getView(), org.fenfire.loom.SundewWheelView)
+    assert s.getViewIndex() == 2
     assert s.isWheelView()
     s.changeView(-1)
     assert isinstance(s.getView(), org.fenfire.loom.SimpleView)
Index: loom/org/fenfire/loom/WheelView.java
diff -u loom/org/fenfire/loom/WheelView.java:1.6 
loom/org/fenfire/loom/WheelView.java:1.7
--- loom/org/fenfire/loom/WheelView.java:1.6    Sun Apr  6 19:43:48 2003
+++ loom/org/fenfire/loom/WheelView.java        Wed Apr  9 08:18:20 2003
@@ -45,21 +45,24 @@
  */
 public class WheelView implements View {
 
-    public static boolean dbg = false;
+    public static boolean dbg = true;
     private static void p(String s) { System.out.println(s); }
 
     /** The view used to show the individual nodes.
      */
     protected NodeView nodeView;
 
-    protected final Vob conn = new SimpleConnection(1,.5f,0,.5f);
+    protected final Vob posConn = new SimpleConnection(1,.5f,0,.5f);
+    protected final Vob negConn = new SimpleConnection(0,.5f,1,.5f);
+    protected final Vob posStub = new PinStub(1,.5f,0,.5f);
+    protected final Vob negStub = new PinStub(0,.5f,1,.5f);
 
     /** WheelView
-     * @param depth How deeply should the structure be shown.
+     * @param maxDepth How deeply should the structure be shown.
      */
-    public WheelView(NodeView nodeView, int depth) {
+    public WheelView(NodeView nodeView, int maxDepth) {
        this.nodeView = nodeView;
-       this.depth = depth;
+       this.maxDepth = maxDepth;
     }
     public WheelView(NodeView nodeView) { this(nodeView, 2); }
 
@@ -70,7 +73,7 @@
     protected int gapx = 50, gapy = 30;
 
     protected int radius = sizex + gapx;
-    protected int depth = 1;
+    protected int maxDepth;
 
     /** Maximum rotation angle. */
     protected double maxrota = Math.PI / 9;
@@ -79,77 +82,113 @@
      *  Render either posward or negward connections
      *  (or onward, maybe).
      */
-    public void renderSomewardConnections(VobScene sc, int into, Cursor c, 
Resource focus,
-                                         Collection nodes, int before, int dir,
-                                         double starta, double rota, float r, 
-                                         int focusCs, int depth,
-                                         int midx, int midy) {
+    public void renderSomewardConnections(VobScene sc, int into, int focusCs, 
+                                         Cursor c, Pair focus, Pair oldFocus, 
+                                         Collection nodes, int before,
+                                         int dir, double starta, double rota,
+                                         float r, int midx, int midy, int 
depth) {
+       if (dbg) {
+           if (dir > 0)
+               p("POS Render, nodes: "+nodes.size()
+                 +", starta: "+starta+", rota: "+rota+", depth: "+depth
+                 +", position: "+before);          
+           else
+               p("NEG Render, nodes: "+nodes.size()
+                 +", starta: "+starta+", rota: "+rota+", depth: "+depth
+                 +", position: "+before);          
+       }
+
        double cura = starta - (before * rota);
-       if (dbg) p("Render, nodes: "+nodes.size()+", starta: "+starta
-                  +", cura: "+cura+", depth: "+depth);     
        for(Iterator i=nodes.iterator(); i.hasNext();) {
            Pair current = (Pair)i.next();
-           
-           NodeView.Nodespec spec = 
-               new NodeView.Nodespec((RDFNode)current.first,
-                                     (Property)current.second,
-                                     dir);
-           int x = midx+x(cura, r)-sizex/2;
-           int y = midy+y(cura, r)-sizey/2;
-           int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before),
-                                   x, y, 1, 1, sizex, sizey);
-           sc.coords.activate(cs2);
-           nodeView.render(sc, cs2, spec);
-                           
-           if(dir > 0)
-               sc.map.put(conn, focusCs, cs2);    
-           else
-               sc.map.put(conn, cs2, focusCs);
 
-           if (depth > 1)
-               renderDepth(sc, into, c, focus, current, nodes, dir,
-                           cura, rota, r, cs2, depth, midx, midy);
-           
+           if (!current.equals(oldFocus)) {
+               NodeView.Nodespec spec = 
+                   new NodeView.Nodespec((RDFNode)current.first,
+                                         (Property)current.second,
+                                         dir);
+               int x = midx+x(cura, r)-sizex/2;
+               int y = midy+y(cura, r)-sizey/2;
+               int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before),
+                                       x, y, 1, 1, sizex, sizey);
+       
+               if (depth == maxDepth) {
+                   Vob stub;
+                   if(dir > 0) stub = posStub;
+                   else stub = negStub;
+                   sc.map.put(stub, focusCs, cs2);
+               } else if (depth < maxDepth) {
+                   sc.coords.activate(cs2);
+                   nodeView.render(sc, cs2, spec);
+                   
+                   Vob conn;
+                   if(dir > 0) conn = posConn;
+                   else conn = negConn;
+                   sc.map.put(conn, focusCs, cs2);
+                   
+                   renderDepth(sc, into, cs2, c, current, focus,
+                               dir, cura, rota, r, midx, midy, depth+1);
+               }
+           }
            cura+=rota;
            before--;
        }
     }
 
-    protected void renderDepth(VobScene sc, int into, Cursor c, Resource focus,
-                           Pair current, Collection nodes, int dir, double 
cura,
-                           double rota, float r, int focusCs, int depth, int 
midx,
-                           int midy) {
-       RDFNode newFocus = (RDFNode)current.first;
-       if (newFocus != null && newFocus instanceof Resource) {
-           
-           Vector removal = new Vector();
-           Pair focusPair = new Pair(focus, (Property)current.second);
-           removal.add(focusPair);
-
-           /** This shows as much nodes as possible. Shows the both directions
-            * also in branches. Removes the focused node+prop pairs from 
branch.
-            * Problem is that moving don't work properly. Nodes change from the
-            * one side to another and it seems to be confusing.
-            */
-           Collection subNodes = getNodes(c, (Resource)newFocus, 0, removal);
-           
-           /** This won't remove any nodes. */
-           //Collection subNodes = getNodes(c, (Resource)newFocus, 0);
-           
-           /** This don't show the links of opposite direction at all in 
branches.
-            * This is the one, which would really work, if we would have 
rotable
-            * stubs to shown the hidden connections
-            */
-           //Collection subNodes = getNodes(c, (Resource)newFocus, dir);
-           
-           double subRota = getRotationAngle(c, (Resource)newFocus, subNodes,
-                                             rota, depth-1);
-           renderSomewardConnections(sc, into, c, (Resource)newFocus, subNodes,
-                                     subNodes.size()/2, dir, cura, subRota,
-                                     r+gapx+sizex, focusCs, depth-1, midx, 
midy);
+    protected void renderDepth(VobScene sc, int into, int focusCs,
+                              Cursor c, Pair focus, Pair oldFocus,
+                              int dir, double cura, double rota,
+                              float r, int midx, int midy, int depth) {
+       if (((RDFNode)focus.first) instanceof Resource) {
+           oldFocus = new Pair(oldFocus.first, focus.second);
+           
+           Collection posNodes, negNodes;
+
+           if (dir > 0) {
+               posNodes = getNodes(c, (Resource)focus.first, 1);
+               negNodes = getNodes(c, (Resource)focus.first, -1);
+           } else {
+               posNodes = getNodes(c, (Resource)focus.first, 1);
+               negNodes = getNodes(c, (Resource)focus.first, -1);
+           }    
+                   
+           double posRota = getRotationAngle(c, (Resource)focus.first, 
posNodes,
+                                             Math.PI, depth);
+           double negRota = getRotationAngle(c, (Resource)focus.first, 
negNodes,
+                                             Math.PI, depth);
+
+           double newRota = (posRota < negRota) ? posRota : negRota;
+           if (posRota < 0) newRota = negRota;
+           else if (negRota < 0) newRota = posRota;
+           
+           int x = midx+x(cura, r);
+           int y = midy+y(cura, r);
+
+           Cursor curPosition = new Cursor(c.getSubjectOrder(), 
c.getObjectOrder(),
+                                           c.getStatementSelector(), c.names,
+                                           (Resource)focus.first, dir*-1,
+                                           (RDFNode)oldFocus.first);
+           int posPosition = curPosition.getRotationIndex(1);
+           int negPosition = curPosition.getRotationIndex(-1);
+           
+           if (dir > 0) {
+               renderSomewardConnections(sc, into, focusCs, c, focus, null,
+                                         posNodes, posPosition, 1, cura, 
newRota,
+                                         r+gapx+sizex, midx, midy,  depth);
+               renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
+                                         negNodes, negPosition, -1, 
Math.PI+cura, newRota,
+                                         gapx+sizex, x, y,  maxDepth);
+           } else {
+               renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
+                                          posNodes, posPosition, 1, 
Math.PI+cura, newRota,
+                                          gapx+sizex, x, y,  maxDepth);
+               renderSomewardConnections(sc, into, focusCs, c, focus, null,
+                                         negNodes, negPosition, -1, cura, 
newRota,
+                                         r+gapx+sizex, midx, midy, depth);
+           }
        }
     }
-
+    
     public void render(VobScene sc, int into, Cursor c) {
        if (dbg) 
p("*******************************************************************");       
   
        int midx = sc.size.width/2, midy = sc.size.height/2;
@@ -161,51 +200,43 @@
 
        Collection posNodes = getNodes(c, 1);
        Collection negNodes = getNodes(c, -1);
-       double posRota = getRotationAngle(c, posNodes, Math.PI, depth);
-       double negRota = getRotationAngle(c, negNodes, Math.PI, depth);
+       double posRota = getRotationAngle(c, posNodes, Math.PI, 0);
+       double negRota = getRotationAngle(c, negNodes, Math.PI, 0);
 
        double rota = (posRota < negRota) ? posRota : negRota;
        if (posRota < 0) rota = negRota;
        else if (negRota < 0) rota = posRota;
        
-       if (dbg) p("Render, posNodes: "+posNodes.size()+
-                  ", posRota: "+posRota+", rota: "+rota);          
        /** Poswards connections */
-       renderSomewardConnections(sc, into, c, c.focus, posNodes,
-                                 c.getRotationIndex(1), 1, 0,
-                                 rota, radius, cs, depth, midx, midy);
+       renderSomewardConnections(sc, into, cs, c, new Pair(c.focus, null), 
null, 
+                                 posNodes, c.getRotationIndex(1),
+                                 1, 0, rota, radius, midx, midy, 0);
 
-       if (dbg) p("Render, negNodes: "+negNodes.size()+
-                  ", negRota: "+negRota+", rota: "+rota);          
        /** Negward connections */
-       renderSomewardConnections(sc, into, c, c.focus, negNodes,
-                                 c.getRotationIndex(-1), -1, Math.PI,
-                                 rota, radius, cs, depth, midx, midy);
+       renderSomewardConnections(sc, into, cs, c, new Pair(c.focus, null), 
null, 
+                                 negNodes, c.getRotationIndex(-1),
+                                 -1, Math.PI, rota, radius, midx, midy, 0);
     }
 
     protected double getRotationAngle(Cursor c, Resource node, Collection 
nodes,
                                      double angle, int depth) {
-       if (dbg) p("Angle, nodes: "+nodes.size()+
-                  ", angle: "+angle+", depth: "+depth);            
        double rota;
-       if (depth < 1) throw new Error("Depth is lesser than 1.");
-       if (depth == 1) {
+       if (depth > maxDepth || depth < 0)
+           throw new Error("Depth greater than maxDepth or lesser than zero.");
+       if (depth == maxDepth) {
            if (nodes.size() == 0) return -1;
            rota = angle / nodes.size();
            /** Rotation angle should be no bigger than defined maximum. */
            if (rota > maxrota) rota = maxrota;
-           if (dbg) p("Angle, first: "+angle / nodes.size()+
-                  ", returned: "+rota);            
            return rota;
        }
 
-       int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth-1); 
+       int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth+1); 
        if (nodeCount == 0) return -1;
        if ((angle / nodeCount) >= maxrota) 
            angle = nodeCount * maxrota;
        rota = angle / nodes.size();
 
-       if (dbg) p("Angle, nodeCount: "+nodeCount+", returned: "+rota);     
        return rota;
     }
     protected double getRotationAngle(Cursor c, Collection nodes, 
@@ -213,43 +244,20 @@
        return getRotationAngle(c, c.focus, nodes, angle, depth);
     }
 
-    protected Collection getNodes(Cursor c, Resource node,
-                                 int dir, Collection removal) {
-       Vector v;
-       if (dir == 0) v = new Vector(c.getConnections(node, 1).size() +
-                                       c.getConnections(node, -1).size());
-       else v = new Vector(c.getConnections(node, dir).size());
+    protected Collection getNodes(Cursor c, Resource node, int dir) {
+       Vector v = new Vector(c.getConnections(node, dir).size());
        
-       if (dir == 0) {
-           for(Iterator i=c.getConnections(node, 1).iterator(); i.hasNext();) {
-               Statement stmt = (Statement)i.next();
-               v.add(new Pair(stmt.getObject(), stmt.getPredicate()));
-           }
-           for(Iterator i=c.getConnections(node, -1).iterator(); i.hasNext();) 
{
-               Statement stmt = (Statement)i.next();
-               v.add(new Pair(stmt.getSubject(), stmt.getPredicate()));
-           }
-       } else {
-           for(Iterator i=c.getConnections(node, dir).iterator(); 
i.hasNext();) {
-               Statement stmt = (Statement)i.next();
-               RDFNode current = (dir<0) ? stmt.getSubject() : 
stmt.getObject();
-               v.add(new Pair(current, stmt.getPredicate()));
-           }
+       for(Iterator i=c.getConnections(node, dir).iterator(); i.hasNext();) {
+           Statement stmt = (Statement)i.next();
+           RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
+           Pair p = new Pair(current, stmt.getPredicate());
+           v.add(p);
        }
        
-       if (removal != null) {
-           for(Iterator i=removal.iterator(); i.hasNext();) {
-               Pair r = (Pair)i.next();
-               while(v.remove(r));
-           }
-       }
        return v;
     }
-    protected Collection getNodes(Cursor c, Resource node, int dir) {
-       return getNodes(c, node, dir, null);
-    }
     protected Collection getNodes(Cursor c, int dir) {
-       return getNodes(c, c.focus, dir, null);
+       return getNodes(c, c.focus, dir);
     }
 
     protected int getSubNodeCount(Cursor c, Collection nodes, int depth) {
@@ -260,7 +268,7 @@
                Collection subNodes = getNodes(c, (Resource)current, 0);
                nodeCount += subNodes.size();
                if (subNodes.size() > 0) nodeCount--;
-               if (depth > 1) nodeCount += getSubNodeCount(c, subNodes, 
depth-1);
+               if (depth < maxDepth) nodeCount += getSubNodeCount(c, subNodes, 
depth+1);
            }
        }
        return nodeCount;
@@ -282,11 +290,11 @@
        return s;
     }
 
-    private int x(double angle, float radius) {
+    protected int x(double angle, float radius) {
         return (int)(Math.cos(angle) * radius);
     }
 
-    private int y(double angle, float radius) {
+    protected int y(double angle, float radius) {
         return (int)(Math.sin(angle) * radius);
     }
 }




reply via email to

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