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
.tmf
.event
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.ITmfImageConstants
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.ISDPreferences
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDCollapseProvider
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDPrintDialog
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDPrintDialogUI
;
44 import org
.eclipse
.swt
.SWT
;
45 import org
.eclipse
.swt
.accessibility
.ACC
;
46 import org
.eclipse
.swt
.accessibility
.Accessible
;
47 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
48 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
49 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
50 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
51 import org
.eclipse
.swt
.events
.DisposeEvent
;
52 import org
.eclipse
.swt
.events
.DisposeListener
;
53 import org
.eclipse
.swt
.events
.FocusEvent
;
54 import org
.eclipse
.swt
.events
.FocusListener
;
55 import org
.eclipse
.swt
.events
.KeyEvent
;
56 import org
.eclipse
.swt
.events
.MouseEvent
;
57 import org
.eclipse
.swt
.events
.SelectionEvent
;
58 import org
.eclipse
.swt
.events
.SelectionListener
;
59 import org
.eclipse
.swt
.events
.TraverseEvent
;
60 import org
.eclipse
.swt
.events
.TraverseListener
;
61 import org
.eclipse
.swt
.graphics
.GC
;
62 import org
.eclipse
.swt
.graphics
.Image
;
63 import org
.eclipse
.swt
.graphics
.ImageData
;
64 import org
.eclipse
.swt
.graphics
.Rectangle
;
65 import org
.eclipse
.swt
.printing
.Printer
;
66 import org
.eclipse
.swt
.printing
.PrinterData
;
67 import org
.eclipse
.swt
.widgets
.Canvas
;
68 import org
.eclipse
.swt
.widgets
.Caret
;
69 import org
.eclipse
.swt
.widgets
.Composite
;
70 import org
.eclipse
.swt
.widgets
.Control
;
71 import org
.eclipse
.swt
.widgets
.Display
;
72 import org
.eclipse
.swt
.widgets
.Event
;
73 import org
.eclipse
.swt
.widgets
.Listener
;
74 import org
.eclipse
.swt
.widgets
.MenuItem
;
75 import org
.eclipse
.ui
.contexts
.IContextService
;
76 import org
.eclipse
.ui
.part
.ViewPart
;
83 public class SDWidget
extends ScrollView
implements SelectionListener
, IPropertyChangeListener
, DisposeListener
, ITimeCompressionListener
{
85 protected Frame frame
;
86 protected Image overView
= null;
87 protected MenuItem zoomIn
= null;
88 protected MenuItem zoomOut
= null;
89 protected SDWidgetSelectionProvider selProvider
= null;
90 public float zoomValue
= 1;
91 protected boolean zoomInMode
= false;
92 protected boolean zoomOutMode
= false;
94 protected List
<GraphNode
> selectedNodeList
= null;
95 protected boolean ctrlSelection
= false;
97 protected ViewPart site
= null;
99 public GraphNode currentGraphNode
= null;
100 public GraphNode listStart
= null;
101 public ArrayList
<GraphNode
> prevList
= null;
103 protected TimeCompressionBar timeBar
= null;
105 protected DiagramToolTip toolTip
= null;
107 protected Accessible accessible
= null;
109 protected GraphNode toolTipNode
;
111 protected Lifeline dragAndDrop
= null;
113 protected int focusedWidget
= -1;
115 protected float printerZoom
= 0;
117 protected int printerY
= 0;
119 protected int printerX
= 0;
121 protected boolean getDragAndDrop
= false;
123 protected int dragX
= 0;
124 protected int dragY
= 0;
126 protected boolean reorderMode
= false;
128 Image collapaseCaretImg
= null;
129 Image arrowUpCaretImg
= null;
130 Image currentCaretImage
= null;
132 protected ISDCollapseProvider collapseProvider
= null;
134 protected Caret insertionCartet
= null;
136 protected ArrayList
<Lifeline
[]> reorderList
= null;
138 protected boolean printing
= false;
139 protected Printer printer
= null;
141 protected boolean shiftSelection
= false;
143 protected DiagramToolTip scrollToolTip
= null;
145 public SDWidget(Composite c
, int s
) {
146 super(c
, s
| SWT
.NO_BACKGROUND
, true);
147 setOverviewEnabled(true);
148 selectedNodeList
= new ArrayList
<GraphNode
>();
149 selProvider
= new SDWidgetSelectionProvider();
150 SDViewPref
.getInstance().addPropertyChangeListener(this);
151 toolTip
= new DiagramToolTip(getViewControl());
152 super.addDisposeListener(this);
154 scrollToolTip
= new DiagramToolTip(c
);
155 getVerticalBar().addListener(SWT
.MouseUp
, new Listener() {
158 public void handleEvent(Event event
) {
159 scrollToolTip
.hideToolTip();
163 // tooltip on vertical bar causes trouble when scrolling, because
164 // tooltip is constantly updated and shown
165 // getVerticalBar().addSelectionListener(new SelectionListener(){
167 // public void widgetSelected(SelectionEvent e) {
168 // scrollToolTip.hideToolTip();
170 // boolean needInit=true;
172 // for (int i=0;i<frame.lifeLinesCount();i++)
174 // Lifeline lifeline=frame.getLifeline(i);
175 // BasicExecutionOccurrence exec=frame.getFirstExecution(lifeline);
176 // if (exec instanceof ExecutionOccurrence) {
177 // ExecutionOccurrence occ=(ExecutionOccurrence)exec;
178 // if ((occ.hasTimeInfo())&&(occ.getFirstTime()<minOcc||needInit))
181 // minOcc=occ.getFirstTime();
188 // int z=frame.getFirstVisibleSyncMessage();
191 // SyncMessage s=frame.getSyncMessage(z);
192 // if (s.hasTimeInfo())
198 // scrollToolTip.showToolTip(MessageFormat.format(SDMessages._134, //$NON-NLS-1$
199 // new Object[] { formatTimeDate(frame.getSDMinTime()),
200 // formatTimeDate(m),
201 // formatTimeDate(frame.getSDMaxTime())} ));
204 // public void widgetDefaultSelected(SelectionEvent e) {
205 // // scrollToolTip.showToolTip("Toto");
211 accessible
= getViewControl().getAccessible();
213 accessible
.addAccessibleListener(new AccessibleAdapter() {
215 public void getName(AccessibleEvent e
) {
216 if (e
.childID
== ACC
.CHILDID_SELF
) {
220 else if (e
.childID
== 0) {
221 if (toolTipNode
!= null) {
222 if (toolTipNode
instanceof Lifeline
) {
223 Lifeline lifeline
= (Lifeline
) toolTipNode
;
224 e
.result
= lifeline
.getToolTipText();
226 e
.result
= toolTipNode
.getName() + getPostfixForTooltip(true);
230 if (getFocusNode() != null) {
231 if (getFocusNode() instanceof Lifeline
) {
232 e
.result
= MessageFormat
.format(SDMessages
._1
, new Object
[] { String
.valueOf(getFocusNode().getName()) });
234 if (getFocusNode() instanceof BaseMessage
) {
235 BaseMessage mes
= (BaseMessage
) getFocusNode();
236 if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() != null)) {
237 e
.result
= MessageFormat
.format(
239 new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()), String
.valueOf(mes
.getEndLifeline().getName()),
240 Integer
.valueOf(mes
.getEndOccurrence()) });
241 } else if ((mes
.getStartLifeline() == null) && (mes
.getEndLifeline() != null)) {
242 e
.result
= MessageFormat
.format(SDMessages
._4
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getEndLifeline().getName()), Integer
.valueOf(mes
.getEndOccurrence()) });
243 } else if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() == null)) {
244 e
.result
= MessageFormat
.format(SDMessages
._3
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()) });
246 } else if (getFocusNode() instanceof BasicExecutionOccurrence
) {
247 BasicExecutionOccurrence exec
= (BasicExecutionOccurrence
) getFocusNode();
248 e
.result
= MessageFormat
.format(SDMessages
._5
,
249 new Object
[] { String
.valueOf(exec
.getName()), String
.valueOf(exec
.getLifeline().getName()), Integer
.valueOf(exec
.getStartOccurrence()), Integer
.valueOf(exec
.getEndOccurrence()) });
253 // e.result =currentGraphNode.getName();
258 accessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
260 public void getFocus(AccessibleControlEvent e
) {
261 if (focusedWidget
== -1)
262 e
.childID
= ACC
.CHILDID_SELF
;
264 e
.childID
= focusedWidget
;
268 public void getRole(AccessibleControlEvent e
) {
270 case ACC
.CHILDID_SELF
:
271 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
274 e
.detail
= ACC
.ROLE_TOOLTIP
;
277 e
.detail
= ACC
.ROLE_LABEL
;
283 public void getState(AccessibleControlEvent e
) {
284 e
.detail
= ACC
.STATE_FOCUSABLE
;
285 if (e
.childID
== ACC
.CHILDID_SELF
) {
286 e
.detail
|= ACC
.STATE_FOCUSED
;
288 e
.detail
|= ACC
.STATE_SELECTABLE
;
289 if (e
.childID
== focusedWidget
)
290 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
295 insertionCartet
= new Caret((Canvas
) getViewControl(), SWT
.NONE
);
296 insertionCartet
.setVisible(false);
298 collapaseCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_COLLAPSE_OBJ
);
299 arrowUpCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_UP_OBJ
);
301 reorderList
= new ArrayList
<Lifeline
[]>();
302 getViewControl().addTraverseListener(new TraverseListener() {
305 public void keyTraversed(TraverseEvent e
) {
306 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
312 addTraverseListener(new TraverseListener() {
315 public void keyTraversed(TraverseEvent e
) {
316 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
))
322 getViewControl().addFocusListener(new FocusListener() {
325 public void focusGained(FocusEvent e
) {
326 // TODO Auto-generated method stub
327 SDViewPref
.getInstance().setNoFocusSelection(false);
328 ctrlSelection
= false;
329 shiftSelection
= false;
334 public void focusLost(FocusEvent e
) {
335 SDViewPref
.getInstance().setNoFocusSelection(true);
341 public void setTimeBar(TimeCompressionBar bar
) {
344 timeBar
.addTimeCompressionListener(this);
348 protected void setCollapseProvider(ISDCollapseProvider provider
) {
349 collapseProvider
= provider
;
353 protected void keyPressedEvent(KeyEvent event
) {
354 if (!(isFocusControl() || getViewControl().isFocusControl())) {
355 Control
[] child
= getParent().getChildren();
356 for (int i
= 0; i
< child
.length
; i
++) {
357 if (child
[i
].isFocusControl()) {
358 if (!(child
[i
] instanceof ScrollView
)) {
359 getViewControl().setFocus();
367 if (event
.keyCode
== SWT
.CTRL
)
368 ctrlSelection
= true;
369 if (event
.keyCode
== SWT
.SHIFT
) {
370 shiftSelection
= true;
371 prevList
= new ArrayList
<GraphNode
>();
372 prevList
.addAll(getSelection());
375 GraphNode prevNode
= getFocusNode();
377 if (event
.keyCode
== SWT
.ARROW_RIGHT
)
380 if (event
.keyCode
== SWT
.ARROW_LEFT
)
383 if (event
.keyCode
== SWT
.ARROW_DOWN
)
386 if (event
.keyCode
== SWT
.ARROW_UP
)
389 if (event
.keyCode
== SWT
.HOME
)
392 if (event
.keyCode
== SWT
.END
)
395 if ((!shiftSelection
) && (!ctrlSelection
))
396 listStart
= currentGraphNode
;
398 if (event
.character
== ' ') {
399 performSelection(currentGraphNode
);
401 listStart
= currentGraphNode
;
404 if ((shiftSelection
) && (prevNode
!= getFocusNode())) {
406 addSelection(prevList
);
407 addSelection(frame
.getNodeList(listStart
, getFocusNode()));
408 if (getFocusNode() instanceof Lifeline
)
409 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
411 ensureVisible(getFocusNode());
412 } else if ((!ctrlSelection
) && (!shiftSelection
)) {
415 if (getFocusNode() != null) {
416 addSelection(getFocusNode());
418 if (getFocusNode() instanceof Lifeline
)
419 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
421 ensureVisible(getFocusNode());
425 if (currentGraphNode
!= null)
426 currentGraphNode
.setFocused(true);
429 if ((event
.character
== ' ') && ((zoomInMode
) || (zoomOutMode
))) {
430 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / zoomValue
);
431 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / zoomValue
);
434 zoomValue
= zoomValue
* (float) 1.25;
436 zoomValue
= zoomValue
/ (float) 1.25;
437 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
438 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
439 setContentsPos(x
, y
);
441 timeBar
.setZoom(zoomValue
);
442 // redraw also resize the scrollView content
448 protected void keyReleasedEvent(KeyEvent event
) {
450 if (event
.keyCode
== SWT
.CTRL
)
451 ctrlSelection
= false;
452 if (event
.keyCode
== SWT
.SHIFT
)
453 shiftSelection
= false;
454 super.keyReleasedEvent(event
);
459 * Resize the contents to insure the frame fit into the view
461 * @param frame the frame which will be drawn in the view
463 public void resizeContents(Frame frame
) {
464 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
465 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
466 resizeContents(width
, height
);
469 protected boolean checkFocusOnChilds(Control childs
) {
470 if (childs
instanceof Composite
) {
471 Control
[] child
= ((Composite
) childs
).getChildren();
472 for (int i
= 0; i
< child
.length
; i
++) {
473 if (child
[i
].isFocusControl()) {
476 checkFocusOnChilds(child
[i
]);
483 public boolean isFocusControl() {
484 Control
[] child
= getChildren();
485 for (int i
= 0; i
< child
.length
; i
++) {
486 if (child
[i
].isFocusControl()) {
489 checkFocusOnChilds(child
[i
]);
495 * The frame to render (the sequence diagram)
497 * @param theFrame the frame to display
499 public void setFrame(Frame theFrame
, boolean resetPosition
) {
501 selectedNodeList
.clear();
502 selProvider
.setSelection(new StructuredSelection());
505 setContentsPos(0, 0);
506 resizeContents(frame
);
509 // prepare the old overview to be reused
510 if (overView
!= null)
513 resizeContents(frame
);
517 * Returns the current Frame (the sequence diagram container)
521 public Frame
getFrame() {
526 * Returns the selection provider for the current sequence diagram
528 * @return the selection provider
530 public ISelectionProvider
getSelectionProvider() {
535 public boolean setContentsPos(int x
, int y
) {
542 if (x
+ getVisibleWidth() > getContentsWidth())
543 x
= getContentsWidth() - getVisibleWidth();
544 if (y
+ getVisibleHeight() > getContentsHeight())
545 y
= getContentsHeight() - getVisibleHeight();
546 int x1
= Math
.round(x
/ zoomValue
);
547 int y2
= Math
.round(y
/ zoomValue
);
548 int width
= Math
.round(getVisibleWidth() / zoomValue
);
549 int height
= Math
.round(getVisibleHeight() / zoomValue
);
550 frame
.updateIndex(x1
, y2
, width
, height
);
552 if (insertionCartet
!= null && insertionCartet
.isVisible())
553 insertionCartet
.setVisible(false);
555 return super.setContentsPos(x
, y
);
559 protected void contentsMouseHover(MouseEvent event
) {
560 GraphNode graphNode
= null;
562 int x
= Math
.round(event
.x
/ zoomValue
);
563 int y
= Math
.round(event
.y
/ zoomValue
);
564 graphNode
= frame
.getNodeAt(x
, y
);
565 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
566 toolTipNode
= graphNode
;
567 String postfix
= getPostfixForTooltip(true);
568 if (graphNode
instanceof Lifeline
) {
569 Lifeline lifeline
= (Lifeline
) graphNode
;
570 toolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
573 toolTip
.showToolTip(graphNode
.getName() + postfix
);
577 toolTip
.hideToolTip();
581 protected String
getPostfixForTooltip(boolean accessible
) {
582 String postfix
= "";//$NON-NLS-1$
583 // Determine if the tooltip must show the time difference between the current mouse position and
584 // the last selected graphNode
585 if ((currentGraphNode
!= null) &&
586 (currentGraphNode
instanceof ITimeRange
) &&
587 (toolTipNode
instanceof ITimeRange
) &&
588 (currentGraphNode
!= toolTipNode
) &&
589 ((ITimeRange
) toolTipNode
).hasTimeInfo() &&
590 ((ITimeRange
) currentGraphNode
).hasTimeInfo()) {
591 postfix
= " -> " + currentGraphNode
.getName() + "\n" + SDMessages
._138
+ " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
593 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
594 TmfTimestamp firstTime
= ((ITimeRange
) currentGraphNode
).getEndTime();
595 TmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
596 TmfTimestamp delta
= lastTime
.getDelta(firstTime
);
597 postfix
+= delta
.toString();
599 if ((toolTipNode
instanceof ITimeRange
) && ((ITimeRange
) toolTipNode
).hasTimeInfo()) {
600 postfix
= "\n";//$NON-NLS-1$
601 TmfTimestamp firstTime
= ((ITimeRange
) toolTipNode
).getStartTime();
602 TmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
604 if (firstTime
!= null) {
605 if (lastTime
!= null && firstTime
.compareTo(lastTime
, true) != 0) {
606 postfix
+= "start: " + firstTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
607 postfix
+= "end: " + lastTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
609 postfix
+= firstTime
.toString();
612 else if (lastTime
!= null) {
613 postfix
+= lastTime
.toString();
620 protected void setFocus(int newFocusShape
) {
621 focusedWidget
= newFocusShape
;
622 if (focusedWidget
== -1) {
623 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
625 getViewControl().getAccessible().setFocus(focusedWidget
);
629 /** Timer for auto_scroll feature */
630 protected AutoScroll local_auto_scroll_
= null;
631 /** TimerTask for auto_scroll feature !=null when auto scroll is running */
632 protected Timer local_auto_scroll_timer_
= null;
634 /** TimerTask for auto scroll feature. */
635 protected static class AutoScroll
extends TimerTask
{
639 public AutoScroll(SDWidget _sv
, int _dx
, int _dy
) {
647 Display
.getDefault().asyncExec(new Runnable() {
650 if (sv_
.isDisposed())
654 sv_
.scrollBy(dx_
, dy_
);
661 protected void contentsMouseMoveEvent(MouseEvent e
) {
662 scrollToolTip
.hideToolTip();
663 toolTip
.hideToolTip();
664 // super.contentsMouseMoveEvent(e);
665 if (!(isFocusControl() || getViewControl().isFocusControl())) {
666 Control
[] child
= getParent().getChildren();
667 for (int i
= 0; i
< child
.length
; i
++) {
668 if (child
[i
].isFocusControl()) {
669 if (!(child
[i
] instanceof ScrollView
)) {
670 getViewControl().setFocus();
678 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((dragAndDrop
!= null) || getDragAndDrop
) && (reorderMode
|| collapseProvider
!= null)) {
679 getDragAndDrop
= false;
680 if (currentGraphNode
instanceof Lifeline
)
681 dragAndDrop
= (Lifeline
) currentGraphNode
;
682 if (dragAndDrop
!= null) {
685 if (e
.x
> getContentsX() + getVisibleWidth()) {
686 dx
= e
.x
- (getContentsX() + getVisibleWidth());
687 } else if (e
.x
< getContentsX()) {
688 dx
= -getContentsX() + e
.x
;
690 if (e
.y
> getContentsY() + getVisibleHeight()) {
691 dy
= e
.y
- (getContentsY() + getVisibleHeight());
692 } else if (e
.y
< getContentsY()) {
693 dy
= -getContentsY() + e
.y
;
697 if (dx
!= 0 || dy
!= 0) {
698 if (local_auto_scroll_
== null) {
699 if (local_auto_scroll_timer_
== null) {
700 local_auto_scroll_timer_
= new Timer(true);
702 local_auto_scroll_
= new AutoScroll(this, dx
, dy
);
703 local_auto_scroll_timer_
.schedule(local_auto_scroll_
, 0, 75);
705 local_auto_scroll_
.dx_
= dx
;
706 local_auto_scroll_
.dy_
= dy
;
708 } else if (local_auto_scroll_
!= null) {
709 local_auto_scroll_
.cancel();
710 local_auto_scroll_
= null;
712 dragX
= Math
.round(e
.x
/ zoomValue
);
713 dragY
= Math
.round(e
.y
/ zoomValue
);
715 Lifeline node
= frame
.getCloserLifeline(dragX
);
716 if ((node
!= null) && (node
!= dragAndDrop
)) {
719 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
720 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
722 int width
= node
.getWidth();
723 if (frame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
)
724 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * zoomValue
));
726 y
= Math
.round(height
* zoomValue
);
728 if (frame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
))
729 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * zoomValue
));
731 y1
= Math
.round(height
* zoomValue
);
733 int rx
= Math
.round(x
* zoomValue
);
735 insertionCartet
.setVisible(true);
736 if ((insertionCartet
.getImage() != null) && (!insertionCartet
.getImage().isDisposed()))
737 insertionCartet
.getImage().dispose();
738 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* zoomValue
)) >= e
.x
) {
739 if (collapseProvider
!= null) {
740 ImageData data
= collapaseCaretImg
.getImageData();
741 data
= data
.scaledTo(Math
.round(collapaseCaretImg
.getBounds().width
* zoomValue
), Math
.round(collapaseCaretImg
.getBounds().height
* zoomValue
));
742 currentCaretImage
= new Image(Display
.getCurrent(), data
);
743 insertionCartet
.setImage(currentCaretImage
);
744 insertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y
);
746 } else if (reorderMode
) {
748 if (node
.getIndex() > 1 && frame
.getLifeline(node
.getIndex() - 2) == dragAndDrop
)
750 ImageData data
= arrowUpCaretImg
.getImageData();
751 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
752 currentCaretImage
= new Image(Display
.getCurrent(), data
);
753 insertionCartet
.setImage(currentCaretImage
);
754 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y1
);
756 if (node
.getIndex() < frame
.lifeLinesCount() && frame
.getLifeline(node
.getIndex()) == dragAndDrop
)
758 ImageData data
= arrowUpCaretImg
.getImageData();
759 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
760 currentCaretImage
= new Image(Display
.getCurrent(), data
);
761 insertionCartet
.setImage(currentCaretImage
);
762 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2 + 1, y1
);
766 insertionCartet
.setVisible(false);
769 super.contentsMouseMoveEvent(e
);
773 protected void contentsMouseUpEvent(MouseEvent event
) {
774 // Just in case the diagram highlight a time compression region
775 // this region need to be released when clicking everywhere
776 insertionCartet
.setVisible(false);
777 if (dragAndDrop
!= null) {
778 if ((overView
!= null) && (!overView
.isDisposed()))
781 Lifeline node
= frame
.getCloserLifeline(dragX
);
783 int rx
= Math
.round(node
.getX() * zoomValue
);
784 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * zoomValue
)) >= event
.x
) {
785 if ((collapseProvider
!= null) && (dragAndDrop
!= node
))
786 collapseProvider
.collapseTwoLifelines((Lifeline
) dragAndDrop
, node
);
787 } else if (rx
< event
.x
) {
788 frame
.insertLifelineAfter((Lifeline
) dragAndDrop
, node
);
789 if (node
.getIndex() < frame
.lifeLinesCount()) {
790 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, frame
.getLifeline(node
.getIndex()) };
791 reorderList
.add(temp
);
793 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, null };
794 reorderList
.add(temp
);
797 frame
.insertLifelineBefore((Lifeline
) dragAndDrop
, node
);
798 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, node
};
799 reorderList
.add(temp
);
808 frame
.resetTimeCompression();
810 // reset auto scroll if it's engaged
811 if (local_auto_scroll_
!= null) {
812 local_auto_scroll_
.cancel();
813 local_auto_scroll_
= null;
815 super.contentsMouseUpEvent(event
);
819 protected void contentsMouseDownEvent(MouseEvent event
) {
820 if (currentGraphNode
!= null)
821 currentGraphNode
.setFocused(false);
822 // Just in case the diagram highlight a time compression region
823 // this region need to be released when clicking everywhere
827 frame
.resetTimeCompression();
829 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
830 ctrlSelection
= true;
832 ctrlSelection
= false;
834 if (((zoomInMode
) || (zoomOutMode
)) && (event
.button
== 1)) {
835 int cx
= Math
.round(event
.x
/ zoomValue
);
836 int cy
= Math
.round(event
.y
/ zoomValue
);
839 zoomValue
= zoomValue
* (float) 1.25;
841 zoomValue
= zoomValue
/ (float) 1.25;
842 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
843 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
844 setContentsPos(x
, y
);
846 timeBar
.setZoom(zoomValue
);
847 // redraw also resize the scrollView content
849 } else// if (event.button ==1)
851 GraphNode node
= null;
853 int x
= Math
.round(event
.x
/ zoomValue
);
854 int y
= Math
.round(event
.y
/ zoomValue
);
855 node
= frame
.getNodeAt(x
, y
);
857 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
860 if (shiftSelection
) {
862 addSelection(frame
.getNodeList(listStart
, node
));
864 performSelection(node
);
865 currentGraphNode
= node
;
867 node
.setFocused(true);
872 if (dragAndDrop
== null)
873 super.contentsMouseDownEvent(event
);
874 getDragAndDrop
= (event
.button
== 1);
879 * Highlight the given GraphNode<br>
880 * The GraphNode is then displayed using the system default selection color
882 * @param node the GraphNode to highlight
884 protected void performSelection(GraphNode node
) {
885 if ((ctrlSelection
) || (shiftSelection
)) {
887 if (selectedNodeList
.contains(node
)) {
888 removeSelection(node
);
902 public List
<GraphNode
> getSelection() {
903 return selectedNodeList
;
906 public void addSelection(GraphNode node
) {
909 selectedNodeList
.add(node
);
910 node
.setSelected(true);
911 currentGraphNode
= node
;
912 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
913 selProvider
.setSelection(selection
);
916 public void addSelection(List
<GraphNode
> list
) {
917 // selectedNodeList.addAll(list);
918 for (int i
= 0; i
< list
.size(); i
++) {
919 if (!selectedNodeList
.contains(list
.get(i
))) {
920 selectedNodeList
.add(list
.get(i
));
921 ((GraphNode
) list
.get(i
)).setSelected(true);
924 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
925 selProvider
.setSelection(selection
);
928 public void removeSelection(GraphNode node
) {
929 selectedNodeList
.remove(node
);
930 node
.setSelected(false);
931 node
.setFocused(false);
932 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
933 selProvider
.setSelection(selection
);
936 public void removeSelection(List
<GraphNode
> list
) {
937 selectedNodeList
.removeAll(list
);
938 for (int i
= 0; i
< list
.size(); i
++) {
939 ((GraphNode
) list
.get(i
)).setSelected(false);
940 ((GraphNode
) list
.get(i
)).setFocused(false);
942 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
943 selProvider
.setSelection(selection
);
947 * Clear the list of GraphNodes which must be drawn selected
950 public void clearSelection() {
951 for (int i
= 0; i
< selectedNodeList
.size(); i
++) {
952 ((GraphNode
) selectedNodeList
.get(i
)).setSelected(false);
953 ((GraphNode
) selectedNodeList
.get(i
)).setFocused(false);
955 currentGraphNode
= null;
956 selectedNodeList
.clear();
957 selProvider
.setSelection(new StructuredSelection());
960 public void setSite(ViewPart viewSite
) {
962 site
.getSite().setSelectionProvider(selProvider
);
963 IContextService service
= (IContextService
) site
.getSite().getWorkbenchWindow().getService(IContextService
.class);
964 service
.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
965 service
.activateContext(IContextIds
.CONTEXT_ID_WINDOW
);
968 protected Image
getDrawBuffer(GC gc
) {
971 Rectangle area
= getClientArea();
972 Image dbuffer
= null;
976 // if (dbuffer!=null)
977 // dbuffer.dispose();
978 dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
979 } catch (Exception e
) {
980 System
.out
.println(e
.toString());
982 gcim
= new GC(dbuffer
);
984 NGC context
= new NGC(this, gcim
);
986 // Set the metrics to use for lifeline text and message text
987 // using the Graphical Context
988 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
989 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
990 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
991 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
992 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
994 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
995 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
996 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
997 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS_RET
));
999 int messageFontHeight
= 0;
1000 if (syncMessFontH
> syncMessRetFontH
)
1001 messageFontHeight
= syncMessFontH
;
1003 messageFontHeight
= syncMessRetFontH
;
1004 if (messageFontHeight
< asyncMessFontH
)
1005 messageFontHeight
= asyncMessFontH
;
1006 if (messageFontHeight
< asyncMessRetFontH
)
1007 messageFontHeight
= asyncMessRetFontH
;
1008 Metrics
.setMessageFontHeight(messageFontHeight
);
1009 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1011 int width
= (int) ((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1012 int height
= (int) ((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1013 // if (width<area.width)
1014 // width=area.width;
1015 // if (height<area.height)
1016 // height=area.height;
1017 resizeContents(width
, height
);
1019 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1020 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1021 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1022 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1023 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1024 gcim
.setLineWidth(1);
1026 frame
.draw(context
);
1027 if (dragAndDrop
!= null) {
1028 Lifeline node
= (Lifeline
) dragAndDrop
;
1029 boolean isSelected
= dragAndDrop
.isSelected();
1030 boolean hasFocus
= dragAndDrop
.hasFocus();
1031 node
.setSelected(false);
1032 node
.setFocused(false);
1033 node
.draw(context
, dragX
, dragY
);
1034 node
.setSelected(isSelected
);
1035 node
.setFocused(hasFocus
);
1044 * @param gc the context
1047 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1048 if (frame
== null) {
1049 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1050 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1054 Frame
.setUserPref(SDViewPref
.getInstance());
1057 Rectangle area
= getClientArea();
1058 Image dbuffer
= getDrawBuffer(gc
);
1059 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1062 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1063 } catch (Exception e
) {
1064 System
.out
.println(e
.getMessage());
1067 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * zoomValue
));
1068 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * zoomValue
));
1069 if ((timeBar
!= null) && (frame
.hasTimeInfo())) {
1070 timeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1071 timeBar
.setContentsPos(getContentsX(), getContentsY());
1075 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1076 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1077 if (yRatio
> xRatio
) {
1078 setOverviewSize((int) (getVisibleHeight() * 0.75));
1080 setOverviewSize((int) (getVisibleWidth() * 0.75));
1085 * Returns the GraphNode overView the mouse if any
1087 * @return the GraphNode
1089 public GraphNode
getMouseOverNode() {
1090 return currentGraphNode
;
1094 public void widgetDefaultSelected(SelectionEvent event
) {
1098 public void widgetSelected(SelectionEvent event
) {
1099 if (event
.widget
== zoomIn
)
1100 zoomValue
= zoomValue
* 2;
1101 else if (event
.widget
== zoomOut
)
1102 zoomValue
= zoomValue
/ 2;
1104 // SearchFilterDialog tt = new SearchFilterDialog(null);//display.getActiveShell());
1109 public void setZoomInMode(boolean value
) {
1111 setZoomOutMode(false);
1115 public void setZoomOutMode(boolean value
) {
1117 setZoomInMode(false);
1118 zoomOutMode
= value
;
1122 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
1124 * @param node the GraphNode to move to
1126 public void moveTo(GraphNode node
) {
1131 ensureVisible(node
);
1135 * Moves the Sequence diagram to ensure the given node is visible
1137 * @param node the GraphNode to move to
1139 public void ensureVisible(GraphNode node
) {
1142 int x
= Math
.round(node
.getX() * zoomValue
);
1143 int y
= Math
.round(node
.getY() * zoomValue
);
1144 int width
= Math
.round(node
.getWidth() * zoomValue
);
1145 int height
= Math
.round(node
.getHeight() * zoomValue
);
1146 if (node
instanceof BaseMessage
) {
1148 int header
= Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
* 2 + Metrics
.getLifelineHeaderFontHeigth();
1149 height
= -Math
.round((Metrics
.getMessagesSpacing() + header
) * zoomValue
);
1150 y
= y
+ Math
.round(Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
* zoomValue
);
1153 if (node
instanceof BasicExecutionOccurrence
) {
1157 if (node
instanceof Lifeline
) {
1159 height
= getVisibleHeight();
1161 ensureVisible(x
, y
, width
, height
, SWT
.CENTER
, true);
1165 public float getZoomFactor() {
1170 * Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply
1173 * @param e the PropertyChangeEvent
1176 public void propertyChange(PropertyChangeEvent e
) {
1177 if (frame
!= null && !isDisposed()) {
1178 frame
.resetTimeCompression();
1180 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1182 // Prepare the overview to be reused for the new
1183 // settings (especially the colors)
1184 if (overView
!= null)
1192 public void widgetDisposed(DisposeEvent e
) {
1193 if (overView
!= null)
1195 super.removeDisposeListener(this);
1196 if ((currentCaretImage
!= null) && (!currentCaretImage
.isDisposed()))
1197 currentCaretImage
.dispose();
1198 if ((arrowUpCaretImg
!= null) && (!arrowUpCaretImg
.isDisposed()))
1199 arrowUpCaretImg
.dispose();
1200 if ((collapaseCaretImg
!= null) && (!collapaseCaretImg
.isDisposed()))
1201 collapaseCaretImg
.dispose();
1202 SDViewPref
.getInstance().removePropertyChangeListener(this);
1203 LoadersManager lm
= LoadersManager
.getInstance();
1204 if (site
!= null && site
instanceof SDView
) {
1205 ((SDView
) site
).resetProviders();
1207 lm
.resetLoader(((SDView
) site
).getViewSite().getId());
1211 public Image
getOverview(Rectangle r
) {
1212 float oldzoom
= zoomValue
;
1213 if ((overView
!= null) && ((r
.width
!= overView
.getBounds().width
) || (r
.height
!= overView
.getBounds().height
))) {
1217 if (overView
== null) {
1218 int backX
= getContentsX();
1219 int backY
= getContentsY();
1220 setContentsPos(0, 0);
1221 overView
= new Image(getDisplay(), r
.width
, r
.height
);
1222 GC gcim
= new GC(overView
);
1223 NGC context
= new NGC(this, gcim
);
1224 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
1225 frame
.draw(context
);
1226 setContentsPos(backX
, backY
);
1230 zoomValue
= oldzoom
;
1235 protected void drawOverview(GC gc
, Rectangle r
) {
1236 float oldzoom
= zoomValue
;
1237 if (getContentsWidth() > getContentsHeight())
1238 zoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
1240 zoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
1241 if ((overView
!= null) && ((r
.width
!= overView
.getBounds().width
) || (r
.height
!= overView
.getBounds().height
))) {
1245 if (overView
== null) {
1246 int backX
= getContentsX();
1247 int backY
= getContentsY();
1248 setContentsPos(0, 0);
1249 overView
= new Image(getDisplay(), r
.width
, r
.height
);
1250 GC gcim
= new GC(overView
);
1251 NGC context
= new NGC(this, gcim
);
1252 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
1253 frame
.draw(context
);
1254 setContentsPos(backX
, backY
);
1258 if ((overView
!= null) && (r
.width
== overView
.getBounds().width
) && (r
.height
== overView
.getBounds().height
))
1259 gc
.drawImage(overView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
1261 zoomValue
= oldzoom
;
1263 super.drawOverview(gc
, r
);
1267 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
1268 frame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
1269 ensureVisible(lifeline
);
1270 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
1271 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
1272 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
1277 public void resetZoomFactor() {
1278 int currentX
= Math
.round(getContentsX() / zoomValue
);
1279 int currentY
= Math
.round(getContentsY() / zoomValue
);
1281 if (timeBar
!= null && !timeBar
.isDisposed()) {
1282 timeBar
.setZoom(zoomValue
);
1286 setContentsPos(currentX
, currentY
);
1290 * Enable or disable the lifeline reodering using Drag and Drop
1292 * @param mode - true to enable false otherwise
1294 public void setReorderMode(boolean mode
) {
1299 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
1300 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
1302 * @return - the re-odered sequence
1304 public ArrayList
<Lifeline
[]> getLifelineReoderList() {
1308 public void setFocus(GraphNode node
) {
1311 if (currentGraphNode
!= null)
1312 currentGraphNode
.setFocused(false);
1313 currentGraphNode
= node
;
1314 node
.setFocused(true);
1315 ensureVisible(node
);
1319 public GraphNode
getFocusNode() {
1320 return currentGraphNode
;
1323 public void traverseRight() {
1324 Object selectedNode
= getFocusNode();
1325 if (selectedNode
== null)
1327 GraphNode node
= null;
1328 if (selectedNode
instanceof BaseMessage
) {
1329 if (((BaseMessage
) selectedNode
).getEndLifeline() != null)
1330 node
= frame
.getCalledMessage((BaseMessage
) selectedNode
);
1332 if (selectedNode
instanceof BasicExecutionOccurrence
) {
1333 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1335 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
1336 // if (selectedNode instanceof BaseMessage)
1338 // if (((BaseMessage)selectedNode).getStartLifeline()!=null)
1339 // selectedNode = ((BaseMessage)selectedNode).getStartLifeline();
1341 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
1342 if ((selectedNode
== frame
.getLifeline(i
)) && (i
< frame
.lifeLinesCount() - 1)) {
1343 node
= frame
.getLifeline(i
+ 1);
1354 public void traverseLeft() {
1355 Object selectedNode
= getFocusNode();
1356 GraphNode node
= null;
1357 if (selectedNode
instanceof BaseMessage
) {
1358 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1359 node
= frame
.getCallerMessage((BaseMessage
) selectedNode
);
1361 if (selectedNode
instanceof BasicExecutionOccurrence
) {
1362 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1365 if (selectedNode
instanceof BaseMessage
) {
1366 if (((BaseMessage
) selectedNode
).getEndLifeline() != null)
1367 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
1369 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
1370 if ((selectedNode
== frame
.getLifeline(i
)) && (i
> 0)) {
1371 node
= frame
.getLifeline(i
- 1);
1375 if ((frame
.lifeLinesCount() > 0) && (node
== null))
1376 node
= frame
.getLifeline(0);
1384 public void traverseUp() {
1385 Object selectedNode
= getFocusNode();
1386 if (selectedNode
== null)
1388 GraphNode node
= null;
1389 if (selectedNode
instanceof BaseMessage
)
1390 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
1391 else if (selectedNode
instanceof Lifeline
) {
1392 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
1393 if (!(node
instanceof Lifeline
))
1395 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1396 node
= frame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
1398 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
1401 if (selectedNode
instanceof BaseMessage
) {
1402 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1403 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
1413 public void traverseDown() {
1414 Object selectedNode
= getFocusNode();
1415 if (selectedNode
== null)
1418 if (selectedNode
instanceof BaseMessage
)
1419 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
1420 else if (selectedNode
instanceof Lifeline
) {
1421 // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
1422 node
= frame
.getFirstExecution((Lifeline
) selectedNode
);
1423 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1424 node
= frame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
1434 public void traverseHome() {
1435 Object selectedNode
= getFocusNode();
1436 if (selectedNode
== null)
1438 GraphNode node
= null;
1440 * if (selectedNode instanceof BaseMessage) { if (((BaseMessage)selectedNode).getStartLifeline()!=null) node =
1441 * ((BaseMessage)selectedNode).getStartLifeline(); }
1443 if (selectedNode
instanceof BaseMessage
) {
1444 if (((BaseMessage
) selectedNode
).getStartLifeline() != null)
1445 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
1447 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
1448 } else if (selectedNode
instanceof Lifeline
)
1449 node
= frame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
1450 else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1451 node
= frame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
1453 if (frame
.lifeLinesCount() > 0) {
1454 Lifeline lifeline
= frame
.getLifeline(0);
1455 node
= frame
.getNextLifelineMessage(lifeline
, null);
1465 public void traverseEnd() {
1466 Object selectedNode
= getFocusNode();
1467 if (selectedNode
== null)
1470 if (selectedNode
instanceof BaseMessage
)
1471 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
1472 else if (selectedNode
instanceof Lifeline
)
1473 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
1474 else if (selectedNode
instanceof BasicExecutionOccurrence
) {
1475 node
= frame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
1477 if (frame
.lifeLinesCount() > 0) {
1478 Lifeline lifeline
= frame
.getLifeline(0);
1479 node
= frame
.getPrevLifelineMessage(lifeline
, null);
1490 public void printUI(SDPrintDialogUI sdPrinter
) {
1491 PrinterData data
= sdPrinter
.getPrinterData();
1493 if ((data
== null) || (frame
== null)) {
1497 printer
= new Printer(data
);
1499 String jobName
= MessageFormat
.format(SDMessages
._116
, new Object
[] { String
.valueOf(site
.getContentDescription()), String
.valueOf(frame
.getName()) });
1500 printer
.startJob(jobName
);
1502 GC gc
= new GC(printer
);
1503 Frame
.setUserPref(SDViewPref
.getInstance());
1505 float lastZoom
= zoomValue
;
1507 Rectangle area
= getClientArea();
1511 NGC context
= new NGC(this, gcim
);
1513 // Set the metrics to use for lifeline text and message text
1514 // using the Graphical Context
1515 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1516 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1517 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1518 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1519 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1521 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
1522 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
1523 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
1524 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS_RET
));
1526 int messageFontHeight
= 0;
1527 if (syncMessFontH
> syncMessRetFontH
)
1528 messageFontHeight
= syncMessFontH
;
1530 messageFontHeight
= syncMessRetFontH
;
1531 if (messageFontHeight
< asyncMessFontH
)
1532 messageFontHeight
= asyncMessFontH
;
1533 if (messageFontHeight
< asyncMessRetFontH
)
1534 messageFontHeight
= asyncMessRetFontH
;
1535 Metrics
.setMessageFontHeight(messageFontHeight
);
1536 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1538 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1539 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1540 if (width
< area
.width
)
1542 if (height
< area
.height
)
1543 height
= area
.height
;
1544 resizeContents(width
, height
);
1546 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1547 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1548 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1549 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1550 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1551 gcim
.setLineWidth(1);
1553 printer
.startPage();
1554 zoomValue
= lastZoom
;
1556 int restoreX
= getContentsX();
1557 int restoreY
= getContentsY();
1559 float zh
= getContentsHeight();
1560 float zw
= getContentsWidth();
1562 zh
= sdPrinter
.getStepY() * sdPrinter
.getZoomFactor();
1563 zw
= sdPrinter
.getStepX() * sdPrinter
.getZoomFactor();
1565 float zoomValueH
= printer
.getClientArea().height
/ zh
;
1566 float zoomValueW
= printer
.getClientArea().width
/ zw
;
1567 if (zoomValueH
> zoomValueW
)
1568 printerZoom
= zoomValueH
;
1570 printerZoom
= zoomValueW
;
1572 if (sdPrinter
.printSelection()) {
1573 int[] pagesList
= sdPrinter
.getPageList();
1575 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1576 printPage(pagesList
[pageIndex
], sdPrinter
, context
);
1578 } else if (sdPrinter
.printAll()) {
1579 for (int pageIndex
= 1; pageIndex
<= sdPrinter
.maxNumOfPages(); pageIndex
++) {
1580 printPage(pageIndex
, sdPrinter
, context
);
1582 } else if (sdPrinter
.printCurrent()) {
1583 printPage(getContentsX(), getContentsY(), sdPrinter
, context
, 1);
1584 } else if (sdPrinter
.printRange()) {
1585 for (int pageIndex
= sdPrinter
.getFrom(); pageIndex
<= sdPrinter
.maxNumOfPages() && pageIndex
<= sdPrinter
.getTo(); pageIndex
++) {
1586 printPage(pageIndex
, sdPrinter
, context
);
1596 zoomValue
= lastZoom
;
1598 setContentsPos(restoreX
, restoreY
);
1602 public void print() {
1603 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1605 if (sdPrinter
.open() != 0)
1607 } catch (Exception e
) {
1611 printUI(sdPrinter
.getDialogUI());
1614 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1615 int j
= pageNum
/ pd
.getNbRow();
1616 int i
= pageNum
% pd
.getNbRow();
1625 i
= (int) (i
* pd
.getStepX());
1626 j
= (int) (j
* pd
.getStepY());
1628 printPage(i
, j
, pd
, context
, pageNum
);
1633 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1635 int pageNumFontZoom
= printer
.getClientArea().height
/ getVisibleHeight();
1638 setContentsPos(i
, j
);
1641 float lastZoom
= zoomValue
;
1642 zoomValue
= printerZoom
* lastZoom
;
1644 frame
.draw(context
);
1646 zoomValue
= pageNumFontZoom
;
1647 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1648 String currentPageNum
= String
.valueOf(pageNum
);
1649 int ii
= context
.textExtent(currentPageNum
);
1650 int jj
= context
.getCurrentFontHeight();
1651 // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1652 // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
1653 zoomValue
= printerZoom
* lastZoom
;
1654 context
.drawText(currentPageNum
, Math
.round(printerX
+ getVisibleWidth() / printerZoom
- ii
/ printerZoom
), Math
.round(printerY
+ getVisibleHeight() / printerZoom
- jj
/ printerZoom
), false);
1656 zoomValue
= lastZoom
;
1660 public int getVisibleWidth() {
1662 return printer
.getClientArea().width
;
1663 return super.getVisibleWidth();
1667 public int getVisibleHeight() {
1669 return printer
.getClientArea().height
;
1670 return super.getVisibleHeight();
1674 public int contentsToViewX(int _x
) {
1676 int v
= Math
.round(printerX
* printerZoom
);
1679 return _x
- getContentsX();
1683 public int contentsToViewY(int _y
) {
1685 int v
= Math
.round(printerY
* printerZoom
);
1688 return _y
- getContentsY();
1692 public int getContentsX() {
1694 return Math
.round(printerX
* printerZoom
);
1695 return super.getContentsX();
1700 public int getContentsY() {
1702 return Math
.round(printerY
* printerZoom
);
1703 return super.getContentsY();
1706 public Printer
getPrinter() {
1710 public boolean isPrinting() {