gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] loom/org/fenfire/loom Cursor.java Loom.java Loo...


From: Benja Fallenstein
Subject: [Gzz-commits] loom/org/fenfire/loom Cursor.java Loom.java Loo...
Date: Tue, 29 Apr 2003 14:07:15 -0400

CVSROOT:        /cvsroot/loom
Module name:    loom
Branch:         benja_2003-04-29_loommatcher_untested
Changes by:     Benja Fallenstein <address@hidden>      03/04/29 14:07:15

Modified files:
        org/fenfire/loom: Cursor.java Loom.java LoomBindings.java 
                          SimpleView.java ViewSettings.java 
                          WheelView.java 
Added files:
        org/fenfire/loom: LoomVobMatcher.java 

Log message:
        A crude, unittest-missing but WORKING connection-based matcher for loom

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/LoomVobMatcher.java?only_with_tag=benja_2003-04-29_loommatcher_untested&rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/Cursor.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.1&tr2=1.1.2.1&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/Loom.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.3&tr2=1.3.2.1&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/LoomBindings.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.2&tr2=1.2.2.1&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/SimpleView.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.1&tr2=1.1.2.1&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/ViewSettings.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.3&tr2=1.3.2.1&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/WheelView.java.diff?only_with_tag=benja_2003-04-29_loommatcher_untested&tr1=1.8&tr2=1.8.2.1&r1=text&r2=text

Patches:
Index: loom/org/fenfire/loom/Loom.java
diff -u loom/org/fenfire/loom/Loom.java:1.2 loom/org/fenfire/loom/Loom.java:1.3
--- loom/org/fenfire/loom/Loom.java:1.2 Sat Apr  5 16:09:51 2003
+++ loom/org/fenfire/loom/Loom.java     Sun Apr  6 19:21:04 2003
@@ -78,6 +78,9 @@
            if(_ instanceof RDFException) 
                _.printStackTrace();
            System.out.println("Exception while loading: "+_);
+           PrintWriter w = new PrintWriter(new 
FileWriter("fenfire.exception"));
+           _.printStackTrace(w);
+           w.close();
            return;
        }
 
Index: loom/org/fenfire/loom/LoomBindings.java
diff -u loom/org/fenfire/loom/LoomBindings.java:1.1 
loom/org/fenfire/loom/LoomBindings.java:1.2
--- loom/org/fenfire/loom/LoomBindings.java:1.1 Mon Mar 31 17:41:23 2003
+++ loom/org/fenfire/loom/LoomBindings.java     Sat Apr  5 16:09:51 2003
@@ -52,18 +52,26 @@
        if(s.equals("Ctrl-Q"))
            System.exit(0);
        if(loom.model == null) return;
+
+       if(s.equals("m")) {
+           Resource r = loom.cursor.focus;
+           if(!loom.markedNodes.contains(r))
+               loom.markedNodes.add(r);
+           else
+               loom.markedNodes.remove(r);
+       }
        
        if(loom.view.isWheelView()) {
            if(s.equals("i") || s.equals("Up") ||
               s.equals(",") || s.equals("Down")) return;
-           if(s.equals("m") || s.equals("n") || s.equals("o"))
+           if(s.equals("n") || s.equals("o"))
                s = "Up";
            else if(s.equals("u") || s.equals("."))
                s = "Down";
        } else if(loom.view.isSimpleView()) {
            if(s.equals("u") || s.equals("o"))
                s = "Up";
-           else if(s.equals("m") || s.equals("n") || s.equals("."))
+           else if(s.equals("n") || s.equals("."))
                s = "Down";
        }
        
Index: loom/org/fenfire/loom/ViewSettings.java
diff -u loom/org/fenfire/loom/ViewSettings.java:1.2 
loom/org/fenfire/loom/ViewSettings.java:1.3
--- loom/org/fenfire/loom/ViewSettings.java:1.2 Sun Apr  6 19:43:48 2003
+++ loom/org/fenfire/loom/ViewSettings.java     Sun Apr  6 21:07:21 2003
@@ -69,6 +69,6 @@
        return viewIndex == 1;
     }
     public boolean isWheelView() {
-       return viewIndex == 0;
+       return viewIndex == 0 || viewIndex == 2;
     }
 }
Index: loom/org/fenfire/loom/WheelView.java
diff -u loom/org/fenfire/loom/WheelView.java:1.8 
loom/org/fenfire/loom/WheelView.java:1.9
--- loom/org/fenfire/loom/WheelView.java:1.8    Wed Apr  9 10:44:52 2003
+++ loom/org/fenfire/loom/WheelView.java        Fri Apr 11 04:22:33 2003
@@ -48,17 +48,24 @@
     public static boolean dbg = false;
     private static void p(String s) { System.out.println(s); }
 
-    /** The view used to show the individual nodes.
-     */
+    /** The view used to show the individual nodes. */
     protected NodeView nodeView;
 
+    /** Connection and Stub vobs for both two directions. Actually
+     * only PinStub vob should be different for both directions. 
+     *
+     * The Length of PinStub vob is currently 1/3 of the distance
+     * between constructor parameter points after transformations.
+     */
     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 maxDepth How deeply should the structure be shown.
+     * @param nodeView The view used to show the individual nodes.
+     * @param maxDepth How deeply should the structure be shown. Equal
+     *                 or greater than zero.
      */
     public WheelView(NodeView nodeView, int maxDepth) {
        this.nodeView = nodeView;
@@ -66,27 +73,57 @@
     }
     public WheelView(NodeView nodeView) { this(nodeView, 1); }
 
-    /** XXX gapy has currently no effect, should be used
+    /** Dimensions 
+     * XXX gapy has currently no effect, should be used
      * to determine the minimum rotation angle.
      */
     protected int sizex = 150, sizey = 20;
     protected int gapx = 50, gapy = 30;
-
     protected int radius = sizex + gapx;
+
+    /** How deeply should the structure be shown. */
     protected int maxDepth;
 
     /** Maximum rotation angle. */
     protected double maxrota = Math.PI / 9;
 
     /** 
-     *  Render either posward or negward connections
-     *  (or onward, maybe).
+     *  Render either posward or negward connections (or onward, maybe).
+     *
+     * @param sc VobScene to draw the view into.
+     * @param into The parent coordinate system transformation to use.
+     * @param focusCs The CS transformation used to place the focuced
+     *                node of the previous drawing depth.
+     * @param c The main cursor, set to the globally focused node of the view.
+     * @param focus Pair containing the focused cell of current drawing
+     *              depth and property, which connects its to the previously
+     *              locally focused node.
+     * @param oldFocus Pair containing the focused node of the previous
+     *                 drawing depth and property, which connects its to the 
+     *                 currently locally focused node.
+     * @param nodes Collection, which contains pairs of all the nodes and their
+     *              properties to be drawn on this depth. One exception: 
drawing
+     *              of the oldFocus pair is skipped and an empty place is left
+     *              instead.
+     * @param before How many nodes should be drawn before the selected one.
+     * @param dir Is the current collection of nodes located to either positive
+     *            or negative direction from the focused node.
+     * @param starta The angle between focused node and the selected node
+     *               of current nodes collection.
+     * @param rota The rotation angle between drawn nodes in curren collection.
+     * @param r The radius of drawn nodes from the coordinate (midx, midy).
+     * @param midx The x coordinate of the center of the wheel.
+     * @param midy The y coordinate of the center of the wheel.
+     * @param depth The Current drawing depth. Depth is increased by one, when
+     *              proceeding deeper. When maxDepth is achieved, stubs are
+     *              drawn instead of nodes in the current collection.
      */
     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) {
+       /** The most important parameters as debug information. */
        if (dbg && nodes.size() > 0) {
            if (dir > 0)
                p("POS Render, nodes: "+nodes.size()
@@ -98,10 +135,13 @@
                  +", position: "+before);          
        }
 
+       /** The angle of the first drawn node. */
        double cura = starta - (before * rota);
+
        for(Iterator i=nodes.iterator(); i.hasNext();) {
            Pair current = (Pair)i.next();
 
+           /** Pair oldFocus is skipped. */
            if (!current.equals(oldFocus)) {
                NodeView.Nodespec spec = 
                    new NodeView.Nodespec((RDFNode)current.first,
@@ -112,6 +152,7 @@
                int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before),
                                        x, y, 1, 1, sizex, sizey);
        
+               /** If maxDepth is achieved, only stubs are being drawn. */
                if (depth == maxDepth) {
                    Vob stub;
                    if(dir > 0) stub = posStub;
@@ -126,104 +167,187 @@
                    else conn = negConn;
                    sc.map.put(conn, focusCs, cs2);
                    
+                   /** A lot of parameter is passed to renderDepth function, 
which
+                    * determines how the next depth should be drawn.
+                    */
                    renderDepth(sc, into, cs2, c, current, focus,
                                dir, cura, rota, r, midx, midy, depth+1);
                }
            }
+           /** Current angle is increased by rotating angle after drawing of
+            * every single vob. Also the amount of nodes preceding the selected
+            * one is reduced by one.
+            */
            cura+=rota;
            before--;
-       }
+       } 
     }
 
+    /** 
+     * Determines how the next depth should be drawn and finally calls
+     * renderSomewardConnections. This is the most usual function to 
+     * be overwritten in other WheelViews.
+     *
+     * @param sc VobScene to draw the view into.
+     * @param into The parent coordinate system transformation to use.
+     * @param focusCs The CS transformation used to place the focuced
+     *                node of the previous drawing depth.
+     * @param c The main cursor, set to the globally focused node of the view.
+     * @param focus Pair containing the focused cell of current drawing
+     *              depth and property, which connects its to the previously
+     *              locally focused node.
+     * @param oldFocus Pair containing the focused node of the previous
+     *                 drawing depth and property, which connects its to the 
+     *                 currently locally focused node.
+     * @param dir Is the current collection of nodes located to either positive
+     *            or negative direction from the focused node.
+     * @param starta The angle between focused node and the selected node
+     *               of curren nodes collection.
+     * @param rota The rotation angle between drawn nodes in curren collection.
+     * @param r The radius of drawn nodes from the coordinate (midx, midy).
+     * @param midx The x coordinate of the center of the wheel.
+     * @param midy The y coordinate of the center of the wheel.
+     * @param depth The Current drawing depth. Depth is increased by one, when
+     *              proceeding deeper.
+     */
     protected void renderDepth(VobScene sc, int into, int focusCs,
                               Cursor c, Pair focus, Pair oldFocus,
-                              int dir, double cura, double rota,
+                              int dir, double starta, double rota,
                               float r, int midx, int midy, int depth) {
+       /** Only resources could have "children". */
        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);
-           }    
+           /** Collects the nodes for both directions, because in the
+            * wheel all nodes on the same level affects the rotation.
+            */
+           Collection posNodes = getNodes(c, (Resource)focus.first, 1);
+           Collection 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);
-
+           /** Calculate rotations for single directions. */
+           double posRota = getRotationAngle(c, posNodes, Math.PI, depth);
+           double negRota = getRotationAngle(c, negNodes, Math.PI, depth);
+           /** Selects the lesser rotation angle to avoid overlapping. */
            double newRota = (posRota < negRota) ? posRota : negRota;
+
+           /** Though, getRotationAngle may return -1 if there is no nodes
+            * at the given direction.
+            */
            if (posRota < 0) newRota = negRota;
            else if (negRota < 0) newRota = posRota;
            
-           int x = midx+x(cura, r);
-           int y = midy+y(cura, r);
-
+           /** Initilize cursor for the current locally focused node with
+            * the right selected node.
+            */
            Cursor curPosition = new Cursor(c.getSubjectOrder(), 
c.getObjectOrder(),
                                            c.getStatementSelector(), c.names,
                                            (Resource)focus.first, dir*-1,
                                            (RDFNode)oldFocus.first);
+           /** After the new cursor is initilized, the selected nodes (given as
+            * before to the drawing function) could be fetched correctly.
+            */
            int posPosition = curPosition.getRotationIndex(1);
            int negPosition = curPosition.getRotationIndex(-1);
            
+           /** Stubs are drawn from the center of the locally focused node. */
+           int x = midx+x(starta, r);
+           int y = midy+y(starta, r);
+
+           /** Finally calls renderSomewardConnection. The proceeding direction
+            * will be drawn from the global origo (globally focused node). 
+            * To the other direction only stubs will be drawn from the local
+            * origo (locally focused node).
+            */
            if (dir > 0) {
                renderSomewardConnections(sc, into, focusCs, c, focus, null,
-                                         posNodes, posPosition, 1, cura, 
newRota,
-                                         r+gapx+sizex, midx, midy,  depth);
+                                         posNodes, posPosition, 1, starta, 
newRota,
+                                         r+gapx+sizex, midx, midy, depth);
                renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
-                                         negNodes, negPosition, -1, 
Math.PI+cura, newRota,
+                                         negNodes, negPosition, -1, 
Math.PI+starta, newRota,
                                          gapx+sizex, x, y,  maxDepth);
            } else {
                renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus,
-                                          posNodes, posPosition, 1, 
Math.PI+cura, newRota,
+                                          posNodes, posPosition, 1, 
Math.PI+starta, newRota,
                                           gapx+sizex, x, y,  maxDepth);
                renderSomewardConnections(sc, into, focusCs, c, focus, null,
-                                         negNodes, negPosition, -1, cura, 
newRota,
+                                         negNodes, negPosition, -1, starta, 
newRota,
                                          r+gapx+sizex, midx, midy, depth);
            }
        }
     }
     
+    /** View render function
+     * @param sc VobScene to draw the view into.
+     * @param into The parent coordinate system transformation to use.
+     * @param c The main cursor, set to the globally focused node of the view.
+     */
     public void render(VobScene sc, int into, Cursor c) {
        if (dbg) 
p("*******************************************************************");       
   
+       /** The global origo is at the center. */
        int midx = sc.size.width/2, midy = sc.size.height/2;
+
+       /** At first draws the globally focused node. */
        NodeView.Nodespec spec = new NodeView.Nodespec(c.focus);
        int cs = sc.orthoBoxCS(into, spec, 0, midx-sizex/2, midy-sizey/2, 
                               1, 1, sizex, sizey);
        sc.coords.activate(cs);
        nodeView.render(sc, cs, spec);
 
+       /** Collects the nodes for both directions, because in the
+        * wheel all nodes on the same level affects the rotation.
+        */
        Collection posNodes = getNodes(c, 1);
        Collection negNodes = getNodes(c, -1);
+
+       /** Calculate rotations for single directions. */
        double posRota = getRotationAngle(c, posNodes, Math.PI, 0);
        double negRota = getRotationAngle(c, negNodes, Math.PI, 0);
 
+       /** Selects the lesser rotation angle to avoid overlapping. */
        double rota = (posRota < negRota) ? posRota : negRota;
+
+       /** Though, getRotationAngle may return -1 if there are no nodes
+        * at the given direction.
+        */
        if (posRota < 0) rota = negRota;
        else if (negRota < 0) rota = posRota;
        
-       /** Poswards connections */
+       /** Call renderSomewardConnections to poswards connections */
        renderSomewardConnections(sc, into, cs, c, new Pair(c.focus, null), 
null, 
                                  posNodes, c.getRotationIndex(1),
                                  1, 0, rota, radius, midx, midy, 0);
 
-       /** Negward connections */
+       /** Call renderSomewardConnections to negwards connections */
        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,
+    /** Calculates rotation angle for a collection of nodes.
+     * @param c The main cursor, set to the globally focused node of the view.
+     * @param nodes Collection, which contains pairs of all the nodes and their
+     *              properties to be drawn on this depth.
+     * @param angle The angle of space available for all the nodes in current 
collection.
+     * @param depth The Current drawing depth. Depth is increased by one, when
+     *              proceeding deeper.
+     * @return Returns the proposed rotation angle, or -1 if amount of nodes in
+     *         the given collection is zero.
+     */
+    protected double getRotationAngle(Cursor c, Collection nodes,
                                      double angle, int depth) {
+       /** The rotation angle to return. */
        double rota;
+
+       /** Depth should be greater than zero, but lesser than maxDepth. */
        if (depth > maxDepth || depth < 0)
            throw new Error("Depth greater than maxDepth or lesser than zero.");
+
+       /** If depth is maxDepth, counting angle is simple, only divide the
+        * angle by the amount of nodes and check wheter that is greater than 
+        * set maximum rotation angle.
+        */
        if (depth == maxDepth) {
+           /** If amount of nodes is zero, return -1 */
            if (nodes.size() == 0) return -1;
            rota = angle / nodes.size();
            /** Rotation angle should be no bigger than defined maximum. */
@@ -231,27 +355,55 @@
            return rota;
        }
 
+       /** If depth is lesser than maxDepth, all the subnodes should be
+        * taken into account when counting the rotation angle.
+        */
        int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth+1); 
+       /** If amount of nodes is zero, return -1 */
        if (nodeCount == 0) return -1;
+       /** Rotation angle is angle divided by the sum of all subnodes, but
+        * it may not be greater than set maximum rotation angle. 
+        */
        if ((angle / nodeCount) >= maxrota) 
            angle = nodeCount * maxrota;
        rota = angle / nodes.size();
 
        return rota;
     }
-    protected double getRotationAngle(Cursor c, Collection nodes, 
-                                     double angle, int depth) {
-       return getRotationAngle(c, c.focus, nodes, angle, depth);
-    }
 
+    /** Get pairs of nodes and their properties in given direction
+     * @param c The main cursor, set to the globally focused node of the view.
+     * @param node The resource reprecenting the focused node.
+     * @param dir The direction from the given node to fetch connected nodes.
+     *            Zero is interpreted as the both directions.
+     * @return Returns a collection of all the nodes from the given
+     *         node in the given direction.
+     */
     protected Collection getNodes(Cursor c, Resource node, int dir) {
-       Vector v = new Vector(c.getConnections(node, dir).size());
+       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());
        
-       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);
+       /** Iterates through all the connections from the given node in the
+        * given direction and cretates a vector of (node, property) pairs 
+        * of them.
+        */
+       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()));
+           }
        }
        
        return v;
@@ -260,6 +412,15 @@
        return getNodes(c, c.focus, dir);
     }
 
+    /** Recursive function to calculate all the subconnections
+     * in some direction.
+     * @param c The main cursor, set to the globally focused node of the view.
+     * @param nodes Collection, which contains pairs of all the nodes and their
+     *              properties to be drawn on this depth.
+     * @param depth The Current drawing depth. Depth is increased by one, when
+     *              proceeding deeper.
+     * @return Returns the total amount of subnodes.
+     */
     protected int getSubNodeCount(Cursor c, Collection nodes, int depth) {
        int nodeCount = 0;
        for(Iterator i=nodes.iterator(); i.hasNext();) {
@@ -274,26 +435,12 @@
        return nodeCount;
     }
     
-    protected int getConnectionCount(Cursor c, Resource node) {
-       int posn = c.getConnections(node, 1).size();
-       int negn = c.getConnections(node, -1).size();
-
-       return (negn>posn) ? negn : posn;
-    }
-    protected int getConnectionCount(Cursor c) { return getConnectionCount(c, 
c.focus);  }
-    
-    private String dArrayToString(double[] a) {
-       if (dbg) p("dArrayToString, length: " + a.length);
-       String s = "";
-       for (int i=0; i<a.length; i++)
-           s += "" + a[i] + " ";
-       return s;
-    }
-
+    /** Calculates x from the origo. */
     protected int x(double angle, float radius) {
         return (int)(Math.cos(angle) * radius);
     }
 
+    /** Calculates y from the origo. */
     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]