1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 * $Id: TimeCompressionBar.java,v 1.3 2008/01/24 02:29:01 apnan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessage
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessageReturn
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ExecutionOccurrence
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SDTimeEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.ColorImpl
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.TimeEventComparator
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.accessibility
.ACC
;
38 import org
.eclipse
.swt
.accessibility
.Accessible
;
39 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
40 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
41 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
42 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
43 import org
.eclipse
.swt
.events
.DisposeEvent
;
44 import org
.eclipse
.swt
.events
.DisposeListener
;
45 import org
.eclipse
.swt
.events
.FocusEvent
;
46 import org
.eclipse
.swt
.events
.FocusListener
;
47 import org
.eclipse
.swt
.events
.KeyEvent
;
48 import org
.eclipse
.swt
.events
.MouseEvent
;
49 import org
.eclipse
.swt
.events
.TraverseEvent
;
50 import org
.eclipse
.swt
.events
.TraverseListener
;
51 import org
.eclipse
.swt
.graphics
.Color
;
52 import org
.eclipse
.swt
.graphics
.GC
;
53 import org
.eclipse
.swt
.graphics
.Image
;
54 import org
.eclipse
.swt
.widgets
.Composite
;
55 import org
.eclipse
.swt
.widgets
.Control
;
56 import org
.eclipse
.swt
.widgets
.Display
;
62 public class TimeCompressionBar
extends ScrollView
implements DisposeListener
{
67 protected ArrayList
<ITimeCompressionListener
> listenerList
= null;
69 protected Frame frame
= null;
70 protected List
<SDTimeEvent
> nodeList
= null;
71 protected TmfTimestamp min
= new TmfTimestamp();
72 protected TmfTimestamp max
= new TmfTimestamp();
73 protected float zoomValue
= 1;
74 protected DrawableToolTip tooltip
= null;
76 protected ColorImpl
[] col
;
78 protected Accessible accessible
= null;
80 protected int focusedWidget
= -1;
82 protected SDView view
= null;
84 protected Lifeline ll
= null;
87 protected IColor lc
= null;
89 protected int nextNodeY
= 0;
90 protected int prevNodeY
= 0;
92 public TimeCompressionBar(Composite parent
, int s
) {
93 super(parent
, s
| SWT
.NO_BACKGROUND
, false);
94 setVScrollBarMode(ScrollView
.ALWAYS_OFF
);
95 setHScrollBarMode(ScrollView
.ALWAYS_OFF
);
96 listenerList
= new ArrayList
<ITimeCompressionListener
>();
97 col
= new ColorImpl
[10];
98 col
[0] = new ColorImpl(Display
.getDefault(), 255, 229, 229);
99 col
[1] = new ColorImpl(Display
.getDefault(), 255, 204, 204);
100 col
[2] = new ColorImpl(Display
.getDefault(), 255, 178, 178);
101 col
[3] = new ColorImpl(Display
.getDefault(), 255, 153, 153);
102 col
[4] = new ColorImpl(Display
.getDefault(), 255, 127, 127);
103 col
[5] = new ColorImpl(Display
.getDefault(), 255, 102, 102);
104 col
[6] = new ColorImpl(Display
.getDefault(), 255, 76, 76);
105 col
[7] = new ColorImpl(Display
.getDefault(), 255, 51, 51);
106 col
[8] = new ColorImpl(Display
.getDefault(), 255, 25, 25);
107 col
[9] = new ColorImpl(Display
.getDefault(), 255, 0, 0);
108 super.addDisposeListener(this);
110 accessible
= getViewControl().getAccessible();
112 accessible
.addAccessibleListener(new AccessibleAdapter() {
114 public void getName(AccessibleEvent e
) {
115 if (e
.childID
== ACC
.CHILDID_SELF
) {
116 // e.result = "Sequence Diagram";
119 else if (e
.childID
== 0) {
121 e
.result
= tooltip
.getAccessibleText();
122 } else if (e
.childID
== 1) {
124 e
.result
= tooltip
.getAccessibleText();
129 accessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
131 public void getFocus(AccessibleControlEvent e
) {
132 if (focusedWidget
== -1)
133 e
.childID
= ACC
.CHILDID_SELF
;
135 e
.childID
= focusedWidget
;
139 public void getRole(AccessibleControlEvent e
) {
141 case ACC
.CHILDID_SELF
:
142 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
145 e
.detail
= ACC
.ROLE_TOOLTIP
;
148 e
.detail
= ACC
.ROLE_LABEL
;
154 public void getState(AccessibleControlEvent e
) {
155 e
.detail
= ACC
.STATE_FOCUSABLE
;
156 if (e
.childID
== ACC
.CHILDID_SELF
) {
157 e
.detail
|= ACC
.STATE_FOCUSED
;
159 e
.detail
|= ACC
.STATE_SELECTABLE
;
160 if (e
.childID
== focusedWidget
)
161 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
166 getViewControl().addTraverseListener(new TraverseListener() {
169 public void keyTraversed(TraverseEvent e
) {
170 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
177 addTraverseListener(new TraverseListener() {
180 public void keyTraversed(TraverseEvent e
) {
181 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
188 getViewControl().addFocusListener(new FocusListener() {
191 public void focusGained(FocusEvent e
) {
197 public void focusLost(FocusEvent e
) {
203 void setFocus(int newFocusShape
) {
204 focusedWidget
= newFocusShape
;
205 if (focusedWidget
== -1) {
206 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
208 getViewControl().getAccessible().setFocus(focusedWidget
);
212 public void setFrame(Frame theFrame
) {
214 min
= frame
.getMinTime();
215 max
= frame
.getMaxTime();
219 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
222 nodeList
= new ArrayList
<SDTimeEvent
>();
223 int messageArraysStep
= 1;
225 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * zoomValue
< Metrics
.MESSAGE_SIGNIFICANT_VSPACING
+ 1)
226 messageArraysStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
+ 1 / ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * zoomValue
));
228 int firstVisible
= frame
.getFirstVisibleSyncMessage();
229 if (firstVisible
> 0)
230 firstVisible
= firstVisible
- 1;
231 for (int i
= firstVisible
; i
< frame
.syncMessageCount(); i
= i
+ messageArraysStep
) {
232 SyncMessage m
= frame
.getSyncMessage(i
);
233 if (m
.hasTimeInfo()) {
234 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getEventOccurrence(), (ITimeRange
) m
);
236 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
241 firstVisible
= frame
.getFirstVisibleSyncMessageReturn();
242 if (firstVisible
> 0)
243 firstVisible
= firstVisible
- 1;
244 for (int i
= firstVisible
; i
< frame
.syncMessageReturnCount(); i
= i
+ messageArraysStep
) {
245 SyncMessage m
= frame
.getSyncMessageReturn(i
);
246 if (m
.hasTimeInfo()) {
247 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getEventOccurrence(), (ITimeRange
) m
);
249 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
254 firstVisible
= frame
.getFirstVisibleAsyncMessage();
255 if (firstVisible
> 0)
256 firstVisible
= firstVisible
- 1;
257 for (int i
= firstVisible
; i
< frame
.asyncMessageCount(); i
= i
+ messageArraysStep
) {
258 AsyncMessage m
= frame
.getAsyncMessage(i
);
259 if (m
.hasTimeInfo()) {
260 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getStartOccurrence(), (ITimeRange
) m
);
262 t
= new SDTimeEvent(m
.getEndTime(), m
.getEndOccurrence(), (ITimeRange
) m
);
264 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
269 firstVisible
= frame
.getFirstVisibleAsyncMessageReturn();
270 if (firstVisible
> 0)
271 firstVisible
= firstVisible
- 1;
272 for (int i
= firstVisible
; i
< frame
.asyncMessageReturnCount(); i
= i
+ messageArraysStep
) {
273 AsyncMessageReturn m
= frame
.getAsyncMessageReturn(i
);
274 if (m
.hasTimeInfo()) {
275 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getStartOccurrence(), (ITimeRange
) m
);
277 t
= new SDTimeEvent(m
.getEndTime(), m
.getEndOccurrence(), (ITimeRange
) m
);
279 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
285 * for (int i=0; i<frame.lifeLinesCount();i++) {
286 * Lifeline lifeline = frame.getLifeline(i);
287 * if (lifeline.getExecutions()!=null)
288 * for (int j=lifeline.getExecOccurrenceDrawIndex(); j<lifeline.getExecutions().size(); j++) {
289 * ExecutionOccurrence exec = (ExecutionOccurrence)lifeline.getExecutions().get(j);
290 * if (exec.hasTimeInfo()) {
291 * TimeEvent t = new TimeEvent(exec.getFirstTime(), exec.getStartOccurrence(),(ITimeRange)exec);
293 * t = new TimeEvent(exec.getLastTime(),exec.getEndOccurrence(),(ITimeRange)exec); nodeList.add(t);
295 * if (exec.getY()*zoomValue>getContentsY()+getVisibleHeight()) break;
297 * float g= lifeline.getX()*zoomValue;
298 * int h=frame.getContentX(); int r=frame.getVisibleWidth();
301 List
<SDTimeEvent
> executionOccurrencesWithTime
= frame
.getExecutionOccurrencesWithTime();
302 if (executionOccurrencesWithTime
!= null) {
303 nodeList
.addAll(executionOccurrencesWithTime
);
306 SDTimeEvent
[] temp
= nodeList
.toArray(new SDTimeEvent
[0]);
307 Arrays
.sort(temp
, new TimeEventComparator());
308 nodeList
= Arrays
.asList(temp
);
310 Image dbuffer
= null;
313 dbuffer
= new Image(getDisplay(), getClientArea().width
, getClientArea().height
);
314 } catch (Exception e
) {
315 System
.out
.println(e
.toString());
317 gcim
= new GC(dbuffer
);
318 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
319 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
320 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
322 if (SDViewPref
.getInstance().excludeExternalTime()) {
323 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
324 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
325 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
326 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
331 min
= frame
.getMinTime();
332 max
= frame
.getMaxTime();
333 TmfTimestamp minMaxdelta
= max
.getDelta(min
);
334 double gr
= (minMaxdelta
.getValue()) / (double) 10;
336 TmfTimestamp delta
= m2
.getTime().getDelta(m1
.getTime()).getDelta(min
);
337 long absDelta
= Math
.abs(delta
.getValue());
341 int colIndex
= Math
.round((float) (absDelta
/ gr
));
342 if (colIndex
< col
.length
&& colIndex
> 0)
343 color
= col
[colIndex
- 1];
344 else if (colIndex
<= 0)
347 color
= col
[col
.length
- 1];
351 if (color
.getColor() instanceof Color
)
352 gcim
.setBackground((Color
) color
.getColor());
353 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
354 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
355 if (m1
.getGraphNode() instanceof AsyncMessage
) {
356 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
357 if (as
.getEndTime() == m1
.getTime())
358 y1
+= as
.getHeight();
360 if (m2
.getGraphNode() instanceof AsyncMessage
) {
361 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
362 if (as
.getEndTime() == m2
.getTime())
363 y2
+= as
.getHeight();
365 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
367 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
368 if (m1
.getEvent() == eo
.getEndOccurrence())
369 y1
+= eo
.getHeight();
371 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
373 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
374 if (m2
.getEvent() == eo2
.getEndOccurrence())
375 y2
+= eo2
.getHeight();
379 gcim
.fillRectangle(contentsToViewX(0), contentsToViewY(Math
.round(y1
* zoomValue
)), 10, Math
.round((y2
- y1
) * zoomValue
) + 1);
380 if (messageArraysStep
== 1) {
381 Color backupColor
= gcim
.getForeground();
382 gcim
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
));
383 gcim
.drawRectangle(contentsToViewX(0), contentsToViewY(Math
.round(y1
* zoomValue
)), 9, Math
.round((y2
- y1
) * zoomValue
));
384 gcim
.setForeground(backupColor
);
387 if (getViewControl().isFocusControl() || isFocusControl()) {
388 gcim
.drawFocus(contentsToViewX(0), contentsToViewY(Math
.round(prevNodeY
* zoomValue
)), contentsToViewX(10), Math
.round((nextNodeY
- prevNodeY
) * zoomValue
));
391 gc
.drawImage(dbuffer
, 0, 0, getClientArea().width
, getClientArea().height
, 0, 0, getClientArea().width
, getClientArea().height
);
392 } catch (Exception e
) {
393 System
.out
.println(e
.getMessage());
396 if (dbuffer
!= null) {
402 protected boolean checkFocusOnChilds(Control childs
) {
403 if (childs
instanceof Composite
) {
404 Control
[] child
= ((Composite
) childs
).getChildren();
405 for (int i
= 0; i
< child
.length
; i
++) {
406 if (child
[i
].isFocusControl()) {
409 checkFocusOnChilds(child
[i
]);
416 public boolean isFocusControl() {
417 Control
[] child
= getChildren();
418 for (int i
= 0; i
< child
.length
; i
++) {
419 if (child
[i
].isFocusControl()) {
422 checkFocusOnChilds(child
[i
]);
428 protected void contentsMouseMoveEvent(MouseEvent event
) {
430 tooltip
.hideToolTip();
431 super.contentsMouseMoveEvent(event
);
432 if (!isFocusControl() || getViewControl().isFocusControl()) {
433 Control
[] child
= getParent().getChildren();
434 for (int i
= 0; i
< child
.length
; i
++) {
435 if (child
[i
].isFocusControl()) {
436 // getViewControl().setFocus();
445 protected void contentsMouseHover(MouseEvent e
) {
446 if (tooltip
== null) {
447 tooltip
= new DrawableToolTip(this);
451 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
452 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
453 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
455 if (SDViewPref
.getInstance().excludeExternalTime()) {
456 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
457 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
458 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
459 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
464 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
465 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
467 if (m1
.getGraphNode() instanceof AsyncMessage
) {
468 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
469 if (as
.getEndTime() == m1
.getTime())
470 y1
+= as
.getHeight();
472 if (m2
.getGraphNode() instanceof AsyncMessage
) {
473 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
474 if (as
.getEndTime() == m2
.getTime())
475 y2
+= as
.getHeight();
477 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
478 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
479 if (m1
.getEvent() == eo
.getEndOccurrence())
480 y1
+= eo
.getHeight();
482 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
484 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
485 if (m2
.getEvent() == eo2
.getEndOccurrence())
486 y2
+= eo2
.getHeight();
490 int m1Y
= Math
.round(y1
* zoomValue
);
491 int m2Y
= Math
.round(y2
* zoomValue
);
492 if ((m1Y
< e
.y
) && (m2Y
>= e
.y
)) {
493 TmfTimestamp delta
= m2
.getTime().getDelta(m1
.getTime());
494 tooltip
.showToolTip(delta
, min
, max
);
502 protected void contentsMouseExit(MouseEvent e
) {
504 tooltip
.hideToolTip();
508 protected void contentsMouseUpEvent(MouseEvent event
) {
509 selectTimeDelta(event
.y
, 0);
511 super.contentsMouseUpEvent(event
);
515 * Force the time compression bar to highlight the event occurrences between the two given messages. The event
516 * occurrences are highlighted on the first message's end lifeline
518 * @param mes1 the first message
521 public void highlightRegion(BaseMessage mes1
, BaseMessage mes2
) {
524 if (!(mes1
instanceof ITimeRange
))
526 if (!(mes2
instanceof ITimeRange
))
528 ITimeRange t1
= (ITimeRange
) mes1
;
529 ITimeRange t2
= (ITimeRange
) mes2
;
531 TmfTimestamp time1
= t1
.getStartTime();
532 TmfTimestamp time2
= t2
.getStartTime();
533 int event1
= mes1
.getEventOccurrence();
534 int event2
= mes2
.getEventOccurrence();
536 if (mes1
instanceof AsyncMessage
) {
537 AsyncMessage as
= (AsyncMessage
) mes2
;
538 time1
= as
.getEndTime();
539 event1
= as
.getEndOccurrence();
541 if (mes2
instanceof AsyncMessage
) {
542 AsyncMessage as
= (AsyncMessage
) mes2
;
543 if (as
.getEndOccurrence() > as
.getStartOccurrence()) {
544 time1
= as
.getEndTime();
545 event1
= as
.getEndOccurrence();
547 time1
= as
.getStartTime();
548 event1
= as
.getStartOccurrence();
552 if (event1
> event2
) {
553 BaseMessage tempMes
= mes2
;
557 t1
= (ITimeRange
) mes1
;
558 t2
= (ITimeRange
) mes2
;
560 time1
= t1
.getStartTime();
561 time2
= t2
.getStartTime();
562 event1
= mes1
.getEventOccurrence();
563 event2
= mes2
.getEventOccurrence();
565 if (mes1
instanceof AsyncMessage
) {
566 AsyncMessage as
= (AsyncMessage
) mes2
;
567 time1
= as
.getEndTime();
568 event1
= as
.getEndOccurrence();
570 if (mes2
instanceof AsyncMessage
) {
571 AsyncMessage as
= (AsyncMessage
) mes2
;
572 if (as
.getEndOccurrence() > as
.getStartOccurrence()) {
573 time1
= as
.getEndTime();
574 event1
= as
.getEndOccurrence();
576 time1
= as
.getStartTime();
577 event1
= as
.getStartOccurrence();
582 TmfTimestamp minMaxdelta
= max
.getDelta(min
);
583 double gr
= (minMaxdelta
.getValue()) / (double) 10;
585 TmfTimestamp delta
= time2
.getDelta(time1
).getDelta(min
);
586 long absDelta
= Math
.abs(delta
.getValue());
590 colIndex
= Math
.round((float) (absDelta
/ gr
));
591 if (colIndex
>= col
.length
)
592 colIndex
= col
.length
- 1;
593 else if (colIndex
< 0)
597 for (int j
= 0; j
< listenerList
.size(); j
++) {
598 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
599 if (mes1
.getEndLifeline() != null) {
600 list
.deltaSelected(mes1
.getEndLifeline(), event1
, event2
- event1
, col
[colIndex
]);
601 } else if (mes2
.getStartLifeline() != null) {
602 list
.deltaSelected(mes2
.getStartLifeline(), event1
, event2
- event1
, col
[colIndex
]);
604 list
.deltaSelected(mes1
.getStartLifeline(), event1
, event2
- event1
, col
[colIndex
]);
609 * Force the time compression bar to highlight the event occurrences between the two given messages. The event
610 * occurrences are highlighted on the first message's end lifeline
612 * @param mes1 the first message
615 public void highlightRegionSync(final BaseMessage mes1
, final BaseMessage mes2
) {
616 getDisplay().syncExec(new Runnable() {
619 highlightRegion(mes1
, mes2
);
625 public void scrollBy(int x
, int y
) {
628 public void setZoom(float value
) {
633 public void addTimeCompressionListener(ITimeCompressionListener listener
) {
634 if (!listenerList
.contains(listener
))
635 listenerList
.add(listener
);
638 public void removeSelectionChangedListener(ITimeCompressionListener listener
) {
639 listenerList
.remove(listener
);
643 public void widgetDisposed(DisposeEvent e
) {
646 super.removeDisposeListener(this);
647 for (int i
= 0; i
< col
.length
; i
++)
652 protected void keyPressedEvent(KeyEvent _e
) {
654 tooltip
.hideToolTip();
655 if (!isFocusControl() || getViewControl().isFocusControl()) {
656 Control
[] child
= getParent().getChildren();
657 for (int i
= 0; i
< child
.length
; i
++) {
658 if (child
[i
].isFocusControl()) {
659 // getViewControl().setFocus();
669 if ((frame
!= null) && (nextNodeY
== 0)) {
670 for (int i
= 0; i
< nodeList
.size() - 1 && i
< 1; i
++) {
671 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
672 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
673 if (SDViewPref
.getInstance().excludeExternalTime()) {
674 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
675 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
676 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
677 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
682 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
683 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
684 if (m1
.getGraphNode() instanceof AsyncMessage
) {
685 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
686 if (as
.getEndTime() == m1
.getTime())
687 y1
+= as
.getHeight();
689 if (m2
.getGraphNode() instanceof AsyncMessage
) {
690 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
691 if (as
.getEndTime() == m2
.getTime())
692 y2
+= as
.getHeight();
694 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
695 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
696 if (m1
.getEvent() == eo
.getEndOccurrence())
697 y1
+= eo
.getHeight();
699 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
701 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
702 if (m2
.getEvent() == eo2
.getEndOccurrence())
703 y2
+= eo2
.getHeight();
707 prevNodeY
= Math
.round(y1
* zoomValue
);
708 nextNodeY
= Math
.round(y2
* zoomValue
);
713 for (int j
= 0; j
< listenerList
.size(); j
++) {
714 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
715 list
.deltaSelected(ll
, ls
, ln
, lc
);
718 if (_e
.keyCode
== SWT
.ARROW_DOWN
) {
720 selectTimeDelta(nextNodeY
+ 1, 1);
722 selectTimeDelta(prevNodeY
+ 1, 1);
724 } else if (_e
.keyCode
== SWT
.ARROW_UP
) {
725 selectTimeDelta(prevNodeY
- 1, 2);
727 } else if (_e
.keyCode
== SWT
.ARROW_RIGHT
) {
728 selectTimeDelta(prevNodeY
, 1);
731 super.keyPressedEvent(_e
);
735 protected void keyReleasedEvent(KeyEvent _e
) {
736 super.keyReleasedEvent(_e
);
740 * 0 no direction, 1 = down, 2 = up
745 protected void selectTimeDelta(int dy
, int direction
) {
746 SDTimeEvent lastM1
= null;
747 SDTimeEvent lastM2
= null;
750 boolean done
= false;
752 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
753 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
754 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
755 if (SDViewPref
.getInstance().excludeExternalTime()) {
756 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
757 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
758 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
759 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
764 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
765 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
766 if (m1
.getGraphNode() instanceof AsyncMessage
) {
767 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
768 if (as
.getEndTime() == m1
.getTime())
769 y1
+= as
.getHeight();
771 if (m2
.getGraphNode() instanceof AsyncMessage
) {
772 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
773 if (as
.getEndTime() == m2
.getTime())
774 y2
+= as
.getHeight();
776 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
777 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
778 if (m1
.getEvent() == eo
.getEndOccurrence())
779 y1
+= eo
.getHeight();
781 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
783 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
784 if (m2
.getEvent() == eo2
.getEndOccurrence())
785 y2
+= eo2
.getHeight();
789 int m1Y
= Math
.round(y1
* zoomValue
);
790 int m2Y
= Math
.round(y2
* zoomValue
);
792 if ((m1Y
< dy
) && (m2Y
> dy
) || (!done
&& m2Y
> dy
&& direction
== 1 && lastM1
!= null) || (!done
&& m1Y
> dy
&& direction
== 2 && lastM1
!= null)) {
793 if (m1Y
> dy
&& direction
== 2) {
802 TmfTimestamp minMaxdelta
= max
.getDelta(min
);
803 double gr
= (minMaxdelta
.getValue()) / (double) 10;
805 TmfTimestamp delta
= m2
.getTime().getDelta(m1
.getTime()).getDelta(min
);
806 long absDelta
= Math
.abs(delta
.getValue());
810 colIndex
= Math
.round((float) (absDelta
/ gr
));
811 if (colIndex
>= col
.length
)
812 colIndex
= col
.length
- 1;
813 else if (colIndex
< 0)
817 if (m1
.getGraphNode() instanceof BaseMessage
) {
818 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
819 if (mes1
.getEndLifeline() != null) {
820 ll
= mes1
.getEndLifeline();
822 ln
= m2
.getEvent() - m1
.getEvent();
824 } else if (m2
.getGraphNode() instanceof BaseMessage
&& ((BaseMessage
) m2
.getGraphNode()).getStartLifeline() != null) {
825 ll
= ((BaseMessage
) m2
.getGraphNode()).getStartLifeline();
827 ln
= m2
.getEvent() - m1
.getEvent();
830 ll
= mes1
.getStartLifeline();
832 ln
= m2
.getEvent() - m1
.getEvent();
835 } else if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
836 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
837 ExecutionOccurrence eo
= (ExecutionOccurrence
) m2
.getGraphNode();
838 ll
= eo
.getLifeline();
840 ln
= m2
.getEvent() - m1
.getEvent();
843 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
844 ll
= eo
.getLifeline();
846 ln
= m2
.getEvent() - m1
.getEvent();
850 for (int j
= 0; j
< listenerList
.size(); j
++) {
851 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
852 list
.deltaSelected(ll
, ls
, ln
, lc
);
865 protected void createFakeTooltip() {
866 if (tooltip
== null) {
867 tooltip
= new DrawableToolTip(this);
871 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
872 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
873 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
875 if (SDViewPref
.getInstance().excludeExternalTime()) {
876 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
877 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
878 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
879 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
884 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
885 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
887 if (m1
.getGraphNode() instanceof AsyncMessage
) {
888 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
889 if (as
.getEndTime() == m1
.getTime())
890 y1
+= as
.getHeight();
892 if (m2
.getGraphNode() instanceof AsyncMessage
) {
893 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
894 if (as
.getEndTime() == m2
.getTime())
895 y2
+= as
.getHeight();
897 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
898 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
899 if (m1
.getEvent() == eo
.getEndOccurrence())
900 y1
+= eo
.getHeight();
902 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
904 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
905 if (m2
.getEvent() == eo2
.getEndOccurrence())
906 y2
+= eo2
.getHeight();
910 int m1Y
= Math
.round(y1
* zoomValue
);
911 int m2Y
= Math
.round(y2
* zoomValue
);
912 if ((m1Y
< prevNodeY
+ 1) && (m2Y
>= prevNodeY
+ 1)) {
913 TmfTimestamp delta
= m2
.getTime().getDelta(m1
.getTime());
914 tooltip
.showToolTip(delta
, min
, max
);
915 tooltip
.hideToolTip();