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
.jdt
.annotation
.NonNull
;
32 import org
.eclipse
.jface
.action
.IStatusLineManager
;
33 import org
.eclipse
.jface
.resource
.JFaceResources
;
34 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
35 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
36 import org
.eclipse
.jface
.viewers
.ISelection
;
37 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
38 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
39 import org
.eclipse
.jface
.viewers
.ViewerFilter
;
40 import org
.eclipse
.osgi
.util
.NLS
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.events
.FocusEvent
;
43 import org
.eclipse
.swt
.events
.FocusListener
;
44 import org
.eclipse
.swt
.events
.KeyEvent
;
45 import org
.eclipse
.swt
.events
.KeyListener
;
46 import org
.eclipse
.swt
.events
.MenuDetectEvent
;
47 import org
.eclipse
.swt
.events
.MenuDetectListener
;
48 import org
.eclipse
.swt
.events
.MouseEvent
;
49 import org
.eclipse
.swt
.events
.MouseListener
;
50 import org
.eclipse
.swt
.events
.MouseMoveListener
;
51 import org
.eclipse
.swt
.events
.MouseTrackListener
;
52 import org
.eclipse
.swt
.events
.MouseWheelListener
;
53 import org
.eclipse
.swt
.events
.PaintEvent
;
54 import org
.eclipse
.swt
.events
.SelectionListener
;
55 import org
.eclipse
.swt
.events
.TraverseEvent
;
56 import org
.eclipse
.swt
.events
.TraverseListener
;
57 import org
.eclipse
.swt
.events
.TypedEvent
;
58 import org
.eclipse
.swt
.graphics
.Color
;
59 import org
.eclipse
.swt
.graphics
.Cursor
;
60 import org
.eclipse
.swt
.graphics
.GC
;
61 import org
.eclipse
.swt
.graphics
.Image
;
62 import org
.eclipse
.swt
.graphics
.Point
;
63 import org
.eclipse
.swt
.graphics
.Rectangle
;
64 import org
.eclipse
.swt
.widgets
.Composite
;
65 import org
.eclipse
.swt
.widgets
.Display
;
66 import org
.eclipse
.swt
.widgets
.Event
;
67 import org
.eclipse
.swt
.widgets
.Listener
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentInfo
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.signal
.TmfTimeViewAlignmentSignal
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.ITmfTimeAligned
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphColorListener
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphPresentationProvider2
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTreeListener
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.StateItem
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTreeExpansionEvent
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ILinkEvent
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.IMarkerEvent
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
87 import com
.google
.common
.collect
.Iterables
;
90 * Time graph control implementation
92 * @author Alvaro Sanchez-Leon
93 * @author Patrick Tasse
95 public class TimeGraphControl
extends TimeGraphBaseControl
96 implements FocusListener
, KeyListener
, MouseMoveListener
, MouseListener
,
97 MouseWheelListener
, MouseTrackListener
, TraverseListener
, ISelectionProvider
,
98 MenuDetectListener
, ITmfTimeGraphDrawingHelper
, ITimeGraphColorListener
, Listener
{
100 /** Constant indicating that all levels of the time graph should be expanded */
101 public static final int ALL_LEVELS
= AbstractTreeViewer
.ALL_LEVELS
;
103 private static final int DRAG_NONE
= 0;
104 private static final int DRAG_TRACE_ITEM
= 1;
105 private static final int DRAG_SPLIT_LINE
= 2;
106 private static final int DRAG_ZOOM
= 3;
107 private static final int DRAG_SELECTION
= 4;
109 private static final int CUSTOM_ITEM_HEIGHT
= -1; // get item height from provider
111 private static final double ZOOM_FACTOR
= 1.5;
112 private static final double ZOOM_IN_FACTOR
= 0.8;
113 private static final double ZOOM_OUT_FACTOR
= 1.25;
115 private static final int SNAP_WIDTH
= 2;
116 private static final int ARROW_HOVER_MAX_DIST
= 5;
118 private static final int NO_STATUS
= -1;
119 private static final int STATUS_WITHOUT_CURSOR_TIME
= -2;
121 private static final int MAX_LABEL_LENGTH
= 256;
123 /** Resource manager */
124 private LocalResourceManager fResourceManager
= new LocalResourceManager(JFaceResources
.getResources());
126 /** Color map for event types */
127 private Color
[] fEventColorMap
= null;
129 private ITimeDataProvider fTimeProvider
;
130 private IStatusLineManager fStatusLineManager
= null;
131 private TimeGraphScale fTimeGraphScale
= null;
133 private boolean fIsInFocus
= false;
134 private boolean fMouseOverSplitLine
= false;
135 private int fGlobalItemHeight
= CUSTOM_ITEM_HEIGHT
;
136 private boolean fBlendSubPixelEvents
= false;
137 private int fMinimumItemWidth
= 0;
138 private int fTopIndex
= 0;
139 private int fDragState
= DRAG_NONE
;
140 private boolean fDragBeginMarker
= false;
141 private int fDragButton
;
142 private int fDragX0
= 0;
143 private int fDragX
= 0;
144 private long fDragTime0
= 0; // used to preserve accuracy of modified selection
145 private int fIdealNameSpace
= 0;
146 private long fTime0bak
;
147 private long fTime1bak
;
148 private ITimeGraphPresentationProvider fTimeGraphProvider
= null;
149 private ItemData fItemData
= 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
<@NonNull 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
, true);
794 fTimeProvider
.setSelectedTimeNotify(nextTime
, true);
796 fireSelectionChanged();
799 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), endTime
, true);
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 markers list.
1006 * The markers list, or null
1009 public void setMarkers(List
<IMarkerEvent
> markers
) {
1011 fTimeGraphScale
.setMarkers(markers
);
1015 * Get the markers list.
1017 * @return The markers list, or null
1020 public List
<IMarkerEvent
> getMarkers() {
1025 * Set the markers visibility. The default is true.
1028 * true to show the markers, false otherwise
1031 public void setMarkersVisible(boolean visible
) {
1032 fMarkersVisible
= visible
;
1033 fTimeGraphScale
.setMarkersVisible(visible
);
1037 * Get the markers visibility.
1039 * @return true if the markers are visible, false otherwise
1042 public boolean getMarkersVisible() {
1043 return fMarkersVisible
;
1049 * @param hideArrows true to hide arrows
1051 public void hideArrows(boolean hideArrows
) {
1052 fHideArrows
= hideArrows
;
1056 * Follow the arrow forward
1059 * true to extend selection range, false for single selection
1062 public void followArrowFwd(boolean extend
) {
1063 ITimeGraphEntry trace
= getSelectedTrace();
1064 if (trace
== null) {
1067 long selectedTime
= fTimeProvider
.getSelectionEnd();
1068 for (ILinkEvent link
: fItemData
.fLinks
) {
1069 if (link
.getEntry() == trace
&& link
.getTime() == selectedTime
) {
1070 selectItem(link
.getDestinationEntry(), false);
1071 if (link
.getDuration() != 0) {
1073 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime() + link
.getDuration(), true);
1075 fTimeProvider
.setSelectedTimeNotify(link
.getTime() + link
.getDuration(), true);
1077 // Notify if visible time window has been adjusted
1078 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1080 fireSelectionChanged();
1081 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1085 selectNextEvent(extend
);
1089 * Follow the arrow backward
1092 * true to extend selection range, false for single selection
1095 public void followArrowBwd(boolean extend
) {
1096 ITimeGraphEntry trace
= getSelectedTrace();
1097 if (trace
== null) {
1100 long selectedTime
= fTimeProvider
.getSelectionEnd();
1101 for (ILinkEvent link
: fItemData
.fLinks
) {
1102 if (link
.getDestinationEntry() == trace
&& link
.getTime() + link
.getDuration() == selectedTime
) {
1103 selectItem(link
.getEntry(), false);
1104 if (link
.getDuration() != 0) {
1106 fTimeProvider
.setSelectionRangeNotify(fTimeProvider
.getSelectionBegin(), link
.getTime(), true);
1108 fTimeProvider
.setSelectedTimeNotify(link
.getTime(), true);
1110 // Notify if visible time window has been adjusted
1111 fTimeProvider
.setStartFinishTimeNotify(fTimeProvider
.getTime0(), fTimeProvider
.getTime1());
1113 fireSelectionChanged();
1114 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
1118 selectPrevEvent(extend
);
1122 * Return the currently selected trace
1124 * @return The entry matching the trace
1126 public ITimeGraphEntry
getSelectedTrace() {
1127 ITimeGraphEntry trace
= null;
1128 int idx
= getSelectedIndex();
1130 trace
= fItemData
.fExpandedItems
[idx
].fEntry
;
1136 * Retrieve the index of the currently selected item
1140 public int getSelectedIndex() {
1142 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1143 Item item
= fItemData
.fExpandedItems
[i
];
1144 if (item
.fSelected
) {
1152 boolean toggle(int idx
) {
1153 boolean toggled
= false;
1154 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1155 Item item
= fItemData
.fExpandedItems
[idx
];
1156 if (item
.fHasChildren
) {
1157 item
.fExpanded
= !item
.fExpanded
;
1158 fItemData
.updateExpandedItems();
1161 fireTreeEvent(item
.fEntry
, item
.fExpanded
);
1168 * Gets the index of the item at the given location.
1172 * @return the index of the item at the given location, of -1 if none.
1174 protected int getItemIndexAtY(int y
) {
1179 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1180 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1188 boolean isOverSplitLine(int x
) {
1189 if (x
< 0 || null == fTimeProvider
) {
1192 int nameWidth
= fTimeProvider
.getNameSpace();
1193 return Math
.abs(x
- nameWidth
) < SNAP_WIDTH
;
1197 * Gets the {@link ITimeGraphEntry} at the given location.
1200 * a point in the widget
1201 * @return the {@link ITimeGraphEntry} at this point, or <code>null</code>
1204 protected ITimeGraphEntry
getEntry(Point pt
) {
1205 int idx
= getItemIndexAtY(pt
.y
);
1206 return idx
>= 0 ? fItemData
.fExpandedItems
[idx
].fEntry
: null;
1210 * Return the arrow event closest to the given point that is no further than
1211 * a maximum distance.
1214 * a point in the widget
1215 * @return The closest arrow event, or null if there is none close enough.
1217 protected ILinkEvent
getArrow(Point pt
) {
1221 ILinkEvent linkEvent
= null;
1222 double minDistance
= Double
.MAX_VALUE
;
1223 for (ILinkEvent event
: fItemData
.fLinks
) {
1224 Rectangle rect
= getArrowRectangle(new Rectangle(0, 0, 0, 0), event
);
1228 int x2
= x1
+ rect
.width
;
1229 int y2
= y1
+ rect
.height
;
1230 double d
= Utils
.distance(pt
.x
, pt
.y
, x1
, y1
, x2
, y2
);
1231 if (minDistance
> d
) {
1237 if (minDistance
<= ARROW_HOVER_MAX_DIST
) {
1244 public int getXForTime(long time
) {
1245 if (null == fTimeProvider
) {
1248 long time0
= fTimeProvider
.getTime0();
1249 long time1
= fTimeProvider
.getTime1();
1250 int width
= getSize().x
;
1251 int nameSpace
= fTimeProvider
.getNameSpace();
1252 double pixelsPerNanoSec
= (width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1253 int x
= getBounds().x
+ nameSpace
+ (int) ((time
- time0
) * pixelsPerNanoSec
);
1258 public long getTimeAtX(int coord
) {
1259 if (null == fTimeProvider
) {
1263 Point size
= getSize();
1264 long time0
= fTimeProvider
.getTime0();
1265 long time1
= fTimeProvider
.getTime1();
1266 int nameWidth
= fTimeProvider
.getNameSpace();
1267 final int x
= coord
- nameWidth
;
1268 int timeWidth
= size
.x
- nameWidth
- RIGHT_MARGIN
;
1269 if (x
>= 0 && size
.x
>= nameWidth
) {
1270 if (time1
- time0
> timeWidth
) {
1271 // nanosecond smaller than one pixel: use the first integer nanosecond of this pixel's time range
1272 hitTime
= time0
+ (long) Math
.ceil((time1
- time0
) * ((double) x
/ timeWidth
));
1274 // nanosecond greater than one pixel: use the nanosecond that covers this pixel start position
1275 hitTime
= time0
+ (long) Math
.floor((time1
- time0
) * ((double) x
/ timeWidth
));
1281 void selectItem(int idx
, boolean addSelection
) {
1282 boolean changed
= false;
1284 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
1285 Item item
= fItemData
.fExpandedItems
[idx
];
1286 changed
= !item
.fSelected
;
1287 item
.fSelected
= true;
1290 for (int i
= 0; i
< fItemData
.fExpandedItems
.length
; i
++) {
1291 Item item
= fItemData
.fExpandedItems
[i
];
1292 if ((i
== idx
&& !item
.fSelected
) || (idx
== -1 && item
.fSelected
)) {
1295 item
.fSelected
= i
== idx
;
1298 changed
|= ensureVisibleItem(idx
, true);
1305 * Callback for item selection
1308 * The entry matching the trace
1309 * @param addSelection
1310 * If the selection is added or removed
1312 public void selectItem(ITimeGraphEntry trace
, boolean addSelection
) {
1313 int idx
= fItemData
.findItemIndex(trace
);
1314 selectItem(idx
, addSelection
);
1318 * Retrieve the number of entries shown per page.
1322 public int countPerPage() {
1323 int height
= getSize().y
;
1326 for (int idx
= fTopIndex
; idx
< fItemData
.fExpandedItems
.length
; idx
++) {
1327 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1328 if (ySum
>= height
) {
1333 for (int idx
= fTopIndex
- 1; idx
>= 0; idx
--) {
1334 ySum
+= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1335 if (ySum
>= height
) {
1344 * Get the index of the top element
1348 public int getTopIndex() {
1353 * Get the number of expanded (visible) items
1355 * @return The count of expanded (visible) items
1357 public int getExpandedElementCount() {
1358 return fItemData
.fExpandedItems
.length
;
1362 * Get an array of all expanded (visible) elements
1364 * @return The expanded (visible) elements
1366 public ITimeGraphEntry
[] getExpandedElements() {
1367 ArrayList
<ITimeGraphEntry
> elements
= new ArrayList
<>();
1368 for (Item item
: fItemData
.fExpandedItems
) {
1369 elements
.add(item
.fEntry
);
1371 return elements
.toArray(new ITimeGraphEntry
[0]);
1374 Rectangle
getNameRect(Rectangle bounds
, int idx
, int nameWidth
) {
1375 Rectangle rect
= getItemRect(bounds
, idx
);
1376 rect
.width
= nameWidth
;
1380 Rectangle
getStatesRect(Rectangle bounds
, int idx
, int nameWidth
) {
1381 Rectangle rect
= getItemRect(bounds
, idx
);
1382 rect
.x
+= nameWidth
;
1383 rect
.width
-= nameWidth
;
1387 Rectangle
getItemRect(Rectangle bounds
, int idx
) {
1389 if (idx
>= fTopIndex
) {
1390 for (int i
= fTopIndex
; i
< idx
; i
++) {
1391 ySum
+= fItemData
.fExpandedItems
[i
].fItemHeight
;
1394 for (int i
= fTopIndex
- 1; i
>= idx
; i
--) {
1395 ySum
-= fItemData
.fExpandedItems
[i
].fItemHeight
;
1398 int y
= bounds
.y
+ ySum
;
1399 int height
= fItemData
.fExpandedItems
[idx
].fItemHeight
;
1400 return new Rectangle(bounds
.x
, y
, bounds
.width
, height
);
1404 void paint(Rectangle bounds
, PaintEvent e
) {
1407 if (bounds
.width
< 2 || bounds
.height
< 2 || null == fTimeProvider
) {
1411 fIdealNameSpace
= 0;
1412 int nameSpace
= fTimeProvider
.getNameSpace();
1414 // draw the background layer
1415 drawBackground(bounds
, nameSpace
, gc
);
1417 // draw the grid lines
1418 drawGridLines(bounds
, gc
);
1420 // draw the background markers
1421 drawMarkers(bounds
, fTimeProvider
, fMarkers
, false, nameSpace
, gc
);
1424 drawItems(bounds
, fTimeProvider
, fItemData
.fExpandedItems
, fTopIndex
, nameSpace
, gc
);
1426 // draw the foreground markers
1427 drawMarkers(bounds
, fTimeProvider
, fMarkers
, true, nameSpace
, gc
);
1429 // draw the links (arrows)
1430 drawLinks(bounds
, fTimeProvider
, fItemData
.fLinks
, nameSpace
, gc
);
1432 fTimeGraphProvider
.postDrawControl(bounds
, gc
);
1434 int alpha
= gc
.getAlpha();
1437 long time0
= fTimeProvider
.getTime0();
1438 long time1
= fTimeProvider
.getTime1();
1439 long selectionBegin
= fTimeProvider
.getSelectionBegin();
1440 long selectionEnd
= fTimeProvider
.getSelectionEnd();
1441 double pixelsPerNanoSec
= (bounds
.width
- nameSpace
<= RIGHT_MARGIN
) ?
0 : (double) (bounds
.width
- nameSpace
- RIGHT_MARGIN
) / (time1
- time0
);
1442 int x0
= bounds
.x
+ nameSpace
+ (int) ((selectionBegin
- time0
) * pixelsPerNanoSec
);
1443 int x1
= bounds
.x
+ nameSpace
+ (int) ((selectionEnd
- time0
) * pixelsPerNanoSec
);
1445 // draw selection lines
1446 if (fDragState
!= DRAG_SELECTION
) {
1447 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1448 if (x0
>= nameSpace
&& x0
< bounds
.x
+ bounds
.width
) {
1449 gc
.drawLine(x0
, bounds
.y
, x0
, bounds
.y
+ bounds
.height
);
1452 if (x1
>= nameSpace
&& x1
< bounds
.x
+ bounds
.width
) {
1453 gc
.drawLine(x1
, bounds
.y
, x1
, bounds
.y
+ bounds
.height
);
1458 // draw selection background
1459 if (selectionBegin
!= 0 && selectionEnd
!= 0 && fDragState
!= DRAG_SELECTION
) {
1460 x0
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x0
));
1461 x1
= Math
.max(nameSpace
, Math
.min(bounds
.x
+ bounds
.width
, x1
));
1462 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1464 gc
.fillRectangle(new Rectangle(x0
+ 1, bounds
.y
, x1
- x0
- 1, bounds
.height
));
1465 } else if (x0
- x1
> 1) {
1466 gc
.fillRectangle(new Rectangle(x1
+ 1, bounds
.y
, x0
- x1
- 1, bounds
.height
));
1470 // draw drag selection background
1471 if (fDragState
== DRAG_ZOOM
|| fDragState
== DRAG_SELECTION
) {
1472 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1473 if (fDragX0
< fDragX
) {
1474 gc
.fillRectangle(new Rectangle(fDragX0
, bounds
.y
, fDragX
- fDragX0
, bounds
.height
));
1475 } else if (fDragX0
> fDragX
) {
1476 gc
.fillRectangle(new Rectangle(fDragX
, bounds
.y
, fDragX0
- fDragX
, bounds
.height
));
1481 if (DRAG_SPLIT_LINE
== fDragState
) {
1482 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.BLACK
));
1483 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1484 } else if (DRAG_ZOOM
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1485 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.TOOL_FOREGROUND
));
1486 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1487 if (fDragX
!= fDragX0
) {
1488 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1490 } else if (DRAG_SELECTION
== fDragState
&& Math
.max(fDragX
, fDragX0
) > nameSpace
) {
1491 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.SELECTED_TIME
));
1492 gc
.drawLine(fDragX0
, bounds
.y
, fDragX0
, bounds
.y
+ bounds
.height
- 1);
1493 if (fDragX
!= fDragX0
) {
1494 gc
.drawLine(fDragX
, bounds
.y
, fDragX
, bounds
.y
+ bounds
.height
- 1);
1496 } else if (DRAG_NONE
== fDragState
&& fMouseOverSplitLine
&& fTimeProvider
.getNameSpace() > 0) {
1497 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.RED
));
1498 gc
.drawLine(bounds
.x
+ nameSpace
, bounds
.y
, bounds
.x
+ nameSpace
, bounds
.y
+ bounds
.height
- 1);
1505 * Draw the background layer. Fills the background of the control's name
1506 * space and states space, updates the background of items if necessary,
1507 * and draws the item's name text and middle line.
1510 * The bounds of the control
1512 * The name space width
1517 protected void drawBackground(Rectangle bounds
, int nameSpace
, GC gc
) {
1518 // draw empty name space background
1519 gc
.setBackground(getColorScheme().getBkColor(false, false, true));
1520 drawBackground(gc
, bounds
.x
, bounds
.y
, nameSpace
, bounds
.height
);
1522 // draw empty states space background
1523 gc
.setBackground(getColorScheme().getColor(TimeGraphColorScheme
.BACKGROUND
));
1524 drawBackground(gc
, bounds
.x
+ nameSpace
, bounds
.y
, bounds
.width
- nameSpace
, bounds
.height
);
1526 for (int i
= fTopIndex
; i
< fItemData
.fExpandedItems
.length
; i
++) {
1527 Rectangle itemRect
= getItemRect(bounds
, i
);
1528 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1531 Item item
= fItemData
.fExpandedItems
[i
];
1532 // draw the background of selected item and items with no time events
1533 if (! item
.fEntry
.hasTimeEvents()) {
1534 gc
.setBackground(getColorScheme().getBkColorGroup(item
.fSelected
, fIsInFocus
));
1535 gc
.fillRectangle(itemRect
);
1536 } else if (item
.fSelected
) {
1537 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, true));
1538 gc
.fillRectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1539 gc
.setBackground(getColorScheme().getBkColor(true, fIsInFocus
, false));
1540 gc
.fillRectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1542 // draw the name and middle line
1543 if (! item
.fEntry
.hasTimeEvents()) {
1544 drawName(item
, itemRect
, gc
);
1546 Rectangle nameRect
= new Rectangle(itemRect
.x
, itemRect
.y
, nameSpace
, itemRect
.height
);
1547 drawName(item
, nameRect
, gc
);
1548 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1549 drawMidLine(rect
, gc
);
1555 * Draw the grid lines
1558 * The bounds of the control
1563 public void drawGridLines(Rectangle bounds
, GC gc
) {
1564 if (!fGridLinesVisible
) {
1567 gc
.setForeground(fGridLineColor
);
1568 gc
.setAlpha(fGridLineColor
.getAlpha());
1569 for (int x
: fTimeGraphScale
.getTickList()) {
1570 gc
.drawLine(x
, bounds
.y
, x
, bounds
.y
+ bounds
.height
);
1579 * The rectangle of the area
1580 * @param timeProvider
1583 * The list of markers
1585 * true to draw the foreground markers, false otherwise
1587 * The width reserved for the names
1589 * Reference to the SWT GC object
1592 protected void drawMarkers(Rectangle bounds
, ITimeDataProvider timeProvider
, List
<IMarkerEvent
> markers
, boolean foreground
, int nameSpace
, GC gc
) {
1593 if (!fMarkersVisible
|| markers
== null || markers
.isEmpty()) {
1596 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1597 /* the list can grow concurrently but cannot shrink */
1598 for (int i
= 0; i
< markers
.size(); i
++) {
1599 IMarkerEvent marker
= markers
.get(i
);
1600 if (marker
.isForeground() == foreground
) {
1601 drawMarker(marker
, bounds
, timeProvider
, nameSpace
, gc
);
1604 gc
.setClipping((Rectangle
) null);
1608 * Draw a single marker
1613 * The bounds of the control
1614 * @param timeProvider
1617 * The width reserved for the name
1619 * Reference to the SWT GC object
1622 protected void drawMarker(IMarkerEvent marker
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1623 Rectangle rect
= Utils
.clone(bounds
);
1624 if (marker
.getEntry() != null) {
1625 int index
= fItemData
.findItemIndex(marker
.getEntry());
1629 rect
= getStatesRect(bounds
, index
, nameSpace
);
1630 if (rect
.y
< 0 || rect
.y
> bounds
.height
) {
1634 int x0
= getXForTime(marker
.getTime());
1635 int x1
= getXForTime(marker
.getTime() + marker
.getDuration());
1636 if (x0
> bounds
.width
|| x1
< nameSpace
) {
1639 rect
.x
= Math
.max(nameSpace
, Math
.min(bounds
.width
, x0
));
1640 rect
.width
= Math
.max(1, Math
.min(bounds
.width
, x1
) - rect
.x
);
1642 gc
.setBackground(marker
.getColor());
1643 gc
.setAlpha(marker
.getColor().getAlpha());
1644 gc
.fillRectangle(rect
);
1646 String label
= marker
.getLabel();
1647 if (label
!= null && marker
.getEntry() != null) {
1648 label
= label
.substring(0, Math
.min(label
.indexOf('\n') != -1 ? label
.indexOf('\n') : label
.length(), MAX_LABEL_LENGTH
));
1649 gc
.setForeground(marker
.getColor());
1650 Utils
.drawText(gc
, label
, rect
.x
- gc
.textExtent(label
).x
, rect
.y
, true);
1655 * Draw many items at once
1658 * The bounds of the control
1659 * @param timeProvider
1662 * The array items to draw
1664 * The index of the first element to draw
1666 * The name space width
1670 public void drawItems(Rectangle bounds
, ITimeDataProvider timeProvider
,
1671 Item
[] items
, int topIndex
, int nameSpace
, GC gc
) {
1672 for (int i
= topIndex
; i
< items
.length
; i
++) {
1673 Item item
= items
[i
];
1674 drawItem(item
, bounds
, timeProvider
, i
, nameSpace
, gc
);
1684 * The bounds of the control
1685 * @param timeProvider
1688 * The expanded item index
1690 * The name space width
1694 protected void drawItem(Item item
, Rectangle bounds
, ITimeDataProvider timeProvider
, int i
, int nameSpace
, GC gc
) {
1695 Rectangle itemRect
= getItemRect(bounds
, i
);
1696 if (itemRect
.y
>= bounds
.y
+ bounds
.height
) {
1700 ITimeGraphEntry entry
= item
.fEntry
;
1701 long time0
= timeProvider
.getTime0();
1702 long time1
= timeProvider
.getTime1();
1703 long selectedTime
= fTimeProvider
.getSelectionEnd();
1705 Rectangle rect
= new Rectangle(nameSpace
, itemRect
.y
, itemRect
.width
- nameSpace
, itemRect
.height
);
1706 if (rect
.isEmpty() || (time1
<= time0
)) {
1707 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1711 boolean selected
= item
.fSelected
;
1712 // K pixels per second
1713 double pixelsPerNanoSec
= (rect
.width
<= RIGHT_MARGIN
) ?
0 : (double) (rect
.width
- RIGHT_MARGIN
) / (time1
- time0
);
1715 if (item
.fEntry
.hasTimeEvents()) {
1716 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1717 fillSpace(rect
, gc
, selected
);
1719 * State rectangle is smaller than item bounds. Use a margin height
1720 * of 3 pixels, keep at least 3 pixels for the state, but not more
1721 * than the item height. Favor the top margin for the remainder.
1723 int height
= Math
.min(rect
.height
, Math
.max(3, rect
.height
- 6));
1724 int margin
= (rect
.height
- height
+ 1) / 2;
1725 Rectangle stateRect
= new Rectangle(rect
.x
, rect
.y
+ margin
, rect
.width
, height
);
1727 long maxDuration
= (timeProvider
.getTimeSpace() == 0) ? Long
.MAX_VALUE
: 1 * (time1
- time0
) / timeProvider
.getTimeSpace();
1728 Iterator
<ITimeEvent
> iterator
= entry
.getTimeEventsIterator(time0
, time1
, maxDuration
);
1731 while (iterator
.hasNext()) {
1732 ITimeEvent event
= iterator
.next();
1733 int x
= rect
.x
+ (int) ((event
.getTime() - time0
) * pixelsPerNanoSec
);
1734 int xEnd
= rect
.x
+ (int) ((event
.getTime() + event
.getDuration() - time0
) * pixelsPerNanoSec
);
1735 if (x
>= rect
.x
+ rect
.width
|| xEnd
< rect
.x
) {
1736 // event is out of bounds
1739 xEnd
= Math
.min(rect
.x
+ rect
.width
, xEnd
);
1740 stateRect
.x
= Math
.max(rect
.x
, x
);
1741 stateRect
.width
= Math
.max(0, xEnd
- stateRect
.x
+ 1);
1742 if (stateRect
.x
== lastX
) {
1743 stateRect
.width
-= 1;
1744 if (stateRect
.width
> 0) {
1745 gc
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
));
1746 gc
.drawPoint(stateRect
.x
, stateRect
.y
- 2);
1750 boolean timeSelected
= selectedTime
>= event
.getTime() && selectedTime
< event
.getTime() + event
.getDuration();
1751 if (drawState(getColorScheme(), event
, stateRect
, gc
, selected
, timeSelected
)) {
1752 lastX
= stateRect
.x
;
1755 gc
.setClipping((Rectangle
) null);
1757 fTimeGraphProvider
.postDrawEntry(entry
, rect
, gc
);
1764 * The bounds of the control
1765 * @param timeProvider
1768 * The list of link events
1770 * The name space width
1774 public void drawLinks(Rectangle bounds
, ITimeDataProvider timeProvider
,
1775 List
<ILinkEvent
> links
, int nameSpace
, GC gc
) {
1779 gc
.setClipping(new Rectangle(nameSpace
, 0, bounds
.width
- nameSpace
, bounds
.height
));
1780 /* the list can grow concurrently but cannot shrink */
1781 for (int i
= 0; i
< links
.size(); i
++) {
1782 drawLink(links
.get(i
), bounds
, timeProvider
, nameSpace
, gc
);
1784 gc
.setClipping((Rectangle
) null);
1788 * Draws a link type event
1791 * The link event to draw
1793 * The bounds of the control
1794 * @param timeProvider
1797 * The name space width
1801 protected void drawLink(ILinkEvent event
, Rectangle bounds
, ITimeDataProvider timeProvider
, int nameSpace
, GC gc
) {
1802 drawArrow(getColorScheme(), event
, getArrowRectangle(bounds
, event
), gc
);
1805 private Rectangle
getArrowRectangle(Rectangle bounds
, ILinkEvent event
) {
1806 int srcIndex
= fItemData
.findItemIndex(event
.getEntry());
1807 int destIndex
= fItemData
.findItemIndex(event
.getDestinationEntry());
1809 if ((srcIndex
== -1) || (destIndex
== -1)) {
1813 Rectangle src
= getStatesRect(bounds
, srcIndex
, fTimeProvider
.getNameSpace());
1814 Rectangle dst
= getStatesRect(bounds
, destIndex
, fTimeProvider
.getNameSpace());
1816 int x0
= getXForTime(event
.getTime());
1817 int x1
= getXForTime(event
.getTime() + event
.getDuration());
1819 // limit the x-coordinates to prevent integer overflow in calculations
1820 // and also GC.drawLine doesn't draw properly with large coordinates
1821 final int limit
= Integer
.MAX_VALUE
/ 1024;
1822 x0
= Math
.max(-limit
, Math
.min(x0
, limit
));
1823 x1
= Math
.max(-limit
, Math
.min(x1
, limit
));
1825 int y0
= src
.y
+ src
.height
/ 2;
1826 int y1
= dst
.y
+ dst
.height
/ 2;
1827 return new Rectangle(x0
, y0
, x1
- x0
, y1
- y0
);
1836 * Time event for which we're drawing the arrow
1838 * The arrow rectangle
1841 * @return true if the arrow was drawn
1843 protected boolean drawArrow(TimeGraphColorScheme colors
, ITimeEvent event
,
1844 Rectangle rect
, GC gc
) {
1849 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
1853 boolean visible
= ((rect
.height
== 0) && (rect
.width
== 0)) ?
false : true;
1856 Color stateColor
= null;
1857 if (colorIdx
< fEventColorMap
.length
) {
1858 stateColor
= fEventColorMap
[colorIdx
];
1860 stateColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
1863 gc
.setForeground(stateColor
);
1864 gc
.setBackground(stateColor
);
1866 /* Draw the arrow */
1867 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
);
1868 drawArrowHead(rect
.x
, rect
.y
, rect
.x
+ rect
.width
, rect
.y
+ rect
.height
, gc
);
1871 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
1876 * @author Francis Giraldeau
1879 * http://stackoverflow.com/questions/3010803/draw-arrow-on-line-algorithm
1881 * The algorithm was taken from this site, not the code itself
1883 private static void drawArrowHead(int x0
, int y0
, int x1
, int y1
, GC gc
)
1886 double cos
= 0.9510;
1887 double sin
= 0.3090;
1888 long lenx
= x1
- x0
;
1889 long leny
= y1
- y0
;
1890 double len
= Math
.sqrt(lenx
* lenx
+ leny
* leny
);
1892 double dx
= factor
* lenx
/ len
;
1893 double dy
= factor
* leny
/ len
;
1894 int end1X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* -sin
)));
1895 int end1Y
= (int) Math
.round((y1
- (dx
* sin
+ dy
* cos
)));
1896 int end2X
= (int) Math
.round((x1
- (dx
* cos
+ dy
* sin
)));
1897 int end2Y
= (int) Math
.round((y1
- (dx
* -sin
+ dy
* cos
)));
1898 int[] arrow
= new int[] { x1
, y1
, end1X
, end1Y
, end2X
, end2Y
, x1
, y1
};
1899 gc
.fillPolygon(arrow
);
1903 * Draw the name of an item.
1908 * The bounds of the item's name space
1912 protected void drawName(Item item
, Rectangle bounds
, GC gc
) {
1913 boolean hasTimeEvents
= item
.fEntry
.hasTimeEvents();
1915 // No name to be drawn
1916 if (fTimeProvider
.getNameSpace() == 0) {
1920 int leftMargin
= MARGIN
+ item
.fLevel
* EXPAND_SIZE
;
1921 if (item
.fHasChildren
) {
1922 gc
.setForeground(getColorScheme().getFgColorGroup(false, false));
1923 gc
.setBackground(getColorScheme().getBkColor(false, false, false));
1924 Rectangle rect
= Utils
.clone(bounds
);
1925 rect
.x
+= leftMargin
;
1926 rect
.y
+= (bounds
.height
- EXPAND_SIZE
) / 2;
1927 rect
.width
= EXPAND_SIZE
;
1928 rect
.height
= EXPAND_SIZE
;
1929 gc
.fillRectangle(rect
);
1930 gc
.drawRectangle(rect
.x
, rect
.y
, rect
.width
- 1, rect
.height
- 1);
1931 int midy
= rect
.y
+ rect
.height
/ 2;
1932 gc
.drawLine(rect
.x
+ 2, midy
, rect
.x
+ rect
.width
- 3, midy
);
1933 if (!item
.fExpanded
) {
1934 int midx
= rect
.x
+ rect
.width
/ 2;
1935 gc
.drawLine(midx
, rect
.y
+ 2, midx
, rect
.y
+ rect
.height
- 3);
1938 leftMargin
+= EXPAND_SIZE
+ MARGIN
;
1940 Image img
= fTimeGraphProvider
.getItemImage(item
.fEntry
);
1943 int imgHeight
= img
.getImageData().height
;
1944 int imgWidth
= img
.getImageData().width
;
1946 int y
= bounds
.y
+ (bounds
.height
- imgHeight
) / 2;
1947 gc
.drawImage(img
, x
, y
);
1948 leftMargin
+= imgWidth
+ MARGIN
;
1950 String name
= item
.fName
;
1951 Point size
= gc
.stringExtent(name
);
1952 if (fIdealNameSpace
< leftMargin
+ size
.x
+ MARGIN
) {
1953 fIdealNameSpace
= leftMargin
+ size
.x
+ MARGIN
;
1955 if (hasTimeEvents
) {
1956 // cut long string with "..."
1957 int width
= bounds
.width
- leftMargin
;
1959 while (size
.x
> width
&& name
.length() > 1) {
1961 name
= name
.substring(0, name
.length() - 1);
1962 size
= gc
.stringExtent(name
+ "..."); //$NON-NLS-1$
1965 name
+= "..."; //$NON-NLS-1$
1968 Rectangle rect
= Utils
.clone(bounds
);
1969 rect
.x
+= leftMargin
;
1970 rect
.width
-= leftMargin
;
1972 if (rect
.width
> 0) {
1973 rect
.y
+= (bounds
.height
- gc
.stringExtent(name
).y
) / 2;
1974 gc
.setForeground(getColorScheme().getFgColor(item
.fSelected
, fIsInFocus
));
1975 int textWidth
= Utils
.drawText(gc
, name
, rect
, true);
1976 leftMargin
+= textWidth
+ MARGIN
;
1978 if (hasTimeEvents
) {
1980 rect
.x
= bounds
.x
+ leftMargin
;
1982 rect
.width
= bounds
.width
- rect
.x
;
1983 drawMidLine(rect
, gc
);
1989 * Draw the state (color fill)
1994 * Time event for which we're drawing the state
1996 * The state rectangle
2000 * Is this time event currently selected (so it appears
2002 * @param timeSelected
2003 * Is the timestamp currently selected
2004 * @return true if the state was drawn
2006 protected boolean drawState(TimeGraphColorScheme colors
, ITimeEvent event
,
2007 Rectangle rect
, GC gc
, boolean selected
, boolean timeSelected
) {
2009 int colorIdx
= fTimeGraphProvider
.getStateTableIndex(event
);
2010 if (colorIdx
< 0 && colorIdx
!= ITimeGraphPresentationProvider
.TRANSPARENT
) {
2013 boolean visible
= rect
.width
== 0 ?
false : true;
2014 rect
.width
= Math
.max(1, rect
.width
);
2015 Color black
= Display
.getDefault().getSystemColor(SWT
.COLOR_BLACK
);
2016 gc
.setForeground(black
);
2018 if (colorIdx
== ITimeGraphPresentationProvider
.TRANSPARENT
) {
2020 // Only draw the top and bottom borders
2021 gc
.drawLine(rect
.x
, rect
.y
, rect
.x
+ rect
.width
- 1, rect
.y
);
2022 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
- 1, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
- 1);
2023 if (rect
.width
== 1) {
2024 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2027 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2030 Color stateColor
= null;
2031 if (colorIdx
< fEventColorMap
.length
) {
2032 stateColor
= fEventColorMap
[colorIdx
];
2037 boolean reallySelected
= timeSelected
&& selected
;
2038 // fill all rect area
2039 gc
.setBackground(stateColor
);
2041 gc
.fillRectangle(rect
);
2042 } else if (fBlendSubPixelEvents
) {
2044 gc
.fillRectangle(rect
);
2048 if (reallySelected
) {
2049 gc
.drawLine(rect
.x
, rect
.y
- 1, rect
.x
+ rect
.width
- 1, rect
.y
- 1);
2050 gc
.drawLine(rect
.x
, rect
.y
+ rect
.height
, rect
.x
+ rect
.width
- 1, rect
.y
+ rect
.height
);
2053 gc
.drawPoint(rect
.x
, rect
.y
- 2);
2055 fTimeGraphProvider
.postDrawEvent(event
, rect
, gc
);
2060 * Fill an item's states rectangle
2063 * The states rectangle
2067 * true if the item is selected
2069 protected void fillSpace(Rectangle rect
, GC gc
, boolean selected
) {
2070 /* Nothing to draw */
2074 * Draw a line at the middle height of a rectangle
2081 private void drawMidLine(Rectangle rect
, GC gc
) {
2082 gc
.setForeground(getColorScheme().getColor(TimeGraphColorScheme
.MID_LINE
));
2083 int midy
= rect
.y
+ rect
.height
/ 2;
2084 gc
.drawLine(rect
.x
, midy
, rect
.x
+ rect
.width
, midy
);
2088 public void keyTraversed(TraverseEvent e
) {
2089 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {
2095 public void keyPressed(KeyEvent e
) {
2097 if (fItemData
.fExpandedItems
.length
== 0) {
2100 if (SWT
.HOME
== e
.keyCode
) {
2102 } else if (SWT
.END
== e
.keyCode
) {
2103 idx
= fItemData
.fExpandedItems
.length
- 1;
2104 } else if (SWT
.ARROW_DOWN
== e
.keyCode
) {
2105 idx
= getSelectedIndex();
2108 } else if (idx
< fItemData
.fExpandedItems
.length
- 1) {
2111 } else if (SWT
.ARROW_UP
== e
.keyCode
) {
2112 idx
= getSelectedIndex();
2115 } else if (idx
> 0) {
2118 } else if (SWT
.ARROW_LEFT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2119 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2120 selectPrevEvent(extend
);
2121 } else if (SWT
.ARROW_RIGHT
== e
.keyCode
&& fDragState
== DRAG_NONE
) {
2122 boolean extend
= (e
.stateMask
& SWT
.SHIFT
) != 0;
2123 selectNextEvent(extend
);
2124 } else if (SWT
.PAGE_DOWN
== e
.keyCode
) {
2125 int page
= countPerPage();
2126 idx
= getSelectedIndex();
2131 if (idx
>= fItemData
.fExpandedItems
.length
) {
2132 idx
= fItemData
.fExpandedItems
.length
- 1;
2134 } else if (SWT
.PAGE_UP
== e
.keyCode
) {
2135 int page
= countPerPage();
2136 idx
= getSelectedIndex();
2144 } else if (SWT
.CR
== e
.keyCode
) {
2145 idx
= getSelectedIndex();
2147 if (fItemData
.fExpandedItems
[idx
].fHasChildren
) {
2150 fireDefaultSelection();
2156 selectItem(idx
, false);
2157 fireSelectionChanged();
2159 int x
= toControl(e
.display
.getCursorLocation()).x
;
2160 updateCursor(x
, e
.stateMask
| e
.keyCode
);
2164 public void keyReleased(KeyEvent e
) {
2165 int x
= toControl(e
.display
.getCursorLocation()).x
;
2166 updateCursor(x
, e
.stateMask
& ~e
.keyCode
);
2170 public void focusGained(FocusEvent e
) {
2173 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2177 public void focusLost(FocusEvent e
) {
2179 if (DRAG_NONE
!= fDragState
) {
2181 fDragState
= DRAG_NONE
;
2184 updateStatusLine(NO_STATUS
);
2188 * @return If the current view is focused
2190 public boolean isInFocus() {
2195 * Provide the possibility to control the wait cursor externally e.g. data
2196 * requests in progress
2198 * @param waitInd Should we wait indefinitely?
2200 public void waitCursor(boolean waitInd
) {
2201 // Update cursor as indicated
2203 setCursor(fWaitCursor
);
2209 private void updateCursor(int x
, int stateMask
) {
2210 // if Wait cursor not active, check for the need to change the cursor
2211 if (getCursor() == fWaitCursor
) {
2214 Cursor cursor
= null;
2215 if (fDragState
== DRAG_SPLIT_LINE
) {
2216 } else if (fDragState
== DRAG_SELECTION
) {
2217 cursor
= fResizeCursor
;
2218 } else if (fDragState
== DRAG_TRACE_ITEM
) {
2219 cursor
= fDragCursor
;
2220 } else if (fDragState
== DRAG_ZOOM
) {
2221 cursor
= fZoomCursor
;
2222 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2223 cursor
= fDragCursor
;
2224 } else if ((stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2225 cursor
= fResizeCursor
;
2226 } else if (!isOverSplitLine(x
)) {
2227 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2228 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2229 int xBegin
= getXForTime(selectionBegin
);
2230 int xEnd
= getXForTime(selectionEnd
);
2231 if (Math
.abs(x
- xBegin
) < SNAP_WIDTH
|| Math
.abs(x
- xEnd
) < SNAP_WIDTH
) {
2232 cursor
= fResizeCursor
;
2235 if (getCursor() != cursor
) {
2241 * Update the status line following a change of selection.
2245 public void updateStatusLine() {
2246 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2249 private void updateStatusLine(int x
) {
2250 // use the time provider of the time graph scale for the status line
2251 ITimeDataProvider tdp
= fTimeGraphScale
.getTimeProvider();
2252 if (fStatusLineManager
== null || null == tdp
||
2253 tdp
.getTime0() == tdp
.getTime1()) {
2256 TimeFormat tf
= tdp
.getTimeFormat();
2257 Resolution res
= Resolution
.NANOSEC
;
2258 StringBuilder message
= new StringBuilder();
2259 if ((x
>= 0 || x
== STATUS_WITHOUT_CURSOR_TIME
) && fDragState
== DRAG_NONE
) {
2260 if (x
!= STATUS_WITHOUT_CURSOR_TIME
) {
2261 long time
= getTimeAtX(x
);
2263 if (tdp
instanceof ITimeDataProviderConverter
) {
2264 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2266 message
.append(NLS
.bind("T: {0}{1} ", //$NON-NLS-1$
2268 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2269 Utils
.formatTime(time
, tf
, res
)
2273 long selectionBegin
= tdp
.getSelectionBegin();
2274 long selectionEnd
= tdp
.getSelectionEnd();
2275 message
.append(NLS
.bind("T1: {0}{1}", //$NON-NLS-1$
2277 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionBegin
) + ' ' : "", //$NON-NLS-1$
2278 Utils
.formatTime(selectionBegin
, tf
, res
)
2280 if (selectionBegin
!= selectionEnd
) {
2281 message
.append(NLS
.bind(" T2: {0}{1} \u0394: {2}", //$NON-NLS-1$
2283 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(selectionEnd
) + ' ' : "", //$NON-NLS-1$
2284 Utils
.formatTime(selectionEnd
, tf
, res
),
2285 Utils
.formatDelta(selectionEnd
- selectionBegin
, tf
, res
)
2288 } else if (fDragState
== DRAG_SELECTION
|| fDragState
== DRAG_ZOOM
) {
2289 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2290 long time
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2291 if (tdp
instanceof ITimeDataProviderConverter
) {
2292 time0
= ((ITimeDataProviderConverter
) tdp
).convertTime(time0
);
2293 time
= ((ITimeDataProviderConverter
) tdp
).convertTime(time
);
2295 message
.append(NLS
.bind("T1: {0}{1} T2: {2}{3} \u0394: {4}", //$NON-NLS-1$
2297 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time0
) + ' ' : "", //$NON-NLS-1$
2298 Utils
.formatTime(time0
, tf
, res
),
2299 tf
== TimeFormat
.CALENDAR ? Utils
.formatDate(time
) + ' ' : "", //$NON-NLS-1$
2300 Utils
.formatTime(time
, tf
, res
),
2301 Utils
.formatDelta(time
- time0
, tf
, res
)
2304 fStatusLineManager
.setMessage(message
.toString());
2308 public void mouseMove(MouseEvent e
) {
2309 if (null == fTimeProvider
) {
2312 Point size
= getSize();
2313 if (DRAG_TRACE_ITEM
== fDragState
) {
2314 int nameWidth
= fTimeProvider
.getNameSpace();
2315 if (e
.x
> nameWidth
&& size
.x
> nameWidth
&& fDragX
!= e
.x
) {
2317 double pixelsPerNanoSec
= (size
.x
- nameWidth
<= RIGHT_MARGIN
) ?
0 : (double) (size
.x
- nameWidth
- RIGHT_MARGIN
) / (fTime1bak
- fTime0bak
);
2318 long timeDelta
= (long) ((pixelsPerNanoSec
== 0) ?
0 : ((fDragX
- fDragX0
) / pixelsPerNanoSec
));
2319 long time1
= fTime1bak
- timeDelta
;
2320 long maxTime
= fTimeProvider
.getMaxTime();
2321 if (time1
> maxTime
) {
2324 long time0
= time1
- (fTime1bak
- fTime0bak
);
2325 if (time0
< fTimeProvider
.getMinTime()) {
2326 time0
= fTimeProvider
.getMinTime();
2327 time1
= time0
+ (fTime1bak
- fTime0bak
);
2329 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2331 } else if (DRAG_SPLIT_LINE
== fDragState
) {
2333 fTimeProvider
.setNameSpace(e
.x
);
2334 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2335 } else if (DRAG_SELECTION
== fDragState
) {
2336 if (fDragBeginMarker
) {
2337 fDragX0
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2339 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2342 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2343 fireDragSelectionChanged(getTimeAtX(fDragX0
), getTimeAtX(fDragX
));
2344 } else if (DRAG_ZOOM
== fDragState
) {
2345 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), size
.x
- RIGHT_MARGIN
);
2347 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2348 } else if (DRAG_NONE
== fDragState
) {
2349 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2350 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2353 fMouseOverSplitLine
= mouseOverSplitLine
;
2355 updateCursor(e
.x
, e
.stateMask
);
2356 updateStatusLine(e
.x
);
2360 public void mouseDoubleClick(MouseEvent e
) {
2361 if (null == fTimeProvider
) {
2364 if (1 == e
.button
&& (e
.stateMask
& SWT
.BUTTON_MASK
) == 0) {
2365 if (isOverSplitLine(e
.x
) && fTimeProvider
.getNameSpace() != 0) {
2366 fTimeProvider
.setNameSpace(fIdealNameSpace
);
2367 boolean mouseOverSplitLine
= isOverSplitLine(e
.x
);
2368 if (fMouseOverSplitLine
!= mouseOverSplitLine
) {
2371 fMouseOverSplitLine
= mouseOverSplitLine
;
2372 TmfSignalManager
.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
2375 int idx
= getItemIndexAtY(e
.y
);
2377 selectItem(idx
, false);
2378 fireDefaultSelection();
2384 public void mouseDown(MouseEvent e
) {
2385 if (fDragState
!= DRAG_NONE
|| null == fTimeProvider
||
2386 fTimeProvider
.getTime0() == fTimeProvider
.getTime1() ||
2387 getSize().x
- fTimeProvider
.getNameSpace() <= 0) {
2391 if (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == 0) {
2392 int nameSpace
= fTimeProvider
.getNameSpace();
2393 if (nameSpace
!= 0 && isOverSplitLine(e
.x
)) {
2394 fDragState
= DRAG_SPLIT_LINE
;
2395 fDragButton
= e
.button
;
2398 fTime0bak
= fTimeProvider
.getTime0();
2399 fTime1bak
= fTimeProvider
.getTime1();
2401 updateCursor(e
.x
, e
.stateMask
);
2405 if (1 == e
.button
&& ((e
.stateMask
& SWT
.MODIFIER_MASK
) == 0 || (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
)) {
2406 int nameSpace
= fTimeProvider
.getNameSpace();
2407 idx
= getItemIndexAtY(e
.y
);
2409 Item item
= fItemData
.fExpandedItems
[idx
];
2410 if (item
.fHasChildren
&& e
.x
< nameSpace
&& e
.x
< MARGIN
+ (item
.fLevel
+ 1) * EXPAND_SIZE
) {
2414 selectItem(idx
, false);
2415 fireSelectionChanged();
2417 selectItem(idx
, false); // clear selection
2418 fireSelectionChanged();
2420 long hitTime
= getTimeAtX(e
.x
);
2424 fDragState
= DRAG_SELECTION
;
2425 fDragBeginMarker
= false;
2426 fDragButton
= e
.button
;
2429 fDragTime0
= getTimeAtX(fDragX0
);
2430 long selectionBegin
= fTimeProvider
.getSelectionBegin();
2431 long selectionEnd
= fTimeProvider
.getSelectionEnd();
2432 int xBegin
= getXForTime(selectionBegin
);
2433 int xEnd
= getXForTime(selectionEnd
);
2434 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.SHIFT
) {
2435 long time
= getTimeAtX(e
.x
);
2436 if (Math
.abs(time
- selectionBegin
) < Math
.abs(time
- selectionEnd
)) {
2437 fDragBeginMarker
= true;
2440 fDragTime0
= selectionEnd
;
2443 fDragTime0
= selectionBegin
;
2446 long time
= getTimeAtX(e
.x
);
2447 if (Math
.abs(e
.x
- xBegin
) < SNAP_WIDTH
&& Math
.abs(time
- selectionBegin
) <= Math
.abs(time
- selectionEnd
)) {
2448 fDragBeginMarker
= true;
2451 fDragTime0
= selectionEnd
;
2452 } else if (Math
.abs(e
.x
- xEnd
) < SNAP_WIDTH
&& Math
.abs(time
- selectionEnd
) <= Math
.abs(time
- selectionBegin
)) {
2454 fDragTime0
= selectionBegin
;
2457 fTime0bak
= fTimeProvider
.getTime0();
2458 fTime1bak
= fTimeProvider
.getTime1();
2460 updateCursor(e
.x
, e
.stateMask
);
2461 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2463 } else if (2 == e
.button
|| (1 == e
.button
&& (e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
)) {
2464 long hitTime
= getTimeAtX(e
.x
);
2467 fDragState
= DRAG_TRACE_ITEM
;
2468 fDragButton
= e
.button
;
2471 fTime0bak
= fTimeProvider
.getTime0();
2472 fTime1bak
= fTimeProvider
.getTime1();
2473 updateCursor(e
.x
, e
.stateMask
);
2475 } else if (3 == e
.button
) {
2477 fDragX
= Math
.min(Math
.max(e
.x
, fTimeProvider
.getNameSpace()), getSize().x
- RIGHT_MARGIN
);
2479 fDragTime0
= getTimeAtX(fDragX0
);
2480 fDragState
= DRAG_ZOOM
;
2481 fDragButton
= e
.button
;
2483 updateCursor(e
.x
, e
.stateMask
);
2484 fTimeGraphScale
.setDragRange(fDragX0
, fDragX
);
2489 public void mouseUp(MouseEvent e
) {
2490 if (fPendingMenuDetectEvent
!= null && e
.button
== 3) {
2491 menuDetected(fPendingMenuDetectEvent
);
2493 if (DRAG_NONE
!= fDragState
) {
2495 if (e
.button
== fDragButton
&& DRAG_TRACE_ITEM
== fDragState
) {
2496 if (fDragX
!= fDragX0
) {
2497 fTimeProvider
.notifyStartFinishTime();
2499 fDragState
= DRAG_NONE
;
2500 } else if (e
.button
== fDragButton
&& DRAG_SPLIT_LINE
== fDragState
) {
2501 fDragState
= DRAG_NONE
;
2503 } else if (e
.button
== fDragButton
&& DRAG_SELECTION
== fDragState
) {
2504 if (fDragX
== fDragX0
) { // click without selecting anything
2505 long time
= getTimeAtX(e
.x
);
2506 fTimeProvider
.setSelectedTimeNotify(time
, false);
2508 long time0
= fDragBeginMarker ?
getTimeAtX(fDragX0
) : fDragTime0
;
2509 long time1
= fDragBeginMarker ? fDragTime0
: getTimeAtX(fDragX
);
2510 fTimeProvider
.setSelectionRangeNotify(time0
, time1
, false);
2512 fDragState
= DRAG_NONE
;
2514 fTimeGraphScale
.setDragRange(-1, -1);
2515 } else if (e
.button
== fDragButton
&& DRAG_ZOOM
== fDragState
) {
2516 int nameWidth
= fTimeProvider
.getNameSpace();
2517 if (Math
.max(fDragX
, fDragX0
) > nameWidth
&& fDragX
!= fDragX0
) {
2518 long time0
= getTimeAtX(fDragX0
);
2519 long time1
= getTimeAtX(fDragX
);
2520 if (time0
< time1
) {
2521 fTimeProvider
.setStartFinishTimeNotify(time0
, time1
);
2523 fTimeProvider
.setStartFinishTimeNotify(time1
, time0
);
2528 fDragState
= DRAG_NONE
;
2529 fTimeGraphScale
.setDragRange(-1, -1);
2532 updateCursor(e
.x
, e
.stateMask
);
2533 updateStatusLine(e
.x
);
2537 public void mouseEnter(MouseEvent e
) {
2541 public void mouseExit(MouseEvent e
) {
2542 if (fMouseOverSplitLine
) {
2543 fMouseOverSplitLine
= false;
2546 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME
);
2550 public void mouseHover(MouseEvent e
) {
2554 public void mouseScrolled(MouseEvent e
) {
2555 if (fDragState
!= DRAG_NONE
) {
2558 boolean zoomScroll
= false;
2559 boolean horizontalScroll
= false;
2560 Point p
= getParent().toControl(getDisplay().getCursorLocation());
2561 Point parentSize
= getParent().getSize();
2562 if (p
.x
>= 0 && p
.x
< parentSize
.x
&& p
.y
>= 0 && p
.y
< parentSize
.y
) {
2563 // over the parent control
2564 if (e
.x
> getSize().x
) {
2565 // over the vertical scroll bar
2567 } else if (e
.y
< 0) {
2568 // over the time scale
2570 } else if (e
.y
>= getSize().y
) {
2571 // over the horizontal scroll bar
2572 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2575 horizontalScroll
= true;
2578 if (e
.x
< fTimeProvider
.getNameSpace()) {
2579 // over the name space
2582 // over the state area
2583 if ((e
.stateMask
& SWT
.MODIFIER_MASK
) == SWT
.CTRL
) {
2584 // over the state area, CTRL pressed
2587 // over the state area, CTRL not pressed
2593 if (zoomScroll
&& fTimeProvider
.getTime0() != fTimeProvider
.getTime1()) {
2596 } else if (e
.count
< 0) {
2599 } else if (horizontalScroll
) {
2600 horizontalScroll(e
.count
> 0);
2602 setTopIndex(getTopIndex() - e
.count
);
2607 public void handleEvent(Event event
) {
2608 if (event
.type
== SWT
.MouseWheel
) {
2609 // prevent horizontal scrolling when the mouse wheel is used to
2610 // scroll vertically or zoom
2616 public int getBorderWidth() {
2617 return fBorderWidth
;
2621 * Set the border width
2623 * @param borderWidth
2626 public void setBorderWidth(int borderWidth
) {
2627 this.fBorderWidth
= borderWidth
;
2631 * @return The current height of the header row
2633 public int getHeaderHeight() {
2634 return fHeaderHeight
;
2638 * Set the height of the header row
2640 * @param headerHeight
2643 public void setHeaderHeight(int headerHeight
) {
2644 this.fHeaderHeight
= headerHeight
;
2648 * @return The default height of regular item rows
2650 public int getItemHeight() {
2651 return fGlobalItemHeight
;
2655 * Set the default height of regular item rows.
2660 public void setItemHeight(int rowHeight
) {
2661 this.fGlobalItemHeight
= rowHeight
;
2662 for (Item item
: fItemData
.fItems
) {
2663 item
.fItemHeight
= rowHeight
;
2668 * Set the height of a specific item. Overrides the default item height.
2671 * A time graph entry
2674 * @return true if the height is successfully stored, false otherwise
2676 public boolean setItemHeight(ITimeGraphEntry entry
, int rowHeight
) {
2677 Item item
= fItemData
.findItem(entry
);
2679 item
.fItemHeight
= rowHeight
;
2686 * Set the minimum item width
2688 * @param width The minimum width
2690 public void setMinimumItemWidth(int width
) {
2691 this.fMinimumItemWidth
= width
;
2695 * @return The minimum item width
2697 public int getMinimumItemWidth() {
2698 return fMinimumItemWidth
;
2702 * Set whether all time events with a duration shorter than one pixel should
2703 * be blended in. If false, only the first such time event will be drawn and
2704 * the subsequent time events in the same pixel will be discarded. The
2705 * default value is false.
2708 * true if sub-pixel events should be blended, false otherwise.
2711 public void setBlendSubPixelEvents(boolean blend
) {
2712 fBlendSubPixelEvents
= blend
;
2716 public void addSelectionChangedListener(ISelectionChangedListener listener
) {
2717 if (listener
!= null && !fSelectionChangedListeners
.contains(listener
)) {
2718 fSelectionChangedListeners
.add(listener
);
2723 public void removeSelectionChangedListener(ISelectionChangedListener listener
) {
2724 if (listener
!= null) {
2725 fSelectionChangedListeners
.remove(listener
);
2730 public void setSelection(ISelection selection
) {
2731 if (selection
instanceof TimeGraphSelection
) {
2732 TimeGraphSelection sel
= (TimeGraphSelection
) selection
;
2733 Object ob
= sel
.getFirstElement();
2734 if (ob
instanceof ITimeGraphEntry
) {
2735 ITimeGraphEntry trace
= (ITimeGraphEntry
) ob
;
2736 selectItem(trace
, false);
2743 * @param filter The filter object to be attached to the view
2745 public void addFilter(@NonNull ViewerFilter filter
) {
2746 if (!fFilters
.contains(filter
)) {
2747 fFilters
.add(filter
);
2752 * @param filter The filter object to be attached to the view
2754 public void removeFilter(@NonNull ViewerFilter filter
) {
2755 fFilters
.remove(filter
);
2759 * Returns this control's filters.
2761 * @return an array of viewer filters
2764 public @NonNull ViewerFilter
[] getFilters() {
2765 return Iterables
.toArray(fFilters
, ViewerFilter
.class);
2769 * Sets the filters, replacing any previous filters.
2772 * an array of viewer filters, or null
2775 public void setFilters(@NonNull ViewerFilter
[] filters
) {
2777 if (filters
!= null) {
2778 fFilters
.addAll(Arrays
.asList(filters
));
2783 public void colorSettingsChanged(StateItem
[] stateItems
) {
2784 /* Destroy previous colors from the resource manager */
2785 if (fEventColorMap
!= null) {
2786 for (Color color
: fEventColorMap
) {
2787 fResourceManager
.destroyColor(color
.getRGB());
2790 if (stateItems
!= null) {
2791 fEventColorMap
= new Color
[stateItems
.length
];
2792 for (int i
= 0; i
< stateItems
.length
; i
++) {
2793 fEventColorMap
[i
] = fResourceManager
.createColor(stateItems
[i
].getStateColor());
2796 fEventColorMap
= new Color
[] { };
2801 private class ItemData
{
2802 private Map
<ITimeGraphEntry
, Item
> fItemMap
= new LinkedHashMap
<>();
2803 private Item
[] fExpandedItems
= new Item
[0];
2804 private Item
[] fItems
= new Item
[0];
2805 private ITimeGraphEntry fRootEntries
[] = new ITimeGraphEntry
[0];
2806 private List
<ILinkEvent
> fLinks
= new ArrayList
<>();
2811 public Item
findItem(ITimeGraphEntry entry
) {
2812 return fItemMap
.get(entry
);
2815 public int findItemIndex(ITimeGraphEntry entry
) {
2816 Item item
= fItemMap
.get(entry
);
2820 return item
.fExpandedIndex
;
2823 public void refreshData() {
2824 ITimeGraphEntry selection
= getSelectedTrace();
2825 Map
<ITimeGraphEntry
, Item
> itemMap
= new LinkedHashMap
<>();
2826 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2827 ITimeGraphEntry entry
= fRootEntries
[i
];
2828 refreshData(itemMap
, null, 0, entry
);
2831 fItems
= fItemMap
.values().toArray(new Item
[0]);
2832 updateExpandedItems();
2833 if (selection
!= null) {
2834 for (Item item
: fExpandedItems
) {
2835 if (item
.fEntry
== selection
) {
2836 item
.fSelected
= true;
2843 private void refreshData(Map
<ITimeGraphEntry
, Item
> itemMap
, Item parent
, int level
, ITimeGraphEntry entry
) {
2844 Item item
= new Item(entry
, entry
.getName(), level
);
2845 if (parent
!= null) {
2846 parent
.fChildren
.add(item
);
2848 if (fGlobalItemHeight
== CUSTOM_ITEM_HEIGHT
) {
2849 item
.fItemHeight
= fTimeGraphProvider
.getItemHeight(entry
);
2851 item
.fItemHeight
= fGlobalItemHeight
;
2853 itemMap
.put(entry
, item
);
2854 if (entry
.hasChildren()) {
2855 Item oldItem
= fItemMap
.get(entry
);
2856 if (oldItem
!= null && oldItem
.fHasChildren
&& level
== oldItem
.fLevel
&& entry
.getParent() == oldItem
.fEntry
.getParent()) {
2857 /* existing items keep their old expanded state */
2858 item
.fExpanded
= oldItem
.fExpanded
;
2860 /* new items set the expanded state according to auto-expand level */
2861 item
.fExpanded
= fAutoExpandLevel
== ALL_LEVELS
|| level
< fAutoExpandLevel
;
2863 item
.fHasChildren
= true;
2864 for (ITimeGraphEntry child
: entry
.getChildren()) {
2865 refreshData(itemMap
, item
, level
+ 1, child
);
2870 public void updateExpandedItems() {
2871 for (Item item
: fItems
) {
2872 item
.fExpandedIndex
= -1;
2874 List
<Item
> expandedItemList
= new ArrayList
<>();
2875 for (int i
= 0; i
< fRootEntries
.length
; i
++) {
2876 ITimeGraphEntry entry
= fRootEntries
[i
];
2877 Item item
= findItem(entry
);
2878 refreshExpanded(expandedItemList
, item
);
2880 fExpandedItems
= expandedItemList
.toArray(new Item
[0]);
2881 fTopIndex
= Math
.min(fTopIndex
, Math
.max(0, fExpandedItems
.length
- 1));
2884 private void refreshExpanded(List
<Item
> expandedItemList
, Item item
) {
2885 // Check for filters
2886 boolean display
= true;
2887 for (ViewerFilter filter
: fFilters
) {
2888 if (!filter
.select(null, item
.fEntry
.getParent(), item
.fEntry
)) {
2894 item
.fExpandedIndex
= expandedItemList
.size();
2895 expandedItemList
.add(item
);
2896 if (item
.fHasChildren
&& item
.fExpanded
) {
2897 for (Item child
: item
.fChildren
) {
2898 refreshExpanded(expandedItemList
, child
);
2904 public void refreshData(ITimeGraphEntry
[] entries
) {
2905 if (entries
== null) {
2906 fRootEntries
= null;
2908 fRootEntries
= Arrays
.copyOf(entries
, entries
.length
);
2914 public void refreshArrows(List
<ILinkEvent
> events
) {
2915 /* If links are null, reset the list */
2916 if (events
!= null) {
2919 fLinks
= new ArrayList
<>();
2923 public ITimeGraphEntry
[] getEntries() {
2924 return fRootEntries
;
2928 private class Item
{
2929 private boolean fExpanded
;
2930 private int fExpandedIndex
;
2931 private boolean fSelected
;
2932 private boolean fHasChildren
;
2933 private int fItemHeight
;
2934 private final int fLevel
;
2935 private final List
<Item
> fChildren
;
2936 private final String fName
;
2937 private final ITimeGraphEntry fEntry
;
2939 public Item(ITimeGraphEntry entry
, String name
, int level
) {
2940 this.fEntry
= entry
;
2942 this.fLevel
= level
;
2943 this.fChildren
= new ArrayList
<>();
2947 public String
toString() {
2953 public void menuDetected(MenuDetectEvent e
) {
2954 if (null == fTimeProvider
) {
2957 if (e
.detail
== SWT
.MENU_MOUSE
) {
2958 if (fPendingMenuDetectEvent
== null) {
2959 /* Feature in Linux. The MenuDetectEvent is received before mouseDown.
2960 * Store the event and trigger it later just before handling mouseUp.
2961 * This allows for the method to detect if mouse is used to drag zoom.
2963 fPendingMenuDetectEvent
= e
;
2966 fPendingMenuDetectEvent
= null;
2967 if (fDragState
!= DRAG_ZOOM
|| fDragX
!= fDragX0
) {
2971 if (fDragState
!= DRAG_NONE
) {
2975 Point p
= toControl(e
.x
, e
.y
);
2976 int idx
= getItemIndexAtY(p
.y
);
2977 if (idx
>= 0 && idx
< fItemData
.fExpandedItems
.length
) {
2978 Item item
= fItemData
.fExpandedItems
[idx
];
2979 ITimeGraphEntry entry
= item
.fEntry
;
2980 if (entry
.hasTimeEvents()) {
2981 ITimeEvent event
= Utils
.findEvent(entry
, getTimeAtX(p
.x
), 2);
2982 if (event
!= null) {
2984 fireMenuEventOnTimeEvent(e
);
2989 fireMenuEventOnTimeGraphEntry(e
);
2994 * Perform the alignment operation.
2997 * the alignment offset
2999 * @see ITmfTimeAligned
3003 public void performAlign(int offset
) {
3004 fTimeProvider
.setNameSpace(offset
);
3008 * Return the time alignment information
3010 * @return the time alignment information
3012 * @see ITmfTimeAligned
3016 public TmfTimeViewAlignmentInfo
getTimeViewAlignmentInfo() {
3017 return new TmfTimeViewAlignmentInfo(getShell(), toDisplay(0, 0), fTimeProvider
.getNameSpace());