WheelView.java from gzz at Krugle
Show WheelView.java syntax highlighted
/*
WheelView.java
*
* Copyright (c) 2003 by Asko Soukka
*
* This file is part of Gzz.
*
* Gzz is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Gzz is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with Gzz; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
/*
* Written by Asko Soukka
*/
package gzz.loom;
import gzz.client.*;
import gzz.vob.*;
import gzz.vob.vobs.*;
import java.lang.Math;
import java.util.*;
import com.hp.hpl.mesa.rdf.jena.model.*;
/** A simple wheel view.
* Example:
* <pre>
* neg1 |
* neg2 \ / pos1
* neg3 - focus - pos2
* neg4 / \ pos3
* neg5 |
* </pre>
*/
public class WheelView implements View {
/** The view used to show the individual nodes.
*/
protected NodeView nodeView;
protected final Vob conn = new SimpleConnection(1,.5f,0,.5f);
public WheelView(NodeView nodeView) {
this.nodeView = nodeView;
}
/** XXX gapy has currently no effect, should be used
* to determine the minimum rotation angle
*/
protected int sizex = 250, sizey = 20;
protected int gapx = 50, gapy = 30;
public void render(VobScene sc, int into, Cursor c) {
int midx = sc.size.width/2, midy = sc.size.height/2;
int cs = sc.orthoBoxCS(into, c.focus, 0, midx-sizex/2, midy-sizey/2,
1, 1, sizex, sizey);
nodeView.render(sc, cs, c.focus, 0);
int totpos = c.getConnections(1).size();
int totneg = c.getConnections(-1).size();
/* Rotation angle = 2PI / 2(greater of totpos and totgen) */
double rota;
if (totpos < totneg) rota = 2 * totneg;
else rota = 2 * totpos;
rota = (2 * Math.PI) / rota;
/* Radius = gapx * sizex */
int r = gapx + sizex;
/* Poswards connections */
int before = c.getRotationIndex(1);
double cura = -(before * rota);
for(Iterator j=c.getConnections(1).iterator(); j.hasNext();) {
RDFNode node = (RDFNode)j.next();
int cs2 = sc.orthoBoxCS(into, node, Math.abs(before),
midx+x(cura, r)-sizex/2,
midy+y(cura, r)-sizey/2,
1, 1, sizex, sizey);
nodeView.render(sc, cs2, node, 1);
sc.map.put(conn, cs, cs2);
cura+=rota;
before--;
}
/* Negward connections */
before = c.getRotationIndex(-1);
cura = Math.PI-(before * rota);
for(Iterator j=c.getConnections(-1).iterator(); j.hasNext();) {
RDFNode node = (RDFNode)j.next();
int cs2 = sc.orthoBoxCS(into, node, Math.abs(before),
midx+x(cura, r)-sizex/2,
midy+y(cura, r)-sizey/2,
1, 1, sizex, sizey);
nodeView.render(sc, cs2, node, -1);
sc.map.put(conn, cs2, cs);
cura+=rota;
before--;
}
}
int x(double angle, int radius) {
return (int)(Math.cos(angle) * radius);
}
int y(double angle, float radius) {
return (int)(Math.sin(angle) * radius);
}
}
See more files for this project here