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: SDWidget.java,v 1.6 2008/12/12 22:21:46 jcayne Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
15 import java
.text
.MessageFormat
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
18 import java
.util
.Timer
;
19 import java
.util
.TimerTask
;
21 import org
.eclipse
.jface
.contexts
.IContextIds
;
22 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
23 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
24 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.ISDPreferences
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDCollapseProvider
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDPrintDialog
;
44 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDPrintDialogUI
;
45 import org
.eclipse
.swt
.SWT
;
46 import org
.eclipse
.swt
.accessibility
.ACC
;
47 import org
.eclipse
.swt
.accessibility
.Accessible
;
48 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
49 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
50 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
51 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
52 import org
.eclipse
.swt
.events
.DisposeEvent
;
53 import org
.eclipse
.swt
.events
.DisposeListener
;
54 import org
.eclipse
.swt
.events
.FocusEvent
;
55 import org
.eclipse
.swt
.events
.FocusListener
;
56 import org
.eclipse
.swt
.events
.KeyEvent
;
57 import org
.eclipse
.swt
.events
.MouseEvent
;
58 import org
.eclipse
.swt
.events
.SelectionEvent
;
59 import org
.eclipse
.swt
.events
.SelectionListener
;
60 import org
.eclipse
.swt
.events
.TraverseEvent
;
61 import org
.eclipse
.swt
.events
.TraverseListener
;
62 import org
.eclipse
.swt
.graphics
.GC
;
63 import org
.eclipse
.swt
.graphics
.Image
;
64 import org
.eclipse
.swt
.graphics
.ImageData
;
65 import org
.eclipse
.swt
.graphics
.Rectangle
;
66 import org
.eclipse
.swt
.printing
.Printer
;
67 import org
.eclipse
.swt
.printing
.PrinterData
;
68 import org
.eclipse
.swt
.widgets
.Canvas
;
69 import org
.eclipse
.swt
.widgets
.Caret
;
70 import org
.eclipse
.swt
.widgets
.Composite
;
71 import org
.eclipse
.swt
.widgets
.Control
;
72 import org
.eclipse
.swt
.widgets
.Display
;
73 import org
.eclipse
.swt
.widgets
.Event
;
74 import org
.eclipse
.swt
.widgets
.Listener
;
75 import org
.eclipse
.swt
.widgets
.MenuItem
;
76 import org
.eclipse
.ui
.contexts
.IContextService
;
77 import org
.eclipse
.ui
.part
.ViewPart
;
84 public class SDWidget
extends ScrollView
implements SelectionListener
, IPropertyChangeListener
, DisposeListener
, ITimeCompressionListener
{
86 protected Frame frame
;
87 protected Image overView
= null;
88 protected MenuItem zoomIn
= null;
89 protected MenuItem zoomOut
= null;
90 protected SDWidgetSelectionProvider selProvider
= null;
91 public float zoomValue
= 1;
92 protected boolean zoomInMode
= false;
93 protected boolean zoomOutMode
= false;
95 protected List
<GraphNode
> selectedNodeList
= null;
96 protected boolean ctrlSelection
= false;
98 protected ViewPart site
= null;
100 public GraphNode currentGraphNode
= null;
101 public GraphNode listStart
= null;
102 public ArrayList
<GraphNode
> prevList
= null;
104 protected TimeCompressionBar timeBar
= null;
106 protected DiagramToolTip toolTip
= null;
108 protected Accessible accessible
= null;
110 protected GraphNode toolTipNode
;
112 protected Lifeline dragAndDrop
= null;
114 protected int focusedWidget
= -1;
116 protected float printerZoom
= 0;
118 protected int printerY
= 0;
120 protected int printerX
= 0;
122 protected boolean getDragAndDrop
= false;
124 protected int dragX
= 0;
125 protected int dragY
= 0;
127 protected boolean reorderMode
= false;
129 Image collapaseCaretImg
= null;
130 Image arrowUpCaretImg
= null;
131 Image currentCaretImage
= null;
133 protected ISDCollapseProvider collapseProvider
= null;
135 protected Caret insertionCartet
= null;
137 protected ArrayList
<Lifeline
[]> reorderList
= null;
139 protected boolean printing
= false;
140 protected Printer printer
= null;
142 protected boolean shiftSelection
= false;
144 protected DiagramToolTip scrollToolTip
= null;
146 public SDWidget(Composite c
, int s
) {
147 super(c
, s
| SWT
.NO_BACKGROUND
, true);
148 setOverviewEnabled(true);
149 selectedNodeList
= new ArrayList
<GraphNode
>();
150 selProvider
= new SDWidgetSelectionProvider();
151 SDViewPref
.getInstance().addPropertyChangeListener(this);
152 toolTip
= new DiagramToolTip(getViewControl());
153 super.addDisposeListener(this);
155 scrollToolTip
= new DiagramToolTip(c
);
156 getVerticalBar().addListener(SWT
.MouseUp
, new Listener() {
159 public void handleEvent(Event event
) {
160 scrollToolTip
.hideToolTip();
164 // tooltip on vertical bar causes trouble when scrolling, because
165 // tooltip is constantly updated and shown
166 // getVerticalBar().addSelectionListener(new SelectionListener(){
168 // public void widgetSelected(SelectionEvent e) {
169 // scrollToolTip.hideToolTip();
171 // boolean needInit=true;
173 // for (int i=0;i<frame.lifeLinesCount();i++)
175 // Lifeline lifeline=frame.getLifeline(i);
176 // BasicExecutionOccurrence exec=frame.getFirstExecution(lifeline);
177 // if (exec instanceof ExecutionOccurrence) {
178 // ExecutionOccurrence occ=(ExecutionOccurrence)exec;
179 // if ((occ.hasTimeInfo())&&(occ.getFirstTime()<minOcc||needInit))
182 // minOcc=occ.getFirstTime();
189 // int z=frame.getFirstVisibleSyncMessage();
192 // SyncMessage s=frame.getSyncMessage(z);
193 // if (s.hasTimeInfo())
199 // scrollToolTip.showToolTip(MessageFormat.format(SDMessages._134, //$NON-NLS-1$
200 // new Object[] { formatTimeDate(frame.getSDMinTime()),
201 // formatTimeDate(m),
202 // formatTimeDate(frame.getSDMaxTime())} ));
205 // public void widgetDefaultSelected(SelectionEvent e) {
206 // // scrollToolTip.showToolTip("Toto");
212 accessible
= getViewControl().getAccessible();
214 accessible
.addAccessibleListener(new AccessibleAdapter() {
216 public void getName(AccessibleEvent e
) {
217 if (e
.childID
== ACC
.CHILDID_SELF
) {
221 else if (e
.childID
== 0) {
222 if (toolTipNode
!= null) {
223 if (toolTipNode
instanceof Lifeline
) {
224 Lifeline lifeline
= (Lifeline
) toolTipNode
;
225 e
.result
= lifeline
.getToolTipText();
227 e
.result
= toolTipNode
.getName() + getPostfixForTooltip(true);
231 if (getFocusNode() != null) {
232 if (getFocusNode() instanceof Lifeline
) {
233 e
.result
= MessageFormat
.format(SDMessages
._1
, new Object
[] { String
.valueOf(getFocusNode().getName()) });
235 if (getFocusNode() instanceof BaseMessage
) {
236 BaseMessage mes
= (BaseMessage
) getFocusNode();
237 if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() != null)) {
238 e
.result
= MessageFormat
.format(
240 new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()), String
.valueOf(mes
.getEndLifeline().getName()),
241 Integer
.valueOf(mes
.getEndOccurrence()) });
242 } else if ((mes
.getStartLifeline() == null) && (mes
.getEndLifeline() != null)) {
243 e
.result
= MessageFormat
.format(SDMessages
._4
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getEndLifeline().getName()), Integer
.valueOf(mes
.getEndOccurrence()) });
244 } else if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() == null)) {
245 e
.result
= MessageFormat
.format(SDMessages
._3
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()) });
247 } else if (getFocusNode() instanceof BasicExecutionOccurrence
) {
248 BasicExecutionOccurrence exec
= (BasicExecutionOccurrence
) getFocusNode();
249 e
.result
= MessageFormat
.format(SDMessages
._5
,
250 new Object
[] { String
.valueOf(exec
.getName()), String
.valueOf(exec
.getLifeline().getName()), Integer
.valueOf(exec
.getStartOccurrence()), Integer
.valueOf(exec
.getEndOccurrence()) });
254 // e.result =currentGraphNode.getName();
259 accessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
261 public void getFocus(AccessibleControlEvent e
) {
262 if (focusedWidget
== -1)
263 e
.childID
= ACC
.CHILDID_SELF
;
265 e
.childID
= focusedWidget
;
269 public void getRole(AccessibleControlEvent e
) {
271 case ACC
.CHILDID_SELF
:
272 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
275 e
.detail
= ACC
.ROLE_TOOLTIP
;
278 e
.detail
= ACC
.ROLE_LABEL
;
284 public void getState(AccessibleControlEvent e
) {
285 e
.detail
= ACC
.STATE_FOCUSABLE
;
286 if (e
.childID
== ACC
.CHILDID_SELF
) {
287 e
.detail
|= ACC
.STATE_FOCUSED
;
289 e
.detail
|= ACC
.STATE_SELECTABLE
;
290 if (e
.childID
== focusedWidget
)
291 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
296 insertionCartet
= new Caret((Canvas
) getViewControl(), SWT
.NONE
);
297 insertionCartet
.setVisible(false);
299 collapaseCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_COLLAPSE_OBJ
);
300 arrowUpCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_UP_OBJ
);
302 reorderList
= new ArrayList
<Lifeline
[]>();
303 getViewControl().addTraverseListener(new TraverseListener() {
306 public void keyTraversed(TraverseEvent e
) {
307 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
313 addTraverseListener(new TraverseListener() {
316 public void keyTraversed(TraverseEvent e
) {
317 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
323 getViewControl().addFocusListener(new FocusListener() {
326 public void focusGained(FocusEvent e
) {
327 // TODO Auto-generated method stub
328 SDViewPref
.getInstance().setNoFocusSelection(false);
329 ctrlSelection
= false;
330 shiftSelection
= false;
335 public void focusLost(FocusEvent e
) {
336 SDViewPref
.getInstance().setNoFocusSelection(true);
342 public void setTimeBar(TimeCompressionBar bar
) {
345 timeBar
.addTimeCompressionListener(this);
349 protected void setCollapseProvider(ISDCollapseProvider provider
) {
350 collapseProvider
= provider
;
354 protected void keyPressedEvent(KeyEvent event
) {
355 if (!(isFocusControl() || getViewControl().isFocusControl())) {
356 Control
[] child
= getParent().getChildren();
357 for (int i
= 0; i
< child
.length
; i
++) {
358 if (child
[i
].isFocusControl()) {
359 if (!(child
[i
] instanceof ScrollView
)) {
360 getViewControl().setFocus();
368 if (event
.keyCode
== SWT
.CTRL
)
369 ctrlSelection
= true;
370 if (event
.keyCode
== SWT
.SHIFT
) {
371 shiftSelection
= true;
372 prevList
= new ArrayList
<GraphNode
>();
373 prevList
.addAll(getSelection());
376 GraphNode prevNode
= getFocusNode();
378 if (event
.keyCode
== SWT
.ARROW_RIGHT
)
381 if (event
.keyCode
== SWT
.ARROW_LEFT
)
384 if (event
.keyCode
== SWT
.ARROW_DOWN
)
387 if (event
.keyCode
== SWT
.ARROW_UP
)
390 if (event
.keyCode
== SWT
.HOME
)
393 if (event
.keyCode
== SWT
.END
)
396 if ((!shiftSelection
) && (!ctrlSelection
))
397 listStart
= currentGraphNode
;
399 if (event
.character
== ' ') {
400 performSelection(currentGraphNode
);
402 listStart
= currentGraphNode
;
405 if ((shiftSelection
) && (prevNode
!= getFocusNode())) {
407 addSelection(prevList
);
408 addSelection(frame
.getNodeList(listStart
, getFocusNode()));
409 if (getFocusNode() instanceof Lifeline
)
410 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
412 ensureVisible(getFocusNode());
413 } else if ((!ctrlSelection
) && (!shiftSelection
)) {
416 if (getFocusNode() != null) {
417 addSelection(getFocusNode());
419 if (getFocusNode() instanceof Lifeline
)
420 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
422 ensureVisible(getFocusNode());
426 if (currentGraphNode
!= null)
427 currentGraphNode
.setFocused(true);
430 if ((event
.character
== ' ') && ((zoomInMode
) || (zoomOutMode
))) {
431 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / zoomValue
);
432 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / zoomValue
);
435 zoomValue
= zoomValue
* (float) 1.25;
437 zoomValue
= zoomValue
/ (float) 1.25;
438 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
439 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
440 setContentsPos(x
, y
);
442 timeBar
.setZoom(zoomValue
);
443 // redraw also resize the scrollView content
449 protected void keyReleasedEvent(KeyEvent event
) {
451 if (event
.keyCode
== SWT
.CTRL
)
452 ctrlSelection
= false;
453 if (event
.keyCode
== SWT
.SHIFT
)
454 shiftSelection
= false;
455 super.keyReleasedEvent(event
);
460 * Resize the contents to insure the frame fit into the view
462 * @param frame the frame which will be drawn in the view
464 public void resizeContents(Frame frame
) {
465 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
466 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
467 resizeContents(width
, height
);
470 protected boolean checkFocusOnChilds(Control childs
) {
471 if (childs
instanceof Composite
) {
472 Control
[] child
= ((Composite
) childs
).getChildren();
473 for (int i
= 0; i
< child
.length
; i
++) {
474 if (child
[i
].isFocusControl()) {
477 checkFocusOnChilds(child
[i
]);
484 public boolean isFocusControl() {
485 Control
[] child
= getChildren();
486 for (int i
= 0; i
< child
.length
; i
++) {
487 if (child
[i
].isFocusControl()) {
490 checkFocusOnChilds(child
[i
]);
496 * The frame to render (the sequence diagram)
498 * @param theFrame the frame to display
500 public void setFrame(Frame theFrame
, boolean resetPosition
) {
502 selectedNodeList
.clear();
503 selProvider
.setSelection(new StructuredSelection());
506 setContentsPos(0, 0);
507 resizeContents(frame
);
510 // prepare the old overview to be reused
511 if (overView
!= null)
514 resizeContents(frame
);
518 * Returns the current Frame (the sequence diagram container)
522 public Frame
getFrame() {
527 * Returns the selection provider for the current sequence diagram
529 * @return the selection provider
531 public ISelectionProvider
getSelectionProvider() {
536 public boolean setContentsPos(int x
, int y
) {
543 if (x
+ getVisibleWidth() > getContentsWidth())
544 x
= getContentsWidth() - getVisibleWidth();
545 if (y
+ getVisibleHeight() > getContentsHeight())
546 y
= getContentsHeight() - getVisibleHeight();
547 int x1
= Math
.round(x
/ zoomValue
);
548 int y2
= Math
.round(y
/ zoomValue
);
549 int width
= Math
.round(getVisibleWidth() / zoomValue
);
550 int height
= Math
.round(getVisibleHeight() / zoomValue
);
551 frame
.updateIndex(x1
, y2
, width
, height
);
553 if (insertionCartet
!= null && insertionCartet
.isVisible())
554 insertionCartet
.setVisible(false);
556 return super.setContentsPos(x
, y
);
560 protected void contentsMouseHover(MouseEvent event
) {
561 GraphNode graphNode
= null;
563 int x
= Math
.round(event
.x
/ zoomValue
);
564 int y
= Math
.round(event
.y
/ zoomValue
);
565 graphNode
= frame
.getNodeAt(x
, y
);
566 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
567 toolTipNode
= graphNode
;
568 String postfix
= getPostfixForTooltip(true);
569 if (graphNode
instanceof Lifeline
) {
570 Lifeline lifeline
= (Lifeline
) graphNode
;
571 toolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
574 toolTip
.showToolTip(graphNode
.getName() + postfix
);
578 toolTip
.hideToolTip();
582 protected String
getPostfixForTooltip(boolean accessible
) {
583 String postfix
= "";//$NON-NLS-1$
584 // Determine if the tooltip must show the time difference between the current mouse position and
585 // the last selected graphNode
586 if ((currentGraphNode
!= null) &&
587 (currentGraphNode
instanceof ITimeRange
) &&
588 (toolTipNode
instanceof ITimeRange
) &&
589 (currentGraphNode
!= toolTipNode
) &&
590 ((ITimeRange
) toolTipNode
).hasTimeInfo() &&
591 ((ITimeRange
) currentGraphNode
).hasTimeInfo()) {
592 postfix
= " -> " + currentGraphNode
.getName() + "\n" + SDMessages
._138
+ " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
594 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
595 ITmfTimestamp firstTime
= ((ITimeRange
) currentGraphNode
).getEndTime();
596 ITmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
597 TmfTimestamp delta
= (TmfTimestamp
) lastTime
.getDelta(firstTime
);
598 postfix
+= delta
.toString();
600 if ((toolTipNode
instanceof ITimeRange
) && ((ITimeRange
) toolTipNode
).hasTimeInfo()) {
601 postfix
= "\n";//$NON-NLS-1$
602 ITmfTimestamp firstTime
= ((ITimeRange
) toolTipNode
).getStartTime();
603 ITmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
605 if (firstTime
!= null) {
606 if (lastTime
!= null && firstTime
.compareTo(lastTime
, true) != 0) {
607 postfix
+= "start: " + firstTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
608 postfix
+= "end: " + lastTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
610 postfix
+= firstTime
.toString();
613 else if (lastTime
!= null) {
614 postfix
+= lastTime
.toString();
621 protected void setFocus(int newFocusShape
) {
622 focusedWidget
= newFocusShape
;
623 if (focusedWidget
== -1) {
624 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
626 getViewControl().getAccessible().setFocus(focusedWidget
);
630 /** Timer for auto_scroll feature */
631 protected AutoScroll local_auto_scroll_
= null;
632 /** TimerTask for auto_scroll feature !=null when auto scroll is running */
633 protected Timer local_auto_scroll_timer_
= null;
635 /** TimerTask for auto scroll feature. */
636 protected static class AutoScroll
extends TimerTask
{
640 public AutoScroll(SDWidget _sv
, int _dx
, int _dy
) {
648 Display
.getDefault().asyncExec(new Runnable() {
651 if (sv_
.isDisposed())
655 sv_
.scrollBy(dx_
, dy_
);
662 protected void contentsMouseMoveEvent(MouseEvent e
) {
663 scrollToolTip
.hideToolTip();
664 toolTip
.hideToolTip();
665 // super.contentsMouseMoveEvent(e);
666 if (!(isFocusControl() || getViewControl().isFocusControl())) {
667 Control
[] child
= getParent().getChildren();
668 for (int i
= 0; i
< child
.length
; i
++) {
669 if (child
[i
].isFocusControl()) {
670 if (!(child
[i
] instanceof ScrollView
)) {
671 getViewControl().setFocus();
679 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((dragAndDrop
!= null) || getDragAndDrop
) && (reorderMode
|| collapseProvider
!= null)) {
680 getDragAndDrop
= false;
681 if (currentGraphNode
instanceof Lifeline
)
682 dragAndDrop
= (Lifeline
) currentGraphNode
;
683 if (dragAndDrop
!= null) {
686 if (e
.x
> getContentsX() + getVisibleWidth()) {
687 dx
= e
.x
- (getContentsX() + getVisibleWidth());
688 } else if (e
.x
< getContentsX()) {
689 dx
= -getContentsX() + e
.x
;
691 if (e
.y
> getContentsY() + getVisibleHeight()) {
692 dy
= e
.y
- (getContentsY() + getVisibleHeight());
693 } else if (e
.y
< getContentsY()) {
694 dy
= -getContentsY() + e
.y
;
698 if (dx
!= 0 || dy
!= 0) {
699 if (local_auto_scroll_
== null) {
700 if (local_auto_scroll_timer_
== null) {
701 local_auto_scroll_timer_
= new Timer(true);
703 local_auto_scroll_
= new AutoScroll(this, dx
, dy
);
704 local_auto_scroll_timer_
.schedule(local_auto_scroll_
, 0, 75);
706 local_auto_scroll_
.dx_
= dx
;
707 local_auto_scroll_
.dy_
= dy
;
709 } else if (local_auto_scroll_
!= null) {
710 local_auto_scroll_
.cancel();
711 local_auto_scroll_
= null;
713 dragX
= Math
.round(e
.x
/ zoomValue
);
714 dragY
= Math
.round(e
.y
/ zoomValue
);
716 Lifeline node
= frame
.getCloserLifeline(dragX
);
717 if ((node
!= null) && (node
!= dragAndDrop
)) {
720 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
721 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
723 int width
= node
.getWidth();
724 if (frame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
)
725 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * zoomValue
));
727 y
= Math
.round(height
* zoomValue
);
729 if (frame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
))
730 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * zoomValue
));
732 y1
= Math
.round(height
* zoomValue
);
734 int rx
= Math
.round(x
* zoomValue
);
736 insertionCartet
.setVisible(true);
737 if ((insertionCartet
.getImage() != null) && (!insertionCartet
.getImage().isDisposed()))
738 insertionCartet
.getImage().dispose();
739 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* zoomValue
)) >= e
.x
) {
740 if (collapseProvider
!= null) {
741 ImageData data
= collapaseCaretImg
.getImageData();
742 data
= data
.scaledTo(Math
.round(collapaseCaretImg
.getBounds().width
* zoomValue
), Math
.round(collapaseCaretImg
.getBounds().height
* zoomValue
));
743 currentCaretImage
= new Image(Display
.getCurrent(), data
);
744 insertionCartet
.setImage(currentCaretImage
);
745 insertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y
);
747 } else if (reorderMode
) {
749 if (node
.getIndex() > 1 && frame
.getLifeline(node
.getIndex() - 2) == dragAndDrop
)
751 ImageData data
= arrowUpCaretImg
.getImageData();
752 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
753 currentCaretImage
= new Image(Display
.getCurrent(), data
);
754 insertionCartet
.setImage(currentCaretImage
);
755 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y1
);
757 if (node
.getIndex() < frame
.lifeLinesCount() && frame
.getLifeline(node
.getIndex()) == dragAndDrop
)
759 ImageData data
= arrowUpCaretImg
.getImageData();
760 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
761 currentCaretImage
= new Image(Display
.getCurrent(), data
);
762 insertionCartet
.setImage(currentCaretImage
);
763 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2 + 1, y1
);
767 insertionCartet
.setVisible(false);
770 super.contentsMouseMoveEvent(e
);
774 protected void contentsMouseUpEvent(MouseEvent event
) {
775 // Just in case the diagram highlight a time compression region
776 // this region need to be released when clicking everywhere
777 insertionCartet
.setVisible(false);
778 if (dragAndDrop
!= null) {
779 if ((overView
!= null) && (!overView
.isDisposed()))
782 Lifeline node
= frame
.getCloserLifeline(dragX
);
784 int rx
= Math
.round(node
.getX() * zoomValue
);
785 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * zoomValue
)) >= event
.x
) {
786 if ((collapseProvider
!= null) && (dragAndDrop
!= node
))
787 collapseProvider
.collapseTwoLifelines((Lifeline
) dragAndDrop
, node
);
788 } else if (rx
< event
.x
) {
789 frame
.insertLifelineAfter((Lifeline
) dragAndDrop
, node
);
790 if (node
.getIndex() < frame
.lifeLinesCount()) {
791 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, frame
.getLifeline(node
.getIndex()) };
792 reorderList
.add(temp
);
794 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, null };
795 reorderList
.add(temp
);
798 frame
.insertLifelineBefore((Lifeline
) dragAndDrop
, node
);
799 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, node
};
800 reorderList
.add(temp
);
809 frame
.resetTimeCompression();
811 // reset auto scroll if it's engaged
812 if (local_auto_scroll_
!= null) {
813 local_auto_scroll_
.cancel();
814 local_auto_scroll_
= null;
816 super.contentsMouseUpEvent(event
);
820 protected void contentsMouseDownEvent(MouseEvent event
) {
821 if (currentGraphNode
!= null)
822 currentGraphNode
.setFocused(false);
823 // Just in case the diagram highlight a time compression region
824 // this region need to be released when clicking everywhere
828 frame
.resetTimeCompression();
830 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
831 ctrlSelection
= true;
833 ctrlSelection
= false;
835 if (((zoomInMode
) || (zoomOutMode
)) && (event
.button
== 1)) {
836 int cx
= Math
.round(event
.x
/ zoomValue
);
837 int cy
= Math
.round(event
.y
/ zoomValue
);
840 zoomValue
= zoomValue
* (float) 1.25;
842 zoomValue
= zoomValue
/ (float) 1.25;
843 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
844 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
845 setContentsPos(x
, y
);
847 timeBar
.setZoom(zoomValue
);
848 // redraw also resize the scrollView content
850 } else// if (event.button ==1)
852 GraphNode node
= null;
854 int x
= Math
.round(event
.x
/ zoomValue
);
855 int y
= Math
.round(event
.y
/ zoomValue
);
856 node
= frame
.getNodeAt(x
, y
);
858 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
861 if (shiftSelection
) {
863 addSelection(frame
.getNodeList(listStart
, node
));
865 performSelection(node
);
866 currentGraphNode
= node
;
868 node
.setFocused(true);
873 if (dragAndDrop
== null)
874 super.contentsMouseDownEvent(event
);
875 getDragAndDrop
= (event
.button
== 1);
880 * Highlight the given GraphNode<br>
881 * The GraphNode is then displayed using the system default selection color
883 * @param node the GraphNode to highlight
885 protected void performSelection(GraphNode node
) {
886 if ((ctrlSelection
) || (shiftSelection
)) {
888 if (selectedNodeList
.contains(node
)) {
889 removeSelection(node
);
903 public List
<GraphNode
> getSelection() {
904 return selectedNodeList
;
907 public void addSelection(GraphNode node
) {
910 selectedNodeList
.add(node
);
911 node
.setSelected(true);
912 currentGraphNode
= node
;
913 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
914 selProvider
.setSelection(selection
);
917 public void addSelection(List
<GraphNode
> list
) {
918 // selectedNodeList.addAll(list);
919 for (int i
= 0; i
< list
.size(); i
++) {
920 if (!selectedNodeList
.contains(list
.get(i
))) {
921 selectedNodeList
.add(list
.get(i
));
922 ((GraphNode
) list
.get(i
)).setSelected(true);
925 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
926 selProvider
.setSelection(selection
);
929 public void removeSelection(GraphNode node
) {
930 selectedNodeList
.remove(node
);
931 node
.setSelected(false);
932 node
.setFocused(false);
933 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
934 selProvider
.setSelection(selection
);
937 public void removeSelection(List
<GraphNode
> list
) {
938 selectedNodeList
.removeAll(list
);
939 for (int i
= 0; i
< list
.size(); i
++) {
940 ((GraphNode
) list
.get(i
)).setSelected(false);
941 ((GraphNode
) list
.get(i
)).setFocused(false);
943 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
944 selProvider
.setSelection(selection
);
948 * Clear the list of GraphNodes which must be drawn selected
951 public void clearSelection() {
952 for (int i
= 0; i
< selectedNodeList
.size(); i
++) {
953 ((GraphNode
) selectedNodeList
.get(i
)).setSelected(false);
954 ((GraphNode
) selectedNodeList
.get(i
)).setFocused(false);
956 currentGraphNode
= null;
957 selectedNodeList
.clear();
958 selProvider
.setSelection(new StructuredSelection());
961 public void setSite(ViewPart viewSite
) {
963 site
.getSite().setSelectionProvider(selProvider
);
964 IContextService service
= (IContextService
) site
.getSite().getWorkbenchWindow().getService(IContextService
.class);
965 service
.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
966 service
.activateContext(IContextIds
.CONTEXT_ID_WINDOW
);
969 protected Image
getDrawBuffer(GC gc
) {
972 Rectangle area
= getClientArea();
973 Image dbuffer
= null;
977 // if (dbuffer!=null)
978 // dbuffer.dispose();
979 dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
980 } catch (Exception e
) {
981 System
.out
.println(e
.toString());
983 gcim
= new GC(dbuffer
);
985 NGC context
= new NGC(this, gcim
);
987 // Set the metrics to use for lifeline text and message text
988 // using the Graphical Context
989 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
990 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
991 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
992 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
993 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
995 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
996 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
997 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
998 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS_RET
));
1000 int messageFontHeight
= 0;
1001 if (syncMessFontH
> syncMessRetFontH
)
1002 messageFontHeight
= syncMessFontH
;
1004 messageFontHeight
= syncMessRetFontH
;
1005 if (messageFontHeight
< asyncMessFontH
)
1006 messageFontHeight
= asyncMessFontH
;
1007 if (messageFontHeight
< asyncMessRetFontH
)
1008 messageFontHeight
= asyncMessRetFontH
;
1009 Metrics
.setMessageFontHeight(messageFontHeight
);
1010 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1012 int width
= (int) ((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1013 int height
= (int) ((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1014 // if (width<area.width)
1015 // width=area.width;
1016 // if (height<area.height)
1017 // height=area.height;
1018 resizeContents(width
, height
);
1020 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1021 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1022 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1023 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1024 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1025 gcim
.setLineWidth(1);
1027 frame
.draw(context
);
1028 if (dragAndDrop
!= null) {
1029 Lifeline node
= (Lifeline
) dragAndDrop
;
1030 boolean isSelected
= dragAndDrop
.isSelected();
1031 boolean hasFocus
= dragAndDrop
.hasFocus();
1032 node
.setSelected(false);
1033 node
.setFocused(false);
1034 node
.draw(context
, dragX
, dragY
);
1035 node
.setSelected(isSelected
);
1036 node
.setFocused(hasFocus
);
1045 * @param gc the context
1048 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1049 if (frame
== null) {
1050 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1051 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1055 Frame
.setUserPref(SDViewPref
.getInstance());
1058 Rectangle area
= getClientArea();
1059 Image dbuffer
= getDrawBuffer(gc
);
1060 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1063 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1064 } catch (Exception e
) {
1065 System
.out
.println(e
.getMessage());
1068 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * zoomValue
));
1069 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * zoomValue
));
1070 if ((timeBar
!= null) && (frame
.hasTimeInfo())) {
1071 timeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1072 timeBar
.setContentsPos(getContentsX(), getContentsY());
1076 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1077 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1078 if (yRatio
> xRatio
) {
1079 setOverviewSize((int) (getVisibleHeight() * 0.75));
1081 setOverviewSize((int) (getVisibleWidth() * 0.75));
1086 * Returns the GraphNode overView the mouse if any
1088 * @return the GraphNode
1090 public GraphNode
getMouseOverNode() {
1091 return currentGraphNode
;
1095 public void widgetDefaultSelected(SelectionEvent event
) {
1099 public void widgetSelected(SelectionEvent event
) {
1100 if (event
.widget
== zoomIn
)
1101 zoomValue
= zoomValue
* 2;
1102 else if (event
.widget
== zoomOut
)
1103 zoomValue
= zoomValue
/ 2;
1105 // SearchFilterDialog tt = new SearchFilterDialog(null);//display.getActiveShell());
1110 public void setZoomInMode(boolean value
) {
1112 setZoomOutMode(false);
1116 public void setZoomOutMode(boolean value
) {
1118 setZoomInMode(false);
1119 zoomOutMode
= value
;
1123 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
1125 * @param node the GraphNode to move to
1127 public void moveTo(GraphNode node
) {
1132 ensureVisible(node
);
1136 * Moves the Sequence diagram to ensure the given node is visible
1138 * @param node the GraphNode to move to
1140 public void ensureVisible(GraphNode node
) {
1143 int x
= Math
.round(node
.getX() * zoomValue
);
1144 int y
= Math
.round(node
.getY() * zoomValue
);
1145 int width
= Math
.round(node
.getWidth() * zoomValue
);
1146 int height
= Math
.round(node
.getHeight() * zoomValue
);
1147 if (node
instanceof BaseMessage
) {
1149 int header
= Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
* 2 + Metrics
.getLifelineHeaderFontHeigth();
1150 height
= -Math
.round((Metrics
.getMessagesSpacing() + header
) * zoomValue
);
1151 y
= y
+ Math
.round(Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
* zoomValue
);
1154 if (node
instanceof BasicExecutionOccurrence
) {
1158 if (node
instanceof Lifeline
) {
1160 height
= getVisibleHeight();
1162 ensureVisible(x
, y
, width
, height
, SWT
.CENTER
, true);
1166 public float getZoomFactor() {
1171 * Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply
1174 * @param e the PropertyChangeEvent
1177 public void propertyChange(PropertyChangeEvent e
) {
1178 if (frame
!= null && !isDisposed()) {
1179 frame
.resetTimeCompression();
1181 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1183 // Prepare the overview to be reused for the new
1184 // settings (especially the colors)
1185 if (overView
!= null)
1193 public void widgetDisposed(DisposeEvent e
) {
1194 if (overView
!= null)
1196 super.removeDisposeListener(this);
1197 if ((currentCaretImage
!= null) && (!currentCaretImage
.isDisposed()))
1198 currentCaretImage
.dispose();
1199 if ((arrowUpCaretImg
!= null) && (!arrowUpCaretImg
.isDisposed()))
1200 arrowUpCaretImg
.dispose();
1201 if ((collapaseCaretImg
!= null) && (!collapaseCaretImg
.isDisposed()))
1202 collapaseCaretImg
.dispose();
1203 SDViewPref
.getInstance().removePropertyChangeListener(this);
1204 LoadersManager lm
= LoadersManager
.getInstance();
1205 if (site
!= null && site
instanceof SDView
) {
1206 ((SDView
) site
).resetProviders();
1208 lm
.resetLoader(((SDView
) site
).getViewSite().getId());
1212 public Image
getOverview(Rectangle r
) {
1213 float oldzoom
= zoomValue
;
1214 if ((overView
!= null) && ((r
.width
!= overView
.getBounds().width
) || (r
.height
!= overView
.getBounds().height
))) {
1218 if (overView
== null) {
1219 int backX
= getContentsX();
1220 int backY
= getContentsY();
1221 setContentsPos(0, 0);
1222 overView
= new Image(getDisplay(), r
.width
, r
.height
);
1223 GC gcim
= new GC(overView
);
1224 NGC context
= new NGC(this, gcim
);
1225 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
1226 frame
.draw(context
);
1227 setContentsPos(backX
, backY
);
1231 zoomValue
= oldzoom
;
1236 protected void drawOverview(GC gc
, Rectangle r
) {
1237 float oldzoom
= zoomValue
;
1238 if (getContentsWidth() > getContentsHeight())
1239 zoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
1241 zoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
1242 if ((overView
!= null) && ((r
.width
!= overView
.getBounds().width
) || (r
.height
!= overView
.getBounds().height
))) {
1246 if (overView
== null) {
1247 int backX
= getContentsX();
1248 int backY
= getContentsY();
1249 setContentsPos(0, 0);
1250 overView
= new Image(getDisplay(), r
.width
, r
.height
);
1251 GC gcim
= new GC(overView
);
1252 NGC context
= new NGC(this, gcim
);
1253 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
1254 frame
.draw(context
);
1255 setContentsPos(backX
, backY
);
1259 if ((overView
!= null) && (r
.width
== overView
.getBounds().width
) && (r
.height
== overView
.getBounds().height
))
1260 gc
.drawImage(overView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
1262 zoomValue
= oldzoom
;
1264 super.drawOverview(gc
, r
);
1268 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
1269 frame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
1270 ensureVisible(lifeline
);
1271 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
1272 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
1273 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
1278 public void resetZoomFactor() {
1279 int currentX
= Math
.round(getContentsX() / zoomValue
);
1280 int currentY
= Math
.round(getContentsY() / zoomValue
);
1282 if (timeBar
!= null && !timeBar
.isDisposed()) {
1283 timeBar
.setZoom(zoomValue
);
1287 setContentsPos(currentX
, currentY
);
1291 * Enable or disable the lifeline reodering using Drag and Drop
1293 * @param mode - true to enable false otherwise
1295 public void setReorderMode(boolean mode
) {
1300 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
1301 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
1303 * @return - the re-odered sequence
1305 public ArrayList
<Lifeline
[]> getLifelineReoderList() {
1309 public void setFocus(GraphNode node
) {
1312 if (currentGraphNode
!= null)
1313 currentGraphNode
.setFocused(false);
1314 currentGraphNode
= node
;
1315 node
.setFocused(true);
1316 ensureVisible(node
);
1320 public GraphNode
getFocusNode() {
1321 return currentGraphNode
;
1324 public void traverseRight() {
1325 Object selectedNode
= getFocusNode();
1326 if (selectedNode
== null)
1328 GraphNode node
= null;
1329 if (selectedNode
instanceof BaseMessage
) {
1330 if (((BaseMessage
) selectedNode
).getEndLifeline() != null)
1331 node
= frame
.getCalledMessage((BaseMessage
) selectedNode
);
1333 if (selectedNode
instanceof BasicExecutionOccurrence
) {
1334 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1336 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
1337 // if (selectedNode instanceof BaseMessage)
1339 // if (((BaseMessage)selectedNode).getStartLifeline()!=null)
1340 // selectedNode = ((BaseMessage)selectedNode).getStartLifeline();
1342 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
1343 if ((selectedNode
== frame
.getLifeline(i
)) && (i
< frame
.lifeLinesCount() - 1)) {
1344 node
= frame
.getLifeline(i
+ 1);
1355 public void traverseLeft() {
1356 Object selectedNode
= getFocusNode();
1357 GraphNode node
= null;
1358 if (selectedNode
instanceof BaseMessage
) {
1359 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1360 node
= frame
.getCallerMessage((BaseMessage
) selectedNode
);
1362 if (selectedNode
instanceof BasicExecutionOccurrence
) {
1363 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1366 if (selectedNode
instanceof BaseMessage
) {
1367 if (((BaseMessage
) selectedNode
).getEndLifeline() != null)
1368 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
1370 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
1371 if ((selectedNode
== frame
.getLifeline(i
)) && (i
> 0)) {
1372 node
= frame
.getLifeline(i
- 1);
1376 if ((frame
.lifeLinesCount() > 0) && (node
== null))
1377 node
= frame
.getLifeline(0);
1385 public void traverseUp() {
1386 Object selectedNode
= getFocusNode();
1387 if (selectedNode
== null)
1389 GraphNode node
= null;
1390 if (selectedNode
instanceof BaseMessage
)
1391 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
1392 else if (selectedNode
instanceof Lifeline
) {
1393 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
1394 if (!(node
instanceof Lifeline
))
1396 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1397 node
= frame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
1399 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1402 if (selectedNode
instanceof BaseMessage
) {
1403 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1404 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
1414 public void traverseDown() {
1415 Object selectedNode
= getFocusNode();
1416 if (selectedNode
== null)
1419 if (selectedNode
instanceof BaseMessage
)
1420 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
1421 else if (selectedNode
instanceof Lifeline
) {
1422 // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
1423 node
= frame
.getFirstExecution((Lifeline
) selectedNode
);
1424 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1425 node
= frame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
1435 public void traverseHome() {
1436 Object selectedNode
= getFocusNode();
1437 if (selectedNode
== null)
1439 GraphNode node
= null;
1441 * if (selectedNode instanceof BaseMessage) { if (((BaseMessage)selectedNode).getStartLifeline()!=null) node =
1442 * ((BaseMessage)selectedNode).getStartLifeline(); }
1444 if (selectedNode
instanceof BaseMessage
) {
1445 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1446 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
1448 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
1449 } else if (selectedNode
instanceof Lifeline
)
1450 node
= frame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
1451 else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1452 node
= frame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
1454 if (frame
.lifeLinesCount() > 0) {
1455 Lifeline lifeline
= frame
.getLifeline(0);
1456 node
= frame
.getNextLifelineMessage(lifeline
, null);
1466 public void traverseEnd() {
1467 Object selectedNode
= getFocusNode();
1468 if (selectedNode
== null)
1471 if (selectedNode
instanceof BaseMessage
)
1472 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
1473 else if (selectedNode
instanceof Lifeline
)
1474 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
1475 else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1476 node
= frame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
1478 if (frame
.lifeLinesCount() > 0) {
1479 Lifeline lifeline
= frame
.getLifeline(0);
1480 node
= frame
.getPrevLifelineMessage(lifeline
, null);
1491 public void printUI(SDPrintDialogUI sdPrinter
) {
1492 PrinterData data
= sdPrinter
.getPrinterData();
1494 if ((data
== null) || (frame
== null)) {
1498 printer
= new Printer(data
);
1500 String jobName
= MessageFormat
.format(SDMessages
._116
, new Object
[] { String
.valueOf(site
.getContentDescription()), String
.valueOf(frame
.getName()) });
1501 printer
.startJob(jobName
);
1503 GC gc
= new GC(printer
);
1504 Frame
.setUserPref(SDViewPref
.getInstance());
1506 float lastZoom
= zoomValue
;
1508 Rectangle area
= getClientArea();
1512 NGC context
= new NGC(this, gcim
);
1514 // Set the metrics to use for lifeline text and message text
1515 // using the Graphical Context
1516 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1517 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1518 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1519 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1520 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1522 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
1523 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
1524 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
1525 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS_RET
));
1527 int messageFontHeight
= 0;
1528 if (syncMessFontH
> syncMessRetFontH
)
1529 messageFontHeight
= syncMessFontH
;
1531 messageFontHeight
= syncMessRetFontH
;
1532 if (messageFontHeight
< asyncMessFontH
)
1533 messageFontHeight
= asyncMessFontH
;
1534 if (messageFontHeight
< asyncMessRetFontH
)
1535 messageFontHeight
= asyncMessRetFontH
;
1536 Metrics
.setMessageFontHeight(messageFontHeight
);
1537 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1539 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1540 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1541 if (width
< area
.width
)
1543 if (height
< area
.height
)
1544 height
= area
.height
;
1545 resizeContents(width
, height
);
1547 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1548 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1549 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1550 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1551 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1552 gcim
.setLineWidth(1);
1554 printer
.startPage();
1555 zoomValue
= lastZoom
;
1557 int restoreX
= getContentsX();
1558 int restoreY
= getContentsY();
1560 float zh
= getContentsHeight();
1561 float zw
= getContentsWidth();
1563 zh
= sdPrinter
.getStepY() * sdPrinter
.getZoomFactor();
1564 zw
= sdPrinter
.getStepX() * sdPrinter
.getZoomFactor();
1566 float zoomValueH
= printer
.getClientArea().height
/ zh
;
1567 float zoomValueW
= printer
.getClientArea().width
/ zw
;
1568 if (zoomValueH
> zoomValueW
)
1569 printerZoom
= zoomValueH
;
1571 printerZoom
= zoomValueW
;
1573 if (sdPrinter
.printSelection()) {
1574 int[] pagesList
= sdPrinter
.getPageList();
1576 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1577 printPage(pagesList
[pageIndex
], sdPrinter
, context
);
1579 } else if (sdPrinter
.printAll()) {
1580 for (int pageIndex
= 1; pageIndex
<= sdPrinter
.maxNumOfPages(); pageIndex
++) {
1581 printPage(pageIndex
, sdPrinter
, context
);
1583 } else if (sdPrinter
.printCurrent()) {
1584 printPage(getContentsX(), getContentsY(), sdPrinter
, context
, 1);
1585 } else if (sdPrinter
.printRange()) {
1586 for (int pageIndex
= sdPrinter
.getFrom(); pageIndex
<= sdPrinter
.maxNumOfPages() && pageIndex
<= sdPrinter
.getTo(); pageIndex
++) {
1587 printPage(pageIndex
, sdPrinter
, context
);
1597 zoomValue
= lastZoom
;
1599 setContentsPos(restoreX
, restoreY
);
1603 public void print() {
1604 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1606 if (sdPrinter
.open() != 0)
1608 } catch (Exception e
) {
1612 printUI(sdPrinter
.getDialogUI());
1615 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1616 int j
= pageNum
/ pd
.getNbRow();
1617 int i
= pageNum
% pd
.getNbRow();
1626 i
= (int) (i
* pd
.getStepX());
1627 j
= (int) (j
* pd
.getStepY());
1629 printPage(i
, j
, pd
, context
, pageNum
);
1634 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1636 int pageNumFontZoom
= printer
.getClientArea().height
/ getVisibleHeight();
1639 setContentsPos(i
, j
);
1642 float lastZoom
= zoomValue
;
1643 zoomValue
= printerZoom
* lastZoom
;
1645 frame
.draw(context
);
1647 zoomValue
= pageNumFontZoom
;
1648 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1649 String currentPageNum
= String
.valueOf(pageNum
);
1650 int ii
= context
.textExtent(currentPageNum
);
1651 int jj
= context
.getCurrentFontHeight();
1652 // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1653 // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
1654 zoomValue
= printerZoom
* lastZoom
;
1655 context
.drawText(currentPageNum
, Math
.round(printerX
+ getVisibleWidth() / printerZoom
- ii
/ printerZoom
), Math
.round(printerY
+ getVisibleHeight() / printerZoom
- jj
/ printerZoom
), false);
1657 zoomValue
= lastZoom
;
1661 public int getVisibleWidth() {
1663 return printer
.getClientArea().width
;
1664 return super.getVisibleWidth();
1668 public int getVisibleHeight() {
1670 return printer
.getClientArea().height
;
1671 return super.getVisibleHeight();
1675 public int contentsToViewX(int _x
) {
1677 int v
= Math
.round(printerX
* printerZoom
);
1680 return _x
- getContentsX();
1684 public int contentsToViewY(int _y
) {
1686 int v
= Math
.round(printerY
* printerZoom
);
1689 return _y
- getContentsY();
1693 public int getContentsX() {
1695 return Math
.round(printerX
* printerZoom
);
1696 return super.getContentsX();
1701 public int getContentsY() {
1703 return Math
.round(printerY
* printerZoom
);
1704 return super.getContentsY();
1707 public Printer
getPrinter() {
1711 public boolean isPrinting() {