1 /*****************************************************************************
2 * Copyright (c) 2007, 2015 Intel Corporation and others
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Intel Corporation - Initial API and implementation
11 * Ruslan A. Scherbakov, Intel - Initial API and implementation
12 * Alvaro Sanchez-Leon, Ericsson - Updated for TMF
13 * Patrick Tasse, Ericsson - Refactoring
14 * Geneviève Bastien, École Polytechnique de Montréal - Move code to
15 * provide base classes for time graph view
16 * Add display of links between items
17 * Xavier Raynaud, Kalray - Code optimization
18 * Generoso Pagano, Inria - Support for drag selection listeners
19 *****************************************************************************/
21 package org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
;
23 import java
.util
.ArrayList
;
24 import java
.util
.Arrays
;
25 import java
.util
.Collections
;
26 import java
.util
.Iterator
;
27 import java
.util
.LinkedHashMap
;
28 import java
.util
.List
;
31 import org
.eclipse
.jface
.action
.IStatusLineManager
;
32 import org
.eclipse
.jface
.resource
.JFaceResources
;
33 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
34 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
35 import org
.eclipse
.jface
.viewers
.ISelection
;
36 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
37 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
38 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
39 import org
.eclipse
.osgi
.util
.NLS
;
40 import org
.eclipse
.swt
.SWT
;
41 import org
.eclipse
.swt
.events
.FocusEvent
;
42 import org
.eclipse
.swt
.events
.FocusListener
;
43 import org
.eclipse
.swt
.events
.KeyEvent
;
44 import org
.eclipse
.swt
.events
.KeyListener
;
45 import org
.eclipse
.swt
.events
.MenuDetectEvent
;
46 import org
.eclipse
.swt
.events
.MenuDetectListener
;
47 import org
.eclipse
.swt
.events
.MouseEvent
;
48 import org
.eclipse
.swt
.events
.MouseListener
;
49 import org
.eclipse
.swt
.events
.MouseMoveListener
;
50 import org
.eclipse
.swt
.events
.MouseTrackListener
;
51 import org
.eclipse
.swt
.events
.MouseWheelListener
;
52 import org
.eclipse
.swt
.events
.PaintEvent
;
53 import org
.eclipse
.swt
.events
.SelectionListener
;
54 import org
.eclipse
.swt
.events
.TraverseEvent
;
55 import org
.eclipse
.swt
.events
.TraverseListener
;
56 import org
.eclipse
.swt
.events
.TypedEvent
;
57 import org
.eclipse
.swt
.graphics
.Color
;
58 import org
.eclipse
.swt
.graphics
.Cursor
;
59 import org
.eclipse
.swt
.graphics
.GC
;
60 import org
.eclipse
.swt
.graphics
.Image
;
61 import org
.eclipse
.swt
.graphics
.Point
;
62 import org
.eclipse
.swt
.graphics
.Rectangle
;
63 import org
.eclipse
.swt
.widgets
.Composite
;
64 import org
.eclipse
.swt
.widgets
.Display
;
65 import org
.eclipse
.swt
.widgets
.Event
;
66 import org
.eclipse
.swt
.widgets
.Listener
;
67 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentSignal
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphColorListener
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTreeListener
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.StateItem
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTreeExpansionEvent
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
86 import com
.google
.common
.collect
.Iterables
;
89 * Time graph control implementation
91 * @author Alvaro Sanchez-Leon
92 * @author Patrick Tasse
94 public class TimeGraphControl
extends TimeGraphBaseControl
95 implements FocusListener
, KeyListener
, MouseMoveListener
, MouseListener
,
96 MouseWheelListener
, MouseTrackListener
, TraverseListener
, ISelectionProvider
,
97 MenuDetectListener
, ITmfTimeGraphDrawingHelper
, ITimeGraphColorListener
, Listener
{
99 /** Constant indicating that all levels of the time graph should be expanded */
100 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
102 private static final int DRAG_NONE
= 0;
103 private static final int DRAG_TRACE_ITEM
= 1;
104 private static final int DRAG_SPLIT_LINE
= 2;
105 private static final int DRAG_ZOOM
= 3;
106 private static final int DRAG_SELECTION
= 4;
108 private static final int CUSTOM_ITEM_HEIGHT
= -1; // get item height from provider
110 private static final double ZOOM_FACTOR
= 1.5;
111 private static final double ZOOM_IN_FACTOR
= 0.8;
112 private static final double ZOOM_OUT_FACTOR
= 1.25;
114 private static final int SNAP_WIDTH
= 2;
115 private static final int ARROW_HOVER_MAX_DIST
= 5;
117 private static final int NO_STATUS
= -1;
118 private static final int STATUS_WITHOUT_CURSOR_TIME
= -2;
120 private static final int MAX_LABEL_LENGTH
= 256;
122 /** Resource manager */
123 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
125 /** Color map for event types */
126 private Color
[] fEventColorMap
= null;
128 private ITimeDataProvider fTimeProvider
;
129 private IStatusLineManager fStatusLineManager
= null;
130 private TimeGraphScale fTimeGraphScale
= null;
132 private boolean fIsInFocus
= false;
133 private boolean fMouseOverSplitLine
= false;
134 private int fGlobalItemHeight
= CUSTOM_ITEM_HEIGHT
;
135 private boolean fBlendSubPixelEvents
= false;
136 private int fMinimumItemWidth
= 0;
137 private int fTopIndex
= 0;
138 private int fDragState
= DRAG_NONE
;
139 private boolean fDragBeginMarker
= false;
140 private int fDragButton
;
141 private int fDragX0
= 0;
142 private int fDragX
= 0;
143 private long fDragTime0
= 0; // used to preserve accuracy of modified selection
144 private int fIdealNameSpace
= 0;
145 private long fTime0bak
;
146 private long fTime1bak
;
147 private ITimeGraphPresentationProvider fTimeGraphProvider
= null;
148 private ItemData fItemData
= null;
149 private List
<IMarkerEvent
> fMarkers
= null;
150 private boolean fMarkersVisible
= true;
151 private List
<SelectionListener
> fSelectionListeners
;
152 private List
<ITimeGraphTimeListener
> fDragSelectionListeners
;
153 private final List
<ISelectionChangedListener
> fSelectionChangedListeners
= new ArrayList
<>();
154 private final List
<ITimeGraphTreeListener
> fTreeListeners
= new ArrayList
<>();
155 private final List
<MenuDetectListener
> fTimeGraphEntryMenuListeners
= new ArrayList
<>();
156 private final List
<MenuDetectListener
> fTimeEventMenuListeners
= new ArrayList
<>();
157 private final Cursor fDragCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_HAND
);
158 private final Cursor fResizeCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_IBEAM
);
159 private final Cursor fWaitCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_WAIT
);
160 private final Cursor fZoomCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_SIZEWE
);
161 private final List
<ViewerFilter
> fFilters
= new ArrayList
<>();
162 private MenuDetectEvent fPendingMenuDetectEvent
= null;
163 private boolean fGridLinesVisible
= true;
164 private Color fGridLineColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
);
165 private boolean fHideArrows
= false;
166 private int fAutoExpandLevel
= ALL_LEVELS
;
168 private int fBorderWidth
= 0;
169 private int fHeaderHeight
= 0;
172 * Standard constructor
175 * The parent composite object
177 * The color scheme to use
179 public TimeGraphControl(Composite parent
, TimeGraphColorScheme colors
) {
181 super(parent
, colors
, SWT
.NO_BACKGROUND
| SWT
.DOUBLE_BUFFERED
);
183 fItemData
= new ItemData();
185 addFocusListener(this);
186 addMouseListener(this);
187 addMouseMoveListener(this);
188 addMouseTrackListener(this);
189 addMouseWheelListener(this);
190 addTraverseListener(this);
191 addKeyListener(this);
192 addMenuDetectListener(this);
193 addListener(SWT
.MouseWheel
, this);
197 public void dispose() {
199 fResourceManager
.dispose();
203 * Sets the timegraph provider used by this timegraph viewer.
205 * @param timeGraphProvider the timegraph provider
207 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
208 fTimeGraphProvider
= timeGraphProvider
;
210 if (timeGraphProvider
instanceof ITimeGraphPresentationProvider2
) {
211 ((ITimeGraphPresentationProvider2
) timeGraphProvider
).setDrawingHelper(this);
212 ((ITimeGraphPresentationProvider2
) timeGraphProvider
).addColorListener(this);
215 StateItem
[] stateItems
= fTimeGraphProvider
.getStateTable();
216 colorSettingsChanged(stateItems
);
220 * Gets the timegraph provider used by this timegraph viewer.
222 * @return the timegraph provider, or <code>null</code> if not set.
224 public ITimeGraphPresentationProvider
getTimeGraphProvider() {
225 return fTimeGraphProvider
;
229 * Gets the color map used by this timegraph viewer.
231 * @return a color map, or <code>null</code> if not set.
233 public Color
[] getEventColorMap() {
234 return fEventColorMap
;
238 * Assign the given time provider
240 * @param timeProvider
243 public void setTimeProvider(ITimeDataProvider timeProvider
) {
244 fTimeProvider
= timeProvider
;
249 * Assign the status line manager
251 * @param statusLineManager
252 * The status line manager, or null to disable status line messages
254 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
255 if (fStatusLineManager
!= null && statusLineManager
== null) {
256 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
258 fStatusLineManager
= statusLineManager
;
262 * Assign the time graph scale
264 * @param timeGraphScale
265 * The time graph scale
267 public void setTimeGraphScale(TimeGraphScale timeGraphScale
) {
268 fTimeGraphScale
= timeGraphScale
;
272 * Add a selection listener
275 * The listener to add
277 public void addSelectionListener(SelectionListener listener
) {
278 if (listener
== null) {
279 SWT
.error(SWT
.ERROR_NULL_ARGUMENT
);
281 if (null == fSelectionListeners
) {
282 fSelectionListeners
= new ArrayList
<>();
284 fSelectionListeners
.add(listener
);
288 * Remove a selection listener
291 * The listener to remove
293 public void removeSelectionListener(SelectionListener listener
) {
294 if (null != fSelectionListeners
) {
295 fSelectionListeners
.remove(listener
);
300 * Selection changed callback
302 public void fireSelectionChanged() {
303 if (null != fSelectionListeners
) {
304 Iterator
<SelectionListener
> it
= fSelectionListeners
.iterator();
305 while (it
.hasNext()) {
306 SelectionListener listener
= it
.next();
307 listener
.widgetSelected(null);
313 * Default selection callback
315 public void fireDefaultSelection() {
316 if (null != fSelectionListeners
) {
317 Iterator
<SelectionListener
> it
= fSelectionListeners
.iterator();
318 while (it
.hasNext()) {
319 SelectionListener listener
= it
.next();
320 listener
.widgetDefaultSelected(null);
326 * Add a drag selection listener
329 * The listener to add
331 public void addDragSelectionListener(ITimeGraphTimeListener listener
) {
332 if (listener
== null) {
333 SWT
.error(SWT
.ERROR_NULL_ARGUMENT
);
335 if (null == fDragSelectionListeners
) {
336 fDragSelectionListeners
= new ArrayList
<>();
338 fDragSelectionListeners
.add(listener
);
342 * Remove a drag selection listener
345 * The listener to remove
347 public void removeDragSelectionListener(ITimeGraphTimeListener listener
) {
348 if (null != fDragSelectionListeners
) {
349 fDragSelectionListeners
.remove(listener
);
354 * Drag Selection changed callback
357 * Time interval start
361 public void fireDragSelectionChanged(long start
, long end
) {
362 // check for backward intervals
363 long beginTime
, endTime
;
371 // call the listeners
372 if (null != fDragSelectionListeners
) {
373 Iterator
<ITimeGraphTimeListener
> it
= fDragSelectionListeners
.iterator();
374 while (it
.hasNext()) {
375 ITimeGraphTimeListener listener
= it
.next();
376 listener
.timeSelected(new TimeGraphTimeEvent(this, beginTime
, endTime
));
382 * Get the traces in the model
384 * @return The array of traces
386 public ITimeGraphEntry
[] getTraces() {
387 return fItemData
.getEntries();
391 * Refresh the data for the thing
393 public void refreshData() {
394 fItemData
.refreshData();
399 * Refresh data for the given traces
402 * The traces to refresh
404 public void refreshData(ITimeGraphEntry
[] traces
) {
405 fItemData
.refreshData(traces
);
410 * Refresh the links (arrows) of this widget
412 * @param events The link event list
414 public void refreshArrows(List
<ILinkEvent
> events
) {
415 fItemData
.refreshArrows(events
);
419 * Get the links (arrows) of this widget
421 * @return The unmodifiable link event list
425 public List
<ILinkEvent
> getArrows() {
426 return Collections
.unmodifiableList(fItemData
.fLinks
);
429 boolean ensureVisibleItem(int idx
, boolean redraw
) {
430 boolean changed
= false;
433 for (index
= 0; index
< fItemData
.fExpandedItems
.length
; index
++) {
434 if (fItemData
.fExpandedItems
[index
].fSelected
) {
439 if (index
>= fItemData
.fExpandedItems
.length
) {
442 if (index
< fTopIndex
) {
449 int page
= countPerPage();
450 if (index
>= fTopIndex
+ page
) {
451 setTopIndex(index
- page
+ 1);
462 * Assign the given index as the top one
467 public void setTopIndex(int idx
) {
468 int index
= Math
.min(idx
, fItemData
.fExpandedItems
.length
- countPerPage());
469 index
= Math
.max(0, index
);
475 * Sets the auto-expand level to be used for new entries discovered when
476 * calling {@link #refreshData()} or {@link #refreshData(ITimeGraphEntry[])}
477 * . The value 0 means that there is no auto-expand; 1 means that top-level
478 * entries are expanded, but not their children; 2 means that top-level
479 * entries are expanded, and their children, but not grand-children; and so
482 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
486 * non-negative level, or <code>ALL_LEVELS</code> to expand all
489 public void setAutoExpandLevel(int level
) {
490 fAutoExpandLevel
= level
;
494 * Returns the auto-expand level.
496 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
497 * the tree are expanded automatically
498 * @see #setAutoExpandLevel
500 public int getAutoExpandLevel() {
501 return fAutoExpandLevel
;
505 * Get the expanded state of a given entry.
509 * @return true if the entry is expanded, false if collapsed
512 public boolean getExpandedState(ITimeGraphEntry entry
) {
513 Item item
= fItemData
.fItemMap
.get(entry
);
514 return (item
!= null ? item
.fExpanded
: false);
518 * Set the expanded state of a given entry
523 * True if expanded, false if collapsed
525 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
526 Item item
= fItemData
.findItem(entry
);
527 if (item
!= null && item
.fExpanded
!= expanded
) {
528 item
.fExpanded
= expanded
;
529 fItemData
.updateExpandedItems();
535 * Collapses all nodes of the viewer's tree, starting with the root.
537 public void collapseAll() {
538 for (Item item
: fItemData
.fItems
) {
539 item
.fExpanded
= false;
541 fItemData
.updateExpandedItems();
546 * Expands all nodes of the viewer's tree, starting with the root.
548 public void expandAll() {
549 for (Item item
: fItemData
.fItems
) {
550 item
.fExpanded
= true;
552 fItemData
.updateExpandedItems();
557 * Add a tree listener
560 * The listener to add
562 public void addTreeListener(ITimeGraphTreeListener listener
) {
563 if (!fTreeListeners
.contains(listener
)) {
564 fTreeListeners
.add(listener
);
569 * Remove a tree listener
572 * The listener to remove
574 public void removeTreeListener(ITimeGraphTreeListener listener
) {
575 if (fTreeListeners
.contains(listener
)) {
576 fTreeListeners
.remove(listener
);
581 * Tree event callback
586 * The expanded state (true for expanded, false for collapsed)
588 public void fireTreeEvent(ITimeGraphEntry entry
, boolean expanded
) {
589 TimeGraphTreeExpansionEvent event
= new TimeGraphTreeExpansionEvent(this, entry
);
590 for (ITimeGraphTreeListener listener
: fTreeListeners
) {
592 listener
.treeExpanded(event
);
594 listener
.treeCollapsed(event
);
600 * Add a menu listener on {@link ITimeGraphEntry}s
603 * The listener to add
605 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
606 if (!fTimeGraphEntryMenuListeners
.contains(listener
)) {
607 fTimeGraphEntryMenuListeners
.add(listener
);
612 * Remove a menu listener on {@link ITimeGraphEntry}s
615 * The listener to remove
617 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
618 if (fTimeGraphEntryMenuListeners
.contains(listener
)) {
619 fTimeGraphEntryMenuListeners
.remove(listener
);
624 * Menu event callback on {@link ITimeGraphEntry}s
627 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeGraphEntry}
629 private void fireMenuEventOnTimeGraphEntry(MenuDetectEvent event
) {
630 for (MenuDetectListener listener
: fTimeGraphEntryMenuListeners
) {
631 listener
.menuDetected(event
);
636 * Add a menu listener on {@link ITimeEvent}s
639 * The listener to add
641 public void addTimeEventMenuListener(MenuDetectListener listener
) {
642 if (!fTimeEventMenuListeners
.contains(listener
)) {
643 fTimeEventMenuListeners
.add(listener
);
648 * Remove a menu listener on {@link ITimeEvent}s
651 * The listener to remove
653 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
654 if (fTimeEventMenuListeners
.contains(listener
)) {
655 fTimeEventMenuListeners
.remove(listener
);
660 * Menu event callback on {@link ITimeEvent}s
663 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeEvent}
665 private void fireMenuEventOnTimeEvent(MenuDetectEvent event
) {
666 for (MenuDetectListener listener
: fTimeEventMenuListeners
) {
667 listener
.menuDetected(event
);
672 public ISelection
getSelection() {
673 TimeGraphSelection sel
= new TimeGraphSelection();
674 ITimeGraphEntry trace
= getSelectedTrace();
675 if (null != trace
&& null != fTimeProvider
) {
676 long selectedTime
= fTimeProvider
.getSelectionBegin();
677 ITimeEvent event
= Utils
.findEvent(trace
, selectedTime
, 0);
688 * Get the selection object
690 * @return The selection
692 public ISelection
getSelectionTrace() {
693 TimeGraphSelection sel
= new TimeGraphSelection();
694 ITimeGraphEntry trace
= getSelectedTrace();
702 * Enable/disable one of the traces in the model
705 * 1 to enable it, -1 to disable. The method returns immediately
706 * if another value is used.
708 public void selectTrace(int n
) {
709 if ((n
!= 1) && (n
!= -1)) {
713 boolean changed
= false;
714 int lastSelection
= -1;
715 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
716 Item item
= fItemData
.fExpandedItems
[i
];
717 if (item
.fSelected
) {
719 if ((1 == n
) && (i
< fItemData
.fExpandedItems
.length
- 1)) {
720 item
.fSelected
= false;
721 item
= fItemData
.fExpandedItems
[i
+ 1];
722 item
.fSelected
= true;
724 } else if ((-1 == n
) && (i
> 0)) {
725 item
.fSelected
= false;
726 item
= fItemData
.fExpandedItems
[i
- 1];
727 item
.fSelected
= true;
734 if (lastSelection
< 0 && fItemData
.fExpandedItems
.length
> 0) {
735 Item item
= fItemData
.fExpandedItems
[0];
736 item
.fSelected
= true;
741 ensureVisibleItem(-1, false);
743 fireSelectionChanged();
751 * 1 for next event, -1 for previous event
753 * true to extend selection range, false for single selection
756 public void selectEvent(int n
, boolean extend
) {
757 if (null == fTimeProvider
) {
760 ITimeGraphEntry trace
= getSelectedTrace();
764 long selectedTime
= fTimeProvider
.getSelectionEnd();
765 long endTime
= fTimeProvider
.getMaxTime();
766 ITimeEvent nextEvent
;
767 if (n
== -1 && selectedTime
> endTime
) {
768 nextEvent
= Utils
.findEvent(trace
, selectedTime
, 0);
770 nextEvent
= Utils
.findEvent(trace
, selectedTime
, n
);
772 if (null == nextEvent
&& n
== -1) {
773 nextEvent
= Utils
.getFirstEvent(trace
);
775 if (null != nextEvent
) {
776 long nextTime
= nextEvent
.getTime();
777 // If last event detected e.g. going back or not moving to a next
779 if (nextTime
<= selectedTime
&& n
== 1) {
780 // Select to the end of this last event
781 nextTime
= nextEvent
.getTime() + nextEvent
.getDuration();
782 // but not beyond the end of the trace
783 if (nextTime
> endTime
) {
786 } else if (n
== -1 && nextEvent
.getTime() + nextEvent
.getDuration() < selectedTime
) {
787 // for previous event go to its end time unless we were already there
788 nextTime
= nextEvent
.getTime() + nextEvent
.getDuration();
791 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), nextTime
);
793 fTimeProvider
.setSelectedTimeNotify(nextTime
, true);
795 fireSelectionChanged();
798 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), endTime
);
800 fTimeProvider
.setSelectedTimeNotify(endTime
, true);
802 fireSelectionChanged();
804 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
808 * Select the next event
811 * true to extend selection range, false for single selection
814 public void selectNextEvent(boolean extend
) {
815 selectEvent(1, extend
);
816 // Notify if visible time window has been adjusted
817 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
821 * Select the previous event
824 * true to extend selection range, false for single selection
827 public void selectPrevEvent(boolean extend
) {
828 selectEvent(-1, extend
);
829 // Notify if visible time window has been adjusted
830 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
834 * Select the next trace
836 public void selectNextTrace() {
841 * Select the previous trace
843 public void selectPrevTrace() {
848 * Scroll left or right by one half window size
851 * true to scroll left, false to scroll right
853 public void horizontalScroll(boolean left
) {
854 long time0
= fTimeProvider
.getTime0();
855 long time1
= fTimeProvider
.getTime1();
856 long timeMin
= fTimeProvider
.getMinTime();
857 long timeMax
= fTimeProvider
.getMaxTime();
858 long range
= time1
- time0
;
862 long increment
= Math
.max(1, range
/ 2);
864 time0
= Math
.max(time0
- increment
, timeMin
);
865 time1
= time0
+ range
;
867 time1
= Math
.min(time1
+ increment
, timeMax
);
868 time0
= time1
- range
;
870 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
874 * Zoom based on mouse cursor location with mouse scrolling
876 * @param zoomIn true to zoom in, false to zoom out
878 public void zoom(boolean zoomIn
) {
879 int globalX
= getDisplay().getCursorLocation().x
;
880 Point p
= toControl(globalX
, 0);
881 int nameSpace
= fTimeProvider
.getNameSpace();
882 int timeSpace
= fTimeProvider
.getTimeSpace();
883 int xPos
= Math
.max(nameSpace
, Math
.min(nameSpace
+ timeSpace
, p
.x
));
884 long time0
= fTimeProvider
.getTime0();
885 long time1
= fTimeProvider
.getTime1();
886 long interval
= time1
- time0
;
889 } // to allow getting out of single point interval
892 newInterval
= Math
.max(Math
.round(interval
* ZOOM_IN_FACTOR
), fTimeProvider
.getMinTimeInterval());
894 newInterval
= (long) Math
.ceil(interval
* ZOOM_OUT_FACTOR
);
896 long center
= time0
+ Math
.round(((double) (xPos
- nameSpace
) / timeSpace
* interval
));
897 long newTime0
= center
- Math
.round((double) newInterval
* (center
- time0
) / interval
);
898 long newTime1
= newTime0
+ newInterval
;
899 fTimeProvider
.setStartFinishTimeNotify(newTime0
, newTime1
);
903 * zoom in using single click
905 public void zoomIn() {
906 long prevTime0
= fTimeProvider
.getTime0();
907 long prevTime1
= fTimeProvider
.getTime1();
908 long prevRange
= prevTime1
- prevTime0
;
909 if (prevRange
== 0) {
912 ITimeDataProvider provider
= fTimeProvider
;
913 long selTime
= (provider
.getSelectionEnd() + provider
.getSelectionBegin()) / 2;
914 if (selTime
<= prevTime0
|| selTime
>= prevTime1
) {
915 selTime
= (prevTime0
+ prevTime1
) / 2;
917 long time0
= selTime
- (long) ((selTime
- prevTime0
) / ZOOM_FACTOR
);
918 long time1
= selTime
+ (long) ((prevTime1
- selTime
) / ZOOM_FACTOR
);
920 long inaccuracy
= (fTimeProvider
.getMaxTime() - fTimeProvider
.getMinTime()) - (time1
- time0
);
922 if (inaccuracy
> 0 && inaccuracy
< 100) {
923 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getMinTime(), fTimeProvider
.getMaxTime());
927 long min
= fTimeProvider
.getMinTimeInterval();
928 if ((time1
- time0
) < min
) {
929 time0
= selTime
- (selTime
- prevTime0
) * min
/ prevRange
;
933 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
937 * zoom out using single click
939 public void zoomOut() {
940 long prevTime0
= fTimeProvider
.getTime0();
941 long prevTime1
= fTimeProvider
.getTime1();
942 ITimeDataProvider provider
= fTimeProvider
;
943 long selTime
= (provider
.getSelectionEnd() + provider
.getSelectionBegin()) / 2;
944 if (selTime
<= prevTime0
|| selTime
>= prevTime1
) {
945 selTime
= (prevTime0
+ prevTime1
) / 2;
947 long time0
= (long) (selTime
- (selTime
- prevTime0
) * ZOOM_FACTOR
);
948 long time1
= (long) (selTime
+ (prevTime1
- selTime
) * ZOOM_FACTOR
);
950 long inaccuracy
= (fTimeProvider
.getMaxTime() - fTimeProvider
.getMinTime()) - (time1
- time0
);
951 if (inaccuracy
> 0 && inaccuracy
< 100) {
952 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getMinTime(), fTimeProvider
.getMaxTime());
956 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
960 * Set the grid lines visibility. The default is true.
963 * true to show the grid lines, false otherwise
966 public void setGridLinesVisible(boolean visible
) {
967 fGridLinesVisible
= visible
;
971 * Get the grid lines visibility.
973 * @return true if the grid lines are visible, false otherwise
976 public boolean getGridLinesVisible() {
977 return fGridLinesVisible
;
981 * Set the grid line color. The default is SWT.COLOR_GRAY.
984 * the grid line color
987 public void setGridLineColor(Color color
) {
988 fGridLineColor
= color
;
992 * Get the grid line color.
994 * @return the grid line color
997 public Color
getGridLineColor() {
998 return fGridLineColor
;
1002 * Set the markers list.
1005 * The markers list, or null
1008 public void setMarkers(List
<IMarkerEvent
> markers
) {
1010 fTimeGraphScale
.setMarkers(markers
);
1014 * Get the markers list.
1016 * @return The markers list, or null
1019 public List
<IMarkerEvent
> getMarkers() {
1024 * Set the markers visibility. The default is true.
1027 * true to show the markers, false otherwise
1030 public void setMarkersVisible(boolean visible
) {
1031 fMarkersVisible
= visible
;
1032 fTimeGraphScale
.setMarkersVisible(visible
);
1036 * Get the markers visibility.
1038 * @return true if the markers are visible, false otherwise
1041 public boolean getMarkersVisible() {
1042 return fMarkersVisible
;
1048 * @param hideArrows true to hide arrows
1050 public void hideArrows(boolean hideArrows
) {
1051 fHideArrows
= hideArrows
;
1055 * Follow the arrow forward
1058 * true to extend selection range, false for single selection
1061 public void followArrowFwd(boolean extend
) {
1062 ITimeGraphEntry trace
= getSelectedTrace();
1063 if (trace
== null) {
1066 long selectedTime
= fTimeProvider
.getSelectionEnd();
1067 for (ILinkEvent link
: fItemData
.fLinks
) {
1068 if (link
.getEntry() == trace
&& link
.getTime() == selectedTime
) {
1069 selectItem(link
.getDestinationEntry(), false);
1070 if (link
.getDuration() != 0) {
1072 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime() + link
.getDuration());
1074 fTimeProvider
.setSelectedTimeNotify(link
.getTime() + link
.getDuration(), true);
1076 // Notify if visible time window has been adjusted
1077 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1079 fireSelectionChanged();
1080 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1084 selectNextEvent(extend
);
1088 * Follow the arrow backward
1091 * true to extend selection range, false for single selection
1094 public void followArrowBwd(boolean extend
) {
1095 ITimeGraphEntry trace
= getSelectedTrace();
1096 if (trace
== null) {
1099 long selectedTime
= fTimeProvider
.getSelectionEnd();
1100 for (ILinkEvent link
: fItemData
.fLinks
) {
1101 if (link
.getDestinationEntry() == trace
&& link
.getTime() + link
.getDuration() == selectedTime
) {
1102 selectItem(link
.getEntry(), false);
1103 if (link
.getDuration() != 0) {
1105 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime());
1107 fTimeProvider
.setSelectedTimeNotify(link
.getTime(), true);
1109 // Notify if visible time window has been adjusted
1110 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1112 fireSelectionChanged();
1113 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1117 selectPrevEvent(extend
);
1121 * Return the currently selected trace
1123 * @return The entry matching the trace
1125 public ITimeGraphEntry
getSelectedTrace() {
1126 ITimeGraphEntry trace
= null;
1127 int idx
= getSelectedIndex();
1129 trace
= fItemData
.fExpandedItems
[idx
].fEntry
;
1135 * Retrieve the index of the currently selected item
1139 public int getSelectedIndex() {
1141 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1142 Item item
= fItemData
.fExpandedItems
[i
];
1143 if (item
.fSelected
) {
1151 boolean toggle(int idx
) {
1152 boolean toggled
= false;
1153 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1154 Item item
= fItemData
.fExpandedItems
[idx
];
1155 if (item
.fHasChildren
) {
1156 item
.fExpanded
= !item
.fExpanded
;
1157 fItemData
.updateExpandedItems();
1160 fireTreeEvent(item
.fEntry
, item
.fExpanded
);
1167 * Gets the index of the item at the given location.
1171 * @return the index of the item at the given location, of -1 if none.
1173 protected int getItemIndexAtY(int y
) {
1178 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1179 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1187 boolean isOverSplitLine(int x
) {
1188 if (x
< 0 || null == fTimeProvider
) {
1191 int nameWidth
= fTimeProvider
.getNameSpace();
1192 return Math
.abs(x
- nameWidth
) < SNAP_WIDTH
;
1196 * Gets the {@link ITimeGraphEntry} at the given location.
1199 * a point in the widget
1200 * @return the {@link ITimeGraphEntry} at this point, or <code>null</code>
1203 protected ITimeGraphEntry
getEntry(Point pt
) {
1204 int idx
= getItemIndexAtY(pt
.y
);
1205 return idx
>= 0 ? fItemData
.fExpandedItems
[idx
].fEntry
: null;
1209 * Return the arrow event closest to the given point that is no further than
1210 * a maximum distance.
1213 * a point in the widget
1214 * @return The closest arrow event, or null if there is none close enough.
1216 protected ILinkEvent
getArrow(Point pt
) {
1220 ILinkEvent linkEvent
= null;
1221 double minDistance
= Double
.MAX_VALUE
;
1222 for (ILinkEvent event
: fItemData
.fLinks
) {
1223 Rectangle rect
= getArrowRectangle(new Rectangle(0, 0, 0, 0), event
);
1227 int x2
= x1
+ rect
.width
;
1228 int y2
= y1
+ rect
.height
;
1229 double d
= Utils
.distance(pt
.x
, pt
.y
, x1
, y1
, x2
, y2
);
1230 if (minDistance
> d
) {
1236 if (minDistance
<= ARROW_HOVER_MAX_DIST
) {
1243 public int getXForTime(long time
) {
1244 if (null == fTimeProvider
) {
1247 long time0
= fTimeProvider
.getTime0();
1248 long time1
= fTimeProvider
.getTime1();
1249 int width
= getSize().x
;
1250 int nameSpace
= fTimeProvider
.getNameSpace();
1251 double pixelsPerNanoSec
= (width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1252 int x
= getBounds().x
+ nameSpace
+ (int) ((time
- time0
) * pixelsPerNanoSec
);
1257 public long getTimeAtX(int coord
) {
1258 if (null == fTimeProvider
) {
1262 Point size
= getSize();
1263 long time0
= fTimeProvider
.getTime0();
1264 long time1
= fTimeProvider
.getTime1();
1265 int nameWidth
= fTimeProvider
.getNameSpace();
1266 final int x
= coord
- nameWidth
;
1267 int timeWidth
= size
.x
- nameWidth
- RIGHT_MARGIN
;
1268 if (x
>= 0 && size
.x
>= nameWidth
) {
1269 if (time1
- time0
> timeWidth
) {
1270 // nanosecond smaller than one pixel: use the first integer nanosecond of this pixel's time range
1271 hitTime
= time0
+ (long) Math
.ceil((time1
- time0
) * ((double) x
/ timeWidth
));
1273 // nanosecond greater than one pixel: use the nanosecond that covers this pixel start position
1274 hitTime
= time0
+ (long) Math
.floor((time1
- time0
) * ((double) x
/ timeWidth
));
1280 void selectItem(int idx
, boolean addSelection
) {
1281 boolean changed
= false;
1283 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1284 Item item
= fItemData
.fExpandedItems
[idx
];
1285 changed
= !item
.fSelected
;
1286 item
.fSelected
= true;
1289 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1290 Item item
= fItemData
.fExpandedItems
[i
];
1291 if ((i
== idx
&& !item
.fSelected
) || (idx
== -1 && item
.fSelected
)) {
1294 item
.fSelected
= i
== idx
;
1297 changed
|= ensureVisibleItem(idx
, true);
1304 * Callback for item selection
1307 * The entry matching the trace
1308 * @param addSelection
1309 * If the selection is added or removed
1311 public void selectItem(ITimeGraphEntry trace
, boolean addSelection
) {
1312 int idx
= fItemData
.findItemIndex(trace
);
1313 selectItem(idx
, addSelection
);
1317 * Retrieve the number of entries shown per page.
1321 public int countPerPage() {
1322 int height
= getSize().y
;
1325 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1326 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1327 if (ySum
>= height
) {
1332 for (int idx
= fTopIndex
- 1; idx
>= 0; idx
--) {
1333 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1334 if (ySum
>= height
) {
1343 * Get the index of the top element
1347 public int getTopIndex() {
1352 * Get the number of expanded (visible) items
1354 * @return The count of expanded (visible) items
1356 public int getExpandedElementCount() {
1357 return fItemData
.fExpandedItems
.length
;
1361 * Get an array of all expanded (visible) elements
1363 * @return The expanded (visible) elements
1365 public ITimeGraphEntry
[] getExpandedElements() {
1366 ArrayList
<ITimeGraphEntry
> elements
= new ArrayList
<>();
1367 for (Item item
: fItemData
.fExpandedItems
) {
1368 elements
.add(item
.fEntry
);
1370 return elements
.toArray(new ITimeGraphEntry
[0]);
1373 Rectangle
getNameRect(Rectangle bounds
, int idx
, int nameWidth
) {
1374 Rectangle rect
= getItemRect(bounds
, idx
);
1375 rect
.width
= nameWidth
;
1379 Rectangle
getStatesRect(Rectangle bounds
, int idx
, int nameWidth
) {
1380 Rectangle rect
= getItemRect(bounds
, idx
);
1381 rect
.x
+= nameWidth
;
1382 rect
.width
-= nameWidth
;
1386 Rectangle
getItemRect(Rectangle bounds
, int idx
) {
1388 if (idx
>= fTopIndex
) {
1389 for (int i
= fTopIndex
; i
< idx
; i
++) {
1390 ySum
+= fItemData
.fExpandedItems
[i
].fItemHeight
;
1393 for (int i
= fTopIndex
- 1; i
>= idx
; i
--) {
1394 ySum
-= fItemData
.fExpandedItems
[i
].fItemHeight
;
1397 int y
= bounds
.y
+ ySum
;
1398 int height
= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1399 return new Rectangle(bounds
.x
, y
, bounds
.width
, height
);
1403 void paint(Rectangle bounds
, PaintEvent e
) {
1406 if (bounds
.width
< 2 || bounds
.height
< 2 || null == fTimeProvider
) {
1410 fIdealNameSpace
= 0;
1411 int nameSpace
= fTimeProvider
.getNameSpace();
1413 // draw the background layer
1414 drawBackground(bounds
, nameSpace
, gc
);
1416 // draw the grid lines
1417 drawGridLines(bounds
, gc
);
1419 // draw the background markers
1420 drawMarkers(bounds
, fTimeProvider
, fMarkers
, false, nameSpace
, gc
);
1423 drawItems(bounds
, fTimeProvider
, fItemData
.fExpandedItems
, fTopIndex
, nameSpace
, gc
);
1425 // draw the foreground markers
1426 drawMarkers(bounds
, fTimeProvider
, fMarkers
, true, nameSpace
, gc
);
1428 // draw the links (arrows)
1429 drawLinks(bounds
, fTimeProvider
, fItemData
.fLinks
, nameSpace
, gc
);
1431 fTimeGraphProvider
.postDrawControl(bounds
, gc
);
1433 int alpha
= gc
.getAlpha();
1436 long time0
= fTimeProvider
.getTime0();
1437 long time1
= fTimeProvider
.getTime1();
1438 long selectionBegin
= fTimeProvider
.getSelectionBegin();
1439 long selectionEnd
= fTimeProvider
.getSelectionEnd();
1440 double pixelsPerNanoSec
= (bounds
.width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (bounds
.width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1441 int x0
= bounds
.x
+ nameSpace
+ (int) ((selectionBegin
- time0
) * pixelsPerNanoSec
);
1442 int x1
= bounds
.x
+ nameSpace
+ (int) ((selectionEnd
- time0
) * pixelsPerNanoSec
);
1444 // draw selection lines
1445 if (fDragState
!= DRAG_SELECTION
) {
1446 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1447 if (x0
>= nameSpace
&& x0
< bounds
.x
+ bounds
.width
) {
1448 gc
.drawLine(x0
, bounds
.y
, x0
, bounds
.y
+ bounds
.height
);
1451 if (x1
>= nameSpace
&& x1
< bounds
.x
+ bounds
.width
) {
1452 gc
.drawLine(x1
, bounds
.y
, x1
, bounds
.y
+ bounds
.height
);
1457 // draw selection background
1458 if (selectionBegin
!= 0 && selectionEnd
!= 0 && fDragState
!= DRAG_SELECTION
) {
1459 x0
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x0
));
1460 x1
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x1
));
1461 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1463 gc
.fillRectangle(new Rectangle(x0
+ 1, bounds
.y
, x1
- x0
- 1, bounds
.height
));
1464 } else if (x0
- x1
> 1) {
1465 gc
.fillRectangle(new Rectangle(x1
+ 1, bounds
.y
, x0
- x1
- 1, bounds
.height
));
1469 // draw drag selection background
1470 if (fDragState
== DRAG_ZOOM
|| fDragState
== DRAG_SELECTION
) {
1471 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1472 if (fDragX0
< fDragX
) {
1473 gc
.fillRectangle(new Rectangle(fDragX0
, bounds
.y
, fDragX
- fDragX0
, bounds
.height
));
1474 } else if (fDragX0
> fDragX
) {
1475 gc
.fillRectangle(new Rectangle(fDragX
, bounds
.y
, fDragX0
- fDragX
, bounds
.height
));
1480 if (DRAG_SPLIT_LINE
== fDragState
) {
1481 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.BLACK
));
1482 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1483 } else if (DRAG_ZOOM
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1484 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.TOOL_FOREGROUND
));
1485 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1486 if (fDragX
!= fDragX0
) {
1487 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1489 } else if (DRAG_SELECTION
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1490 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1491 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1492 if (fDragX
!= fDragX0
) {
1493 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1495 } else if (DRAG_NONE
== fDragState
&& fMouseOverSplitLine
&& fTimeProvider
.getNameSpace() > 0) {
1496 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.RED
));
1497 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1504 * Draw the background layer. Fills the background of the control's name
1505 * space and states space, updates the background of items if necessary,
1506 * and draws the item's name text and middle line.
1509 * The bounds of the control
1511 * The name space width
1516 protected void drawBackground(Rectangle bounds
, int nameSpace
, GC gc
) {
1517 // draw empty name space background
1518 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1519 drawBackground(gc
, bounds
.x
, bounds
.y
, nameSpace
, bounds
.height
);
1521 // draw empty states space background
1522 gc
.setBackground(getColorScheme().getColor(TimeGraphColorScheme
.BACKGROUND
));
1523 drawBackground(gc
, bounds
.x
+ nameSpace
, bounds
.y
, bounds
.width
- nameSpace
, bounds
.height
);
1525 for (int i
= fTopIndex
; i
< fItemData
.fExpandedItems
.length
; i
++) {
1526 Rectangle itemRect
= getItemRect(bounds
, i
);
1527 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1530 Item item
= fItemData
.fExpandedItems
[i
];
1531 // draw the background of selected item and items with no time events
1532 if (! item
.fEntry
.hasTimeEvents()) {
1533 gc
.setBackground(getColorScheme().getBkColorGroup(item
.fSelected
, fIsInFocus
));
1534 gc
.fillRectangle(itemRect
);
1535 } else if (item
.fSelected
) {
1536 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, true));
1537 gc
.fillRectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1538 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, false));
1539 gc
.fillRectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1541 // draw the name and middle line
1542 if (! item
.fEntry
.hasTimeEvents()) {
1543 drawName(item
, itemRect
, gc
);
1545 Rectangle nameRect
= new Rectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1546 drawName(item
, nameRect
, gc
);
1547 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1548 drawMidLine(rect
, gc
);
1554 * Draw the grid lines
1557 * The bounds of the control
1562 public void drawGridLines(Rectangle bounds
, GC gc
) {
1563 if (!fGridLinesVisible
) {
1566 gc
.setForeground(fGridLineColor
);
1567 gc
.setAlpha(fGridLineColor
.getAlpha());
1568 for (int x
: fTimeGraphScale
.getTickList()) {
1569 gc
.drawLine(x
, bounds
.y
, x
, bounds
.y
+ bounds
.height
);
1578 * The rectangle of the area
1579 * @param timeProvider
1582 * The list of markers
1584 * true to draw the foreground markers, false otherwise
1586 * The width reserved for the names
1588 * Reference to the SWT GC object
1591 protected void drawMarkers(Rectangle bounds
, ITimeDataProvider timeProvider
, List
<IMarkerEvent
> markers
, boolean foreground
, int nameSpace
, GC gc
) {
1592 if (!fMarkersVisible
|| markers
== null || markers
.isEmpty()) {
1595 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1596 /* the list can grow concurrently but cannot shrink */
1597 for (int i
= 0; i
< markers
.size(); i
++) {
1598 IMarkerEvent marker
= markers
.get(i
);
1599 if (marker
.isForeground() == foreground
) {
1600 drawMarker(marker
, bounds
, timeProvider
, nameSpace
, gc
);
1603 gc
.setClipping((Rectangle
) null);
1607 * Draw a single marker
1612 * The bounds of the control
1613 * @param timeProvider
1616 * The width reserved for the name
1618 * Reference to the SWT GC object
1621 protected void drawMarker(IMarkerEvent marker
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1622 Rectangle rect
= Utils
.clone(bounds
);
1623 if (marker
.getEntry() != null) {
1624 int index
= fItemData
.findItemIndex(marker
.getEntry());
1628 rect
= getStatesRect(bounds
, index
, nameSpace
);
1629 if (rect
.y
< 0 || rect
.y
> bounds
.height
) {
1633 int x0
= getXForTime(marker
.getTime());
1634 int x1
= getXForTime(marker
.getTime() + marker
.getDuration());
1635 if (x0
> bounds
.width
|| x1
< nameSpace
) {
1638 rect
.x
= Math
.max(nameSpace
, Math
.min(bounds
.width
, x0
));
1639 rect
.width
= Math
.max(1, Math
.min(bounds
.width
, x1
) - rect
.x
);
1641 gc
.setBackground(marker
.getColor());
1642 gc
.setAlpha(marker
.getColor().getAlpha());
1643 gc
.fillRectangle(rect
);
1645 String label
= marker
.getLabel();
1646 if (label
!= null && marker
.getEntry() != null) {
1647 label
= label
.substring(0, Math
.min(label
.indexOf('\n') != -1 ? label
.indexOf('\n') : label
.length(), MAX_LABEL_LENGTH
));
1648 gc
.setForeground(marker
.getColor());
1649 Utils
.drawText(gc
, label
, rect
.x
- gc
.textExtent(label
).x
, rect
.y
, true);
1654 * Draw many items at once
1657 * The bounds of the control
1658 * @param timeProvider
1661 * The array items to draw
1663 * The index of the first element to draw
1665 * The name space width
1669 public void drawItems(Rectangle bounds
, ITimeDataProvider timeProvider
,
1670 Item
[] items
, int topIndex
, int nameSpace
, GC gc
) {
1671 for (int i
= topIndex
; i
< items
.length
; i
++) {
1672 Item item
= items
[i
];
1673 drawItem(item
, bounds
, timeProvider
, i
, nameSpace
, gc
);
1683 * The bounds of the control
1684 * @param timeProvider
1687 * The expanded item index
1689 * The name space width
1693 protected void drawItem(Item item
, Rectangle bounds
, ITimeDataProvider timeProvider
, int i
, int nameSpace
, GC gc
) {
1694 Rectangle itemRect
= getItemRect(bounds
, i
);
1695 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1699 ITimeGraphEntry entry
= item
.fEntry
;
1700 long time0
= timeProvider
.getTime0();
1701 long time1
= timeProvider
.getTime1();
1702 long selectedTime
= fTimeProvider
.getSelectionEnd();
1704 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1705 if (rect
.isEmpty() || (time1
<= time0
)) {
1706 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1710 boolean selected
= item
.fSelected
;
1711 // K pixels per second
1712 double pixelsPerNanoSec
= (rect
.width
<= RIGHT_MARGIN
) ?
0 : (double) (rect
.width
- RIGHT_MARGIN
) / (time1
- time0
);
1714 if (item
.fEntry
.hasTimeEvents()) {
1715 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1716 fillSpace(rect
, gc
, selected
);
1718 * State rectangle is smaller than item bounds. Use a margin height
1719 * of 3 pixels, keep at least 3 pixels for the state, but not more
1720 * than the item height. Favor the top margin for the remainder.
1722 int height
= Math
.min(rect
.height
, Math
.max(3, rect
.height
- 6));
1723 int margin
= (rect
.height
- height
+ 1) / 2;
1724 Rectangle stateRect
= new Rectangle(rect
.x
, rect
.y
+ margin
, rect
.width
, height
);
1726 long maxDuration
= (timeProvider
.getTimeSpace() == 0) ? Long
.MAX_VALUE
: 1 * (time1
- time0
) / timeProvider
.getTimeSpace();
1727 Iterator
<ITimeEvent
> iterator
= entry
.getTimeEventsIterator(time0
, time1
, maxDuration
);
1730 while (iterator
.hasNext()) {
1731 ITimeEvent event
= iterator
.next();
1732 int x
= rect
.x
+ (int) ((event
.getTime() - time0
) * pixelsPerNanoSec
);
1733 int xEnd
= rect
.x
+ (int) ((event
.getTime() + event
.getDuration() - time0
) * pixelsPerNanoSec
);
1734 if (x
>= rect
.x
+ rect
.width
|| xEnd
< rect
.x
) {
1735 // event is out of bounds
1738 xEnd
= Math
.min(rect
.x
+ rect
.width
, xEnd
);
1739 stateRect
.x
= Math
.max(rect
.x
, x
);
1740 stateRect
.width
= Math
.max(0, xEnd
- stateRect
.x
+ 1);
1741 if (stateRect
.x
== lastX
) {
1742 stateRect
.width
-= 1;
1743 if (stateRect
.width
> 0) {
1744 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
1745 gc
.drawPoint(stateRect
.x
, stateRect
.y
- 2);
1749 boolean timeSelected
= selectedTime
>= event
.getTime() && selectedTime
< event
.getTime() + event
.getDuration();
1750 if (drawState(getColorScheme(), event
, stateRect
, gc
, selected
, timeSelected
)) {
1751 lastX
= stateRect
.x
;
1754 gc
.setClipping((Rectangle
) null);
1756 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1763 * The bounds of the control
1764 * @param timeProvider
1767 * The list of link events
1769 * The name space width
1773 public void drawLinks(Rectangle bounds
, ITimeDataProvider timeProvider
,
1774 List
<ILinkEvent
> links
, int nameSpace
, GC gc
) {
1778 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1779 /* the list can grow concurrently but cannot shrink */
1780 for (int i
= 0; i
< links
.size(); i
++) {
1781 drawLink(links
.get(i
), bounds
, timeProvider
, nameSpace
, gc
);
1783 gc
.setClipping((Rectangle
) null);
1787 * Draws a link type event
1790 * The link event to draw
1792 * The bounds of the control
1793 * @param timeProvider
1796 * The name space width
1800 protected void drawLink(ILinkEvent event
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1801 drawArrow(getColorScheme(), event
, getArrowRectangle(bounds
, event
), gc
);
1804 private Rectangle
getArrowRectangle(Rectangle bounds
, ILinkEvent event
) {
1805 int srcIndex
= fItemData
.findItemIndex(event
.getEntry());
1806 int destIndex
= fItemData
.findItemIndex(event
.getDestinationEntry());
1808 if ((srcIndex
== -1) || (destIndex
== -1)) {
1812 Rectangle src
= getStatesRect(bounds
, srcIndex
, fTimeProvider
.getNameSpace());
1813 Rectangle dst
= getStatesRect(bounds
, destIndex
, fTimeProvider
.getNameSpace());
1815 int x0
= getXForTime(event
.getTime());
1816 int x1
= getXForTime(event
.getTime() + event
.getDuration());
1818 // limit the x-coordinates to prevent integer overflow in calculations
1819 // and also GC.drawLine doesn't draw properly with large coordinates
1820 final int limit
= Integer
.MAX_VALUE
/ 1024;
1821 x0
= Math
.max(-limit
, Math
.min(x0
, limit
));
1822 x1
= Math
.max(-limit
, Math
.min(x1
, limit
));
1824 int y0
= src
.y
+ src
.height
/ 2;
1825 int y1
= dst
.y
+ dst
.height
/ 2;
1826 return new Rectangle(x0
, y0
, x1
- x0
, y1
- y0
);
1835 * Time event for which we're drawing the arrow
1837 * The arrow rectangle
1840 * @return true if the arrow was drawn
1842 protected boolean drawArrow(TimeGraphColorScheme colors
, ITimeEvent event
,
1843 Rectangle rect
, GC gc
) {
1848 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
1852 boolean visible
= ((rect
.height
== 0) && (rect
.width
== 0)) ?
false : true;
1855 Color stateColor
= null;
1856 if (colorIdx
< fEventColorMap
.length
) {
1857 stateColor
= fEventColorMap
[colorIdx
];
1859 stateColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
1862 gc
.setForeground(stateColor
);
1863 gc
.setBackground(stateColor
);
1865 /* Draw the arrow */
1866 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
1867 drawArrowHead(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
, gc
);
1870 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
1875 * @author Francis Giraldeau
1878 * http://stackoverflow.com/questions/3010803/draw-arrow-on-line-algorithm
1880 * The algorithm was taken from this site, not the code itself
1882 private static void drawArrowHead(int x0
, int y0
, int x1
, int y1
, GC gc
)
1885 double cos
= 0.9510;
1886 double sin
= 0.3090;
1887 long lenx
= x1
- x0
;
1888 long leny
= y1
- y0
;
1889 double len
= Math
.sqrt(lenx
* lenx
+ leny
* leny
);
1891 double dx
= factor
* lenx
/ len
;
1892 double dy
= factor
* leny
/ len
;
1893 int end1X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* -sin
)));
1894 int end1Y
= (int) Math
.round((y1
- (dx
* sin
+ dy
* cos
)));
1895 int end2X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* sin
)));
1896 int end2Y
= (int) Math
.round((y1
- (dx
* -sin
+ dy
* cos
)));
1897 int[] arrow
= new int[] { x1
, y1
, end1X
, end1Y
, end2X
, end2Y
, x1
, y1
};
1898 gc
.fillPolygon(arrow
);
1902 * Draw the name of an item.
1907 * The bounds of the item's name space
1911 protected void drawName(Item item
, Rectangle bounds
, GC gc
) {
1912 boolean hasTimeEvents
= item
.fEntry
.hasTimeEvents();
1914 // No name to be drawn
1915 if (fTimeProvider
.getNameSpace() == 0) {
1919 int leftMargin
= MARGIN
+ item
.fLevel
* EXPAND_SIZE
;
1920 if (item
.fHasChildren
) {
1921 gc
.setForeground(getColorScheme().getFgColorGroup(false, false));
1922 gc
.setBackground(getColorScheme().getBkColor(false, false, false));
1923 Rectangle rect
= Utils
.clone(bounds
);
1924 rect
.x
+= leftMargin
;
1925 rect
.y
+= (bounds
.height
- EXPAND_SIZE
) / 2;
1926 rect
.width
= EXPAND_SIZE
;
1927 rect
.height
= EXPAND_SIZE
;
1928 gc
.fillRectangle(rect
);
1929 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1, rect
.height
- 1);
1930 int midy
= rect
.y
+ rect
.height
/ 2;
1931 gc
.drawLine(rect
.x
+ 2, midy
, rect
.x
+ rect
.width
- 3, midy
);
1932 if (!item
.fExpanded
) {
1933 int midx
= rect
.x
+ rect
.width
/ 2;
1934 gc
.drawLine(midx
, rect
.y
+ 2, midx
, rect
.y
+ rect
.height
- 3);
1937 leftMargin
+= EXPAND_SIZE
+ MARGIN
;
1939 Image img
= fTimeGraphProvider
.getItemImage(item
.fEntry
);
1942 int imgHeight
= img
.getImageData().height
;
1943 int imgWidth
= img
.getImageData().width
;
1945 int y
= bounds
.y
+ (bounds
.height
- imgHeight
) / 2;
1946 gc
.drawImage(img
, x
, y
);
1947 leftMargin
+= imgWidth
+ MARGIN
;
1949 String name
= item
.fName
;
1950 Point size
= gc
.stringExtent(name
);
1951 if (fIdealNameSpace
< leftMargin
+ size
.x
+ MARGIN
) {
1952 fIdealNameSpace
= leftMargin
+ size
.x
+ MARGIN
;
1954 if (hasTimeEvents
) {
1955 // cut long string with "..."
1956 int width
= bounds
.width
- leftMargin
;
1958 while (size
.x
> width
&& name
.length() > 1) {
1960 name
= name
.substring(0, name
.length() - 1);
1961 size
= gc
.stringExtent(name
+ "..."); //$NON-NLS-1$
1964 name
+= "..."; //$NON-NLS-1$
1967 Rectangle rect
= Utils
.clone(bounds
);
1968 rect
.x
+= leftMargin
;
1969 rect
.width
-= leftMargin
;
1971 if (rect
.width
> 0) {
1972 rect
.y
+= (bounds
.height
- gc
.stringExtent(name
).y
) / 2;
1973 gc
.setForeground(getColorScheme().getFgColor(item
.fSelected
, fIsInFocus
));
1974 int textWidth
= Utils
.drawText(gc
, name
, rect
, true);
1975 leftMargin
+= textWidth
+ MARGIN
;
1977 if (hasTimeEvents
) {
1979 rect
.x
= bounds
.x
+ leftMargin
;
1981 rect
.width
= bounds
.width
- rect
.x
;
1982 drawMidLine(rect
, gc
);
1988 * Draw the state (color fill)
1993 * Time event for which we're drawing the state
1995 * The state rectangle
1999 * Is this time event currently selected (so it appears
2001 * @param timeSelected
2002 * Is the timestamp currently selected
2003 * @return true if the state was drawn
2005 protected boolean drawState(TimeGraphColorScheme colors
, ITimeEvent event
,
2006 Rectangle rect
, GC gc
, boolean selected
, boolean timeSelected
) {
2008 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
2009 if (colorIdx
< 0 && colorIdx
!= ITimeGraphPresentationProvider
.TRANSPARENT
) {
2012 boolean visible
= rect
.width
== 0 ?
false : true;
2013 rect
.width
= Math
.max(1, rect
.width
);
2014 Color black
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
2015 gc
.setForeground(black
);
2017 if (colorIdx
== ITimeGraphPresentationProvider
.TRANSPARENT
) {
2019 // Only draw the top and bottom borders
2020 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1, rect
.y
);
2021 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
- 1);
2022 if (rect
.width
== 1) {
2023 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2026 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2029 Color stateColor
= null;
2030 if (colorIdx
< fEventColorMap
.length
) {
2031 stateColor
= fEventColorMap
[colorIdx
];
2036 boolean reallySelected
= timeSelected
&& selected
;
2037 // fill all rect area
2038 gc
.setBackground(stateColor
);
2040 gc
.fillRectangle(rect
);
2041 } else if (fBlendSubPixelEvents
) {
2043 gc
.fillRectangle(rect
);
2047 if (reallySelected
) {
2048 gc
.drawLine(rect
.x
, rect
.y
- 1, rect
.x
+ rect
.width
- 1, rect
.y
- 1);
2049 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
);
2052 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2054 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2059 * Fill an item's states rectangle
2062 * The states rectangle
2066 * true if the item is selected
2068 protected void fillSpace(Rectangle rect
, GC gc
, boolean selected
) {
2069 /* Nothing to draw */
2073 * Draw a line at the middle height of a rectangle
2080 private void drawMidLine(Rectangle rect
, GC gc
) {
2081 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.MID_LINE
));
2082 int midy
= rect
.y
+ rect
.height
/ 2;
2083 gc
.drawLine(rect
.x
, midy
, rect
.x
+ rect
.width
, midy
);
2087 public void keyTraversed(TraverseEvent e
) {
2088 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {
2094 public void keyPressed(KeyEvent e
) {
2096 if (fItemData
.fExpandedItems
.length
== 0) {
2099 if (SWT
.HOME
== e
.keyCode
) {
2101 } else if (SWT
.END
== e
.keyCode
) {
2102 idx
= fItemData
.fExpandedItems
.length
- 1;
2103 } else if (SWT
.ARROW_DOWN
== e
.keyCode
) {
2104 idx
= getSelectedIndex();
2107 } else if (idx
< fItemData
.fExpandedItems
.length
- 1) {
2110 } else if (SWT
.ARROW_UP
== e
.keyCode
) {
2111 idx
= getSelectedIndex();
2114 } else if (idx
> 0) {
2117 } else if (SWT
.ARROW_LEFT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2118 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2119 selectPrevEvent(extend
);
2120 } else if (SWT
.ARROW_RIGHT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2121 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2122 selectNextEvent(extend
);
2123 } else if (SWT
.PAGE_DOWN
== e
.keyCode
) {
2124 int page
= countPerPage();
2125 idx
= getSelectedIndex();
2130 if (idx
>= fItemData
.fExpandedItems
.length
) {
2131 idx
= fItemData
.fExpandedItems
.length
- 1;
2133 } else if (SWT
.PAGE_UP
== e
.keyCode
) {
2134 int page
= countPerPage();
2135 idx
= getSelectedIndex();
2143 } else if (SWT
.CR
== e
.keyCode
) {
2144 idx
= getSelectedIndex();
2146 if (fItemData
.fExpandedItems
[idx
].fHasChildren
) {
2149 fireDefaultSelection();
2155 selectItem(idx
, false);
2156 fireSelectionChanged();
2158 int x
= toControl(e
.display
.getCursorLocation()).x
;
2159 updateCursor(x
, e
.stateMask
| e
.keyCode
);
2163 public void keyReleased(KeyEvent e
) {
2164 int x
= toControl(e
.display
.getCursorLocation()).x
;
2165 updateCursor(x
, e
.stateMask
& ~e
.keyCode
);
2169 public void focusGained(FocusEvent e
) {
2172 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2176 public void focusLost(FocusEvent e
) {
2178 if (DRAG_NONE
!= fDragState
) {
2180 fDragState
= DRAG_NONE
;
2183 updateStatusLine(NO_STATUS
);
2187 * @return If the current view is focused
2189 public boolean isInFocus() {
2194 * Provide the possibility to control the wait cursor externally e.g. data
2195 * requests in progress
2197 * @param waitInd Should we wait indefinitely?
2199 public void waitCursor(boolean waitInd
) {
2200 // Update cursor as indicated
2202 setCursor(fWaitCursor
);
2208 private void updateCursor(int x
, int stateMask
) {
2209 // if Wait cursor not active, check for the need to change the cursor
2210 if (getCursor() == fWaitCursor
) {
2213 Cursor cursor
= null;
2214 if (fDragState
== DRAG_SPLIT_LINE
) {
2215 } else if (fDragState
== DRAG_SELECTION
) {
2216 cursor
= fResizeCursor
;
2217 } else if (fDragState
== DRAG_TRACE_ITEM
) {
2218 cursor
= fDragCursor
;
2219 } else if (fDragState
== DRAG_ZOOM
) {
2220 cursor
= fZoomCursor
;
2221 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2222 cursor
= fDragCursor
;
2223 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2224 cursor
= fResizeCursor
;
2225 } else if (!isOverSplitLine(x
)) {
2226 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2227 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2228 int xBegin
= getXForTime(selectionBegin
);
2229 int xEnd
= getXForTime(selectionEnd
);
2230 if (Math
.abs(x
- xBegin
) < SNAP_WIDTH
|| Math
.abs(x
- xEnd
) < SNAP_WIDTH
) {
2231 cursor
= fResizeCursor
;
2234 if (getCursor() != cursor
) {
2240 * Update the status line following a change of selection.
2244 public void updateStatusLine() {
2245 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2248 private void updateStatusLine(int x
) {
2249 // use the time provider of the time graph scale for the status line
2250 ITimeDataProvider tdp
= fTimeGraphScale
.getTimeProvider();
2251 if (fStatusLineManager
== null || null == tdp
||
2252 tdp
.getTime0() == tdp
.getTime1()) {
2255 TimeFormat tf
= tdp
.getTimeFormat();
2256 Resolution res
= Resolution
.NANOSEC
;
2257 StringBuilder message
= new StringBuilder();
2258 if ((x
>= 0 || x
== STATUS_WITHOUT_CURSOR_TIME
) && fDragState
== DRAG_NONE
) {
2259 if (x
!= STATUS_WITHOUT_CURSOR_TIME
) {
2260 long time
= getTimeAtX(x
);
2262 if (tdp
instanceof ITimeDataProviderConverter
) {
2263 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2265 message
.append(NLS
.bind("T: {0}{1} ", //$NON-NLS-1$
2267 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2268 Utils
.formatTime(time
, tf
, res
)
2272 long selectionBegin
= tdp
.getSelectionBegin();
2273 long selectionEnd
= tdp
.getSelectionEnd();
2274 message
.append(NLS
.bind("T1: {0}{1}", //$NON-NLS-1$
2276 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionBegin
) + ' ' : "", //$NON-NLS-1$
2277 Utils
.formatTime(selectionBegin
, tf
, res
)
2279 if (selectionBegin
!= selectionEnd
) {
2280 message
.append(NLS
.bind(" T2: {0}{1} \u0394: {2}", //$NON-NLS-1$
2282 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionEnd
) + ' ' : "", //$NON-NLS-1$
2283 Utils
.formatTime(selectionEnd
, tf
, res
),
2284 Utils
.formatDelta(selectionEnd
- selectionBegin
, tf
, res
)
2287 } else if (fDragState
== DRAG_SELECTION
|| fDragState
== DRAG_ZOOM
) {
2288 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2289 long time
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2290 if (tdp
instanceof ITimeDataProviderConverter
) {
2291 time0
= ((ITimeDataProviderConverter
) tdp
).convertTime(time0
);
2292 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2294 message
.append(NLS
.bind("T1: {0}{1} T2: {2}{3} \u0394: {4}", //$NON-NLS-1$
2296 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time0
) + ' ' : "", //$NON-NLS-1$
2297 Utils
.formatTime(time0
, tf
, res
),
2298 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2299 Utils
.formatTime(time
, tf
, res
),
2300 Utils
.formatDelta(time
- time0
, tf
, res
)
2303 fStatusLineManager
.setMessage(message
.toString());
2307 public void mouseMove(MouseEvent e
) {
2308 if (null == fTimeProvider
) {
2311 Point size
= getSize();
2312 if (DRAG_TRACE_ITEM
== fDragState
) {
2313 int nameWidth
= fTimeProvider
.getNameSpace();
2314 if (e
.x
> nameWidth
&& size
.x
> nameWidth
&& fDragX
!= e
.x
) {
2316 double pixelsPerNanoSec
= (size
.x
- nameWidth
<= RIGHT_MARGIN
) ?
0 : (double) (size
.x
- nameWidth
- RIGHT_MARGIN
) / (fTime1bak
- fTime0bak
);
2317 long timeDelta
= (long) ((pixelsPerNanoSec
== 0) ?
0 : ((fDragX
- fDragX0
) / pixelsPerNanoSec
));
2318 long time1
= fTime1bak
- timeDelta
;
2319 long maxTime
= fTimeProvider
.getMaxTime();
2320 if (time1
> maxTime
) {
2323 long time0
= time1
- (fTime1bak
- fTime0bak
);
2324 if (time0
< fTimeProvider
.getMinTime()) {
2325 time0
= fTimeProvider
.getMinTime();
2326 time1
= time0
+ (fTime1bak
- fTime0bak
);
2328 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2330 } else if (DRAG_SPLIT_LINE
== fDragState
) {
2332 fTimeProvider
.setNameSpace(e
.x
);
2333 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2334 } else if (DRAG_SELECTION
== fDragState
) {
2335 if (fDragBeginMarker
) {
2336 fDragX0
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2338 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2341 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2342 fireDragSelectionChanged(getTimeAtX(fDragX0
), getTimeAtX(fDragX
));
2343 } else if (DRAG_ZOOM
== fDragState
) {
2344 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2346 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2347 } else if (DRAG_NONE
== fDragState
) {
2348 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2349 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2352 fMouseOverSplitLine
= mouseOverSplitLine
;
2354 updateCursor(e
.x
, e
.stateMask
);
2355 updateStatusLine(e
.x
);
2359 public void mouseDoubleClick(MouseEvent e
) {
2360 if (null == fTimeProvider
) {
2363 if (1 == e
.button
&& (e
.stateMask
& SWT
.BUTTON_MASK
) == 0) {
2364 if (isOverSplitLine(e
.x
) && fTimeProvider
.getNameSpace() != 0) {
2365 fTimeProvider
.setNameSpace(fIdealNameSpace
);
2366 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2367 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2370 fMouseOverSplitLine
= mouseOverSplitLine
;
2371 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2374 int idx
= getItemIndexAtY(e
.y
);
2376 selectItem(idx
, false);
2377 fireDefaultSelection();
2383 public void mouseDown(MouseEvent e
) {
2384 if (fDragState
!= DRAG_NONE
|| null == fTimeProvider
||
2385 fTimeProvider
.getTime0() == fTimeProvider
.getTime1() ||
2386 getSize().x
- fTimeProvider
.getNameSpace() <= 0) {
2390 if (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == 0) {
2391 int nameSpace
= fTimeProvider
.getNameSpace();
2392 if (nameSpace
!= 0 && isOverSplitLine(e
.x
)) {
2393 fDragState
= DRAG_SPLIT_LINE
;
2394 fDragButton
= e
.button
;
2397 fTime0bak
= fTimeProvider
.getTime0();
2398 fTime1bak
= fTimeProvider
.getTime1();
2400 updateCursor(e
.x
, e
.stateMask
);
2404 if (1 == e
.button
&& ((e
.stateMask
& SWT
.MODIFIER_MASK
) == 0 || (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
)) {
2405 int nameSpace
= fTimeProvider
.getNameSpace();
2406 idx
= getItemIndexAtY(e
.y
);
2408 Item item
= fItemData
.fExpandedItems
[idx
];
2409 if (item
.fHasChildren
&& e
.x
< nameSpace
&& e
.x
< MARGIN
+ (item
.fLevel
+ 1) * EXPAND_SIZE
) {
2413 selectItem(idx
, false);
2414 fireSelectionChanged();
2416 selectItem(idx
, false); // clear selection
2417 fireSelectionChanged();
2419 long hitTime
= getTimeAtX(e
.x
);
2423 fDragState
= DRAG_SELECTION
;
2424 fDragBeginMarker
= false;
2425 fDragButton
= e
.button
;
2428 fDragTime0
= getTimeAtX(fDragX0
);
2429 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2430 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2431 int xBegin
= getXForTime(selectionBegin
);
2432 int xEnd
= getXForTime(selectionEnd
);
2433 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2434 long time
= getTimeAtX(e
.x
);
2435 if (Math
.abs(time
- selectionBegin
) < Math
.abs(time
- selectionEnd
)) {
2436 fDragBeginMarker
= true;
2439 fDragTime0
= selectionEnd
;
2442 fDragTime0
= selectionBegin
;
2445 long time
= getTimeAtX(e
.x
);
2446 if (Math
.abs(e
.x
- xBegin
) < SNAP_WIDTH
&& Math
.abs(time
- selectionBegin
) <= Math
.abs(time
- selectionEnd
)) {
2447 fDragBeginMarker
= true;
2450 fDragTime0
= selectionEnd
;
2451 } else if (Math
.abs(e
.x
- xEnd
) < SNAP_WIDTH
&& Math
.abs(time
- selectionEnd
) <= Math
.abs(time
- selectionBegin
)) {
2453 fDragTime0
= selectionBegin
;
2456 fTime0bak
= fTimeProvider
.getTime0();
2457 fTime1bak
= fTimeProvider
.getTime1();
2459 updateCursor(e
.x
, e
.stateMask
);
2460 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2462 } else if (2 == e
.button
|| (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
)) {
2463 long hitTime
= getTimeAtX(e
.x
);
2466 fDragState
= DRAG_TRACE_ITEM
;
2467 fDragButton
= e
.button
;
2470 fTime0bak
= fTimeProvider
.getTime0();
2471 fTime1bak
= fTimeProvider
.getTime1();
2472 updateCursor(e
.x
, e
.stateMask
);
2474 } else if (3 == e
.button
) {
2476 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), getSize().x
- RIGHT_MARGIN
);
2478 fDragTime0
= getTimeAtX(fDragX0
);
2479 fDragState
= DRAG_ZOOM
;
2480 fDragButton
= e
.button
;
2482 updateCursor(e
.x
, e
.stateMask
);
2483 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2488 public void mouseUp(MouseEvent e
) {
2489 if (fPendingMenuDetectEvent
!= null && e
.button
== 3) {
2490 menuDetected(fPendingMenuDetectEvent
);
2492 if (DRAG_NONE
!= fDragState
) {
2494 if (e
.button
== fDragButton
&& DRAG_TRACE_ITEM
== fDragState
) {
2495 if (fDragX
!= fDragX0
) {
2496 fTimeProvider
.notifyStartFinishTime();
2498 fDragState
= DRAG_NONE
;
2499 } else if (e
.button
== fDragButton
&& DRAG_SPLIT_LINE
== fDragState
) {
2500 fDragState
= DRAG_NONE
;
2502 } else if (e
.button
== fDragButton
&& DRAG_SELECTION
== fDragState
) {
2503 if (fDragX
== fDragX0
) { // click without selecting anything
2504 long time
= getTimeAtX(e
.x
);
2505 fTimeProvider
.setSelectedTimeNotify(time
, false);
2507 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2508 long time1
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2509 fTimeProvider
.setSelectionRangeNotify(time0
, time1
);
2511 fDragState
= DRAG_NONE
;
2513 fTimeGraphScale
.setDragRange(-1, -1);
2514 } else if (e
.button
== fDragButton
&& DRAG_ZOOM
== fDragState
) {
2515 int nameWidth
= fTimeProvider
.getNameSpace();
2516 if (Math
.max(fDragX
, fDragX0
) > nameWidth
&& fDragX
!= fDragX0
) {
2517 long time0
= getTimeAtX(fDragX0
);
2518 long time1
= getTimeAtX(fDragX
);
2519 if (time0
< time1
) {
2520 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2522 fTimeProvider
.setStartFinishTimeNotify(time1
, time0
);
2527 fDragState
= DRAG_NONE
;
2528 fTimeGraphScale
.setDragRange(-1, -1);
2531 updateCursor(e
.x
, e
.stateMask
);
2532 updateStatusLine(e
.x
);
2536 public void mouseEnter(MouseEvent e
) {
2540 public void mouseExit(MouseEvent e
) {
2541 if (fMouseOverSplitLine
) {
2542 fMouseOverSplitLine
= false;
2545 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2549 public void mouseHover(MouseEvent e
) {
2553 public void mouseScrolled(MouseEvent e
) {
2554 if (fDragState
!= DRAG_NONE
) {
2557 boolean zoomScroll
= false;
2558 boolean horizontalScroll
= false;
2559 Point p
= getParent().toControl(getDisplay().getCursorLocation());
2560 Point parentSize
= getParent().getSize();
2561 if (p
.x
>= 0 && p
.x
< parentSize
.x
&& p
.y
>= 0 && p
.y
< parentSize
.y
) {
2562 // over the parent control
2563 if (e
.x
> getSize().x
) {
2564 // over the vertical scroll bar
2566 } else if (e
.y
< 0) {
2567 // over the time scale
2569 } else if (e
.y
>= getSize().y
) {
2570 // over the horizontal scroll bar
2571 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2574 horizontalScroll
= true;
2577 if (e
.x
< fTimeProvider
.getNameSpace()) {
2578 // over the name space
2581 // over the state area
2582 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2583 // over the state area, CTRL pressed
2586 // over the state area, CTRL not pressed
2592 if (zoomScroll
&& fTimeProvider
.getTime0() != fTimeProvider
.getTime1()) {
2595 } else if (e
.count
< 0) {
2598 } else if (horizontalScroll
) {
2599 horizontalScroll(e
.count
> 0);
2601 setTopIndex(getTopIndex() - e
.count
);
2606 public void handleEvent(Event event
) {
2607 if (event
.type
== SWT
.MouseWheel
) {
2608 // prevent horizontal scrolling when the mouse wheel is used to
2609 // scroll vertically or zoom
2615 public int getBorderWidth() {
2616 return fBorderWidth
;
2620 * Set the border width
2622 * @param borderWidth
2625 public void setBorderWidth(int borderWidth
) {
2626 this.fBorderWidth
= borderWidth
;
2630 * @return The current height of the header row
2632 public int getHeaderHeight() {
2633 return fHeaderHeight
;
2637 * Set the height of the header row
2639 * @param headerHeight
2642 public void setHeaderHeight(int headerHeight
) {
2643 this.fHeaderHeight
= headerHeight
;
2647 * @return The default height of regular item rows
2649 public int getItemHeight() {
2650 return fGlobalItemHeight
;
2654 * Set the default height of regular item rows.
2659 public void setItemHeight(int rowHeight
) {
2660 this.fGlobalItemHeight
= rowHeight
;
2661 for (Item item
: fItemData
.fItems
) {
2662 item
.fItemHeight
= rowHeight
;
2667 * Set the height of a specific item. Overrides the default item height.
2670 * A time graph entry
2673 * @return true if the height is successfully stored, false otherwise
2675 public boolean setItemHeight(ITimeGraphEntry entry
, int rowHeight
) {
2676 Item item
= fItemData
.findItem(entry
);
2678 item
.fItemHeight
= rowHeight
;
2685 * Set the minimum item width
2687 * @param width The minimum width
2689 public void setMinimumItemWidth(int width
) {
2690 this.fMinimumItemWidth
= width
;
2694 * @return The minimum item width
2696 public int getMinimumItemWidth() {
2697 return fMinimumItemWidth
;
2701 * Set whether all time events with a duration shorter than one pixel should
2702 * be blended in. If false, only the first such time event will be drawn and
2703 * the subsequent time events in the same pixel will be discarded. The
2704 * default value is false.
2707 * true if sub-pixel events should be blended, false otherwise.
2710 public void setBlendSubPixelEvents(boolean blend
) {
2711 fBlendSubPixelEvents
= blend
;
2715 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2716 if (listener
!= null && !fSelectionChangedListeners
.contains(listener
)) {
2717 fSelectionChangedListeners
.add(listener
);
2722 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2723 if (listener
!= null) {
2724 fSelectionChangedListeners
.remove(listener
);
2729 public void setSelection(ISelection selection
) {
2730 if (selection
instanceof TimeGraphSelection
) {
2731 TimeGraphSelection sel
= (TimeGraphSelection
) selection
;
2732 Object ob
= sel
.getFirstElement();
2733 if (ob
instanceof ITimeGraphEntry
) {
2734 ITimeGraphEntry trace
= (ITimeGraphEntry
) ob
;
2735 selectItem(trace
, false);
2742 * @param filter The filter object to be attached to the view
2744 public void addFilter(ViewerFilter filter
) {
2745 if (!fFilters
.contains(filter
)) {
2746 fFilters
.add(filter
);
2751 * @param filter The filter object to be attached to the view
2753 public void removeFilter(ViewerFilter filter
) {
2754 fFilters
.remove(filter
);
2758 * Returns this control's filters.
2760 * @return an array of viewer filters
2763 public ViewerFilter
[] getFilters() {
2764 return Iterables
.toArray(fFilters
, ViewerFilter
.class);
2768 * Sets the filters, replacing any previous filters.
2771 * an array of viewer filters, or null
2774 public void setFilters(ViewerFilter
[] filters
) {
2776 if (filters
!= null) {
2777 fFilters
.addAll(Arrays
.asList(filters
));
2782 public void colorSettingsChanged(StateItem
[] stateItems
) {
2783 /* Destroy previous colors from the resource manager */
2784 if (fEventColorMap
!= null) {
2785 for (Color color
: fEventColorMap
) {
2786 fResourceManager
.destroyColor(color
.getRGB());
2789 if (stateItems
!= null) {
2790 fEventColorMap
= new Color
[stateItems
.length
];
2791 for (int i
= 0; i
< stateItems
.length
; i
++) {
2792 fEventColorMap
[i
] = fResourceManager
.createColor(stateItems
[i
].getStateColor());
2795 fEventColorMap
= new Color
[] { };
2800 private class ItemData
{
2801 private Map
<ITimeGraphEntry
, Item
> fItemMap
= new LinkedHashMap
<>();
2802 private Item
[] fExpandedItems
= new Item
[0];
2803 private Item
[] fItems
= new Item
[0];
2804 private ITimeGraphEntry fRootEntries
[] = new ITimeGraphEntry
[0];
2805 private List
<ILinkEvent
> fLinks
= new ArrayList
<>();
2810 public Item
findItem(ITimeGraphEntry entry
) {
2811 return fItemMap
.get(entry
);
2814 public int findItemIndex(ITimeGraphEntry entry
) {
2815 Item item
= fItemMap
.get(entry
);
2819 return item
.fExpandedIndex
;
2822 public void refreshData() {
2823 ITimeGraphEntry selection
= getSelectedTrace();
2824 Map
<ITimeGraphEntry
, Item
> itemMap
= new LinkedHashMap
<>();
2825 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2826 ITimeGraphEntry entry
= fRootEntries
[i
];
2827 refreshData(itemMap
, null, 0, entry
);
2830 fItems
= fItemMap
.values().toArray(new Item
[0]);
2831 updateExpandedItems();
2832 if (selection
!= null) {
2833 for (Item item
: fExpandedItems
) {
2834 if (item
.fEntry
== selection
) {
2835 item
.fSelected
= true;
2842 private void refreshData(Map
<ITimeGraphEntry
, Item
> itemMap
, Item parent
, int level
, ITimeGraphEntry entry
) {
2843 Item item
= new Item(entry
, entry
.getName(), level
);
2844 if (parent
!= null) {
2845 parent
.fChildren
.add(item
);
2847 if (fGlobalItemHeight
== CUSTOM_ITEM_HEIGHT
) {
2848 item
.fItemHeight
= fTimeGraphProvider
.getItemHeight(entry
);
2850 item
.fItemHeight
= fGlobalItemHeight
;
2852 itemMap
.put(entry
, item
);
2853 if (entry
.hasChildren()) {
2854 Item oldItem
= fItemMap
.get(entry
);
2855 if (oldItem
!= null && oldItem
.fHasChildren
&& level
== oldItem
.fLevel
&& entry
.getParent() == oldItem
.fEntry
.getParent()) {
2856 /* existing items keep their old expanded state */
2857 item
.fExpanded
= oldItem
.fExpanded
;
2859 /* new items set the expanded state according to auto-expand level */
2860 item
.fExpanded
= fAutoExpandLevel
== ALL_LEVELS
|| level
< fAutoExpandLevel
;
2862 item
.fHasChildren
= true;
2863 for (ITimeGraphEntry child
: entry
.getChildren()) {
2864 refreshData(itemMap
, item
, level
+ 1, child
);
2869 public void updateExpandedItems() {
2870 for (Item item
: fItems
) {
2871 item
.fExpandedIndex
= -1;
2873 List
<Item
> expandedItemList
= new ArrayList
<>();
2874 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2875 ITimeGraphEntry entry
= fRootEntries
[i
];
2876 Item item
= findItem(entry
);
2877 refreshExpanded(expandedItemList
, item
);
2879 fExpandedItems
= expandedItemList
.toArray(new Item
[0]);
2880 fTopIndex
= Math
.min(fTopIndex
, Math
.max(0, fExpandedItems
.length
- 1));
2883 private void refreshExpanded(List
<Item
> expandedItemList
, Item item
) {
2884 // Check for filters
2885 boolean display
= true;
2886 for (ViewerFilter filter
: fFilters
) {
2887 if (!filter
.select(null, item
.fEntry
.getParent(), item
.fEntry
)) {
2893 item
.fExpandedIndex
= expandedItemList
.size();
2894 expandedItemList
.add(item
);
2895 if (item
.fHasChildren
&& item
.fExpanded
) {
2896 for (Item child
: item
.fChildren
) {
2897 refreshExpanded(expandedItemList
, child
);
2903 public void refreshData(ITimeGraphEntry
[] entries
) {
2904 if (entries
== null) {
2905 fRootEntries
= null;
2907 fRootEntries
= Arrays
.copyOf(entries
, entries
.length
);
2913 public void refreshArrows(List
<ILinkEvent
> events
) {
2914 /* If links are null, reset the list */
2915 if (events
!= null) {
2918 fLinks
= new ArrayList
<>();
2922 public ITimeGraphEntry
[] getEntries() {
2923 return fRootEntries
;
2927 private class Item
{
2928 private boolean fExpanded
;
2929 private int fExpandedIndex
;
2930 private boolean fSelected
;
2931 private boolean fHasChildren
;
2932 private int fItemHeight
;
2933 private final int fLevel
;
2934 private final List
<Item
> fChildren
;
2935 private final String fName
;
2936 private final ITimeGraphEntry fEntry
;
2938 public Item(ITimeGraphEntry entry
, String name
, int level
) {
2939 this.fEntry
= entry
;
2941 this.fLevel
= level
;
2942 this.fChildren
= new ArrayList
<>();
2946 public String
toString() {
2952 public void menuDetected(MenuDetectEvent e
) {
2953 if (null == fTimeProvider
) {
2956 if (e
.detail
== SWT
.MENU_MOUSE
) {
2957 if (fPendingMenuDetectEvent
== null) {
2958 /* Feature in Linux. The MenuDetectEvent is received before mouseDown.
2959 * Store the event and trigger it later just before handling mouseUp.
2960 * This allows for the method to detect if mouse is used to drag zoom.
2962 fPendingMenuDetectEvent
= e
;
2965 fPendingMenuDetectEvent
= null;
2966 if (fDragState
!= DRAG_ZOOM
|| fDragX
!= fDragX0
) {
2970 if (fDragState
!= DRAG_NONE
) {
2974 Point p
= toControl(e
.x
, e
.y
);
2975 int idx
= getItemIndexAtY(p
.y
);
2976 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
2977 Item item
= fItemData
.fExpandedItems
[idx
];
2978 ITimeGraphEntry entry
= item
.fEntry
;
2979 if (entry
.hasTimeEvents()) {
2980 ITimeEvent event
= Utils
.findEvent(entry
, getTimeAtX(p
.x
), 2);
2981 if (event
!= null) {
2983 fireMenuEventOnTimeEvent(e
);
2988 fireMenuEventOnTimeGraphEntry(e
);
2993 * Perform the alignment operation.
2996 * the alignment offset
2998 * @see ITmfTimeAligned
3002 public void performAlign(int offset
) {
3003 fTimeProvider
.setNameSpace(offset
);
3007 * Return the time alignment information
3009 * @return the time alignment information
3011 * @see ITmfTimeAligned
3015 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
3016 return new TmfTimeViewAlignmentInfo(getShell(), toDisplay(0, 0), fTimeProvider
.getNameSpace());