VisClient/org/hfbk/vis/visnode/VisSrt.java

Go to the documentation of this file.
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;  // DisplayList number
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>();   //and faces as vertex indicies
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) { //.obj file not found 
00071                         e.printStackTrace();
00072                 }
00073 
00074                 
00075         }
00076 
00077         
00084         void load(String filename) throws IOException{
00085                 
00086 //              filename="president.srt";
00087                 
00088                 BufferedReader r=new BufferedReader(new FileReader(new File(filename)));
00089                 
00090 
00091                 String line;
00092                 
00093                 /*
00094 0
00095 00:00:01,000 --> 00:00:04,000
00096 Downloaded From www.AllSubs.org
00097 
00098 1
00099 00:03:06,760 --> 00:03:08,910
00100 President Bush is
00101 in Chicago tonight
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                 //System.out.println(new Date(now).getTimezoneOffset());  
00118                 
00119                 
00120                 while ((line=r.readLine())!=null){ //read file while lines left..
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 //                      System.out.println(df.format(st)+" ->"+df.format(et));
00144                         
00145                         }
00146 
00147                         
00148                         if (line.equals(""))
00149                         {
00150                                 isevent=false;
00151                                 
00152                                 desc.trim();
00153 //                              String words[]=desc.split(" +");
00154 //                              events.add(new eventtype(st.getTime()+now+3600000,et.getTime()+now,words));
00155                                 events.add(new eventtype(st.getTime()+now+3600000,et.getTime()+now,desc));
00156                                 desc="";
00157                         }
00158                         
00159                 }
00160                 
00161                 
00162 /*      //DEBUG
00163                 for(Iterator iter =events.iterator();iter.hasNext();){
00164                         eventtype p = (eventtype)iter.next();
00165                         System.out.println(df.format(new Date(p.BEGIN))+"-"+df.format(new Date(p.END)));
00166         //              System.out.println(p.description);
00167                         
00168                 }*/
00169 
00170                 
00171                 
00172         }
00173         
00174         
00178         void renderSelf() {
00179                 //do update if time elapsed
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         //                      children.clear();
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 //                              root.client.reset();
00202                         
00203                         /*      for (int i=1; i<p.words.length; i++){
00204                                         System.out.print(p.words[i]+',');
00205                                         po.x=(float)Math.random()*100;
00206                                         po.y=(float)Math.random()*100;
00207                                         po.z=(float)Math.random()*100;
00208                                         
00209                                         root.add(new VisKeyword(new Node(p.words[i]), po));     
00210                                 
00211                                 }*/
00212                                 System.out.println();
00213                                 }
00214                                 
00215                         }
00216                         
00217                         
00218                 }
00219         }
00220 
00221 }

Generated on Tue Apr 7 17:57:22 2009 for visclient by  doxygen 1.5.1