00001 package org.hfbk.vis.visnode;
00002
00003 import java.awt.event.MouseEvent;
00004 import java.io.File;
00005
00006 import org.dronus.gl.GLBoxRenderer;
00007 import org.dronus.gl.GLFont;
00008 import org.dronus.gl.GLTextPanel;
00009 import org.dronus.gl.GLUtil;
00010 import org.dronus.graph.Edge;
00011 import org.dronus.graph.Graph;
00012 import org.dronus.graph.Node;
00013 import org.hfbk.util.Counter;
00014 import org.hfbk.util.Sleeper;
00015 import org.hfbk.vis.Prefs;
00016 import org.lwjgl.opengl.GL11;
00017 import org.lwjgl.util.vector.Vector3f;
00018
00031 public class VisFilesys extends VisSet {
00032
00034 final int DELAY=1000;
00035
00037 Graph profile=new Graph();
00038
00039
00040
00042 Counter<Integer> callCounter=new Counter<Integer>();
00043
00044 Counter<String> sizeAdder=new Counter<String>();
00045
00046
00047 boolean dirty=true;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00072 class VisCallBall extends VisNodeDraggable {
00073 int dl;
00074 GLTextPanel helpText;
00075 Node node;
00076 boolean isTriggered=true;
00077
00078 VisCallBall(Node n, Vector3f position) {
00079 super(n, position);
00080
00081 this.node=n;
00082 w=h=radius=1.6f;
00083 String[] b = n.text.split("#");
00084 n.text=b[0];
00085 float f=1.6f;
00086 if (b.length>1) {
00087 f = Float.valueOf( b[1] ).floatValue();
00088 w=h=radius=f/10000;
00089 w=h=radius=((float)Math.pow(f,(double)( 1.0/3))/10f);
00090 }
00091
00092 int cutoff=n.text.lastIndexOf("/");
00093 String caption=n.text;
00094 if (cutoff>0)caption=n.text.substring(n.text.lastIndexOf("/")+1);
00095
00096 helpText=new GLTextPanel(caption,0,0);
00097 }
00098
00099 String cleanPath(String path){
00100 path=path.replace('\\', '/');
00101 path=path.replace("file://", "");
00102 if (path.matches("file:/.*?\\:.*?")){
00103 path=path.replace("file:/", "");
00104
00105
00106 }
00107
00108 return path.trim();
00109 }
00110
00111 void handleEvent(VisMouseEvent evt) {
00112 super.handleEvent(evt);
00113
00114 VisRoot root=getRoot();
00115
00116
00117 if (evt.getID()==MouseEvent.MOUSE_CLICKED)
00118
00119 {
00120
00121
00122
00123
00124
00125 if (node.text.toLowerCase().matches(".*?\\.("+Prefs.current.suffixesImage+"|"+Prefs.current.suffixesVideo+")(.|\\s)*"))
00126 {
00127
00128 System.out.println(cleanPath(node.text));
00129
00130
00131
00132
00133
00134 Vector3f posi=position;
00135 posi.y+=1;
00136 add(new VisImage(new Node(cleanPath(node.text)),new Vector3f(0,1,0)));
00137
00138
00139
00140
00141
00142
00143 }
00144 else if (node.text.toLowerCase().matches(".*?\\.(obj)(.|\\s)*"))
00145 {
00146 System.out.println(cleanPath(node.text));
00147
00148
00149
00150
00151
00152 root.client.root.create("obj", cleanPath(node.text));
00153
00154 }
00155
00156 }
00157 }
00158
00159
00160 void renderSelf() {
00161 boolean isOur=false;
00162 Integer count=callCounter.get(node.id);
00163 if (count!=null){
00164
00165
00166 }
00167 if (isHoovered || isTriggered)
00168 GL11.glColor3f(1,1,1);
00169 else if (node.type.equals("File"))
00170 {
00171 if (node.text.toLowerCase().matches(".*?\\.("+Prefs.current.suffixesImage+"|"+Prefs.current.suffixesVideo+")(.|\\s)*")){
00172 GL11.glColor4f(1f,1f,.1f,.5f);
00173 }
00174 else if (node.text.toLowerCase().matches(".*?\\.(java)(.|\\s)*")){
00175 GL11.glColor3f(0f,.8f,1f);
00176
00177
00178 }else if (node.text.toLowerCase().matches(".*?\\.(obj|srt|coord|coords)(.|\\s)*")){
00179 GL11.glColor3f(.1f,1f,.1f);
00180
00181 }
00182 else GL11.glColor3f(.8f,.5f,.01f);
00183 }
00184 else if (node.type.equals("Dir")){
00185 isOur=true;
00186 GL11.glColor4f(1,0,0,(isOur ? 1 : .5f ));
00187 }
00188
00189
00190
00191
00192 GL11.glDisable(GL11.GL_TEXTURE_2D);
00193
00194 GLBoxRenderer.renderBox(radius,radius,radius);
00195
00196
00197
00198 if (isHoovered || isOur) {
00199 GL11.glTranslatef(radius,radius,0);
00200 GLUtil.billboardCylinder();
00201 GL11.glScalef(1,2,1);
00202 GLFont.getDefault().render();
00203 helpText.render();
00204 GL11.glDisable(GL11.GL_TEXTURE_2D);
00205 }
00206
00207 isTriggered=false;
00208 }
00209 }
00210
00212 VisNode create(Node node, Vector3f pos) {
00213 return new VisCallBall(node, pos);
00214 }
00215
00217 public VisFilesys(Node n, Vector3f position) {
00218 super(null, position);
00219 if (n.text.length()==0) n.text=".";
00220
00221 final String start=n.text;
00222
00223
00224 profile.addNode(new Node("0","Vis/Client","Set"));
00225
00226
00227
00228
00229 Thread scanner=new Thread(){
00230
00231 public void run() {
00232 setName("VisProfiler");
00233 while(true){
00234 synchronized(VisFilesys.this){ scandir(start,null); };
00235 Sleeper.sleep(DELAY);
00236 }
00237 }
00238 };
00239 scanner.start();
00240
00241 }
00242
00247 void scandir(String startatdir, Node parentnode){
00248 Node rootset=profile.getRoot();
00249 if (startatdir.equals("")) {startatdir=".";parentnode=rootset;}
00250
00251 if (parentnode==null)parentnode=rootset;
00252
00253 File f = null;
00254
00255 f = new File(startatdir);
00256
00257
00258
00259 String path=f.getAbsolutePath();
00260
00261 for (File f2 : f.listFiles()) {
00262 String fn1=f2.getName();
00263 int size=(int)f2.length();
00264
00265 boolean isdir=f2.isDirectory();
00266 char c=fn1.charAt(0);
00267 if ((c!='.')&&(!fn1.endsWith("~"))&&(!fn1.endsWith("strip")&&(!fn1.endsWith(".class"))))
00268 {
00269 int fileId=fn1.hashCode();
00270
00271 callCounter.add(fileId);
00272 sizeAdder.add(startatdir,size);
00273
00274 Node fileNode=profile.findNode(fileId);
00275 if(fileNode==null) {
00276 if (isdir)
00277 {
00278
00279 fileNode=new Node(fileId, fn1, "Dir");
00280
00281
00282 }
00283 else
00284 {
00285
00286 fileNode=new Node(fileId, path+"/"+fn1+"#"+size, "File");
00287
00288 }
00289
00290
00291 profile.addNode(fileNode);
00292 dirty=true;
00293
00294
00295 profile.addEdge(new Edge(fileNode,rootset, null, "in",1f));
00296
00297 profile.addEdge(new Edge(fileNode,parentnode, null, "",.05f));
00298
00299 if (isdir){
00300 scandir(startatdir+"/"+fn1,fileNode);
00301 }
00302
00303 }
00304 }
00305
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 }
00362
00363 void renderSelf() {
00364 super.renderSelf();
00365
00366
00367 if (dirty) synchronized(this){
00368 Node root=profile.getRoot();
00369 update(root);
00370
00371 dirty=false;
00372 }
00373 }
00374 }