KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > property > Property


1 /*
2  * PropertyDescription.java
3  *
4  * Created on July 25, 2005, 3:19 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10 package org.netbeans.modules.piagetproject.property;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.Enumeration JavaDoc;
14 import java.util.Hashtable JavaDoc;
15
16
17 /**
18  *
19  * @author loicsegapelli
20  */

21
22 public abstract class Property implements Comparable JavaDoc{
23     
24     /* these two Strings are used by TCRAnalyzer to
25      * name some specific top components, ie: all Editor
26      * windows + the time spent outside of NB
27      */

28     public static final String JavaDoc EDITOR = "Editor";
29     public static final String JavaDoc OUT = "Outside_NB";
30     
31     /* all windows inside Editor */
32     public static final String JavaDoc WINDOW = "win";
33     
34     /*file extensions */
35     public static final String JavaDoc EXTENSION = "ext";
36     
37     /* name of log file */
38     public static final String JavaDoc LOG_FILE = "logFile";
39     
40     /* usage of java class nodes */
41     public static final String JavaDoc JAVA_CLASS_NODE = "jcn";
42     public static final String JavaDoc CN_FIELDS = "jcnfields";
43     public static final String JavaDoc CN_BEANS = "jcnbeans";
44     public static final String JavaDoc CN_CONS = "jcnconstructors";
45     public static final String JavaDoc CN_METHODS = "jcnmethods";
46     
47     /* editor stats... */
48     public static final String JavaDoc TAB_SWITCH = "tabSwitch";
49     public static final String JavaDoc MAX_TABS = "maxTabs";
50     public static final String JavaDoc TAB_PERIOD = "tabPeriod";
51     public static final String JavaDoc TOTAL_TIME = "total";
52     public static final String JavaDoc TYPING_FREQ = "TypingFreq";
53     public static final String JavaDoc TYPING_TIME = "TypingTime";
54     
55     /* magnification of top components */
56     public static final String JavaDoc MAGNIFIED = "magnified";
57     
58     /* names of tables */
59     public static final String JavaDoc LOG_TABLE = "Log Files";
60     public static final String JavaDoc EDITOR_TABLE = "Editor";
61     public static final String JavaDoc WINDOW_TABLE = "TopComponents";
62     public static final String JavaDoc EXTENSION_TABLE = "File Extensions";
63     public static final String JavaDoc MAGNIFIED_TABLE = "Magnified TopComponents";
64     public static final String JavaDoc CLASS_NODE_TABLE = "Java Class Node Fields";
65     public static final String JavaDoc OTHER_TABLE = "Other Stats...";
66     public static final String JavaDoc UNKNOWN_TABLE = "Unknown statistics!";
67     
68     private static Hashtable JavaDoc properties;
69     
70     protected String JavaDoc name, table, key;
71     private byte type;
72     protected static long ideTotal, outTotal;
73     
74     protected Property(String JavaDoc key, String JavaDoc table){
75         this.key = key;
76         this.table = table;
77     }
78     
79     protected Property(String JavaDoc key, String JavaDoc table, String JavaDoc name){
80         this.key = key;
81         this.table = table;
82         this.name = name;
83     }
84     
85     public static String JavaDoc [] getTableIDs(){
86         return new String JavaDoc [] {
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 JavaDoc();
100         ideTotal = outTotal = 0;
101     }
102     
103     public static void addProperty(String JavaDoc key, String JavaDoc 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 JavaDoc name = key.replaceFirst(WINDOW, "");
112                 p = new WindowProperty(key, name, value, WINDOW_TABLE);
113                 
114             } else if(key.startsWith(EXTENSION)) {
115                 String JavaDoc name = key.replaceFirst(EXTENSION, "");
116                 p = new IntProperty(key, name, value, EXTENSION_TABLE);
117                 
118             } else if(key.startsWith(JAVA_CLASS_NODE)) {
119                 String JavaDoc 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 JavaDoc 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 JavaDoc 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         /* last: update the global variable concerning time spent in the IDE */
157         if(key.equals(TOTAL_TIME)){
158                 long l = Long.parseLong(value);
159                 ideTotal += l;
160         }
161     }
162     
163     public String JavaDoc getName(){
164         return name;
165     }
166     
167     public String JavaDoc getTableName(){
168         return table;
169     }
170     
171     public static Property[] getTableElements(String JavaDoc tableName){
172         
173         Enumeration JavaDoc e = properties.elements();
174         ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc o) {
192         Property p = (Property)o;
193         return this.getName().compareTo(p.getName());
194     }
195     
196     protected abstract void combineProperties(String JavaDoc key, String JavaDoc value);
197     
198     public abstract Object JavaDoc getValue(int counter);
199     
200 }
201
Popular Tags