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
> fBookmarks
= null;
150 private List
<IMarkerEvent
> fMarkers
= null;
151 private boolean fMarkersVisible
= true;
152 private List
<SelectionListener
> fSelectionListeners
;
153 private List
<ITimeGraphTimeListener
> fDragSelectionListeners
;
154 private final List
<ISelectionChangedListener
> fSelectionChangedListeners
= new ArrayList
<>();
155 private final List
<ITimeGraphTreeListener
> fTreeListeners
= new ArrayList
<>();
156 private final List
<MenuDetectListener
> fTimeGraphEntryMenuListeners
= new ArrayList
<>();
157 private final List
<MenuDetectListener
> fTimeEventMenuListeners
= new ArrayList
<>();
158 private final Cursor fDragCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_HAND
);
159 private final Cursor fResizeCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_IBEAM
);
160 private final Cursor fWaitCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_WAIT
);
161 private final Cursor fZoomCursor
= Display
.getDefault().getSystemCursor(SWT
.CURSOR_SIZEWE
);
162 private final List
<ViewerFilter
> fFilters
= new ArrayList
<>();
163 private MenuDetectEvent fPendingMenuDetectEvent
= null;
164 private boolean fGridLinesVisible
= true;
165 private Color fGridLineColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_GRAY
);
166 private boolean fHideArrows
= false;
167 private int fAutoExpandLevel
= ALL_LEVELS
;
169 private int fBorderWidth
= 0;
170 private int fHeaderHeight
= 0;
173 * Standard constructor
176 * The parent composite object
178 * The color scheme to use
180 public TimeGraphControl(Composite parent
, TimeGraphColorScheme colors
) {
182 super(parent
, colors
, SWT
.NO_BACKGROUND
| SWT
.DOUBLE_BUFFERED
);
184 fItemData
= new ItemData();
186 addFocusListener(this);
187 addMouseListener(this);
188 addMouseMoveListener(this);
189 addMouseTrackListener(this);
190 addMouseWheelListener(this);
191 addTraverseListener(this);
192 addKeyListener(this);
193 addMenuDetectListener(this);
194 addListener(SWT
.MouseWheel
, this);
198 public void dispose() {
200 fResourceManager
.dispose();
204 * Sets the timegraph provider used by this timegraph viewer.
206 * @param timeGraphProvider the timegraph provider
208 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider
) {
209 fTimeGraphProvider
= timeGraphProvider
;
211 if (timeGraphProvider
instanceof ITimeGraphPresentationProvider2
) {
212 ((ITimeGraphPresentationProvider2
) timeGraphProvider
).setDrawingHelper(this);
213 ((ITimeGraphPresentationProvider2
) timeGraphProvider
).addColorListener(this);
216 StateItem
[] stateItems
= fTimeGraphProvider
.getStateTable();
217 colorSettingsChanged(stateItems
);
221 * Gets the timegraph provider used by this timegraph viewer.
223 * @return the timegraph provider, or <code>null</code> if not set.
225 public ITimeGraphPresentationProvider
getTimeGraphProvider() {
226 return fTimeGraphProvider
;
230 * Gets the color map used by this timegraph viewer.
232 * @return a color map, or <code>null</code> if not set.
234 public Color
[] getEventColorMap() {
235 return fEventColorMap
;
239 * Assign the given time provider
241 * @param timeProvider
244 public void setTimeProvider(ITimeDataProvider timeProvider
) {
245 fTimeProvider
= timeProvider
;
250 * Assign the status line manager
252 * @param statusLineManager
253 * The status line manager, or null to disable status line messages
255 public void setStatusLineManager(IStatusLineManager statusLineManager
) {
256 if (fStatusLineManager
!= null && statusLineManager
== null) {
257 fStatusLineManager
.setMessage(""); //$NON-NLS-1$
259 fStatusLineManager
= statusLineManager
;
263 * Assign the time graph scale
265 * @param timeGraphScale
266 * The time graph scale
268 public void setTimeGraphScale(TimeGraphScale timeGraphScale
) {
269 fTimeGraphScale
= timeGraphScale
;
273 * Add a selection listener
276 * The listener to add
278 public void addSelectionListener(SelectionListener listener
) {
279 if (listener
== null) {
280 SWT
.error(SWT
.ERROR_NULL_ARGUMENT
);
282 if (null == fSelectionListeners
) {
283 fSelectionListeners
= new ArrayList
<>();
285 fSelectionListeners
.add(listener
);
289 * Remove a selection listener
292 * The listener to remove
294 public void removeSelectionListener(SelectionListener listener
) {
295 if (null != fSelectionListeners
) {
296 fSelectionListeners
.remove(listener
);
301 * Selection changed callback
303 public void fireSelectionChanged() {
304 if (null != fSelectionListeners
) {
305 Iterator
<SelectionListener
> it
= fSelectionListeners
.iterator();
306 while (it
.hasNext()) {
307 SelectionListener listener
= it
.next();
308 listener
.widgetSelected(null);
314 * Default selection callback
316 public void fireDefaultSelection() {
317 if (null != fSelectionListeners
) {
318 Iterator
<SelectionListener
> it
= fSelectionListeners
.iterator();
319 while (it
.hasNext()) {
320 SelectionListener listener
= it
.next();
321 listener
.widgetDefaultSelected(null);
327 * Add a drag selection listener
330 * The listener to add
332 public void addDragSelectionListener(ITimeGraphTimeListener listener
) {
333 if (listener
== null) {
334 SWT
.error(SWT
.ERROR_NULL_ARGUMENT
);
336 if (null == fDragSelectionListeners
) {
337 fDragSelectionListeners
= new ArrayList
<>();
339 fDragSelectionListeners
.add(listener
);
343 * Remove a drag selection listener
346 * The listener to remove
348 public void removeDragSelectionListener(ITimeGraphTimeListener listener
) {
349 if (null != fDragSelectionListeners
) {
350 fDragSelectionListeners
.remove(listener
);
355 * Drag Selection changed callback
358 * Time interval start
362 public void fireDragSelectionChanged(long start
, long end
) {
363 // check for backward intervals
364 long beginTime
, endTime
;
372 // call the listeners
373 if (null != fDragSelectionListeners
) {
374 Iterator
<ITimeGraphTimeListener
> it
= fDragSelectionListeners
.iterator();
375 while (it
.hasNext()) {
376 ITimeGraphTimeListener listener
= it
.next();
377 listener
.timeSelected(new TimeGraphTimeEvent(this, beginTime
, endTime
));
383 * Get the traces in the model
385 * @return The array of traces
387 public ITimeGraphEntry
[] getTraces() {
388 return fItemData
.getEntries();
392 * Refresh the data for the thing
394 public void refreshData() {
395 fItemData
.refreshData();
400 * Refresh data for the given traces
403 * The traces to refresh
405 public void refreshData(ITimeGraphEntry
[] traces
) {
406 fItemData
.refreshData(traces
);
411 * Refresh the links (arrows) of this widget
413 * @param events The link event list
415 public void refreshArrows(List
<ILinkEvent
> events
) {
416 fItemData
.refreshArrows(events
);
420 * Get the links (arrows) of this widget
422 * @return The unmodifiable link event list
426 public List
<ILinkEvent
> getArrows() {
427 return Collections
.unmodifiableList(fItemData
.fLinks
);
430 boolean ensureVisibleItem(int idx
, boolean redraw
) {
431 boolean changed
= false;
434 for (index
= 0; index
< fItemData
.fExpandedItems
.length
; index
++) {
435 if (fItemData
.fExpandedItems
[index
].fSelected
) {
440 if (index
>= fItemData
.fExpandedItems
.length
) {
443 if (index
< fTopIndex
) {
450 int page
= countPerPage();
451 if (index
>= fTopIndex
+ page
) {
452 setTopIndex(index
- page
+ 1);
463 * Assign the given index as the top one
468 public void setTopIndex(int idx
) {
469 int index
= Math
.min(idx
, fItemData
.fExpandedItems
.length
- countPerPage());
470 index
= Math
.max(0, index
);
476 * Sets the auto-expand level to be used for new entries discovered when
477 * calling {@link #refreshData()} or {@link #refreshData(ITimeGraphEntry[])}
478 * . The value 0 means that there is no auto-expand; 1 means that top-level
479 * entries are expanded, but not their children; 2 means that top-level
480 * entries are expanded, and their children, but not grand-children; and so
483 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
487 * non-negative level, or <code>ALL_LEVELS</code> to expand all
490 public void setAutoExpandLevel(int level
) {
491 fAutoExpandLevel
= level
;
495 * Returns the auto-expand level.
497 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
498 * the tree are expanded automatically
499 * @see #setAutoExpandLevel
501 public int getAutoExpandLevel() {
502 return fAutoExpandLevel
;
506 * Get the expanded state of a given entry.
510 * @return true if the entry is expanded, false if collapsed
513 public boolean getExpandedState(ITimeGraphEntry entry
) {
514 Item item
= fItemData
.fItemMap
.get(entry
);
515 return (item
!= null ? item
.fExpanded
: false);
519 * Set the expanded state of a given entry
524 * True if expanded, false if collapsed
526 public void setExpandedState(ITimeGraphEntry entry
, boolean expanded
) {
527 Item item
= fItemData
.findItem(entry
);
528 if (item
!= null && item
.fExpanded
!= expanded
) {
529 item
.fExpanded
= expanded
;
530 fItemData
.updateExpandedItems();
536 * Collapses all nodes of the viewer's tree, starting with the root.
538 public void collapseAll() {
539 for (Item item
: fItemData
.fItems
) {
540 item
.fExpanded
= false;
542 fItemData
.updateExpandedItems();
547 * Expands all nodes of the viewer's tree, starting with the root.
549 public void expandAll() {
550 for (Item item
: fItemData
.fItems
) {
551 item
.fExpanded
= true;
553 fItemData
.updateExpandedItems();
558 * Add a tree listener
561 * The listener to add
563 public void addTreeListener(ITimeGraphTreeListener listener
) {
564 if (!fTreeListeners
.contains(listener
)) {
565 fTreeListeners
.add(listener
);
570 * Remove a tree listener
573 * The listener to remove
575 public void removeTreeListener(ITimeGraphTreeListener listener
) {
576 if (fTreeListeners
.contains(listener
)) {
577 fTreeListeners
.remove(listener
);
582 * Tree event callback
587 * The expanded state (true for expanded, false for collapsed)
589 public void fireTreeEvent(ITimeGraphEntry entry
, boolean expanded
) {
590 TimeGraphTreeExpansionEvent event
= new TimeGraphTreeExpansionEvent(this, entry
);
591 for (ITimeGraphTreeListener listener
: fTreeListeners
) {
593 listener
.treeExpanded(event
);
595 listener
.treeCollapsed(event
);
601 * Add a menu listener on {@link ITimeGraphEntry}s
604 * The listener to add
606 public void addTimeGraphEntryMenuListener(MenuDetectListener listener
) {
607 if (!fTimeGraphEntryMenuListeners
.contains(listener
)) {
608 fTimeGraphEntryMenuListeners
.add(listener
);
613 * Remove a menu listener on {@link ITimeGraphEntry}s
616 * The listener to remove
618 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener
) {
619 if (fTimeGraphEntryMenuListeners
.contains(listener
)) {
620 fTimeGraphEntryMenuListeners
.remove(listener
);
625 * Menu event callback on {@link ITimeGraphEntry}s
628 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeGraphEntry}
630 private void fireMenuEventOnTimeGraphEntry(MenuDetectEvent event
) {
631 for (MenuDetectListener listener
: fTimeGraphEntryMenuListeners
) {
632 listener
.menuDetected(event
);
637 * Add a menu listener on {@link ITimeEvent}s
640 * The listener to add
642 public void addTimeEventMenuListener(MenuDetectListener listener
) {
643 if (!fTimeEventMenuListeners
.contains(listener
)) {
644 fTimeEventMenuListeners
.add(listener
);
649 * Remove a menu listener on {@link ITimeEvent}s
652 * The listener to remove
654 public void removeTimeEventMenuListener(MenuDetectListener listener
) {
655 if (fTimeEventMenuListeners
.contains(listener
)) {
656 fTimeEventMenuListeners
.remove(listener
);
661 * Menu event callback on {@link ITimeEvent}s
664 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeEvent}
666 private void fireMenuEventOnTimeEvent(MenuDetectEvent event
) {
667 for (MenuDetectListener listener
: fTimeEventMenuListeners
) {
668 listener
.menuDetected(event
);
673 public ISelection
getSelection() {
674 TimeGraphSelection sel
= new TimeGraphSelection();
675 ITimeGraphEntry trace
= getSelectedTrace();
676 if (null != trace
&& null != fTimeProvider
) {
677 long selectedTime
= fTimeProvider
.getSelectionBegin();
678 ITimeEvent event
= Utils
.findEvent(trace
, selectedTime
, 0);
689 * Get the selection object
691 * @return The selection
693 public ISelection
getSelectionTrace() {
694 TimeGraphSelection sel
= new TimeGraphSelection();
695 ITimeGraphEntry trace
= getSelectedTrace();
703 * Enable/disable one of the traces in the model
706 * 1 to enable it, -1 to disable. The method returns immediately
707 * if another value is used.
709 public void selectTrace(int n
) {
710 if ((n
!= 1) && (n
!= -1)) {
714 boolean changed
= false;
715 int lastSelection
= -1;
716 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
717 Item item
= fItemData
.fExpandedItems
[i
];
718 if (item
.fSelected
) {
720 if ((1 == n
) && (i
< fItemData
.fExpandedItems
.length
- 1)) {
721 item
.fSelected
= false;
722 item
= fItemData
.fExpandedItems
[i
+ 1];
723 item
.fSelected
= true;
725 } else if ((-1 == n
) && (i
> 0)) {
726 item
.fSelected
= false;
727 item
= fItemData
.fExpandedItems
[i
- 1];
728 item
.fSelected
= true;
735 if (lastSelection
< 0 && fItemData
.fExpandedItems
.length
> 0) {
736 Item item
= fItemData
.fExpandedItems
[0];
737 item
.fSelected
= true;
742 ensureVisibleItem(-1, false);
744 fireSelectionChanged();
752 * 1 for next event, -1 for previous event
754 * true to extend selection range, false for single selection
757 public void selectEvent(int n
, boolean extend
) {
758 if (null == fTimeProvider
) {
761 ITimeGraphEntry trace
= getSelectedTrace();
765 long selectedTime
= fTimeProvider
.getSelectionEnd();
766 long endTime
= fTimeProvider
.getMaxTime();
767 ITimeEvent nextEvent
;
768 if (n
== -1 && selectedTime
> endTime
) {
769 nextEvent
= Utils
.findEvent(trace
, selectedTime
, 0);
771 nextEvent
= Utils
.findEvent(trace
, selectedTime
, n
);
773 if (null == nextEvent
&& n
== -1) {
774 nextEvent
= Utils
.getFirstEvent(trace
);
776 if (null != nextEvent
) {
777 long nextTime
= nextEvent
.getTime();
778 // If last event detected e.g. going back or not moving to a next
780 if (nextTime
<= selectedTime
&& n
== 1) {
781 // Select to the end of this last event
782 nextTime
= nextEvent
.getTime() + nextEvent
.getDuration();
783 // but not beyond the end of the trace
784 if (nextTime
> endTime
) {
787 } else if (n
== -1 && nextEvent
.getTime() + nextEvent
.getDuration() < selectedTime
) {
788 // for previous event go to its end time unless we were already there
789 nextTime
= nextEvent
.getTime() + nextEvent
.getDuration();
792 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), nextTime
);
794 fTimeProvider
.setSelectedTimeNotify(nextTime
, true);
796 fireSelectionChanged();
799 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), endTime
);
801 fTimeProvider
.setSelectedTimeNotify(endTime
, true);
803 fireSelectionChanged();
805 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
809 * Select the next event
812 * true to extend selection range, false for single selection
815 public void selectNextEvent(boolean extend
) {
816 selectEvent(1, extend
);
817 // Notify if visible time window has been adjusted
818 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
822 * Select the previous event
825 * true to extend selection range, false for single selection
828 public void selectPrevEvent(boolean extend
) {
829 selectEvent(-1, extend
);
830 // Notify if visible time window has been adjusted
831 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
835 * Select the next trace
837 public void selectNextTrace() {
842 * Select the previous trace
844 public void selectPrevTrace() {
849 * Scroll left or right by one half window size
852 * true to scroll left, false to scroll right
854 public void horizontalScroll(boolean left
) {
855 long time0
= fTimeProvider
.getTime0();
856 long time1
= fTimeProvider
.getTime1();
857 long timeMin
= fTimeProvider
.getMinTime();
858 long timeMax
= fTimeProvider
.getMaxTime();
859 long range
= time1
- time0
;
863 long increment
= Math
.max(1, range
/ 2);
865 time0
= Math
.max(time0
- increment
, timeMin
);
866 time1
= time0
+ range
;
868 time1
= Math
.min(time1
+ increment
, timeMax
);
869 time0
= time1
- range
;
871 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
875 * Zoom based on mouse cursor location with mouse scrolling
877 * @param zoomIn true to zoom in, false to zoom out
879 public void zoom(boolean zoomIn
) {
880 int globalX
= getDisplay().getCursorLocation().x
;
881 Point p
= toControl(globalX
, 0);
882 int nameSpace
= fTimeProvider
.getNameSpace();
883 int timeSpace
= fTimeProvider
.getTimeSpace();
884 int xPos
= Math
.max(nameSpace
, Math
.min(nameSpace
+ timeSpace
, p
.x
));
885 long time0
= fTimeProvider
.getTime0();
886 long time1
= fTimeProvider
.getTime1();
887 long interval
= time1
- time0
;
890 } // to allow getting out of single point interval
893 newInterval
= Math
.max(Math
.round(interval
* ZOOM_IN_FACTOR
), fTimeProvider
.getMinTimeInterval());
895 newInterval
= (long) Math
.ceil(interval
* ZOOM_OUT_FACTOR
);
897 long center
= time0
+ Math
.round(((double) (xPos
- nameSpace
) / timeSpace
* interval
));
898 long newTime0
= center
- Math
.round((double) newInterval
* (center
- time0
) / interval
);
899 long newTime1
= newTime0
+ newInterval
;
900 fTimeProvider
.setStartFinishTimeNotify(newTime0
, newTime1
);
904 * zoom in using single click
906 public void zoomIn() {
907 long prevTime0
= fTimeProvider
.getTime0();
908 long prevTime1
= fTimeProvider
.getTime1();
909 long prevRange
= prevTime1
- prevTime0
;
910 if (prevRange
== 0) {
913 ITimeDataProvider provider
= fTimeProvider
;
914 long selTime
= (provider
.getSelectionEnd() + provider
.getSelectionBegin()) / 2;
915 if (selTime
<= prevTime0
|| selTime
>= prevTime1
) {
916 selTime
= (prevTime0
+ prevTime1
) / 2;
918 long time0
= selTime
- (long) ((selTime
- prevTime0
) / ZOOM_FACTOR
);
919 long time1
= selTime
+ (long) ((prevTime1
- selTime
) / ZOOM_FACTOR
);
921 long inaccuracy
= (fTimeProvider
.getMaxTime() - fTimeProvider
.getMinTime()) - (time1
- time0
);
923 if (inaccuracy
> 0 && inaccuracy
< 100) {
924 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getMinTime(), fTimeProvider
.getMaxTime());
928 long min
= fTimeProvider
.getMinTimeInterval();
929 if ((time1
- time0
) < min
) {
930 time0
= selTime
- (selTime
- prevTime0
) * min
/ prevRange
;
934 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
938 * zoom out using single click
940 public void zoomOut() {
941 long prevTime0
= fTimeProvider
.getTime0();
942 long prevTime1
= fTimeProvider
.getTime1();
943 ITimeDataProvider provider
= fTimeProvider
;
944 long selTime
= (provider
.getSelectionEnd() + provider
.getSelectionBegin()) / 2;
945 if (selTime
<= prevTime0
|| selTime
>= prevTime1
) {
946 selTime
= (prevTime0
+ prevTime1
) / 2;
948 long time0
= (long) (selTime
- (selTime
- prevTime0
) * ZOOM_FACTOR
);
949 long time1
= (long) (selTime
+ (prevTime1
- selTime
) * ZOOM_FACTOR
);
951 long inaccuracy
= (fTimeProvider
.getMaxTime() - fTimeProvider
.getMinTime()) - (time1
- time0
);
952 if (inaccuracy
> 0 && inaccuracy
< 100) {
953 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getMinTime(), fTimeProvider
.getMaxTime());
957 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
961 * Set the grid lines visibility. The default is true.
964 * true to show the grid lines, false otherwise
967 public void setGridLinesVisible(boolean visible
) {
968 fGridLinesVisible
= visible
;
972 * Get the grid lines visibility.
974 * @return true if the grid lines are visible, false otherwise
977 public boolean getGridLinesVisible() {
978 return fGridLinesVisible
;
982 * Set the grid line color. The default is SWT.COLOR_GRAY.
985 * the grid line color
988 public void setGridLineColor(Color color
) {
989 fGridLineColor
= color
;
993 * Get the grid line color.
995 * @return the grid line color
998 public Color
getGridLineColor() {
999 return fGridLineColor
;
1003 * Set the bookmarks list.
1006 * The bookmarks list, or null
1009 public void setBookmarks(List
<IMarkerEvent
> bookmarks
) {
1010 fBookmarks
= bookmarks
;
1011 fTimeGraphScale
.setBookmarks(bookmarks
);
1015 * Set the markers list.
1018 * The markers list, or null
1021 public void setMarkers(List
<IMarkerEvent
> markers
) {
1023 fTimeGraphScale
.setMarkers(markers
);
1027 * Get the markers list.
1029 * @return The markers list, or null
1032 public List
<IMarkerEvent
> getMarkers() {
1037 * Set the markers visibility. The default is true.
1040 * true to show the markers, false otherwise
1043 public void setMarkersVisible(boolean visible
) {
1044 fMarkersVisible
= visible
;
1045 fTimeGraphScale
.setMarkersVisible(visible
);
1049 * Get the markers visibility.
1051 * @return true if the markers are visible, false otherwise
1054 public boolean getMarkersVisible() {
1055 return fMarkersVisible
;
1061 * @param hideArrows true to hide arrows
1063 public void hideArrows(boolean hideArrows
) {
1064 fHideArrows
= hideArrows
;
1068 * Follow the arrow forward
1071 * true to extend selection range, false for single selection
1074 public void followArrowFwd(boolean extend
) {
1075 ITimeGraphEntry trace
= getSelectedTrace();
1076 if (trace
== null) {
1079 long selectedTime
= fTimeProvider
.getSelectionEnd();
1080 for (ILinkEvent link
: fItemData
.fLinks
) {
1081 if (link
.getEntry() == trace
&& link
.getTime() == selectedTime
) {
1082 selectItem(link
.getDestinationEntry(), false);
1083 if (link
.getDuration() != 0) {
1085 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime() + link
.getDuration());
1087 fTimeProvider
.setSelectedTimeNotify(link
.getTime() + link
.getDuration(), true);
1089 // Notify if visible time window has been adjusted
1090 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1092 fireSelectionChanged();
1093 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1097 selectNextEvent(extend
);
1101 * Follow the arrow backward
1104 * true to extend selection range, false for single selection
1107 public void followArrowBwd(boolean extend
) {
1108 ITimeGraphEntry trace
= getSelectedTrace();
1109 if (trace
== null) {
1112 long selectedTime
= fTimeProvider
.getSelectionEnd();
1113 for (ILinkEvent link
: fItemData
.fLinks
) {
1114 if (link
.getDestinationEntry() == trace
&& link
.getTime() + link
.getDuration() == selectedTime
) {
1115 selectItem(link
.getEntry(), false);
1116 if (link
.getDuration() != 0) {
1118 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime());
1120 fTimeProvider
.setSelectedTimeNotify(link
.getTime(), true);
1122 // Notify if visible time window has been adjusted
1123 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1125 fireSelectionChanged();
1126 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1130 selectPrevEvent(extend
);
1134 * Return the currently selected trace
1136 * @return The entry matching the trace
1138 public ITimeGraphEntry
getSelectedTrace() {
1139 ITimeGraphEntry trace
= null;
1140 int idx
= getSelectedIndex();
1142 trace
= fItemData
.fExpandedItems
[idx
].fEntry
;
1148 * Retrieve the index of the currently selected item
1152 public int getSelectedIndex() {
1154 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1155 Item item
= fItemData
.fExpandedItems
[i
];
1156 if (item
.fSelected
) {
1164 boolean toggle(int idx
) {
1165 boolean toggled
= false;
1166 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1167 Item item
= fItemData
.fExpandedItems
[idx
];
1168 if (item
.fHasChildren
) {
1169 item
.fExpanded
= !item
.fExpanded
;
1170 fItemData
.updateExpandedItems();
1173 fireTreeEvent(item
.fEntry
, item
.fExpanded
);
1180 * Gets the index of the item at the given location.
1184 * @return the index of the item at the given location, of -1 if none.
1186 protected int getItemIndexAtY(int y
) {
1191 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1192 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1200 boolean isOverSplitLine(int x
) {
1201 if (x
< 0 || null == fTimeProvider
) {
1204 int nameWidth
= fTimeProvider
.getNameSpace();
1205 return Math
.abs(x
- nameWidth
) < SNAP_WIDTH
;
1209 * Gets the {@link ITimeGraphEntry} at the given location.
1212 * a point in the widget
1213 * @return the {@link ITimeGraphEntry} at this point, or <code>null</code>
1216 protected ITimeGraphEntry
getEntry(Point pt
) {
1217 int idx
= getItemIndexAtY(pt
.y
);
1218 return idx
>= 0 ? fItemData
.fExpandedItems
[idx
].fEntry
: null;
1222 * Return the arrow event closest to the given point that is no further than
1223 * a maximum distance.
1226 * a point in the widget
1227 * @return The closest arrow event, or null if there is none close enough.
1229 protected ILinkEvent
getArrow(Point pt
) {
1233 ILinkEvent linkEvent
= null;
1234 double minDistance
= Double
.MAX_VALUE
;
1235 for (ILinkEvent event
: fItemData
.fLinks
) {
1236 Rectangle rect
= getArrowRectangle(new Rectangle(0, 0, 0, 0), event
);
1240 int x2
= x1
+ rect
.width
;
1241 int y2
= y1
+ rect
.height
;
1242 double d
= Utils
.distance(pt
.x
, pt
.y
, x1
, y1
, x2
, y2
);
1243 if (minDistance
> d
) {
1249 if (minDistance
<= ARROW_HOVER_MAX_DIST
) {
1256 public int getXForTime(long time
) {
1257 if (null == fTimeProvider
) {
1260 long time0
= fTimeProvider
.getTime0();
1261 long time1
= fTimeProvider
.getTime1();
1262 int width
= getSize().x
;
1263 int nameSpace
= fTimeProvider
.getNameSpace();
1264 double pixelsPerNanoSec
= (width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1265 int x
= getBounds().x
+ nameSpace
+ (int) ((time
- time0
) * pixelsPerNanoSec
);
1270 public long getTimeAtX(int coord
) {
1271 if (null == fTimeProvider
) {
1275 Point size
= getSize();
1276 long time0
= fTimeProvider
.getTime0();
1277 long time1
= fTimeProvider
.getTime1();
1278 int nameWidth
= fTimeProvider
.getNameSpace();
1279 final int x
= coord
- nameWidth
;
1280 int timeWidth
= size
.x
- nameWidth
- RIGHT_MARGIN
;
1281 if (x
>= 0 && size
.x
>= nameWidth
) {
1282 if (time1
- time0
> timeWidth
) {
1283 // nanosecond smaller than one pixel: use the first integer nanosecond of this pixel's time range
1284 hitTime
= time0
+ (long) Math
.ceil((time1
- time0
) * ((double) x
/ timeWidth
));
1286 // nanosecond greater than one pixel: use the nanosecond that covers this pixel start position
1287 hitTime
= time0
+ (long) Math
.floor((time1
- time0
) * ((double) x
/ timeWidth
));
1293 void selectItem(int idx
, boolean addSelection
) {
1294 boolean changed
= false;
1296 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1297 Item item
= fItemData
.fExpandedItems
[idx
];
1298 changed
= !item
.fSelected
;
1299 item
.fSelected
= true;
1302 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1303 Item item
= fItemData
.fExpandedItems
[i
];
1304 if ((i
== idx
&& !item
.fSelected
) || (idx
== -1 && item
.fSelected
)) {
1307 item
.fSelected
= i
== idx
;
1310 changed
|= ensureVisibleItem(idx
, true);
1317 * Callback for item selection
1320 * The entry matching the trace
1321 * @param addSelection
1322 * If the selection is added or removed
1324 public void selectItem(ITimeGraphEntry trace
, boolean addSelection
) {
1325 int idx
= fItemData
.findItemIndex(trace
);
1326 selectItem(idx
, addSelection
);
1330 * Retrieve the number of entries shown per page.
1334 public int countPerPage() {
1335 int height
= getSize().y
;
1338 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1339 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1340 if (ySum
>= height
) {
1345 for (int idx
= fTopIndex
- 1; idx
>= 0; idx
--) {
1346 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1347 if (ySum
>= height
) {
1356 * Get the index of the top element
1360 public int getTopIndex() {
1365 * Get the number of expanded (visible) items
1367 * @return The count of expanded (visible) items
1369 public int getExpandedElementCount() {
1370 return fItemData
.fExpandedItems
.length
;
1374 * Get an array of all expanded (visible) elements
1376 * @return The expanded (visible) elements
1378 public ITimeGraphEntry
[] getExpandedElements() {
1379 ArrayList
<ITimeGraphEntry
> elements
= new ArrayList
<>();
1380 for (Item item
: fItemData
.fExpandedItems
) {
1381 elements
.add(item
.fEntry
);
1383 return elements
.toArray(new ITimeGraphEntry
[0]);
1386 Rectangle
getNameRect(Rectangle bounds
, int idx
, int nameWidth
) {
1387 Rectangle rect
= getItemRect(bounds
, idx
);
1388 rect
.width
= nameWidth
;
1392 Rectangle
getStatesRect(Rectangle bounds
, int idx
, int nameWidth
) {
1393 Rectangle rect
= getItemRect(bounds
, idx
);
1394 rect
.x
+= nameWidth
;
1395 rect
.width
-= nameWidth
;
1399 Rectangle
getItemRect(Rectangle bounds
, int idx
) {
1401 if (idx
>= fTopIndex
) {
1402 for (int i
= fTopIndex
; i
< idx
; i
++) {
1403 ySum
+= fItemData
.fExpandedItems
[i
].fItemHeight
;
1406 for (int i
= fTopIndex
- 1; i
>= idx
; i
--) {
1407 ySum
-= fItemData
.fExpandedItems
[i
].fItemHeight
;
1410 int y
= bounds
.y
+ ySum
;
1411 int height
= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1412 return new Rectangle(bounds
.x
, y
, bounds
.width
, height
);
1416 void paint(Rectangle bounds
, PaintEvent e
) {
1419 if (bounds
.width
< 2 || bounds
.height
< 2 || null == fTimeProvider
) {
1423 fIdealNameSpace
= 0;
1424 int nameSpace
= fTimeProvider
.getNameSpace();
1426 // draw the background layer
1427 drawBackground(bounds
, nameSpace
, gc
);
1429 // draw the grid lines
1430 drawGridLines(bounds
, gc
);
1432 // draw the background markers
1433 drawMarkers(bounds
, fTimeProvider
, fMarkers
, false, nameSpace
, gc
);
1435 // draw the background bookmarks
1436 drawMarkers(bounds
, fTimeProvider
, fBookmarks
, false, nameSpace
, gc
);
1439 drawItems(bounds
, fTimeProvider
, fItemData
.fExpandedItems
, fTopIndex
, nameSpace
, gc
);
1441 // draw the foreground markers
1442 drawMarkers(bounds
, fTimeProvider
, fMarkers
, true, nameSpace
, gc
);
1444 // draw the foreground bookmarks
1445 drawMarkers(bounds
, fTimeProvider
, fBookmarks
, true, nameSpace
, gc
);
1447 // draw the links (arrows)
1448 drawLinks(bounds
, fTimeProvider
, fItemData
.fLinks
, nameSpace
, gc
);
1450 fTimeGraphProvider
.postDrawControl(bounds
, gc
);
1452 int alpha
= gc
.getAlpha();
1455 long time0
= fTimeProvider
.getTime0();
1456 long time1
= fTimeProvider
.getTime1();
1457 long selectionBegin
= fTimeProvider
.getSelectionBegin();
1458 long selectionEnd
= fTimeProvider
.getSelectionEnd();
1459 double pixelsPerNanoSec
= (bounds
.width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (bounds
.width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1460 int x0
= bounds
.x
+ nameSpace
+ (int) ((selectionBegin
- time0
) * pixelsPerNanoSec
);
1461 int x1
= bounds
.x
+ nameSpace
+ (int) ((selectionEnd
- time0
) * pixelsPerNanoSec
);
1463 // draw selection lines
1464 if (fDragState
!= DRAG_SELECTION
) {
1465 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1466 if (x0
>= nameSpace
&& x0
< bounds
.x
+ bounds
.width
) {
1467 gc
.drawLine(x0
, bounds
.y
, x0
, bounds
.y
+ bounds
.height
);
1470 if (x1
>= nameSpace
&& x1
< bounds
.x
+ bounds
.width
) {
1471 gc
.drawLine(x1
, bounds
.y
, x1
, bounds
.y
+ bounds
.height
);
1476 // draw selection background
1477 if (selectionBegin
!= 0 && selectionEnd
!= 0 && fDragState
!= DRAG_SELECTION
) {
1478 x0
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x0
));
1479 x1
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x1
));
1480 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1482 gc
.fillRectangle(new Rectangle(x0
+ 1, bounds
.y
, x1
- x0
- 1, bounds
.height
));
1483 } else if (x0
- x1
> 1) {
1484 gc
.fillRectangle(new Rectangle(x1
+ 1, bounds
.y
, x0
- x1
- 1, bounds
.height
));
1488 // draw drag selection background
1489 if (fDragState
== DRAG_ZOOM
|| fDragState
== DRAG_SELECTION
) {
1490 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1491 if (fDragX0
< fDragX
) {
1492 gc
.fillRectangle(new Rectangle(fDragX0
, bounds
.y
, fDragX
- fDragX0
, bounds
.height
));
1493 } else if (fDragX0
> fDragX
) {
1494 gc
.fillRectangle(new Rectangle(fDragX
, bounds
.y
, fDragX0
- fDragX
, bounds
.height
));
1499 if (DRAG_SPLIT_LINE
== fDragState
) {
1500 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.BLACK
));
1501 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1502 } else if (DRAG_ZOOM
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1503 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.TOOL_FOREGROUND
));
1504 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1505 if (fDragX
!= fDragX0
) {
1506 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1508 } else if (DRAG_SELECTION
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1509 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1510 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1511 if (fDragX
!= fDragX0
) {
1512 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1514 } else if (DRAG_NONE
== fDragState
&& fMouseOverSplitLine
&& fTimeProvider
.getNameSpace() > 0) {
1515 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.RED
));
1516 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1523 * Draw the background layer. Fills the background of the control's name
1524 * space and states space, updates the background of items if necessary,
1525 * and draws the item's name text and middle line.
1528 * The bounds of the control
1530 * The name space width
1535 protected void drawBackground(Rectangle bounds
, int nameSpace
, GC gc
) {
1536 // draw empty name space background
1537 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1538 drawBackground(gc
, bounds
.x
, bounds
.y
, nameSpace
, bounds
.height
);
1540 // draw empty states space background
1541 gc
.setBackground(getColorScheme().getColor(TimeGraphColorScheme
.BACKGROUND
));
1542 drawBackground(gc
, bounds
.x
+ nameSpace
, bounds
.y
, bounds
.width
- nameSpace
, bounds
.height
);
1544 for (int i
= fTopIndex
; i
< fItemData
.fExpandedItems
.length
; i
++) {
1545 Rectangle itemRect
= getItemRect(bounds
, i
);
1546 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1549 Item item
= fItemData
.fExpandedItems
[i
];
1550 // draw the background of selected item and items with no time events
1551 if (! item
.fEntry
.hasTimeEvents()) {
1552 gc
.setBackground(getColorScheme().getBkColorGroup(item
.fSelected
, fIsInFocus
));
1553 gc
.fillRectangle(itemRect
);
1554 } else if (item
.fSelected
) {
1555 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, true));
1556 gc
.fillRectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1557 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, false));
1558 gc
.fillRectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1560 // draw the name and middle line
1561 if (! item
.fEntry
.hasTimeEvents()) {
1562 drawName(item
, itemRect
, gc
);
1564 Rectangle nameRect
= new Rectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1565 drawName(item
, nameRect
, gc
);
1566 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1567 drawMidLine(rect
, gc
);
1573 * Draw the grid lines
1576 * The bounds of the control
1581 public void drawGridLines(Rectangle bounds
, GC gc
) {
1582 if (!fGridLinesVisible
) {
1585 gc
.setForeground(fGridLineColor
);
1586 gc
.setAlpha(fGridLineColor
.getAlpha());
1587 for (int x
: fTimeGraphScale
.getTickList()) {
1588 gc
.drawLine(x
, bounds
.y
, x
, bounds
.y
+ bounds
.height
);
1597 * The rectangle of the area
1598 * @param timeProvider
1601 * The list of markers
1603 * true to draw the foreground markers, false otherwise
1605 * The width reserved for the names
1607 * Reference to the SWT GC object
1610 protected void drawMarkers(Rectangle bounds
, ITimeDataProvider timeProvider
, List
<IMarkerEvent
> markers
, boolean foreground
, int nameSpace
, GC gc
) {
1611 if (!fMarkersVisible
|| markers
== null || markers
.isEmpty()) {
1614 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1615 /* the list can grow concurrently but cannot shrink */
1616 for (int i
= 0; i
< markers
.size(); i
++) {
1617 IMarkerEvent marker
= markers
.get(i
);
1618 if (marker
.isForeground() == foreground
) {
1619 drawMarker(marker
, bounds
, timeProvider
, nameSpace
, gc
);
1622 gc
.setClipping((Rectangle
) null);
1626 * Draw a single marker
1631 * The bounds of the control
1632 * @param timeProvider
1635 * The width reserved for the name
1637 * Reference to the SWT GC object
1640 protected void drawMarker(IMarkerEvent marker
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1641 Rectangle rect
= Utils
.clone(bounds
);
1642 if (marker
.getEntry() != null) {
1643 int index
= fItemData
.findItemIndex(marker
.getEntry());
1647 rect
= getStatesRect(bounds
, index
, nameSpace
);
1648 if (rect
.y
< 0 || rect
.y
> bounds
.height
) {
1652 int x0
= getXForTime(marker
.getTime());
1653 int x1
= getXForTime(marker
.getTime() + marker
.getDuration());
1654 if (x0
> bounds
.width
|| x1
< nameSpace
) {
1657 rect
.x
= Math
.max(nameSpace
, Math
.min(bounds
.width
, x0
));
1658 rect
.width
= Math
.max(1, Math
.min(bounds
.width
, x1
) - rect
.x
);
1660 gc
.setBackground(marker
.getColor());
1661 gc
.setAlpha(marker
.getColor().getAlpha());
1662 gc
.fillRectangle(rect
);
1664 String label
= marker
.getLabel();
1665 if (label
!= null && marker
.getEntry() != null) {
1666 label
= label
.substring(0, Math
.min(label
.indexOf('\n') != -1 ? label
.indexOf('\n') : label
.length(), MAX_LABEL_LENGTH
));
1667 gc
.setForeground(marker
.getColor());
1668 Utils
.drawText(gc
, label
, rect
.x
- gc
.textExtent(label
).x
, rect
.y
, true);
1673 * Draw many items at once
1676 * The bounds of the control
1677 * @param timeProvider
1680 * The array items to draw
1682 * The index of the first element to draw
1684 * The name space width
1688 public void drawItems(Rectangle bounds
, ITimeDataProvider timeProvider
,
1689 Item
[] items
, int topIndex
, int nameSpace
, GC gc
) {
1690 for (int i
= topIndex
; i
< items
.length
; i
++) {
1691 Item item
= items
[i
];
1692 drawItem(item
, bounds
, timeProvider
, i
, nameSpace
, gc
);
1702 * The bounds of the control
1703 * @param timeProvider
1706 * The expanded item index
1708 * The name space width
1712 protected void drawItem(Item item
, Rectangle bounds
, ITimeDataProvider timeProvider
, int i
, int nameSpace
, GC gc
) {
1713 Rectangle itemRect
= getItemRect(bounds
, i
);
1714 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1718 ITimeGraphEntry entry
= item
.fEntry
;
1719 long time0
= timeProvider
.getTime0();
1720 long time1
= timeProvider
.getTime1();
1721 long selectedTime
= fTimeProvider
.getSelectionEnd();
1723 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1724 if (rect
.isEmpty() || (time1
<= time0
)) {
1725 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1729 boolean selected
= item
.fSelected
;
1730 // K pixels per second
1731 double pixelsPerNanoSec
= (rect
.width
<= RIGHT_MARGIN
) ?
0 : (double) (rect
.width
- RIGHT_MARGIN
) / (time1
- time0
);
1733 if (item
.fEntry
.hasTimeEvents()) {
1734 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1735 fillSpace(rect
, gc
, selected
);
1737 * State rectangle is smaller than item bounds. Use a margin height
1738 * of 3 pixels, keep at least 3 pixels for the state, but not more
1739 * than the item height. Favor the top margin for the remainder.
1741 int height
= Math
.min(rect
.height
, Math
.max(3, rect
.height
- 6));
1742 int margin
= (rect
.height
- height
+ 1) / 2;
1743 Rectangle stateRect
= new Rectangle(rect
.x
, rect
.y
+ margin
, rect
.width
, height
);
1745 long maxDuration
= (timeProvider
.getTimeSpace() == 0) ? Long
.MAX_VALUE
: 1 * (time1
- time0
) / timeProvider
.getTimeSpace();
1746 Iterator
<ITimeEvent
> iterator
= entry
.getTimeEventsIterator(time0
, time1
, maxDuration
);
1749 while (iterator
.hasNext()) {
1750 ITimeEvent event
= iterator
.next();
1751 int x
= rect
.x
+ (int) ((event
.getTime() - time0
) * pixelsPerNanoSec
);
1752 int xEnd
= rect
.x
+ (int) ((event
.getTime() + event
.getDuration() - time0
) * pixelsPerNanoSec
);
1753 if (x
>= rect
.x
+ rect
.width
|| xEnd
< rect
.x
) {
1754 // event is out of bounds
1757 xEnd
= Math
.min(rect
.x
+ rect
.width
, xEnd
);
1758 stateRect
.x
= Math
.max(rect
.x
, x
);
1759 stateRect
.width
= Math
.max(0, xEnd
- stateRect
.x
+ 1);
1760 if (stateRect
.x
== lastX
) {
1761 stateRect
.width
-= 1;
1762 if (stateRect
.width
> 0) {
1763 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
1764 gc
.drawPoint(stateRect
.x
, stateRect
.y
- 2);
1768 boolean timeSelected
= selectedTime
>= event
.getTime() && selectedTime
< event
.getTime() + event
.getDuration();
1769 if (drawState(getColorScheme(), event
, stateRect
, gc
, selected
, timeSelected
)) {
1770 lastX
= stateRect
.x
;
1773 gc
.setClipping((Rectangle
) null);
1775 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1782 * The bounds of the control
1783 * @param timeProvider
1786 * The list of link events
1788 * The name space width
1792 public void drawLinks(Rectangle bounds
, ITimeDataProvider timeProvider
,
1793 List
<ILinkEvent
> links
, int nameSpace
, GC gc
) {
1797 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1798 /* the list can grow concurrently but cannot shrink */
1799 for (int i
= 0; i
< links
.size(); i
++) {
1800 drawLink(links
.get(i
), bounds
, timeProvider
, nameSpace
, gc
);
1802 gc
.setClipping((Rectangle
) null);
1806 * Draws a link type event
1809 * The link event to draw
1811 * The bounds of the control
1812 * @param timeProvider
1815 * The name space width
1819 protected void drawLink(ILinkEvent event
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1820 drawArrow(getColorScheme(), event
, getArrowRectangle(bounds
, event
), gc
);
1823 private Rectangle
getArrowRectangle(Rectangle bounds
, ILinkEvent event
) {
1824 int srcIndex
= fItemData
.findItemIndex(event
.getEntry());
1825 int destIndex
= fItemData
.findItemIndex(event
.getDestinationEntry());
1827 if ((srcIndex
== -1) || (destIndex
== -1)) {
1831 Rectangle src
= getStatesRect(bounds
, srcIndex
, fTimeProvider
.getNameSpace());
1832 Rectangle dst
= getStatesRect(bounds
, destIndex
, fTimeProvider
.getNameSpace());
1834 int x0
= getXForTime(event
.getTime());
1835 int x1
= getXForTime(event
.getTime() + event
.getDuration());
1837 // limit the x-coordinates to prevent integer overflow in calculations
1838 // and also GC.drawLine doesn't draw properly with large coordinates
1839 final int limit
= Integer
.MAX_VALUE
/ 1024;
1840 x0
= Math
.max(-limit
, Math
.min(x0
, limit
));
1841 x1
= Math
.max(-limit
, Math
.min(x1
, limit
));
1843 int y0
= src
.y
+ src
.height
/ 2;
1844 int y1
= dst
.y
+ dst
.height
/ 2;
1845 return new Rectangle(x0
, y0
, x1
- x0
, y1
- y0
);
1854 * Time event for which we're drawing the arrow
1856 * The arrow rectangle
1859 * @return true if the arrow was drawn
1861 protected boolean drawArrow(TimeGraphColorScheme colors
, ITimeEvent event
,
1862 Rectangle rect
, GC gc
) {
1867 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
1871 boolean visible
= ((rect
.height
== 0) && (rect
.width
== 0)) ?
false : true;
1874 Color stateColor
= null;
1875 if (colorIdx
< fEventColorMap
.length
) {
1876 stateColor
= fEventColorMap
[colorIdx
];
1878 stateColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
1881 gc
.setForeground(stateColor
);
1882 gc
.setBackground(stateColor
);
1884 /* Draw the arrow */
1885 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
1886 drawArrowHead(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
, gc
);
1889 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
1894 * @author Francis Giraldeau
1897 * http://stackoverflow.com/questions/3010803/draw-arrow-on-line-algorithm
1899 * The algorithm was taken from this site, not the code itself
1901 private static void drawArrowHead(int x0
, int y0
, int x1
, int y1
, GC gc
)
1904 double cos
= 0.9510;
1905 double sin
= 0.3090;
1906 long lenx
= x1
- x0
;
1907 long leny
= y1
- y0
;
1908 double len
= Math
.sqrt(lenx
* lenx
+ leny
* leny
);
1910 double dx
= factor
* lenx
/ len
;
1911 double dy
= factor
* leny
/ len
;
1912 int end1X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* -sin
)));
1913 int end1Y
= (int) Math
.round((y1
- (dx
* sin
+ dy
* cos
)));
1914 int end2X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* sin
)));
1915 int end2Y
= (int) Math
.round((y1
- (dx
* -sin
+ dy
* cos
)));
1916 int[] arrow
= new int[] { x1
, y1
, end1X
, end1Y
, end2X
, end2Y
, x1
, y1
};
1917 gc
.fillPolygon(arrow
);
1921 * Draw the name of an item.
1926 * The bounds of the item's name space
1930 protected void drawName(Item item
, Rectangle bounds
, GC gc
) {
1931 boolean hasTimeEvents
= item
.fEntry
.hasTimeEvents();
1933 // No name to be drawn
1934 if (fTimeProvider
.getNameSpace() == 0) {
1938 int leftMargin
= MARGIN
+ item
.fLevel
* EXPAND_SIZE
;
1939 if (item
.fHasChildren
) {
1940 gc
.setForeground(getColorScheme().getFgColorGroup(false, false));
1941 gc
.setBackground(getColorScheme().getBkColor(false, false, false));
1942 Rectangle rect
= Utils
.clone(bounds
);
1943 rect
.x
+= leftMargin
;
1944 rect
.y
+= (bounds
.height
- EXPAND_SIZE
) / 2;
1945 rect
.width
= EXPAND_SIZE
;
1946 rect
.height
= EXPAND_SIZE
;
1947 gc
.fillRectangle(rect
);
1948 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1, rect
.height
- 1);
1949 int midy
= rect
.y
+ rect
.height
/ 2;
1950 gc
.drawLine(rect
.x
+ 2, midy
, rect
.x
+ rect
.width
- 3, midy
);
1951 if (!item
.fExpanded
) {
1952 int midx
= rect
.x
+ rect
.width
/ 2;
1953 gc
.drawLine(midx
, rect
.y
+ 2, midx
, rect
.y
+ rect
.height
- 3);
1956 leftMargin
+= EXPAND_SIZE
+ MARGIN
;
1958 Image img
= fTimeGraphProvider
.getItemImage(item
.fEntry
);
1961 int imgHeight
= img
.getImageData().height
;
1962 int imgWidth
= img
.getImageData().width
;
1964 int y
= bounds
.y
+ (bounds
.height
- imgHeight
) / 2;
1965 gc
.drawImage(img
, x
, y
);
1966 leftMargin
+= imgWidth
+ MARGIN
;
1968 String name
= item
.fName
;
1969 Point size
= gc
.stringExtent(name
);
1970 if (fIdealNameSpace
< leftMargin
+ size
.x
+ MARGIN
) {
1971 fIdealNameSpace
= leftMargin
+ size
.x
+ MARGIN
;
1973 if (hasTimeEvents
) {
1974 // cut long string with "..."
1975 int width
= bounds
.width
- leftMargin
;
1977 while (size
.x
> width
&& name
.length() > 1) {
1979 name
= name
.substring(0, name
.length() - 1);
1980 size
= gc
.stringExtent(name
+ "..."); //$NON-NLS-1$
1983 name
+= "..."; //$NON-NLS-1$
1986 Rectangle rect
= Utils
.clone(bounds
);
1987 rect
.x
+= leftMargin
;
1988 rect
.width
-= leftMargin
;
1990 if (rect
.width
> 0) {
1991 rect
.y
+= (bounds
.height
- gc
.stringExtent(name
).y
) / 2;
1992 gc
.setForeground(getColorScheme().getFgColor(item
.fSelected
, fIsInFocus
));
1993 int textWidth
= Utils
.drawText(gc
, name
, rect
, true);
1994 leftMargin
+= textWidth
+ MARGIN
;
1996 if (hasTimeEvents
) {
1998 rect
.x
= bounds
.x
+ leftMargin
;
2000 rect
.width
= bounds
.width
- rect
.x
;
2001 drawMidLine(rect
, gc
);
2007 * Draw the state (color fill)
2012 * Time event for which we're drawing the state
2014 * The state rectangle
2018 * Is this time event currently selected (so it appears
2020 * @param timeSelected
2021 * Is the timestamp currently selected
2022 * @return true if the state was drawn
2024 protected boolean drawState(TimeGraphColorScheme colors
, ITimeEvent event
,
2025 Rectangle rect
, GC gc
, boolean selected
, boolean timeSelected
) {
2027 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
2028 if (colorIdx
< 0 && colorIdx
!= ITimeGraphPresentationProvider
.TRANSPARENT
) {
2031 boolean visible
= rect
.width
== 0 ?
false : true;
2032 rect
.width
= Math
.max(1, rect
.width
);
2033 Color black
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
2034 gc
.setForeground(black
);
2036 if (colorIdx
== ITimeGraphPresentationProvider
.TRANSPARENT
) {
2038 // Only draw the top and bottom borders
2039 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1, rect
.y
);
2040 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
- 1);
2041 if (rect
.width
== 1) {
2042 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2045 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2048 Color stateColor
= null;
2049 if (colorIdx
< fEventColorMap
.length
) {
2050 stateColor
= fEventColorMap
[colorIdx
];
2055 boolean reallySelected
= timeSelected
&& selected
;
2056 // fill all rect area
2057 gc
.setBackground(stateColor
);
2059 gc
.fillRectangle(rect
);
2060 } else if (fBlendSubPixelEvents
) {
2062 gc
.fillRectangle(rect
);
2066 if (reallySelected
) {
2067 gc
.drawLine(rect
.x
, rect
.y
- 1, rect
.x
+ rect
.width
- 1, rect
.y
- 1);
2068 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
);
2071 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2073 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2078 * Fill an item's states rectangle
2081 * The states rectangle
2085 * true if the item is selected
2087 protected void fillSpace(Rectangle rect
, GC gc
, boolean selected
) {
2088 /* Nothing to draw */
2092 * Draw a line at the middle height of a rectangle
2099 private void drawMidLine(Rectangle rect
, GC gc
) {
2100 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.MID_LINE
));
2101 int midy
= rect
.y
+ rect
.height
/ 2;
2102 gc
.drawLine(rect
.x
, midy
, rect
.x
+ rect
.width
, midy
);
2106 public void keyTraversed(TraverseEvent e
) {
2107 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {
2113 public void keyPressed(KeyEvent e
) {
2115 if (fItemData
.fExpandedItems
.length
== 0) {
2118 if (SWT
.HOME
== e
.keyCode
) {
2120 } else if (SWT
.END
== e
.keyCode
) {
2121 idx
= fItemData
.fExpandedItems
.length
- 1;
2122 } else if (SWT
.ARROW_DOWN
== e
.keyCode
) {
2123 idx
= getSelectedIndex();
2126 } else if (idx
< fItemData
.fExpandedItems
.length
- 1) {
2129 } else if (SWT
.ARROW_UP
== e
.keyCode
) {
2130 idx
= getSelectedIndex();
2133 } else if (idx
> 0) {
2136 } else if (SWT
.ARROW_LEFT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2137 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2138 selectPrevEvent(extend
);
2139 } else if (SWT
.ARROW_RIGHT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2140 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2141 selectNextEvent(extend
);
2142 } else if (SWT
.PAGE_DOWN
== e
.keyCode
) {
2143 int page
= countPerPage();
2144 idx
= getSelectedIndex();
2149 if (idx
>= fItemData
.fExpandedItems
.length
) {
2150 idx
= fItemData
.fExpandedItems
.length
- 1;
2152 } else if (SWT
.PAGE_UP
== e
.keyCode
) {
2153 int page
= countPerPage();
2154 idx
= getSelectedIndex();
2162 } else if (SWT
.CR
== e
.keyCode
) {
2163 idx
= getSelectedIndex();
2165 if (fItemData
.fExpandedItems
[idx
].fHasChildren
) {
2168 fireDefaultSelection();
2174 selectItem(idx
, false);
2175 fireSelectionChanged();
2177 int x
= toControl(e
.display
.getCursorLocation()).x
;
2178 updateCursor(x
, e
.stateMask
| e
.keyCode
);
2182 public void keyReleased(KeyEvent e
) {
2183 int x
= toControl(e
.display
.getCursorLocation()).x
;
2184 updateCursor(x
, e
.stateMask
& ~e
.keyCode
);
2188 public void focusGained(FocusEvent e
) {
2191 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2195 public void focusLost(FocusEvent e
) {
2197 if (DRAG_NONE
!= fDragState
) {
2199 fDragState
= DRAG_NONE
;
2202 updateStatusLine(NO_STATUS
);
2206 * @return If the current view is focused
2208 public boolean isInFocus() {
2213 * Provide the possibility to control the wait cursor externally e.g. data
2214 * requests in progress
2216 * @param waitInd Should we wait indefinitely?
2218 public void waitCursor(boolean waitInd
) {
2219 // Update cursor as indicated
2221 setCursor(fWaitCursor
);
2227 private void updateCursor(int x
, int stateMask
) {
2228 // if Wait cursor not active, check for the need to change the cursor
2229 if (getCursor() == fWaitCursor
) {
2232 Cursor cursor
= null;
2233 if (fDragState
== DRAG_SPLIT_LINE
) {
2234 } else if (fDragState
== DRAG_SELECTION
) {
2235 cursor
= fResizeCursor
;
2236 } else if (fDragState
== DRAG_TRACE_ITEM
) {
2237 cursor
= fDragCursor
;
2238 } else if (fDragState
== DRAG_ZOOM
) {
2239 cursor
= fZoomCursor
;
2240 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2241 cursor
= fDragCursor
;
2242 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2243 cursor
= fResizeCursor
;
2244 } else if (!isOverSplitLine(x
)) {
2245 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2246 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2247 int xBegin
= getXForTime(selectionBegin
);
2248 int xEnd
= getXForTime(selectionEnd
);
2249 if (Math
.abs(x
- xBegin
) < SNAP_WIDTH
|| Math
.abs(x
- xEnd
) < SNAP_WIDTH
) {
2250 cursor
= fResizeCursor
;
2253 if (getCursor() != cursor
) {
2258 private void updateStatusLine(int x
) {
2259 // use the time provider of the time graph scale for the status line
2260 ITimeDataProvider tdp
= fTimeGraphScale
.getTimeProvider();
2261 if (fStatusLineManager
== null || null == tdp
||
2262 tdp
.getTime0() == tdp
.getTime1()) {
2265 TimeFormat tf
= tdp
.getTimeFormat();
2266 Resolution res
= Resolution
.NANOSEC
;
2267 StringBuilder message
= new StringBuilder();
2268 if ((x
>= 0 || x
== STATUS_WITHOUT_CURSOR_TIME
) && fDragState
== DRAG_NONE
) {
2269 if (x
!= STATUS_WITHOUT_CURSOR_TIME
) {
2270 long time
= getTimeAtX(x
);
2272 if (tdp
instanceof ITimeDataProviderConverter
) {
2273 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2275 message
.append(NLS
.bind("T: {0}{1} ", //$NON-NLS-1$
2277 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2278 Utils
.formatTime(time
, tf
, res
)
2282 long selectionBegin
= tdp
.getSelectionBegin();
2283 long selectionEnd
= tdp
.getSelectionEnd();
2284 message
.append(NLS
.bind("T1: {0}{1}", //$NON-NLS-1$
2286 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionBegin
) + ' ' : "", //$NON-NLS-1$
2287 Utils
.formatTime(selectionBegin
, tf
, res
)
2289 if (selectionBegin
!= selectionEnd
) {
2290 message
.append(NLS
.bind(" T2: {0}{1} \u0394: {2}", //$NON-NLS-1$
2292 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionEnd
) + ' ' : "", //$NON-NLS-1$
2293 Utils
.formatTime(selectionEnd
, tf
, res
),
2294 Utils
.formatDelta(selectionEnd
- selectionBegin
, tf
, res
)
2297 } else if (fDragState
== DRAG_SELECTION
|| fDragState
== DRAG_ZOOM
) {
2298 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2299 long time
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2300 if (tdp
instanceof ITimeDataProviderConverter
) {
2301 time0
= ((ITimeDataProviderConverter
) tdp
).convertTime(time0
);
2302 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2304 message
.append(NLS
.bind("T1: {0}{1} T2: {2}{3} \u0394: {4}", //$NON-NLS-1$
2306 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time0
) + ' ' : "", //$NON-NLS-1$
2307 Utils
.formatTime(time0
, tf
, res
),
2308 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2309 Utils
.formatTime(time
, tf
, res
),
2310 Utils
.formatDelta(time
- time0
, tf
, res
)
2313 fStatusLineManager
.setMessage(message
.toString());
2317 public void mouseMove(MouseEvent e
) {
2318 if (null == fTimeProvider
) {
2321 Point size
= getSize();
2322 if (DRAG_TRACE_ITEM
== fDragState
) {
2323 int nameWidth
= fTimeProvider
.getNameSpace();
2324 if (e
.x
> nameWidth
&& size
.x
> nameWidth
&& fDragX
!= e
.x
) {
2326 double pixelsPerNanoSec
= (size
.x
- nameWidth
<= RIGHT_MARGIN
) ?
0 : (double) (size
.x
- nameWidth
- RIGHT_MARGIN
) / (fTime1bak
- fTime0bak
);
2327 long timeDelta
= (long) ((pixelsPerNanoSec
== 0) ?
0 : ((fDragX
- fDragX0
) / pixelsPerNanoSec
));
2328 long time1
= fTime1bak
- timeDelta
;
2329 long maxTime
= fTimeProvider
.getMaxTime();
2330 if (time1
> maxTime
) {
2333 long time0
= time1
- (fTime1bak
- fTime0bak
);
2334 if (time0
< fTimeProvider
.getMinTime()) {
2335 time0
= fTimeProvider
.getMinTime();
2336 time1
= time0
+ (fTime1bak
- fTime0bak
);
2338 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2340 } else if (DRAG_SPLIT_LINE
== fDragState
) {
2342 fTimeProvider
.setNameSpace(e
.x
);
2343 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2344 } else if (DRAG_SELECTION
== fDragState
) {
2345 if (fDragBeginMarker
) {
2346 fDragX0
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2348 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2351 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2352 fireDragSelectionChanged(getTimeAtX(fDragX0
), getTimeAtX(fDragX
));
2353 } else if (DRAG_ZOOM
== fDragState
) {
2354 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2356 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2357 } else if (DRAG_NONE
== fDragState
) {
2358 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2359 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2362 fMouseOverSplitLine
= mouseOverSplitLine
;
2364 updateCursor(e
.x
, e
.stateMask
);
2365 updateStatusLine(e
.x
);
2369 public void mouseDoubleClick(MouseEvent e
) {
2370 if (null == fTimeProvider
) {
2373 if (1 == e
.button
&& (e
.stateMask
& SWT
.BUTTON_MASK
) == 0) {
2374 if (isOverSplitLine(e
.x
) && fTimeProvider
.getNameSpace() != 0) {
2375 fTimeProvider
.setNameSpace(fIdealNameSpace
);
2376 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2377 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2380 fMouseOverSplitLine
= mouseOverSplitLine
;
2381 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2384 int idx
= getItemIndexAtY(e
.y
);
2386 selectItem(idx
, false);
2387 fireDefaultSelection();
2393 public void mouseDown(MouseEvent e
) {
2394 if (fDragState
!= DRAG_NONE
|| null == fTimeProvider
||
2395 fTimeProvider
.getTime0() == fTimeProvider
.getTime1() ||
2396 getSize().x
- fTimeProvider
.getNameSpace() <= 0) {
2400 if (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == 0) {
2401 int nameSpace
= fTimeProvider
.getNameSpace();
2402 if (nameSpace
!= 0 && isOverSplitLine(e
.x
)) {
2403 fDragState
= DRAG_SPLIT_LINE
;
2404 fDragButton
= e
.button
;
2407 fTime0bak
= fTimeProvider
.getTime0();
2408 fTime1bak
= fTimeProvider
.getTime1();
2410 updateCursor(e
.x
, e
.stateMask
);
2414 if (1 == e
.button
&& ((e
.stateMask
& SWT
.MODIFIER_MASK
) == 0 || (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
)) {
2415 int nameSpace
= fTimeProvider
.getNameSpace();
2416 idx
= getItemIndexAtY(e
.y
);
2418 Item item
= fItemData
.fExpandedItems
[idx
];
2419 if (item
.fHasChildren
&& e
.x
< nameSpace
&& e
.x
< MARGIN
+ (item
.fLevel
+ 1) * EXPAND_SIZE
) {
2423 selectItem(idx
, false);
2424 fireSelectionChanged();
2426 selectItem(idx
, false); // clear selection
2427 fireSelectionChanged();
2429 long hitTime
= getTimeAtX(e
.x
);
2433 fDragState
= DRAG_SELECTION
;
2434 fDragBeginMarker
= false;
2435 fDragButton
= e
.button
;
2438 fDragTime0
= getTimeAtX(fDragX0
);
2439 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2440 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2441 int xBegin
= getXForTime(selectionBegin
);
2442 int xEnd
= getXForTime(selectionEnd
);
2443 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2444 long time
= getTimeAtX(e
.x
);
2445 if (Math
.abs(time
- selectionBegin
) < Math
.abs(time
- selectionEnd
)) {
2446 fDragBeginMarker
= true;
2449 fDragTime0
= selectionEnd
;
2452 fDragTime0
= selectionBegin
;
2455 long time
= getTimeAtX(e
.x
);
2456 if (Math
.abs(e
.x
- xBegin
) < SNAP_WIDTH
&& Math
.abs(time
- selectionBegin
) <= Math
.abs(time
- selectionEnd
)) {
2457 fDragBeginMarker
= true;
2460 fDragTime0
= selectionEnd
;
2461 } else if (Math
.abs(e
.x
- xEnd
) < SNAP_WIDTH
&& Math
.abs(time
- selectionEnd
) <= Math
.abs(time
- selectionBegin
)) {
2463 fDragTime0
= selectionBegin
;
2466 fTime0bak
= fTimeProvider
.getTime0();
2467 fTime1bak
= fTimeProvider
.getTime1();
2469 updateCursor(e
.x
, e
.stateMask
);
2470 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2472 } else if (2 == e
.button
|| (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
)) {
2473 long hitTime
= getTimeAtX(e
.x
);
2476 fDragState
= DRAG_TRACE_ITEM
;
2477 fDragButton
= e
.button
;
2480 fTime0bak
= fTimeProvider
.getTime0();
2481 fTime1bak
= fTimeProvider
.getTime1();
2482 updateCursor(e
.x
, e
.stateMask
);
2484 } else if (3 == e
.button
) {
2486 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), getSize().x
- RIGHT_MARGIN
);
2488 fDragTime0
= getTimeAtX(fDragX0
);
2489 fDragState
= DRAG_ZOOM
;
2490 fDragButton
= e
.button
;
2492 updateCursor(e
.x
, e
.stateMask
);
2493 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2498 public void mouseUp(MouseEvent e
) {
2499 if (fPendingMenuDetectEvent
!= null && e
.button
== 3) {
2500 menuDetected(fPendingMenuDetectEvent
);
2502 if (DRAG_NONE
!= fDragState
) {
2504 if (e
.button
== fDragButton
&& DRAG_TRACE_ITEM
== fDragState
) {
2505 if (fDragX
!= fDragX0
) {
2506 fTimeProvider
.notifyStartFinishTime();
2508 fDragState
= DRAG_NONE
;
2509 } else if (e
.button
== fDragButton
&& DRAG_SPLIT_LINE
== fDragState
) {
2510 fDragState
= DRAG_NONE
;
2512 } else if (e
.button
== fDragButton
&& DRAG_SELECTION
== fDragState
) {
2513 if (fDragX
== fDragX0
) { // click without selecting anything
2514 long time
= getTimeAtX(e
.x
);
2515 fTimeProvider
.setSelectedTimeNotify(time
, false);
2517 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2518 long time1
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2519 fTimeProvider
.setSelectionRangeNotify(time0
, time1
);
2521 fDragState
= DRAG_NONE
;
2523 fTimeGraphScale
.setDragRange(-1, -1);
2524 } else if (e
.button
== fDragButton
&& DRAG_ZOOM
== fDragState
) {
2525 int nameWidth
= fTimeProvider
.getNameSpace();
2526 if (Math
.max(fDragX
, fDragX0
) > nameWidth
&& fDragX
!= fDragX0
) {
2527 long time0
= getTimeAtX(fDragX0
);
2528 long time1
= getTimeAtX(fDragX
);
2529 if (time0
< time1
) {
2530 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2532 fTimeProvider
.setStartFinishTimeNotify(time1
, time0
);
2537 fDragState
= DRAG_NONE
;
2538 fTimeGraphScale
.setDragRange(-1, -1);
2541 updateCursor(e
.x
, e
.stateMask
);
2542 updateStatusLine(e
.x
);
2546 public void mouseEnter(MouseEvent e
) {
2550 public void mouseExit(MouseEvent e
) {
2551 if (fMouseOverSplitLine
) {
2552 fMouseOverSplitLine
= false;
2555 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2559 public void mouseHover(MouseEvent e
) {
2563 public void mouseScrolled(MouseEvent e
) {
2564 if (fDragState
!= DRAG_NONE
) {
2567 boolean zoomScroll
= false;
2568 boolean horizontalScroll
= false;
2569 Point p
= getParent().toControl(getDisplay().getCursorLocation());
2570 Point parentSize
= getParent().getSize();
2571 if (p
.x
>= 0 && p
.x
< parentSize
.x
&& p
.y
>= 0 && p
.y
< parentSize
.y
) {
2572 // over the parent control
2573 if (e
.x
> getSize().x
) {
2574 // over the vertical scroll bar
2576 } else if (e
.y
< 0) {
2577 // over the time scale
2579 } else if (e
.y
>= getSize().y
) {
2580 // over the horizontal scroll bar
2581 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2584 horizontalScroll
= true;
2587 if (e
.x
< fTimeProvider
.getNameSpace()) {
2588 // over the name space
2591 // over the state area
2592 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2593 // over the state area, CTRL pressed
2596 // over the state area, CTRL not pressed
2602 if (zoomScroll
&& fTimeProvider
.getTime0() != fTimeProvider
.getTime1()) {
2605 } else if (e
.count
< 0) {
2608 } else if (horizontalScroll
) {
2609 horizontalScroll(e
.count
> 0);
2611 setTopIndex(getTopIndex() - e
.count
);
2616 public void handleEvent(Event event
) {
2617 if (event
.type
== SWT
.MouseWheel
) {
2618 // prevent horizontal scrolling when the mouse wheel is used to
2619 // scroll vertically or zoom
2625 public int getBorderWidth() {
2626 return fBorderWidth
;
2630 * Set the border width
2632 * @param borderWidth
2635 public void setBorderWidth(int borderWidth
) {
2636 this.fBorderWidth
= borderWidth
;
2640 * @return The current height of the header row
2642 public int getHeaderHeight() {
2643 return fHeaderHeight
;
2647 * Set the height of the header row
2649 * @param headerHeight
2652 public void setHeaderHeight(int headerHeight
) {
2653 this.fHeaderHeight
= headerHeight
;
2657 * @return The default height of regular item rows
2659 public int getItemHeight() {
2660 return fGlobalItemHeight
;
2664 * Set the default height of regular item rows.
2669 public void setItemHeight(int rowHeight
) {
2670 this.fGlobalItemHeight
= rowHeight
;
2671 for (Item item
: fItemData
.fItems
) {
2672 item
.fItemHeight
= rowHeight
;
2677 * Set the height of a specific item. Overrides the default item height.
2680 * A time graph entry
2683 * @return true if the height is successfully stored, false otherwise
2685 public boolean setItemHeight(ITimeGraphEntry entry
, int rowHeight
) {
2686 Item item
= fItemData
.findItem(entry
);
2688 item
.fItemHeight
= rowHeight
;
2695 * Set the minimum item width
2697 * @param width The minimum width
2699 public void setMinimumItemWidth(int width
) {
2700 this.fMinimumItemWidth
= width
;
2704 * @return The minimum item width
2706 public int getMinimumItemWidth() {
2707 return fMinimumItemWidth
;
2711 * Set whether all time events with a duration shorter than one pixel should
2712 * be blended in. If false, only the first such time event will be drawn and
2713 * the subsequent time events in the same pixel will be discarded. The
2714 * default value is false.
2717 * true if sub-pixel events should be blended, false otherwise.
2720 public void setBlendSubPixelEvents(boolean blend
) {
2721 fBlendSubPixelEvents
= blend
;
2725 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2726 if (listener
!= null && !fSelectionChangedListeners
.contains(listener
)) {
2727 fSelectionChangedListeners
.add(listener
);
2732 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2733 if (listener
!= null) {
2734 fSelectionChangedListeners
.remove(listener
);
2739 public void setSelection(ISelection selection
) {
2740 if (selection
instanceof TimeGraphSelection
) {
2741 TimeGraphSelection sel
= (TimeGraphSelection
) selection
;
2742 Object ob
= sel
.getFirstElement();
2743 if (ob
instanceof ITimeGraphEntry
) {
2744 ITimeGraphEntry trace
= (ITimeGraphEntry
) ob
;
2745 selectItem(trace
, false);
2752 * @param filter The filter object to be attached to the view
2754 public void addFilter(ViewerFilter filter
) {
2755 if (!fFilters
.contains(filter
)) {
2756 fFilters
.add(filter
);
2761 * @param filter The filter object to be attached to the view
2763 public void removeFilter(ViewerFilter filter
) {
2764 fFilters
.remove(filter
);
2768 * Returns this control's filters.
2770 * @return an array of viewer filters
2773 public ViewerFilter
[] getFilters() {
2774 return Iterables
.toArray(fFilters
, ViewerFilter
.class);
2778 * Sets the filters, replacing any previous filters.
2781 * an array of viewer filters, or null
2784 public void setFilters(ViewerFilter
[] filters
) {
2786 if (filters
!= null) {
2787 fFilters
.addAll(Arrays
.asList(filters
));
2792 public void colorSettingsChanged(StateItem
[] stateItems
) {
2793 /* Destroy previous colors from the resource manager */
2794 if (fEventColorMap
!= null) {
2795 for (Color color
: fEventColorMap
) {
2796 fResourceManager
.destroyColor(color
.getRGB());
2799 if (stateItems
!= null) {
2800 fEventColorMap
= new Color
[stateItems
.length
];
2801 for (int i
= 0; i
< stateItems
.length
; i
++) {
2802 fEventColorMap
[i
] = fResourceManager
.createColor(stateItems
[i
].getStateColor());
2805 fEventColorMap
= new Color
[] { };
2810 private class ItemData
{
2811 private Map
<ITimeGraphEntry
, Item
> fItemMap
= new LinkedHashMap
<>();
2812 private Item
[] fExpandedItems
= new Item
[0];
2813 private Item
[] fItems
= new Item
[0];
2814 private ITimeGraphEntry fRootEntries
[] = new ITimeGraphEntry
[0];
2815 private List
<ILinkEvent
> fLinks
= new ArrayList
<>();
2820 public Item
findItem(ITimeGraphEntry entry
) {
2821 return fItemMap
.get(entry
);
2824 public int findItemIndex(ITimeGraphEntry entry
) {
2825 Item item
= fItemMap
.get(entry
);
2829 return item
.fExpandedIndex
;
2832 public void refreshData() {
2833 ITimeGraphEntry selection
= getSelectedTrace();
2834 Map
<ITimeGraphEntry
, Item
> itemMap
= new LinkedHashMap
<>();
2835 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2836 ITimeGraphEntry entry
= fRootEntries
[i
];
2837 refreshData(itemMap
, null, 0, entry
);
2840 fItems
= fItemMap
.values().toArray(new Item
[0]);
2841 updateExpandedItems();
2842 if (selection
!= null) {
2843 for (Item item
: fExpandedItems
) {
2844 if (item
.fEntry
== selection
) {
2845 item
.fSelected
= true;
2852 private void refreshData(Map
<ITimeGraphEntry
, Item
> itemMap
, Item parent
, int level
, ITimeGraphEntry entry
) {
2853 Item item
= new Item(entry
, entry
.getName(), level
);
2854 if (parent
!= null) {
2855 parent
.fChildren
.add(item
);
2857 if (fGlobalItemHeight
== CUSTOM_ITEM_HEIGHT
) {
2858 item
.fItemHeight
= fTimeGraphProvider
.getItemHeight(entry
);
2860 item
.fItemHeight
= fGlobalItemHeight
;
2862 itemMap
.put(entry
, item
);
2863 if (entry
.hasChildren()) {
2864 Item oldItem
= fItemMap
.get(entry
);
2865 if (oldItem
!= null && oldItem
.fHasChildren
&& level
== oldItem
.fLevel
&& entry
.getParent() == oldItem
.fEntry
.getParent()) {
2866 /* existing items keep their old expanded state */
2867 item
.fExpanded
= oldItem
.fExpanded
;
2869 /* new items set the expanded state according to auto-expand level */
2870 item
.fExpanded
= fAutoExpandLevel
== ALL_LEVELS
|| level
< fAutoExpandLevel
;
2872 item
.fHasChildren
= true;
2873 for (ITimeGraphEntry child
: entry
.getChildren()) {
2874 refreshData(itemMap
, item
, level
+ 1, child
);
2879 public void updateExpandedItems() {
2880 for (Item item
: fItems
) {
2881 item
.fExpandedIndex
= -1;
2883 List
<Item
> expandedItemList
= new ArrayList
<>();
2884 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2885 ITimeGraphEntry entry
= fRootEntries
[i
];
2886 Item item
= findItem(entry
);
2887 refreshExpanded(expandedItemList
, item
);
2889 fExpandedItems
= expandedItemList
.toArray(new Item
[0]);
2890 fTopIndex
= Math
.min(fTopIndex
, Math
.max(0, fExpandedItems
.length
- 1));
2893 private void refreshExpanded(List
<Item
> expandedItemList
, Item item
) {
2894 // Check for filters
2895 boolean display
= true;
2896 for (ViewerFilter filter
: fFilters
) {
2897 if (!filter
.select(null, item
.fEntry
.getParent(), item
.fEntry
)) {
2903 item
.fExpandedIndex
= expandedItemList
.size();
2904 expandedItemList
.add(item
);
2905 if (item
.fHasChildren
&& item
.fExpanded
) {
2906 for (Item child
: item
.fChildren
) {
2907 refreshExpanded(expandedItemList
, child
);
2913 public void refreshData(ITimeGraphEntry
[] entries
) {
2914 if (entries
== null) {
2915 fRootEntries
= null;
2917 fRootEntries
= Arrays
.copyOf(entries
, entries
.length
);
2923 public void refreshArrows(List
<ILinkEvent
> events
) {
2924 /* If links are null, reset the list */
2925 if (events
!= null) {
2928 fLinks
= new ArrayList
<>();
2932 public ITimeGraphEntry
[] getEntries() {
2933 return fRootEntries
;
2937 private class Item
{
2938 private boolean fExpanded
;
2939 private int fExpandedIndex
;
2940 private boolean fSelected
;
2941 private boolean fHasChildren
;
2942 private int fItemHeight
;
2943 private final int fLevel
;
2944 private final List
<Item
> fChildren
;
2945 private final String fName
;
2946 private final ITimeGraphEntry fEntry
;
2948 public Item(ITimeGraphEntry entry
, String name
, int level
) {
2949 this.fEntry
= entry
;
2951 this.fLevel
= level
;
2952 this.fChildren
= new ArrayList
<>();
2956 public String
toString() {
2962 public void menuDetected(MenuDetectEvent e
) {
2963 if (null == fTimeProvider
) {
2966 if (e
.detail
== SWT
.MENU_MOUSE
) {
2967 if (fPendingMenuDetectEvent
== null) {
2968 /* Feature in Linux. The MenuDetectEvent is received before mouseDown.
2969 * Store the event and trigger it later just before handling mouseUp.
2970 * This allows for the method to detect if mouse is used to drag zoom.
2972 fPendingMenuDetectEvent
= e
;
2975 fPendingMenuDetectEvent
= null;
2976 if (fDragState
!= DRAG_ZOOM
|| fDragX
!= fDragX0
) {
2980 if (fDragState
!= DRAG_NONE
) {
2984 Point p
= toControl(e
.x
, e
.y
);
2985 int idx
= getItemIndexAtY(p
.y
);
2986 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
2987 Item item
= fItemData
.fExpandedItems
[idx
];
2988 ITimeGraphEntry entry
= item
.fEntry
;
2989 if (entry
.hasTimeEvents()) {
2990 ITimeEvent event
= Utils
.findEvent(entry
, getTimeAtX(p
.x
), 2);
2991 if (event
!= null) {
2993 fireMenuEventOnTimeEvent(e
);
2998 fireMenuEventOnTimeGraphEntry(e
);
3003 * Perform the alignment operation.
3006 * the alignment offset
3008 * @see ITmfTimeAligned
3012 public void performAlign(int offset
) {
3013 fTimeProvider
.setNameSpace(offset
);
3017 * Return the time alignment information
3019 * @return the time alignment information
3021 * @see ITmfTimeAligned
3025 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
3026 return new TmfTimeViewAlignmentInfo(getShell(), toDisplay(0, 0), fTimeProvider
.getNameSpace());