Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
013a5f1c | 4 | * |
73005152 BH |
5 | * All rights reserved. This program and the accompanying materials |
6 | * are made available under the terms of the Eclipse Public License v1.0 | |
7 | * which accompanies this distribution, and is available at | |
8 | * http://www.eclipse.org/legal/epl-v10.html | |
013a5f1c AM |
9 | * |
10 | * Contributors: | |
73005152 BH |
11 | * IBM - Initial API and implementation |
12 | * Bernd Hufmann - Updated for TMF | |
013a5f1c | 13 | * |
73005152 BH |
14 | **********************************************************************/ |
15 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd; | |
16 | ||
17 | import java.util.ArrayList; | |
18 | import java.util.Arrays; | |
19 | import java.util.List; | |
20 | ||
8fd82db5 | 21 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
4df4581d | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
73005152 BH |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessage; |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.AsyncMessageReturn; | |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage; | |
27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ExecutionOccurrence; | |
28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; | |
29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
30 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange; | |
31 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; | |
32 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Metrics; | |
33 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SDTimeEvent; | |
34 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.SyncMessage; | |
35 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
36 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.impl.ColorImpl; | |
37 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
38 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.TimeEventComparator; | |
39 | import org.eclipse.swt.SWT; | |
40 | import org.eclipse.swt.accessibility.ACC; | |
41 | import org.eclipse.swt.accessibility.Accessible; | |
42 | import org.eclipse.swt.accessibility.AccessibleAdapter; | |
43 | import org.eclipse.swt.accessibility.AccessibleControlAdapter; | |
44 | import org.eclipse.swt.accessibility.AccessibleControlEvent; | |
45 | import org.eclipse.swt.accessibility.AccessibleEvent; | |
46 | import org.eclipse.swt.events.DisposeEvent; | |
47 | import org.eclipse.swt.events.DisposeListener; | |
48 | import org.eclipse.swt.events.FocusEvent; | |
49 | import org.eclipse.swt.events.FocusListener; | |
50 | import org.eclipse.swt.events.KeyEvent; | |
51 | import org.eclipse.swt.events.MouseEvent; | |
52 | import org.eclipse.swt.events.TraverseEvent; | |
53 | import org.eclipse.swt.events.TraverseListener; | |
54 | import org.eclipse.swt.graphics.Color; | |
55 | import org.eclipse.swt.graphics.GC; | |
56 | import org.eclipse.swt.graphics.Image; | |
57 | import org.eclipse.swt.widgets.Composite; | |
58 | import org.eclipse.swt.widgets.Control; | |
59 | import org.eclipse.swt.widgets.Display; | |
60 | ||
61 | /** | |
df0b8ff4 BH |
62 | * <p> |
63 | * The time compression bar implementation. | |
64 | * </p> | |
013a5f1c | 65 | * |
df0b8ff4 | 66 | * @version 1.0 |
73005152 | 67 | * @author sveyrier |
73005152 BH |
68 | */ |
69 | public class TimeCompressionBar extends ScrollView implements DisposeListener { | |
70 | ||
df0b8ff4 BH |
71 | // ------------------------------------------------------------------------ |
72 | // Attributes | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
73005152 BH |
75 | /** |
76 | * The listener list | |
77 | */ | |
eb63f5ff | 78 | protected List<ITimeCompressionListener> fListenerList = null; |
df0b8ff4 BH |
79 | /** |
80 | * The current frame displayed. | |
81 | */ | |
eb63f5ff | 82 | protected Frame fFrame = null; |
df0b8ff4 BH |
83 | /** |
84 | * List of time events. | |
85 | */ | |
eb63f5ff | 86 | protected List<SDTimeEvent> fNodeList = null; |
df0b8ff4 BH |
87 | /** |
88 | * The minimum time delta. | |
89 | */ | |
eb63f5ff | 90 | protected ITmfTimestamp fMinTime = new TmfTimestamp(); |
df0b8ff4 BH |
91 | /** |
92 | * The maximum time delta. | |
93 | */ | |
eb63f5ff | 94 | protected ITmfTimestamp fMaxTime = new TmfTimestamp(); |
df0b8ff4 BH |
95 | /** |
96 | * The current zoom value. | |
97 | */ | |
eb63f5ff | 98 | protected float fZoomValue = 1; |
df0b8ff4 BH |
99 | /** |
100 | * The tooltip to display. | |
101 | */ | |
eb63f5ff | 102 | protected DrawableToolTip fTooltip = null; |
df0b8ff4 | 103 | /** |
013a5f1c | 104 | * Array of colors for displaying wight of time deltas. |
df0b8ff4 | 105 | */ |
eb63f5ff | 106 | protected ColorImpl[] fColors; |
df0b8ff4 BH |
107 | /** |
108 | * The accessible object reference. | |
109 | */ | |
eb63f5ff | 110 | protected Accessible fAccessible = null; |
df0b8ff4 BH |
111 | /** |
112 | * The focused widget reference. | |
113 | */ | |
eb63f5ff | 114 | protected int fFocusedWidget = -1; |
df0b8ff4 | 115 | /** |
013a5f1c | 116 | * The sequence diagram view reference. |
df0b8ff4 | 117 | */ |
73005152 | 118 | protected SDView view = null; |
df0b8ff4 BH |
119 | /** |
120 | * The current lifeline. | |
121 | */ | |
eb63f5ff | 122 | protected Lifeline fLifeline = null; |
df0b8ff4 BH |
123 | /** |
124 | * The current start event value. | |
125 | */ | |
eb63f5ff | 126 | protected int fLifelineStart = 0; |
df0b8ff4 BH |
127 | /** |
128 | * The current number of events. | |
129 | */ | |
eb63f5ff | 130 | protected int fLifelineNumEvents = 0; |
df0b8ff4 | 131 | /** |
013a5f1c | 132 | * The Current color of range to display. |
df0b8ff4 | 133 | */ |
eb63f5ff | 134 | protected IColor fLifelineColor = null; |
df0b8ff4 | 135 | /** |
013a5f1c | 136 | * The next graph node y coordinate. |
df0b8ff4 | 137 | */ |
eb63f5ff | 138 | protected int fNextNodeY = 0; |
df0b8ff4 | 139 | /** |
013a5f1c | 140 | * The previous graph node y coordinate. |
df0b8ff4 | 141 | */ |
eb63f5ff | 142 | protected int fPrevNodeY = 0; |
73005152 | 143 | |
df0b8ff4 BH |
144 | // ------------------------------------------------------------------------ |
145 | // Constructors | |
146 | // ------------------------------------------------------------------------ | |
147 | /** | |
148 | * Standard constructor | |
013a5f1c | 149 | * |
df0b8ff4 BH |
150 | * @param parent The parent composite |
151 | * @param s The style bits | |
152 | */ | |
73005152 BH |
153 | public TimeCompressionBar(Composite parent, int s) { |
154 | super(parent, s | SWT.NO_BACKGROUND, false); | |
155 | setVScrollBarMode(ScrollView.ALWAYS_OFF); | |
156 | setHScrollBarMode(ScrollView.ALWAYS_OFF); | |
eb63f5ff BH |
157 | fListenerList = new ArrayList<ITimeCompressionListener>(); |
158 | fColors = new ColorImpl[10]; | |
159 | fColors[0] = new ColorImpl(Display.getDefault(), 255, 229, 229); | |
160 | fColors[1] = new ColorImpl(Display.getDefault(), 255, 204, 204); | |
161 | fColors[2] = new ColorImpl(Display.getDefault(), 255, 178, 178); | |
162 | fColors[3] = new ColorImpl(Display.getDefault(), 255, 153, 153); | |
163 | fColors[4] = new ColorImpl(Display.getDefault(), 255, 127, 127); | |
164 | fColors[5] = new ColorImpl(Display.getDefault(), 255, 102, 102); | |
165 | fColors[6] = new ColorImpl(Display.getDefault(), 255, 76, 76); | |
166 | fColors[7] = new ColorImpl(Display.getDefault(), 255, 51, 51); | |
167 | fColors[8] = new ColorImpl(Display.getDefault(), 255, 25, 25); | |
168 | fColors[9] = new ColorImpl(Display.getDefault(), 255, 0, 0); | |
73005152 BH |
169 | super.addDisposeListener(this); |
170 | ||
eb63f5ff | 171 | fAccessible = getViewControl().getAccessible(); |
73005152 | 172 | |
eb63f5ff | 173 | fAccessible.addAccessibleListener(new AccessibleAdapter() { |
73005152 BH |
174 | @Override |
175 | public void getName(AccessibleEvent e) { | |
73005152 | 176 | // Case toolTip |
eb63f5ff BH |
177 | if (e.childID == 0) { |
178 | if (fTooltip != null) { | |
179 | e.result = fTooltip.getAccessibleText(); | |
df0b8ff4 | 180 | } |
73005152 BH |
181 | } else if (e.childID == 1) { |
182 | createFakeTooltip(); | |
eb63f5ff | 183 | e.result = fTooltip.getAccessibleText(); |
73005152 BH |
184 | } |
185 | } | |
186 | }); | |
187 | ||
eb63f5ff | 188 | fAccessible.addAccessibleControlListener(new AccessibleControlAdapter() { |
df0b8ff4 BH |
189 | /* |
190 | * (non-Javadoc) | |
191 | * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getFocus(org.eclipse.swt.accessibility.AccessibleControlEvent) | |
192 | */ | |
73005152 BH |
193 | @Override |
194 | public void getFocus(AccessibleControlEvent e) { | |
eb63f5ff | 195 | if (fFocusedWidget == -1) { |
73005152 | 196 | e.childID = ACC.CHILDID_SELF; |
df0b8ff4 BH |
197 | } |
198 | else { | |
eb63f5ff | 199 | e.childID = fFocusedWidget; |
df0b8ff4 | 200 | } |
73005152 BH |
201 | } |
202 | ||
df0b8ff4 BH |
203 | /* |
204 | * (non-Javadoc) | |
205 | * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getRole(org.eclipse.swt.accessibility.AccessibleControlEvent) | |
206 | */ | |
73005152 BH |
207 | @Override |
208 | public void getRole(AccessibleControlEvent e) { | |
209 | switch (e.childID) { | |
210 | case ACC.CHILDID_SELF: | |
211 | e.detail = ACC.ROLE_CLIENT_AREA; | |
212 | break; | |
213 | case 0: | |
214 | e.detail = ACC.ROLE_TOOLTIP; | |
215 | break; | |
216 | case 1: | |
217 | e.detail = ACC.ROLE_LABEL; | |
218 | break; | |
eb63f5ff BH |
219 | default: |
220 | break; | |
73005152 BH |
221 | } |
222 | } | |
223 | ||
df0b8ff4 BH |
224 | /* |
225 | * (non-Javadoc) | |
226 | * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getState(org.eclipse.swt.accessibility.AccessibleControlEvent) | |
227 | */ | |
73005152 BH |
228 | @Override |
229 | public void getState(AccessibleControlEvent e) { | |
230 | e.detail = ACC.STATE_FOCUSABLE; | |
231 | if (e.childID == ACC.CHILDID_SELF) { | |
232 | e.detail |= ACC.STATE_FOCUSED; | |
233 | } else { | |
234 | e.detail |= ACC.STATE_SELECTABLE; | |
eb63f5ff | 235 | if (e.childID == fFocusedWidget) { |
73005152 | 236 | e.detail |= ACC.STATE_FOCUSED | ACC.STATE_SELECTED | ACC.STATE_CHECKED; |
df0b8ff4 | 237 | } |
73005152 BH |
238 | } |
239 | } | |
240 | }); | |
241 | ||
3145ec83 | 242 | getViewControl().addTraverseListener(new LocalTraverseListener()); |
73005152 | 243 | |
3145ec83 | 244 | addTraverseListener(new LocalTraverseListener()); |
73005152 BH |
245 | |
246 | getViewControl().addFocusListener(new FocusListener() { | |
247 | ||
df0b8ff4 BH |
248 | /* |
249 | * (non-Javadoc) | |
250 | * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) | |
251 | */ | |
73005152 BH |
252 | @Override |
253 | public void focusGained(FocusEvent e) { | |
73005152 BH |
254 | redraw(); |
255 | } | |
256 | ||
df0b8ff4 BH |
257 | /* |
258 | * (non-Javadoc) | |
259 | * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) | |
260 | */ | |
73005152 BH |
261 | @Override |
262 | public void focusLost(FocusEvent e) { | |
263 | redraw(); | |
264 | } | |
265 | }); | |
266 | } | |
267 | ||
df0b8ff4 BH |
268 | // ------------------------------------------------------------------------ |
269 | // Methods | |
270 | // ------------------------------------------------------------------------ | |
271 | ||
272 | /** | |
273 | * Sets the focus widget | |
013a5f1c | 274 | * |
df0b8ff4 BH |
275 | * @param newFocusShape widget reference to set |
276 | */ | |
73005152 | 277 | void setFocus(int newFocusShape) { |
eb63f5ff BH |
278 | fFocusedWidget = newFocusShape; |
279 | if (fFocusedWidget == -1) { | |
73005152 BH |
280 | getViewControl().getAccessible().setFocus(ACC.CHILDID_SELF); |
281 | } else { | |
eb63f5ff | 282 | getViewControl().getAccessible().setFocus(fFocusedWidget); |
73005152 BH |
283 | } |
284 | } | |
285 | ||
df0b8ff4 BH |
286 | /** |
287 | * Sets the current frame. | |
013a5f1c | 288 | * |
df0b8ff4 BH |
289 | * @param theFrame The frame to set |
290 | */ | |
73005152 | 291 | public void setFrame(Frame theFrame) { |
eb63f5ff BH |
292 | fFrame = theFrame; |
293 | fMinTime = fFrame.getMinTime(); | |
294 | fMaxTime = fFrame.getMaxTime(); | |
73005152 BH |
295 | } |
296 | ||
df0b8ff4 BH |
297 | /* |
298 | * (non-Javadoc) | |
299 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int) | |
300 | */ | |
73005152 BH |
301 | @Override |
302 | protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) { | |
eb63f5ff | 303 | if (fFrame == null) { |
73005152 | 304 | return; |
df0b8ff4 | 305 | } |
eb63f5ff | 306 | fNodeList = new ArrayList<SDTimeEvent>(); |
73005152 BH |
307 | int messageArraysStep = 1; |
308 | ||
eb63f5ff BH |
309 | if ((Metrics.getMessageFontHeigth() + Metrics.MESSAGES_NAME_SPACING * 2) * fZoomValue < Metrics.MESSAGE_SIGNIFICANT_VSPACING + 1) { |
310 | messageArraysStep = Math.round(Metrics.MESSAGE_SIGNIFICANT_VSPACING + 1 / ((Metrics.getMessageFontHeigth() + Metrics.MESSAGES_NAME_SPACING * 2) * fZoomValue)); | |
df0b8ff4 | 311 | } |
73005152 | 312 | |
eb63f5ff | 313 | int firstVisible = fFrame.getFirstVisibleSyncMessage(); |
df0b8ff4 | 314 | if (firstVisible > 0) { |
73005152 | 315 | firstVisible = firstVisible - 1; |
df0b8ff4 | 316 | } |
eb63f5ff BH |
317 | for (int i = firstVisible; i < fFrame.syncMessageCount(); i = i + messageArraysStep) { |
318 | SyncMessage m = fFrame.getSyncMessage(i); | |
73005152 | 319 | if (m.hasTimeInfo()) { |
abbdd66a | 320 | SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), m); |
eb63f5ff BH |
321 | fNodeList.add(t); |
322 | if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) { | |
73005152 | 323 | break; |
df0b8ff4 | 324 | } |
73005152 BH |
325 | } |
326 | } | |
327 | ||
eb63f5ff | 328 | firstVisible = fFrame.getFirstVisibleSyncMessageReturn(); |
df0b8ff4 | 329 | if (firstVisible > 0) { |
73005152 | 330 | firstVisible = firstVisible - 1; |
df0b8ff4 | 331 | } |
eb63f5ff BH |
332 | for (int i = firstVisible; i < fFrame.syncMessageReturnCount(); i = i + messageArraysStep) { |
333 | SyncMessage m = fFrame.getSyncMessageReturn(i); | |
73005152 | 334 | if (m.hasTimeInfo()) { |
abbdd66a | 335 | SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getEventOccurrence(), m); |
eb63f5ff BH |
336 | fNodeList.add(t); |
337 | if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) { | |
73005152 | 338 | break; |
df0b8ff4 | 339 | } |
73005152 BH |
340 | } |
341 | } | |
342 | ||
eb63f5ff | 343 | firstVisible = fFrame.getFirstVisibleAsyncMessage(); |
df0b8ff4 | 344 | if (firstVisible > 0) { |
73005152 | 345 | firstVisible = firstVisible - 1; |
df0b8ff4 | 346 | } |
eb63f5ff BH |
347 | for (int i = firstVisible; i < fFrame.asyncMessageCount(); i = i + messageArraysStep) { |
348 | AsyncMessage m = fFrame.getAsyncMessage(i); | |
73005152 | 349 | if (m.hasTimeInfo()) { |
abbdd66a | 350 | SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), m); |
eb63f5ff | 351 | fNodeList.add(t); |
abbdd66a | 352 | t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), m); |
eb63f5ff BH |
353 | fNodeList.add(t); |
354 | if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) { | |
73005152 | 355 | break; |
df0b8ff4 | 356 | } |
73005152 BH |
357 | } |
358 | } | |
359 | ||
eb63f5ff | 360 | firstVisible = fFrame.getFirstVisibleAsyncMessageReturn(); |
df0b8ff4 | 361 | if (firstVisible > 0) { |
73005152 | 362 | firstVisible = firstVisible - 1; |
df0b8ff4 | 363 | } |
eb63f5ff BH |
364 | for (int i = firstVisible; i < fFrame.asyncMessageReturnCount(); i = i + messageArraysStep) { |
365 | AsyncMessageReturn m = fFrame.getAsyncMessageReturn(i); | |
73005152 | 366 | if (m.hasTimeInfo()) { |
abbdd66a | 367 | SDTimeEvent t = new SDTimeEvent(m.getStartTime(), m.getStartOccurrence(), m); |
eb63f5ff | 368 | fNodeList.add(t); |
abbdd66a | 369 | t = new SDTimeEvent(m.getEndTime(), m.getEndOccurrence(), m); |
eb63f5ff BH |
370 | fNodeList.add(t); |
371 | if (m.getY() * fZoomValue > getContentsY() + getVisibleHeight()) { | |
73005152 | 372 | break; |
df0b8ff4 | 373 | } |
73005152 BH |
374 | } |
375 | } | |
376 | ||
eb63f5ff | 377 | List<SDTimeEvent> executionOccurrencesWithTime = fFrame.getExecutionOccurrencesWithTime(); |
73005152 | 378 | if (executionOccurrencesWithTime != null) { |
eb63f5ff | 379 | fNodeList.addAll(executionOccurrencesWithTime); |
73005152 BH |
380 | } |
381 | ||
eb63f5ff | 382 | SDTimeEvent[] temp = fNodeList.toArray(new SDTimeEvent[fNodeList.size()]); |
73005152 | 383 | Arrays.sort(temp, new TimeEventComparator()); |
eb63f5ff | 384 | fNodeList = Arrays.asList(temp); |
73005152 BH |
385 | |
386 | Image dbuffer = null; | |
387 | GC gcim = null; | |
388 | try { | |
389 | dbuffer = new Image(getDisplay(), getClientArea().width, getClientArea().height); | |
390 | } catch (Exception e) { | |
8fd82db5 | 391 | Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$ |
73005152 BH |
392 | } |
393 | gcim = new GC(dbuffer); | |
eb63f5ff | 394 | for (int i = 0; i < fNodeList.size() - 1; i++) { |
abbdd66a AM |
395 | SDTimeEvent m1 = fNodeList.get(i); |
396 | SDTimeEvent m2 = fNodeList.get(i + 1); | |
eb63f5ff BH |
397 | |
398 | if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { | |
399 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
400 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
401 | if ((mes2.getStartLifeline() == null) || (mes1.getEndLifeline() == null)) { | |
402 | continue; | |
73005152 BH |
403 | } |
404 | } | |
405 | ||
eb63f5ff BH |
406 | fMinTime = fFrame.getMinTime(); |
407 | fMaxTime = fFrame.getMaxTime(); | |
408 | ITmfTimestamp minMaxdelta = fMaxTime.getDelta(fMinTime); | |
73005152 BH |
409 | double gr = (minMaxdelta.getValue()) / (double) 10; |
410 | ||
eb63f5ff | 411 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()).getDelta(fMinTime); |
73005152 | 412 | long absDelta = Math.abs(delta.getValue()); |
013a5f1c | 413 | |
73005152 BH |
414 | ColorImpl color; |
415 | if (gr != 0) { | |
416 | int colIndex = Math.round((float) (absDelta / gr)); | |
eb63f5ff BH |
417 | if (colIndex < fColors.length && colIndex > 0) { |
418 | color = fColors[colIndex - 1]; | |
df0b8ff4 | 419 | } else if (colIndex <= 0) { |
eb63f5ff | 420 | color = fColors[0]; |
df0b8ff4 | 421 | } else { |
eb63f5ff | 422 | color = fColors[fColors.length - 1]; |
df0b8ff4 BH |
423 | } |
424 | } else { | |
eb63f5ff | 425 | color = fColors[0]; |
df0b8ff4 | 426 | } |
73005152 | 427 | |
df0b8ff4 | 428 | if (color.getColor() instanceof Color) { |
73005152 | 429 | gcim.setBackground((Color) color.getColor()); |
df0b8ff4 | 430 | } |
73005152 BH |
431 | int y1 = ((GraphNode) m1.getGraphNode()).getY(); |
432 | int y2 = ((GraphNode) m2.getGraphNode()).getY(); | |
433 | if (m1.getGraphNode() instanceof AsyncMessage) { | |
434 | AsyncMessage as = (AsyncMessage) m1.getGraphNode(); | |
df0b8ff4 | 435 | if (as.getEndTime() == m1.getTime()) { |
73005152 | 436 | y1 += as.getHeight(); |
df0b8ff4 | 437 | } |
73005152 BH |
438 | } |
439 | if (m2.getGraphNode() instanceof AsyncMessage) { | |
440 | AsyncMessage as = (AsyncMessage) m2.getGraphNode(); | |
df0b8ff4 | 441 | if (as.getEndTime() == m2.getTime()) { |
73005152 | 442 | y2 += as.getHeight(); |
df0b8ff4 | 443 | } |
73005152 BH |
444 | } |
445 | if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
446 | ||
447 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
df0b8ff4 | 448 | if (m1.getEvent() == eo.getEndOccurrence()) { |
73005152 | 449 | y1 += eo.getHeight(); |
df0b8ff4 | 450 | } |
73005152 BH |
451 | |
452 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
453 | ||
454 | ExecutionOccurrence eo2 = (ExecutionOccurrence) m2.getGraphNode(); | |
df0b8ff4 | 455 | if (m2.getEvent() == eo2.getEndOccurrence()) { |
73005152 | 456 | y2 += eo2.getHeight(); |
df0b8ff4 | 457 | } |
73005152 BH |
458 | |
459 | } | |
460 | } | |
eb63f5ff | 461 | gcim.fillRectangle(contentsToViewX(0), contentsToViewY(Math.round(y1 * fZoomValue)), 10, Math.round((y2 - y1) * fZoomValue) + 1); |
73005152 BH |
462 | if (messageArraysStep == 1) { |
463 | Color backupColor = gcim.getForeground(); | |
464 | gcim.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); | |
eb63f5ff | 465 | gcim.drawRectangle(contentsToViewX(0), contentsToViewY(Math.round(y1 * fZoomValue)), 9, Math.round((y2 - y1) * fZoomValue)); |
73005152 BH |
466 | gcim.setForeground(backupColor); |
467 | } | |
468 | } | |
469 | if (getViewControl().isFocusControl() || isFocusControl()) { | |
eb63f5ff | 470 | gcim.drawFocus(contentsToViewX(0), contentsToViewY(Math.round(fPrevNodeY * fZoomValue)), contentsToViewX(10), Math.round((fNextNodeY - fPrevNodeY) * fZoomValue)); |
73005152 BH |
471 | } |
472 | try { | |
473 | gc.drawImage(dbuffer, 0, 0, getClientArea().width, getClientArea().height, 0, 0, getClientArea().width, getClientArea().height); | |
474 | } catch (Exception e) { | |
8fd82db5 | 475 | Activator.getDefault().logError("Error drawing image", e); //$NON-NLS-1$ |
73005152 BH |
476 | } |
477 | gcim.dispose(); | |
478 | if (dbuffer != null) { | |
479 | dbuffer.dispose(); | |
480 | } | |
481 | gc.dispose(); | |
482 | } | |
483 | ||
df0b8ff4 BH |
484 | /** |
485 | * Checks for focus of children. | |
013a5f1c | 486 | * |
df0b8ff4 BH |
487 | * @param children Control to check |
488 | * @return true if child is on focus else false | |
489 | */ | |
73005152 BH |
490 | protected boolean checkFocusOnChilds(Control childs) { |
491 | if (childs instanceof Composite) { | |
492 | Control[] child = ((Composite) childs).getChildren(); | |
493 | for (int i = 0; i < child.length; i++) { | |
494 | if (child[i].isFocusControl()) { | |
495 | return true; | |
df0b8ff4 | 496 | } |
abbdd66a | 497 | checkFocusOnChilds(child[i]); |
73005152 BH |
498 | } |
499 | } | |
500 | return false; | |
501 | } | |
502 | ||
df0b8ff4 BH |
503 | /* |
504 | * (non-Javadoc) | |
505 | * @see org.eclipse.swt.widgets.Control#isFocusControl() | |
506 | */ | |
73005152 BH |
507 | @Override |
508 | public boolean isFocusControl() { | |
509 | Control[] child = getChildren(); | |
510 | for (int i = 0; i < child.length; i++) { | |
511 | if (child[i].isFocusControl()) { | |
512 | return true; | |
df0b8ff4 | 513 | } |
abbdd66a | 514 | checkFocusOnChilds(child[i]); |
73005152 BH |
515 | } |
516 | return false; | |
517 | } | |
518 | ||
df0b8ff4 BH |
519 | /* |
520 | * (non-Javadoc) | |
521 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseMoveEvent(org.eclipse.swt.events.MouseEvent) | |
522 | */ | |
73005152 BH |
523 | @Override |
524 | protected void contentsMouseMoveEvent(MouseEvent event) { | |
eb63f5ff BH |
525 | if (fTooltip != null) { |
526 | fTooltip.hideToolTip(); | |
df0b8ff4 | 527 | } |
73005152 BH |
528 | super.contentsMouseMoveEvent(event); |
529 | if (!isFocusControl() || getViewControl().isFocusControl()) { | |
530 | Control[] child = getParent().getChildren(); | |
531 | for (int i = 0; i < child.length; i++) { | |
532 | if (child[i].isFocusControl()) { | |
73005152 BH |
533 | break; |
534 | } | |
535 | } | |
536 | } | |
537 | setFocus(-1); | |
538 | } | |
539 | ||
df0b8ff4 BH |
540 | /* |
541 | * (non-Javadoc) | |
542 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseHover(org.eclipse.swt.events.MouseEvent) | |
543 | */ | |
73005152 BH |
544 | @Override |
545 | protected void contentsMouseHover(MouseEvent e) { | |
eb63f5ff BH |
546 | if (fTooltip == null) { |
547 | fTooltip = new DrawableToolTip(this); | |
73005152 | 548 | } |
eb63f5ff | 549 | if (fFrame != null) { |
73005152 | 550 | setFocus(0); |
eb63f5ff | 551 | for (int i = 0; i < fNodeList.size() - 1; i++) { |
abbdd66a AM |
552 | SDTimeEvent m1 = fNodeList.get(i); |
553 | SDTimeEvent m2 = fNodeList.get(i + 1); | |
73005152 | 554 | |
eb63f5ff BH |
555 | if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { |
556 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
557 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
558 | if ((mes2.getStartLifeline() == null) || (mes1.getEndLifeline() == null)) { | |
559 | continue; | |
73005152 BH |
560 | } |
561 | } | |
562 | ||
563 | int y1 = ((GraphNode) m1.getGraphNode()).getY(); | |
564 | int y2 = ((GraphNode) m2.getGraphNode()).getY(); | |
565 | ||
566 | if (m1.getGraphNode() instanceof AsyncMessage) { | |
567 | AsyncMessage as = (AsyncMessage) m1.getGraphNode(); | |
df0b8ff4 | 568 | if (as.getEndTime() == m1.getTime()) { |
73005152 | 569 | y1 += as.getHeight(); |
df0b8ff4 | 570 | } |
73005152 BH |
571 | } |
572 | if (m2.getGraphNode() instanceof AsyncMessage) { | |
573 | AsyncMessage as = (AsyncMessage) m2.getGraphNode(); | |
df0b8ff4 | 574 | if (as.getEndTime() == m2.getTime()) { |
73005152 | 575 | y2 += as.getHeight(); |
df0b8ff4 | 576 | } |
73005152 BH |
577 | } |
578 | if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
579 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
df0b8ff4 | 580 | if (m1.getEvent() == eo.getEndOccurrence()) { |
73005152 | 581 | y1 += eo.getHeight(); |
df0b8ff4 | 582 | } |
73005152 BH |
583 | |
584 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
585 | ||
586 | ExecutionOccurrence eo2 = (ExecutionOccurrence) m2.getGraphNode(); | |
df0b8ff4 | 587 | if (m2.getEvent() == eo2.getEndOccurrence()) { |
73005152 | 588 | y2 += eo2.getHeight(); |
df0b8ff4 | 589 | } |
73005152 BH |
590 | } |
591 | } | |
eb63f5ff BH |
592 | int m1Y = Math.round(y1 * fZoomValue); |
593 | int m2Y = Math.round(y2 * fZoomValue); | |
73005152 | 594 | if ((m1Y < e.y) && (m2Y >= e.y)) { |
df0b8ff4 | 595 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()); |
eb63f5ff | 596 | fTooltip.showToolTip(delta, fMinTime, fMaxTime); |
73005152 BH |
597 | } |
598 | } | |
599 | } | |
600 | setFocus(0); | |
601 | } | |
602 | ||
df0b8ff4 BH |
603 | /* |
604 | * (non-Javadoc) | |
605 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseExit(org.eclipse.swt.events.MouseEvent) | |
606 | */ | |
73005152 BH |
607 | @Override |
608 | protected void contentsMouseExit(MouseEvent e) { | |
013a5f1c | 609 | if (fTooltip != null) { |
eb63f5ff | 610 | fTooltip.hideToolTip(); |
013a5f1c | 611 | } |
73005152 BH |
612 | } |
613 | ||
df0b8ff4 BH |
614 | /* |
615 | * (non-Javadoc) | |
616 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseUpEvent(org.eclipse.swt.events.MouseEvent) | |
617 | */ | |
73005152 BH |
618 | @Override |
619 | protected void contentsMouseUpEvent(MouseEvent event) { | |
620 | selectTimeDelta(event.y, 0); | |
621 | setFocus(); | |
622 | super.contentsMouseUpEvent(event); | |
623 | } | |
624 | ||
625 | /** | |
a55887ca AM |
626 | * Force the time compression bar to highlight the event occurrences between |
627 | * the two given messages. The event occurrences are highlighted on the | |
628 | * first message's end lifeline | |
013a5f1c | 629 | * |
a55887ca AM |
630 | * @param mes1 |
631 | * the first message | |
632 | * @param mes2 | |
633 | * the second message | |
73005152 BH |
634 | */ |
635 | public void highlightRegion(BaseMessage mes1, BaseMessage mes2) { | |
013a5f1c | 636 | BaseMessage localMes1 = mes1; |
eb63f5ff | 637 | BaseMessage localMes2 = mes2; |
013a5f1c | 638 | |
eb63f5ff | 639 | if (fFrame == null) { |
73005152 | 640 | return; |
df0b8ff4 | 641 | } |
eb63f5ff | 642 | if (!(localMes1 instanceof ITimeRange)) { |
73005152 | 643 | return; |
df0b8ff4 | 644 | } |
eb63f5ff | 645 | if (!(localMes2 instanceof ITimeRange)) { |
73005152 | 646 | return; |
df0b8ff4 | 647 | } |
eb63f5ff BH |
648 | ITimeRange t1 = (ITimeRange) localMes1; |
649 | ITimeRange t2 = (ITimeRange) localMes2; | |
73005152 | 650 | |
4df4581d | 651 | ITmfTimestamp time1 = t1.getStartTime(); |
652 | ITmfTimestamp time2 = t2.getStartTime(); | |
eb63f5ff BH |
653 | int event1 = localMes1.getEventOccurrence(); |
654 | int event2 = localMes2.getEventOccurrence(); | |
73005152 | 655 | |
eb63f5ff BH |
656 | if (localMes1 instanceof AsyncMessage) { |
657 | AsyncMessage as = (AsyncMessage) localMes1; | |
73005152 BH |
658 | time1 = as.getEndTime(); |
659 | event1 = as.getEndOccurrence(); | |
660 | } | |
eb63f5ff BH |
661 | if (localMes2 instanceof AsyncMessage) { |
662 | AsyncMessage as = (AsyncMessage) localMes2; | |
73005152 BH |
663 | if (as.getEndOccurrence() > as.getStartOccurrence()) { |
664 | time1 = as.getEndTime(); | |
665 | event1 = as.getEndOccurrence(); | |
666 | } else { | |
667 | time1 = as.getStartTime(); | |
668 | event1 = as.getStartOccurrence(); | |
669 | } | |
670 | } | |
671 | ||
672 | if (event1 > event2) { | |
eb63f5ff BH |
673 | BaseMessage tempMes = localMes2; |
674 | localMes2 = localMes1; | |
675 | localMes1 = tempMes; | |
73005152 | 676 | |
eb63f5ff BH |
677 | t1 = (ITimeRange) localMes1; |
678 | t2 = (ITimeRange) localMes2; | |
73005152 BH |
679 | |
680 | time1 = t1.getStartTime(); | |
681 | time2 = t2.getStartTime(); | |
eb63f5ff BH |
682 | event1 = localMes1.getEventOccurrence(); |
683 | event2 = localMes2.getEventOccurrence(); | |
73005152 | 684 | |
eb63f5ff BH |
685 | if (localMes1 instanceof AsyncMessage) { |
686 | AsyncMessage as = (AsyncMessage) localMes1; | |
73005152 BH |
687 | time1 = as.getEndTime(); |
688 | event1 = as.getEndOccurrence(); | |
689 | } | |
eb63f5ff BH |
690 | if (localMes2 instanceof AsyncMessage) { |
691 | AsyncMessage as = (AsyncMessage) localMes2; | |
73005152 BH |
692 | if (as.getEndOccurrence() > as.getStartOccurrence()) { |
693 | time1 = as.getEndTime(); | |
694 | event1 = as.getEndOccurrence(); | |
695 | } else { | |
696 | time1 = as.getStartTime(); | |
697 | event1 = as.getStartOccurrence(); | |
698 | } | |
699 | } | |
700 | } | |
701 | ||
eb63f5ff | 702 | ITmfTimestamp minMaxdelta = fMaxTime.getDelta(fMinTime); |
73005152 BH |
703 | double gr = (minMaxdelta.getValue()) / (double) 10; |
704 | ||
eb63f5ff | 705 | ITmfTimestamp delta = time2.getDelta(time1).getDelta(fMinTime); |
73005152 BH |
706 | long absDelta = Math.abs(delta.getValue()); |
707 | ||
708 | int colIndex = 0; | |
709 | if (gr != 0) { | |
710 | colIndex = Math.round((float) (absDelta / gr)); | |
eb63f5ff BH |
711 | if (colIndex >= fColors.length) { |
712 | colIndex = fColors.length - 1; | |
df0b8ff4 | 713 | } else if (colIndex < 0) { |
73005152 | 714 | colIndex = 0; |
df0b8ff4 BH |
715 | } |
716 | } else { | |
73005152 | 717 | colIndex = 0; |
df0b8ff4 | 718 | } |
eb63f5ff | 719 | for (int j = 0; j < fListenerList.size(); j++) { |
abbdd66a | 720 | ITimeCompressionListener list = fListenerList.get(j); |
eb63f5ff BH |
721 | if (localMes1.getEndLifeline() != null) { |
722 | list.deltaSelected(localMes1.getEndLifeline(), event1, event2 - event1, fColors[colIndex]); | |
723 | } else if (localMes2.getStartLifeline() != null) { | |
724 | list.deltaSelected(localMes2.getStartLifeline(), event1, event2 - event1, fColors[colIndex]); | |
df0b8ff4 | 725 | } else { |
eb63f5ff | 726 | list.deltaSelected(localMes1.getStartLifeline(), event1, event2 - event1, fColors[colIndex]); |
df0b8ff4 | 727 | } |
73005152 BH |
728 | } |
729 | } | |
730 | ||
731 | /** | |
732 | * Force the time compression bar to highlight the event occurrences between the two given messages. The event | |
733 | * occurrences are highlighted on the first message's end lifeline | |
013a5f1c | 734 | * |
73005152 | 735 | * @param mes1 the first message |
df0b8ff4 | 736 | * @param mes2 the second message |
73005152 BH |
737 | */ |
738 | public void highlightRegionSync(final BaseMessage mes1, final BaseMessage mes2) { | |
739 | getDisplay().syncExec(new Runnable() { | |
740 | @Override | |
741 | public void run() { | |
742 | highlightRegion(mes1, mes2); | |
743 | } | |
744 | }); | |
745 | } | |
746 | ||
df0b8ff4 BH |
747 | /* |
748 | * (non-Javadoc) | |
749 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#scrollBy(int, int) | |
750 | */ | |
73005152 BH |
751 | @Override |
752 | public void scrollBy(int x, int y) { | |
753 | } | |
754 | ||
df0b8ff4 BH |
755 | /** |
756 | * Sets the zoom value. | |
013a5f1c | 757 | * |
df0b8ff4 BH |
758 | * @param value The zoom value to set. |
759 | */ | |
73005152 | 760 | public void setZoom(float value) { |
eb63f5ff | 761 | fZoomValue = value; |
73005152 BH |
762 | redraw(); |
763 | } | |
764 | ||
df0b8ff4 BH |
765 | /** |
766 | * Adds a listener to the time compression listener list to be notified about selected deltas. | |
013a5f1c | 767 | * |
df0b8ff4 BH |
768 | * @param listener The listener to add |
769 | */ | |
73005152 | 770 | public void addTimeCompressionListener(ITimeCompressionListener listener) { |
eb63f5ff BH |
771 | if (!fListenerList.contains(listener)) { |
772 | fListenerList.add(listener); | |
df0b8ff4 | 773 | } |
73005152 BH |
774 | } |
775 | ||
df0b8ff4 BH |
776 | /** |
777 | * Removes a time compression listener. | |
013a5f1c | 778 | * |
df0b8ff4 BH |
779 | * @param listener The listener to remove. |
780 | */ | |
73005152 | 781 | public void removeSelectionChangedListener(ITimeCompressionListener listener) { |
eb63f5ff | 782 | fListenerList.remove(listener); |
73005152 BH |
783 | } |
784 | ||
df0b8ff4 BH |
785 | /* |
786 | * (non-Javadoc) | |
787 | * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) | |
788 | */ | |
73005152 BH |
789 | @Override |
790 | public void widgetDisposed(DisposeEvent e) { | |
eb63f5ff BH |
791 | if (fTooltip != null) { |
792 | fTooltip.dispose(); | |
df0b8ff4 | 793 | } |
73005152 | 794 | super.removeDisposeListener(this); |
eb63f5ff BH |
795 | for (int i = 0; i < fColors.length; i++) { |
796 | fColors[i].dispose(); | |
df0b8ff4 | 797 | } |
73005152 BH |
798 | } |
799 | ||
df0b8ff4 BH |
800 | /* |
801 | * (non-Javadoc) | |
802 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyPressedEvent(org.eclipse.swt.events.KeyEvent) | |
803 | */ | |
73005152 | 804 | @Override |
eb63f5ff BH |
805 | protected void keyPressedEvent(KeyEvent event) { |
806 | if (fTooltip != null) { | |
807 | fTooltip.hideToolTip(); | |
df0b8ff4 | 808 | } |
73005152 BH |
809 | if (!isFocusControl() || getViewControl().isFocusControl()) { |
810 | Control[] child = getParent().getChildren(); | |
811 | for (int i = 0; i < child.length; i++) { | |
812 | if (child[i].isFocusControl()) { | |
813 | // getViewControl().setFocus(); | |
814 | break; | |
815 | } | |
816 | } | |
817 | } | |
818 | setFocus(-1); | |
819 | ||
820 | boolean top = false; | |
eb63f5ff | 821 | if (fNextNodeY == 0) { |
73005152 | 822 | top = true; |
df0b8ff4 | 823 | } |
eb63f5ff BH |
824 | if ((fFrame != null) && (fNextNodeY == 0)) { |
825 | for (int i = 0; i < fNodeList.size() - 1 && i < 1; i++) { | |
abbdd66a AM |
826 | SDTimeEvent m1 = fNodeList.get(i); |
827 | SDTimeEvent m2 = fNodeList.get(i + 1); | |
eb63f5ff BH |
828 | if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { |
829 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
830 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
831 | if ((mes2.getStartLifeline() == null) || (mes1.getEndLifeline() == null)) { | |
832 | continue; | |
73005152 BH |
833 | } |
834 | } | |
835 | ||
836 | int y1 = ((GraphNode) m1.getGraphNode()).getY(); | |
837 | int y2 = ((GraphNode) m2.getGraphNode()).getY(); | |
838 | if (m1.getGraphNode() instanceof AsyncMessage) { | |
839 | AsyncMessage as = (AsyncMessage) m1.getGraphNode(); | |
df0b8ff4 | 840 | if (as.getEndTime() == m1.getTime()) { |
73005152 | 841 | y1 += as.getHeight(); |
df0b8ff4 | 842 | } |
73005152 BH |
843 | } |
844 | if (m2.getGraphNode() instanceof AsyncMessage) { | |
845 | AsyncMessage as = (AsyncMessage) m2.getGraphNode(); | |
df0b8ff4 | 846 | if (as.getEndTime() == m2.getTime()) { |
73005152 | 847 | y2 += as.getHeight(); |
df0b8ff4 | 848 | } |
73005152 BH |
849 | } |
850 | if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
851 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
df0b8ff4 | 852 | if (m1.getEvent() == eo.getEndOccurrence()) { |
73005152 | 853 | y1 += eo.getHeight(); |
df0b8ff4 | 854 | } |
73005152 BH |
855 | |
856 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
857 | ||
858 | ExecutionOccurrence eo2 = (ExecutionOccurrence) m2.getGraphNode(); | |
df0b8ff4 | 859 | if (m2.getEvent() == eo2.getEndOccurrence()) { |
73005152 | 860 | y2 += eo2.getHeight(); |
df0b8ff4 | 861 | } |
73005152 BH |
862 | } |
863 | } | |
eb63f5ff BH |
864 | fPrevNodeY = Math.round(y1 * fZoomValue); |
865 | fNextNodeY = Math.round(y2 * fZoomValue); | |
73005152 BH |
866 | } |
867 | } | |
868 | ||
eb63f5ff BH |
869 | if (fLifeline != null) { |
870 | for (int j = 0; j < fListenerList.size(); j++) { | |
abbdd66a | 871 | ITimeCompressionListener list = fListenerList.get(j); |
eb63f5ff | 872 | list.deltaSelected(fLifeline, fLifelineStart, fLifelineNumEvents, fLifelineColor); |
73005152 | 873 | } |
df0b8ff4 | 874 | } |
73005152 | 875 | |
eb63f5ff | 876 | if (event.keyCode == SWT.ARROW_DOWN) { |
df0b8ff4 | 877 | if (!top) { |
eb63f5ff | 878 | selectTimeDelta(fNextNodeY + 1, 1); |
df0b8ff4 | 879 | } else { |
eb63f5ff | 880 | selectTimeDelta(fPrevNodeY + 1, 1); |
df0b8ff4 | 881 | } |
73005152 | 882 | setFocus(1); |
eb63f5ff BH |
883 | } else if (event.keyCode == SWT.ARROW_UP) { |
884 | selectTimeDelta(fPrevNodeY - 1, 2); | |
73005152 | 885 | setFocus(1); |
eb63f5ff BH |
886 | } else if (event.keyCode == SWT.ARROW_RIGHT) { |
887 | selectTimeDelta(fPrevNodeY, 1); | |
73005152 BH |
888 | setFocus(1); |
889 | } | |
eb63f5ff | 890 | super.keyPressedEvent(event); |
73005152 BH |
891 | } |
892 | ||
73005152 | 893 | /** |
df0b8ff4 | 894 | * Selects the time delta for given delta y coordinate and direction. |
013a5f1c AM |
895 | * |
896 | * @param dy The delta in y coordinate. | |
df0b8ff4 | 897 | * @param direction 0 no direction, 1 = down, 2 = up |
73005152 BH |
898 | */ |
899 | protected void selectTimeDelta(int dy, int direction) { | |
900 | SDTimeEvent lastM1 = null; | |
901 | SDTimeEvent lastM2 = null; | |
902 | int lastY1 = 0; | |
903 | int lastY2 = 0; | |
904 | boolean done = false; | |
eb63f5ff BH |
905 | if (fFrame != null) { |
906 | for (int i = 0; i < fNodeList.size() - 1; i++) { | |
abbdd66a AM |
907 | SDTimeEvent m1 = fNodeList.get(i); |
908 | SDTimeEvent m2 = fNodeList.get(i + 1); | |
eb63f5ff BH |
909 | if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { |
910 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
911 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
912 | if ((mes2.getStartLifeline() == null) || (mes1.getEndLifeline() == null)) { | |
913 | continue; | |
73005152 BH |
914 | } |
915 | } | |
916 | ||
917 | int y1 = ((GraphNode) m1.getGraphNode()).getY(); | |
918 | int y2 = ((GraphNode) m2.getGraphNode()).getY(); | |
919 | if (m1.getGraphNode() instanceof AsyncMessage) { | |
920 | AsyncMessage as = (AsyncMessage) m1.getGraphNode(); | |
df0b8ff4 | 921 | if (as.getEndTime() == m1.getTime()) { |
73005152 | 922 | y1 += as.getHeight(); |
df0b8ff4 | 923 | } |
73005152 BH |
924 | } |
925 | if (m2.getGraphNode() instanceof AsyncMessage) { | |
926 | AsyncMessage as = (AsyncMessage) m2.getGraphNode(); | |
df0b8ff4 | 927 | if (as.getEndTime() == m2.getTime()) { |
73005152 | 928 | y2 += as.getHeight(); |
df0b8ff4 | 929 | } |
73005152 BH |
930 | } |
931 | if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
932 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
df0b8ff4 | 933 | if (m1.getEvent() == eo.getEndOccurrence()) { |
73005152 | 934 | y1 += eo.getHeight(); |
df0b8ff4 | 935 | } |
73005152 BH |
936 | |
937 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
73005152 | 938 | ExecutionOccurrence eo2 = (ExecutionOccurrence) m2.getGraphNode(); |
df0b8ff4 | 939 | if (m2.getEvent() == eo2.getEndOccurrence()) { |
73005152 | 940 | y2 += eo2.getHeight(); |
df0b8ff4 | 941 | } |
73005152 BH |
942 | } |
943 | } | |
eb63f5ff BH |
944 | int m1Y = Math.round(y1 * fZoomValue); |
945 | int m2Y = Math.round(y2 * fZoomValue); | |
73005152 BH |
946 | |
947 | if ((m1Y < dy) && (m2Y > dy) || (!done && m2Y > dy && direction == 1 && lastM1 != null) || (!done && m1Y > dy && direction == 2 && lastM1 != null)) { | |
948 | if (m1Y > dy && direction == 2) { | |
949 | m1 = lastM1; | |
950 | m2 = lastM2; | |
951 | m1Y = lastY1; | |
952 | m2Y = lastY2; | |
953 | } | |
954 | done = true; | |
eb63f5ff BH |
955 | fPrevNodeY = m1Y; |
956 | fNextNodeY = m2Y; | |
957 | ITmfTimestamp minMaxdelta = fMaxTime.getDelta(fMinTime); | |
73005152 BH |
958 | double gr = (minMaxdelta.getValue()) / (double) 10; |
959 | ||
eb63f5ff | 960 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()).getDelta(fMinTime); |
73005152 BH |
961 | long absDelta = Math.abs(delta.getValue()); |
962 | ||
963 | int colIndex = 0; | |
964 | if (gr != 0) { | |
965 | colIndex = Math.round((float) (absDelta / gr)); | |
eb63f5ff BH |
966 | if (colIndex >= fColors.length) { |
967 | colIndex = fColors.length - 1; | |
df0b8ff4 | 968 | } else if (colIndex < 0) { |
73005152 | 969 | colIndex = 0; |
df0b8ff4 BH |
970 | } |
971 | } else { | |
73005152 | 972 | colIndex = 0; |
df0b8ff4 | 973 | } |
73005152 BH |
974 | if (m1.getGraphNode() instanceof BaseMessage) { |
975 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
976 | if (mes1.getEndLifeline() != null) { | |
eb63f5ff BH |
977 | fLifeline = mes1.getEndLifeline(); |
978 | fLifelineStart = m1.getEvent(); | |
979 | fLifelineNumEvents = m2.getEvent() - m1.getEvent(); | |
980 | fLifelineColor = fColors[colIndex]; | |
73005152 | 981 | } else if (m2.getGraphNode() instanceof BaseMessage && ((BaseMessage) m2.getGraphNode()).getStartLifeline() != null) { |
eb63f5ff BH |
982 | fLifeline = ((BaseMessage) m2.getGraphNode()).getStartLifeline(); |
983 | fLifelineStart = m1.getEvent(); | |
984 | fLifelineNumEvents = m2.getEvent() - m1.getEvent(); | |
985 | fLifelineColor = fColors[colIndex]; | |
73005152 | 986 | } else { |
eb63f5ff BH |
987 | fLifeline = mes1.getStartLifeline(); |
988 | fLifelineStart = m1.getEvent(); | |
989 | fLifelineNumEvents = m2.getEvent() - m1.getEvent(); | |
990 | fLifelineColor = fColors[colIndex]; | |
73005152 BH |
991 | } |
992 | } else if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
993 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
994 | ExecutionOccurrence eo = (ExecutionOccurrence) m2.getGraphNode(); | |
eb63f5ff BH |
995 | fLifeline = eo.getLifeline(); |
996 | fLifelineStart = m1.getEvent(); | |
997 | fLifelineNumEvents = m2.getEvent() - m1.getEvent(); | |
998 | fLifelineColor = fColors[colIndex]; | |
73005152 BH |
999 | } else { |
1000 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
eb63f5ff BH |
1001 | fLifeline = eo.getLifeline(); |
1002 | fLifelineStart = m1.getEvent(); | |
1003 | fLifelineNumEvents = m2.getEvent() - m1.getEvent(); | |
1004 | fLifelineColor = fColors[colIndex]; | |
73005152 BH |
1005 | } |
1006 | } | |
eb63f5ff | 1007 | for (int j = 0; j < fListenerList.size(); j++) { |
abbdd66a | 1008 | ITimeCompressionListener list = fListenerList.get(j); |
eb63f5ff | 1009 | list.deltaSelected(fLifeline, fLifelineStart, fLifelineNumEvents, fLifelineColor); |
73005152 BH |
1010 | } |
1011 | break; | |
73005152 | 1012 | } |
abbdd66a AM |
1013 | lastM1 = m1; |
1014 | lastM2 = m2; | |
1015 | lastY1 = m1Y; | |
1016 | lastY2 = m2Y; | |
73005152 BH |
1017 | } |
1018 | } | |
1019 | } | |
1020 | ||
df0b8ff4 | 1021 | /** |
013a5f1c | 1022 | * Creates a fake tool tip. |
df0b8ff4 | 1023 | */ |
73005152 | 1024 | protected void createFakeTooltip() { |
eb63f5ff BH |
1025 | if (fTooltip == null) { |
1026 | fTooltip = new DrawableToolTip(this); | |
73005152 | 1027 | } |
df0b8ff4 | 1028 | |
eb63f5ff | 1029 | if (fFrame != null) { |
73005152 | 1030 | setFocus(0); |
eb63f5ff | 1031 | for (int i = 0; i < fNodeList.size() - 1; i++) { |
abbdd66a AM |
1032 | SDTimeEvent m1 = fNodeList.get(i); |
1033 | SDTimeEvent m2 = fNodeList.get(i + 1); | |
73005152 | 1034 | |
eb63f5ff BH |
1035 | if ((SDViewPref.getInstance().excludeExternalTime()) && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { |
1036 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
1037 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
1038 | if ((mes2.getStartLifeline() == null) || (mes1.getEndLifeline() == null)) { | |
1039 | continue; | |
73005152 BH |
1040 | } |
1041 | } | |
1042 | ||
1043 | int y1 = ((GraphNode) m1.getGraphNode()).getY(); | |
1044 | int y2 = ((GraphNode) m2.getGraphNode()).getY(); | |
1045 | ||
1046 | if (m1.getGraphNode() instanceof AsyncMessage) { | |
1047 | AsyncMessage as = (AsyncMessage) m1.getGraphNode(); | |
df0b8ff4 | 1048 | if (as.getEndTime() == m1.getTime()) { |
73005152 | 1049 | y1 += as.getHeight(); |
df0b8ff4 | 1050 | } |
73005152 BH |
1051 | } |
1052 | if (m2.getGraphNode() instanceof AsyncMessage) { | |
1053 | AsyncMessage as = (AsyncMessage) m2.getGraphNode(); | |
df0b8ff4 | 1054 | if (as.getEndTime() == m2.getTime()) { |
73005152 | 1055 | y2 += as.getHeight(); |
df0b8ff4 | 1056 | } |
73005152 BH |
1057 | } |
1058 | if (m1.getGraphNode() instanceof ExecutionOccurrence) { | |
1059 | ExecutionOccurrence eo = (ExecutionOccurrence) m1.getGraphNode(); | |
df0b8ff4 | 1060 | if (m1.getEvent() == eo.getEndOccurrence()) { |
73005152 | 1061 | y1 += eo.getHeight(); |
df0b8ff4 | 1062 | } |
73005152 BH |
1063 | |
1064 | if (m2.getGraphNode() instanceof ExecutionOccurrence) { | |
1065 | ||
1066 | ExecutionOccurrence eo2 = (ExecutionOccurrence) m2.getGraphNode(); | |
df0b8ff4 | 1067 | if (m2.getEvent() == eo2.getEndOccurrence()) { |
73005152 | 1068 | y2 += eo2.getHeight(); |
df0b8ff4 | 1069 | } |
73005152 BH |
1070 | } |
1071 | } | |
eb63f5ff BH |
1072 | int m1Y = Math.round(y1 * fZoomValue); |
1073 | int m2Y = Math.round(y2 * fZoomValue); | |
1074 | if ((m1Y < fPrevNodeY + 1) && (m2Y >= fPrevNodeY + 1)) { | |
df0b8ff4 | 1075 | ITmfTimestamp delta = m2.getTime().getDelta(m1.getTime()); |
eb63f5ff BH |
1076 | fTooltip.showToolTip(delta, fMinTime, fMaxTime); |
1077 | fTooltip.hideToolTip(); | |
73005152 BH |
1078 | } |
1079 | } | |
1080 | } | |
1081 | } | |
013a5f1c | 1082 | |
3145ec83 BH |
1083 | /** |
1084 | * Traverse Listener implementation. | |
1085 | */ | |
1086 | protected static class LocalTraverseListener implements TraverseListener { | |
1087 | ||
1088 | /* | |
1089 | * (non-Javadoc) | |
1090 | * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent) | |
1091 | */ | |
1092 | @Override | |
1093 | public void keyTraversed(TraverseEvent e) { | |
1094 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) { | |
1095 | e.doit = true; | |
1096 | } | |
1097 | } | |
1098 | } | |
73005152 | 1099 | } |