00001 package org.hfbk.vis.visnode;
00002
00003 import java.io.BufferedReader;
00004 import java.io.File;
00005 import java.io.FileInputStream;
00006 import java.io.IOException;
00007 import java.io.InputStreamReader;
00008 import java.nio.charset.Charset;
00009 import java.text.DateFormat;
00010 import java.text.SimpleDateFormat;
00011 import java.util.ArrayList;
00012 import java.util.Collections;
00013 import java.util.Date;
00014 import java.util.Iterator;
00015
00016 import org.dronus.graph.Node;
00017 import org.hfbk.vis.Prefs;
00018 import org.lwjgl.util.vector.Vector3f;
00019
00020
00032 public class VisIcal extends VisNode {
00033
00034 int dl;
00035 boolean isevent=false;
00036 boolean isdescription=false;
00037 long lastupdate;
00038 int eventcount=0;
00039
00040 public class eventtype implements Comparable{
00041 Long BEGIN;
00042 Long END;
00043 String description;
00044 String evturl;
00045 String[] words;
00046
00047 public eventtype() {
00048
00049 }
00050 public eventtype(Long BEGIN,Long END,String description, String ur) {
00051 this.BEGIN=BEGIN;
00052 this.END=END;
00053 this.description=description;
00054 this.words=description.split(" +");
00055 this.evturl=ur;
00056 }
00057 public eventtype(Long BEGIN,Long END,String[] words) {
00058 this.BEGIN=BEGIN;
00059 this.END=END;
00060 this.words=words;
00061 }
00062
00063 public int compareTo(Object other) {
00064 return (int)Math.signum(BEGIN-((eventtype)other).BEGIN);
00065 }
00066
00067 }
00068 ArrayList<eventtype> events=new ArrayList<eventtype>();
00069
00070
00071
00072 public VisIcal(Node n, Vector3f position) {
00073 super(n, new Vector3f(0,0,0));
00074 radius=2000;
00075 try {
00076 load(n.text);
00077 } catch (IOException e) {
00078 e.printStackTrace();
00079 }
00080
00081
00082 }
00083
00084
00090 @SuppressWarnings("unchecked")
00091 void load(String filename) throws IOException{
00092
00093 BufferedReader r=new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)),Charset.forName("UTF-8")));
00094
00095 String line;
00096
00097 String url="";
00098
00099 Date st = new Date();
00100 Date et = new Date();
00101 String desc = new String();
00102 SimpleDateFormat df = new SimpleDateFormat( "yyyyMMdd'T'HHmmss" );
00103 SimpleDateFormat dfday = new SimpleDateFormat( "yyyyMMdd" );
00104
00105 System.out.println("parsing "+filename+", NOW is "+df.format(System.currentTimeMillis()));
00106
00107
00108 while ((line=r.readLine())!=null){
00109
00110 if (line.equals("BEGIN:VEVENT")){isevent=true;url="";eventcount++;}
00111
00112 if (isevent)
00113 {
00114
00115
00116 String[] params2=line.split(":");
00117 if (params2[0].equals("DESCRIPTION"))
00118 {
00119 if (params2.length>1)
00120 {desc=params2[1];} else desc="none";
00121
00122
00123
00124 }
00125 else
00126 if (params2[0].equals("URL"))
00127 {
00128 url="http://"+params2[2];
00129
00130
00131 }
00132 else
00133
00134 if (params2[0].equals("SUMMARY"))
00135 {
00136 if (params2.length>1)
00137 {desc=params2[1]+" "+desc;} else desc="none";
00138
00139
00140
00141 }
00142 else
00143 {
00144 isdescription=false;
00145 String[] params=line.split(";");
00146 if (params[0].equals("DTSTART"))
00147 {
00148 String[] vals=params[1].split(":");
00149 String stamp=vals[1];
00150
00151 if (stamp.contains("T"))
00152 {try {st=df.parse( stamp );}
00153 catch(Exception e){throw new RuntimeException(e);}}
00154 else
00155 {try {st=dfday.parse( stamp );}
00156 catch(Exception e){throw new RuntimeException(e);}}
00157
00158
00159
00160
00161 }
00162 if (params[0].equals("DTEND"))
00163 {
00164 String[] vals=params[1].split(":");
00165 String stamp=vals[1];
00166 if (stamp.contains("T"))
00167 {try {et=df.parse( stamp );}
00168 catch(Exception e){throw new RuntimeException(e);}}
00169 else
00170 {try {et=dfday.parse( stamp );}
00171 catch(Exception e){throw new RuntimeException(e);}}
00172
00173 }
00174
00175
00176 }
00177
00178 }
00179 if (line.equals("END:VEVENT"))
00180 {
00181 isevent=false;
00182 events.add(new eventtype(st.getTime(),et.getTime(),desc,url));
00183
00184
00185
00186
00187 }
00188
00189 }
00190
00191
00192 Collections.sort(events);
00193
00194
00195
00196
00197 DateFormat datef=new SimpleDateFormat();
00198 if (Prefs.current.verbose) for(Iterator iter =events.iterator();iter.hasNext();){
00199 eventtype p = (eventtype)iter.next();
00200 System.out.println(datef.format(new Date(p.BEGIN))+"-"+datef.format(new Date(p.END)));
00201 System.out.println(p.description);
00202
00203 for (int i=1; i<p.words.length; i++){
00204
00205
00206 }
00207
00208
00209
00210 }
00211
00212
00213
00214 System.out.println();
00215 }
00216
00217
00218
00219 long nextUpdate=System.currentTimeMillis();
00223 void renderSelf() {
00224
00225 Vector3f po=new Vector3f();
00226
00227 Vector3f pe=new Vector3f();
00228
00229 long time=System.currentTimeMillis();
00230
00231
00232 SimpleDateFormat df = new SimpleDateFormat( "yyyyMMdd'T'HHmmss" );
00233
00234
00235
00236 if (time>nextUpdate){
00237
00238 System.out.println("updating ical at #"+df.format(time));
00239
00240 for (eventtype e: events){
00241
00242
00243
00244 if(time>e.BEGIN && time<e.END){
00245
00246
00247 VisRoot root=getRoot();
00248 Vector3f c=root.epicenter;
00249
00250
00251
00252
00253 root.add(this);
00254
00255 System.out.println("jetzt: "+df.format(e.BEGIN)+"#"+e.description);
00256
00257 po.x=c.x+(float)Math.random()*100;
00258 po.y=c.y+(float)Math.random()*30;
00259 po.z=c.z+(float)Math.random()*100;
00260
00261
00262
00263 VisNode um=new VisText(new Node(e.description), po);
00264
00265
00266
00267 root.add(um=new VisText(new Node(e.description), po));
00268
00269 um.url=e.evturl;
00270
00271
00272
00273
00274
00275 for (String word: e.words){
00276 pe.x=po.x-10+(float)Math.random()*10;
00277 pe.y=po.y-10+(float)Math.random()*10;
00278 pe.z=po.z-10+(float)Math.random()*10;
00279 if (word.length()>3)
00280 um.add(new VisKeyword(new Node(word), pe));
00281 }
00282
00283
00284
00285
00286
00287
00288 nextUpdate=time+1000*60*15;
00289
00290
00291 }else if (time<e.BEGIN)
00292 {
00293 nextUpdate=e.BEGIN;
00294
00295
00296 }
00297 }
00298
00299
00300 }
00301 }
00302 }