45 |
*/ |
*/ |
46 |
public class WheelView implements View { |
public class WheelView implements View { |
47 |
|
|
48 |
public static boolean dbg = false; |
public static boolean dbg = true; |
49 |
private static void p(String s) { System.out.println(s); } |
private static void p(String s) { System.out.println(s); } |
50 |
|
|
51 |
/** The view used to show the individual nodes. |
/** The view used to show the individual nodes. |
52 |
*/ |
*/ |
53 |
protected NodeView nodeView; |
protected NodeView nodeView; |
54 |
|
|
55 |
protected final Vob conn = new SimpleConnection(1,.5f,0,.5f); |
protected final Vob posConn = new SimpleConnection(1,.5f,0,.5f); |
56 |
|
protected final Vob negConn = new SimpleConnection(0,.5f,1,.5f); |
57 |
|
protected final Vob posStub = new PinStub(1,.5f,0,.5f); |
58 |
|
protected final Vob negStub = new PinStub(0,.5f,1,.5f); |
59 |
|
|
60 |
/** WheelView |
/** WheelView |
61 |
* @param depth How deeply should the structure be shown. |
* @param maxDepth How deeply should the structure be shown. |
62 |
*/ |
*/ |
63 |
public WheelView(NodeView nodeView, int depth) { |
public WheelView(NodeView nodeView, int maxDepth) { |
64 |
this.nodeView = nodeView; |
this.nodeView = nodeView; |
65 |
this.depth = depth; |
this.maxDepth = maxDepth; |
66 |
} |
} |
67 |
public WheelView(NodeView nodeView) { this(nodeView, 2); } |
public WheelView(NodeView nodeView) { this(nodeView, 2); } |
68 |
|
|
73 |
protected int gapx = 50, gapy = 30; |
protected int gapx = 50, gapy = 30; |
74 |
|
|
75 |
protected int radius = sizex + gapx; |
protected int radius = sizex + gapx; |
76 |
protected int depth = 1; |
protected int maxDepth; |
77 |
|
|
78 |
/** Maximum rotation angle. */ |
/** Maximum rotation angle. */ |
79 |
protected double maxrota = Math.PI / 9; |
protected double maxrota = Math.PI / 9; |
82 |
* Render either posward or negward connections |
* Render either posward or negward connections |
83 |
* (or onward, maybe). |
* (or onward, maybe). |
84 |
*/ |
*/ |
85 |
public void renderSomewardConnections(VobScene sc, int into, Cursor c, Resource focus, |
public void renderSomewardConnections(VobScene sc, int into, int focusCs, |
86 |
Collection nodes, int before, int dir, |
Cursor c, Pair focus, Pair oldFocus, |
87 |
double starta, double rota, float r, |
Collection nodes, int before, |
88 |
int focusCs, int depth, |
int dir, double starta, double rota, |
89 |
int midx, int midy) { |
float r, int midx, int midy, int depth) { |
90 |
|
if (dbg) { |
91 |
|
if (dir > 0) |
92 |
|
p("POS Render, nodes: "+nodes.size() |
93 |
|
+", starta: "+starta+", rota: "+rota+", depth: "+depth |
94 |
|
+", position: "+before); |
95 |
|
else |
96 |
|
p("NEG Render, nodes: "+nodes.size() |
97 |
|
+", starta: "+starta+", rota: "+rota+", depth: "+depth |
98 |
|
+", position: "+before); |
99 |
|
} |
100 |
|
|
101 |
double cura = starta - (before * rota); |
double cura = starta - (before * rota); |
|
if (dbg) p("Render, nodes: "+nodes.size()+", starta: "+starta |
|
|
+", cura: "+cura+", depth: "+depth); |
|
102 |
for(Iterator i=nodes.iterator(); i.hasNext();) { |
for(Iterator i=nodes.iterator(); i.hasNext();) { |
103 |
Pair current = (Pair)i.next(); |
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); |
|
104 |
|
|
105 |
if (depth > 1) |
if (!current.equals(oldFocus)) { |
106 |
renderDepth(sc, into, c, focus, current, nodes, dir, |
NodeView.Nodespec spec = |
107 |
cura, rota, r, cs2, depth, midx, midy); |
new NodeView.Nodespec((RDFNode)current.first, |
108 |
|
(Property)current.second, |
109 |
|
dir); |
110 |
|
int x = midx+x(cura, r)-sizex/2; |
111 |
|
int y = midy+y(cura, r)-sizey/2; |
112 |
|
int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before), |
113 |
|
x, y, 1, 1, sizex, sizey); |
114 |
|
|
115 |
|
if (depth == maxDepth) { |
116 |
|
Vob stub; |
117 |
|
if(dir > 0) stub = posStub; |
118 |
|
else stub = negStub; |
119 |
|
sc.map.put(stub, focusCs, cs2); |
120 |
|
} else if (depth < maxDepth) { |
121 |
|
sc.coords.activate(cs2); |
122 |
|
nodeView.render(sc, cs2, spec); |
123 |
|
|
124 |
|
Vob conn; |
125 |
|
if(dir > 0) conn = posConn; |
126 |
|
else conn = negConn; |
127 |
|
sc.map.put(conn, focusCs, cs2); |
128 |
|
|
129 |
|
renderDepth(sc, into, cs2, c, current, focus, |
130 |
|
dir, cura, rota, r, midx, midy, depth+1); |
131 |
|
} |
132 |
|
} |
133 |
cura+=rota; |
cura+=rota; |
134 |
before--; |
before--; |
135 |
} |
} |
136 |
} |
} |
137 |
|
|
138 |
protected void renderDepth(VobScene sc, int into, Cursor c, Resource focus, |
protected void renderDepth(VobScene sc, int into, int focusCs, |
139 |
Pair current, Collection nodes, int dir, double cura, |
Cursor c, Pair focus, Pair oldFocus, |
140 |
double rota, float r, int focusCs, int depth, int midx, |
int dir, double cura, double rota, |
141 |
int midy) { |
float r, int midx, int midy, int depth) { |
142 |
RDFNode newFocus = (RDFNode)current.first; |
if (((RDFNode)focus.first) instanceof Resource) { |
143 |
if (newFocus != null && newFocus instanceof Resource) { |
oldFocus = new Pair(oldFocus.first, focus.second); |
|
|
|
|
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); |
|
144 |
|
|
145 |
/** This won't remove any nodes. */ |
Collection posNodes, negNodes; |
146 |
//Collection subNodes = getNodes(c, (Resource)newFocus, 0); |
|
147 |
|
if (dir > 0) { |
148 |
|
posNodes = getNodes(c, (Resource)focus.first, 1); |
149 |
|
negNodes = getNodes(c, (Resource)focus.first, -1); |
150 |
|
} else { |
151 |
|
posNodes = getNodes(c, (Resource)focus.first, 1); |
152 |
|
negNodes = getNodes(c, (Resource)focus.first, -1); |
153 |
|
} |
154 |
|
|
155 |
|
double posRota = getRotationAngle(c, (Resource)focus.first, posNodes, |
156 |
|
Math.PI, depth); |
157 |
|
double negRota = getRotationAngle(c, (Resource)focus.first, negNodes, |
158 |
|
Math.PI, depth); |
159 |
|
|
160 |
|
double newRota = (posRota < negRota) ? posRota : negRota; |
161 |
|
if (posRota < 0) newRota = negRota; |
162 |
|
else if (negRota < 0) newRota = posRota; |
163 |
|
|
164 |
/** This don't show the links of opposite direction at all in branches. |
int x = midx+x(cura, r); |
165 |
* This is the one, which would really work, if we would have rotable |
int y = midy+y(cura, r); |
166 |
* stubs to shown the hidden connections |
|
167 |
*/ |
Cursor curPosition = new Cursor(c.getSubjectOrder(), c.getObjectOrder(), |
168 |
//Collection subNodes = getNodes(c, (Resource)newFocus, dir); |
c.getStatementSelector(), c.names, |
169 |
|
(Resource)focus.first, dir*-1, |
170 |
|
(RDFNode)oldFocus.first); |
171 |
|
int posPosition = curPosition.getRotationIndex(1); |
172 |
|
int negPosition = curPosition.getRotationIndex(-1); |
173 |
|
|
174 |
double subRota = getRotationAngle(c, (Resource)newFocus, subNodes, |
if (dir > 0) { |
175 |
rota, depth-1); |
renderSomewardConnections(sc, into, focusCs, c, focus, null, |
176 |
renderSomewardConnections(sc, into, c, (Resource)newFocus, subNodes, |
posNodes, posPosition, 1, cura, newRota, |
177 |
subNodes.size()/2, dir, cura, subRota, |
r+gapx+sizex, midx, midy, depth); |
178 |
r+gapx+sizex, focusCs, depth-1, midx, midy); |
renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus, |
179 |
|
negNodes, negPosition, -1, Math.PI+cura, newRota, |
180 |
|
gapx+sizex, x, y, maxDepth); |
181 |
|
} else { |
182 |
|
renderSomewardConnections(sc, into, focusCs, c, focus, oldFocus, |
183 |
|
posNodes, posPosition, 1, Math.PI+cura, newRota, |
184 |
|
gapx+sizex, x, y, maxDepth); |
185 |
|
renderSomewardConnections(sc, into, focusCs, c, focus, null, |
186 |
|
negNodes, negPosition, -1, cura, newRota, |
187 |
|
r+gapx+sizex, midx, midy, depth); |
188 |
|
} |
189 |
} |
} |
190 |
} |
} |
191 |
|
|
192 |
public void render(VobScene sc, int into, Cursor c) { |
public void render(VobScene sc, int into, Cursor c) { |
193 |
if (dbg) p("*******************************************************************"); |
if (dbg) p("*******************************************************************"); |
194 |
int midx = sc.size.width/2, midy = sc.size.height/2; |
int midx = sc.size.width/2, midy = sc.size.height/2; |
200 |
|
|
201 |
Collection posNodes = getNodes(c, 1); |
Collection posNodes = getNodes(c, 1); |
202 |
Collection negNodes = getNodes(c, -1); |
Collection negNodes = getNodes(c, -1); |
203 |
double posRota = getRotationAngle(c, posNodes, Math.PI, depth); |
double posRota = getRotationAngle(c, posNodes, Math.PI, 0); |
204 |
double negRota = getRotationAngle(c, negNodes, Math.PI, depth); |
double negRota = getRotationAngle(c, negNodes, Math.PI, 0); |
205 |
|
|
206 |
double rota = (posRota < negRota) ? posRota : negRota; |
double rota = (posRota < negRota) ? posRota : negRota; |
207 |
if (posRota < 0) rota = negRota; |
if (posRota < 0) rota = negRota; |
208 |
else if (negRota < 0) rota = posRota; |
else if (negRota < 0) rota = posRota; |
209 |
|
|
|
if (dbg) p("Render, posNodes: "+posNodes.size()+ |
|
|
", posRota: "+posRota+", rota: "+rota); |
|
210 |
/** Poswards connections */ |
/** Poswards connections */ |
211 |
renderSomewardConnections(sc, into, c, c.focus, posNodes, |
renderSomewardConnections(sc, into, cs, c, new Pair(c.focus, null), null, |
212 |
c.getRotationIndex(1), 1, 0, |
posNodes, c.getRotationIndex(1), |
213 |
rota, radius, cs, depth, midx, midy); |
1, 0, rota, radius, midx, midy, 0); |
214 |
|
|
|
if (dbg) p("Render, negNodes: "+negNodes.size()+ |
|
|
", negRota: "+negRota+", rota: "+rota); |
|
215 |
/** Negward connections */ |
/** Negward connections */ |
216 |
renderSomewardConnections(sc, into, c, c.focus, negNodes, |
renderSomewardConnections(sc, into, cs, c, new Pair(c.focus, null), null, |
217 |
c.getRotationIndex(-1), -1, Math.PI, |
negNodes, c.getRotationIndex(-1), |
218 |
rota, radius, cs, depth, midx, midy); |
-1, Math.PI, rota, radius, midx, midy, 0); |
219 |
} |
} |
220 |
|
|
221 |
protected double getRotationAngle(Cursor c, Resource node, Collection nodes, |
protected double getRotationAngle(Cursor c, Resource node, Collection nodes, |
222 |
double angle, int depth) { |
double angle, int depth) { |
|
if (dbg) p("Angle, nodes: "+nodes.size()+ |
|
|
", angle: "+angle+", depth: "+depth); |
|
223 |
double rota; |
double rota; |
224 |
if (depth < 1) throw new Error("Depth is lesser than 1."); |
if (depth > maxDepth || depth < 0) |
225 |
if (depth == 1) { |
throw new Error("Depth greater than maxDepth or lesser than zero."); |
226 |
|
if (depth == maxDepth) { |
227 |
if (nodes.size() == 0) return -1; |
if (nodes.size() == 0) return -1; |
228 |
rota = angle / nodes.size(); |
rota = angle / nodes.size(); |
229 |
/** Rotation angle should be no bigger than defined maximum. */ |
/** Rotation angle should be no bigger than defined maximum. */ |
230 |
if (rota > maxrota) rota = maxrota; |
if (rota > maxrota) rota = maxrota; |
|
if (dbg) p("Angle, first: "+angle / nodes.size()+ |
|
|
", returned: "+rota); |
|
231 |
return rota; |
return rota; |
232 |
} |
} |
233 |
|
|
234 |
int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth-1); |
int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth+1); |
235 |
if (nodeCount == 0) return -1; |
if (nodeCount == 0) return -1; |
236 |
if ((angle / nodeCount) >= maxrota) |
if ((angle / nodeCount) >= maxrota) |
237 |
angle = nodeCount * maxrota; |
angle = nodeCount * maxrota; |
238 |
rota = angle / nodes.size(); |
rota = angle / nodes.size(); |
239 |
|
|
|
if (dbg) p("Angle, nodeCount: "+nodeCount+", returned: "+rota); |
|
240 |
return rota; |
return rota; |
241 |
} |
} |
242 |
protected double getRotationAngle(Cursor c, Collection nodes, |
protected double getRotationAngle(Cursor c, Collection nodes, |
244 |
return getRotationAngle(c, c.focus, nodes, angle, depth); |
return getRotationAngle(c, c.focus, nodes, angle, depth); |
245 |
} |
} |
246 |
|
|
247 |
protected Collection getNodes(Cursor c, Resource node, |
protected Collection getNodes(Cursor c, Resource node, int dir) { |
248 |
int dir, Collection removal) { |
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()); |
|
249 |
|
|
250 |
if (dir == 0) { |
for(Iterator i=c.getConnections(node, dir).iterator(); i.hasNext();) { |
251 |
for(Iterator i=c.getConnections(node, 1).iterator(); i.hasNext();) { |
Statement stmt = (Statement)i.next(); |
252 |
Statement stmt = (Statement)i.next(); |
RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject(); |
253 |
v.add(new Pair(stmt.getObject(), stmt.getPredicate())); |
Pair p = new Pair(current, stmt.getPredicate()); |
254 |
} |
v.add(p); |
|
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())); |
|
|
} |
|
255 |
} |
} |
256 |
|
|
|
if (removal != null) { |
|
|
for(Iterator i=removal.iterator(); i.hasNext();) { |
|
|
Pair r = (Pair)i.next(); |
|
|
while(v.remove(r)); |
|
|
} |
|
|
} |
|
257 |
return v; |
return v; |
258 |
} |
} |
|
protected Collection getNodes(Cursor c, Resource node, int dir) { |
|
|
return getNodes(c, node, dir, null); |
|
|
} |
|
259 |
protected Collection getNodes(Cursor c, int dir) { |
protected Collection getNodes(Cursor c, int dir) { |
260 |
return getNodes(c, c.focus, dir, null); |
return getNodes(c, c.focus, dir); |
261 |
} |
} |
262 |
|
|
263 |
protected int getSubNodeCount(Cursor c, Collection nodes, int depth) { |
protected int getSubNodeCount(Cursor c, Collection nodes, int depth) { |
268 |
Collection subNodes = getNodes(c, (Resource)current, 0); |
Collection subNodes = getNodes(c, (Resource)current, 0); |
269 |
nodeCount += subNodes.size(); |
nodeCount += subNodes.size(); |
270 |
if (subNodes.size() > 0) nodeCount--; |
if (subNodes.size() > 0) nodeCount--; |
271 |
if (depth > 1) nodeCount += getSubNodeCount(c, subNodes, depth-1); |
if (depth < maxDepth) nodeCount += getSubNodeCount(c, subNodes, depth+1); |
272 |
} |
} |
273 |
} |
} |
274 |
return nodeCount; |
return nodeCount; |
290 |
return s; |
return s; |
291 |
} |
} |
292 |
|
|
293 |
private int x(double angle, float radius) { |
protected int x(double angle, float radius) { |
294 |
return (int)(Math.cos(angle) * radius); |
return (int)(Math.cos(angle) * radius); |
295 |
} |
} |
296 |
|
|
297 |
private int y(double angle, float radius) { |
protected int y(double angle, float radius) { |
298 |
return (int)(Math.sin(angle) * radius); |
return (int)(Math.sin(angle) * radius); |
299 |
} |
} |
300 |
} |
} |