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