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

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import java.awt.AWTEvent;
00004 import java.io.File;
00005 import java.util.List;
00006 
00007 import org.dronus.gl.GLBoxRenderer;
00008 import org.dronus.gl.GLFont;
00009 import org.dronus.gl.GLTextPanel;
00010 import org.dronus.graph.Edge;
00011 import org.dronus.graph.Graph;
00012 import org.dronus.graph.Node;
00013 import org.hfbk.util.Sleeper;
00014 import org.hfbk.vis.Prefs;
00015 import org.lwjgl.opengl.GL11;
00016 import org.lwjgl.util.vector.Vector3f;
00017 
00028 public class VisFilesysTree extends VisNode {
00029 
00031         final int DELAY = 1000;
00032 
00034         Graph tree = new Graph();
00035 
00036         // if something was sampled but not yet visualised.
00037         boolean dirty = false;
00038         
00039         float inset=0.9f;
00044 private class FileBox extends VisNodeMousable {
00045                 int dl;
00046 
00047                 GLTextPanel helpText;
00048 
00049                 boolean isTriggered = true;
00050 
00051                 FileBox(Node n, Vector3f position, float w, float h, boolean isVertical) {
00052                         super(n, position);
00053                         this.w=w;
00054                         this.h=h;
00055                         
00056                         radius=w+h;
00057                         
00058                         String[] b = n.text.split("#");
00059                         
00060                         int cutoff = b[0].lastIndexOf("/");
00061                         String caption=b[0];
00062                         if (cutoff > 0)
00063                                 caption = b[0].substring(b[0].lastIndexOf("/") + 1);
00064 
00065                         helpText = new GLTextPanel(caption, 0, 0);
00066                         
00067                         //recurse for children
00068                         
00069                         float oursize=Float.parseFloat(b[1]);
00070                         
00071                         float cpos=(1-inset)/2, cw, ch;
00072                         
00073                         int filecount=n.getFromNodes().size();
00074                         
00075                         for (Node c: n.getFromNodes()){
00076                                 
00077                                 float csize=Float.parseFloat(c.text.substring(c.text.lastIndexOf('#')+1));
00078                                 
00079                                 
00080                                 float cscale=csize/oursize;
00081                                 
00082                                 cscale=.5f*cscale+.5f*1f/filecount;  
00083                                 cscale*=inset;
00084                                 
00085                                 Vector3f pos;
00086                                 if (isVertical) {
00087                                         cw=w*inset*cscale;
00088                                         ch=h*inset;
00089                                         pos=new Vector3f(cpos*w-w/2+cw/2,0,3);                                  
00090                                         //pos=new Vector3f(cpos*w-w/2+cw/2,3,0);                                        
00091                                 }
00092                                 else{
00093                                         
00094                                         cw=w*inset;
00095                                         ch=h*inset*cscale;
00096                                         pos=new Vector3f(0,cpos*h-h/2+ch/2,3);
00097                                         //pos=new Vector3f(0,3,cpos*h-h/2+ch/2);
00098 
00099                                 }
00100                                 
00101                                 add(new FileBox(c, pos, cw, ch, !isVertical));
00102                                 
00103                                 cpos+=cscale*inset;
00104                         }                       
00105                 }
00106 
00107                 void renderSelf() {
00108                         if (isHoovered || isTriggered)
00109                                 GL11.glColor3f(1, 1, 1);
00110                         else if (node.type.equals("File")) {
00111                                 if (node.text.toLowerCase().matches(
00112                                                 ".*?\\.(" + Prefs.current.suffixesImage + "|"
00113                                                                 + Prefs.current.suffixesVideo + ")(.|\\s)*")) {
00114                                         GL11.glColor4f(1f, 1f, .1f,1);
00115                                 } else if (node.text.toLowerCase().matches(
00116                                                 ".*?\\.(java)(.|\\s)*")) {
00117                                         GL11.glColor4f(0f, .8f, 1f,1);
00118 
00119                                         // is it some subtitles file?
00120                                 } else if (node.text.toLowerCase().matches(
00121                                                 ".*?\\.(obj|srt|coord|coords)(.|\\s)*")) {
00122                                         GL11.glColor4f(.1f, 1f, .1f,1);
00123 
00124                                 } else
00125                                         GL11.glColor4f(.8f, .5f, .01f,1);
00126                         } else if (node.type.equals("Dir")) {
00127                                 GL11.glColor4f(1, 0, 0,.3f);
00128                         }
00129 
00130                         // GLSphereRenderer.renderSphere(radius);
00131 
00132                         GL11.glDisable(GL11.GL_TEXTURE_2D);
00133 
00134                         GLBoxRenderer.renderBox(w, h, 5f);
00135 //                      GLBoxRenderer.renderBox(w, 5f, h-.3f);
00136                         //GLBoxRenderer.renderFrame(w, 5f, h-.3f);
00137 
00138                         // if (isHoovered || radius>=1.6f) { //describe "fat" calls
00139                         // unhoovered also
00140                         if (isHoovered) {
00141 //                              System.out.println(radius);
00142 //GL11.glRotatef(180,0,1,0);
00143                                 GL11.glTranslatef(hit.x, hit.y, hit.z+15);
00144                                 GL11.glScalef(10,10,10);
00145                                 GL11.glColor3f(1,1,1);
00146                                 GLFont.getDefault().render();
00147                                 helpText.render();
00148                                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00149                         }
00150 
00151                         isTriggered = false;
00152                 }
00153                 Vector3f hit=new Vector3f();
00154                 @Override
00155                 void handleEvent(VisMouseEvent evt) {
00156                         hit=evt.hit;
00157                 }
00158         }
00159 
00161         public VisFilesysTree(Node n, Vector3f position) {
00162                 super(null, position);
00163                 if (n.text.length()==0) n.text=".";
00164 
00165                 final String start = n.text;
00166 
00167                 //tree.addNode(new Node("0", "Vis/Client", "Set"));
00168 
00169                 Thread scanner = new Thread() {
00170 
00171                         public void run() {
00172                                 setName("VisScanner");
00173                         //      while (true) {
00174                                         synchronized (tree) {
00175                                                 scanfile(start, null);
00176                                         };
00177                                         
00178                                         dirty=true;
00179                                         Sleeper.sleep(DELAY);
00180                                 //}
00181                         }
00182                 };
00183                 scanner.start();
00184 
00185         }
00186 
00191         int scanfile(String startatdir, Node parentnode) {
00192                 File f = new File(startatdir);
00193                 
00194                 boolean isdir=f.isDirectory();
00195                 String fn = f.getName();
00196                 String path = f.getAbsolutePath();
00197                 
00198                 if (
00199                         fn.startsWith(".svn")||
00200                         fn.endsWith("~") ||
00201                         fn.endsWith("strip") ||
00202                         fn.endsWith(".class") 
00203                 ) return 0; 
00204                         
00205                 int fileId = path.hashCode();
00206                 Node fileNode = tree.findNode(fileId);
00207                 if (fileNode == null) {
00208                         if (isdir) {
00209 
00210                                 fileNode = new Node(fileId, fn+" #", "Dir");
00211                                 // System.out.println(fn1+": dir added "+fileNode);
00212 
00213                         } else {
00214 
00215                                 fileNode = new Node(fileId, path+" #", "File");
00216                                 // System.out.println(fn1+": file added "+fileNode);                            
00217                         }       
00218                         tree.addNode(fileNode);
00219                         if (parentnode!=null) tree.addEdge(new Edge(fileNode, parentnode, null, ""));
00220                         
00221                 }               
00222                 
00223                 int size=0;
00224                 if (isdir){             
00225                         for (String sub: f.list())
00226                                 size+=scanfile(startatdir + "/" + sub, fileNode);
00227                 }else
00228                         size=(int) f.length();
00229                 
00230                 fileNode.text+=size;
00231                 
00232                 if (size==0) size=1;
00233                 return size;
00234         }
00235 
00236         
00237         void transform() {      
00238                 super.transform();
00239         //      GL11.glRotatef(180, 0, 1, 0);
00240                 GL11.glRotatef(-90, 1, 0, 0);
00241                 
00242         }
00243         
00244         void renderSelf() {
00245                 if (dirty)
00246                         synchronized (tree) {
00247                                 Node root = tree.getRoot();
00248                                 children.clear();                               
00249                                 add(new FileBox(root, new Vector3f(),150,150, true));
00250 
00251                                 dirty = false;
00252                         }
00253         }
00254         
00255         public void render(List<AWTEvent> events) {
00256         //      GL11.glEnable(GL11.GL_CULL_FACE);
00257                 super.render(events);
00258                 //GL11.glDisable(GL11.GL_CULL_FACE);
00259         }
00260 }

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