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

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import java.io.File;
00004 import java.util.ArrayList;
00005 import java.util.HashMap;
00006 import java.util.List;
00007 
00008 import org.dronus.graph.Node;
00009 import org.hfbk.vis.Allesfresser;
00010 import org.hfbk.vis.Prefs;
00011 import org.lwjgl.util.vector.Vector3f;
00012 
00020 public class VisDir extends VisImagefield {
00021 
00022         HashMap<File, VisNode> visnodesByFiles = new HashMap<File, VisNode>();
00023 
00024         HashMap<File, Long> tstamps = new HashMap<File, Long>();
00025 
00026         Allesfresser af;
00027 
00028         public VisDir(Node n, Vector3f position) {
00029                 super(n, position);
00030         }
00031 
00032         void renderSelf() {
00033                 String dir = node.text;
00034                 if (dir.equals(""))
00035                         dir = Prefs.current.watchdir;
00036                 if (dir.equals(".") || !new File(dir).exists()) {
00037                         children.clear();
00038                         return;
00039                 }
00040 
00041                 // build a Allesfresser if needed
00042                 if (af == null)
00043                         af = new Allesfresser(getRoot().client);
00044 
00045                 int count = children.size();
00046 
00047                 List<VisNode> active = new ArrayList<VisNode>();
00048 
00049                 // for all files in dir..
00050                 for (File f : new File(dir).listFiles()) {
00051 
00052                         long tstamp = f.lastModified(); // get modification time
00053                         VisNode currentv = visnodesByFiles.get(f); // find VisNode if file
00054                                                                                                                 // is
00055                         // already visualised.
00056 
00057                         if ((currentv == null || tstamps.get(f) < tstamp) && !f.isHidden()
00058                                         && !f.getPath().endsWith("~")) {
00059                                 // if a file is new or modified, and it is not hidden
00060                                 // and not a backup file (....~)
00061 
00062                                 VisNode v = null;
00063                                 try { // try to get a VisNode for that file
00064                                         v = af.frissFile("file://" + f.getAbsolutePath());
00065                                 } catch (Exception e) {
00066                                         System.out.println("Unable to read " + f.getAbsolutePath());
00067                                 }
00068 
00069                                 if (v != null) { // we found something visualisable!
00070 
00071                                         // show a + button instead of dir recursion
00072                                         // to allow user to decide to go into
00073                                         if (v instanceof VisDir)
00074                                                 v = new OpenButton(v, f);
00075 
00076                                         if (currentv != null) {
00077                                                 // we already visualised this one,
00078                                                 // replace it by the new version
00079                                                 children.set(children.indexOf(currentv), v); // replace
00080                                                 v.position = currentv.position; // keep position
00081                                                 v.parent = this;
00082                                         } else {
00083                                                 // a new file, just add it
00084                                                 add(v);
00085                                         }
00086                                         currentv = v;
00087                                 }
00088 
00089                                 visnodesByFiles.put(f, v); // store visualisation
00090                                 tstamps.put(f, tstamp); // store modification time
00091                                 // else if (Prefs.current.verbose)
00092                                 // System.out.println(f.getName()+" rejected");
00093 
00094                         }
00095 
00096                         if (currentv != null)
00097                                 active.add(currentv);
00098                 }
00099 
00100                 children.retainAll(active);
00101 
00102                 if (count != children.size())// amount of files changed
00103                         setLayout(layoutMode); // redo layout
00104 
00105                 super.renderSelf();
00106         }
00107 
00111         class OpenButton extends MoreButton {
00112                 VisNode n;
00113                 File dir;
00114 
00115                 public OpenButton(VisNode n) {
00116                         super(new Vector3f());
00117                         this.n = n;
00118 
00119                 }
00120 
00121                 public OpenButton(VisNode n, File dir) {
00122                         super(new Vector3f());
00123                         this.n = n;
00124                         this.help = dir.getName();
00125                         this.dir = dir;
00126                 }
00127 
00129                 public void handleClick() {
00130                         // just replace this button by
00131                         // associated VisDir.
00132                         int i = parent.children.indexOf(this);
00133                         parent.children.remove(i);
00134                         parent.children.add(i, n);
00135                         n.parent = parent;
00136                         n.position.x = parent.getExtends();
00137                         visnodesByFiles.put(dir, n); // replace too
00138                 }
00139         }
00140 }

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