[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] loom/org/fenfire/loom WheelView.java
From: |
Asko Soukka |
Subject: |
[Gzz-commits] loom/org/fenfire/loom WheelView.java |
Date: |
Fri, 04 Apr 2003 07:02:01 -0500 |
CVSROOT: /cvsroot/loom
Module name: loom
Changes by: Asko Soukka <address@hidden> 03/04/04 07:02:01
Modified files:
org/fenfire/loom: WheelView.java
Log message:
Probably a better direction now, many variations possible (probably the
default not best), what do we want? need that rotable stub vob also, commenting
later :)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/WheelView.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
Patches:
Index: loom/org/fenfire/loom/WheelView.java
diff -u loom/org/fenfire/loom/WheelView.java:1.3
loom/org/fenfire/loom/WheelView.java:1.4
--- loom/org/fenfire/loom/WheelView.java:1.3 Thu Apr 3 04:16:34 2003
+++ loom/org/fenfire/loom/WheelView.java Fri Apr 4 07:02:01 2003
@@ -30,6 +30,7 @@
import java.lang.Math;
import java.util.*;
+import org.fenfire.util.Pair;
import com.hp.hpl.mesa.rdf.jena.model.*;
/** A simple wheel view.
@@ -64,7 +65,7 @@
protected int gapx = 50, gapy = 30;
protected int radius = sizex + gapx;
- protected int recursionDepth = 0;
+ protected int depth = 1;
/** Maximum rotation angle. */
protected double maxrota = Math.PI / 9;
@@ -73,19 +74,21 @@
* Render either posward or negward connections
* (or onward, maybe).
*/
- /*
- public void renderSomewardConnections(VobScene sc, int into, Cursor c,
- Resource node, int before,
- int dir, double rota, float r,
+ 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) {
- double cura = -(before * rota);
- if(dir < 0) cura += Math.PI;
- for(Iterator j=c.getConnections(node, dir).iterator(); j.hasNext();) {
- Statement stmt = (Statement)j.next();
+ 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(stmt, dir);
+ 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),
@@ -98,70 +101,32 @@
else
sc.map.put(conn, cs2, focusCs);
- cura+=rota;
- before--;
- }
- }
- */
-
- /**
- * Render either posward or negward connections
- * (or onward, maybe).
- * @param recursion Recursions steps left. Giving zero will cause
- * no recursion at all.
- * @param dir -1 for negative, 1 for positive, 0 for both
- */
- public void renderSomewardConnections(VobScene sc, int into, Cursor c,
- Resource node, int dir, double cura,
- double [] rotas, float r, int
focusCs,
- int midx, int midy, int depth, int
recursion) {
- if (dbg) p("Render, cura: "+cura+", r: "+r+", recursion: "+recursion);
- int connCount = 0;
-
- SortedSet connSet;
- if (dir == 0) {
- connSet = c.getConnections(node, -1);
- connSet.addAll(c.getConnections(node, 1));
- } else connSet = c.getConnections(node, dir);
-
- for(Iterator j=connSet.iterator(); j.hasNext();) {
- if (dbg) p("Render, cura: "+cura+", connCount: "+connCount);
-
- Statement stmt = (Statement)j.next();
- RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
-
- NodeView.Nodespec spec =
- new NodeView.Nodespec(stmt, 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(depth),
- 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 if (dir < 0)
- sc.map.put(conn, cs2, focusCs);
-
- if (recursion > 0 && current != null && current instanceof
Resource) {
- double suba;
- suba = rotas[connCount];
- double[] subas = getRotationAngles(c, (Resource)current, suba,
0,
- recursion - 1);
- renderSomewardConnections(sc, into, c, (Resource)current,
- 0, cura-(rotas[connCount]/2), subas,
- r + gapx + sizex,
- cs2, midx, midy, depth, recursion -
1);
+ if (depth > 1) {
+ 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);
+
+ // Hmm... that 0 could be replaced with dir and then the
+ // other direction should be replaced with stubs
+ Collection subNodes = getNodes(c, (Resource)newFocus, 0,
removal);
+ 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, cs2, depth-1, midx,
midy);
+ }
}
- cura+=rotas[connCount];
- connCount++;
- depth--;
+ cura+=rota;
+ before--;
}
}
public void render(VobScene sc, int into, Cursor c) {
+ if (dbg)
p("*******************************************************************");
int midx = sc.size.width/2, midy = sc.size.height/2;
NodeView.Nodespec spec = new NodeView.Nodespec(c.focus);
int cs = sc.orthoBoxCS(into, spec, 0, midx-sizex/2, midy-sizey/2,
@@ -172,186 +137,125 @@
/** Radius = gapx * sizex */
int r = gapx + sizex;
- int negConnCount = c.getConnections(-1).size();
- int posConnCount = c.getConnections(1).size();
- int negRotIndex = c.getRotationIndex(-1);
- int posRotIndex = c.getRotationIndex(1);
- double[] negRotAngles = getRotationAngles(c, c.focus, Math.PI, -1,
- recursionDepth);
- double[] posRotAngles = getRotationAngles(c, c.focus, Math.PI, 1,
- recursionDepth);
-
- /** Negwards connections */
- double cura = Math.PI;
- if (negRotAngles != null) {
- if (negRotIndex < 0)
- for (int i = posConnCount+negRotIndex; i < posConnCount; i++)
- cura += posRotAngles[i];
- else {
- if (negRotIndex > negConnCount)
- for (int i = negRotIndex-negConnCount-1; i >= 0; i--)
- cura -= posRotAngles[i];
- for (int i = 0; i < negRotIndex && i < negConnCount; i++)
- cura -= negRotAngles[i];
- }
- if (dbg) p("Negwards, cura: "+cura+", rotationIndex: "+negRotIndex);
- renderSomewardConnections(sc, into, c, c.focus,
- -1, cura, negRotAngles, r,
- cs, midx, midy, negRotIndex,
- recursionDepth);
- }
-
- /** Poswards connections */
- cura = 0;
- if (posRotAngles != null) {
- if (posRotIndex < 0)
- for (int i = negConnCount+posRotIndex; i < negConnCount; i++)
- cura += negRotAngles[i];
- else {
- if (posRotIndex > posConnCount)
- for (int i = posRotIndex-posConnCount-1; i >= 0; i--)
- cura -= negRotAngles[i];
- for (int i = 0; i < posRotIndex && i < posConnCount; i++)
- cura -= posRotAngles[i];
- }
- if (dbg) p("Poswards, cura: "+cura+", rotationIndex: "+posRotIndex);
- renderSomewardConnections(sc, into, c, c.focus,
- 1, cura, posRotAngles, r,
- cs, midx, midy, posRotIndex,
- recursionDepth);
- }
+ 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 rota = (posRota < negRota) ? posRota : negRota;
+ if (posRota < 0) rota = negRota;
+ else if (negRota < 0) rota = posRota;
- // int totpos = c.getConnections(1).size();
- // int totneg = c.getConnections(-1).size();
-
- /** Rotation angle */
- // double rota = (Math.PI) / c.getConnectionCount();
-
- /** Rotation angle should be no bigger than defined maximum. */
- // if (rota > maxrota) rota = maxrota;
-
-
+ if (dbg) p("Render, posNodes: "+posNodes.size()+
+ ", posRota: "+posRota+", rota: "+rota);
/** Poswards connections */
- // renderSomewardConnections(sc, into, c, c.focus,
- // c.getRotationIndex(1), 1,
- // rota, r, cs, 1, midx, midy);
+ renderSomewardConnections(sc, into, c, c.focus, posNodes,
+ c.getRotationIndex(1), 1, 0,
+ rota, r, cs, depth, midx, midy);
+ if (dbg) p("Render, negNodes: "+negNodes.size()+
+ ", negRota: "+negRota+", rota: "+rota);
/** Negward connections */
- // renderSomewardConnections(sc, into, c, c.focus,
- // c.getRotationIndex(-1), -1,
- // rota, r, cs, 1, midx, midy);
+ renderSomewardConnections(sc, into, c, c.focus, negNodes,
+ c.getRotationIndex(-1), -1, Math.PI,
+ rota, r, cs, depth, midx, midy);
}
- /**
- * @param recursion Recursions steps left. Giving zero will cause
- * no recursion at all.
- * @param dir -1 for negative, 1 for positive, 0 for both
- */
- protected double[] getRotationAngles(Cursor c, Resource node,
- double angle, int dir,
- int recursion) {
- if (dbg) p("getRotationAngles, angle: "+angle+", dir: "+dir+",
recursion: "+recursion);
-
- int conns = 0;
- if (dir == 0) {
- conns = c.getConnections(node, -1).size() +
- c.getConnections(node, 1).size();
- } else conns = c.getConnections(node, dir).size();
-
- if (dbg) p("getRotationAngles, conns: "+conns);
- if (conns == 0) return null;
-
- double[] angles = new double[conns];
-
-
- if (recursion == 0) {
- double rota = angle / conns;
- if (dbg) p("getRotationAngle, no recursion, rota: "+rota);
- double shift = 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 (nodes.size() == 0) return -1;
+ rota = angle / nodes.size();
+ /** Rotation angle should be no bigger than defined maximum. */
if (rota > maxrota) rota = maxrota;
- for (int i = 0; i < conns; i++) angles[i] = rota;
- if (dbg) p("getRotationAngle, no recursion, angles:
"+dArrayToString(angles));
- return angles;
- }
-
- int connCount = 0;
- int totalsubconns = 0;
- int[] subconns = new int[conns];
-
- SortedSet connSet;
+ if (dbg) p("Angle, first: "+angle / nodes.size()+
+ ", returned: "+rota);
+ return rota;
+ }
+
+ 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,
+ double angle, int depth) {
+ 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());
+
if (dir == 0) {
- connSet = c.getConnections(node, -1);
- connSet.addAll(c.getConnections(node, 1));
- } else connSet = c.getConnections(node, dir);
-
- for(Iterator j=connSet.iterator(); j.hasNext();) {
- Statement stmt = (Statement)j.next();
- RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
- if(current != null && current instanceof Resource) {
- subconns[connCount] = getConnectionCount(c, (Resource)current,
- 0, recursion - 1);
- totalsubconns += subconns[connCount];
- if (subconns[connCount] == 0) {
- subconns[connCount] = 1;
- totalsubconns ++;
- }
- } else {
- subconns[connCount] = 1;
- totalsubconns++;
+ 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()));
}
- connCount++;
}
- if (dbg) p("getRotationAngles, totalsubconns: "+totalsubconns);
-
- if ((angle / totalsubconns) >= maxrota)
- angle = totalsubconns * maxrota;
- for (int i = 0; i < conns; i++)
- angles[i] = angle / conns;
- /** Variable angles just didnt work */
- //angles[i] = angle * ((double)subconns[i] / (double)totalsubconns);
- if (dbg) p("getRotationAngle, angles: "+dArrayToString(angles));
-
- return angles;
+ 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);
}
- protected int getConnectionCount(Cursor c, Resource node,
- int dir, int recursion) {
- if (dbg) p("getConnectionCount, dir: "+dir+", recursion: "+recursion);
- int conns = 0;
- if (dir == 0) {
- conns = c.getConnections(node, -1).size() +
- c.getConnections(node, 1).size();
- } else conns = c.getConnections(node, dir).size();
-
- if (dbg) p("getConnectionCount, conns: "+conns);
-
- if (recursion == 0) return conns;
-
- int subconns = 0;
-
- SortedSet connSet;
- if (dir == 0) {
- connSet = c.getConnections(node, -1);
- connSet.addAll(c.getConnections(node, 1));
- } else connSet = c.getConnections(node, dir);
-
- for(Iterator j=connSet.iterator(); j.hasNext();) {
- Statement stmt = (Statement)j.next();
- RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
- if(current != null && current instanceof Resource)
- subconns += getConnectionCount(c, (Resource)current,
- dir, recursion - 1);
+ protected int getSubNodeCount(Cursor c, Collection nodes, int depth) {
+ int nodeCount = 0;
+ for(Iterator i=nodes.iterator(); i.hasNext();) {
+ RDFNode current = (RDFNode)((Pair)i.next()).first;
+ if (current != null && current instanceof Resource) {
+ 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 (dbg) p("getConnectionCount, subconns: "+subconns);
- return (conns<subconns) ? subconns : conns;
+ 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++)
+ for (int i=0; i<a.length; i++)
s += "" + a[i] + " ";
return s;
}