KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piaget > analyze > WindowData


1 /*
2  * WindowData.java
3  *
4  * Created on April 19, 2005, 11:24 AM
5  */

6
7 package org.netbeans.modules.piaget.analyze;
8
9 import java.util.Date JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.awt.Color JavaDoc;
12
13 /**
14  * This class represents user actions concerning windows inside NetBeans IDE.
15  * By "window" I am referring to IDE windows such as "Projects", "Output",
16  * etc. but also to Editor tabs.
17  * @author loicsegapelli
18  */

19 public class WindowData implements Comparable JavaDoc{
20     
21     /**
22      * the name of this window
23      */

24     public String JavaDoc name;
25     
26     /**
27      * is this window inside the editor?
28      */

29     public boolean editor;
30     
31     /**
32      * how long this window has been opened
33      */

34     public long open;
35     
36     /**
37      * how long this window has been activated
38      */

39     public long activated;
40     
41     /**
42      * at what time was it last opened / activated
43      */

44     public long openTime, activatedTime;
45     
46     public boolean activatedB, openB;
47     Date JavaDoc start;
48     ArrayList JavaDoc actions;
49     Coord[] graphArray;
50     
51     /**
52      * X coordinates for the graph
53      */

54     public int[] sliceX;
55     
56     /**
57      * Y coordinates for the graph
58      */

59     public int[] sliceY;
60     /**
61      * the color used to display this window timeline
62      */

63     public Color JavaDoc chartColor;
64     
65     
66     /**
67      * Creates a new instance of WindowData
68      * @param editorWindow is this window a tab inside the editor?
69      * @param myId name of this window (filename if it is a tab in the Editor,
70      * NetBeans window name otherwise)
71      */

72     public WindowData(boolean editor, String JavaDoc name) {
73         activatedTime = openTime = open = activated = 0;
74         openB = activatedB = false;
75         this.editor = editor;
76         this.name = name;
77         chartColor = Color.BLACK;
78         actions = new ArrayList JavaDoc();
79     }
80     
81     /**
82      * called when this window is opened
83      * @param ts timestamp - when the event occured
84      */

85     public void open(long ts){
86         if(openB==true) {
87             //System.out.println("WindowData:already opened:"+name);
88
return;
89         }
90         openTime = ts;
91         if(start==null){
92             start = new Date JavaDoc(ts);
93         }
94         openB = true;
95     }
96     
97     /**
98      * called when this window is closed
99      * @param ts timestamp - when the event occured
100      */

101     public void close(long ts){
102         if(openB)open += ts-openTime;
103         else {
104             //System.out.println("WindowData:already closed:"+name);
105
}
106         openB = false;
107     }
108     
109     /**
110      * called when this window is activated
111      * @param ts timestamp - when the event occured
112      */

113     public void activated(long ts){
114         addAction(ts, true);
115         activatedTime = ts;
116         activatedB = true;
117     }
118     
119     /**
120      * called when this window is deactivated
121      * @param ts timestamp - when the event occured
122      */

123     public void deactivated(long ts){
124         addAction(ts, false);
125         if(activatedB)activated += ts-activatedTime;
126         activatedB = false;
127     }
128     
129     /**
130      * called when parsing is done, makes sure that all windows are closed for
131      * consistency
132      * @param ts timestamp - when the event occured
133      */

134     public void end(long ts){
135         if(openB)close(ts);
136         if(activatedB)deactivated(ts);
137         graphArray = (Coord[])actions.toArray(new Coord[0]);
138     }
139     
140     /**
141      * used to classify windows by alphabetic order
142      * @param o the other window object this object is compared to
143      * @return integer comparing the two window names
144      */

145     public int compareTo(Object JavaDoc o){
146         return name.compareTo(((WindowData)o).name);
147     }
148     
149     /**
150      * returns events occuring for this window within a timeslice.
151      * <CODE>true</CODE> if the window is activated, <CODE>false</CODE>
152      * otherwise
153      * @param start when the timeslice begins
154      * @param end when the timeslice ends
155      */

156     public void computeSlice(long start,long end){
157         int i = 0;
158         // find a start point
159
while(i<graphArray.length){
160             if(graphArray[i].x>start)break;
161             i++;
162         }
163         // if no start point is found return
164
if(i==graphArray.length)return;
165         
166         
167         ArrayList JavaDoc coordList=new ArrayList JavaDoc();
168         
169         int j = i;
170         while(j<graphArray.length){
171             if(graphArray[j].x>end){
172                 break;
173             }
174             coordList.add(graphArray[j]);
175             j++;
176         }
177         
178         // this is added so that the last coordinate corresponds to the end
179
// of the timeslice
180
if(coordList.size()>0){
181             Coord lastCoord = (Coord)coordList.get(coordList.size()-1);
182             boolean lastBool = lastCoord.y==1 ? true : false;
183             coordList.add(new Coord(end,lastBool));
184         }
185         
186         // copy of the list into arrays
187
sliceX = new int [coordList.size()];
188         sliceY = new int [coordList.size()];
189         Coord c;
190         for(int k = 0; k<coordList.size(); k++){
191             c = (Coord)coordList.get(k);
192             sliceX[k] = new Long JavaDoc((c.x-start)/1000).intValue();
193             sliceY[k] = c.y;
194         }
195     }
196     
197     private void addAction(long ts,boolean act){
198         Coord c1 = new Coord(ts,activatedB);
199         Coord c2 = new Coord(ts,act);
200         actions.add(c1);
201         actions.add(c2);
202     }
203     
204 }
205
Popular Tags