1 10 package org.netbeans.modules.piagetproject.property; 11 import java.util.ArrayList ; 12 import java.util.Collections ; 13 import java.util.Enumeration ; 14 import java.util.Hashtable ; 15 16 17 21 22 public abstract class Property implements Comparable { 23 24 28 public static final String EDITOR = "Editor"; 29 public static final String OUT = "Outside_NB"; 30 31 32 public static final String WINDOW = "win"; 33 34 35 public static final String EXTENSION = "ext"; 36 37 38 public static final String LOG_FILE = "logFile"; 39 40 41 public static final String JAVA_CLASS_NODE = "jcn"; 42 public static final String CN_FIELDS = "jcnfields"; 43 public static final String CN_BEANS = "jcnbeans"; 44 public static final String CN_CONS = "jcnconstructors"; 45 public static final String CN_METHODS = "jcnmethods"; 46 47 48 public static final String TAB_SWITCH = "tabSwitch"; 49 public static final String MAX_TABS = "maxTabs"; 50 public static final String TAB_PERIOD = "tabPeriod"; 51 public static final String TOTAL_TIME = "total"; 52 public static final String TYPING_FREQ = "TypingFreq"; 53 public static final String TYPING_TIME = "TypingTime"; 54 55 56 public static final String MAGNIFIED = "magnified"; 57 58 59 public static final String LOG_TABLE = "Log Files"; 60 public static final String EDITOR_TABLE = "Editor"; 61 public static final String WINDOW_TABLE = "TopComponents"; 62 public static final String EXTENSION_TABLE = "File Extensions"; 63 public static final String MAGNIFIED_TABLE = "Magnified TopComponents"; 64 public static final String CLASS_NODE_TABLE = "Java Class Node Fields"; 65 public static final String OTHER_TABLE = "Other Stats..."; 66 public static final String UNKNOWN_TABLE = "Unknown statistics!"; 67 68 private static Hashtable properties; 69 70 protected String name, table, key; 71 private byte type; 72 protected static long ideTotal, outTotal; 73 74 protected Property(String key, String table){ 75 this.key = key; 76 this.table = table; 77 } 78 79 protected Property(String key, String table, String name){ 80 this.key = key; 81 this.table = table; 82 this.name = name; 83 } 84 85 public static String [] getTableIDs(){ 86 return new String [] { 87 WINDOW_TABLE, 88 MAGNIFIED_TABLE, 89 EDITOR_TABLE, 90 EXTENSION_TABLE, 91 CLASS_NODE_TABLE, 92 OTHER_TABLE, 93 UNKNOWN_TABLE, 94 LOG_TABLE 95 }; 96 } 97 98 public static void reset(){ 99 properties = new Hashtable (); 100 ideTotal = outTotal = 0; 101 } 102 103 public static void addProperty(String key, String value) { 104 Property p = null; 105 if(properties.containsKey(key)){ 106 p = (Property)properties.get(key); 107 p.combineProperties(key, value); 108 } else { 109 110 if(key.startsWith(WINDOW)) { 111 String name = key.replaceFirst(WINDOW, ""); 112 p = new WindowProperty(key, name, value, WINDOW_TABLE); 113 114 } else if(key.startsWith(EXTENSION)) { 115 String name = key.replaceFirst(EXTENSION, ""); 116 p = new IntProperty(key, name, value, EXTENSION_TABLE); 117 118 } else if(key.startsWith(JAVA_CLASS_NODE)) { 119 String name = key.replaceFirst(JAVA_CLASS_NODE, ""); 120 p = new IntProperty(key, name, value, CLASS_NODE_TABLE); 121 122 } else if(key.equals(TAB_SWITCH)) { 123 p = new IntProperty(key, key, value, EDITOR_TABLE); 124 125 } else if(key.equals(MAX_TABS)) { 126 p = new IntProperty(key, key, value, EDITOR_TABLE); 127 128 } else if(key.equals(TAB_PERIOD)) { 129 p = new LongProperty(key, key, value, EDITOR_TABLE); 130 131 } else if(key.equals(TOTAL_TIME)) { 132 p = new LongProperty(key, key, value, OTHER_TABLE); 133 134 } else if(key.startsWith(LOG_FILE)) { 135 String name = key.replaceFirst(LOG_FILE, ""); 136 p = new StringProperty(key, name, value, LOG_TABLE); 137 138 } else if(key.startsWith(TYPING_FREQ)) { 139 p = new DoubleProperty(key, key, value, EDITOR_TABLE); 140 141 } else if(key.startsWith(TYPING_TIME)) { 142 p = new LongProperty(key, key, value, EDITOR_TABLE); 143 144 } else if(key.startsWith(MAGNIFIED)) { 145 String name = "magnified"; 146 p = new StringProperty(key, name, value, MAGNIFIED_TABLE); 147 } 148 149 } 150 if(p == null){ 151 System.out.println("unknown key:"+key+" for value:"+value); 152 p = new StringProperty(key, key, value, UNKNOWN_TABLE); 153 } 154 properties.put(key, p); 155 156 157 if(key.equals(TOTAL_TIME)){ 158 long l = Long.parseLong(value); 159 ideTotal += l; 160 } 161 } 162 163 public String getName(){ 164 return name; 165 } 166 167 public String getTableName(){ 168 return table; 169 } 170 171 public static Property[] getTableElements(String tableName){ 172 173 Enumeration e = properties.elements(); 174 ArrayList list = new ArrayList (); 175 Property p; 176 while(e.hasMoreElements()){ 177 p = (Property)e.nextElement(); 178 if(p.getTableName().equals(tableName)){ 179 list.add(p); 180 } 181 } 182 Collections.sort(list); 183 184 Property [] out = new Property [list.size()]; 185 for(int i=0; i<out.length; i++){ 186 out [i] = (Property)list.get(i); 187 } 188 return out; 189 } 190 191 public int compareTo(Object o) { 192 Property p = (Property)o; 193 return this.getName().compareTo(p.getName()); 194 } 195 196 protected abstract void combineProperties(String key, String value); 197 198 public abstract Object getValue(int counter); 199 200 } 201 | Popular Tags |