00001 package org.hfbk.vis.visnode;
00002
00003 import java.awt.AWTEvent;
00004 import java.awt.event.MouseEvent;
00005 import java.util.HashMap;
00006 import java.util.List;
00007
00008 import org.dronus.gl.Buffers;
00009 import org.dronus.gl.GLFont;
00010 import org.dronus.gl.GLSphereRenderer;
00011 import org.dronus.gl.GLTextPanel;
00012 import org.dronus.gl.GLUtil;
00013 import org.dronus.graph.Edge;
00014 import org.dronus.graph.Graph;
00015 import org.dronus.graph.Node;
00016 import org.hfbk.vis.Prefs;
00017 import org.hfbk.vis.source.Source;
00018 import org.lwjgl.opengl.GL11;
00019 import org.lwjgl.util.vector.Vector3f;
00020
00029 public class VisLog extends VisPartitionNode implements VisUI{
00030
00031 Source source;
00032
00033 HashMap<String, Graph> incoming=new HashMap<String, Graph>();
00034
00035
00036 long lastupdate=0;
00037
00038
00039 float z=0, ox=0;
00040 long maxtime=0;
00041
00042
00047 class LogPoint extends VisNodeMousable implements VisUI{
00048
00049 String msg, timestamp;
00050 int ourDL;
00051 GLTextPanel helpText;
00052
00053 LogPoint(String timestamp, String user, String msg, Vector3f position) {
00054 super(null, position);
00055 this.timestamp=timestamp;
00056 this.msg=msg;
00057 radius=w=h=3;
00058
00059
00060
00061
00062
00063 GLSphereRenderer.renderSphere(0);
00064
00065 ourDL=GL11.glGenLists(1);
00066
00067 GL11.glNewList(ourDL, GL11.GL_COMPILE);
00068
00069 int c=user.hashCode();
00070 GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, Buffers.f4(
00071 (inject01(c/23.0)),
00072 (inject01(c/3645.0)),
00073 (1f-inject01(c/23.0))
00074 ,1));
00075 GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 10);
00076 GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, Buffers.f4(
00077 (inject01(c/3.5)),
00078 (inject01(c/5645.2)),
00079 (inject01(c/2818678.7))
00080 ,1));
00081 GLSphereRenderer.renderSphere(w/2);
00082 GL11.glColor3f(1,1,1);
00083 GL11.glEndList();
00084
00085 String[] args=msg.substring(1,msg.length()-1).split(", ");
00086 helpText=new GLTextPanel(args[2]+"\n"+args[3]+"\nby "+user,0,0);
00087
00088 }
00089
00090
00091 float inject01(double x){
00092 double f=Math.abs(x);
00093 return (float)(f-Math.floor(f));
00094 }
00095
00096
00101 void handleEvent(VisMouseEvent evt) {
00102 if (evt.getID()!=MouseEvent.MOUSE_RELEASED) return;
00103 fetch();
00104 }
00105
00106 void fetch(){
00107 if (Prefs.current.verbose) System.out.println(msg);
00108
00109 String[] args=msg.substring(1,msg.length()-1).split(", ");
00110
00111 if (!(args[0].equals("top") && args[1].equals("get")))
00112 throw new RuntimeException("VisLog: Illegal log message:"+msg);
00113
00114 getRoot().fetch(args[2], args[3], this);
00115 }
00116
00120 void renderSelf() {
00121 if (isHoovered) {
00122 GL11.glDisable(GL11.GL_LIGHTING);
00123 GL11.glColor3f(1,1,1);
00124 }
00125 GL11.glCallList(ourDL);
00126 if (isHoovered) {
00127 GL11.glTranslatef(0,10,0);
00128 GLUtil.billboardCylinder();
00129 GL11.glScalef(2,4,1);
00130 GLFont.getDefault().render();
00131 helpText.render();
00132 GL11.glEnable(GL11.GL_LIGHTING);
00133 GL11.glDisable(GL11.GL_TEXTURE_2D);
00134 }
00135 }
00136
00137
00143 public void add(VisNode node) {
00144 VisRoot root=getRoot();
00145 node.position=this.traverse(root, node.position);
00146 root.add(node);
00147 }
00148
00149 public String toString() {
00150 return "LogPoint: "+msg+" @ "+timestamp;
00151 }
00152 }
00153
00154 VisLog(){
00155 super(new Vector3f());
00156 }
00157
00163 void addIncoming(Node logRoot){
00164
00165 boolean firstFetch=(maxtime==0);
00166
00167 float scale=10000;
00168
00169 for (Edge e: logRoot.getEdges()){
00170 Node nts=e.getFrom();
00171 Node nmsg=null, nuser=null;
00172
00173
00174 for(Node n: nts.getFromNodes())
00175 if(n.type.equals("message"))
00176 nmsg=n;
00177 else if(n.type.equals("user"))
00178 nuser=n;
00179 if (nmsg==null)
00180 throw new RuntimeException("LogPoint: bad log entry.");
00181
00182
00183 long timestamp=Long.parseLong(nts.text);
00184 float x=-timestamp/scale;
00185 if (timestamp>maxtime)
00186 maxtime=timestamp;
00187
00188 z+=4;
00189 if (x<ox-20){
00190 z=0;
00191 ox=x;
00192 }
00193
00194 LogPoint l=new LogPoint(nts.text, nuser.text, nmsg.text, new Vector3f(x,0,z));
00195 add(l);
00196
00197 if(!firstFetch && Math.random()*100<Prefs.current.automate) l.fetch();
00198
00199 }
00200
00201 position.x=maxtime/scale;
00202 }
00203
00209 void fetch (long time){
00210 source=Source.getSource(Prefs.current.baseURL+"graph.php?action=getgraph&source=log&count="+Prefs.current.logCount+"&start="+maxtime);
00211 }
00212
00213 public void render(List<AWTEvent> events){
00214 if (Prefs.current.logCount<=0) return;
00215
00216 GL11.glDisable(GL11.GL_TEXTURE_2D);
00217 GL11.glEnable(GL11.GL_LIGHTING);
00218 super.render(events);
00219 GL11.glDisable(GL11.GL_LIGHTING);
00220 }
00221
00222
00226 void renderSelf() {
00227 super.renderSelf();
00228
00229 if (source!=null && source.finished){
00230 addIncoming(source.graph.getRoot());
00231 source=null;
00232 }
00233
00234
00235 long time=System.currentTimeMillis();
00236 if (lastupdate+Prefs.current.logUpdate<System.currentTimeMillis()){
00237 fetch(time);
00238 lastupdate=time;
00239 }
00240 }
00241 }
00242
00243