00001 package org.hfbk.vis.visnode;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileReader;
00006 import java.io.IOException;
00007 import java.text.SimpleDateFormat;
00008 import java.util.ArrayList;
00009 import java.util.Date;
00010 import java.util.Iterator;
00011
00012 import org.dronus.graph.Node;
00013 import org.lwjgl.util.vector.Vector3f;
00014
00015
00028 public class VisSrt extends VisNode {
00029
00030 int dl;
00031 boolean isevent=false;
00032 boolean isdescription=false;
00033 long lastupdate;
00034 int eventcount=0;
00035
00036 public class eventtype implements Comparable{
00037 Long BEGIN;
00038 Long END;
00039 String description;
00040 String[] words;
00041
00042 public eventtype() {
00043
00044 }
00045 public eventtype(Long BEGIN,Long END,String description) {
00046 this.BEGIN=BEGIN;
00047 this.END=END;
00048 this.description=description;
00049 }
00050 public eventtype(Long BEGIN,Long END,String[] words) {
00051 this.BEGIN=BEGIN;
00052 this.END=END;
00053 this.words=words;
00054 }
00055
00056 public int compareTo(Object other) {
00057 return (int)Math.signum(BEGIN-((eventtype)other).BEGIN);
00058 }
00059
00060 }
00061 ArrayList<eventtype> events=new ArrayList<eventtype>();
00062
00063
00064
00065 public VisSrt(Node n, Vector3f position) {
00066 super(n, new Vector3f(0,0,0));
00067 radius=2000;
00068 try {
00069 load(n.text);
00070 } catch (IOException e) {
00071 e.printStackTrace();
00072 }
00073
00074
00075 }
00076
00077
00084 void load(String filename) throws IOException{
00085
00086
00087
00088 BufferedReader r=new BufferedReader(new FileReader(new File(filename)));
00089
00090
00091 String line;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 Date st = new Date();
00106 Date et = new Date();
00107 long now;
00108
00109 String desc = new String();
00110 SimpleDateFormat df = new SimpleDateFormat( "HH:mm:ss,SSS" );
00111
00112 now=System.currentTimeMillis();
00113
00114
00115 System.out.println("parsing "+filename+", NOW is "+df.format(now));
00116
00117
00118
00119
00120 while ((line=r.readLine())!=null){
00121
00122 if (isevent)
00123 {if (desc.equals("")){desc=line;}
00124 else
00125 {desc+=" "+line;}
00126 }
00127
00128 if (line.contains("-->"))
00129 {
00130 isevent=true;eventcount++;
00131 String[] params=line.split(" --> ");
00132 String stamp=params[0];
00133 {try {st=df.parse( stamp );}
00134 catch(Exception e){throw new RuntimeException(e);}}
00135
00136 stamp=params[1];
00137 {try {et=df.parse( stamp );}
00138 catch(Exception e){throw new RuntimeException(e);}}
00139
00140
00141
00142
00143
00144
00145 }
00146
00147
00148 if (line.equals(""))
00149 {
00150 isevent=false;
00151
00152 desc.trim();
00153
00154
00155 events.add(new eventtype(st.getTime()+now+3600000,et.getTime()+now,desc));
00156 desc="";
00157 }
00158
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 }
00173
00174
00178 void renderSelf() {
00179
00180 Vector3f po=new Vector3f();
00181 SimpleDateFormat df = new SimpleDateFormat( "HH:mm:ss,SSS" );
00182
00183
00184 long time=System.currentTimeMillis();
00185 if (lastupdate+1000<System.currentTimeMillis())
00186 {
00187 lastupdate=time;
00188
00189 for(Iterator iter =events.iterator();iter.hasNext();){
00190 eventtype p = (eventtype)iter.next();
00191 if ((p.BEGIN/1000)==(time/1000)){
00192 System.out.println("SUB: "+df.format(new Date(p.BEGIN))+"-"+df.format(new Date(p.END))+": "+p.description);
00193
00194
00195 po.x=(float)Math.random()*100;
00196 po.y=(float)Math.random()*100;
00197 po.z=(float)Math.random()*-100;
00198
00199 add(new VisText(new Node(p.description), po));
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 System.out.println();
00213 }
00214
00215 }
00216
00217
00218 }
00219 }
00220
00221 }