19 |
19 |
20 import java.awt.Dimension; |
20 import java.awt.Dimension; |
21 import java.awt.event.ActionEvent; |
21 import java.awt.event.ActionEvent; |
22 import java.awt.event.ActionListener; |
22 import java.awt.event.ActionListener; |
23 import java.text.DecimalFormat; |
23 import java.text.DecimalFormat; |
|
24 import java.text.MessageFormat; |
24 import java.util.Enumeration; |
25 import java.util.Enumeration; |
25 import java.util.Hashtable; |
26 import java.util.Hashtable; |
|
27 import java.util.Iterator; |
|
28 import java.util.Map; |
|
29 import java.util.Set; |
26 import java.util.Vector; |
30 import java.util.Vector; |
|
31 import java.util.Map.Entry; |
27 |
32 |
28 import org.eclipse.draw2d.ColorConstants; |
33 import org.eclipse.draw2d.ColorConstants; |
29 import org.eclipse.draw2d.FigureCanvas; |
34 import org.eclipse.draw2d.FigureCanvas; |
30 import org.eclipse.draw2d.Graphics; |
35 import org.eclipse.draw2d.Graphics; |
31 import org.eclipse.draw2d.MouseEvent; |
36 import org.eclipse.draw2d.MouseEvent; |
96 // private int[] capaValues; |
101 // private int[] capaValues; |
97 private double maxAmps = Integer.MIN_VALUE; |
102 private double maxAmps = Integer.MIN_VALUE; |
98 private double minAmps = Integer.MAX_VALUE; |
103 private double minAmps = Integer.MAX_VALUE; |
99 private double maxPower = 0.0; |
104 private double maxPower = 0.0; |
100 private boolean mSelecting = false; |
105 private boolean mSelecting = false; |
|
106 |
|
107 private static final int EVENT_TOPOFLINE = 50; |
|
108 private static final int EVENT_BOTTOMOFLINE = 30; |
|
109 private static final int EVENT_RECTWIDTH = 5; |
|
110 private static final int EVENT_RECTHEIGHT = 5; |
101 |
111 |
102 // used when determining when to draw the text over the power bar. |
112 // used when determining when to draw the text over the power bar. |
103 private int leftBorder = 0; |
113 private int leftBorder = 0; |
104 |
114 |
105 private static int xLegendHeight = 20; |
115 private static int xLegendHeight = 20; |
109 private static DecimalFormat powerFormat = new DecimalFormat(Messages.getString("powerFormat")); //$NON-NLS-1$ |
119 private static DecimalFormat powerFormat = new DecimalFormat(Messages.getString("powerFormat")); //$NON-NLS-1$ |
110 private static DecimalFormat voltageFormat = new DecimalFormat(Messages.getString("voltageFormat")); //$NON-NLS-1$ |
120 private static DecimalFormat voltageFormat = new DecimalFormat(Messages.getString("voltageFormat")); //$NON-NLS-1$ |
111 |
121 |
112 private int uid; |
122 private int uid; |
113 |
123 |
114 protected static int SAMPLES_AT_ONE_TIME = 1000; |
124 protected final static int SAMPLES_AT_ONE_TIME = 1000; |
115 protected int stringTime; |
125 protected int stringTime; |
|
126 private boolean backlightEnabled; |
116 |
127 |
117 |
128 |
118 // class to pass sample data to the save wizard |
129 // class to pass sample data to the save wizard |
119 public class SaveSampleString implements ISaveSamples { |
130 public class SaveSampleString implements ISaveSamples { |
120 int startTime; |
131 int startTime; |
164 } |
179 } |
165 |
180 |
166 double oldCurrent = -1; |
181 double oldCurrent = -1; |
167 double oldVoltage = -1; |
182 double oldVoltage = -1; |
168 double oldCapacity = -1; |
183 double oldCapacity = -1; |
|
184 int oldBacklight = -1; |
169 String string = ""; //$NON-NLS-1$ |
185 String string = ""; //$NON-NLS-1$ |
170 |
186 |
171 if (this.trace.isComplete()) { |
187 if (this.trace.isComplete()) { |
172 for ( ; |
188 for ( ; |
173 (this.stringTime < endTime + 1) && (count > 0) && (this.stringTime < sampleVector.size()); |
189 (this.stringTime < endTime + 1) && (count > 0) && (this.stringTime < sampleVector.size()); |
174 this.stringTime++) { |
190 this.stringTime++) { |
175 PwrSample sample = (PwrSample) sampleVector.get(stringTime); |
191 PwrSample sample = (PwrSample) sampleVector.get(stringTime); |
176 double current = sample.current; |
192 double current = sample.current; |
177 double voltage = sample.voltage; |
193 double voltage = sample.voltage; |
178 double capacity = sample.capacity; |
194 double capacity = sample.capacity; |
|
195 int backlight = sample.backlight; |
179 |
196 |
180 if ((oldCurrent != current) || (oldVoltage != voltage) || (oldCapacity != capacity)) { |
197 if ((oldCurrent != current) || (oldVoltage != voltage) || (oldCapacity != capacity)|| (oldBacklight != backlight)) { |
181 string = Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
198 if(backlightEnabled){ |
|
199 string = Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + Messages.getString("PowerTraceGraph.comma") + PwrSample.getBacklightInformation(backlight) +"\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
|
200 }else{ |
|
201 string = Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
202 } |
182 oldCurrent = current; |
203 oldCurrent = current; |
183 oldVoltage = voltage; |
204 oldVoltage = voltage; |
184 oldCapacity = capacity; |
205 oldCapacity = capacity; |
|
206 oldBacklight = backlight; |
185 } |
207 } |
186 |
208 |
187 returnString += sample.sampleSynchTime + string; |
209 returnString += sample.sampleSynchTime + string; |
188 count--; |
210 count--; |
189 } |
211 } |
207 break; |
229 break; |
208 |
230 |
209 double current = sample.current; |
231 double current = sample.current; |
210 double voltage = sample.voltage; |
232 double voltage = sample.voltage; |
211 double capacity = sample.capacity; |
233 double capacity = sample.capacity; |
|
234 int backlight = sample.backlight; |
212 |
235 |
213 returnString += sample.sampleSynchTime + Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
236 if(backlightEnabled){ |
|
237 returnString += sample.sampleSynchTime + Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + Messages.getString("PowerTraceGraph.comma") + PwrSample.getBacklightInformation(backlight) +"\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
|
238 }else{ |
|
239 returnString += sample.sampleSynchTime + Messages.getString("PowerTraceGraph.comma") + (int) current + Messages.getString("PowerTraceGraph.comma") + (int) voltage + Messages.getString("PowerTraceGraph.comma") + (int) capacity + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
240 } |
|
241 |
214 count--; |
242 count--; |
215 } |
243 } |
216 } |
244 } |
217 |
245 |
218 // check if we have returned everything |
246 // check if we have returned everything |
444 |
476 |
445 // draws the same selection as the Address/Thread trace |
477 // draws the same selection as the Address/Thread trace |
446 this.drawSelectionSection(graphics, PowerTraceGraph.xLegendHeight); |
478 this.drawSelectionSection(graphics, PowerTraceGraph.xLegendHeight); |
447 |
479 |
448 if (mShowPowerLine) |
480 if (mShowPowerLine) |
449 this.drawPowerLine(graphics); |
481 this.drawPowerLine(graphics); |
450 } |
482 |
451 |
483 if(backlightEnabled){ |
|
484 drawBacklightEvents(graphics); |
|
485 } |
|
486 } |
|
487 |
|
488 private void drawBacklightEvents(Graphics graphics){ |
|
489 Map<Long, Integer> backLightChangePoints = ((PwrTrace)getTrace()).getBacklightChangePoints(); |
|
490 Set<Entry<Long, Integer>> entrySet = backLightChangePoints.entrySet(); |
|
491 Iterator<Entry<Long, Integer>> iterator = entrySet.iterator(); |
|
492 int lastXLabelEnd = -1; //the x coordinate at which the last drawn label ended |
|
493 int height = this.getVisualSize().height; |
|
494 String eventName = ""; //$NON-NLS-1$ |
|
495 while(iterator.hasNext()){ |
|
496 Entry<Long, Integer> entry = iterator.next(); |
|
497 double scale = this.getScale(); |
|
498 int x = (int)(entry.getKey()/scale); |
|
499 graphics.setForegroundColor(ColorConstants.red); |
|
500 graphics.drawLine(x, height - EVENT_TOPOFLINE, x, height - EVENT_BOTTOMOFLINE); |
|
501 |
|
502 eventName = Messages.getString("PowerTraceGraph.backlightGraphItem") + PwrSample.getBacklightInformation(entry.getValue()); //$NON-NLS-1$ |
|
503 |
|
504 graphics.setFont(PIPageEditor.helvetica_8); |
|
505 |
|
506 GC gc = new GC(PIPageEditor.currentPageEditor().getSite().getShell()); |
|
507 Point point = gc.stringExtent(eventName); |
|
508 gc.dispose(); |
|
509 |
|
510 int xLabelStart = x - (point.x / 2); |
|
511 if(xLabelStart < 0){ |
|
512 xLabelStart = 0; |
|
513 } |
|
514 if (xLabelStart > lastXLabelEnd){ //only draw label if it doesn't overlap with previous |
|
515 graphics.setForegroundColor(ColorConstants.red); |
|
516 graphics.drawString(eventName, xLabelStart, height - EVENT_BOTTOMOFLINE + 3 + EVENT_RECTHEIGHT); |
|
517 lastXLabelEnd = x + (point.x / 2); |
|
518 } |
|
519 |
|
520 graphics.setBackgroundColor(ColorConstants.red); |
|
521 |
|
522 graphics.drawLine(x , height - EVENT_BOTTOMOFLINE + 1, x, height - EVENT_BOTTOMOFLINE + 2); |
|
523 graphics.fillRectangle(x - (EVENT_RECTWIDTH / 2), height - EVENT_BOTTOMOFLINE + 3, |
|
524 EVENT_RECTWIDTH, EVENT_RECTHEIGHT); |
|
525 } |
|
526 } |
|
527 |
452 public void repaint() |
528 public void repaint() |
453 { |
529 { |
454 this.parentComponent.repaintComponent(); |
530 this.parentComponent.repaintComponent(); |
455 } |
531 } |
456 |
532 |
457 private void showPowerValueAtX(MouseEvent me) |
533 private void showPowerValueAtX(MouseEvent me) |
458 { |
534 { |
459 if (me.y > this.getVisualSizeY() - PowerTraceGraph.xLegendHeight) { |
535 if (me.y > this.getVisualSizeY() - PowerTraceGraph.xLegendHeight) { |
460 this.setToolTipText(null); |
536 handleBacklightMouseEvents(me); |
461 return; |
537 return; |
462 } |
538 } |
463 |
539 |
464 // scale the value of x |
540 // scale the value of x |
465 int x = (int) (me.x * this.getScale() + 0.5); |
541 int x = (int) (me.x * this.getScale() + 0.5); |
466 |
542 |
467 if (x > (int) (PIPageEditor.currentPageEditor().getMaxEndTime() * 1000 + 0.0005)) { |
543 if (x > (int) (PIPageEditor.currentPageEditor().getMaxEndTime() * 1000 + 0.0005)) { |
468 this.setToolTipText(null); |
544 handleBacklightMouseEvents(me); |
469 return; |
545 return; |
470 } |
546 } |
471 |
547 |
472 if (x > trace.getLastSampleNumber()) |
548 if (x > trace.getLastSampleNumber()) |
473 x = trace.getLastSampleNumber(); |
549 x = trace.getLastSampleNumber(); |
1172 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITitleBarMenu#getContextHelpId() |
1251 * @see com.nokia.carbide.cpp.internal.pi.plugin.model.ITitleBarMenu#getContextHelpId() |
1173 */ |
1252 */ |
1174 public String getContextHelpId() { |
1253 public String getContextHelpId() { |
1175 return PowerPlugin.HELP_CONTEXT_ID_MAIN_PAGE; |
1254 return PowerPlugin.HELP_CONTEXT_ID_MAIN_PAGE; |
1176 } |
1255 } |
|
1256 |
|
1257 private void handleBacklightMouseEvents(MouseEvent me) { |
|
1258 if (!backlightEnabled){ |
|
1259 setToolTipText(null); |
|
1260 return; |
|
1261 } |
|
1262 long x = me.x; |
|
1263 long y = me.y; |
|
1264 |
|
1265 int height = this.getVisualSize().height; |
|
1266 |
|
1267 // make sure we're in the right area of the graph window |
|
1268 if ((y < height - EVENT_BOTTOMOFLINE) || (y > height - EVENT_BOTTOMOFLINE + EVENT_RECTHEIGHT + 2)) |
|
1269 return; |
|
1270 |
|
1271 double scale = this.getScale(); |
|
1272 |
|
1273 String tooltip = ""; //$NON-NLS-1$ |
|
1274 |
|
1275 Map<Long, Integer> backLightChangePoints = ((PwrTrace)getTrace()).getBacklightChangePoints(); |
|
1276 Set<Entry<Long, Integer>> entrySet = backLightChangePoints.entrySet(); |
|
1277 Iterator<Entry<Long, Integer>> iterator = entrySet.iterator(); |
|
1278 |
|
1279 while(iterator.hasNext()){ |
|
1280 Entry<Long, Integer> entry = iterator.next(); |
|
1281 |
|
1282 long xSample = (long)(entry.getKey()/scale + 0.5); |
|
1283 |
|
1284 // samples are in timestamp order, so stop when xSample + EVENT_RECTWIDTH is too high |
|
1285 if (x < xSample - EVENT_RECTWIDTH) |
|
1286 break; |
|
1287 |
|
1288 if ((x >= xSample - EVENT_RECTWIDTH) && (x <= xSample + EVENT_RECTWIDTH)) |
|
1289 { |
|
1290 String parsedName = PwrSample.getBacklightInformation(entry.getValue()); |
|
1291 if (tooltip.length() > 0){ |
|
1292 tooltip += Messages.getString("PowerTraceGraph.newLine"); //$NON-NLS-1$ |
|
1293 } |
|
1294 tooltip += MessageFormat.format(Messages.getString("PowerTraceGraph.backlightTooltip"), parsedName,entry.getKey()/1000.0 ); //$NON-NLS-1$ |
|
1295 |
|
1296 } |
|
1297 } |
|
1298 if (tooltip.length() > 0) { |
|
1299 setToolTipText(tooltip); |
|
1300 } |
|
1301 else{ |
|
1302 setToolTipText(null); |
|
1303 } |
|
1304 } |
1177 } |
1305 } |