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