|
Lines 35-74
Link Here
|
| 35 |
import org.eclipse.swt.events.MouseEvent; |
35 |
import org.eclipse.swt.events.MouseEvent; |
| 36 |
import org.eclipse.swt.events.MouseListener; |
36 |
import org.eclipse.swt.events.MouseListener; |
| 37 |
import org.eclipse.swt.events.MouseMoveListener; |
37 |
import org.eclipse.swt.events.MouseMoveListener; |
|
|
38 |
import org.eclipse.swt.events.MouseTrackListener; |
| 39 |
import org.eclipse.swt.events.PaintEvent; |
| 38 |
import org.eclipse.swt.events.SelectionEvent; |
40 |
import org.eclipse.swt.events.SelectionEvent; |
| 39 |
import org.eclipse.swt.events.SelectionListener; |
41 |
import org.eclipse.swt.events.SelectionListener; |
|
|
42 |
import org.eclipse.swt.graphics.Cursor; |
| 40 |
import org.eclipse.swt.graphics.GC; |
43 |
import org.eclipse.swt.graphics.GC; |
|
|
44 |
import org.eclipse.swt.graphics.Image; |
| 41 |
import org.eclipse.swt.graphics.Point; |
45 |
import org.eclipse.swt.graphics.Point; |
| 42 |
import org.eclipse.swt.graphics.Rectangle; |
46 |
import org.eclipse.swt.graphics.Rectangle; |
| 43 |
import org.eclipse.swt.widgets.Composite; |
47 |
import org.eclipse.swt.widgets.Composite; |
| 44 |
|
48 |
|
| 45 |
public class ThreadStatesCtrl extends TraceCtrl implements FocusListener, |
49 |
public class ThreadStatesCtrl extends TraceCtrl implements FocusListener, |
| 46 |
KeyListener, MouseMoveListener, MouseListener, ControlListener, |
50 |
KeyListener, MouseMoveListener, MouseListener, ControlListener, |
| 47 |
SelectionListener { |
51 |
SelectionListener, MouseTrackListener { |
| 48 |
|
52 |
|
| 49 |
private ITimeDataProvider _timeProvider; |
53 |
private ITimeDataProvider _timeProvider; |
| 50 |
boolean _isInFocus = false; |
54 |
private boolean _isInFocus = false; |
|
|
55 |
private boolean _isDragCursor3 = false; |
| 56 |
private boolean _mouseHover = false; |
| 51 |
private int _topItem = 0; |
57 |
private int _topItem = 0; |
| 52 |
private int _itemHeight = 18; |
58 |
private int _itemHeight = 18; |
| 53 |
private int _dragState = 0; |
59 |
private int _dragState = 0; |
| 54 |
private int _hitIdx = 0; |
60 |
private int _hitIdx = 0; |
| 55 |
private int _dragX0 = 0; |
61 |
private int _dragX0 = 0; |
| 56 |
private int _dragX = 0; |
62 |
private int _dragX = 0; |
|
|
63 |
private int _idealNameWidth = 0; |
| 57 |
private double _timeStep = 0.01; |
64 |
private double _timeStep = 0.01; |
| 58 |
private double _time0bak; |
65 |
private double _time0bak; |
| 59 |
private double _time1bak; |
66 |
private double _time1bak; |
| 60 |
private ItemData _data = new ItemData(); |
67 |
private ItemData _data = new ItemData(); |
| 61 |
private ArrayList _selectionListeners; |
68 |
private ArrayList _selectionListeners; |
| 62 |
|
69 |
private Rectangle _rect0 = new Rectangle(0, 0, 0, 0); |
|
|
70 |
private Rectangle _rect1 = new Rectangle(0, 0, 0, 0); |
| 71 |
private Cursor _dragCursor3; |
| 72 |
|
| 63 |
public ThreadStatesCtrl(Composite parent, TraceColorScheme colors) { |
73 |
public ThreadStatesCtrl(Composite parent, TraceColorScheme colors) { |
| 64 |
super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.V_SCROLL); |
74 |
super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED); |
| 65 |
addFocusListener(this); |
75 |
addFocusListener(this); |
| 66 |
addMouseListener(this); |
76 |
addMouseListener(this); |
| 67 |
addMouseMoveListener(this); |
77 |
addMouseMoveListener(this); |
|
|
78 |
addMouseTrackListener(this); |
| 68 |
addKeyListener(this); |
79 |
addKeyListener(this); |
| 69 |
addControlListener(this); |
80 |
addControlListener(this); |
| 70 |
getVerticalBar().addSelectionListener(this); |
81 |
getVerticalBar().addSelectionListener(this); |
| 71 |
getHorizontalBar().addSelectionListener(this); |
82 |
getHorizontalBar().addSelectionListener(this); |
|
|
83 |
_dragCursor3 = new Cursor(parent.getDisplay(), SWT.CURSOR_SIZEWE); |
| 84 |
} |
| 85 |
|
| 86 |
public void dispose() { |
| 87 |
super.dispose(); |
| 88 |
_dragCursor3.dispose(); |
| 72 |
} |
89 |
} |
| 73 |
|
90 |
|
| 74 |
public void setTimeProvider(ITimeDataProvider timeProvider) { |
91 |
public void setTimeProvider(ITimeDataProvider timeProvider) { |
|
Lines 141-147
Link Here
|
| 141 |
|
158 |
|
| 142 |
boolean ensureVisibleItem(int idx, boolean redraw) { |
159 |
boolean ensureVisibleItem(int idx, boolean redraw) { |
| 143 |
boolean changed = false; |
160 |
boolean changed = false; |
| 144 |
if (idx < 0 || idx >= _data._items.length) |
161 |
if (idx < 0) { |
|
|
162 |
for (idx = 0; idx < _data._items.length; idx++) { |
| 163 |
if (((Item)_data._items[idx])._selected) |
| 164 |
break; |
| 165 |
} |
| 166 |
} |
| 167 |
if (idx >= _data._items.length) |
| 145 |
return changed; |
168 |
return changed; |
| 146 |
if (idx < _topItem) { |
169 |
if (idx < _topItem) { |
| 147 |
_topItem = idx; |
170 |
_topItem = idx; |
|
Lines 162-210
Link Here
|
| 162 |
return changed; |
185 |
return changed; |
| 163 |
} |
186 |
} |
| 164 |
|
187 |
|
| 165 |
static TRCThreadEvent getFirstEvent(TRCThread thread) { |
|
|
| 166 |
EList list = thread.getThreadEvents(); |
| 167 |
TRCThreadEvent event = null; |
| 168 |
if (!list.isEmpty()) |
| 169 |
event = (TRCThreadEvent) list.get(0); |
| 170 |
return event; |
| 171 |
} |
| 172 |
|
| 173 |
static TRCThreadEvent findEvent(TRCThread thread, double time, int n) { |
| 174 |
EList list = thread.getThreadEvents(); |
| 175 |
Iterator it = list.iterator(); |
| 176 |
TRCThreadEvent event = null; |
| 177 |
TRCThreadEvent prevEvent = null; |
| 178 |
TRCThreadEvent nextEvent = null; |
| 179 |
if (it.hasNext()) { |
| 180 |
event = (TRCThreadEvent) it.next(); |
| 181 |
double currTime = event.getTime(); |
| 182 |
if (time < currTime) { |
| 183 |
if (1 != n) |
| 184 |
event = null; |
| 185 |
return event; |
| 186 |
} |
| 187 |
while (it.hasNext()) { |
| 188 |
nextEvent = (TRCThreadEvent) it.next(); |
| 189 |
double nextTime = nextEvent.getTime(); |
| 190 |
if (currTime <= time && time < nextTime) { |
| 191 |
if (1 == n) |
| 192 |
event = nextEvent; |
| 193 |
else if (-1 == n) |
| 194 |
event = prevEvent; |
| 195 |
return event; |
| 196 |
} |
| 197 |
prevEvent = event; |
| 198 |
event = nextEvent; |
| 199 |
} |
| 200 |
} |
| 201 |
if (1 == n) |
| 202 |
event = null; |
| 203 |
else if (-1 == n) |
| 204 |
event = prevEvent; |
| 205 |
return event; |
| 206 |
} |
| 207 |
|
| 208 |
static class Selection implements IStructuredSelection { |
188 |
static class Selection implements IStructuredSelection { |
| 209 |
|
189 |
|
| 210 |
List list = new ArrayList(); |
190 |
List list = new ArrayList(); |
|
Lines 241-247
Link Here
|
| 241 |
TRCThread thread = getSelectedThread(); |
221 |
TRCThread thread = getSelectedThread(); |
| 242 |
if (null != thread && null != _timeProvider) { |
222 |
if (null != thread && null != _timeProvider) { |
| 243 |
double selectedTime = _timeProvider.getSelectedTime(); |
223 |
double selectedTime = _timeProvider.getSelectedTime(); |
| 244 |
TRCThreadEvent event = findEvent(thread, selectedTime, 0); |
224 |
TRCThreadEvent event = Utils.findEvent(thread, selectedTime, 0); |
| 245 |
if (null != event) |
225 |
if (null != event) |
| 246 |
sel.list.add(event); |
226 |
sel.list.add(event); |
| 247 |
} |
227 |
} |
|
Lines 307-312
Link Here
|
| 307 |
} |
287 |
} |
| 308 |
} |
288 |
} |
| 309 |
if (changed) { |
289 |
if (changed) { |
|
|
290 |
ensureVisibleItem(-1, false); |
| 310 |
redraw(); |
291 |
redraw(); |
| 311 |
fireSelectionChanged(); |
292 |
fireSelectionChanged(); |
| 312 |
} |
293 |
} |
|
Lines 322-332
Link Here
|
| 322 |
double endTime = _timeProvider.getEndTime(); |
303 |
double endTime = _timeProvider.getEndTime(); |
| 323 |
TRCThreadEvent nextEvent; |
304 |
TRCThreadEvent nextEvent; |
| 324 |
if (-1 == n && selectedTime >= endTime) |
305 |
if (-1 == n && selectedTime >= endTime) |
| 325 |
nextEvent = findEvent(thread, selectedTime, 0); |
306 |
nextEvent = Utils.findEvent(thread, selectedTime, 0); |
| 326 |
else |
307 |
else |
| 327 |
nextEvent = findEvent(thread, selectedTime, n); |
308 |
nextEvent = Utils.findEvent(thread, selectedTime, n); |
| 328 |
if (null == nextEvent && -1 == n) |
309 |
if (null == nextEvent && -1 == n) |
| 329 |
nextEvent = getFirstEvent(thread); |
310 |
nextEvent = Utils.getFirstEvent(thread); |
| 330 |
if (null != nextEvent) { |
311 |
if (null != nextEvent) { |
| 331 |
_timeProvider.setSelectedTime(nextEvent.getTime(), true); |
312 |
_timeProvider.setSelectedTime(nextEvent.getTime(), true); |
| 332 |
fireSelectionChanged(); |
313 |
fireSelectionChanged(); |
|
Lines 389-397
Link Here
|
| 389 |
} |
370 |
} |
| 390 |
|
371 |
|
| 391 |
int hitTest(int x, int y) { |
372 |
int hitTest(int x, int y) { |
| 392 |
if (x < 0) |
373 |
if (x < 0 || y < 0) |
| 393 |
return -1; |
|
|
| 394 |
if (y < 0) |
| 395 |
return -1; |
374 |
return -1; |
| 396 |
int hit = -1; |
375 |
int hit = -1; |
| 397 |
int idx = y / _itemHeight; |
376 |
int idx = y / _itemHeight; |
|
Lines 401-406
Link Here
|
| 401 |
return hit; |
380 |
return hit; |
| 402 |
} |
381 |
} |
| 403 |
|
382 |
|
|
|
383 |
int hitSplitTest(int x, int y) { |
| 384 |
if (x < 0 || y < 0 || null == _timeProvider) |
| 385 |
return -1; |
| 386 |
int w = 4; |
| 387 |
int hit = -1; |
| 388 |
int nameWidth = _timeProvider.getNameSpace(); |
| 389 |
if (x > nameWidth - w && x < nameWidth + w) |
| 390 |
hit = 1; |
| 391 |
return hit; |
| 392 |
} |
| 393 |
|
| 394 |
public Item getItem(Point pt) { |
| 395 |
int idx = hitTest(pt.x, pt.y); |
| 396 |
return idx >= 0 ? (Item)_data._items[idx] : null; |
| 397 |
} |
| 398 |
|
| 404 |
double hitTimeTest(int x, int y) { |
399 |
double hitTimeTest(int x, int y) { |
| 405 |
if (null == _timeProvider) |
400 |
if (null == _timeProvider) |
| 406 |
return -1; |
401 |
return -1; |
|
Lines 408-417
Link Here
|
| 408 |
Point size = getCtrlSize(); |
403 |
Point size = getCtrlSize(); |
| 409 |
double time0 = _timeProvider.getTime0(); |
404 |
double time0 = _timeProvider.getTime0(); |
| 410 |
double time1 = _timeProvider.getTime1(); |
405 |
double time1 = _timeProvider.getTime1(); |
| 411 |
int left = _timeProvider.getNameSpace(); |
406 |
int nameWidth = _timeProvider.getNameSpace(); |
| 412 |
x -= left; |
407 |
x -= nameWidth; |
| 413 |
if (x >= 0 && size.x >= left) { |
408 |
if (x >= 0 && size.x >= nameWidth) { |
| 414 |
hitTime = time0 + (time1 - time0) * x / (size.x - left); |
409 |
hitTime = time0 + (time1 - time0) * x / (size.x - nameWidth); |
| 415 |
} |
410 |
} |
| 416 |
return hitTime; |
411 |
return hitTime; |
| 417 |
} |
412 |
} |
|
Lines 460-537
Link Here
|
| 460 |
return size; |
455 |
return size; |
| 461 |
} |
456 |
} |
| 462 |
|
457 |
|
| 463 |
void getNameRect(Rectangle rect, Point size, int idx, int nameWidth) { |
458 |
void getNameRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) { |
| 464 |
idx -= _topItem; |
459 |
idx -= _topItem; |
| 465 |
rect.x = 0; |
460 |
rect.x = bound.x; |
| 466 |
rect.y = idx * _itemHeight; |
461 |
rect.y = bound.y + idx * _itemHeight; |
| 467 |
rect.width = nameWidth; |
462 |
rect.width = nameWidth; |
| 468 |
rect.height = _itemHeight; |
463 |
rect.height = _itemHeight; |
| 469 |
} |
464 |
} |
| 470 |
|
465 |
|
| 471 |
void getStatesRect(Rectangle rect, Point size, int idx, int nameWidth) { |
466 |
void getStatesRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) { |
| 472 |
idx -= _topItem; |
467 |
idx -= _topItem; |
| 473 |
rect.x = nameWidth; |
468 |
rect.x = bound.x + nameWidth; |
| 474 |
rect.y = idx * _itemHeight; |
469 |
rect.y = bound.y + idx * _itemHeight; |
| 475 |
rect.width = size.x - rect.x; |
470 |
rect.width = bound.width - rect.x; |
| 476 |
rect.height = _itemHeight; |
471 |
rect.height = _itemHeight; |
| 477 |
} |
472 |
} |
| 478 |
|
473 |
|
| 479 |
void paint(Rectangle rect, GC gc) { |
474 |
void paint(Rectangle bound, PaintEvent e) { |
| 480 |
Point size = getCtrlSize(); |
475 |
_itemHeight = getFontHeight() + 6; |
| 481 |
if (size.x < 2 || size.y < 2 || null == _timeProvider) |
476 |
if (bound.width < 2 || bound.height < 2 || null == _timeProvider) |
| 482 |
return; |
477 |
return; |
|
|
478 |
_idealNameWidth = 0; |
| 479 |
GC gc = e.gc; |
| 480 |
int nameWidth = _timeProvider.getNameSpace(); |
| 483 |
double time0 = _timeProvider.getTime0(); |
481 |
double time0 = _timeProvider.getTime0(); |
| 484 |
double time1 = _timeProvider.getTime1(); |
482 |
double time1 = _timeProvider.getTime1(); |
| 485 |
double endTime = _timeProvider.getEndTime(); |
483 |
double endTime = _timeProvider.getEndTime(); |
| 486 |
double selectedTime = _timeProvider.getSelectedTime(); |
484 |
double selectedTime = _timeProvider.getSelectedTime(); |
| 487 |
int left = _timeProvider.getNameSpace(); |
|
|
| 488 |
// draw thread states |
485 |
// draw thread states |
| 489 |
Object[] items = _data._items; |
486 |
Object[] items = _data._items; |
| 490 |
for (int i = _topItem; i < items.length; i++) { |
487 |
for (int i = _topItem; i < items.length; i++) { |
| 491 |
Item item = (Item) items[i]; |
488 |
Item item = (Item) items[i]; |
| 492 |
getNameRect(_rect0, size, i, left); |
489 |
getNameRect(_rect0, bound, i, nameWidth); |
| 493 |
if (_rect0.y >= size.y) |
490 |
if (_rect0.y >= bound.y + bound.height) |
| 494 |
break; |
491 |
break; |
| 495 |
if (item instanceof GroupItem) { |
492 |
if (item instanceof GroupItem) { |
| 496 |
getStatesRect(_rect1, size, i, left); |
493 |
getStatesRect(_rect1, bound, i, nameWidth); |
| 497 |
_rect0.width += _rect1.width; |
494 |
_rect0.width += _rect1.width; |
| 498 |
drawName(item, _rect0, gc); |
495 |
drawName(item, _rect0, gc); |
| 499 |
} else { |
496 |
} else { |
| 500 |
drawName(item, _rect0, gc); |
497 |
drawName(item, _rect0, gc); |
| 501 |
getStatesRect(_rect0, size, i, left); |
|
|
| 502 |
drawItemData(item, _rect0, time0, time1, endTime, selectedTime, |
| 503 |
gc); |
| 504 |
} |
498 |
} |
|
|
499 |
getStatesRect(_rect0, bound, i, nameWidth); |
| 500 |
drawItemData(item, _rect0, time0, time1, endTime, selectedTime, gc); |
| 505 |
} |
501 |
} |
| 506 |
// fill free canvas area |
502 |
// fill free canvas area |
| 507 |
_rect0.x = 0; |
503 |
_rect0.x = bound.x; |
| 508 |
_rect0.y += _rect0.height; |
504 |
_rect0.y += _rect0.height; |
| 509 |
_rect0.width = size.x; |
505 |
_rect0.width = bound.width; |
| 510 |
_rect0.height = size.y - _rect0.y; |
506 |
_rect0.height = bound.y + bound.height - _rect0.y; |
| 511 |
if (_rect0.y < size.y) { |
507 |
if (_rect0.y < bound.y + bound.height) { |
| 512 |
gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND)); |
508 |
gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND)); |
| 513 |
gc.fillRectangle(_rect0); |
509 |
gc.fillRectangle(_rect0); |
| 514 |
} |
510 |
} |
|
|
511 |
// draw drag line |
| 512 |
if (3 == _dragState) { |
| 513 |
gc.setForeground(_colors.getColor(TraceColorScheme.BLACK)); |
| 514 |
gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth, bound.y + bound.height - 1); |
| 515 |
} else if (0 == _dragState && _mouseHover) { |
| 516 |
gc.setForeground(_colors.getColor(TraceColorScheme.RED)); |
| 517 |
gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth, bound.y + bound.height - 1); |
| 518 |
} |
| 515 |
} |
519 |
} |
| 516 |
|
520 |
|
| 517 |
void drawName(Item item, Rectangle rect, GC gc) { |
521 |
void drawName(Item item, Rectangle rect, GC gc) { |
| 518 |
boolean group = item instanceof GroupItem; |
522 |
boolean group = item instanceof GroupItem; |
| 519 |
int elemHeight = rect.height / 2; |
523 |
int elemHeight = rect.height / 2; |
| 520 |
int elemWidth = elemHeight; |
524 |
int elemWidth = elemHeight; |
|
|
525 |
String name = item._name; |
| 521 |
if (group) { |
526 |
if (group) { |
| 522 |
gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus)); |
527 |
gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus)); |
| 523 |
gc.fillRectangle(rect); |
528 |
gc.fillRectangle(rect); |
| 524 |
if (item._selected && _isInFocus) { |
529 |
if (item._selected && _isInFocus) { |
| 525 |
gc.setForeground(_colors.getBkColor(item._selected, _isInFocus, false)); |
530 |
gc.setForeground(_colors.getBkColor(item._selected, _isInFocus, false)); |
| 526 |
//gc.drawRectangle(rect.x, rect.y, rect.width - 2, rect.height - 2); |
531 |
gc.drawRectangle(rect.x, rect.y, rect.width - 2, rect.height - 2); |
| 527 |
gc.drawRoundRectangle(rect.x, rect.y, rect.width - 2, rect.height - 2, 2, 2); |
|
|
| 528 |
} |
532 |
} |
| 529 |
gc.setForeground(_colors.getBkColor(false, false, false)); |
533 |
gc.setForeground(_colors.getBkColor(false, false, false)); |
| 530 |
gc.drawLine(rect.x, rect.y + rect.height - 1, rect.width - 1, rect.y + rect.height - 1); |
534 |
gc.drawLine(rect.x, rect.y + rect.height - 1, rect.width - 1, rect.y + rect.height - 1); |
| 531 |
gc.setForeground(_colors.getFgColorGroup(false, false)); |
535 |
gc.setForeground(_colors.getFgColorGroup(false, false)); |
| 532 |
gc.setBackground(_colors.getBkColor(false, false, false)); |
536 |
gc.setBackground(_colors.getBkColor(false, false, false)); |
| 533 |
Utils.init(_rect1, rect); |
537 |
Utils.init(_rect1, rect); |
| 534 |
_rect1.x += 2; |
538 |
_rect1.x += MARGIN; |
| 535 |
_rect1.y += (rect.height - elemHeight) / 2; |
539 |
_rect1.y += (rect.height - elemHeight) / 2; |
| 536 |
_rect1.width = elemWidth; |
540 |
_rect1.width = elemWidth; |
| 537 |
_rect1.height = elemHeight; |
541 |
_rect1.height = elemHeight; |
|
Lines 544-571
Link Here
|
| 544 |
gc.drawLine(p, _rect1.y + 2, p, _rect1.y + _rect1.height - 3); |
548 |
gc.drawLine(p, _rect1.y + 2, p, _rect1.y + _rect1.height - 3); |
| 545 |
} |
549 |
} |
| 546 |
gc.setForeground(_colors.getFgColorGroup(item._selected, _isInFocus)); |
550 |
gc.setForeground(_colors.getFgColorGroup(item._selected, _isInFocus)); |
| 547 |
elemWidth+= 4; |
551 |
elemWidth+= MARGIN; |
| 548 |
} else { |
552 |
} else { |
| 549 |
gc.setBackground(_colors.getBkColor(item._selected, _isInFocus, true)); |
553 |
gc.setBackground(_colors.getBkColor(item._selected, _isInFocus, true)); |
| 550 |
gc.setForeground(_colors.getFgColor(item._selected, _isInFocus)); |
554 |
gc.setForeground(_colors.getFgColor(item._selected, _isInFocus)); |
| 551 |
gc.fillRectangle(rect); |
555 |
gc.fillRectangle(rect); |
|
|
556 |
Utils.init(_rect1, rect); |
| 557 |
_rect1.x += MARGIN; |
| 558 |
// draw icon |
| 559 |
TRCThread thread = ((ThreadItem)item)._thread; |
| 560 |
Image img = Utils.getItemImage(thread); |
| 561 |
if (null != img) { |
| 562 |
_rect1.y += (rect.height - img.getImageData().height) / 2; |
| 563 |
gc.drawImage(img, _rect1.x, _rect1.y); |
| 564 |
} |
| 565 |
elemWidth = SMALL_ICON_SIZE; |
| 566 |
// cut long string with "..." |
| 567 |
Point size = gc.stringExtent(name); |
| 568 |
if (_idealNameWidth < size.x) |
| 569 |
_idealNameWidth = size.x; |
| 570 |
int width = rect.width - MARGIN - MARGIN - elemWidth; |
| 571 |
int cuts = 0; |
| 572 |
while (size.x > width && name.length() > 1) { |
| 573 |
cuts++; |
| 574 |
name = name.substring(0, name.length() - 1); |
| 575 |
size = gc.stringExtent(name + "..."); |
| 576 |
} |
| 577 |
if (cuts > 0) |
| 578 |
name += "..."; |
| 579 |
elemWidth+= MARGIN; |
| 552 |
} |
580 |
} |
| 553 |
Utils.init(_rect1, rect); |
581 |
Utils.init(_rect1, rect); |
| 554 |
int leftMargin = 4 + (group ? elemWidth : 0); |
582 |
int leftMargin = MARGIN + elemWidth; |
| 555 |
_rect1.x += leftMargin; |
583 |
_rect1.x += leftMargin; |
| 556 |
_rect1.width -= leftMargin; |
584 |
_rect1.width -= leftMargin; |
| 557 |
int textWidth = 0; |
585 |
int textWidth = 0; |
| 558 |
// draw text |
586 |
// draw text |
| 559 |
if (_rect1.width > 0) { |
587 |
if (_rect1.width > 0) { |
| 560 |
String name = group ? item._name + " (group}" : item._name; |
588 |
_rect1.y += 2; |
| 561 |
textWidth = Utils.drawText(gc, name, _rect1, true) + 8; |
589 |
textWidth = Utils.drawText(gc, name, _rect1, true) + 8; |
|
|
590 |
_rect1.y -= 2; |
| 562 |
} |
591 |
} |
| 563 |
// draw middle line |
592 |
// draw middle line |
| 564 |
Utils.init(_rect1, rect); |
593 |
if (_rect1.width > 0 && !group) { |
| 565 |
_rect1.x += textWidth; |
594 |
Utils.init(_rect1, rect); |
| 566 |
_rect1.width -= textWidth; |
595 |
_rect1.x += leftMargin + textWidth; |
| 567 |
gc.setForeground(_colors.getColor(TraceColorScheme.LIGHT_LINE)); |
596 |
_rect1.width -= textWidth; |
| 568 |
if (_rect1.width > 0 && item instanceof ThreadItem) { |
597 |
gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE)); |
| 569 |
int midy = _rect1.y + _rect1.height / 2; |
598 |
int midy = _rect1.y + _rect1.height / 2; |
| 570 |
gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); |
599 |
gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); |
| 571 |
} |
600 |
} |
|
Lines 586-595
Link Here
|
| 586 |
Utils.init(_rect1, rect); |
615 |
Utils.init(_rect1, rect); |
| 587 |
boolean selected = item._selected; |
616 |
boolean selected = item._selected; |
| 588 |
double K = (double) rect.width / (time1 - time0); |
617 |
double K = (double) rect.width / (time1 - time0); |
|
|
618 |
boolean group = item instanceof GroupItem; |
| 589 |
|
619 |
|
| 590 |
if (item instanceof GroupItem) { |
620 |
if (group) { |
| 591 |
gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); |
621 |
//gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus)); |
| 592 |
gc.fillRectangle(rect); |
622 |
//gc.fillRectangle(rect); |
| 593 |
} else if (item instanceof ThreadItem) { |
623 |
} else if (item instanceof ThreadItem) { |
| 594 |
TRCThread thread = ((ThreadItem) item)._thread; |
624 |
TRCThread thread = ((ThreadItem) item)._thread; |
| 595 |
int x0 = rect.x; |
625 |
int x0 = rect.x; |
|
Lines 612-623
Link Here
|
| 612 |
// fill space before first event |
642 |
// fill space before first event |
| 613 |
if (x0 > rect.x) { |
643 |
if (x0 > rect.x) { |
| 614 |
_rect1.width = (x0 <= xEnd ? x0 : xEnd) - _rect1.x; |
644 |
_rect1.width = (x0 <= xEnd ? x0 : xEnd) - _rect1.x; |
| 615 |
gc.setBackground(_colors.getBkColor(selected, _isInFocus, |
645 |
gc.setBackground(_colors.getBkColor(selected, _isInFocus, false)); |
| 616 |
false)); |
|
|
| 617 |
gc.fillRectangle(_rect1); |
646 |
gc.fillRectangle(_rect1); |
| 618 |
// draw middle line |
647 |
// draw middle line |
| 619 |
gc.setForeground(_colors |
648 |
gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE)); |
| 620 |
.getColor(TraceColorScheme.MID_LINE)); |
|
|
| 621 |
int midy = _rect1.y + _rect1.height / 2; |
649 |
int midy = _rect1.y + _rect1.height / 2; |
| 622 |
gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); |
650 |
gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy); |
| 623 |
} |
651 |
} |
|
Lines 667-673
Link Here
|
| 667 |
|
695 |
|
| 668 |
// draw focus ares |
696 |
// draw focus ares |
| 669 |
Utils.init(_rect1, rect); |
697 |
Utils.init(_rect1, rect); |
| 670 |
gc.setForeground(_colors.getBkColor(false, false, false)); |
698 |
gc.setForeground(_colors.getBkColor(selected, _isInFocus, false)); |
| 671 |
int y = _rect1.y; |
699 |
int y = _rect1.y; |
| 672 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
700 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
| 673 |
y++; |
701 |
y++; |
|
Lines 680-694
Link Here
|
| 680 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
708 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
| 681 |
y--; |
709 |
y--; |
| 682 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
710 |
gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y); |
| 683 |
// gc.setForeground(_colors.getBkColor(selected, _isInFocus, |
|
|
| 684 |
// false)); |
| 685 |
} |
711 |
} |
| 686 |
|
712 |
|
| 687 |
// draw selected time |
713 |
// draw selected time |
| 688 |
int x = rect.x + (int) ((selectedTime - time0) * K); |
714 |
int x = rect.x + (int) ((selectedTime - time0) * K); |
| 689 |
if (x >= rect.x && x < rect.x + rect.width) { |
715 |
if (x >= rect.x && x < rect.x + rect.width) { |
| 690 |
gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); |
716 |
gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME)); |
| 691 |
gc.drawLine(x, rect.y, x, rect.y + rect.height); |
717 |
if (group) |
|
|
718 |
gc.drawLine(x, rect.y + rect.height - 1, x, rect.y + rect.height); |
| 719 |
else |
| 720 |
gc.drawLine(x, rect.y, x, rect.y + rect.height); |
| 692 |
} |
721 |
} |
| 693 |
} |
722 |
} |
| 694 |
|
723 |
|
|
Lines 756-762
Link Here
|
| 756 |
|
785 |
|
| 757 |
public void focusLost(FocusEvent e) { |
786 |
public void focusLost(FocusEvent e) { |
| 758 |
_isInFocus = false; |
787 |
_isInFocus = false; |
| 759 |
if (1 == _dragState) { |
788 |
if (0 != _dragState) { |
| 760 |
setCapture(false); |
789 |
setCapture(false); |
| 761 |
_dragState = 0; |
790 |
_dragState = 0; |
| 762 |
} |
791 |
} |
|
Lines 764-777
Link Here
|
| 764 |
} |
793 |
} |
| 765 |
|
794 |
|
| 766 |
public void mouseMove(MouseEvent e) { |
795 |
public void mouseMove(MouseEvent e) { |
|
|
796 |
if (null == _timeProvider) |
| 797 |
return; |
| 767 |
Point size = getCtrlSize(); |
798 |
Point size = getCtrlSize(); |
| 768 |
if (1 == _dragState && null != _timeProvider) { |
799 |
if (1 == _dragState) { |
| 769 |
int leftSpace = _timeProvider.getNameSpace(); |
800 |
int nameWidth = _timeProvider.getNameSpace(); |
| 770 |
int x = e.x - leftSpace; |
801 |
int x = e.x - nameWidth; |
| 771 |
if (x > 0 && size.x > leftSpace && _dragX != x) { |
802 |
if (x > 0 && size.x > nameWidth && _dragX != x) { |
| 772 |
_dragX = x; |
803 |
_dragX = x; |
| 773 |
double K = (double) (size.x - leftSpace) |
804 |
double K = (double) (size.x - nameWidth) / (_time1bak - _time0bak); |
| 774 |
/ (_time1bak - _time0bak); |
|
|
| 775 |
double timeDelta = (_dragX - _dragX0) / K; |
805 |
double timeDelta = (_dragX - _dragX0) / K; |
| 776 |
double time1 = _time1bak - timeDelta; |
806 |
double time1 = _time1bak - timeDelta; |
| 777 |
double maxTime = _timeProvider.getMaxTime(); |
807 |
double maxTime = _timeProvider.getMaxTime(); |
|
Lines 782-793
Link Here
|
| 782 |
time0 = 0; |
812 |
time0 = 0; |
| 783 |
_timeProvider.setStartFinishTime(time0, time1); |
813 |
_timeProvider.setStartFinishTime(time0, time1); |
| 784 |
} |
814 |
} |
|
|
815 |
} else if (3 == _dragState) { |
| 816 |
_dragX = e.x; |
| 817 |
_timeProvider.setNameSpace(_hitIdx + _dragX - _dragX0); |
| 818 |
} else if (0 == _dragState) { |
| 819 |
boolean mouseHover = hitSplitTest(e.x, e.y) > 0; |
| 820 |
if (_mouseHover != mouseHover) |
| 821 |
redraw(); |
| 822 |
_mouseHover = mouseHover; |
| 785 |
} |
823 |
} |
|
|
824 |
updateCursor(e.x, e.y); |
| 786 |
} |
825 |
} |
| 787 |
|
826 |
|
| 788 |
public void mouseDoubleClick(MouseEvent e) { |
827 |
public void mouseDoubleClick(MouseEvent e) { |
|
|
828 |
if (null == _timeProvider) |
| 829 |
return; |
| 789 |
if (1 == e.button) { |
830 |
if (1 == e.button) { |
| 790 |
int idx = hitTest(e.x, e.y); |
831 |
int idx = hitSplitTest(e.x, e.y); |
|
|
832 |
if (idx >= 0) { |
| 833 |
_timeProvider.setNameSpace(_idealNameWidth + 3 * MARGIN + SMALL_ICON_SIZE); |
| 834 |
return; |
| 835 |
} |
| 836 |
idx = hitTest(e.x, e.y); |
| 791 |
if (idx >= 0) { |
837 |
if (idx >= 0) { |
| 792 |
selectItem(idx, false); |
838 |
selectItem(idx, false); |
| 793 |
if (_data._items[idx] instanceof ThreadItem) { |
839 |
if (_data._items[idx] instanceof ThreadItem) { |
|
Lines 797-807
Link Here
|
| 797 |
} |
843 |
} |
| 798 |
} |
844 |
} |
| 799 |
|
845 |
|
|
|
846 |
void updateCursor(int x, int y) { |
| 847 |
int idx = hitSplitTest(x, y); |
| 848 |
if (idx > 0 && !_isDragCursor3) { |
| 849 |
setCursor(_dragCursor3); |
| 850 |
_isDragCursor3 = true; |
| 851 |
} else if (idx <= 0 && _isDragCursor3) { |
| 852 |
setCursor(null); |
| 853 |
_isDragCursor3 = false; |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 800 |
public void mouseDown(MouseEvent e) { |
857 |
public void mouseDown(MouseEvent e) { |
| 801 |
if (null == _timeProvider) |
858 |
if (null == _timeProvider) |
| 802 |
return; |
859 |
return; |
| 803 |
if (1 == e.button) { |
860 |
if (1 == e.button) { |
| 804 |
int idx = hitTest(e.x, e.y); |
861 |
int idx = hitSplitTest(e.x, e.y); |
|
|
862 |
if (idx > 0) { |
| 863 |
_dragState = 3; |
| 864 |
_dragX = _dragX0 = e.x; |
| 865 |
_hitIdx = _timeProvider.getNameSpace();; |
| 866 |
_time0bak = _timeProvider.getTime0(); |
| 867 |
_time1bak = _timeProvider.getTime1(); |
| 868 |
redraw(); |
| 869 |
return; |
| 870 |
} |
| 871 |
idx = hitTest(e.x, e.y); |
| 805 |
if (idx >= 0) { |
872 |
if (idx >= 0) { |
| 806 |
if (_data._items[idx] instanceof ThreadItem) { |
873 |
if (_data._items[idx] instanceof ThreadItem) { |
| 807 |
double hitTime = hitTimeTest(e.x, e.y); |
874 |
double hitTime = hitTimeTest(e.x, e.y); |
|
Lines 829-834
Link Here
|
| 829 |
if (2 == _dragState) { |
896 |
if (2 == _dragState) { |
| 830 |
if (hitTest(e.x, e.y) == _hitIdx) |
897 |
if (hitTest(e.x, e.y) == _hitIdx) |
| 831 |
toggle(_hitIdx); |
898 |
toggle(_hitIdx); |
|
|
899 |
} else if (3 == _dragState) { |
| 900 |
redraw(); |
| 832 |
} |
901 |
} |
| 833 |
_dragState = 0; |
902 |
_dragState = 0; |
| 834 |
} |
903 |
} |
|
Lines 861-866
Link Here
|
| 861 |
_timeProvider.setStartFinishTime(time0, time1); |
930 |
_timeProvider.setStartFinishTime(time0, time1); |
| 862 |
} |
931 |
} |
| 863 |
} |
932 |
} |
|
|
933 |
|
| 934 |
public void mouseEnter(MouseEvent e) { |
| 935 |
} |
| 936 |
|
| 937 |
public void mouseExit(MouseEvent e) { |
| 938 |
if (_mouseHover) { |
| 939 |
_mouseHover = false; |
| 940 |
redraw(); |
| 941 |
} |
| 942 |
} |
| 943 |
|
| 944 |
public void mouseHover(MouseEvent e) { |
| 945 |
} |
| 864 |
} |
946 |
} |
| 865 |
|
947 |
|
| 866 |
class Item { |
948 |
class Item { |
|
Lines 882-888
Link Here
|
| 882 |
public TRCThread _thread; |
964 |
public TRCThread _thread; |
| 883 |
|
965 |
|
| 884 |
ThreadItem(TRCThread thread) { |
966 |
ThreadItem(TRCThread thread) { |
| 885 |
super(thread.getName()); |
967 |
super(Utils.composeThreadName(thread, false)); |
| 886 |
_thread = thread; |
968 |
_thread = thread; |
| 887 |
} |
969 |
} |
| 888 |
} |
970 |
} |
|
Lines 928-933
Link Here
|
| 928 |
} |
1010 |
} |
| 929 |
} |
1011 |
} |
| 930 |
|
1012 |
|
|
|
1013 |
ThreadItem findThreadItem(TRCThread thread) { |
| 1014 |
ThreadItem threadItem = null; |
| 1015 |
for (int i = 0; i < _items.length; i++) { |
| 1016 |
if (_items[i] instanceof ThreadItem && |
| 1017 |
((ThreadItem)_items[i])._thread == thread) { |
| 1018 |
threadItem = (ThreadItem) _items[i]; |
| 1019 |
break; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
return threadItem; |
| 1023 |
} |
| 1024 |
|
| 931 |
public void updateItems() { |
1025 |
public void updateItems() { |
| 932 |
ArrayList itemList = new ArrayList(); |
1026 |
ArrayList itemList = new ArrayList(); |
| 933 |
Set keys = _groupTable.keySet(); |
1027 |
Set keys = _groupTable.keySet(); |
|
Lines 939-946
Link Here
|
| 939 |
itemList.add(group); |
1033 |
itemList.add(group); |
| 940 |
if (_flatList || group._expanded) { |
1034 |
if (_flatList || group._expanded) { |
| 941 |
Iterator it2 = group._threads.iterator(); |
1035 |
Iterator it2 = group._threads.iterator(); |
| 942 |
while (it2.hasNext()) |
1036 |
while (it2.hasNext()) { |
| 943 |
itemList.add(new ThreadItem((TRCThread) it2.next())); |
1037 |
TRCThread thread = (TRCThread) it2.next(); |
|
|
1038 |
ThreadItem threadItem = findThreadItem(thread); |
| 1039 |
if (threadItem == null) |
| 1040 |
threadItem = new ThreadItem(thread); |
| 1041 |
itemList.add(threadItem); |
| 1042 |
} |
| 944 |
} |
1043 |
} |
| 945 |
} |
1044 |
} |
| 946 |
_items = itemList.toArray(); |
1045 |
_items = itemList.toArray(); |
|
Lines 972-978
Link Here
|
| 972 |
groupName = undef; |
1071 |
groupName = undef; |
| 973 |
GroupItem group = (GroupItem) _groupTable.get(groupName); |
1072 |
GroupItem group = (GroupItem) _groupTable.get(groupName); |
| 974 |
if (null == group) { |
1073 |
if (null == group) { |
| 975 |
group = new GroupItem(groupName); |
1074 |
group = new GroupItem("Thread Group [" + groupName + "]"); |
| 976 |
group._expanded = !groupName.equalsIgnoreCase("system") |
1075 |
group._expanded = !groupName.equalsIgnoreCase("system") |
| 977 |
&& !groupName.equalsIgnoreCase(undef); |
1076 |
&& !groupName.equalsIgnoreCase(undef); |
| 978 |
_groupTable.put(groupName, group); |
1077 |
_groupTable.put(groupName, group); |