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