1 6 7 package org.netbeans.modules.logger.listeners; 8 9 import java.util.Hashtable ; 10 import java.io.IOException ; 11 import org.openide.loaders.DataObject; 12 import org.openide.cookies.*; 13 14 19 public class DocManager extends ListenerTools { 20 21 24 private Hashtable hashNames; 25 int counter; 26 long totalTime; 27 double sumFreq; 28 29 32 public DocManager() { 33 super("DOC"); 34 hashNames = new Hashtable (); 35 counter = 0; 36 } 37 38 43 public String getName(DataObject d){ 44 if(hashNames.containsKey((Object )d)) return (String )hashNames.get((Object )d); 45 else { 46 String codeName = assignName(d); 47 EditorCookie ec = (EditorCookie)d.getCookie(EditorCookie.class); 48 ec.getDocument().addDocumentListener(new DocListener(this)); 49 return codeName; 50 } 51 } 52 53 58 private String assignName(DataObject d){ 59 String fileName = d.getPrimaryFile().getNameExt(); 60 int dotIndex = fileName.lastIndexOf("."); 61 String extension = dotIndex!=-1 ? fileName.substring(dotIndex,fileName.length()) : ""; 62 String out = "f"+new Integer (counter).toString()+extension; 63 hashNames.put((Object )d,(Object )out); 64 counter++; 65 return out; 66 } 67 68 73 public String findName(DataObject d){ 74 if(hashNames.containsKey((Object )d)) return (String )hashNames.get((Object )d); 75 else return ""; 76 } 77 78 81 public synchronized void logDoc(double freq, long time){ 82 newBuffer(); 83 append("\n"+System.currentTimeMillis()); 84 append("f"+Double.toString(freq)); 85 append("t"+Long.toString(time)); 86 flush(); 87 } 88 } 89 | Popular Tags |