lttng: Add Next/Previous TID event action in CFV
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / widgets / TimeGraphControl.java
CommitLineData
837a2f8c 1/*****************************************************************************
8910dea2 2 * Copyright (c) 2007, 2016 Intel Corporation and others
4999a196 3 *
837a2f8c
PT
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
8 *
9 * Contributors:
10 * Intel Corporation - Initial API and implementation
11 * Ruslan A. Scherbakov, Intel - Initial API and implementation
4999a196
GB
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
bec1f1ac 16 * Add display of links between items
351a2391 17 * Xavier Raynaud, Kalray - Code optimization
f2ca0f69 18 * Generoso Pagano, Inria - Support for drag selection listeners
837a2f8c
PT
19 *****************************************************************************/
20
2bdf0193 21package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets;
837a2f8c 22
48072ae3 23import java.util.AbstractMap.SimpleEntry;
837a2f8c 24import java.util.ArrayList;
f1fae91f 25import java.util.Arrays;
2fe6a9ea 26import java.util.Collections;
83d0971d 27import java.util.HashMap;
837a2f8c 28import java.util.Iterator;
70e10acc 29import java.util.LinkedHashMap;
8b516722 30import java.util.LinkedList;
837a2f8c 31import java.util.List;
70e10acc 32import java.util.Map;
48072ae3 33import java.util.Map.Entry;
8b516722 34import java.util.Queue;
837a2f8c 35
367e2932 36import org.eclipse.jdt.annotation.NonNull;
0fcf3b09 37import org.eclipse.jface.action.IStatusLineManager;
837a2f8c
PT
38import org.eclipse.jface.resource.JFaceResources;
39import org.eclipse.jface.resource.LocalResourceManager;
f4617471 40import org.eclipse.jface.viewers.AbstractTreeViewer;
837a2f8c
PT
41import org.eclipse.jface.viewers.ISelection;
42import org.eclipse.jface.viewers.ISelectionChangedListener;
43import org.eclipse.jface.viewers.ISelectionProvider;
ad4415e1 44import org.eclipse.jface.viewers.SelectionChangedEvent;
6ac5a950 45import org.eclipse.jface.viewers.ViewerFilter;
0fab12b0 46import org.eclipse.osgi.util.NLS;
837a2f8c 47import org.eclipse.swt.SWT;
837a2f8c
PT
48import org.eclipse.swt.events.FocusEvent;
49import org.eclipse.swt.events.FocusListener;
50import org.eclipse.swt.events.KeyEvent;
51import org.eclipse.swt.events.KeyListener;
27df1564
XR
52import org.eclipse.swt.events.MenuDetectEvent;
53import org.eclipse.swt.events.MenuDetectListener;
837a2f8c
PT
54import org.eclipse.swt.events.MouseEvent;
55import org.eclipse.swt.events.MouseListener;
56import org.eclipse.swt.events.MouseMoveListener;
57import org.eclipse.swt.events.MouseTrackListener;
58import org.eclipse.swt.events.MouseWheelListener;
59import org.eclipse.swt.events.PaintEvent;
837a2f8c
PT
60import org.eclipse.swt.events.SelectionListener;
61import org.eclipse.swt.events.TraverseEvent;
62import org.eclipse.swt.events.TraverseListener;
27df1564 63import org.eclipse.swt.events.TypedEvent;
837a2f8c
PT
64import org.eclipse.swt.graphics.Color;
65import org.eclipse.swt.graphics.Cursor;
3bd20aa6
PT
66import org.eclipse.swt.graphics.Font;
67import org.eclipse.swt.graphics.FontData;
837a2f8c
PT
68import org.eclipse.swt.graphics.GC;
69import org.eclipse.swt.graphics.Image;
70import org.eclipse.swt.graphics.Point;
71import org.eclipse.swt.graphics.Rectangle;
72import org.eclipse.swt.widgets.Composite;
73import org.eclipse.swt.widgets.Display;
74import org.eclipse.swt.widgets.Event;
75import org.eclipse.swt.widgets.Listener;
024658d1 76import org.eclipse.swt.widgets.Menu;
d2e4afa7
MAL
77import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
78import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo;
79import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentSignal;
80import org.eclipse.tracecompass.tmf.ui.views.ITmfTimeAligned;
2bdf0193
AM
81import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphColorListener;
82import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
83import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
84import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener;
85import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTreeListener;
86import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
87import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTimeEvent;
88import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphTreeExpansionEvent;
89import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
56b43ab2 90import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent;
2bdf0193
AM
91import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
92import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
93import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
94import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
837a2f8c 95
4923d7b9
PT
96import com.google.common.collect.Iterables;
97
837a2f8c
PT
98/**
99 * Time graph control implementation
100 *
837a2f8c
PT
101 * @author Alvaro Sanchez-Leon
102 * @author Patrick Tasse
103 */
496f76d3 104public class TimeGraphControl extends TimeGraphBaseControl
b698ec63
PT
105 implements FocusListener, KeyListener, MouseMoveListener, MouseListener,
106 MouseWheelListener, MouseTrackListener, TraverseListener, ISelectionProvider,
6b11be52 107 MenuDetectListener, ITmfTimeGraphDrawingHelper, ITimeGraphColorListener, Listener {
f1fae91f 108
ae09c4ad 109 /** Constant indicating that all levels of the time graph should be expanded */
f4617471
PT
110 public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
111
837a2f8c
PT
112 private static final int DRAG_NONE = 0;
113 private static final int DRAG_TRACE_ITEM = 1;
114 private static final int DRAG_SPLIT_LINE = 2;
5b2b9bd7 115 private static final int DRAG_ZOOM = 3;
0fcf3b09 116 private static final int DRAG_SELECTION = 4;
a0a88f65 117
837a2f8c
PT
118 private static final int CUSTOM_ITEM_HEIGHT = -1; // get item height from provider
119
f1fae91f
PT
120 private static final double ZOOM_FACTOR = 1.5;
121 private static final double ZOOM_IN_FACTOR = 0.8;
122 private static final double ZOOM_OUT_FACTOR = 1.25;
123
0fcf3b09 124 private static final int SNAP_WIDTH = 2;
1053eaa6 125 private static final int ARROW_HOVER_MAX_DIST = 5;
0fcf3b09
PT
126
127 private static final int NO_STATUS = -1;
33fa1fc7 128 private static final int STATUS_WITHOUT_CURSOR_TIME = -2;
0fcf3b09 129
1d012443
PT
130 private static final int MAX_LABEL_LENGTH = 256;
131
83d0971d
PT
132 private static final int PPI = 72; // points per inch
133 private static final int DPI = Display.getDefault().getDPI().y;
134
48072ae3
PT
135 private static final int VERTICAL_ZOOM_DELAY = 400;
136
f1fae91f
PT
137 /** Resource manager */
138 private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
139
140 /** Color map for event types */
141 private Color[] fEventColorMap = null;
142
143 private ITimeDataProvider fTimeProvider;
0fcf3b09
PT
144 private IStatusLineManager fStatusLineManager = null;
145 private TimeGraphScale fTimeGraphScale = null;
146
f1fae91f 147 private boolean fIsInFocus = false;
f1fae91f
PT
148 private boolean fMouseOverSplitLine = false;
149 private int fGlobalItemHeight = CUSTOM_ITEM_HEIGHT;
3bd20aa6 150 private int fHeightAdjustment = 0;
83d0971d 151 private Map<Integer, Font> fFonts = new HashMap<>();
b052914f 152 private boolean fBlendSubPixelEvents = false;
f1fae91f
PT
153 private int fMinimumItemWidth = 0;
154 private int fTopIndex = 0;
155 private int fDragState = DRAG_NONE;
85203d74 156 private boolean fDragBeginMarker = false;
0fcf3b09 157 private int fDragButton;
f1fae91f
PT
158 private int fDragX0 = 0;
159 private int fDragX = 0;
8b516722 160 private boolean fHasNamespaceFocus = false;
0fcf3b09 161 private long fDragTime0 = 0; // used to preserve accuracy of modified selection
f1fae91f
PT
162 private int fIdealNameSpace = 0;
163 private long fTime0bak;
164 private long fTime1bak;
837a2f8c 165 private ITimeGraphPresentationProvider fTimeGraphProvider = null;
f1fae91f 166 private ItemData fItemData = null;
56b43ab2
PT
167 private List<IMarkerEvent> fMarkers = null;
168 private boolean fMarkersVisible = true;
f1fae91f 169 private List<SelectionListener> fSelectionListeners;
f2ca0f69 170 private List<ITimeGraphTimeListener> fDragSelectionListeners;
507b1336
AM
171 private final List<ISelectionChangedListener> fSelectionChangedListeners = new ArrayList<>();
172 private final List<ITimeGraphTreeListener> fTreeListeners = new ArrayList<>();
173 private final List<MenuDetectListener> fTimeGraphEntryMenuListeners = new ArrayList<>();
174 private final List<MenuDetectListener> fTimeEventMenuListeners = new ArrayList<>();
0fcf3b09
PT
175 private final Cursor fDragCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_HAND);
176 private final Cursor fResizeCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_IBEAM);
177 private final Cursor fWaitCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_WAIT);
178 private final Cursor fZoomCursor = Display.getDefault().getSystemCursor(SWT.CURSOR_SIZEWE);
367e2932 179 private final List<@NonNull ViewerFilter> fFilters = new ArrayList<>();
0b5a90a0 180 private MenuDetectEvent fPendingMenuDetectEvent = null;
55d1fc96
PT
181 private boolean fGridLinesVisible = true;
182 private Color fGridLineColor = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
79ec0b89 183 private boolean fHideArrows = false;
f4617471 184 private int fAutoExpandLevel = ALL_LEVELS;
48072ae3
PT
185 private Entry<ITimeGraphEntry, Integer> fVerticalZoomAlignEntry = null;
186 private long fVerticalZoomAlignTime = 0;
f1fae91f
PT
187 private int fBorderWidth = 0;
188 private int fHeaderHeight = 0;
837a2f8c 189
837a2f8c
PT
190 /**
191 * Standard constructor
192 *
193 * @param parent
194 * The parent composite object
195 * @param colors
196 * The color scheme to use
197 */
198 public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) {
199
b698ec63 200 super(parent, colors, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED);
837a2f8c 201
f1fae91f 202 fItemData = new ItemData();
837a2f8c
PT
203
204 addFocusListener(this);
205 addMouseListener(this);
206 addMouseMoveListener(this);
207 addMouseTrackListener(this);
208 addMouseWheelListener(this);
209 addTraverseListener(this);
210 addKeyListener(this);
27df1564 211 addMenuDetectListener(this);
6b11be52 212 addListener(SWT.MouseWheel, this);
25033fef
PT
213 addDisposeListener((e) -> {
214 fResourceManager.dispose();
215 for (Font font : fFonts.values()) {
216 font.dispose();
217 }
218 });
837a2f8c
PT
219 }
220
221 /**
222 * Sets the timegraph provider used by this timegraph viewer.
223 *
224 * @param timeGraphProvider the timegraph provider
225 */
226 public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
227 fTimeGraphProvider = timeGraphProvider;
837a2f8c 228
4999a196
GB
229 if (timeGraphProvider instanceof ITimeGraphPresentationProvider2) {
230 ((ITimeGraphPresentationProvider2) timeGraphProvider).setDrawingHelper(this);
496f76d3 231 ((ITimeGraphPresentationProvider2) timeGraphProvider).addColorListener(this);
4999a196
GB
232 }
233
837a2f8c 234 StateItem[] stateItems = fTimeGraphProvider.getStateTable();
496f76d3 235 colorSettingsChanged(stateItems);
837a2f8c
PT
236 }
237
5a66cf9c
XR
238 /**
239 * Gets the timegraph provider used by this timegraph viewer.
240 *
241 * @return the timegraph provider, or <code>null</code> if not set.
5a66cf9c
XR
242 */
243 public ITimeGraphPresentationProvider getTimeGraphProvider() {
244 return fTimeGraphProvider;
245 }
246
e50f28e6
AM
247 /**
248 * Gets the time data provider used by this viewer.
249 *
250 * @return The time data provider, or <code>null</code> if not set
251 */
252 public ITimeDataProvider getTimeDataProvider() {
253 return fTimeProvider;
254 }
255
5a66cf9c
XR
256 /**
257 * Gets the color map used by this timegraph viewer.
258 *
259 * @return a color map, or <code>null</code> if not set.
5a66cf9c
XR
260 */
261 public Color[] getEventColorMap() {
262 return fEventColorMap;
263 }
264
837a2f8c
PT
265 /**
266 * Assign the given time provider
267 *
268 * @param timeProvider
269 * The time provider
270 */
271 public void setTimeProvider(ITimeDataProvider timeProvider) {
f1fae91f 272 fTimeProvider = timeProvider;
837a2f8c
PT
273 redraw();
274 }
275
0fcf3b09
PT
276 /**
277 * Assign the status line manager
278 *
279 * @param statusLineManager
280 * The status line manager, or null to disable status line messages
0fcf3b09
PT
281 */
282 public void setStatusLineManager(IStatusLineManager statusLineManager) {
283 if (fStatusLineManager != null && statusLineManager == null) {
284 fStatusLineManager.setMessage(""); //$NON-NLS-1$
285 }
286 fStatusLineManager = statusLineManager;
287 }
288
289 /**
290 * Assign the time graph scale
291 *
292 * @param timeGraphScale
293 * The time graph scale
0fcf3b09
PT
294 */
295 public void setTimeGraphScale(TimeGraphScale timeGraphScale) {
296 fTimeGraphScale = timeGraphScale;
297 }
298
837a2f8c
PT
299 /**
300 * Add a selection listener
301 *
302 * @param listener
303 * The listener to add
304 */
305 public void addSelectionListener(SelectionListener listener) {
306 if (listener == null) {
307 SWT.error(SWT.ERROR_NULL_ARGUMENT);
308 }
f1fae91f 309 if (null == fSelectionListeners) {
507b1336 310 fSelectionListeners = new ArrayList<>();
837a2f8c 311 }
f1fae91f 312 fSelectionListeners.add(listener);
837a2f8c
PT
313 }
314
315 /**
316 * Remove a selection listener
317 *
318 * @param listener
319 * The listener to remove
320 */
321 public void removeSelectionListener(SelectionListener listener) {
f1fae91f
PT
322 if (null != fSelectionListeners) {
323 fSelectionListeners.remove(listener);
837a2f8c
PT
324 }
325 }
326
327 /**
328 * Selection changed callback
329 */
330 public void fireSelectionChanged() {
f1fae91f
PT
331 if (null != fSelectionListeners) {
332 Iterator<SelectionListener> it = fSelectionListeners.iterator();
837a2f8c
PT
333 while (it.hasNext()) {
334 SelectionListener listener = it.next();
335 listener.widgetSelected(null);
336 }
337 }
ad4415e1
BH
338
339 if (null != fSelectionChangedListeners) {
340 for (ISelectionChangedListener listener : fSelectionChangedListeners) {
341 listener.selectionChanged(new SelectionChangedEvent(this, getSelection()));
342 }
343 }
837a2f8c
PT
344 }
345
346 /**
347 * Default selection callback
348 */
349 public void fireDefaultSelection() {
f1fae91f
PT
350 if (null != fSelectionListeners) {
351 Iterator<SelectionListener> it = fSelectionListeners.iterator();
837a2f8c
PT
352 while (it.hasNext()) {
353 SelectionListener listener = it.next();
354 listener.widgetDefaultSelected(null);
355 }
356 }
357 }
358
f2ca0f69
GP
359 /**
360 * Add a drag selection listener
361 *
362 * @param listener
363 * The listener to add
f2ca0f69
GP
364 */
365 public void addDragSelectionListener(ITimeGraphTimeListener listener) {
366 if (listener == null) {
367 SWT.error(SWT.ERROR_NULL_ARGUMENT);
368 }
369 if (null == fDragSelectionListeners) {
370 fDragSelectionListeners = new ArrayList<>();
371 }
372 fDragSelectionListeners.add(listener);
373 }
374
375 /**
376 * Remove a drag selection listener
377 *
378 * @param listener
379 * The listener to remove
f2ca0f69
GP
380 */
381 public void removeDragSelectionListener(ITimeGraphTimeListener listener) {
382 if (null != fDragSelectionListeners) {
383 fDragSelectionListeners.remove(listener);
384 }
385 }
386
387 /**
388 * Drag Selection changed callback
389 *
390 * @param start
391 * Time interval start
392 * @param end
393 * Time interval end
f2ca0f69
GP
394 */
395 public void fireDragSelectionChanged(long start, long end) {
396 // check for backward intervals
397 long beginTime, endTime;
398 if (start > end) {
399 beginTime = end;
400 endTime = start;
401 } else {
402 beginTime = start;
403 endTime = end;
404 }
405 // call the listeners
406 if (null != fDragSelectionListeners) {
407 Iterator<ITimeGraphTimeListener> it = fDragSelectionListeners.iterator();
408 while (it.hasNext()) {
409 ITimeGraphTimeListener listener = it.next();
410 listener.timeSelected(new TimeGraphTimeEvent(this, beginTime, endTime));
411 }
412 }
413 }
414
837a2f8c
PT
415 /**
416 * Get the traces in the model
417 *
418 * @return The array of traces
419 */
420 public ITimeGraphEntry[] getTraces() {
70e10acc 421 return fItemData.getEntries();
837a2f8c
PT
422 }
423
837a2f8c
PT
424 /**
425 * Refresh the data for the thing
426 */
427 public void refreshData() {
f1fae91f 428 fItemData.refreshData();
837a2f8c
PT
429 redraw();
430 }
431
432 /**
433 * Refresh data for the given traces
434 *
435 * @param traces
436 * The traces to refresh
437 */
438 public void refreshData(ITimeGraphEntry[] traces) {
f1fae91f 439 fItemData.refreshData(traces);
837a2f8c
PT
440 redraw();
441 }
442
bec1f1ac
GB
443 /**
444 * Refresh the links (arrows) of this widget
445 *
2fe6a9ea 446 * @param events The link event list
bec1f1ac
GB
447 */
448 public void refreshArrows(List<ILinkEvent> events) {
449 fItemData.refreshArrows(events);
450 }
451
2fe6a9ea
PT
452 /**
453 * Get the links (arrows) of this widget
454 *
455 * @return The unmodifiable link event list
456 *
0336f981 457 * @since 1.1
2fe6a9ea
PT
458 */
459 public List<ILinkEvent> getArrows() {
460 return Collections.unmodifiableList(fItemData.fLinks);
461 }
462
837a2f8c
PT
463 boolean ensureVisibleItem(int idx, boolean redraw) {
464 boolean changed = false;
41b5c37f
AM
465 int index = idx;
466 if (index < 0) {
f1fae91f
PT
467 for (index = 0; index < fItemData.fExpandedItems.length; index++) {
468 if (fItemData.fExpandedItems[index].fSelected) {
837a2f8c
PT
469 break;
470 }
471 }
472 }
f1fae91f 473 if (index >= fItemData.fExpandedItems.length) {
837a2f8c
PT
474 return changed;
475 }
f1fae91f 476 if (index < fTopIndex) {
41b5c37f 477 setTopIndex(index);
837a2f8c
PT
478 if (redraw) {
479 redraw();
480 }
481 changed = true;
482 } else {
483 int page = countPerPage();
f1fae91f 484 if (index >= fTopIndex + page) {
41b5c37f 485 setTopIndex(index - page + 1);
837a2f8c
PT
486 if (redraw) {
487 redraw();
488 }
489 changed = true;
490 }
491 }
492 return changed;
493 }
494
495 /**
496 * Assign the given index as the top one
497 *
498 * @param idx
499 * The index
500 */
501 public void setTopIndex(int idx) {
f1fae91f 502 int index = Math.min(idx, fItemData.fExpandedItems.length - countPerPage());
41b5c37f 503 index = Math.max(0, index);
f1fae91f 504 fTopIndex = index;
837a2f8c
PT
505 redraw();
506 }
507
48072ae3
PT
508 /**
509 * Set the top index so that the requested element is at the specified
510 * position.
511 *
512 * @param entry
513 * the time graph entry to be positioned
514 * @param y
515 * the requested y-coordinate
516 * @since 2.0
517 */
518 public void setElementPosition(ITimeGraphEntry entry, int y) {
519 Item item = fItemData.fItemMap.get(entry);
520 if (item == null || item.fExpandedIndex == -1) {
521 return;
522 }
523 int index = item.fExpandedIndex;
524 Rectangle itemRect = getItemRect(getClientArea(), index);
525 int delta = itemRect.y + itemRect.height - y;
526 int topIndex = getItemIndexAtY(delta);
527 if (topIndex != -1) {
528 setTopIndex(topIndex);
529 } else {
530 if (delta < 0) {
531 setTopIndex(0);
532 } else {
533 setTopIndex(getExpandedElementCount());
534 }
535 }
536 }
537
f4617471 538 /**
df0e3d5f
PT
539 * Sets the auto-expand level to be used for new entries discovered when
540 * calling {@link #refreshData()} or {@link #refreshData(ITimeGraphEntry[])}
541 * . The value 0 means that there is no auto-expand; 1 means that top-level
f4617471
PT
542 * entries are expanded, but not their children; 2 means that top-level
543 * entries are expanded, and their children, but not grand-children; and so
544 * on.
545 * <p>
546 * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
547 * </p>
df0e3d5f 548 *
f4617471
PT
549 * @param level
550 * non-negative level, or <code>ALL_LEVELS</code> to expand all
551 * levels of the tree
f4617471
PT
552 */
553 public void setAutoExpandLevel(int level) {
554 fAutoExpandLevel = level;
555 }
556
557 /**
558 * Returns the auto-expand level.
559 *
560 * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
561 * the tree are expanded automatically
562 * @see #setAutoExpandLevel
f4617471
PT
563 */
564 public int getAutoExpandLevel() {
565 return fAutoExpandLevel;
566 }
567
df0e3d5f
PT
568 /**
569 * Get the expanded state of a given entry.
570 *
571 * @param entry
572 * The entry
573 * @return true if the entry is expanded, false if collapsed
0336f981 574 * @since 1.1
df0e3d5f
PT
575 */
576 public boolean getExpandedState(ITimeGraphEntry entry) {
577 Item item = fItemData.fItemMap.get(entry);
578 return (item != null ? item.fExpanded : false);
579 }
580
837a2f8c
PT
581 /**
582 * Set the expanded state of a given entry
583 *
584 * @param entry
585 * The entry
586 * @param expanded
587 * True if expanded, false if collapsed
588 */
589 public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
f1fae91f
PT
590 Item item = fItemData.findItem(entry);
591 if (item != null && item.fExpanded != expanded) {
592 item.fExpanded = expanded;
593 fItemData.updateExpandedItems();
837a2f8c
PT
594 redraw();
595 }
596 }
597
8b516722
BH
598 /**
599 * Set the expanded state of a given entry to certain relative level.
600 * It will call fireTreeEvent() for each changed entry. At the end
601 * it will call redraw().
602 *
603 * @param entry
604 * The entry
605 * @param level
606 * level to expand to or negative for all levels
607 * @param expanded
608 * True if expanded, false if collapsed
609 */
610 private void setExpandedState(ITimeGraphEntry entry, int level, boolean expanded) {
611 setExpandedStateInt(entry, level, expanded);
612 redraw();
613 }
614
615 /**
616 * Set the expanded state of a given entry and its children to the first
617 * level that has one collapsed entry.
618 *
619 * @param entry
620 * The entry
621 */
622 private void setExpandedStateLevel(ITimeGraphEntry entry) {
623 int level = findExpandedLevel(entry);
624 if (level >= 0) {
625 setExpandedStateInt(entry, level, true);
626 redraw();
627 }
628 }
629
630 /*
631 * Inner class for finding relative level with at least one
632 * collapsed entry.
633 */
634 private class SearchNode {
635 SearchNode(ITimeGraphEntry e, int l) {
636 entry = e;
637 level = l;
638 }
639 ITimeGraphEntry entry;
640 int level;
641 }
642
643 /**
644 * Finds the relative level with at least one collapsed entry.
645 *
646 * @param entry
647 * the start entry
648 * @return the found level or -1 if all levels are already expanded.
649 */
650 private int findExpandedLevel(ITimeGraphEntry entry) {
651 Queue<SearchNode> queue = new LinkedList<>();
652 SearchNode root = new SearchNode(entry, 0);
653 SearchNode node = root;
654 queue.add(root);
655
656 while (!queue.isEmpty()) {
657 node = queue.remove();
658 if (node.entry.hasChildren() && !getExpandedState(node.entry)) {
659 return node.level;
660 }
661 for (ITimeGraphEntry e : node.entry.getChildren()) {
662 if (e.hasChildren()) {
663 SearchNode n = new SearchNode(e, node.level + 1);
664 queue.add(n);
665 }
666 }
667 }
668 return -1;
669 }
670
671 /**
672 * Set the expanded state of a given entry to certain relative level.
673 * It will call fireTreeEvent() for each changed entry. No redraw is done.
674 *
675 * @param entry
676 * The entry
677 * @param level
678 * level to expand to or negative for all levels
679 * @param expanded
680 * True if expanded, false if collapsed
681 */
682 private void setExpandedStateInt(ITimeGraphEntry entry, int aLevel, boolean expanded) {
683 int level = aLevel;
684 if ((level > 0) || (level < 0)) {
685 level--;
686 if (entry.hasChildren()) {
687 for (ITimeGraphEntry e : entry.getChildren()) {
688 setExpandedStateInt(e, level, expanded);
689 }
690 }
691 }
692 Item item = fItemData.findItem(entry);
693 if (item != null && item.fExpanded != expanded) {
694 item.fExpanded = expanded;
695 fItemData.updateExpandedItems();
696 fireTreeEvent(item.fEntry, item.fExpanded);
697 }
698 }
699
837a2f8c
PT
700 /**
701 * Collapses all nodes of the viewer's tree, starting with the root.
837a2f8c
PT
702 */
703 public void collapseAll() {
f1fae91f
PT
704 for (Item item : fItemData.fItems) {
705 item.fExpanded = false;
837a2f8c 706 }
f1fae91f 707 fItemData.updateExpandedItems();
837a2f8c
PT
708 redraw();
709 }
710
711 /**
712 * Expands all nodes of the viewer's tree, starting with the root.
837a2f8c
PT
713 */
714 public void expandAll() {
f1fae91f
PT
715 for (Item item : fItemData.fItems) {
716 item.fExpanded = true;
837a2f8c 717 }
f1fae91f 718 fItemData.updateExpandedItems();
837a2f8c
PT
719 redraw();
720 }
721
722 /**
723 * Add a tree listener
724 *
725 * @param listener
726 * The listener to add
727 */
728 public void addTreeListener(ITimeGraphTreeListener listener) {
f1fae91f
PT
729 if (!fTreeListeners.contains(listener)) {
730 fTreeListeners.add(listener);
837a2f8c
PT
731 }
732 }
733
734 /**
735 * Remove a tree listener
736 *
737 * @param listener
738 * The listener to remove
739 */
740 public void removeTreeListener(ITimeGraphTreeListener listener) {
f1fae91f
PT
741 if (fTreeListeners.contains(listener)) {
742 fTreeListeners.remove(listener);
837a2f8c
PT
743 }
744 }
745
746 /**
747 * Tree event callback
748 *
749 * @param entry
750 * The affected entry
751 * @param expanded
752 * The expanded state (true for expanded, false for collapsed)
753 */
754 public void fireTreeEvent(ITimeGraphEntry entry, boolean expanded) {
755 TimeGraphTreeExpansionEvent event = new TimeGraphTreeExpansionEvent(this, entry);
f1fae91f 756 for (ITimeGraphTreeListener listener : fTreeListeners) {
837a2f8c
PT
757 if (expanded) {
758 listener.treeExpanded(event);
759 } else {
760 listener.treeCollapsed(event);
761 }
762 }
763 }
764
27df1564
XR
765 /**
766 * Add a menu listener on {@link ITimeGraphEntry}s
ae09c4ad 767 *
27df1564
XR
768 * @param listener
769 * The listener to add
27df1564
XR
770 */
771 public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
f1fae91f
PT
772 if (!fTimeGraphEntryMenuListeners.contains(listener)) {
773 fTimeGraphEntryMenuListeners.add(listener);
27df1564
XR
774 }
775 }
776
777 /**
778 * Remove a menu listener on {@link ITimeGraphEntry}s
779 *
780 * @param listener
781 * The listener to remove
27df1564
XR
782 */
783 public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
f1fae91f
PT
784 if (fTimeGraphEntryMenuListeners.contains(listener)) {
785 fTimeGraphEntryMenuListeners.remove(listener);
27df1564
XR
786 }
787 }
788
789 /**
790 * Menu event callback on {@link ITimeGraphEntry}s
791 *
792 * @param event
793 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeGraphEntry}
794 */
795 private void fireMenuEventOnTimeGraphEntry(MenuDetectEvent event) {
f1fae91f 796 for (MenuDetectListener listener : fTimeGraphEntryMenuListeners) {
27df1564
XR
797 listener.menuDetected(event);
798 }
799 }
800
801 /**
802 * Add a menu listener on {@link ITimeEvent}s
803 *
804 * @param listener
805 * The listener to add
27df1564
XR
806 */
807 public void addTimeEventMenuListener(MenuDetectListener listener) {
f1fae91f
PT
808 if (!fTimeEventMenuListeners.contains(listener)) {
809 fTimeEventMenuListeners.add(listener);
27df1564
XR
810 }
811 }
812
813 /**
814 * Remove a menu listener on {@link ITimeEvent}s
815 *
816 * @param listener
817 * The listener to remove
27df1564
XR
818 */
819 public void removeTimeEventMenuListener(MenuDetectListener listener) {
f1fae91f
PT
820 if (fTimeEventMenuListeners.contains(listener)) {
821 fTimeEventMenuListeners.remove(listener);
27df1564
XR
822 }
823 }
824
825 /**
826 * Menu event callback on {@link ITimeEvent}s
827 *
828 * @param event
829 * The MenuDetectEvent, with field {@link TypedEvent#data} set to the selected {@link ITimeEvent}
830 */
831 private void fireMenuEventOnTimeEvent(MenuDetectEvent event) {
f1fae91f 832 for (MenuDetectListener listener : fTimeEventMenuListeners) {
27df1564
XR
833 listener.menuDetected(event);
834 }
835 }
836
8b516722
BH
837 @Override
838 public boolean setFocus() {
839 if ((fTimeProvider != null) && fTimeProvider.getNameSpace() > 0) {
840 fHasNamespaceFocus = true;
841 }
842 return super.setFocus();
843 }
844
837a2f8c
PT
845 @Override
846 public ISelection getSelection() {
847 TimeGraphSelection sel = new TimeGraphSelection();
848 ITimeGraphEntry trace = getSelectedTrace();
f1fae91f 849 if (null != trace && null != fTimeProvider) {
baf92cac 850 long selectedTime = fTimeProvider.getSelectionBegin();
837a2f8c 851 ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);
9bdf1671 852 sel.add(trace);
837a2f8c
PT
853 if (event != null) {
854 sel.add(event);
837a2f8c
PT
855 }
856 }
857 return sel;
858 }
859
860 /**
861 * Get the selection object
862 *
863 * @return The selection
864 */
865 public ISelection getSelectionTrace() {
866 TimeGraphSelection sel = new TimeGraphSelection();
867 ITimeGraphEntry trace = getSelectedTrace();
868 if (null != trace) {
869 sel.add(trace);
870 }
871 return sel;
872 }
873
874 /**
875 * Enable/disable one of the traces in the model
876 *
877 * @param n
878 * 1 to enable it, -1 to disable. The method returns immediately
879 * if another value is used.
880 */
881 public void selectTrace(int n) {
882 if ((n != 1) && (n != -1)) {
883 return;
884 }
885
886 boolean changed = false;
887 int lastSelection = -1;
f1fae91f
PT
888 for (int i = 0; i < fItemData.fExpandedItems.length; i++) {
889 Item item = fItemData.fExpandedItems[i];
890 if (item.fSelected) {
837a2f8c 891 lastSelection = i;
f1fae91f
PT
892 if ((1 == n) && (i < fItemData.fExpandedItems.length - 1)) {
893 item.fSelected = false;
894 item = fItemData.fExpandedItems[i + 1];
895 item.fSelected = true;
837a2f8c
PT
896 changed = true;
897 } else if ((-1 == n) && (i > 0)) {
f1fae91f
PT
898 item.fSelected = false;
899 item = fItemData.fExpandedItems[i - 1];
900 item.fSelected = true;
837a2f8c
PT
901 changed = true;
902 }
903 break;
904 }
905 }
906
f1fae91f
PT
907 if (lastSelection < 0 && fItemData.fExpandedItems.length > 0) {
908 Item item = fItemData.fExpandedItems[0];
909 item.fSelected = true;
837a2f8c
PT
910 changed = true;
911 }
912
913 if (changed) {
914 ensureVisibleItem(-1, false);
915 redraw();
916 fireSelectionChanged();
917 }
918 }
919
920 /**
921 * Select an event
922 *
923 * @param n
924 * 1 for next event, -1 for previous event
33fa1fc7
PT
925 * @param extend
926 * true to extend selection range, false for single selection
927 * @since 1.0
837a2f8c 928 */
33fa1fc7 929 public void selectEvent(int n, boolean extend) {
f1fae91f 930 if (null == fTimeProvider) {
837a2f8c
PT
931 return;
932 }
933 ITimeGraphEntry trace = getSelectedTrace();
934 if (trace == null) {
935 return;
936 }
33fa1fc7 937 long selectedTime = fTimeProvider.getSelectionEnd();
50d36521 938 long endTime = fTimeProvider.getMaxTime();
837a2f8c 939 ITimeEvent nextEvent;
33fa1fc7 940 if (n == -1 && selectedTime > endTime) {
837a2f8c
PT
941 nextEvent = Utils.findEvent(trace, selectedTime, 0);
942 } else {
943 nextEvent = Utils.findEvent(trace, selectedTime, n);
944 }
33fa1fc7 945 if (null == nextEvent && n == -1) {
837a2f8c
PT
946 nextEvent = Utils.getFirstEvent(trace);
947 }
948 if (null != nextEvent) {
949 long nextTime = nextEvent.getTime();
950 // If last event detected e.g. going back or not moving to a next
951 // event
952 if (nextTime <= selectedTime && n == 1) {
953 // Select to the end of this last event
954 nextTime = nextEvent.getTime() + nextEvent.getDuration();
955 // but not beyond the end of the trace
956 if (nextTime > endTime) {
957 nextTime = endTime;
958 }
f1fae91f 959 } else if (n == -1 && nextEvent.getTime() + nextEvent.getDuration() < selectedTime) {
837a2f8c 960 // for previous event go to its end time unless we were already there
f1fae91f 961 nextTime = nextEvent.getTime() + nextEvent.getDuration();
837a2f8c 962 }
33fa1fc7 963 if (extend) {
84c8aef7 964 fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), nextTime, true);
33fa1fc7
PT
965 } else {
966 fTimeProvider.setSelectedTimeNotify(nextTime, true);
967 }
837a2f8c 968 fireSelectionChanged();
33fa1fc7
PT
969 } else if (n == 1) {
970 if (extend) {
84c8aef7 971 fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), endTime, true);
33fa1fc7
PT
972 } else {
973 fTimeProvider.setSelectedTimeNotify(endTime, true);
974 }
837a2f8c
PT
975 fireSelectionChanged();
976 }
33fa1fc7 977 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
837a2f8c
PT
978 }
979
980 /**
981 * Select the next event
33fa1fc7
PT
982 *
983 * @param extend
984 * true to extend selection range, false for single selection
985 * @since 1.0
837a2f8c 986 */
33fa1fc7
PT
987 public void selectNextEvent(boolean extend) {
988 selectEvent(1, extend);
837a2f8c 989 // Notify if visible time window has been adjusted
f1fae91f 990 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getTime0(), fTimeProvider.getTime1());
837a2f8c
PT
991 }
992
993 /**
994 * Select the previous event
33fa1fc7
PT
995 *
996 * @param extend
997 * true to extend selection range, false for single selection
998 * @since 1.0
837a2f8c 999 */
33fa1fc7
PT
1000 public void selectPrevEvent(boolean extend) {
1001 selectEvent(-1, extend);
837a2f8c 1002 // Notify if visible time window has been adjusted
f1fae91f 1003 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getTime0(), fTimeProvider.getTime1());
837a2f8c
PT
1004 }
1005
1006 /**
1007 * Select the next trace
1008 */
1009 public void selectNextTrace() {
1010 selectTrace(1);
1011 }
1012
1013 /**
1014 * Select the previous trace
1015 */
1016 public void selectPrevTrace() {
1017 selectTrace(-1);
1018 }
1019
b698ec63
PT
1020 /**
1021 * Scroll left or right by one half window size
1022 *
1023 * @param left
1024 * true to scroll left, false to scroll right
b698ec63
PT
1025 */
1026 public void horizontalScroll(boolean left) {
1027 long time0 = fTimeProvider.getTime0();
1028 long time1 = fTimeProvider.getTime1();
1029 long timeMin = fTimeProvider.getMinTime();
1030 long timeMax = fTimeProvider.getMaxTime();
1031 long range = time1 - time0;
1032 if (range <= 0) {
1033 return;
1034 }
1035 long increment = Math.max(1, range / 2);
1036 if (left) {
1037 time0 = Math.max(time0 - increment, timeMin);
1038 time1 = time0 + range;
1039 } else {
1040 time1 = Math.min(time1 + increment, timeMax);
1041 time0 = time1 - range;
1042 }
1043 fTimeProvider.setStartFinishTimeNotify(time0, time1);
1044 }
1045
837a2f8c
PT
1046 /**
1047 * Zoom based on mouse cursor location with mouse scrolling
1048 *
1049 * @param zoomIn true to zoom in, false to zoom out
1050 */
1051 public void zoom(boolean zoomIn) {
1052 int globalX = getDisplay().getCursorLocation().x;
1053 Point p = toControl(globalX, 0);
f1fae91f
PT
1054 int nameSpace = fTimeProvider.getNameSpace();
1055 int timeSpace = fTimeProvider.getTimeSpace();
837a2f8c 1056 int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x));
f1fae91f
PT
1057 long time0 = fTimeProvider.getTime0();
1058 long time1 = fTimeProvider.getTime1();
837a2f8c
PT
1059 long interval = time1 - time0;
1060 if (interval == 0) {
1061 interval = 1;
1062 } // to allow getting out of single point interval
1063 long newInterval;
1064 if (zoomIn) {
f1fae91f 1065 newInterval = Math.max(Math.round(interval * ZOOM_IN_FACTOR), fTimeProvider.getMinTimeInterval());
837a2f8c 1066 } else {
f1fae91f 1067 newInterval = (long) Math.ceil(interval * ZOOM_OUT_FACTOR);
837a2f8c
PT
1068 }
1069 long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval));
1070 long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval);
1071 long newTime1 = newTime0 + newInterval;
10ad9fa6 1072 fTimeProvider.setStartFinishTimeNotify(newTime0, newTime1);
837a2f8c
PT
1073 }
1074
1075 /**
1076 * zoom in using single click
1077 */
1078 public void zoomIn() {
f1fae91f
PT
1079 long prevTime0 = fTimeProvider.getTime0();
1080 long prevTime1 = fTimeProvider.getTime1();
1081 long prevRange = prevTime1 - prevTime0;
1082 if (prevRange == 0) {
3e9a3685
PT
1083 return;
1084 }
baf92cac
AM
1085 ITimeDataProvider provider = fTimeProvider;
1086 long selTime = (provider.getSelectionEnd() + provider.getSelectionBegin()) / 2;
f1fae91f
PT
1087 if (selTime <= prevTime0 || selTime >= prevTime1) {
1088 selTime = (prevTime0 + prevTime1) / 2;
837a2f8c 1089 }
f1fae91f
PT
1090 long time0 = selTime - (long) ((selTime - prevTime0) / ZOOM_FACTOR);
1091 long time1 = selTime + (long) ((prevTime1 - selTime) / ZOOM_FACTOR);
837a2f8c 1092
f1fae91f 1093 long inaccuracy = (fTimeProvider.getMaxTime() - fTimeProvider.getMinTime()) - (time1 - time0);
837a2f8c
PT
1094
1095 if (inaccuracy > 0 && inaccuracy < 100) {
f1fae91f 1096 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getMinTime(), fTimeProvider.getMaxTime());
837a2f8c
PT
1097 return;
1098 }
1099
f1fae91f
PT
1100 long min = fTimeProvider.getMinTimeInterval();
1101 if ((time1 - time0) < min) {
1102 time0 = selTime - (selTime - prevTime0) * min / prevRange;
1103 time1 = time0 + min;
837a2f8c
PT
1104 }
1105
f1fae91f 1106 fTimeProvider.setStartFinishTimeNotify(time0, time1);
837a2f8c
PT
1107 }
1108
1109 /**
1110 * zoom out using single click
1111 */
1112 public void zoomOut() {
f1fae91f
PT
1113 long prevTime0 = fTimeProvider.getTime0();
1114 long prevTime1 = fTimeProvider.getTime1();
baf92cac
AM
1115 ITimeDataProvider provider = fTimeProvider;
1116 long selTime = (provider.getSelectionEnd() + provider.getSelectionBegin()) / 2;
f1fae91f
PT
1117 if (selTime <= prevTime0 || selTime >= prevTime1) {
1118 selTime = (prevTime0 + prevTime1) / 2;
837a2f8c 1119 }
f1fae91f
PT
1120 long time0 = (long) (selTime - (selTime - prevTime0) * ZOOM_FACTOR);
1121 long time1 = (long) (selTime + (prevTime1 - selTime) * ZOOM_FACTOR);
837a2f8c 1122
f1fae91f 1123 long inaccuracy = (fTimeProvider.getMaxTime() - fTimeProvider.getMinTime()) - (time1 - time0);
837a2f8c 1124 if (inaccuracy > 0 && inaccuracy < 100) {
f1fae91f 1125 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getMinTime(), fTimeProvider.getMaxTime());
837a2f8c
PT
1126 return;
1127 }
1128
f1fae91f 1129 fTimeProvider.setStartFinishTimeNotify(time0, time1);
837a2f8c
PT
1130 }
1131
3bd20aa6
PT
1132 /**
1133 * Zoom vertically.
1134 *
1135 * @param zoomIn
1136 * true to zoom in, false to zoom out
3bd20aa6
PT
1137 * @since 2.0
1138 */
83d0971d 1139 public void verticalZoom(boolean zoomIn) {
3bd20aa6
PT
1140 if (zoomIn) {
1141 fHeightAdjustment++;
1142 } else {
1143 fHeightAdjustment--;
1144 }
83d0971d 1145 fItemData.refreshData();
3bd20aa6
PT
1146 redraw();
1147 }
1148
1149 /**
1150 * Reset the vertical zoom to default.
1151 *
3bd20aa6
PT
1152 * @since 2.0
1153 */
83d0971d 1154 public void resetVerticalZoom() {
3bd20aa6 1155 fHeightAdjustment = 0;
83d0971d 1156 fItemData.refreshData();
3bd20aa6
PT
1157 redraw();
1158 }
1159
55d1fc96
PT
1160 /**
1161 * Set the grid lines visibility. The default is true.
1162 *
1163 * @param visible
1164 * true to show the grid lines, false otherwise
1165 * @since 2.0
1166 */
1167 public void setGridLinesVisible(boolean visible) {
1168 fGridLinesVisible = visible;
1169 }
1170
1171 /**
1172 * Get the grid lines visibility.
1173 *
1174 * @return true if the grid lines are visible, false otherwise
1175 * @since 2.0
1176 */
1177 public boolean getGridLinesVisible() {
1178 return fGridLinesVisible;
1179 }
1180
1181 /**
1182 * Set the grid line color. The default is SWT.COLOR_GRAY.
1183 *
1184 * @param color
1185 * the grid line color
1186 * @since 2.0
1187 */
1188 public void setGridLineColor(Color color) {
1189 fGridLineColor = color;
1190 }
1191
1192 /**
1193 * Get the grid line color.
1194 *
1195 * @return the grid line color
1196 * @since 2.0
1197 */
1198 public Color getGridLineColor() {
1199 return fGridLineColor;
1200 }
1201
56b43ab2
PT
1202 /**
1203 * Set the markers list.
1204 *
1205 * @param markers
1206 * The markers list, or null
1207 * @since 2.0
1208 */
1209 public void setMarkers(List<IMarkerEvent> markers) {
1210 fMarkers = markers;
56b43ab2
PT
1211 }
1212
1213 /**
1214 * Get the markers list.
1215 *
1216 * @return The markers list, or null
1217 * @since 2.0
1218 */
1219 public List<IMarkerEvent> getMarkers() {
1220 return fMarkers;
1221 }
1222
1223 /**
1224 * Set the markers visibility. The default is true.
1225 *
1226 * @param visible
1227 * true to show the markers, false otherwise
1228 * @since 2.0
1229 */
1230 public void setMarkersVisible(boolean visible) {
1231 fMarkersVisible = visible;
56b43ab2
PT
1232 }
1233
1234 /**
1235 * Get the markers visibility.
1236 *
1237 * @return true if the markers are visible, false otherwise
1238 * @since 2.0
1239 */
1240 public boolean getMarkersVisible() {
1241 return fMarkersVisible;
1242 }
1243
79ec0b89
PT
1244 /**
1245 * Hide arrows
1246 *
1247 * @param hideArrows true to hide arrows
79ec0b89
PT
1248 */
1249 public void hideArrows(boolean hideArrows) {
1250 fHideArrows = hideArrows;
1251 }
1252
086f21ae
PT
1253 /**
1254 * Follow the arrow forward
33fa1fc7
PT
1255 *
1256 * @param extend
1257 * true to extend selection range, false for single selection
1258 * @since 1.0
086f21ae 1259 */
33fa1fc7 1260 public void followArrowFwd(boolean extend) {
086f21ae
PT
1261 ITimeGraphEntry trace = getSelectedTrace();
1262 if (trace == null) {
1263 return;
1264 }
33fa1fc7 1265 long selectedTime = fTimeProvider.getSelectionEnd();
086f21ae
PT
1266 for (ILinkEvent link : fItemData.fLinks) {
1267 if (link.getEntry() == trace && link.getTime() == selectedTime) {
1268 selectItem(link.getDestinationEntry(), false);
1269 if (link.getDuration() != 0) {
33fa1fc7 1270 if (extend) {
84c8aef7 1271 fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime() + link.getDuration(), true);
33fa1fc7
PT
1272 } else {
1273 fTimeProvider.setSelectedTimeNotify(link.getTime() + link.getDuration(), true);
1274 }
086f21ae
PT
1275 // Notify if visible time window has been adjusted
1276 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getTime0(), fTimeProvider.getTime1());
1277 }
1278 fireSelectionChanged();
33fa1fc7 1279 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
086f21ae
PT
1280 return;
1281 }
1282 }
33fa1fc7 1283 selectNextEvent(extend);
086f21ae
PT
1284 }
1285
1286 /**
1287 * Follow the arrow backward
33fa1fc7
PT
1288 *
1289 * @param extend
1290 * true to extend selection range, false for single selection
1291 * @since 1.0
086f21ae 1292 */
33fa1fc7 1293 public void followArrowBwd(boolean extend) {
086f21ae
PT
1294 ITimeGraphEntry trace = getSelectedTrace();
1295 if (trace == null) {
1296 return;
1297 }
33fa1fc7 1298 long selectedTime = fTimeProvider.getSelectionEnd();
086f21ae
PT
1299 for (ILinkEvent link : fItemData.fLinks) {
1300 if (link.getDestinationEntry() == trace && link.getTime() + link.getDuration() == selectedTime) {
1301 selectItem(link.getEntry(), false);
1302 if (link.getDuration() != 0) {
33fa1fc7 1303 if (extend) {
84c8aef7 1304 fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime(), true);
33fa1fc7
PT
1305 } else {
1306 fTimeProvider.setSelectedTimeNotify(link.getTime(), true);
1307 }
086f21ae
PT
1308 // Notify if visible time window has been adjusted
1309 fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getTime0(), fTimeProvider.getTime1());
1310 }
1311 fireSelectionChanged();
33fa1fc7 1312 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
086f21ae
PT
1313 return;
1314 }
1315 }
33fa1fc7 1316 selectPrevEvent(extend);
086f21ae
PT
1317 }
1318
837a2f8c
PT
1319 /**
1320 * Return the currently selected trace
1321 *
1322 * @return The entry matching the trace
1323 */
1324 public ITimeGraphEntry getSelectedTrace() {
1325 ITimeGraphEntry trace = null;
1326 int idx = getSelectedIndex();
1327 if (idx >= 0) {
70e10acc 1328 trace = fItemData.fExpandedItems[idx].fEntry;
837a2f8c
PT
1329 }
1330 return trace;
1331 }
1332
1333 /**
1334 * Retrieve the index of the currently selected item
1335 *
1336 * @return The index
1337 */
1338 public int getSelectedIndex() {
1339 int idx = -1;
f1fae91f
PT
1340 for (int i = 0; i < fItemData.fExpandedItems.length; i++) {
1341 Item item = fItemData.fExpandedItems[i];
1342 if (item.fSelected) {
837a2f8c
PT
1343 idx = i;
1344 break;
1345 }
1346 }
1347 return idx;
1348 }
1349
1350 boolean toggle(int idx) {
1351 boolean toggled = false;
f1fae91f
PT
1352 if (idx >= 0 && idx < fItemData.fExpandedItems.length) {
1353 Item item = fItemData.fExpandedItems[idx];
1354 if (item.fHasChildren) {
1355 item.fExpanded = !item.fExpanded;
1356 fItemData.updateExpandedItems();
837a2f8c
PT
1357 redraw();
1358 toggled = true;
70e10acc 1359 fireTreeEvent(item.fEntry, item.fExpanded);
837a2f8c
PT
1360 }
1361 }
1362 return toggled;
1363 }
1364
bedfbbb5
XR
1365 /**
1366 * Gets the index of the item at the given location.
1367 *
1368 * @param y
1369 * the y coordinate
1370 * @return the index of the item at the given location, of -1 if none.
bedfbbb5
XR
1371 */
1372 protected int getItemIndexAtY(int y) {
c004295c 1373 int ySum = 0;
48072ae3
PT
1374 if (y < 0) {
1375 for (int idx = fTopIndex - 1; idx >= 0; idx--) {
1376 ySum -= fItemData.fExpandedItems[idx].fItemHeight;
1377 if (y >= ySum) {
1378 return idx;
1379 }
1380 }
1381 } else {
1382 for (int idx = fTopIndex; idx < fItemData.fExpandedItems.length; idx++) {
1383 ySum += fItemData.fExpandedItems[idx].fItemHeight;
1384 if (y < ySum) {
1385 return idx;
1386 }
837a2f8c 1387 }
837a2f8c
PT
1388 }
1389 return -1;
1390 }
1391
1392 boolean isOverSplitLine(int x) {
f1fae91f 1393 if (x < 0 || null == fTimeProvider) {
837a2f8c
PT
1394 return false;
1395 }
f1fae91f 1396 int nameWidth = fTimeProvider.getNameSpace();
0fcf3b09 1397 return Math.abs(x - nameWidth) < SNAP_WIDTH;
837a2f8c
PT
1398 }
1399
bedfbbb5
XR
1400 /**
1401 * Gets the {@link ITimeGraphEntry} at the given location.
1402 *
1403 * @param pt
1404 * a point in the widget
1405 * @return the {@link ITimeGraphEntry} at this point, or <code>null</code>
1406 * if none.
8c684b48 1407 * @since 2.0
bedfbbb5 1408 */
8c684b48 1409 public ITimeGraphEntry getEntry(Point pt) {
837a2f8c 1410 int idx = getItemIndexAtY(pt.y);
70e10acc 1411 return idx >= 0 ? fItemData.fExpandedItems[idx].fEntry : null;
837a2f8c
PT
1412 }
1413
1053eaa6
PT
1414 /**
1415 * Return the arrow event closest to the given point that is no further than
1416 * a maximum distance.
1417 *
1418 * @param pt
1419 * a point in the widget
1420 * @return The closest arrow event, or null if there is none close enough.
1053eaa6
PT
1421 */
1422 protected ILinkEvent getArrow(Point pt) {
1423 if (fHideArrows) {
1424 return null;
1425 }
1426 ILinkEvent linkEvent = null;
1427 double minDistance = Double.MAX_VALUE;
1428 for (ILinkEvent event : fItemData.fLinks) {
1429 Rectangle rect = getArrowRectangle(new Rectangle(0, 0, 0, 0), event);
1430 if (rect != null) {
1431 int x1 = rect.x;
1432 int y1 = rect.y;
1433 int x2 = x1 + rect.width;
1434 int y2 = y1 + rect.height;
1435 double d = Utils.distance(pt.x, pt.y, x1, y1, x2, y2);
1436 if (minDistance > d) {
1437 minDistance = d;
1438 linkEvent = event;
1439 }
1440 }
1441 }
1442 if (minDistance <= ARROW_HOVER_MAX_DIST) {
1443 return linkEvent;
1444 }
1445 return null;
1446 }
1447
4999a196 1448 @Override
713a70ae 1449 public int getXForTime(long time) {
f1fae91f 1450 if (null == fTimeProvider) {
713a70ae
PT
1451 return -1;
1452 }
f1fae91f
PT
1453 long time0 = fTimeProvider.getTime0();
1454 long time1 = fTimeProvider.getTime1();
b698ec63 1455 int width = getSize().x;
f1fae91f 1456 int nameSpace = fTimeProvider.getNameSpace();
713a70ae
PT
1457 double pixelsPerNanoSec = (width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (width - nameSpace - RIGHT_MARGIN) / (time1 - time0);
1458 int x = getBounds().x + nameSpace + (int) ((time - time0) * pixelsPerNanoSec);
1459 return x;
1460 }
1461
4999a196 1462 @Override
41b5c37f 1463 public long getTimeAtX(int coord) {
f1fae91f 1464 if (null == fTimeProvider) {
837a2f8c
PT
1465 return -1;
1466 }
1467 long hitTime = -1;
b698ec63 1468 Point size = getSize();
f1fae91f
PT
1469 long time0 = fTimeProvider.getTime0();
1470 long time1 = fTimeProvider.getTime1();
1471 int nameWidth = fTimeProvider.getNameSpace();
41b5c37f 1472 final int x = coord - nameWidth;
837a2f8c
PT
1473 int timeWidth = size.x - nameWidth - RIGHT_MARGIN;
1474 if (x >= 0 && size.x >= nameWidth) {
1475 if (time1 - time0 > timeWidth) {
1476 // nanosecond smaller than one pixel: use the first integer nanosecond of this pixel's time range
1477 hitTime = time0 + (long) Math.ceil((time1 - time0) * ((double) x / timeWidth));
1478 } else {
1479 // nanosecond greater than one pixel: use the nanosecond that covers this pixel start position
1480 hitTime = time0 + (long) Math.floor((time1 - time0) * ((double) x / timeWidth));
1481 }
1482 }
1483 return hitTime;
1484 }
1485
1486 void selectItem(int idx, boolean addSelection) {
1487 boolean changed = false;
1488 if (addSelection) {
f1fae91f
PT
1489 if (idx >= 0 && idx < fItemData.fExpandedItems.length) {
1490 Item item = fItemData.fExpandedItems[idx];
1491 changed = !item.fSelected;
1492 item.fSelected = true;
837a2f8c
PT
1493 }
1494 } else {
f1fae91f
PT
1495 for (int i = 0; i < fItemData.fExpandedItems.length; i++) {
1496 Item item = fItemData.fExpandedItems[i];
1497 if ((i == idx && !item.fSelected) || (idx == -1 && item.fSelected)) {
837a2f8c
PT
1498 changed = true;
1499 }
f1fae91f 1500 item.fSelected = i == idx;
837a2f8c
PT
1501 }
1502 }
1503 changed |= ensureVisibleItem(idx, true);
1504 if (changed) {
1505 redraw();
1506 }
1507 }
1508
1509 /**
1510 * Callback for item selection
1511 *
1512 * @param trace
1513 * The entry matching the trace
1514 * @param addSelection
1515 * If the selection is added or removed
1516 */
1517 public void selectItem(ITimeGraphEntry trace, boolean addSelection) {
f1fae91f 1518 int idx = fItemData.findItemIndex(trace);
837a2f8c
PT
1519 selectItem(idx, addSelection);
1520 }
1521
1522 /**
1523 * Retrieve the number of entries shown per page.
1524 *
1525 * @return The count
1526 */
1527 public int countPerPage() {
b698ec63 1528 int height = getSize().y;
837a2f8c 1529 int count = 0;
c004295c
PT
1530 int ySum = 0;
1531 for (int idx = fTopIndex; idx < fItemData.fExpandedItems.length; idx++) {
1532 ySum += fItemData.fExpandedItems[idx].fItemHeight;
1533 if (ySum >= height) {
1534 return count;
837a2f8c 1535 }
c004295c 1536 count++;
837a2f8c 1537 }
c004295c
PT
1538 for (int idx = fTopIndex - 1; idx >= 0; idx--) {
1539 ySum += fItemData.fExpandedItems[idx].fItemHeight;
1540 if (ySum >= height) {
1541 return count;
1542 }
1543 count++;
837a2f8c
PT
1544 }
1545 return count;
1546 }
1547
1548 /**
1549 * Get the index of the top element
1550 *
1551 * @return The index
1552 */
1553 public int getTopIndex() {
f1fae91f 1554 return fTopIndex;
837a2f8c
PT
1555 }
1556
1557 /**
df0e3d5f 1558 * Get the number of expanded (visible) items
837a2f8c 1559 *
df0e3d5f 1560 * @return The count of expanded (visible) items
837a2f8c
PT
1561 */
1562 public int getExpandedElementCount() {
f1fae91f 1563 return fItemData.fExpandedItems.length;
837a2f8c
PT
1564 }
1565
1566 /**
df0e3d5f 1567 * Get an array of all expanded (visible) elements
837a2f8c 1568 *
df0e3d5f 1569 * @return The expanded (visible) elements
837a2f8c
PT
1570 */
1571 public ITimeGraphEntry[] getExpandedElements() {
507b1336 1572 ArrayList<ITimeGraphEntry> elements = new ArrayList<>();
f1fae91f 1573 for (Item item : fItemData.fExpandedItems) {
70e10acc 1574 elements.add(item.fEntry);
837a2f8c
PT
1575 }
1576 return elements.toArray(new ITimeGraphEntry[0]);
1577 }
1578
48072ae3
PT
1579 /**
1580 * Get the expanded (visible) element at the specified index.
1581 *
1582 * @param index
1583 * the element index
1584 * @return The expanded (visible) element or null if out of range
1585 * @since 2.0
1586 */
1587 public ITimeGraphEntry getExpandedElement(int index) {
1588 if (index < 0 || index >= fItemData.fExpandedItems.length) {
1589 return null;
1590 }
1591 return fItemData.fExpandedItems[index].fEntry;
1592 }
1593
83b36bb4
PT
1594 Rectangle getNameRect(Rectangle bounds, int idx, int nameWidth) {
1595 Rectangle rect = getItemRect(bounds, idx);
c004295c
PT
1596 rect.width = nameWidth;
1597 return rect;
837a2f8c
PT
1598 }
1599
83b36bb4
PT
1600 Rectangle getStatesRect(Rectangle bounds, int idx, int nameWidth) {
1601 Rectangle rect = getItemRect(bounds, idx);
1602 rect.x += nameWidth;
1603 rect.width -= nameWidth;
1604 return rect;
1605 }
1606
1607 Rectangle getItemRect(Rectangle bounds, int idx) {
c004295c
PT
1608 int ySum = 0;
1609 if (idx >= fTopIndex) {
f1fae91f
PT
1610 for (int i = fTopIndex; i < idx; i++) {
1611 ySum += fItemData.fExpandedItems[i].fItemHeight;
837a2f8c 1612 }
c004295c
PT
1613 } else {
1614 for (int i = fTopIndex - 1; i >= idx; i--) {
1615 ySum -= fItemData.fExpandedItems[i].fItemHeight;
1616 }
837a2f8c 1617 }
83b36bb4 1618 int y = bounds.y + ySum;
c004295c 1619 int height = fItemData.fExpandedItems[idx].fItemHeight;
83b36bb4 1620 return new Rectangle(bounds.x, y, bounds.width, height);
837a2f8c
PT
1621 }
1622
1623 @Override
1624 void paint(Rectangle bounds, PaintEvent e) {
1625 GC gc = e.gc;
837a2f8c 1626
f1fae91f 1627 if (bounds.width < 2 || bounds.height < 2 || null == fTimeProvider) {
837a2f8c
PT
1628 return;
1629 }
1630
f1fae91f
PT
1631 fIdealNameSpace = 0;
1632 int nameSpace = fTimeProvider.getNameSpace();
837a2f8c 1633
1c67fff3 1634 // draw the background layer
83b36bb4 1635 drawBackground(bounds, nameSpace, gc);
837a2f8c 1636
55d1fc96
PT
1637 // draw the grid lines
1638 drawGridLines(bounds, gc);
1639
56b43ab2
PT
1640 // draw the background markers
1641 drawMarkers(bounds, fTimeProvider, fMarkers, false, nameSpace, gc);
1642
1c67fff3 1643 // draw the items
f1fae91f 1644 drawItems(bounds, fTimeProvider, fItemData.fExpandedItems, fTopIndex, nameSpace, gc);
1c67fff3 1645
56b43ab2
PT
1646 // draw the foreground markers
1647 drawMarkers(bounds, fTimeProvider, fMarkers, true, nameSpace, gc);
1648
1c67fff3 1649 // draw the links (arrows)
bec1f1ac 1650 drawLinks(bounds, fTimeProvider, fItemData.fLinks, nameSpace, gc);
1c67fff3 1651
bec1f1ac 1652 fTimeGraphProvider.postDrawControl(bounds, gc);
837a2f8c 1653
0fcf3b09
PT
1654 int alpha = gc.getAlpha();
1655 gc.setAlpha(100);
1656
f1fae91f
PT
1657 long time0 = fTimeProvider.getTime0();
1658 long time1 = fTimeProvider.getTime1();
baf92cac
AM
1659 long selectionBegin = fTimeProvider.getSelectionBegin();
1660 long selectionEnd = fTimeProvider.getSelectionEnd();
837a2f8c 1661 double pixelsPerNanoSec = (bounds.width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (bounds.width - nameSpace - RIGHT_MARGIN) / (time1 - time0);
0fcf3b09
PT
1662 int x0 = bounds.x + nameSpace + (int) ((selectionBegin - time0) * pixelsPerNanoSec);
1663 int x1 = bounds.x + nameSpace + (int) ((selectionEnd - time0) * pixelsPerNanoSec);
1664
1665 // draw selection lines
1666 if (fDragState != DRAG_SELECTION) {
f1fae91f 1667 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.SELECTED_TIME));
0fcf3b09
PT
1668 if (x0 >= nameSpace && x0 < bounds.x + bounds.width) {
1669 gc.drawLine(x0, bounds.y, x0, bounds.y + bounds.height);
1670 }
1671 if (x1 != x0) {
1672 if (x1 >= nameSpace && x1 < bounds.x + bounds.width) {
1673 gc.drawLine(x1, bounds.y, x1, bounds.y + bounds.height);
1674 }
1675 }
837a2f8c
PT
1676 }
1677
0fcf3b09
PT
1678 // draw selection background
1679 if (selectionBegin != 0 && selectionEnd != 0 && fDragState != DRAG_SELECTION) {
1680 x0 = Math.max(nameSpace, Math.min(bounds.x + bounds.width, x0));
1681 x1 = Math.max(nameSpace, Math.min(bounds.x + bounds.width, x1));
1682 gc.setBackground(getColorScheme().getBkColor(false, false, true));
1683 if (x1 - x0 > 1) {
1684 gc.fillRectangle(new Rectangle(x0 + 1, bounds.y, x1 - x0 - 1, bounds.height));
1685 } else if (x0 - x1 > 1) {
1686 gc.fillRectangle(new Rectangle(x1 + 1, bounds.y, x0 - x1 - 1, bounds.height));
1687 }
1688 }
1689
1690 // draw drag selection background
1691 if (fDragState == DRAG_ZOOM || fDragState == DRAG_SELECTION) {
1692 gc.setBackground(getColorScheme().getBkColor(false, false, true));
1693 if (fDragX0 < fDragX) {
1694 gc.fillRectangle(new Rectangle(fDragX0, bounds.y, fDragX - fDragX0, bounds.height));
1695 } else if (fDragX0 > fDragX) {
1696 gc.fillRectangle(new Rectangle(fDragX, bounds.y, fDragX0 - fDragX, bounds.height));
1697 }
1698 }
1699
1700 // draw drag line
f1fae91f
PT
1701 if (DRAG_SPLIT_LINE == fDragState) {
1702 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.BLACK));
837a2f8c 1703 gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1);
0fcf3b09 1704 } else if (DRAG_ZOOM == fDragState && Math.max(fDragX, fDragX0) > nameSpace) {
f1fae91f
PT
1705 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.TOOL_FOREGROUND));
1706 gc.drawLine(fDragX0, bounds.y, fDragX0, bounds.y + bounds.height - 1);
0fcf3b09
PT
1707 if (fDragX != fDragX0) {
1708 gc.drawLine(fDragX, bounds.y, fDragX, bounds.y + bounds.height - 1);
1709 }
1710 } else if (DRAG_SELECTION == fDragState && Math.max(fDragX, fDragX0) > nameSpace) {
1711 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.SELECTED_TIME));
1712 gc.drawLine(fDragX0, bounds.y, fDragX0, bounds.y + bounds.height - 1);
1713 if (fDragX != fDragX0) {
1714 gc.drawLine(fDragX, bounds.y, fDragX, bounds.y + bounds.height - 1);
1715 }
f1fae91f
PT
1716 } else if (DRAG_NONE == fDragState && fMouseOverSplitLine && fTimeProvider.getNameSpace() > 0) {
1717 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.RED));
837a2f8c
PT
1718 gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1);
1719 }
0fcf3b09
PT
1720
1721 gc.setAlpha(alpha);
837a2f8c
PT
1722 }
1723
83b36bb4 1724 /**
1c67fff3
PT
1725 * Draw the background layer. Fills the background of the control's name
1726 * space and states space, updates the background of items if necessary,
1727 * and draws the item's name text and middle line.
83b36bb4
PT
1728 *
1729 * @param bounds
1c67fff3 1730 * The bounds of the control
83b36bb4 1731 * @param nameSpace
1c67fff3 1732 * The name space width
83b36bb4 1733 * @param gc
1c67fff3 1734 * Graphics context
83b36bb4
PT
1735 * @since 2.0
1736 */
1737 protected void drawBackground(Rectangle bounds, int nameSpace, GC gc) {
1738 // draw empty name space background
1739 gc.setBackground(getColorScheme().getBkColor(false, false, true));
1740 drawBackground(gc, bounds.x, bounds.y, nameSpace, bounds.height);
1741
1742 // draw empty states space background
1743 gc.setBackground(getColorScheme().getColor(TimeGraphColorScheme.BACKGROUND));
1744 drawBackground(gc, bounds.x + nameSpace, bounds.y, bounds.width - nameSpace, bounds.height);
1745
83b36bb4
PT
1746 for (int i = fTopIndex; i < fItemData.fExpandedItems.length; i++) {
1747 Rectangle itemRect = getItemRect(bounds, i);
1748 if (itemRect.y >= bounds.y + bounds.height) {
1749 break;
1750 }
1751 Item item = fItemData.fExpandedItems[i];
1c67fff3 1752 // draw the background of selected item and items with no time events
83b36bb4
PT
1753 if (! item.fEntry.hasTimeEvents()) {
1754 gc.setBackground(getColorScheme().getBkColorGroup(item.fSelected, fIsInFocus));
1755 gc.fillRectangle(itemRect);
1756 } else if (item.fSelected) {
1757 gc.setBackground(getColorScheme().getBkColor(true, fIsInFocus, true));
1758 gc.fillRectangle(itemRect.x, itemRect.y, nameSpace, itemRect.height);
1759 gc.setBackground(getColorScheme().getBkColor(true, fIsInFocus, false));
1760 gc.fillRectangle(nameSpace, itemRect.y, itemRect.width - nameSpace, itemRect.height);
1761 }
1c67fff3
PT
1762 // draw the name and middle line
1763 if (! item.fEntry.hasTimeEvents()) {
1764 drawName(item, itemRect, gc);
1765 } else {
1766 Rectangle nameRect = new Rectangle(itemRect.x, itemRect.y, nameSpace, itemRect.height);
1767 drawName(item, nameRect, gc);
1768 Rectangle rect = new Rectangle(nameSpace, itemRect.y, itemRect.width - nameSpace, itemRect.height);
1769 drawMidLine(rect, gc);
1770 }
83b36bb4
PT
1771 }
1772 }
1773
55d1fc96
PT
1774 /**
1775 * Draw the grid lines
1776 *
1777 * @param bounds
1c67fff3 1778 * The bounds of the control
55d1fc96 1779 * @param gc
1c67fff3 1780 * Graphics context
55d1fc96
PT
1781 * @since 2.0
1782 */
1783 public void drawGridLines(Rectangle bounds, GC gc) {
1784 if (!fGridLinesVisible) {
1785 return;
1786 }
1787 gc.setForeground(fGridLineColor);
56b43ab2 1788 gc.setAlpha(fGridLineColor.getAlpha());
55d1fc96
PT
1789 for (int x : fTimeGraphScale.getTickList()) {
1790 gc.drawLine(x, bounds.y, x, bounds.y + bounds.height);
1791 }
56b43ab2
PT
1792 gc.setAlpha(255);
1793 }
1794
1795 /**
1796 * Draw the markers
1797 *
1798 * @param bounds
1799 * The rectangle of the area
1800 * @param timeProvider
1801 * The time provider
1802 * @param markers
1803 * The list of markers
1804 * @param foreground
1805 * true to draw the foreground markers, false otherwise
1806 * @param nameSpace
1807 * The width reserved for the names
1808 * @param gc
1809 * Reference to the SWT GC object
1810 * @since 2.0
1811 */
1812 protected void drawMarkers(Rectangle bounds, ITimeDataProvider timeProvider, List<IMarkerEvent> markers, boolean foreground, int nameSpace, GC gc) {
1813 if (!fMarkersVisible || markers == null || markers.isEmpty()) {
1814 return;
1815 }
1816 gc.setClipping(new Rectangle(nameSpace, 0, bounds.width - nameSpace, bounds.height));
1817 /* the list can grow concurrently but cannot shrink */
1818 for (int i = 0; i < markers.size(); i++) {
1819 IMarkerEvent marker = markers.get(i);
1820 if (marker.isForeground() == foreground) {
1821 drawMarker(marker, bounds, timeProvider, nameSpace, gc);
1822 }
1823 }
1824 gc.setClipping((Rectangle) null);
1825 }
1826
1827 /**
1828 * Draw a single marker
1829 *
1830 * @param marker
1831 * The marker event
1832 * @param bounds
1833 * The bounds of the control
1834 * @param timeProvider
1835 * The time provider
1836 * @param nameSpace
1837 * The width reserved for the name
1838 * @param gc
1839 * Reference to the SWT GC object
1840 * @since 2.0
1841 */
1842 protected void drawMarker(IMarkerEvent marker, Rectangle bounds, ITimeDataProvider timeProvider, int nameSpace, GC gc) {
1843 Rectangle rect = Utils.clone(bounds);
1844 if (marker.getEntry() != null) {
1845 int index = fItemData.findItemIndex(marker.getEntry());
1846 if (index == -1) {
1847 return;
1848 }
1849 rect = getStatesRect(bounds, index, nameSpace);
1850 if (rect.y < 0 || rect.y > bounds.height) {
1851 return;
1852 }
1853 }
1854 int x0 = getXForTime(marker.getTime());
1855 int x1 = getXForTime(marker.getTime() + marker.getDuration());
1856 if (x0 > bounds.width || x1 < nameSpace) {
1857 return;
1858 }
1859 rect.x = Math.max(nameSpace, Math.min(bounds.width, x0));
1860 rect.width = Math.max(1, Math.min(bounds.width, x1) - rect.x);
1861
8910dea2
PT
1862 Color color = getColorScheme().getColor(marker.getColor());
1863 gc.setBackground(color);
1864 gc.setAlpha(color.getAlpha());
56b43ab2
PT
1865 gc.fillRectangle(rect);
1866 gc.setAlpha(255);
1867 String label = marker.getLabel();
1868 if (label != null && marker.getEntry() != null) {
1d012443 1869 label = label.substring(0, Math.min(label.indexOf('\n') != -1 ? label.indexOf('\n') : label.length(), MAX_LABEL_LENGTH));
8910dea2 1870 gc.setForeground(color);
1d012443 1871 Utils.drawText(gc, label, rect.x - gc.textExtent(label).x, rect.y, true);
56b43ab2 1872 }
55d1fc96
PT
1873 }
1874
837a2f8c
PT
1875 /**
1876 * Draw many items at once
1877 *
1878 * @param bounds
1c67fff3 1879 * The bounds of the control
837a2f8c
PT
1880 * @param timeProvider
1881 * The time provider
1882 * @param items
1883 * The array items to draw
1884 * @param topIndex
1885 * The index of the first element to draw
1886 * @param nameSpace
1c67fff3 1887 * The name space width
837a2f8c 1888 * @param gc
1c67fff3 1889 * Graphics context
837a2f8c
PT
1890 */
1891 public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider,
1892 Item[] items, int topIndex, int nameSpace, GC gc) {
1893 for (int i = topIndex; i < items.length; i++) {
1894 Item item = items[i];
1895 drawItem(item, bounds, timeProvider, i, nameSpace, gc);
1896 }
837a2f8c
PT
1897 }
1898
1899 /**
1900 * Draws the item
1901 *
1c67fff3
PT
1902 * @param item
1903 * The item to draw
1904 * @param bounds
1905 * The bounds of the control
1906 * @param timeProvider
1907 * The time provider
1908 * @param i
1909 * The expanded item index
1910 * @param nameSpace
1911 * The name space width
1912 * @param gc
1913 * Graphics context
837a2f8c
PT
1914 */
1915 protected void drawItem(Item item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) {
83b36bb4
PT
1916 Rectangle itemRect = getItemRect(bounds, i);
1917 if (itemRect.y >= bounds.y + bounds.height) {
1918 return;
1919 }
1920
70e10acc 1921 ITimeGraphEntry entry = item.fEntry;
837a2f8c
PT
1922 long time0 = timeProvider.getTime0();
1923 long time1 = timeProvider.getTime1();
33fa1fc7 1924 long selectedTime = fTimeProvider.getSelectionEnd();
837a2f8c 1925
83b36bb4 1926 Rectangle rect = new Rectangle(nameSpace, itemRect.y, itemRect.width - nameSpace, itemRect.height);
1c67fff3 1927 if (rect.isEmpty() || (time1 <= time0)) {
837a2f8c
PT
1928 fTimeGraphProvider.postDrawEntry(entry, rect, gc);
1929 return;
1930 }
1931
f1fae91f 1932 boolean selected = item.fSelected;
837a2f8c
PT
1933 // K pixels per second
1934 double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0);
1935
70e10acc 1936 if (item.fEntry.hasTimeEvents()) {
ab0a54d5 1937 gc.setClipping(new Rectangle(nameSpace, 0, bounds.width - nameSpace, bounds.height));
837a2f8c 1938 fillSpace(rect, gc, selected);
83d0971d
PT
1939
1940 int margins = getMarginForHeight(rect.height);
1941 int height = rect.height - margins;
1942 int topMargin = (margins + 1) / 2;
1943 Rectangle stateRect = new Rectangle(rect.x, rect.y + topMargin, rect.width, height);
1944
1945 /* Set the font for this item */
1946 setFontForHeight(height, gc);
837a2f8c
PT
1947
1948 long maxDuration = (timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (time1 - time0) / timeProvider.getTimeSpace();
1949 Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator(time0, time1, maxDuration);
1950
1951 int lastX = -1;
1952 while (iterator.hasNext()) {
1953 ITimeEvent event = iterator.next();
1954 int x = rect.x + (int) ((event.getTime() - time0) * pixelsPerNanoSec);
1955 int xEnd = rect.x + (int) ((event.getTime() + event.getDuration() - time0) * pixelsPerNanoSec);
1956 if (x >= rect.x + rect.width || xEnd < rect.x) {
1957 // event is out of bounds
1958 continue;
1959 }
1960 xEnd = Math.min(rect.x + rect.width, xEnd);
1961 stateRect.x = Math.max(rect.x, x);
1962 stateRect.width = Math.max(0, xEnd - stateRect.x + 1);
1963 if (stateRect.x == lastX) {
1964 stateRect.width -= 1;
1965 if (stateRect.width > 0) {
1966 gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
1967 gc.drawPoint(stateRect.x, stateRect.y - 2);
1968 stateRect.x += 1;
1969 }
837a2f8c
PT
1970 }
1971 boolean timeSelected = selectedTime >= event.getTime() && selectedTime < event.getTime() + event.getDuration();
f1fae91f 1972 if (drawState(getColorScheme(), event, stateRect, gc, selected, timeSelected)) {
b052914f 1973 lastX = stateRect.x;
ad128fd8 1974 }
837a2f8c 1975 }
ab0a54d5 1976 gc.setClipping((Rectangle) null);
837a2f8c
PT
1977 }
1978 fTimeGraphProvider.postDrawEntry(entry, rect, gc);
1979 }
1980
bec1f1ac
GB
1981 /**
1982 * Draw the links
1983 *
1984 * @param bounds
1c67fff3 1985 * The bounds of the control
bec1f1ac
GB
1986 * @param timeProvider
1987 * The time provider
1988 * @param links
6ae6c5bd 1989 * The list of link events
bec1f1ac 1990 * @param nameSpace
1c67fff3 1991 * The name space width
bec1f1ac 1992 * @param gc
1c67fff3 1993 * Graphics context
bec1f1ac
GB
1994 */
1995 public void drawLinks(Rectangle bounds, ITimeDataProvider timeProvider,
1996 List<ILinkEvent> links, int nameSpace, GC gc) {
79ec0b89
PT
1997 if (fHideArrows) {
1998 return;
1999 }
ab0a54d5 2000 gc.setClipping(new Rectangle(nameSpace, 0, bounds.width - nameSpace, bounds.height));
6ae6c5bd
PT
2001 /* the list can grow concurrently but cannot shrink */
2002 for (int i = 0; i < links.size(); i++) {
2003 drawLink(links.get(i), bounds, timeProvider, nameSpace, gc);
bec1f1ac 2004 }
ab0a54d5 2005 gc.setClipping((Rectangle) null);
bec1f1ac
GB
2006 }
2007
2008 /**
1c67fff3 2009 * Draws a link type event
bec1f1ac
GB
2010 *
2011 * @param event
1c67fff3 2012 * The link event to draw
bec1f1ac 2013 * @param bounds
1c67fff3 2014 * The bounds of the control
bec1f1ac 2015 * @param timeProvider
1c67fff3 2016 * The time provider
bec1f1ac 2017 * @param nameSpace
1c67fff3 2018 * The name space width
bec1f1ac
GB
2019 * @param gc
2020 * Graphics context
bec1f1ac
GB
2021 */
2022 protected void drawLink(ILinkEvent event, Rectangle bounds, ITimeDataProvider timeProvider, int nameSpace, GC gc) {
1053eaa6
PT
2023 drawArrow(getColorScheme(), event, getArrowRectangle(bounds, event), gc);
2024 }
2025
2026 private Rectangle getArrowRectangle(Rectangle bounds, ILinkEvent event) {
bec1f1ac
GB
2027 int srcIndex = fItemData.findItemIndex(event.getEntry());
2028 int destIndex = fItemData.findItemIndex(event.getDestinationEntry());
2029
2030 if ((srcIndex == -1) || (destIndex == -1)) {
1053eaa6 2031 return null;
bec1f1ac
GB
2032 }
2033
1053eaa6
PT
2034 Rectangle src = getStatesRect(bounds, srcIndex, fTimeProvider.getNameSpace());
2035 Rectangle dst = getStatesRect(bounds, destIndex, fTimeProvider.getNameSpace());
bec1f1ac
GB
2036
2037 int x0 = getXForTime(event.getTime());
2038 int x1 = getXForTime(event.getTime() + event.getDuration());
03ab8eeb
PT
2039
2040 // limit the x-coordinates to prevent integer overflow in calculations
2041 // and also GC.drawLine doesn't draw properly with large coordinates
2042 final int limit = Integer.MAX_VALUE / 1024;
2043 x0 = Math.max(-limit, Math.min(x0, limit));
2044 x1 = Math.max(-limit, Math.min(x1, limit));
2045
bec1f1ac
GB
2046 int y0 = src.y + src.height / 2;
2047 int y1 = dst.y + dst.height / 2;
1053eaa6 2048 return new Rectangle(x0, y0, x1 - x0, y1 - y0);
bec1f1ac
GB
2049 }
2050
2051 /**
1c67fff3 2052 * Draw an arrow
bec1f1ac
GB
2053 *
2054 * @param colors
2055 * Color scheme
2056 * @param event
1c67fff3 2057 * Time event for which we're drawing the arrow
bec1f1ac 2058 * @param rect
1c67fff3 2059 * The arrow rectangle
bec1f1ac
GB
2060 * @param gc
2061 * Graphics context
1c67fff3 2062 * @return true if the arrow was drawn
bec1f1ac
GB
2063 */
2064 protected boolean drawArrow(TimeGraphColorScheme colors, ITimeEvent event,
2065 Rectangle rect, GC gc) {
2066
a5e66312
PT
2067 if (rect == null) {
2068 return false;
2069 }
bec1f1ac
GB
2070 int colorIdx = fTimeGraphProvider.getStateTableIndex(event);
2071 if (colorIdx < 0) {
2072 return false;
2073 }
2074 boolean visible = ((rect.height == 0) && (rect.width == 0)) ? false : true;
2075
2076 if (visible) {
2077 Color stateColor = null;
2078 if (colorIdx < fEventColorMap.length) {
2079 stateColor = fEventColorMap[colorIdx];
2080 } else {
2081 stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
2082 }
2083
2084 gc.setForeground(stateColor);
2085 gc.setBackground(stateColor);
2086
2087 /* Draw the arrow */
2088 gc.drawLine(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
2089 drawArrowHead(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, gc);
2090
2091 }
2092 fTimeGraphProvider.postDrawEvent(event, rect, gc);
2093 return visible;
2094 }
2095
2096 /*
2097 * @author Francis Giraldeau
2098 *
2099 * Inspiration:
2100 * http://stackoverflow.com/questions/3010803/draw-arrow-on-line-algorithm
2101 *
2102 * The algorithm was taken from this site, not the code itself
2103 */
2104 private static void drawArrowHead(int x0, int y0, int x1, int y1, GC gc)
2105 {
2106 int factor = 10;
2107 double cos = 0.9510;
2108 double sin = 0.3090;
03ab8eeb
PT
2109 long lenx = x1 - x0;
2110 long leny = y1 - y0;
bec1f1ac
GB
2111 double len = Math.sqrt(lenx * lenx + leny * leny);
2112
2113 double dx = factor * lenx / len;
2114 double dy = factor * leny / len;
2115 int end1X = (int) Math.round((x1 - (dx * cos + dy * -sin)));
2116 int end1Y = (int) Math.round((y1 - (dx * sin + dy * cos)));
2117 int end2X = (int) Math.round((x1 - (dx * cos + dy * sin)));
2118 int end2Y = (int) Math.round((y1 - (dx * -sin + dy * cos)));
2119 int[] arrow = new int[] { x1, y1, end1X, end1Y, end2X, end2Y, x1, y1 };
2120 gc.fillPolygon(arrow);
2121 }
2122
a0a88f65
AM
2123 /**
2124 * Draw the name of an item.
2125 *
2126 * @param item
2127 * Item object
2128 * @param bounds
1c67fff3 2129 * The bounds of the item's name space
a0a88f65
AM
2130 * @param gc
2131 * Graphics context
2132 */
837a2f8c 2133 protected void drawName(Item item, Rectangle bounds, GC gc) {
70e10acc 2134 boolean hasTimeEvents = item.fEntry.hasTimeEvents();
837a2f8c
PT
2135
2136 // No name to be drawn
f1fae91f 2137 if (fTimeProvider.getNameSpace() == 0) {
837a2f8c
PT
2138 return;
2139 }
2140
83d0971d
PT
2141 int height = bounds.height - getMarginForHeight(bounds.height);
2142 setFontForHeight(height, gc);
2143
f1fae91f
PT
2144 int leftMargin = MARGIN + item.fLevel * EXPAND_SIZE;
2145 if (item.fHasChildren) {
2146 gc.setForeground(getColorScheme().getFgColorGroup(false, false));
2147 gc.setBackground(getColorScheme().getBkColor(false, false, false));
837a2f8c
PT
2148 Rectangle rect = Utils.clone(bounds);
2149 rect.x += leftMargin;
2150 rect.y += (bounds.height - EXPAND_SIZE) / 2;
2151 rect.width = EXPAND_SIZE;
2152 rect.height = EXPAND_SIZE;
2153 gc.fillRectangle(rect);
2154 gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
2155 int midy = rect.y + rect.height / 2;
2156 gc.drawLine(rect.x + 2, midy, rect.x + rect.width - 3, midy);
f1fae91f 2157 if (!item.fExpanded) {
837a2f8c
PT
2158 int midx = rect.x + rect.width / 2;
2159 gc.drawLine(midx, rect.y + 2, midx, rect.y + rect.height - 3);
2160 }
2161 }
2162 leftMargin += EXPAND_SIZE + MARGIN;
2163
70e10acc 2164 Image img = fTimeGraphProvider.getItemImage(item.fEntry);
837a2f8c
PT
2165 if (img != null) {
2166 // draw icon
2167 int imgHeight = img.getImageData().height;
2168 int imgWidth = img.getImageData().width;
2169 int x = leftMargin;
2170 int y = bounds.y + (bounds.height - imgHeight) / 2;
2171 gc.drawImage(img, x, y);
2172 leftMargin += imgWidth + MARGIN;
2173 }
f1fae91f 2174 String name = item.fName;
837a2f8c 2175 Point size = gc.stringExtent(name);
f1fae91f
PT
2176 if (fIdealNameSpace < leftMargin + size.x + MARGIN) {
2177 fIdealNameSpace = leftMargin + size.x + MARGIN;
837a2f8c
PT
2178 }
2179 if (hasTimeEvents) {
2180 // cut long string with "..."
2181 int width = bounds.width - leftMargin;
2182 int cuts = 0;
2183 while (size.x > width && name.length() > 1) {
2184 cuts++;
2185 name = name.substring(0, name.length() - 1);
2186 size = gc.stringExtent(name + "..."); //$NON-NLS-1$
2187 }
2188 if (cuts > 0) {
2189 name += "..."; //$NON-NLS-1$
2190 }
2191 }
2192 Rectangle rect = Utils.clone(bounds);
2193 rect.x += leftMargin;
2194 rect.width -= leftMargin;
2195 // draw text
2196 if (rect.width > 0) {
2197 rect.y += (bounds.height - gc.stringExtent(name).y) / 2;
f1fae91f 2198 gc.setForeground(getColorScheme().getFgColor(item.fSelected, fIsInFocus));
837a2f8c
PT
2199 int textWidth = Utils.drawText(gc, name, rect, true);
2200 leftMargin += textWidth + MARGIN;
837a2f8c
PT
2201
2202 if (hasTimeEvents) {
2203 // draw middle line
1c67fff3
PT
2204 rect.x = bounds.x + leftMargin;
2205 rect.y = bounds.y;
2206 rect.width = bounds.width - rect.x;
2207 drawMidLine(rect, gc);
837a2f8c
PT
2208 }
2209 }
2210 }
2211
a0a88f65
AM
2212 /**
2213 * Draw the state (color fill)
2214 *
2215 * @param colors
2216 * Color scheme
2217 * @param event
2218 * Time event for which we're drawing the state
2219 * @param rect
1c67fff3 2220 * The state rectangle
a0a88f65
AM
2221 * @param gc
2222 * Graphics context
2223 * @param selected
2224 * Is this time event currently selected (so it appears
2225 * highlighted)
2226 * @param timeSelected
2227 * Is the timestamp currently selected
ad128fd8 2228 * @return true if the state was drawn
a0a88f65 2229 */
ad128fd8 2230 protected boolean drawState(TimeGraphColorScheme colors, ITimeEvent event,
837a2f8c
PT
2231 Rectangle rect, GC gc, boolean selected, boolean timeSelected) {
2232
2233 int colorIdx = fTimeGraphProvider.getStateTableIndex(event);
ad128fd8
PT
2234 if (colorIdx < 0 && colorIdx != ITimeGraphPresentationProvider.TRANSPARENT) {
2235 return false;
837a2f8c
PT
2236 }
2237 boolean visible = rect.width == 0 ? false : true;
b052914f 2238 rect.width = Math.max(1, rect.width);
351a2391
XR
2239 Color black = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
2240 gc.setForeground(black);
837a2f8c 2241
b052914f
PT
2242 if (colorIdx == ITimeGraphPresentationProvider.TRANSPARENT) {
2243 if (visible) {
ad128fd8 2244 // Only draw the top and bottom borders
ad128fd8
PT
2245 gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
2246 gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
2247 if (rect.width == 1) {
ad128fd8
PT
2248 gc.drawPoint(rect.x, rect.y - 2);
2249 }
837a2f8c 2250 }
b052914f
PT
2251 fTimeGraphProvider.postDrawEvent(event, rect, gc);
2252 return false;
2253 }
2254 Color stateColor = null;
2255 if (colorIdx < fEventColorMap.length) {
2256 stateColor = fEventColorMap[colorIdx];
2257 } else {
2258 stateColor = black;
2259 }
837a2f8c 2260
b052914f
PT
2261 boolean reallySelected = timeSelected && selected;
2262 // fill all rect area
2263 gc.setBackground(stateColor);
2264 if (visible) {
837a2f8c 2265 gc.fillRectangle(rect);
b052914f
PT
2266 } else if (fBlendSubPixelEvents) {
2267 gc.setAlpha(128);
2268 gc.fillRectangle(rect);
2269 gc.setAlpha(255);
2270 }
837a2f8c 2271
b052914f
PT
2272 if (reallySelected) {
2273 gc.drawLine(rect.x, rect.y - 1, rect.x + rect.width - 1, rect.y - 1);
2274 gc.drawLine(rect.x, rect.y + rect.height, rect.x + rect.width - 1, rect.y + rect.height);
2275 }
2276 if (!visible) {
837a2f8c 2277 gc.drawPoint(rect.x, rect.y - 2);
837a2f8c
PT
2278 }
2279 fTimeGraphProvider.postDrawEvent(event, rect, gc);
ad128fd8 2280 return visible;
837a2f8c
PT
2281 }
2282
a0a88f65 2283 /**
83b36bb4 2284 * Fill an item's states rectangle
a0a88f65
AM
2285 *
2286 * @param rect
1c67fff3 2287 * The states rectangle
a0a88f65
AM
2288 * @param gc
2289 * Graphics context
2290 * @param selected
83b36bb4 2291 * true if the item is selected
a0a88f65 2292 */
837a2f8c 2293 protected void fillSpace(Rectangle rect, GC gc, boolean selected) {
1c67fff3
PT
2294 /* Nothing to draw */
2295 }
2296
2297 /**
2298 * Draw a line at the middle height of a rectangle
2299 *
2300 * @param rect
2301 * The rectangle
2302 * @param gc
2303 * Graphics context
2304 */
2305 private void drawMidLine(Rectangle rect, GC gc) {
f1fae91f 2306 gc.setForeground(getColorScheme().getColor(TimeGraphColorScheme.MID_LINE));
837a2f8c
PT
2307 int midy = rect.y + rect.height / 2;
2308 gc.drawLine(rect.x, midy, rect.x + rect.width, midy);
2309 }
2310
83d0971d
PT
2311 private static int getMarginForHeight(int height) {
2312 /*
2313 * State rectangle is smaller than the item bounds when height is > 4.
2314 * Don't use any margin if the height is below or equal that threshold.
2315 * Use a maximum of 6 pixels for both margins, otherwise try to use 13
2316 * pixels for the state height, but with a minimum margin of 1.
2317 */
2318 final int MARGIN_THRESHOLD = 4;
2319 final int PREFERRED_HEIGHT = 13;
2320 final int MIN_MARGIN = 1;
2321 final int MAX_MARGIN = 6;
2322 return height <= MARGIN_THRESHOLD ? 0 :
2323 Math.max(Math.min(height - PREFERRED_HEIGHT, MAX_MARGIN), MIN_MARGIN);
2324 }
2325
2326 private void setFontForHeight(int pixels, GC gc) {
2327 /* convert font height from pixels to points */
2328 int height = Math.max(pixels * PPI / DPI, 1);
2329 Font font = fFonts.get(height);
2330 if (font == null) {
2331 FontData fontData = gc.getFont().getFontData()[0];
2332 fontData.setHeight(height);
2333 font = new Font(gc.getDevice(), fontData);
2334 fFonts.put(height, font);
2335 }
2336 gc.setFont(font);
2337 }
2338
837a2f8c
PT
2339 @Override
2340 public void keyTraversed(TraverseEvent e) {
2341 if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
2342 e.doit = true;
2343 }
2344 }
2345
2346 @Override
2347 public void keyPressed(KeyEvent e) {
2348 int idx = -1;
f1fae91f 2349 if (fItemData.fExpandedItems.length == 0) {
837a2f8c
PT
2350 return;
2351 }
2352 if (SWT.HOME == e.keyCode) {
2353 idx = 0;
2354 } else if (SWT.END == e.keyCode) {
f1fae91f 2355 idx = fItemData.fExpandedItems.length - 1;
837a2f8c
PT
2356 } else if (SWT.ARROW_DOWN == e.keyCode) {
2357 idx = getSelectedIndex();
2358 if (idx < 0) {
2359 idx = 0;
f1fae91f 2360 } else if (idx < fItemData.fExpandedItems.length - 1) {
837a2f8c
PT
2361 idx++;
2362 }
2363 } else if (SWT.ARROW_UP == e.keyCode) {
2364 idx = getSelectedIndex();
2365 if (idx < 0) {
2366 idx = 0;
2367 } else if (idx > 0) {
2368 idx--;
2369 }
33fa1fc7
PT
2370 } else if (SWT.ARROW_LEFT == e.keyCode && fDragState == DRAG_NONE) {
2371 boolean extend = (e.stateMask & SWT.SHIFT) != 0;
2372 selectPrevEvent(extend);
2373 } else if (SWT.ARROW_RIGHT == e.keyCode && fDragState == DRAG_NONE) {
2374 boolean extend = (e.stateMask & SWT.SHIFT) != 0;
2375 selectNextEvent(extend);
837a2f8c
PT
2376 } else if (SWT.PAGE_DOWN == e.keyCode) {
2377 int page = countPerPage();
2378 idx = getSelectedIndex();
2379 if (idx < 0) {
2380 idx = 0;
2381 }
2382 idx += page;
f1fae91f
PT
2383 if (idx >= fItemData.fExpandedItems.length) {
2384 idx = fItemData.fExpandedItems.length - 1;
837a2f8c
PT
2385 }
2386 } else if (SWT.PAGE_UP == e.keyCode) {
2387 int page = countPerPage();
2388 idx = getSelectedIndex();
2389 if (idx < 0) {
2390 idx = 0;
2391 }
2392 idx -= page;
2393 if (idx < 0) {
2394 idx = 0;
2395 }
2396 } else if (SWT.CR == e.keyCode) {
2397 idx = getSelectedIndex();
2398 if (idx >= 0) {
f1fae91f 2399 if (fItemData.fExpandedItems[idx].fHasChildren) {
837a2f8c
PT
2400 toggle(idx);
2401 } else {
2402 fireDefaultSelection();
2403 }
2404 }
2405 idx = -1;
3bd20aa6 2406 } else if ((e.character == '+' || e.character == '=') && ((e.stateMask & SWT.CTRL) != 0)) {
48072ae3 2407 fVerticalZoomAlignEntry = getVerticalZoomAlignSelection();
83d0971d 2408 verticalZoom(true);
48072ae3
PT
2409 if (fVerticalZoomAlignEntry != null) {
2410 setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
2411 }
3bd20aa6 2412 } else if (e.character == '-' && ((e.stateMask & SWT.CTRL) != 0)) {
48072ae3 2413 fVerticalZoomAlignEntry = getVerticalZoomAlignSelection();
83d0971d 2414 verticalZoom(false);
48072ae3
PT
2415 if (fVerticalZoomAlignEntry != null) {
2416 setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
2417 }
3bd20aa6 2418 } else if (e.character == '0' && ((e.stateMask & SWT.CTRL) != 0)) {
48072ae3 2419 fVerticalZoomAlignEntry = getVerticalZoomAlignSelection();
83d0971d 2420 resetVerticalZoom();
48072ae3
PT
2421 if (fVerticalZoomAlignEntry != null) {
2422 setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
2423 }
8b516722
BH
2424 } else if ((e.character == '+' || e.character == '=') && ((e.stateMask & SWT.CTRL) == 0)) {
2425 if (fHasNamespaceFocus) {
2426 ITimeGraphEntry entry = getSelectedTrace();
2427 setExpandedState(entry, 0, true);
2428 } else {
2429 zoomIn();
2430 }
2431 } else if (e.character == '-' && ((e.stateMask & SWT.CTRL) == 0)) {
2432 if (fHasNamespaceFocus) {
2433 ITimeGraphEntry entry = getSelectedTrace();
2434 if ((entry != null) && entry.hasChildren()) {
2435 setExpandedState(entry, -1, false);
2436 }
2437 } else {
2438 zoomOut();
2439 }
2440 } else if ((e.character == '*') && ((e.stateMask & SWT.CTRL) == 0)) {
2441 if (fHasNamespaceFocus) {
2442 ITimeGraphEntry entry = getSelectedTrace();
2443 if ((entry != null) && entry.hasChildren()) {
2444 setExpandedStateLevel(entry);
2445 }
2446 }
837a2f8c
PT
2447 }
2448 if (idx >= 0) {
2449 selectItem(idx, false);
2450 fireSelectionChanged();
2451 }
0fcf3b09
PT
2452 int x = toControl(e.display.getCursorLocation()).x;
2453 updateCursor(x, e.stateMask | e.keyCode);
837a2f8c
PT
2454 }
2455
2456 @Override
2457 public void keyReleased(KeyEvent e) {
0fcf3b09
PT
2458 int x = toControl(e.display.getCursorLocation()).x;
2459 updateCursor(x, e.stateMask & ~e.keyCode);
837a2f8c
PT
2460 }
2461
2462 @Override
2463 public void focusGained(FocusEvent e) {
f1fae91f 2464 fIsInFocus = true;
837a2f8c 2465 redraw();
33fa1fc7 2466 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
837a2f8c
PT
2467 }
2468
2469 @Override
2470 public void focusLost(FocusEvent e) {
f1fae91f 2471 fIsInFocus = false;
f1fae91f 2472 if (DRAG_NONE != fDragState) {
837a2f8c 2473 setCapture(false);
f1fae91f 2474 fDragState = DRAG_NONE;
837a2f8c
PT
2475 }
2476 redraw();
0fcf3b09 2477 updateStatusLine(NO_STATUS);
837a2f8c
PT
2478 }
2479
2480 /**
2481 * @return If the current view is focused
2482 */
2483 public boolean isInFocus() {
f1fae91f 2484 return fIsInFocus;
837a2f8c
PT
2485 }
2486
2487 /**
2488 * Provide the possibility to control the wait cursor externally e.g. data
2489 * requests in progress
2490 *
2491 * @param waitInd Should we wait indefinitely?
2492 */
2493 public void waitCursor(boolean waitInd) {
2494 // Update cursor as indicated
2495 if (waitInd) {
f1fae91f 2496 setCursor(fWaitCursor);
837a2f8c
PT
2497 } else {
2498 setCursor(null);
837a2f8c 2499 }
0fcf3b09 2500 }
837a2f8c 2501
0fcf3b09
PT
2502 private void updateCursor(int x, int stateMask) {
2503 // if Wait cursor not active, check for the need to change the cursor
2504 if (getCursor() == fWaitCursor) {
2505 return;
2506 }
2507 Cursor cursor = null;
2508 if (fDragState == DRAG_SPLIT_LINE) {
2509 } else if (fDragState == DRAG_SELECTION) {
2510 cursor = fResizeCursor;
2511 } else if (fDragState == DRAG_TRACE_ITEM) {
2512 cursor = fDragCursor;
2513 } else if (fDragState == DRAG_ZOOM) {
2514 cursor = fZoomCursor;
2515 } else if ((stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
2516 cursor = fDragCursor;
2517 } else if ((stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
2518 cursor = fResizeCursor;
baf92cac
AM
2519 } else if (!isOverSplitLine(x)) {
2520 long selectionBegin = fTimeProvider.getSelectionBegin();
2521 long selectionEnd = fTimeProvider.getSelectionEnd();
2522 int xBegin = getXForTime(selectionBegin);
2523 int xEnd = getXForTime(selectionEnd);
2524 if (Math.abs(x - xBegin) < SNAP_WIDTH || Math.abs(x - xEnd) < SNAP_WIDTH) {
2525 cursor = fResizeCursor;
0fcf3b09
PT
2526 }
2527 }
2528 if (getCursor() != cursor) {
2529 setCursor(cursor);
2530 }
837a2f8c
PT
2531 }
2532
4aa2593c
PT
2533 /**
2534 * Update the status line following a change of selection.
2535 *
2536 * @since 2.0
2537 */
2538 public void updateStatusLine() {
2539 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
2540 }
2541
0fcf3b09 2542 private void updateStatusLine(int x) {
0fab12b0
PT
2543 // use the time provider of the time graph scale for the status line
2544 ITimeDataProvider tdp = fTimeGraphScale.getTimeProvider();
2545 if (fStatusLineManager == null || null == tdp ||
2546 tdp.getTime0() == tdp.getTime1()) {
0fcf3b09
PT
2547 return;
2548 }
0fab12b0
PT
2549 TimeFormat tf = tdp.getTimeFormat();
2550 Resolution res = Resolution.NANOSEC;
0fcf3b09 2551 StringBuilder message = new StringBuilder();
33fa1fc7
PT
2552 if ((x >= 0 || x == STATUS_WITHOUT_CURSOR_TIME) && fDragState == DRAG_NONE) {
2553 if (x != STATUS_WITHOUT_CURSOR_TIME) {
2554 long time = getTimeAtX(x);
2555 if (time >= 0) {
2556 if (tdp instanceof ITimeDataProviderConverter) {
2557 time = ((ITimeDataProviderConverter) tdp).convertTime(time);
2558 }
2559 message.append(NLS.bind("T: {0}{1} ", //$NON-NLS-1$
0fab12b0 2560 new Object[] {
33fa1fc7
PT
2561 tf == TimeFormat.CALENDAR ? Utils.formatDate(time) + ' ' : "", //$NON-NLS-1$
2562 Utils.formatTime(time, tf, res)
0fab12b0 2563 }));
0fcf3b09
PT
2564 }
2565 }
33fa1fc7
PT
2566 long selectionBegin = tdp.getSelectionBegin();
2567 long selectionEnd = tdp.getSelectionEnd();
2568 message.append(NLS.bind("T1: {0}{1}", //$NON-NLS-1$
2569 new Object[] {
2570 tf == TimeFormat.CALENDAR ? Utils.formatDate(selectionBegin) + ' ' : "", //$NON-NLS-1$
2571 Utils.formatTime(selectionBegin, tf, res)
2572 }));
2573 if (selectionBegin != selectionEnd) {
2574 message.append(NLS.bind(" T2: {0}{1} \u0394: {2}", //$NON-NLS-1$
2575 new Object[] {
2576 tf == TimeFormat.CALENDAR ? Utils.formatDate(selectionEnd) + ' ' : "", //$NON-NLS-1$
2577 Utils.formatTime(selectionEnd, tf, res),
2578 Utils.formatDelta(selectionEnd - selectionBegin, tf, res)
2579 }));
2580 }
0fcf3b09 2581 } else if (fDragState == DRAG_SELECTION || fDragState == DRAG_ZOOM) {
85203d74
PT
2582 long time0 = fDragBeginMarker ? getTimeAtX(fDragX0) : fDragTime0;
2583 long time = fDragBeginMarker ? fDragTime0 : getTimeAtX(fDragX);
0fab12b0
PT
2584 if (tdp instanceof ITimeDataProviderConverter) {
2585 time0 = ((ITimeDataProviderConverter) tdp).convertTime(time0);
2586 time = ((ITimeDataProviderConverter) tdp).convertTime(time);
837a2f8c 2587 }
0fab12b0
PT
2588 message.append(NLS.bind("T1: {0}{1} T2: {2}{3} \u0394: {4}", //$NON-NLS-1$
2589 new Object[] {
85203d74
PT
2590 tf == TimeFormat.CALENDAR ? Utils.formatDate(time0) + ' ' : "", //$NON-NLS-1$
2591 Utils.formatTime(time0, tf, res),
2592 tf == TimeFormat.CALENDAR ? Utils.formatDate(time) + ' ' : "", //$NON-NLS-1$
2593 Utils.formatTime(time, tf, res),
2594 Utils.formatDelta(time - time0, tf, res)
0fab12b0 2595 }));
837a2f8c 2596 }
0fcf3b09 2597 fStatusLineManager.setMessage(message.toString());
837a2f8c
PT
2598 }
2599
2600 @Override
2601 public void mouseMove(MouseEvent e) {
f1fae91f 2602 if (null == fTimeProvider) {
837a2f8c
PT
2603 return;
2604 }
b698ec63 2605 Point size = getSize();
f1fae91f
PT
2606 if (DRAG_TRACE_ITEM == fDragState) {
2607 int nameWidth = fTimeProvider.getNameSpace();
0fcf3b09
PT
2608 if (e.x > nameWidth && size.x > nameWidth && fDragX != e.x) {
2609 fDragX = e.x;
f1fae91f
PT
2610 double pixelsPerNanoSec = (size.x - nameWidth <= RIGHT_MARGIN) ? 0 : (double) (size.x - nameWidth - RIGHT_MARGIN) / (fTime1bak - fTime0bak);
2611 long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((fDragX - fDragX0) / pixelsPerNanoSec));
2612 long time1 = fTime1bak - timeDelta;
2613 long maxTime = fTimeProvider.getMaxTime();
837a2f8c
PT
2614 if (time1 > maxTime) {
2615 time1 = maxTime;
2616 }
f1fae91f
PT
2617 long time0 = time1 - (fTime1bak - fTime0bak);
2618 if (time0 < fTimeProvider.getMinTime()) {
2619 time0 = fTimeProvider.getMinTime();
2620 time1 = time0 + (fTime1bak - fTime0bak);
837a2f8c 2621 }
88de10c6 2622 fTimeProvider.setStartFinishTimeNotify(time0, time1);
837a2f8c 2623 }
f1fae91f
PT
2624 } else if (DRAG_SPLIT_LINE == fDragState) {
2625 fDragX = e.x;
2626 fTimeProvider.setNameSpace(e.x);
d2e4afa7 2627 TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
0fcf3b09 2628 } else if (DRAG_SELECTION == fDragState) {
85203d74
PT
2629 if (fDragBeginMarker) {
2630 fDragX0 = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), size.x - RIGHT_MARGIN);
2631 } else {
2632 fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), size.x - RIGHT_MARGIN);
2633 }
baf92cac
AM
2634 redraw();
2635 fTimeGraphScale.setDragRange(fDragX0, fDragX);
f2ca0f69 2636 fireDragSelectionChanged(getTimeAtX(fDragX0), getTimeAtX(fDragX));
f1fae91f
PT
2637 } else if (DRAG_ZOOM == fDragState) {
2638 fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), size.x - RIGHT_MARGIN);
5b2b9bd7 2639 redraw();
0fcf3b09 2640 fTimeGraphScale.setDragRange(fDragX0, fDragX);
f1fae91f 2641 } else if (DRAG_NONE == fDragState) {
837a2f8c 2642 boolean mouseOverSplitLine = isOverSplitLine(e.x);
f1fae91f 2643 if (fMouseOverSplitLine != mouseOverSplitLine) {
837a2f8c
PT
2644 redraw();
2645 }
f1fae91f 2646 fMouseOverSplitLine = mouseOverSplitLine;
837a2f8c 2647 }
8b516722
BH
2648
2649 if (e.x >= fTimeProvider.getNameSpace()) {
2650 fHasNamespaceFocus = false;
2651 } else {
2652 fHasNamespaceFocus = true;
2653 }
0fcf3b09
PT
2654 updateCursor(e.x, e.stateMask);
2655 updateStatusLine(e.x);
837a2f8c
PT
2656 }
2657
2658 @Override
2659 public void mouseDoubleClick(MouseEvent e) {
f1fae91f 2660 if (null == fTimeProvider) {
837a2f8c
PT
2661 return;
2662 }
5b2b9bd7 2663 if (1 == e.button && (e.stateMask & SWT.BUTTON_MASK) == 0) {
f1fae91f
PT
2664 if (isOverSplitLine(e.x) && fTimeProvider.getNameSpace() != 0) {
2665 fTimeProvider.setNameSpace(fIdealNameSpace);
837a2f8c 2666 boolean mouseOverSplitLine = isOverSplitLine(e.x);
f1fae91f 2667 if (fMouseOverSplitLine != mouseOverSplitLine) {
837a2f8c
PT
2668 redraw();
2669 }
f1fae91f 2670 fMouseOverSplitLine = mouseOverSplitLine;
d2e4afa7 2671 TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(this, getTimeViewAlignmentInfo()));
837a2f8c
PT
2672 return;
2673 }
2674 int idx = getItemIndexAtY(e.y);
2675 if (idx >= 0) {
2676 selectItem(idx, false);
2677 fireDefaultSelection();
2678 }
2679 }
2680 }
2681
2682 @Override
2683 public void mouseDown(MouseEvent e) {
407bfdd5
PT
2684 if (fDragState != DRAG_NONE || null == fTimeProvider ||
2685 fTimeProvider.getTime0() == fTimeProvider.getTime1() ||
b698ec63 2686 getSize().x - fTimeProvider.getNameSpace() <= 0) {
837a2f8c
PT
2687 return;
2688 }
2689 int idx;
0fcf3b09 2690 if (1 == e.button && (e.stateMask & SWT.MODIFIER_MASK) == 0) {
f1fae91f
PT
2691 int nameSpace = fTimeProvider.getNameSpace();
2692 if (nameSpace != 0 && isOverSplitLine(e.x)) {
2693 fDragState = DRAG_SPLIT_LINE;
0fcf3b09 2694 fDragButton = e.button;
f1fae91f
PT
2695 fDragX = e.x;
2696 fDragX0 = fDragX;
2697 fTime0bak = fTimeProvider.getTime0();
2698 fTime1bak = fTimeProvider.getTime1();
2699 redraw();
0fcf3b09 2700 updateCursor(e.x, e.stateMask);
f1fae91f 2701 return;
837a2f8c 2702 }
0fcf3b09
PT
2703 }
2704 if (1 == e.button && ((e.stateMask & SWT.MODIFIER_MASK) == 0 || (e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT)) {
2705 int nameSpace = fTimeProvider.getNameSpace();
837a2f8c
PT
2706 idx = getItemIndexAtY(e.y);
2707 if (idx >= 0) {
f1fae91f
PT
2708 Item item = fItemData.fExpandedItems[idx];
2709 if (item.fHasChildren && e.x < nameSpace && e.x < MARGIN + (item.fLevel + 1) * EXPAND_SIZE) {
837a2f8c 2710 toggle(idx);
0fcf3b09 2711 return;
837a2f8c
PT
2712 }
2713 selectItem(idx, false);
2714 fireSelectionChanged();
2715 } else {
2716 selectItem(idx, false); // clear selection
837a2f8c
PT
2717 fireSelectionChanged();
2718 }
0fcf3b09
PT
2719 long hitTime = getTimeAtX(e.x);
2720 if (hitTime >= 0) {
2721 setCapture(true);
2722
2723 fDragState = DRAG_SELECTION;
85203d74 2724 fDragBeginMarker = false;
0fcf3b09
PT
2725 fDragButton = e.button;
2726 fDragX = e.x;
2727 fDragX0 = fDragX;
2728 fDragTime0 = getTimeAtX(fDragX0);
baf92cac
AM
2729 long selectionBegin = fTimeProvider.getSelectionBegin();
2730 long selectionEnd = fTimeProvider.getSelectionEnd();
2731 int xBegin = getXForTime(selectionBegin);
2732 int xEnd = getXForTime(selectionEnd);
2733 if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
2734 long time = getTimeAtX(e.x);
2735 if (Math.abs(time - selectionBegin) < Math.abs(time - selectionEnd)) {
85203d74
PT
2736 fDragBeginMarker = true;
2737 fDragX = xEnd;
2738 fDragX0 = e.x;
baf92cac 2739 fDragTime0 = selectionEnd;
0fcf3b09 2740 } else {
baf92cac
AM
2741 fDragX0 = xBegin;
2742 fDragTime0 = selectionBegin;
2743 }
2744 } else {
2745 long time = getTimeAtX(e.x);
2746 if (Math.abs(e.x - xBegin) < SNAP_WIDTH && Math.abs(time - selectionBegin) <= Math.abs(time - selectionEnd)) {
85203d74
PT
2747 fDragBeginMarker = true;
2748 fDragX = xEnd;
2749 fDragX0 = e.x;
baf92cac
AM
2750 fDragTime0 = selectionEnd;
2751 } else if (Math.abs(e.x - xEnd) < SNAP_WIDTH && Math.abs(time - selectionEnd) <= Math.abs(time - selectionBegin)) {
2752 fDragX0 = xBegin;
2753 fDragTime0 = selectionBegin;
0fcf3b09
PT
2754 }
2755 }
2756 fTime0bak = fTimeProvider.getTime0();
2757 fTime1bak = fTimeProvider.getTime1();
2758 redraw();
2759 updateCursor(e.x, e.stateMask);
2760 fTimeGraphScale.setDragRange(fDragX0, fDragX);
2761 }
2762 } else if (2 == e.button || (1 == e.button && (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL)) {
2763 long hitTime = getTimeAtX(e.x);
2764 if (hitTime > 0) {
2765 setCapture(true);
2766 fDragState = DRAG_TRACE_ITEM;
2767 fDragButton = e.button;
2768 fDragX = e.x;
2769 fDragX0 = fDragX;
2770 fTime0bak = fTimeProvider.getTime0();
2771 fTime1bak = fTimeProvider.getTime1();
2772 updateCursor(e.x, e.stateMask);
2773 }
5b2b9bd7 2774 } else if (3 == e.button) {
14b7dd60
MK
2775 if (e.x >= fTimeProvider.getNameSpace()) {
2776 setCapture(true);
2777 fDragX = Math.min(Math.max(e.x, fTimeProvider.getNameSpace()), getSize().x - RIGHT_MARGIN);
2778 fDragX0 = fDragX;
2779 fDragTime0 = getTimeAtX(fDragX0);
2780 fDragState = DRAG_ZOOM;
2781 fDragButton = e.button;
2782 redraw();
2783 updateCursor(e.x, e.stateMask);
2784 fTimeGraphScale.setDragRange(fDragX0, fDragX);
2989c909
BH
2785 } else {
2786 idx = getItemIndexAtY(e.y);
2787 selectItem(idx, false);
2788 fireSelectionChanged();
14b7dd60 2789 }
837a2f8c
PT
2790 }
2791 }
2792
2793 @Override
2794 public void mouseUp(MouseEvent e) {
0b5a90a0
PT
2795 if (fPendingMenuDetectEvent != null && e.button == 3) {
2796 menuDetected(fPendingMenuDetectEvent);
2797 }
f1fae91f 2798 if (DRAG_NONE != fDragState) {
837a2f8c 2799 setCapture(false);
0fcf3b09
PT
2800 if (e.button == fDragButton && DRAG_TRACE_ITEM == fDragState) {
2801 if (fDragX != fDragX0) {
2802 fTimeProvider.notifyStartFinishTime();
2803 }
2804 fDragState = DRAG_NONE;
2805 } else if (e.button == fDragButton && DRAG_SPLIT_LINE == fDragState) {
2806 fDragState = DRAG_NONE;
2807 redraw();
2808 } else if (e.button == fDragButton && DRAG_SELECTION == fDragState) {
2809 if (fDragX == fDragX0) { // click without selecting anything
837a2f8c 2810 long time = getTimeAtX(e.x);
f1fae91f 2811 fTimeProvider.setSelectedTimeNotify(time, false);
e1725a05 2812 } else {
85203d74
PT
2813 long time0 = fDragBeginMarker ? getTimeAtX(fDragX0) : fDragTime0;
2814 long time1 = fDragBeginMarker ? fDragTime0 : getTimeAtX(fDragX);
84c8aef7 2815 fTimeProvider.setSelectionRangeNotify(time0, time1, false);
837a2f8c 2816 }
f1fae91f 2817 fDragState = DRAG_NONE;
837a2f8c 2818 redraw();
0fcf3b09
PT
2819 fTimeGraphScale.setDragRange(-1, -1);
2820 } else if (e.button == fDragButton && DRAG_ZOOM == fDragState) {
f1fae91f
PT
2821 int nameWidth = fTimeProvider.getNameSpace();
2822 if (Math.max(fDragX, fDragX0) > nameWidth && fDragX != fDragX0) {
2823 long time0 = getTimeAtX(fDragX0);
2824 long time1 = getTimeAtX(fDragX);
5b2b9bd7 2825 if (time0 < time1) {
f1fae91f 2826 fTimeProvider.setStartFinishTimeNotify(time0, time1);
5b2b9bd7 2827 } else {
f1fae91f 2828 fTimeProvider.setStartFinishTimeNotify(time1, time0);
5b2b9bd7
PT
2829 }
2830 } else {
2831 redraw();
2832 }
f1fae91f 2833 fDragState = DRAG_NONE;
0fcf3b09 2834 fTimeGraphScale.setDragRange(-1, -1);
837a2f8c 2835 }
837a2f8c 2836 }
0fcf3b09
PT
2837 updateCursor(e.x, e.stateMask);
2838 updateStatusLine(e.x);
837a2f8c
PT
2839 }
2840
2841 @Override
2842 public void mouseEnter(MouseEvent e) {
2843 }
2844
2845 @Override
2846 public void mouseExit(MouseEvent e) {
f1fae91f
PT
2847 if (fMouseOverSplitLine) {
2848 fMouseOverSplitLine = false;
837a2f8c
PT
2849 redraw();
2850 }
33fa1fc7 2851 updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
837a2f8c
PT
2852 }
2853
2854 @Override
2855 public void mouseHover(MouseEvent e) {
2856 }
2857
2858 @Override
2859 public void mouseScrolled(MouseEvent e) {
93cfc823 2860 if (fDragState != DRAG_NONE || e.count == 0) {
837a2f8c
PT
2861 return;
2862 }
494c9b22
PT
2863
2864 /*
2865 * On some platforms the mouse scroll event is sent to the
2866 * control that has focus even if it is not under the cursor.
2867 * Handle the event only if over the time graph control.
2868 */
2869 Point size = getSize();
2870 Rectangle bounds = new Rectangle(0, 0, size.x, size.y);
2871 if (!bounds.contains(e.x, e.y)) {
2872 return;
2873 }
2874
494d213d 2875 boolean horizontalZoom = false;
b698ec63 2876 boolean horizontalScroll = false;
494d213d 2877 boolean verticalZoom = false;
494c9b22
PT
2878 boolean verticalScroll = false;
2879
2880 // over the time graph control
2881 if ((e.stateMask & SWT.MODIFIER_MASK) == (SWT.SHIFT | SWT.CTRL)) {
2882 verticalZoom = true;
2883 } else if (e.x < fTimeProvider.getNameSpace()) {
2884 // over the name space
2885 verticalScroll = true;
2886 } else {
2887 // over the state area
2888 if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
2889 // over the state area, CTRL pressed
dc4fa715 2890 horizontalZoom = true;
494c9b22
PT
2891 } else if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
2892 // over the state area, SHIFT pressed
2893 horizontalScroll = true;
e5552166 2894 } else {
494c9b22
PT
2895 // over the state area, no modifier pressed
2896 verticalScroll = true;
837a2f8c
PT
2897 }
2898 }
494d213d 2899 if (verticalZoom) {
48072ae3 2900 fVerticalZoomAlignEntry = getVerticalZoomAlignCursor(e.y);
494c9b22 2901 verticalZoom(e.count > 0);
48072ae3
PT
2902 if (fVerticalZoomAlignEntry != null) {
2903 setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
2904 }
494d213d 2905 } else if (horizontalZoom && fTimeProvider.getTime0() != fTimeProvider.getTime1()) {
494c9b22 2906 zoom(e.count > 0);
b698ec63
PT
2907 } else if (horizontalScroll) {
2908 horizontalScroll(e.count > 0);
494c9b22 2909 } else if (verticalScroll){
837a2f8c
PT
2910 setTopIndex(getTopIndex() - e.count);
2911 }
2912 }
2913
48072ae3
PT
2914 /**
2915 * Get the vertical zoom alignment entry and position based on the current
2916 * selection. If there is no selection or if the selection is not visible,
2917 * return an alignment entry with a null time graph entry.
2918 *
2919 * @return a map entry where the key is the selection's time graph entry and
2920 * the value is the center y-coordinate of that entry, or null
2921 */
2922 private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignSelection() {
2923 Entry<ITimeGraphEntry, Integer> alignEntry = getVerticalZoomAlignOngoing();
2924 if (alignEntry != null) {
2925 return alignEntry;
2926 }
2927 int index = getSelectedIndex();
2928 if (index == -1 || index >= getExpandedElementCount()) {
2929 return new SimpleEntry<>(null, 0);
2930 }
2931 Rectangle bounds = getClientArea();
2932 Rectangle itemRect = getItemRect(bounds, index);
2933 if (itemRect.y < bounds.y || itemRect.y > bounds.y + bounds.height) {
2934 /* selection is not visible */
2935 return new SimpleEntry<>(null, 0);
2936 }
2937 ITimeGraphEntry entry = getExpandedElement(index);
2938 int y = itemRect.y + itemRect.height / 2;
2939 return new SimpleEntry<>(entry, y);
2940 }
2941
2942 /**
2943 * Get the vertical zoom alignment entry and position at the specified
2944 * cursor position.
2945 *
2946 * @param y
2947 * the cursor y-coordinate
2948 * @return a map entry where the key is the time graph entry under the
2949 * cursor and the value is the cursor y-coordinate
2950 */
2951 private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignCursor(int y) {
2952 Entry<ITimeGraphEntry, Integer> alignEntry = getVerticalZoomAlignOngoing();
2953 if (alignEntry != null) {
2954 return alignEntry;
2955 }
2956 int index = getItemIndexAtY(y);
2957 if (index == -1) {
2958 index = getExpandedElementCount() - 1;
2959 }
2960 ITimeGraphEntry entry = getExpandedElement(index);
2961 return new SimpleEntry<>(entry, y);
2962 }
2963
2964 /**
2965 * Get the vertical zoom alignment entry and position if there is an ongoing
2966 * one and we are within the vertical zoom delay, or otherwise return null.
2967 *
2968 * @return a map entry where the key is a time graph entry and the value is
2969 * a y-coordinate, or null
2970 */
2971 private Entry<ITimeGraphEntry, Integer> getVerticalZoomAlignOngoing() {
2972 long currentTimeMillis = System.currentTimeMillis();
2973 if (currentTimeMillis < fVerticalZoomAlignTime + VERTICAL_ZOOM_DELAY) {
2974 /*
2975 * If the vertical zoom is triggered repeatedly in a short amount of
2976 * time, use the initial event's entry and position.
2977 */
2978 fVerticalZoomAlignTime = currentTimeMillis;
2979 return fVerticalZoomAlignEntry;
2980 }
2981 fVerticalZoomAlignTime = currentTimeMillis;
2982 return null;
2983 }
2984
6b11be52
PT
2985 @Override
2986 public void handleEvent(Event event) {
2987 if (event.type == SWT.MouseWheel) {
2988 // prevent horizontal scrolling when the mouse wheel is used to
2989 // scroll vertically or zoom
2990 event.doit = false;
2991 }
2992 }
2993
837a2f8c
PT
2994 @Override
2995 public int getBorderWidth() {
f1fae91f 2996 return fBorderWidth;
837a2f8c
PT
2997 }
2998
2999 /**
3000 * Set the border width
3001 *
3002 * @param borderWidth
3003 * The width
3004 */
3005 public void setBorderWidth(int borderWidth) {
f1fae91f 3006 this.fBorderWidth = borderWidth;
837a2f8c
PT
3007 }
3008
3009 /**
3010 * @return The current height of the header row
3011 */
3012 public int getHeaderHeight() {
f1fae91f 3013 return fHeaderHeight;
837a2f8c
PT
3014 }
3015
3016 /**
3017 * Set the height of the header row
3018 *
3019 * @param headerHeight
3020 * The height
3021 */
3022 public void setHeaderHeight(int headerHeight) {
f1fae91f 3023 this.fHeaderHeight = headerHeight;
837a2f8c
PT
3024 }
3025
3026 /**
c004295c 3027 * @return The default height of regular item rows
837a2f8c
PT
3028 */
3029 public int getItemHeight() {
f1fae91f 3030 return fGlobalItemHeight;
837a2f8c
PT
3031 }
3032
3033 /**
c004295c 3034 * Set the default height of regular item rows.
837a2f8c
PT
3035 *
3036 * @param rowHeight
3037 * The height
3038 */
3039 public void setItemHeight(int rowHeight) {
f1fae91f 3040 this.fGlobalItemHeight = rowHeight;
63b93cd6
PT
3041 for (Item item : fItemData.fItems) {
3042 item.fItemHeight = rowHeight;
3043 }
837a2f8c
PT
3044 }
3045
c004295c
PT
3046 /**
3047 * Set the height of a specific item. Overrides the default item height.
3048 *
3049 * @param entry
3050 * A time graph entry
3051 * @param rowHeight
3052 * The height
3053 * @return true if the height is successfully stored, false otherwise
c004295c
PT
3054 */
3055 public boolean setItemHeight(ITimeGraphEntry entry, int rowHeight) {
3056 Item item = fItemData.findItem(entry);
3057 if (item != null) {
3058 item.fItemHeight = rowHeight;
3059 return true;
3060 }
3061 return false;
3062 }
3063
837a2f8c
PT
3064 /**
3065 * Set the minimum item width
3066 *
3067 * @param width The minimum width
3068 */
3069 public void setMinimumItemWidth(int width) {
f1fae91f 3070 this.fMinimumItemWidth = width;
837a2f8c
PT
3071 }
3072
3073 /**
3074 * @return The minimum item width
3075 */
3076 public int getMinimumItemWidth() {
f1fae91f 3077 return fMinimumItemWidth;
837a2f8c
PT
3078 }
3079
b052914f
PT
3080 /**
3081 * Set whether all time events with a duration shorter than one pixel should
3082 * be blended in. If false, only the first such time event will be drawn and
3083 * the subsequent time events in the same pixel will be discarded. The
3084 * default value is false.
3085 *
3086 * @param blend
3087 * true if sub-pixel events should be blended, false otherwise.
0336f981 3088 * @since 1.1
b052914f
PT
3089 */
3090 public void setBlendSubPixelEvents(boolean blend) {
3091 fBlendSubPixelEvents = blend;
3092 }
3093
837a2f8c
PT
3094 @Override
3095 public void addSelectionChangedListener(ISelectionChangedListener listener) {
f1fae91f
PT
3096 if (listener != null && !fSelectionChangedListeners.contains(listener)) {
3097 fSelectionChangedListeners.add(listener);
837a2f8c
PT
3098 }
3099 }
3100
837a2f8c
PT
3101 @Override
3102 public void removeSelectionChangedListener(ISelectionChangedListener listener) {
3103 if (listener != null) {
f1fae91f 3104 fSelectionChangedListeners.remove(listener);
837a2f8c
PT
3105 }
3106 }
3107
837a2f8c
PT
3108 @Override
3109 public void setSelection(ISelection selection) {
3110 if (selection instanceof TimeGraphSelection) {
3111 TimeGraphSelection sel = (TimeGraphSelection) selection;
3112 Object ob = sel.getFirstElement();
3113 if (ob instanceof ITimeGraphEntry) {
3114 ITimeGraphEntry trace = (ITimeGraphEntry) ob;
3115 selectItem(trace, false);
3116 }
3117 }
3118
3119 }
3120
6ac5a950
AM
3121 /**
3122 * @param filter The filter object to be attached to the view
6ac5a950 3123 */
367e2932 3124 public void addFilter(@NonNull ViewerFilter filter) {
f1fae91f
PT
3125 if (!fFilters.contains(filter)) {
3126 fFilters.add(filter);
6ac5a950
AM
3127 }
3128 }
3129
3130 /**
3131 * @param filter The filter object to be attached to the view
6ac5a950 3132 */
367e2932 3133 public void removeFilter(@NonNull ViewerFilter filter) {
f1fae91f 3134 fFilters.remove(filter);
6ac5a950
AM
3135 }
3136
4923d7b9
PT
3137 /**
3138 * Returns this control's filters.
3139 *
3140 * @return an array of viewer filters
066b02aa 3141 * @since 1.2
4923d7b9 3142 */
367e2932 3143 public @NonNull ViewerFilter[] getFilters() {
4923d7b9
PT
3144 return Iterables.toArray(fFilters, ViewerFilter.class);
3145 }
3146
3147 /**
3148 * Sets the filters, replacing any previous filters.
3149 *
3150 * @param filters
3151 * an array of viewer filters, or null
066b02aa 3152 * @since 1.2
4923d7b9 3153 */
367e2932 3154 public void setFilters(@NonNull ViewerFilter[] filters) {
4923d7b9
PT
3155 fFilters.clear();
3156 if (filters != null) {
3157 fFilters.addAll(Arrays.asList(filters));
3158 }
3159 }
3160
496f76d3
GB
3161 @Override
3162 public void colorSettingsChanged(StateItem[] stateItems) {
3163 /* Destroy previous colors from the resource manager */
517fe01b
EB
3164 if (fEventColorMap != null) {
3165 for (Color color : fEventColorMap) {
3166 fResourceManager.destroyColor(color.getRGB());
3167 }
496f76d3
GB
3168 }
3169 if (stateItems != null) {
3170 fEventColorMap = new Color[stateItems.length];
3171 for (int i = 0; i < stateItems.length; i++) {
3172 fEventColorMap[i] = fResourceManager.createColor(stateItems[i].getStateColor());
3173 }
3174 } else {
3175 fEventColorMap = new Color[] { };
3176 }
3177 redraw();
3178 }
3179
837a2f8c 3180 private class ItemData {
df0e3d5f 3181 private Map<ITimeGraphEntry, Item> fItemMap = new LinkedHashMap<>();
f1fae91f
PT
3182 private Item[] fExpandedItems = new Item[0];
3183 private Item[] fItems = new Item[0];
70e10acc 3184 private ITimeGraphEntry fRootEntries[] = new ITimeGraphEntry[0];
507b1336 3185 private List<ILinkEvent> fLinks = new ArrayList<>();
837a2f8c
PT
3186
3187 public ItemData() {
3188 }
3189
70e10acc
PT
3190 public Item findItem(ITimeGraphEntry entry) {
3191 return fItemMap.get(entry);
837a2f8c
PT
3192 }
3193
70e10acc
PT
3194 public int findItemIndex(ITimeGraphEntry entry) {
3195 Item item = fItemMap.get(entry);
3196 if (item == null) {
837a2f8c
PT
3197 return -1;
3198 }
70e10acc 3199 return item.fExpandedIndex;
837a2f8c
PT
3200 }
3201
3202 public void refreshData() {
3e9a3685 3203 ITimeGraphEntry selection = getSelectedTrace();
df0e3d5f 3204 Map<ITimeGraphEntry, Item> itemMap = new LinkedHashMap<>();
70e10acc
PT
3205 for (int i = 0; i < fRootEntries.length; i++) {
3206 ITimeGraphEntry entry = fRootEntries[i];
df0e3d5f 3207 refreshData(itemMap, null, 0, entry);
837a2f8c 3208 }
df0e3d5f 3209 fItemMap = itemMap;
70e10acc 3210 fItems = fItemMap.values().toArray(new Item[0]);
837a2f8c 3211 updateExpandedItems();
3e9a3685 3212 if (selection != null) {
f1fae91f 3213 for (Item item : fExpandedItems) {
70e10acc 3214 if (item.fEntry == selection) {
f1fae91f 3215 item.fSelected = true;
3e9a3685
PT
3216 break;
3217 }
3218 }
3219 }
837a2f8c
PT
3220 }
3221
70e10acc 3222 private void refreshData(Map<ITimeGraphEntry, Item> itemMap, Item parent, int level, ITimeGraphEntry entry) {
837a2f8c
PT
3223 Item item = new Item(entry, entry.getName(), level);
3224 if (parent != null) {
f1fae91f 3225 parent.fChildren.add(item);
837a2f8c 3226 }
c004295c
PT
3227 if (fGlobalItemHeight == CUSTOM_ITEM_HEIGHT) {
3228 item.fItemHeight = fTimeGraphProvider.getItemHeight(entry);
3229 } else {
3230 item.fItemHeight = fGlobalItemHeight;
3231 }
3bd20aa6 3232 item.fItemHeight = Math.max(1, item.fItemHeight + fHeightAdjustment);
70e10acc 3233 itemMap.put(entry, item);
837a2f8c 3234 if (entry.hasChildren()) {
df0e3d5f
PT
3235 Item oldItem = fItemMap.get(entry);
3236 if (oldItem != null && oldItem.fHasChildren && level == oldItem.fLevel && entry.getParent() == oldItem.fEntry.getParent()) {
3237 /* existing items keep their old expanded state */
3238 item.fExpanded = oldItem.fExpanded;
3239 } else {
3240 /* new items set the expanded state according to auto-expand level */
3241 item.fExpanded = fAutoExpandLevel == ALL_LEVELS || level < fAutoExpandLevel;
3242 }
f1fae91f 3243 item.fHasChildren = true;
837a2f8c 3244 for (ITimeGraphEntry child : entry.getChildren()) {
70e10acc 3245 refreshData(itemMap, item, level + 1, child);
837a2f8c
PT
3246 }
3247 }
3248 }
3249
3250 public void updateExpandedItems() {
70e10acc
PT
3251 for (Item item : fItems) {
3252 item.fExpandedIndex = -1;
3253 }
507b1336 3254 List<Item> expandedItemList = new ArrayList<>();
70e10acc
PT
3255 for (int i = 0; i < fRootEntries.length; i++) {
3256 ITimeGraphEntry entry = fRootEntries[i];
837a2f8c
PT
3257 Item item = findItem(entry);
3258 refreshExpanded(expandedItemList, item);
3259 }
f1fae91f 3260 fExpandedItems = expandedItemList.toArray(new Item[0]);
19ed1845 3261 fTopIndex = Math.min(fTopIndex, Math.max(0, fExpandedItems.length - 1));
837a2f8c
PT
3262 }
3263
3264 private void refreshExpanded(List<Item> expandedItemList, Item item) {
6ac5a950
AM
3265 // Check for filters
3266 boolean display = true;
f1fae91f 3267 for (ViewerFilter filter : fFilters) {
70e10acc 3268 if (!filter.select(null, item.fEntry.getParent(), item.fEntry)) {
6ac5a950
AM
3269 display = false;
3270 break;
3271 }
3272 }
3273 if (display) {
70e10acc 3274 item.fExpandedIndex = expandedItemList.size();
6ac5a950 3275 expandedItemList.add(item);
f1fae91f
PT
3276 if (item.fHasChildren && item.fExpanded) {
3277 for (Item child : item.fChildren) {
6ac5a950
AM
3278 refreshExpanded(expandedItemList, child);
3279 }
837a2f8c
PT
3280 }
3281 }
3282 }
3283
70e10acc
PT
3284 public void refreshData(ITimeGraphEntry[] entries) {
3285 if (entries == null) {
70e10acc 3286 fRootEntries = null;
f1fae91f 3287 } else {
70e10acc 3288 fRootEntries = Arrays.copyOf(entries, entries.length);
837a2f8c
PT
3289 }
3290
837a2f8c
PT
3291 refreshData();
3292 }
3293
bec1f1ac
GB
3294 public void refreshArrows(List<ILinkEvent> events) {
3295 /* If links are null, reset the list */
3296 if (events != null) {
3297 fLinks = events;
3298 } else {
507b1336 3299 fLinks = new ArrayList<>();
bec1f1ac
GB
3300 }
3301 }
3302
70e10acc
PT
3303 public ITimeGraphEntry[] getEntries() {
3304 return fRootEntries;
837a2f8c 3305 }
837a2f8c
PT
3306 }
3307
3308 private class Item {
f1fae91f 3309 private boolean fExpanded;
70e10acc 3310 private int fExpandedIndex;
f1fae91f
PT
3311 private boolean fSelected;
3312 private boolean fHasChildren;
3313 private int fItemHeight;
70e10acc
PT
3314 private final int fLevel;
3315 private final List<Item> fChildren;
3316 private final String fName;
3317 private final ITimeGraphEntry fEntry;
837a2f8c 3318
70e10acc
PT
3319 public Item(ITimeGraphEntry entry, String name, int level) {
3320 this.fEntry = entry;
f1fae91f
PT
3321 this.fName = name;
3322 this.fLevel = level;
507b1336 3323 this.fChildren = new ArrayList<>();
837a2f8c
PT
3324 }
3325
3326 @Override
3327 public String toString() {
f1fae91f 3328 return fName;
837a2f8c
PT
3329 }
3330 }
3331
27df1564
XR
3332 @Override
3333 public void menuDetected(MenuDetectEvent e) {
f1fae91f 3334 if (null == fTimeProvider) {
27df1564
XR
3335 return;
3336 }
024658d1 3337 Point p = toControl(e.x, e.y);
0b5a90a0
PT
3338 if (e.detail == SWT.MENU_MOUSE) {
3339 if (fPendingMenuDetectEvent == null) {
3340 /* Feature in Linux. The MenuDetectEvent is received before mouseDown.
3341 * Store the event and trigger it later just before handling mouseUp.
3342 * This allows for the method to detect if mouse is used to drag zoom.
3343 */
3344 fPendingMenuDetectEvent = e;
024658d1
BH
3345 /*
3346 * Prevent the platform to show the menu when returning. The
3347 * menu will be shown (see below) when this method is called
3348 * again during mouseup().
3349 */
3350 e.doit = false;
0b5a90a0
PT
3351 return;
3352 }
3353 fPendingMenuDetectEvent = null;
024658d1 3354 if ((p.x >= fTimeProvider.getNameSpace()) && (fDragState != DRAG_ZOOM || fDragX != fDragX0)) {
0b5a90a0
PT
3355 return;
3356 }
3357 } else {
f1fae91f 3358 if (fDragState != DRAG_NONE) {
0b5a90a0
PT
3359 return;
3360 }
3361 }
27df1564 3362 int idx = getItemIndexAtY(p.y);
f1fae91f 3363 if (idx >= 0 && idx < fItemData.fExpandedItems.length) {
024658d1 3364 e.doit = true;
f1fae91f 3365 Item item = fItemData.fExpandedItems[idx];
70e10acc 3366 ITimeGraphEntry entry = item.fEntry;
9bdf1671
BH
3367
3368 /* Send menu event for the time graph entry */
3369 e.doit = true;
3370 e.data = entry;
3371 fireMenuEventOnTimeGraphEntry(e);
3372 Menu menu = getMenu();
3373 if (e.doit && (menu != null)) {
3374 menu.setVisible(true);
3375 }
3376
3377 /* Send menu event for time event */
27df1564
XR
3378 if (entry.hasTimeEvents()) {
3379 ITimeEvent event = Utils.findEvent(entry, getTimeAtX(p.x), 2);
3380 if (event != null) {
9bdf1671 3381 e.doit = true;
27df1564
XR
3382 e.data = event;
3383 fireMenuEventOnTimeEvent(e);
9bdf1671 3384 menu = getMenu();
024658d1
BH
3385 if (e.doit && (menu != null)) {
3386 menu.setVisible(true);
3387 }
27df1564
XR
3388 }
3389 }
27df1564
XR
3390 }
3391 }
3392
d2e4afa7
MAL
3393 /**
3394 * Perform the alignment operation.
3395 *
3396 * @param offset
3397 * the alignment offset
3398 *
3399 * @see ITmfTimeAligned
3400 *
3401 * @since 1.0
3402 */
3403 public void performAlign(int offset) {
3404 fTimeProvider.setNameSpace(offset);
3405 }
3406
3407 /**
3408 * Return the time alignment information
3409 *
3410 * @return the time alignment information
3411 *
3412 * @see ITmfTimeAligned
3413 *
3414 * @since 1.0
3415 */
3416 public TmfTimeViewAlignmentInfo getTimeViewAlignmentInfo() {
3417 return new TmfTimeViewAlignmentInfo(getShell(), toDisplay(0, 0), fTimeProvider.getNameSpace());
3418 }
837a2f8c 3419}
This page took 0.290564 seconds and 5 git commands to generate.