1 6 7 package org.netbeans.modules.piaget.analyze; 8 9 import java.util.Date ; 10 import java.util.ArrayList ; 11 import java.awt.Color ; 12 13 19 public class WindowData implements Comparable { 20 21 24 public String name; 25 26 29 public boolean editor; 30 31 34 public long open; 35 36 39 public long activated; 40 41 44 public long openTime, activatedTime; 45 46 public boolean activatedB, openB; 47 Date start; 48 ArrayList actions; 49 Coord[] graphArray; 50 51 54 public int[] sliceX; 55 56 59 public int[] sliceY; 60 63 public Color chartColor; 64 65 66 72 public WindowData(boolean editor, String 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 (); 79 } 80 81 85 public void open(long ts){ 86 if(openB==true) { 87 return; 89 } 90 openTime = ts; 91 if(start==null){ 92 start = new Date (ts); 93 } 94 openB = true; 95 } 96 97 101 public void close(long ts){ 102 if(openB)open += ts-openTime; 103 else { 104 } 106 openB = false; 107 } 108 109 113 public void activated(long ts){ 114 addAction(ts, true); 115 activatedTime = ts; 116 activatedB = true; 117 } 118 119 123 public void deactivated(long ts){ 124 addAction(ts, false); 125 if(activatedB)activated += ts-activatedTime; 126 activatedB = false; 127 } 128 129 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 145 public int compareTo(Object o){ 146 return name.compareTo(((WindowData)o).name); 147 } 148 149 156 public void computeSlice(long start,long end){ 157 int i = 0; 158 while(i<graphArray.length){ 160 if(graphArray[i].x>start)break; 161 i++; 162 } 163 if(i==graphArray.length)return; 165 166 167 ArrayList coordList=new ArrayList (); 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 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 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 ((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 |