1 /*****************************************************************************
2 * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Intel Corporation - Initial API and implementation
10 * Ruslan A. Scherbakov, Intel - Initial API and implementation
11 * Alvaro Sanchez-Leon - Updated for TMF
12 * Patrick Tasse - Refactoring
14 *****************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
21 import java
.util
.Vector
;
23 import org
.eclipse
.jface
.resource
.JFaceResources
;
24 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
27 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTreeListener
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTreeExpansionEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
34 import org
.eclipse
.swt
.SWT
;
35 import org
.eclipse
.swt
.events
.ControlEvent
;
36 import org
.eclipse
.swt
.events
.ControlListener
;
37 import org
.eclipse
.swt
.events
.FocusEvent
;
38 import org
.eclipse
.swt
.events
.FocusListener
;
39 import org
.eclipse
.swt
.events
.KeyEvent
;
40 import org
.eclipse
.swt
.events
.KeyListener
;
41 import org
.eclipse
.swt
.events
.MouseEvent
;
42 import org
.eclipse
.swt
.events
.MouseListener
;
43 import org
.eclipse
.swt
.events
.MouseMoveListener
;
44 import org
.eclipse
.swt
.events
.MouseTrackListener
;
45 import org
.eclipse
.swt
.events
.MouseWheelListener
;
46 import org
.eclipse
.swt
.events
.PaintEvent
;
47 import org
.eclipse
.swt
.events
.SelectionEvent
;
48 import org
.eclipse
.swt
.events
.SelectionListener
;
49 import org
.eclipse
.swt
.events
.TraverseEvent
;
50 import org
.eclipse
.swt
.events
.TraverseListener
;
51 import org
.eclipse
.swt
.graphics
.Color
;
52 import org
.eclipse
.swt
.graphics
.Cursor
;
53 import org
.eclipse
.swt
.graphics
.GC
;
54 import org
.eclipse
.swt
.graphics
.Image
;
55 import org
.eclipse
.swt
.graphics
.Point
;
56 import org
.eclipse
.swt
.graphics
.Rectangle
;
57 import org
.eclipse
.swt
.widgets
.Composite
;
58 import org
.eclipse
.swt
.widgets
.Display
;
59 import org
.eclipse
.swt
.widgets
.Event
;
60 import org
.eclipse
.swt
.widgets
.Listener
;
61 import org
.eclipse
.swt
.widgets
.ScrollBar
;
63 public class TimeGraphControl
extends TimeGraphBaseControl
implements FocusListener
, KeyListener
, MouseMoveListener
, MouseListener
, MouseWheelListener
, ControlListener
, SelectionListener
, MouseTrackListener
, TraverseListener
, ISelectionProvider
{
65 private static final int DRAG_NONE
= 0;
66 private static final int DRAG_TRACE_ITEM
= 1;
67 private static final int DRAG_SPLIT_LINE
= 2;
68 public static final boolean DEFAULT_DRAW_THREAD_JOIN
= true;
69 public static final boolean DEFAULT_DRAW_THREAD_WAIT
= true;
70 public static final boolean DEFAULT_DRAW_THREAD_RELEASE
= true;
71 public static final int H_SCROLLBAR_MAX
= Integer
.MAX_VALUE
- 1;
72 private static final int CUSTOM_ITEM_HEIGHT
= -1; // get item height from provider
74 private static final double zoomCoeff
= 1.5;
76 private ITimeDataProvider _timeProvider
;
77 private boolean _isInFocus
= false;
78 private boolean _isDragCursor3
= false;
79 private boolean _isWaitCursor
= true;
80 private boolean _mouseOverSplitLine
= false;
81 private int _itemHeight
= CUSTOM_ITEM_HEIGHT
;
82 private int _minimumItemWidth
= 0;
83 private int _topIndex
= 0;
84 private int _dragState
= DRAG_NONE
;
85 private int _dragX0
= 0;
86 private int _dragX
= 0;
87 private int _idealNameSpace
= 0;
88 // private double _timeStep = 10000000;
89 private long _time0bak
;
90 private long _time1bak
;
91 private ITimeGraphPresentationProvider fTimeGraphProvider
= null;
92 private ItemData _data
= null;
93 private List
<SelectionListener
> _selectionListeners
;
94 private List
<ISelectionChangedListener
> _selectionChangedListeners
= new ArrayList
<ISelectionChangedListener
>();
95 private List
<ITimeGraphTreeListener
> _treeListeners
= new ArrayList
<ITimeGraphTreeListener
>();
96 private Cursor _dragCursor3
;
97 private Cursor _WaitCursor
;
99 // Vertical formatting formatting for the state control view
100 private boolean _visibleVerticalScroll
= true;
101 private int _borderWidth
= 0;
102 private int _headerHeight
= 0;
104 private Listener mouseScrollFilterListener
;
106 protected LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
107 protected Color
[] fEventColorMap
= null;
109 public TimeGraphControl(Composite parent
, TimeGraphColorScheme colors
) {
111 super(parent
, colors
, SWT
.NO_BACKGROUND
| SWT
.H_SCROLL
| SWT
.DOUBLE_BUFFERED
);
113 _data
= new ItemData();
115 addFocusListener(this);
116 addMouseListener(this);
117 addMouseMoveListener(this);
118 addMouseTrackListener(this);
119 addMouseWheelListener(this);
120 addTraverseListener(this);
121 addKeyListener(this);
122 addControlListener(this);
123 ScrollBar scrollHor
= getHorizontalBar();
125 if (scrollHor
!= null) {
126 scrollHor
.addSelectionListener(this);
129 _dragCursor3
= new Cursor(super.getDisplay(), SWT
.CURSOR_SIZEWE
);
130 _WaitCursor
= new Cursor(super.getDisplay(), SWT
.CURSOR_WAIT
);
134 public void dispose() {
136 _dragCursor3
.dispose();
137 _WaitCursor
.dispose();
138 fResourceManager
.dispose();
142 * Sets the timegraph provider used by this timegraph viewer.
144 * @param timeGraphProvider the timegraph provider
146 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
147 fTimeGraphProvider
= timeGraphProvider
;
148 _data
.provider
= timeGraphProvider
;
149 // RGB[] eventColorTable = fTimeGraphProvider.getEventColorTable();
150 // if (eventColorTable != null) {
151 // fEventColorMap = new Color[eventColorTable.length];
152 // for (int i = 0; i < eventColorTable.length; i++) {
153 // fEventColorMap[i] = fResourceManager.createColor(eventColorTable[i]);
156 // fEventColorMap = new Color[] { };
159 StateItem
[] stateItems
= fTimeGraphProvider
.getStateTable();
160 if (stateItems
!= null) {
161 fEventColorMap
= new Color
[stateItems
.length
];
162 for (int i
= 0; i
< stateItems
.length
; i
++) {
163 fEventColorMap
[i
] = fResourceManager
.createColor(stateItems
[i
].getStateColor());
166 fEventColorMap
= new Color
[] { };
172 public void setTimeProvider(ITimeDataProvider timeProvider
) {
173 _timeProvider
= timeProvider
;
178 public void addSelectionListener(SelectionListener listener
) {
179 if (listener
== null)
180 SWT
.error(SWT
.ERROR_NULL_ARGUMENT
);
181 if (null == _selectionListeners
)
182 _selectionListeners
= new ArrayList
<SelectionListener
>();
183 _selectionListeners
.add(listener
);
186 public void removeSelectionListener(SelectionListener listener
) {
187 if (null != _selectionListeners
)
188 _selectionListeners
.remove(listener
);
191 public void fireSelectionChanged() {
192 if (null != _selectionListeners
) {
193 Iterator
<SelectionListener
> it
= _selectionListeners
.iterator();
194 while (it
.hasNext()) {
195 SelectionListener listener
= it
.next();
196 listener
.widgetSelected(null);
201 public void fireDefaultSelection() {
202 if (null != _selectionListeners
) {
203 Iterator
<SelectionListener
> it
= _selectionListeners
.iterator();
204 while (it
.hasNext()) {
205 SelectionListener listener
= it
.next();
206 listener
.widgetDefaultSelected(null);
211 public ITimeGraphEntry
[] getTraces() {
212 return _data
.getTraces();
215 public boolean[] getTraceFilter() {
216 return _data
.getTraceFilter();
219 public void refreshData() {
225 public void refreshData(ITimeGraphEntry traces
[]) {
226 _data
.refreshData(traces
);
231 public void adjustScrolls() {
232 if (null == _timeProvider
) {
233 getHorizontalBar().setValues(0, 1, 1, 1, 1, 1);
239 long time0
= _timeProvider
.getTime0();
240 long time1
= _timeProvider
.getTime1();
242 long timeMin
= _timeProvider
.getMinTime();
243 long timeMax
= _timeProvider
.getMaxTime();
245 long delta
= timeMax
- timeMin
;
248 int thumb
= H_SCROLLBAR_MAX
;
251 // Thumb size (page size)
252 thumb
= Math
.max(1, (int) (H_SCROLLBAR_MAX
* ((double) (time1
- time0
) / delta
)));
253 // At the beginning of visible window
254 timePos
= (int) (H_SCROLLBAR_MAX
* ((double) (time0
- timeMin
) / delta
));
257 // position, minimum, maximum, thumb size, increment (half page)t, page
258 // increment size (full page)
259 getHorizontalBar().setValues(timePos
, 0, H_SCROLLBAR_MAX
, thumb
, Math
.max(1, thumb
/ 2), Math
.max(2, thumb
));
262 boolean ensureVisibleItem(int idx
, boolean redraw
) {
263 boolean changed
= false;
265 for (idx
= 0; idx
< _data
._expandedItems
.length
; idx
++) {
266 if (((TimeGraphItem
) _data
._expandedItems
[idx
])._selected
)
270 if (idx
>= _data
._expandedItems
.length
)
272 if (idx
< _topIndex
) {
274 //FIXME:getVerticalBar().setSelection(_topItem);
279 int page
= countPerPage();
280 if (idx
>= _topIndex
+ page
) {
281 setTopIndex(idx
- page
+ 1);
282 //FIXME:getVerticalBar().setSelection(_topItem);
291 public void setTopIndex(int idx
) {
292 idx
= Math
.min(idx
, _data
._expandedItems
.length
- countPerPage());
293 idx
= Math
.max(0, idx
);
298 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
299 TimeGraphItem item
= _data
.findItem(entry
);
300 if (item
!= null && item
._expanded
!= expanded
) {
301 item
._expanded
= expanded
;
302 _data
.updateExpandedItems();
307 public void addTreeListener (ITimeGraphTreeListener listener
) {
308 if (!_treeListeners
.contains(listener
)) {
309 _treeListeners
.add(listener
);
313 public void removeTreeListener (ITimeGraphTreeListener listener
) {
314 if (_treeListeners
.contains(listener
)) {
315 _treeListeners
.remove(listener
);
319 public void fireTreeEvent(ITimeGraphEntry entry
, boolean expanded
) {
320 TimeGraphTreeExpansionEvent event
= new TimeGraphTreeExpansionEvent(this, entry
);
321 for (ITimeGraphTreeListener listener
: _treeListeners
) {
323 listener
.treeExpanded(event
);
325 listener
.treeCollapsed(event
);
331 public ISelection
getSelection() {
332 TimeGraphSelection sel
= new TimeGraphSelection();
333 ITimeGraphEntry trace
= getSelectedTrace();
334 if (null != trace
&& null != _timeProvider
) {
335 long selectedTime
= _timeProvider
.getSelectedTime();
336 ITimeEvent event
= Utils
.findEvent(trace
, selectedTime
, 0);
345 public ISelection
getSelectionTrace() {
346 TimeGraphSelection sel
= new TimeGraphSelection();
347 ITimeGraphEntry trace
= getSelectedTrace();
354 public void selectTrace(int n
) {
355 if (n
!= 1 && n
!= -1)
357 boolean changed
= false;
358 int lastSelection
= -1;
359 for (int i
= 0; i
< _data
._expandedItems
.length
; i
++) {
360 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[i
];
361 if (item
._selected
) {
363 if (1 == n
&& i
< _data
._expandedItems
.length
- 1) {
364 item
._selected
= false;
365 if (item
._hasChildren
) {
367 fireTreeEvent(item
._trace
, item
._expanded
);
369 item
= (TimeGraphItem
) _data
._expandedItems
[i
+ 1];
370 if (item
._hasChildren
) {
371 _data
.expandItem(i
+ 1);
372 fireTreeEvent(item
._trace
, item
._expanded
);
373 item
= (TimeGraphItem
) _data
._expandedItems
[i
+ 2];
375 item
._selected
= true;
377 } else if (-1 == n
&& i
> 0) {
379 TimeGraphItem prevItem
= (TimeGraphItem
) _data
._expandedItems
[i
];
380 if (prevItem
._hasChildren
) {
381 if (prevItem
._expanded
) {
384 prevItem
= (TimeGraphItem
) _data
._expandedItems
[i
];
387 if (!prevItem
._expanded
) {
389 fireTreeEvent(prevItem
._trace
, prevItem
._expanded
);
390 prevItem
= (TimeGraphItem
) _data
._expandedItems
[i
+ prevItem
.children
.size()];
391 item
._selected
= false;
392 prevItem
._selected
= true;
396 item
._selected
= false;
397 prevItem
._selected
= true;
404 if (lastSelection
< 0 && _data
._expandedItems
.length
> 0) {
405 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[0];
406 if (item
._hasChildren
) {
408 fireTreeEvent(item
._trace
, item
._expanded
);
409 item
= (TimeGraphItem
) _data
._expandedItems
[1];
410 item
._selected
= true;
413 item
._selected
= true;
418 ensureVisibleItem(-1, false);
420 fireSelectionChanged();
424 public void selectEvent(int n
) {
425 if (null == _timeProvider
)
427 ITimeGraphEntry trace
= getSelectedTrace();
430 long selectedTime
= _timeProvider
.getSelectedTime();
431 long endTime
= _timeProvider
.getEndTime();
432 ITimeEvent nextEvent
;
433 if (-1 == n
&& selectedTime
> endTime
)
434 nextEvent
= Utils
.findEvent(trace
, selectedTime
, 0);
436 nextEvent
= Utils
.findEvent(trace
, selectedTime
, n
);
437 if (null == nextEvent
&& -1 == n
)
438 nextEvent
= Utils
.getFirstEvent(trace
);
439 if (null != nextEvent
) {
440 long nextTime
= nextEvent
.getTime();
441 // If last event detected e.g. going back or not moving to a next
443 if (nextTime
<= selectedTime
&& n
== 1) {
444 // Select to the end of this last event
445 nextTime
= nextEvent
.getTime() + nextEvent
.getDuration();
446 // but not beyond the end of the trace
447 if (nextTime
> endTime
) {
451 _timeProvider
.setSelectedTimeInt(nextTime
, true);
452 fireSelectionChanged();
454 _timeProvider
.setSelectedTimeInt(endTime
, true);
455 fireSelectionChanged();
459 public void selectNextEvent() {
461 // Notify if visible time window has been adjusted
462 _timeProvider
.setStartFinishTimeNotify(_timeProvider
.getTime0(), _timeProvider
.getTime1());
465 public void selectPrevEvent() {
467 // Notify if visible time window has been adjusted
468 _timeProvider
.setStartFinishTimeNotify(_timeProvider
.getTime0(), _timeProvider
.getTime1());
471 public void selectNextTrace() {
475 public void selectPrevTrace() {
480 * Zooming based on mouse cursor location with mouse scrolling
484 public void zoom(boolean zoomIn
) {
485 int globalX
= getDisplay().getCursorLocation().x
;
486 Point p
= toControl(globalX
, 0);
487 int nameSpace
= _timeProvider
.getNameSpace();
488 int timeSpace
= _timeProvider
.getTimeSpace();
489 int xPos
= Math
.max(nameSpace
, Math
.min(nameSpace
+ timeSpace
, p
.x
));
490 long time0
= _timeProvider
.getTime0();
491 long time1
= _timeProvider
.getTime1();
492 long interval
= time1
- time0
;
495 } // to allow getting out of single point interval
498 newInterval
= Math
.max(Math
.round((double) interval
* 0.8), _timeProvider
.getMinTimeInterval());
500 newInterval
= (long) Math
.ceil((double) interval
* 1.25);
502 long center
= time0
+ Math
.round(((double) (xPos
- nameSpace
) / timeSpace
* interval
));
503 long newTime0
= center
- Math
.round((double) newInterval
* (center
- time0
) / interval
);
504 long newTime1
= newTime0
+ newInterval
;
505 _timeProvider
.setStartFinishTime(newTime0
, newTime1
);
509 * zoom in using single click
511 public void zoomIn() {
512 long _time0
= _timeProvider
.getTime0();
513 long _time1
= _timeProvider
.getTime1();
514 long _range
= _time1
- _time0
;
515 long selTime
= _timeProvider
.getSelectedTime();
516 if (selTime
<= _time0
|| selTime
>= _time1
) {
517 selTime
= (_time0
+ _time1
) / 2;
519 long time0
= selTime
- (long) ((selTime
- _time0
) / zoomCoeff
);
520 long time1
= selTime
+ (long) ((_time1
- selTime
) / zoomCoeff
);
522 long inaccuracy
= (_timeProvider
.getMaxTime() - _timeProvider
.getMinTime()) - (time1
- time0
);
524 // Trace.debug("selTime:" + selTime + " time0:" + time0 + " time1:"
525 // + time1 + " inaccuracy:" + inaccuracy);
527 if (inaccuracy
> 0 && inaccuracy
< 100) {
528 _timeProvider
.setStartFinishTimeNotify(_timeProvider
.getMinTime(), _timeProvider
.getMaxTime());
532 long m
= _timeProvider
.getMinTimeInterval();
533 if ((time1
- time0
) < m
) {
534 time0
= selTime
- (long) ((selTime
- _time0
) * m
/ _range
);
538 _timeProvider
.setStartFinishTimeNotify(time0
, time1
);
542 * zoom out using single click
544 public void zoomOut() {
545 long _time0
= _timeProvider
.getTime0();
546 long _time1
= _timeProvider
.getTime1();
547 long selTime
= _timeProvider
.getSelectedTime();
548 if (selTime
<= _time0
|| selTime
>= _time1
) {
549 selTime
= (_time0
+ _time1
) / 2;
551 long time0
= (long) (selTime
- (selTime
- _time0
) * zoomCoeff
);
552 long time1
= (long) (selTime
+ (_time1
- selTime
) * zoomCoeff
);
554 long inaccuracy
= (_timeProvider
.getMaxTime() - _timeProvider
.getMinTime()) - (time1
- time0
);
555 if (inaccuracy
> 0 && inaccuracy
< 100) {
556 _timeProvider
.setStartFinishTimeNotify(_timeProvider
.getMinTime(), _timeProvider
.getMaxTime());
560 _timeProvider
.setStartFinishTimeNotify(time0
, time1
);
563 public ITimeGraphEntry
getSelectedTrace() {
564 ITimeGraphEntry trace
= null;
565 int idx
= getSelectedIndex();
567 trace
= _data
._expandedItems
[idx
]._trace
;
571 public int getSelectedIndex() {
573 for (int i
= 0; i
< _data
._expandedItems
.length
; i
++) {
574 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[i
];
575 if (item
._selected
) {
583 boolean toggle(int idx
) {
584 boolean toggled
= false;
585 if (idx
>= 0 && idx
< _data
._expandedItems
.length
) {
586 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[idx
];
587 if (item
._hasChildren
) {
588 item
._expanded
= !item
._expanded
;
589 _data
.updateExpandedItems();
593 fireTreeEvent(item
._trace
, item
._expanded
);
599 int getItemIndexAtY(int y
) {
603 if (_itemHeight
== CUSTOM_ITEM_HEIGHT
) {
605 for (int idx
= _topIndex
; idx
< _data
._expandedItems
.length
; idx
++) {
606 ySum
+= _data
._expandedItems
[idx
].itemHeight
;
613 int idx
= y
/ _itemHeight
;
615 if (idx
< _data
._expandedItems
.length
) {
621 boolean isOverSplitLine(int x
) {
622 if (x
< 0 || null == _timeProvider
)
625 int nameWidth
= _timeProvider
.getNameSpace();
626 if (x
> nameWidth
- w
&& x
< nameWidth
+ w
) {
633 TimeGraphItem
getItem(Point pt
) {
634 int idx
= getItemIndexAtY(pt
.y
);
635 return idx
>= 0 ?
(TimeGraphItem
) _data
._expandedItems
[idx
] : null;
638 long getTimeAtX(int x
) {
639 if (null == _timeProvider
)
642 Point size
= getCtrlSize();
643 long time0
= _timeProvider
.getTime0();
644 long time1
= _timeProvider
.getTime1();
645 int nameWidth
= _timeProvider
.getNameSpace();
647 if (x
>= 0 && size
.x
>= nameWidth
) {
648 if (time1
- time0
> size
.x
- nameWidth
- RIGHT_MARGIN
) {
649 // get the last possible time represented by the pixel position
650 // by taking the time of the next pixel position minus 1
652 hitTime
= time0
+ (long) ((time1
- time0
) * ((double) (x
+ 1) / (size
.x
- nameWidth
- RIGHT_MARGIN
))) - 1;
654 hitTime
= time0
+ (long) ((time1
- time0
) * ((double) (x
) / (size
.x
- nameWidth
- RIGHT_MARGIN
)));
660 void selectItem(int idx
, boolean addSelection
) {
661 boolean changed
= false;
663 if (idx
>= 0 && idx
< _data
._expandedItems
.length
) {
664 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[idx
];
665 changed
= (item
._selected
== false);
666 item
._selected
= true;
669 for (int i
= 0; i
< _data
._expandedItems
.length
; i
++) {
670 TimeGraphItem item
= (TimeGraphItem
) _data
._expandedItems
[i
];
671 if ((i
== idx
&& !item
._selected
) || (idx
== -1 && item
._selected
)) {
674 item
._selected
= i
== idx
;
677 changed
|= ensureVisibleItem(idx
, true);
682 public void selectItem(ITimeGraphEntry trace
, boolean addSelection
) {
683 int idx
= _data
.findItemIndex(trace
);
684 selectItem(idx
, addSelection
);
687 public int countPerPage() {
688 int height
= getCtrlSize().y
;
690 if (_itemHeight
== CUSTOM_ITEM_HEIGHT
) {
692 for (int idx
= _topIndex
; idx
< _data
._expandedItems
.length
; idx
++) {
693 ySum
+= _data
._expandedItems
[idx
].itemHeight
;
694 if (ySum
>= height
) {
699 for (int idx
= _topIndex
- 1; idx
>= 0; idx
--) {
700 ySum
+= _data
._expandedItems
[idx
].itemHeight
;
701 if (ySum
>= height
) {
709 count
= height
/ _itemHeight
;
714 public int getTopIndex() {
718 public int getExpandedElementCount() {
719 return _data
._expandedItems
.length
;
722 Point
getCtrlSize() {
723 Point size
= getSize();
724 if (getHorizontalBar().isVisible()) {
725 size
.y
-= getHorizontalBar().getSize().y
;
730 Rectangle
getNameRect(Rectangle bound
, int idx
, int nameWidth
) {
732 int y
= bound
.y
+ (idx
- _topIndex
) * _itemHeight
;
733 int width
= nameWidth
;
734 int height
= _itemHeight
;
735 if (_itemHeight
== CUSTOM_ITEM_HEIGHT
) {
737 for (int i
= _topIndex
; i
< idx
; i
++) {
738 ySum
+= _data
._expandedItems
[i
].itemHeight
;
741 height
= _data
._expandedItems
[idx
].itemHeight
;
743 return new Rectangle(x
, y
, width
, height
);
746 Rectangle
getStatesRect(Rectangle bound
, int idx
, int nameWidth
) {
747 int x
= bound
.x
+ nameWidth
;
748 int y
= bound
.y
+ (idx
- _topIndex
) * _itemHeight
;
749 int width
= bound
.width
- x
;
750 int height
= _itemHeight
;
751 if (_itemHeight
== CUSTOM_ITEM_HEIGHT
) {
753 for (int i
= _topIndex
; i
< idx
; i
++) {
754 ySum
+= _data
._expandedItems
[i
].itemHeight
;
757 height
= _data
._expandedItems
[idx
].itemHeight
;
759 return new Rectangle(x
, y
, width
, height
);
763 void paint(Rectangle bounds
, PaintEvent e
) {
765 gc
.setBackground(_colors
.getColor(TimeGraphColorScheme
.BACKGROUND
));
766 drawBackground(gc
, bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
768 if (bounds
.width
< 2 || bounds
.height
< 2 || null == _timeProvider
)
772 int nameSpace
= _timeProvider
.getNameSpace();
774 // draw empty name space background
775 gc
.setBackground(_colors
.getBkColor(false, false, true));
776 drawBackground(gc
, bounds
.x
, bounds
.y
, nameSpace
, bounds
.height
);
778 drawItems(bounds
, _timeProvider
, _data
._expandedItems
, _topIndex
, nameSpace
, gc
);
780 // draw selected time
781 long time0
= _timeProvider
.getTime0();
782 long time1
= _timeProvider
.getTime1();
783 long selectedTime
= _timeProvider
.getSelectedTime();
784 double pixelsPerNanoSec
= (bounds
.width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (bounds
.width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
785 int x
= bounds
.x
+ nameSpace
+ (int) ((double) (selectedTime
- time0
) * pixelsPerNanoSec
);
786 if (x
>= nameSpace
&& x
< bounds
.x
+ bounds
.width
) {
787 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.SELECTED_TIME
));
788 gc
.drawLine(x
, bounds
.y
, x
, bounds
.y
+ bounds
.height
);
791 // draw drag line, no line if name space is 0.
792 if (DRAG_SPLIT_LINE
== _dragState
) {
793 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.BLACK
));
794 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
795 } else if (DRAG_NONE
== _dragState
&& _mouseOverSplitLine
&& _timeProvider
.getNameSpace() > 0) {
796 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.RED
));
797 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
801 public void drawItems(Rectangle bounds
, ITimeDataProvider timeProvider
, TimeGraphItem
[] items
, int topIndex
, int nameSpace
, GC gc
) {
802 for (int i
= topIndex
; i
< items
.length
; i
++) {
803 TimeGraphItem item
= (TimeGraphItem
) items
[i
];
804 drawItem(item
, bounds
, timeProvider
, i
, nameSpace
, gc
);
806 fTimeGraphProvider
.postDrawControl(bounds
, gc
);
812 * @param item the item to draw
813 * @param bounds the container rectangle
814 * @param i the item index
815 * @param nameSpace the name space
818 protected void drawItem(TimeGraphItem item
, Rectangle bounds
, ITimeDataProvider timeProvider
, int i
, int nameSpace
, GC gc
) {
819 ITimeGraphEntry entry
= item
._trace
;
820 long time0
= timeProvider
.getTime0();
821 long time1
= timeProvider
.getTime1();
822 long selectedTime
= timeProvider
.getSelectedTime();
824 Rectangle nameRect
= getNameRect(bounds
, i
, nameSpace
);
825 if (nameRect
.y
>= bounds
.y
+ bounds
.height
) {
829 if (item
._trace
.getTimeEventsIterator() == null) {
830 Rectangle statesRect
= getStatesRect(bounds
, i
, nameSpace
);
831 nameRect
.width
+= statesRect
.width
;
832 drawName(item
, nameRect
, gc
);
834 drawName(item
, nameRect
, gc
);
836 Rectangle rect
= getStatesRect(bounds
, i
, nameSpace
);
837 if (rect
.isEmpty()) {
838 fTimeGraphProvider
.postDrawEntry(entry
, bounds
, gc
);
841 if (time1
<= time0
) {
842 gc
.setBackground(_colors
.getBkColor(false, false, false));
843 gc
.fillRectangle(rect
);
844 fTimeGraphProvider
.postDrawEntry(entry
, bounds
, gc
);
848 // Initialize _rect1 to same values as enclosing rectangle rect
849 Rectangle stateRect
= Utils
.clone(rect
);
850 boolean selected
= item
._selected
;
851 // K pixels per second
852 double pixelsPerNanoSec
= (rect
.width
<= RIGHT_MARGIN
) ?
0 : (double) (rect
.width
- RIGHT_MARGIN
) / (time1
- time0
);
854 boolean group
= item
._trace
.getTimeEventsIterator() == null;
857 fillSpace(rect
, gc
, selected
);
858 // Drawing rectangle is smaller than reserved space
860 stateRect
.height
-= 6;
862 long maxDuration
= (timeProvider
.getTimeSpace() == 0) ? Long
.MAX_VALUE
: 1 * (time1
- time0
) / timeProvider
.getTimeSpace();
863 Iterator
<ITimeEvent
> iterator
= entry
.getTimeEventsIterator(time0
, time1
, maxDuration
);
866 while (iterator
.hasNext()) {
867 ITimeEvent event
= iterator
.next();
868 int x
= rect
.x
+ (int) ((event
.getTime() - time0
) * pixelsPerNanoSec
);
869 int xEnd
= rect
.x
+ (int) ((event
.getTime() + event
.getDuration() - time0
) * pixelsPerNanoSec
);
870 if (x
>= rect
.x
+ rect
.width
|| xEnd
< rect
.x
) {
871 // event is out of bounds
874 xEnd
= Math
.min(rect
.x
+ rect
.width
, xEnd
);
875 stateRect
.x
= Math
.max(rect
.x
, x
);
876 stateRect
.width
= Math
.max(0, xEnd
- stateRect
.x
+ 1);
877 if (stateRect
.x
== lastX
) {
878 stateRect
.width
-= 1;
879 if (stateRect
.width
> 0) {
880 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
881 gc
.drawPoint(stateRect
.x
, stateRect
.y
- 2);
887 boolean timeSelected
= selectedTime
>= event
.getTime() && selectedTime
< event
.getTime() + event
.getDuration();
888 drawState(_colors
, event
, stateRect
, gc
, selected
, timeSelected
);
891 fTimeGraphProvider
.postDrawEntry(entry
, bounds
, gc
);
894 protected void drawName(TimeGraphItem item
, Rectangle bounds
, GC gc
) {
895 boolean group
= item
._trace
.getTimeEventsIterator() == null;
897 gc
.setBackground(_colors
.getBkColorGroup(item
._selected
, _isInFocus
));
898 gc
.fillRectangle(bounds
);
899 if (item
._selected
&& _isInFocus
) {
900 gc
.setForeground(_colors
.getBkColor(item
._selected
, _isInFocus
, false));
901 gc
.drawRectangle(bounds
.x
, bounds
.y
, bounds
.width
- 1, bounds
.height
- 1);
904 gc
.setBackground(_colors
.getBkColor(item
._selected
, _isInFocus
, true));
905 gc
.setForeground(_colors
.getFgColor(item
._selected
, _isInFocus
));
906 gc
.fillRectangle(bounds
);
909 // No name to be drawn
910 if (_timeProvider
.getNameSpace() == 0) {
914 int leftMargin
= MARGIN
+ item
.level
* EXPAND_SIZE
;
915 if (item
._hasChildren
) {
916 gc
.setForeground(_colors
.getFgColorGroup(false, false));
917 gc
.setBackground(_colors
.getBkColor(false, false, false));
918 Rectangle rect
= Utils
.clone(bounds
);
919 rect
.x
+= leftMargin
;
920 rect
.y
+= (bounds
.height
- EXPAND_SIZE
) / 2;
921 rect
.width
= EXPAND_SIZE
;
922 rect
.height
= EXPAND_SIZE
;
923 gc
.fillRectangle(rect
);
924 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1, rect
.height
- 1);
925 int midy
= rect
.y
+ rect
.height
/ 2;
926 gc
.drawLine(rect
.x
+ 2, midy
, rect
.x
+ rect
.width
- 3, midy
);
927 if (!item
._expanded
) {
928 int midx
= rect
.x
+ rect
.width
/ 2;
929 gc
.drawLine(midx
, rect
.y
+ 2, midx
, rect
.y
+ rect
.height
- 3);
932 leftMargin
+= EXPAND_SIZE
+ MARGIN
;
934 Image img
= fTimeGraphProvider
.getItemImage(item
._trace
);
937 int imgHeight
= img
.getImageData().height
;
938 int imgWidth
= img
.getImageData().width
;
940 int y
= bounds
.y
+ (bounds
.height
- imgHeight
) / 2;
941 gc
.drawImage(img
, x
, y
);
942 leftMargin
+= imgWidth
+ MARGIN
;
944 String name
= item
._name
;
945 Point size
= gc
.stringExtent(name
);
946 if (_idealNameSpace
< leftMargin
+ size
.x
+ MARGIN
) {
947 _idealNameSpace
= leftMargin
+ size
.x
+ MARGIN
;
950 // cut long string with "..."
951 int width
= bounds
.width
- leftMargin
;
953 while (size
.x
> width
&& name
.length() > 1) {
955 name
= name
.substring(0, name
.length() - 1);
956 size
= gc
.stringExtent(name
+ "..."); //$NON-NLS-1$
959 name
+= "..."; //$NON-NLS-1$
962 Rectangle rect
= Utils
.clone(bounds
);
963 rect
.x
+= leftMargin
;
964 rect
.width
-= leftMargin
;
966 if (rect
.width
> 0) {
967 rect
.y
+= (bounds
.height
- gc
.stringExtent(name
).y
) / 2;
968 gc
.setForeground(_colors
.getFgColor(item
._selected
, _isInFocus
));
969 int textWidth
= Utils
.drawText(gc
, name
, rect
, true);
970 leftMargin
+= textWidth
+ MARGIN
;
975 int x
= bounds
.x
+ leftMargin
;
976 int width
= bounds
.width
- x
;
977 int midy
= bounds
.y
+ bounds
.height
/ 2;
978 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.MID_LINE
));
979 gc
.drawLine(x
, midy
, x
+ width
, midy
);
984 protected void drawState(TimeGraphColorScheme colors
, ITimeEvent event
,
985 Rectangle rect
, GC gc
, boolean selected
, boolean timeSelected
) {
987 int colorIdx
= fTimeGraphProvider
.getEventTableIndex(event
);
991 boolean visible
= rect
.width
== 0 ?
false : true;
994 Color stateColor
= null;
995 if (colorIdx
< fEventColorMap
.length
) {
996 stateColor
= fEventColorMap
[colorIdx
];
998 stateColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
1001 timeSelected
= timeSelected
&& selected
;
1003 // modify the color?
1005 // fill all rect area
1006 gc
.setBackground(stateColor
);
1007 gc
.fillRectangle(rect
);
1008 // get the border color?
1009 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
1012 if (!timeSelected
) {
1013 // Draw the top and bottom borders i.e. no side borders
1015 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1, rect
.y
);
1017 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
- 1);
1020 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
1021 gc
.drawPoint(rect
.x
, rect
.y
- 2);
1023 // selected rectangle area is not visible but can be represented
1024 // with a broken vertical line of specified width.
1027 gc.setForeground(stateColor);
1028 int s = gc.getLineStyle();
1029 int w = gc.getLineWidth();
1030 gc.setLineStyle(SWT.LINE_DOT);
1031 gc.setLineWidth(width);
1032 // Trace.debug("Rectangle not visible, drawing vertical line with: "
1033 // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y
1035 gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1);
1038 if (!timeSelected) {
1039 gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
1040 gc.drawPoint(rect.x, rect.y);
1041 gc.drawPoint(rect.x, rect.y + rect.height - 1);
1045 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
1048 protected void fillSpace(Rectangle rect
, GC gc
, boolean selected
) {
1049 gc
.setBackground(_colors
.getBkColor(selected
, _isInFocus
, false));
1050 gc
.fillRectangle(rect
);
1052 gc
.setForeground(_colors
.getColor(TimeGraphColorScheme
.MID_LINE
));
1053 int midy
= rect
.y
+ rect
.height
/ 2;
1054 gc
.drawLine(rect
.x
, midy
, rect
.x
+ rect
.width
, midy
);
1058 public void keyTraversed(TraverseEvent e
) {
1059 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
1064 public void keyPressed(KeyEvent e
) {
1066 if (_data
._expandedItems
.length
== 0) {
1069 if (SWT
.HOME
== e
.keyCode
) {
1071 } else if (SWT
.END
== e
.keyCode
) {
1072 idx
= _data
._expandedItems
.length
- 1;
1073 } else if (SWT
.ARROW_DOWN
== e
.keyCode
) {
1074 idx
= getSelectedIndex();
1077 else if (idx
< _data
._expandedItems
.length
- 1)
1079 } else if (SWT
.ARROW_UP
== e
.keyCode
) {
1080 idx
= getSelectedIndex();
1085 } else if (SWT
.ARROW_LEFT
== e
.keyCode
) {
1087 } else if (SWT
.ARROW_RIGHT
== e
.keyCode
) {
1089 } else if (SWT
.PAGE_DOWN
== e
.keyCode
) {
1090 int page
= countPerPage();
1091 idx
= getSelectedIndex();
1095 if (idx
>= _data
._expandedItems
.length
)
1096 idx
= _data
._expandedItems
.length
- 1;
1097 } else if (SWT
.PAGE_UP
== e
.keyCode
) {
1098 int page
= countPerPage();
1099 idx
= getSelectedIndex();
1105 } else if (SWT
.CR
== e
.keyCode
) {
1106 idx
= getSelectedIndex();
1108 if (_data
._expandedItems
[idx
]._hasChildren
) {
1111 fireDefaultSelection();
1117 selectItem(idx
, false);
1118 fireSelectionChanged();
1123 public void keyReleased(KeyEvent e
) {
1127 public void focusGained(FocusEvent e
) {
1133 public void focusLost(FocusEvent e
) {
1135 if (DRAG_NONE
!= _dragState
) {
1137 _dragState
= DRAG_NONE
;
1142 public boolean isInFocus() {
1147 * Provide the possibilty to control the wait cursor externally e.g. data
1148 * requests in progress
1152 public void waitCursor(boolean waitInd
) {
1153 // Update cursor as indicated
1155 setCursor(_WaitCursor
);
1156 _isWaitCursor
= true;
1159 _isWaitCursor
= false;
1162 // Get ready for next mouse move
1163 _isDragCursor3
= false;
1168 * If the x, y position is over the vertical split line (name to time
1169 * ranges), then change the cursor to a drag cursor to indicate the user the
1170 * possibility of resizing
1176 void updateCursor(int x
, int y
) {
1177 // if Wait cursor not active, check for the need to change to a drag
1179 if (_isWaitCursor
== false) {
1180 boolean isSplitLine
= isOverSplitLine(x
);
1181 // No dragcursor is name space is fixed to zero
1182 if (isSplitLine
&& !_isDragCursor3
&& _timeProvider
.getNameSpace() > 0) {
1183 setCursor(_dragCursor3
);
1184 _isDragCursor3
= true;
1185 } else if (!isSplitLine
&& _isDragCursor3
) {
1187 _isDragCursor3
= false;
1193 public void mouseMove(MouseEvent e
) {
1194 if (null == _timeProvider
)
1196 Point size
= getCtrlSize();
1197 if (DRAG_TRACE_ITEM
== _dragState
) {
1198 int nameWidth
= _timeProvider
.getNameSpace();
1199 int x
= e
.x
- nameWidth
;
1200 if (x
> 0 && size
.x
> nameWidth
&& _dragX
!= x
) {
1202 double pixelsPerNanoSec
= (size
.x
- nameWidth
<= RIGHT_MARGIN
) ?
0 : (double) (size
.x
- nameWidth
- RIGHT_MARGIN
) / (_time1bak
- _time0bak
);
1203 long timeDelta
= (long) ((pixelsPerNanoSec
== 0) ?
0 : ((_dragX
- _dragX0
) / pixelsPerNanoSec
));
1204 long time1
= _time1bak
- timeDelta
;
1205 long maxTime
= _timeProvider
.getMaxTime();
1206 if (time1
> maxTime
)
1208 long time0
= time1
- (_time1bak
- _time0bak
);
1209 if (time0
< _timeProvider
.getMinTime()) {
1210 time0
= _timeProvider
.getMinTime();
1211 time1
= time0
+ (_time1bak
- _time0bak
);
1213 _timeProvider
.setStartFinishTime(time0
, time1
);
1215 } else if (DRAG_SPLIT_LINE
== _dragState
) {
1217 _timeProvider
.setNameSpace(e
.x
);
1218 } else if (DRAG_NONE
== _dragState
) {
1219 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
1220 if (_mouseOverSplitLine
!= mouseOverSplitLine
) {
1223 _mouseOverSplitLine
= mouseOverSplitLine
;
1224 // Make sure any time changes are notified to the application e.g.
1225 // getting back from the horizontal scroll bar or zoomed using the
1227 _timeProvider
.notifyStartFinishTime();
1229 updateCursor(e
.x
, e
.y
);
1233 public void mouseDoubleClick(MouseEvent e
) {
1234 if (null == _timeProvider
)
1236 if (1 == e
.button
) {
1237 if (isOverSplitLine(e
.x
) && _timeProvider
.getNameSpace() != 0) {
1238 _timeProvider
.setNameSpace(_idealNameSpace
);
1239 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
1240 if (_mouseOverSplitLine
!= mouseOverSplitLine
) {
1243 _mouseOverSplitLine
= mouseOverSplitLine
;
1246 int idx
= getItemIndexAtY(e
.y
);
1248 selectItem(idx
, false);
1249 fireDefaultSelection();
1255 public void mouseDown(MouseEvent e
) {
1256 if (null == _timeProvider
)
1259 if (1 == e
.button
) {
1260 int nameSpace
= _timeProvider
.getNameSpace();
1261 if (nameSpace
!= 0) {
1262 if (isOverSplitLine(e
.x
)) {
1263 _dragState
= DRAG_SPLIT_LINE
;
1264 _dragX
= _dragX0
= e
.x
;
1265 _time0bak
= _timeProvider
.getTime0();
1266 _time1bak
= _timeProvider
.getTime1();
1272 idx
= getItemIndexAtY(e
.y
);
1274 TimeGraphItem item
= _data
._expandedItems
[idx
];
1275 if (item
._hasChildren
&& e
.x
< nameSpace
&& e
.x
< MARGIN
+ (item
.level
+ 1) * EXPAND_SIZE
) {
1278 long hitTime
= getTimeAtX(e
.x
);
1280 // _timeProvider.setSelectedTimeInt(hitTime, false);
1282 _dragState
= DRAG_TRACE_ITEM
;
1283 _dragX
= _dragX0
= e
.x
- nameSpace
;
1284 _time0bak
= _timeProvider
.getTime0();
1285 _time1bak
= _timeProvider
.getTime1();
1288 selectItem(idx
, false);
1289 fireSelectionChanged();
1291 selectItem(idx
, false); // clear selection
1293 fireSelectionChanged();
1299 public void mouseUp(MouseEvent e
) {
1300 if (DRAG_NONE
!= _dragState
) {
1302 if (DRAG_TRACE_ITEM
== _dragState
) {
1303 // Notify time provider to check the need for listener
1305 _timeProvider
.notifyStartFinishTime();
1306 if (_dragX
== _dragX0
) { // click without drag
1307 long time
= getTimeAtX(e
.x
);
1308 _timeProvider
.setSelectedTimeInt(time
, false);
1310 } else if (DRAG_SPLIT_LINE
== _dragState
) {
1313 _dragState
= DRAG_NONE
;
1318 public void mouseEnter(MouseEvent e
) {
1319 if (mouseScrollFilterListener
== null) {
1320 mouseScrollFilterListener
= new Listener() {
1321 // This filter is used to prevent scrolling of the view when the
1322 // mouse wheel is used to zoom
1324 public void handleEvent(Event event
) {
1328 getDisplay().addFilter(SWT
.MouseWheel
, mouseScrollFilterListener
);
1333 public void mouseExit(MouseEvent e
) {
1334 if (mouseScrollFilterListener
!= null) {
1335 getDisplay().removeFilter(SWT
.MouseWheel
, mouseScrollFilterListener
);
1336 mouseScrollFilterListener
= null;
1338 if (_mouseOverSplitLine
) {
1339 _mouseOverSplitLine
= false;
1345 public void mouseHover(MouseEvent e
) {
1349 public void mouseScrolled(MouseEvent e
) {
1350 if ((mouseScrollFilterListener
== null) || _dragState
!= DRAG_NONE
) {
1353 if (e
.x
< _timeProvider
.getNameSpace() || e
.x
> getSize().x
) {
1354 setTopIndex(getTopIndex() - e
.count
);
1355 } else if (_timeProvider
.getTime0() != _timeProvider
.getTime1()) {
1358 } else if (e
.count
< 0) {
1365 public void controlMoved(ControlEvent e
) {
1369 public void controlResized(ControlEvent e
) {
1374 public void widgetDefaultSelected(SelectionEvent e
) {
1378 public void widgetSelected(SelectionEvent e
) {
1379 if (e
.widget
== getVerticalBar()) {
1380 setTopIndex(getVerticalBar().getSelection());
1381 } else if (e
.widget
== getHorizontalBar() && null != _timeProvider
) {
1382 int start
= getHorizontalBar().getSelection();
1383 long time0
= _timeProvider
.getTime0();
1384 long time1
= _timeProvider
.getTime1();
1385 long timeMin
= _timeProvider
.getMinTime();
1386 long timeMax
= _timeProvider
.getMaxTime();
1387 long delta
= timeMax
- timeMin
;
1389 long range
= time1
- time0
;
1390 // _timeRangeFixed = true;
1391 time0
= timeMin
+ Math
.round(delta
* ((double) start
/ H_SCROLLBAR_MAX
));
1392 time1
= time0
+ range
;
1394 // TODO: Follow-up with Bug 310310
1395 // In Linux SWT.DRAG is the only value received
1396 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310
1397 if (e
.detail
== SWT
.DRAG
) {
1398 _timeProvider
.setStartFinishTime(time0
, time1
);
1400 _timeProvider
.setStartFinishTimeNotify(time0
, time1
);
1405 public boolean isVisibleVerticalScroll() {
1406 return _visibleVerticalScroll
;
1410 public int getBorderWidth() {
1411 return _borderWidth
;
1414 public void setBorderWidth(int borderWidth
) {
1415 this._borderWidth
= borderWidth
;
1418 public int getHeaderHeight() {
1419 return _headerHeight
;
1422 public void setHeaderHeight(int headerHeight
) {
1423 this._headerHeight
= headerHeight
;
1426 public int getItemHeight() {
1430 public void setItemHeight(int rowHeight
) {
1431 this._itemHeight
= rowHeight
;
1434 public void setMinimumItemWidth(int width
) {
1435 this._minimumItemWidth
= width
;
1438 public int getMinimumItemWidth() {
1439 return _minimumItemWidth
;
1442 public Vector
<ITimeGraphEntry
> getFilteredOut() {
1443 return _data
.getFilteredOut();
1448 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
1449 if (listener
!= null) {
1450 if (!_selectionChangedListeners
.contains(listener
)) {
1451 _selectionChangedListeners
.add(listener
);
1458 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
1459 if (listener
!= null) {
1460 _selectionChangedListeners
.remove(listener
);
1466 public void setSelection(ISelection selection
) {
1467 if (selection
instanceof TimeGraphSelection
) {
1468 TimeGraphSelection sel
= (TimeGraphSelection
) selection
;
1469 Object ob
= sel
.getFirstElement();
1470 if (ob
instanceof ITimeGraphEntry
) {
1471 ITimeGraphEntry trace
= (ITimeGraphEntry
) ob
;
1472 selectItem(trace
, false);
1481 public TimeGraphItem
[] _expandedItems
= new TimeGraphItem
[0];
1482 public TimeGraphItem
[] _items
= new TimeGraphItem
[0];
1483 private ITimeGraphEntry _traces
[] = new ITimeGraphEntry
[0];
1484 private boolean traceFilter
[] = new boolean[0];
1485 private Vector
<ITimeGraphEntry
> filteredOut
= new Vector
<ITimeGraphEntry
>();
1486 public ITimeGraphPresentationProvider provider
;
1491 TimeGraphItem
findItem(ITimeGraphEntry entry
) {
1495 for (int i
= 0; i
< _items
.length
; i
++) {
1496 TimeGraphItem item
= _items
[i
];
1497 if (item
._trace
== entry
) {
1505 int findItemIndex(ITimeGraphEntry trace
) {
1509 for (int i
= 0; i
< _expandedItems
.length
; i
++) {
1510 TimeGraphItem item
= _expandedItems
[i
];
1511 if (item
._trace
== trace
) {
1519 public void refreshData() {
1520 List
<TimeGraphItem
> itemList
= new ArrayList
<TimeGraphItem
>();
1521 filteredOut
.clear();
1522 for (int i
= 0; i
< _traces
.length
; i
++) {
1523 ITimeGraphEntry entry
= _traces
[i
];
1524 refreshData(itemList
, null, 0, entry
);
1526 _items
= itemList
.toArray(new TimeGraphItem
[0]);
1527 updateExpandedItems();
1530 private void refreshData(List
<TimeGraphItem
> itemList
, TimeGraphItem parent
, int level
, ITimeGraphEntry entry
) {
1531 TimeGraphItem item
= new TimeGraphItem(entry
, entry
.getName(), level
);
1532 if (parent
!= null) {
1533 parent
.children
.add(item
);
1535 item
.itemHeight
= provider
.getItemHeight(entry
);
1537 if (entry
.hasChildren()) {
1538 item
._expanded
= true;
1539 item
._hasChildren
= true;
1540 for (ITimeGraphEntry child
: entry
.getChildren()) {
1541 refreshData(itemList
, item
, level
+ 1, child
);
1546 public void updateExpandedItems() {
1547 List
<TimeGraphItem
> expandedItemList
= new ArrayList
<TimeGraphItem
>();
1548 for (int i
= 0; i
< _traces
.length
; i
++) {
1549 ITimeGraphEntry entry
= _traces
[i
];
1550 TimeGraphItem item
= findItem(entry
);
1551 refreshExpanded(expandedItemList
, item
);
1553 _expandedItems
= expandedItemList
.toArray(new TimeGraphItem
[0]);
1556 private void refreshExpanded(List
<TimeGraphItem
> expandedItemList
, TimeGraphItem item
) {
1557 expandedItemList
.add(item
);
1558 if (item
._hasChildren
&& item
._expanded
) {
1559 for (TimeGraphItem child
: item
.children
) {
1560 refreshExpanded(expandedItemList
, child
);
1565 public void expandItem(int idx
) {
1566 if (idx
< 0 || idx
>= _expandedItems
.length
)
1568 TimeGraphItem item
= (TimeGraphItem
) _expandedItems
[idx
];
1569 if (item
._hasChildren
&& !item
._expanded
) {
1570 item
._expanded
= true;
1571 updateExpandedItems();
1575 public void refreshData(ITimeGraphEntry traces
[]) {
1576 if (traces
== null || traces
.length
== 0) {
1578 } else if (traceFilter
== null || traces
.length
!= traceFilter
.length
) {
1579 traceFilter
= new boolean[traces
.length
];
1580 java
.util
.Arrays
.fill(traceFilter
, true);
1587 public ITimeGraphEntry
[] getTraces() {
1591 public boolean[] getTraceFilter() {
1595 public Vector
<ITimeGraphEntry
> getFilteredOut() {