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
.core
.event
.ITmfTimestamp
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessage
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessageReturn
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ExecutionOccurrence
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SDTimeEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.impl
.ColorImpl
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.TimeEventComparator
;
37 import org
.eclipse
.swt
.SWT
;
38 import org
.eclipse
.swt
.accessibility
.ACC
;
39 import org
.eclipse
.swt
.accessibility
.Accessible
;
40 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
41 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
42 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
43 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
44 import org
.eclipse
.swt
.events
.DisposeEvent
;
45 import org
.eclipse
.swt
.events
.DisposeListener
;
46 import org
.eclipse
.swt
.events
.FocusEvent
;
47 import org
.eclipse
.swt
.events
.FocusListener
;
48 import org
.eclipse
.swt
.events
.KeyEvent
;
49 import org
.eclipse
.swt
.events
.MouseEvent
;
50 import org
.eclipse
.swt
.events
.TraverseEvent
;
51 import org
.eclipse
.swt
.events
.TraverseListener
;
52 import org
.eclipse
.swt
.graphics
.Color
;
53 import org
.eclipse
.swt
.graphics
.GC
;
54 import org
.eclipse
.swt
.graphics
.Image
;
55 import org
.eclipse
.swt
.widgets
.Composite
;
56 import org
.eclipse
.swt
.widgets
.Control
;
57 import org
.eclipse
.swt
.widgets
.Display
;
63 public class TimeCompressionBar
extends ScrollView
implements DisposeListener
{
68 protected ArrayList
<ITimeCompressionListener
> listenerList
= null;
70 protected Frame frame
= null;
71 protected List
<SDTimeEvent
> nodeList
= null;
72 protected ITmfTimestamp min
= new TmfTimestamp();
73 protected ITmfTimestamp max
= new TmfTimestamp();
74 protected float zoomValue
= 1;
75 protected DrawableToolTip tooltip
= null;
77 protected ColorImpl
[] col
;
79 protected Accessible accessible
= null;
81 protected int focusedWidget
= -1;
83 protected SDView view
= null;
85 protected Lifeline ll
= null;
88 protected IColor lc
= null;
90 protected int nextNodeY
= 0;
91 protected int prevNodeY
= 0;
93 public TimeCompressionBar(Composite parent
, int s
) {
94 super(parent
, s
| SWT
.NO_BACKGROUND
, false);
95 setVScrollBarMode(ScrollView
.ALWAYS_OFF
);
96 setHScrollBarMode(ScrollView
.ALWAYS_OFF
);
97 listenerList
= new ArrayList
<ITimeCompressionListener
>();
98 col
= new ColorImpl
[10];
99 col
[0] = new ColorImpl(Display
.getDefault(), 255, 229, 229);
100 col
[1] = new ColorImpl(Display
.getDefault(), 255, 204, 204);
101 col
[2] = new ColorImpl(Display
.getDefault(), 255, 178, 178);
102 col
[3] = new ColorImpl(Display
.getDefault(), 255, 153, 153);
103 col
[4] = new ColorImpl(Display
.getDefault(), 255, 127, 127);
104 col
[5] = new ColorImpl(Display
.getDefault(), 255, 102, 102);
105 col
[6] = new ColorImpl(Display
.getDefault(), 255, 76, 76);
106 col
[7] = new ColorImpl(Display
.getDefault(), 255, 51, 51);
107 col
[8] = new ColorImpl(Display
.getDefault(), 255, 25, 25);
108 col
[9] = new ColorImpl(Display
.getDefault(), 255, 0, 0);
109 super.addDisposeListener(this);
111 accessible
= getViewControl().getAccessible();
113 accessible
.addAccessibleListener(new AccessibleAdapter() {
115 public void getName(AccessibleEvent e
) {
116 if (e
.childID
== ACC
.CHILDID_SELF
) {
117 // e.result = "Sequence Diagram";
120 else if (e
.childID
== 0) {
122 e
.result
= tooltip
.getAccessibleText();
123 } else if (e
.childID
== 1) {
125 e
.result
= tooltip
.getAccessibleText();
130 accessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
132 public void getFocus(AccessibleControlEvent e
) {
133 if (focusedWidget
== -1)
134 e
.childID
= ACC
.CHILDID_SELF
;
136 e
.childID
= focusedWidget
;
140 public void getRole(AccessibleControlEvent e
) {
142 case ACC
.CHILDID_SELF
:
143 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
146 e
.detail
= ACC
.ROLE_TOOLTIP
;
149 e
.detail
= ACC
.ROLE_LABEL
;
155 public void getState(AccessibleControlEvent e
) {
156 e
.detail
= ACC
.STATE_FOCUSABLE
;
157 if (e
.childID
== ACC
.CHILDID_SELF
) {
158 e
.detail
|= ACC
.STATE_FOCUSED
;
160 e
.detail
|= ACC
.STATE_SELECTABLE
;
161 if (e
.childID
== focusedWidget
)
162 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
167 getViewControl().addTraverseListener(new TraverseListener() {
170 public void keyTraversed(TraverseEvent e
) {
171 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
178 addTraverseListener(new TraverseListener() {
181 public void keyTraversed(TraverseEvent e
) {
182 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
189 getViewControl().addFocusListener(new FocusListener() {
192 public void focusGained(FocusEvent e
) {
198 public void focusLost(FocusEvent e
) {
204 void setFocus(int newFocusShape
) {
205 focusedWidget
= newFocusShape
;
206 if (focusedWidget
== -1) {
207 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
209 getViewControl().getAccessible().setFocus(focusedWidget
);
213 public void setFrame(Frame theFrame
) {
215 min
= frame
.getMinTime();
216 max
= frame
.getMaxTime();
220 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
223 nodeList
= new ArrayList
<SDTimeEvent
>();
224 int messageArraysStep
= 1;
226 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * zoomValue
< Metrics
.MESSAGE_SIGNIFICANT_VSPACING
+ 1)
227 messageArraysStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
+ 1 / ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * zoomValue
));
229 int firstVisible
= frame
.getFirstVisibleSyncMessage();
230 if (firstVisible
> 0)
231 firstVisible
= firstVisible
- 1;
232 for (int i
= firstVisible
; i
< frame
.syncMessageCount(); i
= i
+ messageArraysStep
) {
233 SyncMessage m
= frame
.getSyncMessage(i
);
234 if (m
.hasTimeInfo()) {
235 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getEventOccurrence(), (ITimeRange
) m
);
237 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
242 firstVisible
= frame
.getFirstVisibleSyncMessageReturn();
243 if (firstVisible
> 0)
244 firstVisible
= firstVisible
- 1;
245 for (int i
= firstVisible
; i
< frame
.syncMessageReturnCount(); i
= i
+ messageArraysStep
) {
246 SyncMessage m
= frame
.getSyncMessageReturn(i
);
247 if (m
.hasTimeInfo()) {
248 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getEventOccurrence(), (ITimeRange
) m
);
250 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
255 firstVisible
= frame
.getFirstVisibleAsyncMessage();
256 if (firstVisible
> 0)
257 firstVisible
= firstVisible
- 1;
258 for (int i
= firstVisible
; i
< frame
.asyncMessageCount(); i
= i
+ messageArraysStep
) {
259 AsyncMessage m
= frame
.getAsyncMessage(i
);
260 if (m
.hasTimeInfo()) {
261 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getStartOccurrence(), (ITimeRange
) m
);
263 t
= new SDTimeEvent(m
.getEndTime(), m
.getEndOccurrence(), (ITimeRange
) m
);
265 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
270 firstVisible
= frame
.getFirstVisibleAsyncMessageReturn();
271 if (firstVisible
> 0)
272 firstVisible
= firstVisible
- 1;
273 for (int i
= firstVisible
; i
< frame
.asyncMessageReturnCount(); i
= i
+ messageArraysStep
) {
274 AsyncMessageReturn m
= frame
.getAsyncMessageReturn(i
);
275 if (m
.hasTimeInfo()) {
276 SDTimeEvent t
= new SDTimeEvent(m
.getStartTime(), m
.getStartOccurrence(), (ITimeRange
) m
);
278 t
= new SDTimeEvent(m
.getEndTime(), m
.getEndOccurrence(), (ITimeRange
) m
);
280 if (m
.getY() * zoomValue
> getContentsY() + getVisibleHeight())
286 * for (int i=0; i<frame.lifeLinesCount();i++) {
287 * Lifeline lifeline = frame.getLifeline(i);
288 * if (lifeline.getExecutions()!=null)
289 * for (int j=lifeline.getExecOccurrenceDrawIndex(); j<lifeline.getExecutions().size(); j++) {
290 * ExecutionOccurrence exec = (ExecutionOccurrence)lifeline.getExecutions().get(j);
291 * if (exec.hasTimeInfo()) {
292 * TimeEvent t = new TimeEvent(exec.getFirstTime(), exec.getStartOccurrence(),(ITimeRange)exec);
294 * t = new TimeEvent(exec.getLastTime(),exec.getEndOccurrence(),(ITimeRange)exec); nodeList.add(t);
296 * if (exec.getY()*zoomValue>getContentsY()+getVisibleHeight()) break;
298 * float g= lifeline.getX()*zoomValue;
299 * int h=frame.getContentX(); int r=frame.getVisibleWidth();
302 List
<SDTimeEvent
> executionOccurrencesWithTime
= frame
.getExecutionOccurrencesWithTime();
303 if (executionOccurrencesWithTime
!= null) {
304 nodeList
.addAll(executionOccurrencesWithTime
);
307 SDTimeEvent
[] temp
= nodeList
.toArray(new SDTimeEvent
[0]);
308 Arrays
.sort(temp
, new TimeEventComparator());
309 nodeList
= Arrays
.asList(temp
);
311 Image dbuffer
= null;
314 dbuffer
= new Image(getDisplay(), getClientArea().width
, getClientArea().height
);
315 } catch (Exception e
) {
316 System
.out
.println(e
.toString());
318 gcim
= new GC(dbuffer
);
319 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
320 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
321 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
323 if (SDViewPref
.getInstance().excludeExternalTime()) {
324 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
325 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
326 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
327 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
332 min
= frame
.getMinTime();
333 max
= frame
.getMaxTime();
334 ITmfTimestamp minMaxdelta
= (TmfTimestamp
) max
.getDelta(min
);
335 double gr
= (minMaxdelta
.getValue()) / (double) 10;
337 ITmfTimestamp delta
= (TmfTimestamp
) m2
.getTime().getDelta(m1
.getTime()).getDelta(min
);
338 long absDelta
= Math
.abs(delta
.getValue());
342 int colIndex
= Math
.round((float) (absDelta
/ gr
));
343 if (colIndex
< col
.length
&& colIndex
> 0)
344 color
= col
[colIndex
- 1];
345 else if (colIndex
<= 0)
348 color
= col
[col
.length
- 1];
352 if (color
.getColor() instanceof Color
)
353 gcim
.setBackground((Color
) color
.getColor());
354 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
355 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
356 if (m1
.getGraphNode() instanceof AsyncMessage
) {
357 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
358 if (as
.getEndTime() == m1
.getTime())
359 y1
+= as
.getHeight();
361 if (m2
.getGraphNode() instanceof AsyncMessage
) {
362 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
363 if (as
.getEndTime() == m2
.getTime())
364 y2
+= as
.getHeight();
366 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
368 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
369 if (m1
.getEvent() == eo
.getEndOccurrence())
370 y1
+= eo
.getHeight();
372 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
374 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
375 if (m2
.getEvent() == eo2
.getEndOccurrence())
376 y2
+= eo2
.getHeight();
380 gcim
.fillRectangle(contentsToViewX(0), contentsToViewY(Math
.round(y1
* zoomValue
)), 10, Math
.round((y2
- y1
) * zoomValue
) + 1);
381 if (messageArraysStep
== 1) {
382 Color backupColor
= gcim
.getForeground();
383 gcim
.setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_WHITE
));
384 gcim
.drawRectangle(contentsToViewX(0), contentsToViewY(Math
.round(y1
* zoomValue
)), 9, Math
.round((y2
- y1
) * zoomValue
));
385 gcim
.setForeground(backupColor
);
388 if (getViewControl().isFocusControl() || isFocusControl()) {
389 gcim
.drawFocus(contentsToViewX(0), contentsToViewY(Math
.round(prevNodeY
* zoomValue
)), contentsToViewX(10), Math
.round((nextNodeY
- prevNodeY
) * zoomValue
));
392 gc
.drawImage(dbuffer
, 0, 0, getClientArea().width
, getClientArea().height
, 0, 0, getClientArea().width
, getClientArea().height
);
393 } catch (Exception e
) {
394 System
.out
.println(e
.getMessage());
397 if (dbuffer
!= null) {
403 protected boolean checkFocusOnChilds(Control childs
) {
404 if (childs
instanceof Composite
) {
405 Control
[] child
= ((Composite
) childs
).getChildren();
406 for (int i
= 0; i
< child
.length
; i
++) {
407 if (child
[i
].isFocusControl()) {
410 checkFocusOnChilds(child
[i
]);
417 public boolean isFocusControl() {
418 Control
[] child
= getChildren();
419 for (int i
= 0; i
< child
.length
; i
++) {
420 if (child
[i
].isFocusControl()) {
423 checkFocusOnChilds(child
[i
]);
429 protected void contentsMouseMoveEvent(MouseEvent event
) {
431 tooltip
.hideToolTip();
432 super.contentsMouseMoveEvent(event
);
433 if (!isFocusControl() || getViewControl().isFocusControl()) {
434 Control
[] child
= getParent().getChildren();
435 for (int i
= 0; i
< child
.length
; i
++) {
436 if (child
[i
].isFocusControl()) {
437 // getViewControl().setFocus();
446 protected void contentsMouseHover(MouseEvent e
) {
447 if (tooltip
== null) {
448 tooltip
= new DrawableToolTip(this);
452 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
453 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
454 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
456 if (SDViewPref
.getInstance().excludeExternalTime()) {
457 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
458 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
459 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
460 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
465 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
466 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
468 if (m1
.getGraphNode() instanceof AsyncMessage
) {
469 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
470 if (as
.getEndTime() == m1
.getTime())
471 y1
+= as
.getHeight();
473 if (m2
.getGraphNode() instanceof AsyncMessage
) {
474 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
475 if (as
.getEndTime() == m2
.getTime())
476 y2
+= as
.getHeight();
478 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
479 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
480 if (m1
.getEvent() == eo
.getEndOccurrence())
481 y1
+= eo
.getHeight();
483 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
485 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
486 if (m2
.getEvent() == eo2
.getEndOccurrence())
487 y2
+= eo2
.getHeight();
491 int m1Y
= Math
.round(y1
* zoomValue
);
492 int m2Y
= Math
.round(y2
* zoomValue
);
493 if ((m1Y
< e
.y
) && (m2Y
>= e
.y
)) {
494 TmfTimestamp delta
= (TmfTimestamp
) m2
.getTime().getDelta(m1
.getTime());
495 tooltip
.showToolTip(delta
, min
, max
);
503 protected void contentsMouseExit(MouseEvent e
) {
505 tooltip
.hideToolTip();
509 protected void contentsMouseUpEvent(MouseEvent event
) {
510 selectTimeDelta(event
.y
, 0);
512 super.contentsMouseUpEvent(event
);
516 * Force the time compression bar to highlight the event occurrences between the two given messages. The event
517 * occurrences are highlighted on the first message's end lifeline
519 * @param mes1 the first message
522 public void highlightRegion(BaseMessage mes1
, BaseMessage mes2
) {
525 if (!(mes1
instanceof ITimeRange
))
527 if (!(mes2
instanceof ITimeRange
))
529 ITimeRange t1
= (ITimeRange
) mes1
;
530 ITimeRange t2
= (ITimeRange
) mes2
;
532 ITmfTimestamp time1
= t1
.getStartTime();
533 ITmfTimestamp time2
= t2
.getStartTime();
534 int event1
= mes1
.getEventOccurrence();
535 int event2
= mes2
.getEventOccurrence();
537 if (mes1
instanceof AsyncMessage
) {
538 AsyncMessage as
= (AsyncMessage
) mes2
;
539 time1
= as
.getEndTime();
540 event1
= as
.getEndOccurrence();
542 if (mes2
instanceof AsyncMessage
) {
543 AsyncMessage as
= (AsyncMessage
) mes2
;
544 if (as
.getEndOccurrence() > as
.getStartOccurrence()) {
545 time1
= as
.getEndTime();
546 event1
= as
.getEndOccurrence();
548 time1
= as
.getStartTime();
549 event1
= as
.getStartOccurrence();
553 if (event1
> event2
) {
554 BaseMessage tempMes
= mes2
;
558 t1
= (ITimeRange
) mes1
;
559 t2
= (ITimeRange
) mes2
;
561 time1
= t1
.getStartTime();
562 time2
= t2
.getStartTime();
563 event1
= mes1
.getEventOccurrence();
564 event2
= mes2
.getEventOccurrence();
566 if (mes1
instanceof AsyncMessage
) {
567 AsyncMessage as
= (AsyncMessage
) mes2
;
568 time1
= as
.getEndTime();
569 event1
= as
.getEndOccurrence();
571 if (mes2
instanceof AsyncMessage
) {
572 AsyncMessage as
= (AsyncMessage
) mes2
;
573 if (as
.getEndOccurrence() > as
.getStartOccurrence()) {
574 time1
= as
.getEndTime();
575 event1
= as
.getEndOccurrence();
577 time1
= as
.getStartTime();
578 event1
= as
.getStartOccurrence();
583 TmfTimestamp minMaxdelta
= (TmfTimestamp
) max
.getDelta(min
);
584 double gr
= (minMaxdelta
.getValue()) / (double) 10;
586 TmfTimestamp delta
= (TmfTimestamp
) time2
.getDelta(time1
).getDelta(min
);
587 long absDelta
= Math
.abs(delta
.getValue());
591 colIndex
= Math
.round((float) (absDelta
/ gr
));
592 if (colIndex
>= col
.length
)
593 colIndex
= col
.length
- 1;
594 else if (colIndex
< 0)
598 for (int j
= 0; j
< listenerList
.size(); j
++) {
599 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
600 if (mes1
.getEndLifeline() != null) {
601 list
.deltaSelected(mes1
.getEndLifeline(), event1
, event2
- event1
, col
[colIndex
]);
602 } else if (mes2
.getStartLifeline() != null) {
603 list
.deltaSelected(mes2
.getStartLifeline(), event1
, event2
- event1
, col
[colIndex
]);
605 list
.deltaSelected(mes1
.getStartLifeline(), event1
, event2
- event1
, col
[colIndex
]);
610 * Force the time compression bar to highlight the event occurrences between the two given messages. The event
611 * occurrences are highlighted on the first message's end lifeline
613 * @param mes1 the first message
616 public void highlightRegionSync(final BaseMessage mes1
, final BaseMessage mes2
) {
617 getDisplay().syncExec(new Runnable() {
620 highlightRegion(mes1
, mes2
);
626 public void scrollBy(int x
, int y
) {
629 public void setZoom(float value
) {
634 public void addTimeCompressionListener(ITimeCompressionListener listener
) {
635 if (!listenerList
.contains(listener
))
636 listenerList
.add(listener
);
639 public void removeSelectionChangedListener(ITimeCompressionListener listener
) {
640 listenerList
.remove(listener
);
644 public void widgetDisposed(DisposeEvent e
) {
647 super.removeDisposeListener(this);
648 for (int i
= 0; i
< col
.length
; i
++)
653 protected void keyPressedEvent(KeyEvent _e
) {
655 tooltip
.hideToolTip();
656 if (!isFocusControl() || getViewControl().isFocusControl()) {
657 Control
[] child
= getParent().getChildren();
658 for (int i
= 0; i
< child
.length
; i
++) {
659 if (child
[i
].isFocusControl()) {
660 // getViewControl().setFocus();
670 if ((frame
!= null) && (nextNodeY
== 0)) {
671 for (int i
= 0; i
< nodeList
.size() - 1 && i
< 1; i
++) {
672 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
673 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
674 if (SDViewPref
.getInstance().excludeExternalTime()) {
675 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
676 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
677 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
678 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
683 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
684 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
685 if (m1
.getGraphNode() instanceof AsyncMessage
) {
686 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
687 if (as
.getEndTime() == m1
.getTime())
688 y1
+= as
.getHeight();
690 if (m2
.getGraphNode() instanceof AsyncMessage
) {
691 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
692 if (as
.getEndTime() == m2
.getTime())
693 y2
+= as
.getHeight();
695 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
696 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
697 if (m1
.getEvent() == eo
.getEndOccurrence())
698 y1
+= eo
.getHeight();
700 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
702 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
703 if (m2
.getEvent() == eo2
.getEndOccurrence())
704 y2
+= eo2
.getHeight();
708 prevNodeY
= Math
.round(y1
* zoomValue
);
709 nextNodeY
= Math
.round(y2
* zoomValue
);
714 for (int j
= 0; j
< listenerList
.size(); j
++) {
715 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
716 list
.deltaSelected(ll
, ls
, ln
, lc
);
719 if (_e
.keyCode
== SWT
.ARROW_DOWN
) {
721 selectTimeDelta(nextNodeY
+ 1, 1);
723 selectTimeDelta(prevNodeY
+ 1, 1);
725 } else if (_e
.keyCode
== SWT
.ARROW_UP
) {
726 selectTimeDelta(prevNodeY
- 1, 2);
728 } else if (_e
.keyCode
== SWT
.ARROW_RIGHT
) {
729 selectTimeDelta(prevNodeY
, 1);
732 super.keyPressedEvent(_e
);
736 protected void keyReleasedEvent(KeyEvent _e
) {
737 super.keyReleasedEvent(_e
);
741 * 0 no direction, 1 = down, 2 = up
746 protected void selectTimeDelta(int dy
, int direction
) {
747 SDTimeEvent lastM1
= null;
748 SDTimeEvent lastM2
= null;
751 boolean done
= false;
753 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
754 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
755 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
756 if (SDViewPref
.getInstance().excludeExternalTime()) {
757 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
758 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
759 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
760 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
765 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
766 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
767 if (m1
.getGraphNode() instanceof AsyncMessage
) {
768 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
769 if (as
.getEndTime() == m1
.getTime())
770 y1
+= as
.getHeight();
772 if (m2
.getGraphNode() instanceof AsyncMessage
) {
773 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
774 if (as
.getEndTime() == m2
.getTime())
775 y2
+= as
.getHeight();
777 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
778 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
779 if (m1
.getEvent() == eo
.getEndOccurrence())
780 y1
+= eo
.getHeight();
782 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
784 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
785 if (m2
.getEvent() == eo2
.getEndOccurrence())
786 y2
+= eo2
.getHeight();
790 int m1Y
= Math
.round(y1
* zoomValue
);
791 int m2Y
= Math
.round(y2
* zoomValue
);
793 if ((m1Y
< dy
) && (m2Y
> dy
) || (!done
&& m2Y
> dy
&& direction
== 1 && lastM1
!= null) || (!done
&& m1Y
> dy
&& direction
== 2 && lastM1
!= null)) {
794 if (m1Y
> dy
&& direction
== 2) {
803 TmfTimestamp minMaxdelta
= (TmfTimestamp
) max
.getDelta(min
);
804 double gr
= (minMaxdelta
.getValue()) / (double) 10;
806 TmfTimestamp delta
= (TmfTimestamp
) m2
.getTime().getDelta(m1
.getTime()).getDelta(min
);
807 long absDelta
= Math
.abs(delta
.getValue());
811 colIndex
= Math
.round((float) (absDelta
/ gr
));
812 if (colIndex
>= col
.length
)
813 colIndex
= col
.length
- 1;
814 else if (colIndex
< 0)
818 if (m1
.getGraphNode() instanceof BaseMessage
) {
819 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
820 if (mes1
.getEndLifeline() != null) {
821 ll
= mes1
.getEndLifeline();
823 ln
= m2
.getEvent() - m1
.getEvent();
825 } else if (m2
.getGraphNode() instanceof BaseMessage
&& ((BaseMessage
) m2
.getGraphNode()).getStartLifeline() != null) {
826 ll
= ((BaseMessage
) m2
.getGraphNode()).getStartLifeline();
828 ln
= m2
.getEvent() - m1
.getEvent();
831 ll
= mes1
.getStartLifeline();
833 ln
= m2
.getEvent() - m1
.getEvent();
836 } else if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
837 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
838 ExecutionOccurrence eo
= (ExecutionOccurrence
) m2
.getGraphNode();
839 ll
= eo
.getLifeline();
841 ln
= m2
.getEvent() - m1
.getEvent();
844 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
845 ll
= eo
.getLifeline();
847 ln
= m2
.getEvent() - m1
.getEvent();
851 for (int j
= 0; j
< listenerList
.size(); j
++) {
852 ITimeCompressionListener list
= (ITimeCompressionListener
) listenerList
.get(j
);
853 list
.deltaSelected(ll
, ls
, ln
, lc
);
866 protected void createFakeTooltip() {
867 if (tooltip
== null) {
868 tooltip
= new DrawableToolTip(this);
872 for (int i
= 0; i
< nodeList
.size() - 1; i
++) {
873 SDTimeEvent m1
= (SDTimeEvent
) nodeList
.get(i
);
874 SDTimeEvent m2
= (SDTimeEvent
) nodeList
.get(i
+ 1);
876 if (SDViewPref
.getInstance().excludeExternalTime()) {
877 if ((m1
.getGraphNode() instanceof BaseMessage
) && (m2
.getGraphNode() instanceof BaseMessage
)) {
878 BaseMessage mes1
= (BaseMessage
) m1
.getGraphNode();
879 BaseMessage mes2
= (BaseMessage
) m2
.getGraphNode();
880 if ((mes2
.getStartLifeline() == null) || (mes1
.getEndLifeline() == null))
885 int y1
= ((GraphNode
) m1
.getGraphNode()).getY();
886 int y2
= ((GraphNode
) m2
.getGraphNode()).getY();
888 if (m1
.getGraphNode() instanceof AsyncMessage
) {
889 AsyncMessage as
= (AsyncMessage
) m1
.getGraphNode();
890 if (as
.getEndTime() == m1
.getTime())
891 y1
+= as
.getHeight();
893 if (m2
.getGraphNode() instanceof AsyncMessage
) {
894 AsyncMessage as
= (AsyncMessage
) m2
.getGraphNode();
895 if (as
.getEndTime() == m2
.getTime())
896 y2
+= as
.getHeight();
898 if (m1
.getGraphNode() instanceof ExecutionOccurrence
) {
899 ExecutionOccurrence eo
= (ExecutionOccurrence
) m1
.getGraphNode();
900 if (m1
.getEvent() == eo
.getEndOccurrence())
901 y1
+= eo
.getHeight();
903 if (m2
.getGraphNode() instanceof ExecutionOccurrence
) {
905 ExecutionOccurrence eo2
= (ExecutionOccurrence
) m2
.getGraphNode();
906 if (m2
.getEvent() == eo2
.getEndOccurrence())
907 y2
+= eo2
.getHeight();
911 int m1Y
= Math
.round(y1
* zoomValue
);
912 int m2Y
= Math
.round(y2
* zoomValue
);
913 if ((m1Y
< prevNodeY
+ 1) && (m2Y
>= prevNodeY
+ 1)) {
914 TmfTimestamp delta
= (TmfTimestamp
) m2
.getTime().getDelta(m1
.getTime());
915 tooltip
.showToolTip(delta
, min
, max
);
916 tooltip
.hideToolTip();