1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
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
.Activator
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
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
.dialogs
.SDPrintDialog
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.SDPrintDialogUI
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
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
.ISDPreferences
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
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
;
80 * This class implements sequence diagram widget used in the sequence diagram view.
86 public class SDWidget
extends ScrollView
implements SelectionListener
,
87 IPropertyChangeListener
, DisposeListener
, ITimeCompressionListener
{
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 * The frame to display in the sequence diagram widget.
96 protected Frame fFrame
;
98 * The overview image to display.
100 protected Image fOverView
= null;
102 * The zoom in menu item.
104 protected MenuItem fZoomIn
= null;
106 * The zoom out menu item.
108 protected MenuItem fZoomOut
= null;
110 * The sequence diagram selection provider.
112 protected SDWidgetSelectionProvider fSelProvider
= null;
114 * The current zoom value.
116 public float fZoomValue
= 1;
118 * The current zoomInMode (true for zoom in).
120 protected boolean fZoomInMode
= false;
122 * The current zoomOutMode (true for zoom out).
124 protected boolean fZoomOutMode
= false;
126 * The current list of selected graph nodes.
128 protected List
<GraphNode
> fSelectedNodeList
= null;
130 * Flag whether ctrl button is selected or not.
132 protected boolean fCtrlSelection
= false;
134 * A reference to the view site.
136 protected ViewPart fSite
= null;
138 * The current graph node (the last selected one).
140 public GraphNode fCurrentGraphNode
= null;
142 * The first graph node in list (multiple selection).
144 public GraphNode fListStart
= null;
146 * The previous graph node (multiple selection).
148 public List
<GraphNode
> fPrevList
= null;
150 * The time compression bar.
152 protected TimeCompressionBar fTimeBar
= null;
154 * The current diagram tool tip.
156 protected DiagramToolTip fToolTip
= null;
158 * The accessible object reference of view control.
160 protected Accessible fAccessible
= null;
162 * The current node for the tooltip to display.
164 protected GraphNode fToolTipNode
;
166 * The life line to drag and drop.
168 protected Lifeline fDragAndDrop
= null;
170 * The number of focused widgets.
172 protected int fFocusedWidget
= -1;
176 protected float fPrinterZoom
= 0;
178 * Y coordinate for printer.
180 protected int fPrinterY
= 0;
182 * X coordinate for printer.
184 protected int fPrinterX
= 0;
186 * Flag whether drag and drop is enabled or not.
188 protected boolean fIsDragAndDrop
= false;
190 * The x coordinate for drag.
192 protected int fDragX
= 0;
194 * The y coordinate for drag.
196 protected int fDragY
= 0;
200 protected boolean fReorderMode
= false;
202 * The collapse caret image.
204 protected Image fCollapaseCaretImg
= null;
206 * The arrow up caret image.
208 protected Image fArrowUpCaretImg
= null;
210 * The current caret image.
212 protected Image fCurrentCaretImage
= null;
214 * A sequence diagramm collapse provider (for collapsing graph nodes)
216 protected ISDCollapseProvider fCollapseProvider
= null;
218 * The insertion caret.
220 protected Caret fInsertionCartet
= null;
222 * The reorder list when in reorder mode.
224 protected List
<Lifeline
[]> fReorderList
= null;
226 * Flag to specify whether in printing mode or not.
228 protected boolean fIsPrinting
= false;
230 * A printer reference.
232 protected Printer fPrinter
= null;
234 * Flag whether shift was selected or not.
236 protected boolean fShiftSelection
= false;
238 * The scroll tooltip.
240 protected DiagramToolTip fScrollToolTip
= null;
242 * Timer for auto_scroll feature
244 protected AutoScroll fLocalAutoScroll
= null;
246 * TimerTask for auto_scroll feature !=null when auto scroll is running
248 protected Timer fLocalAutoScrollTimer
= null;
250 // ------------------------------------------------------------------------
252 // ------------------------------------------------------------------------
254 * Constructor for SDWidget.
255 * @param c The parent composite
258 public SDWidget(Composite c
, int s
) {
259 super(c
, s
| SWT
.NO_BACKGROUND
, true);
260 setOverviewEnabled(true);
261 fSelectedNodeList
= new ArrayList
<GraphNode
>();
262 fSelProvider
= new SDWidgetSelectionProvider();
263 SDViewPref
.getInstance().addPropertyChangeListener(this);
264 fToolTip
= new DiagramToolTip(getViewControl());
265 super.addDisposeListener(this);
267 fScrollToolTip
= new DiagramToolTip(c
);
268 getVerticalBar().addListener(SWT
.MouseUp
, new Listener() {
271 public void handleEvent(Event event
) {
272 fScrollToolTip
.hideToolTip();
276 fAccessible
= getViewControl().getAccessible();
278 fAccessible
.addAccessibleListener(new AccessibleAdapter() {
280 public void getName(AccessibleEvent e
) {
282 if (e
.childID
== 0) {
283 if (fToolTipNode
!= null) {
284 if (fToolTipNode
instanceof Lifeline
) {
285 Lifeline lifeline
= (Lifeline
) fToolTipNode
;
286 e
.result
= lifeline
.getToolTipText();
288 e
.result
= fToolTipNode
.getName() + getPostfixForTooltip(true);
292 if (getFocusNode() != null) {
293 if (getFocusNode() instanceof Lifeline
) {
294 e
.result
= MessageFormat
.format(Messages
.SequenceDiagram_LifelineNode
, new Object
[] { String
.valueOf(getFocusNode().getName()) });
296 if (getFocusNode() instanceof BaseMessage
) {
297 BaseMessage mes
= (BaseMessage
) getFocusNode();
298 if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() != null)) {
299 e
.result
= MessageFormat
.format(
300 Messages
.SequenceDiagram_MessageNode
,
301 new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()), String
.valueOf(mes
.getEndLifeline().getName()),
302 Integer
.valueOf(mes
.getEndOccurrence()) });
303 } else if ((mes
.getStartLifeline() == null) && (mes
.getEndLifeline() != null)) {
304 e
.result
= MessageFormat
.format(Messages
.SequenceDiagram_FoundMessageNode
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getEndLifeline().getName()), Integer
.valueOf(mes
.getEndOccurrence()) });
305 } else if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() == null)) {
306 e
.result
= MessageFormat
.format(Messages
.SequenceDiagram_LostMessageNode
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()) });
308 } else if (getFocusNode() instanceof BasicExecutionOccurrence
) {
309 BasicExecutionOccurrence exec
= (BasicExecutionOccurrence
) getFocusNode();
310 e
.result
= MessageFormat
.format(Messages
.SequenceDiagram_ExecutionOccurrenceWithParams
,
311 new Object
[] { String
.valueOf(exec
.getName()), String
.valueOf(exec
.getLifeline().getName()), Integer
.valueOf(exec
.getStartOccurrence()), Integer
.valueOf(exec
.getEndOccurrence()) });
319 fAccessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
321 public void getFocus(AccessibleControlEvent e
) {
322 if (fFocusedWidget
== -1) {
323 e
.childID
= ACC
.CHILDID_SELF
;
325 e
.childID
= fFocusedWidget
;
330 public void getRole(AccessibleControlEvent e
) {
332 case ACC
.CHILDID_SELF
:
333 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
336 e
.detail
= ACC
.ROLE_TOOLTIP
;
339 e
.detail
= ACC
.ROLE_LABEL
;
347 public void getState(AccessibleControlEvent e
) {
348 e
.detail
= ACC
.STATE_FOCUSABLE
;
349 if (e
.childID
== ACC
.CHILDID_SELF
) {
350 e
.detail
|= ACC
.STATE_FOCUSED
;
352 e
.detail
|= ACC
.STATE_SELECTABLE
;
353 if (e
.childID
== fFocusedWidget
) {
354 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
360 fInsertionCartet
= new Caret((Canvas
) getViewControl(), SWT
.NONE
);
361 fInsertionCartet
.setVisible(false);
363 fCollapaseCaretImg
= Activator
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_COLLAPSE_OBJ
);
364 fArrowUpCaretImg
= Activator
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_UP_OBJ
);
366 fReorderList
= new ArrayList
<Lifeline
[]>();
367 getViewControl().addTraverseListener(new LocalTraverseListener());
369 addTraverseListener(new LocalTraverseListener());
371 getViewControl().addFocusListener(new FocusListener() {
374 public void focusGained(FocusEvent e
) {
375 SDViewPref
.getInstance().setNoFocusSelection(false);
376 fCtrlSelection
= false;
377 fShiftSelection
= false;
382 public void focusLost(FocusEvent e
) {
383 SDViewPref
.getInstance().setNoFocusSelection(true);
389 // ------------------------------------------------------------------------
391 // ------------------------------------------------------------------------
394 * Sets the time compression bar.
396 * @param bar The time compression bar to set
398 public void setTimeBar(TimeCompressionBar bar
) {
401 fTimeBar
.addTimeCompressionListener(this);
406 * Resize the contents to insure the frame fit into the view
408 * @param frame the frame which will be drawn in the view
410 public void resizeContents(Frame frame
) {
411 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
412 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
413 resizeContents(width
, height
);
417 * The frame to render (the sequence diagram)
419 * @param theFrame the frame to display
420 * @param resetPosition boolean
422 public void setFrame(Frame theFrame
, boolean resetPosition
) {
423 fReorderList
.clear();
424 fSelectedNodeList
.clear();
425 fSelProvider
.setSelection(new StructuredSelection());
428 setContentsPos(0, 0);
429 resizeContents(fFrame
);
432 // prepare the old overview to be reused
433 if (fOverView
!= null) {
437 resizeContents(fFrame
);
441 * Returns the current Frame (the sequence diagram container)
445 public Frame
getFrame() {
450 * Returns the selection provider for the current sequence diagram
452 * @return the selection provider
454 public ISelectionProvider
getSelectionProvider() {
459 * Returns a list of selected graph nodes.
461 * @return a list of selected graph nodes.
463 public List
<GraphNode
> getSelection() {
464 return fSelectedNodeList
;
468 * Adds a graph node to the selected nodes list.
470 * @param node A graph node
472 public void addSelection(GraphNode node
) {
476 fSelectedNodeList
.add(node
);
477 node
.setSelected(true);
478 fCurrentGraphNode
= node
;
479 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
480 fSelProvider
.setSelection(selection
);
484 * Adds a list of node to the selected nodes list.
486 * @param list of graph nodes
488 public void addSelection(List
<GraphNode
> list
) {
489 // selectedNodeList.addAll(list);
490 for (int i
= 0; i
< list
.size(); i
++) {
491 if (!fSelectedNodeList
.contains(list
.get(i
))) {
492 fSelectedNodeList
.add(list
.get(i
));
493 list
.get(i
).setSelected(true);
496 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
497 fSelProvider
.setSelection(selection
);
501 * Removes a node from the selected nodes list.
503 * @param node to remove
505 public void removeSelection(GraphNode node
) {
506 fSelectedNodeList
.remove(node
);
507 node
.setSelected(false);
508 node
.setFocused(false);
509 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
510 fSelProvider
.setSelection(selection
);
514 * Removes a list of graph nodes from the selected nodes list.
516 * @param list of nodes to remove.
518 public void removeSelection(List
<GraphNode
> list
) {
519 fSelectedNodeList
.removeAll(list
);
520 for (int i
= 0; i
< list
.size(); i
++) {
521 list
.get(i
).setSelected(false);
522 list
.get(i
).setFocused(false);
524 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
525 fSelProvider
.setSelection(selection
);
529 * Clear the list of GraphNodes which must be drawn selected.
531 public void clearSelection() {
532 for (int i
= 0; i
< fSelectedNodeList
.size(); i
++) {
533 fSelectedNodeList
.get(i
).setSelected(false);
534 fSelectedNodeList
.get(i
).setFocused(false);
536 fCurrentGraphNode
= null;
537 fSelectedNodeList
.clear();
538 fSelProvider
.setSelection(new StructuredSelection());
544 * @param viewSite The view part to set
546 public void setSite(ViewPart viewSite
) {
548 fSite
.getSite().setSelectionProvider(fSelProvider
);
549 IContextService service
= (IContextService
) fSite
.getSite().getWorkbenchWindow().getService(IContextService
.class);
550 service
.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
551 service
.activateContext(IContextIds
.CONTEXT_ID_WINDOW
);
555 * Returns the GraphNode overView the mouse if any
557 * @return the current graph node
559 public GraphNode
getMouseOverNode() {
560 return fCurrentGraphNode
;
564 * Sets the zoom in mode.
567 * The mode value to set.
569 public void setZoomInMode(boolean value
) {
571 setZoomOutMode(false);
577 * Sets the zoom out mode.
580 * The mode value to set.
582 public void setZoomOutMode(boolean value
) {
584 setZoomInMode(false);
586 fZoomOutMode
= value
;
590 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
592 * @param node the GraphNode to move to
594 public void moveTo(GraphNode node
) {
604 * Moves the Sequence diagram to ensure the given node is visible
606 * @param node the GraphNode to move to
608 public void ensureVisible(GraphNode node
) {
612 int x
= Math
.round(node
.getX() * fZoomValue
);
613 int y
= Math
.round(node
.getY() * fZoomValue
);
614 int width
= Math
.round(node
.getWidth() * fZoomValue
);
615 int height
= Math
.round(node
.getHeight() * fZoomValue
);
616 if ((node
instanceof BaseMessage
) && (height
== 0)) {
617 int header
= Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
* 2 + Metrics
.getLifelineHeaderFontHeigth();
618 height
= -Math
.round((Metrics
.getMessagesSpacing() + header
) * fZoomValue
);
619 y
= y
+ Math
.round(Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
* fZoomValue
);
621 if (node
instanceof BasicExecutionOccurrence
) {
625 if (node
instanceof Lifeline
) {
627 height
= getVisibleHeight();
629 ensureVisible(x
, y
, width
, height
, SWT
.CENTER
, true);
634 * Returns the current zoom factor.
635 * @return the current zoom factor.
637 public float getZoomFactor() {
642 * Returns teh printer reference.
644 * @return the printer reference
646 public Printer
getPrinter() {
651 * Returns whether the widget is used for printing or not.
653 * @return whether the widget is used for printing or not
655 public boolean isPrinting() {
660 * Gets the overview image.
662 * @param rect Rectangle to include overview.
663 * @return the overview image
665 public Image
getOverview(Rectangle rect
) {
666 float oldzoom
= fZoomValue
;
667 if ((fOverView
!= null) && ((rect
.width
!= fOverView
.getBounds().width
) || (rect
.height
!= fOverView
.getBounds().height
))) {
671 if (fOverView
== null) {
672 int backX
= getContentsX();
673 int backY
= getContentsY();
674 setContentsPos(0, 0);
675 fOverView
= new Image(getDisplay(), rect
.width
, rect
.height
);
676 GC gcim
= new GC(fOverView
);
677 NGC context
= new NGC(this, gcim
);
678 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
679 fFrame
.draw(context
);
680 setContentsPos(backX
, backY
);
684 fZoomValue
= oldzoom
;
689 * Resets the zoom factor.
691 public void resetZoomFactor() {
692 int currentX
= Math
.round(getContentsX() / fZoomValue
);
693 int currentY
= Math
.round(getContentsY() / fZoomValue
);
695 if (fTimeBar
!= null && !fTimeBar
.isDisposed()) {
696 fTimeBar
.setZoom(fZoomValue
);
700 setContentsPos(currentX
, currentY
);
704 * Enable or disable the lifeline reodering using Drag and Drop
706 * @param mode - true to enable false otherwise
708 public void setReorderMode(boolean mode
) {
713 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
714 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
716 * @return - the re-odered sequence
718 public List
<Lifeline
[]> getLifelineReoderList() {
723 * Sets the focus on given graph node (current node).
726 * The graph node to focus on.
728 public void setFocus(GraphNode node
) {
732 if (fCurrentGraphNode
!= null) {
733 fCurrentGraphNode
.setFocused(false);
735 fCurrentGraphNode
= node
;
736 node
.setFocused(true);
742 * Returns the graph node focused on.
744 * @return the current graph node
746 public GraphNode
getFocusNode() {
747 return fCurrentGraphNode
;
751 * Method to traverse right.
753 public void traverseRight() {
754 Object selectedNode
= getFocusNode();
755 if (selectedNode
== null) {
758 GraphNode node
= null;
759 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
760 node
= fFrame
.getCalledMessage((BaseMessage
) selectedNode
);
762 if (selectedNode
instanceof BasicExecutionOccurrence
) {
763 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
765 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
766 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
767 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
< fFrame
.lifeLinesCount() - 1)) {
768 node
= fFrame
.getLifeline(i
+ 1);
780 * Method to traverse left.
782 public void traverseLeft() {
783 Object selectedNode
= getFocusNode();
784 GraphNode node
= null;
785 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
786 node
= fFrame
.getCallerMessage((BaseMessage
) selectedNode
);
788 if (selectedNode
instanceof BasicExecutionOccurrence
) {
789 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
792 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
793 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
795 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
796 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
> 0)) {
797 node
= fFrame
.getLifeline(i
- 1);
801 if ((fFrame
.lifeLinesCount() > 0) && (node
== null)) {
802 node
= fFrame
.getLifeline(0);
812 * Method to traverse up.
814 public void traverseUp() {
815 Object selectedNode
= getFocusNode();
816 if (selectedNode
== null) {
819 GraphNode node
= null;
820 if (selectedNode
instanceof BaseMessage
) {
821 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
822 } else if (selectedNode
instanceof Lifeline
) {
823 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
824 if (!(node
instanceof Lifeline
)) {
827 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
828 node
= fFrame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
830 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
833 if ((node
== null) && (selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
834 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
844 * Method to traverse down.
846 public void traverseDown() {
847 Object selectedNode
= getFocusNode();
848 if (selectedNode
== null) {
852 if (selectedNode
instanceof BaseMessage
) {
853 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
854 } else if (selectedNode
instanceof Lifeline
) {
855 // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
856 node
= fFrame
.getFirstExecution((Lifeline
) selectedNode
);
857 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
858 node
= fFrame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
870 * Method to traverse home.
872 public void traverseHome() {
873 Object selectedNode
= getFocusNode();
874 if (selectedNode
== null) {
877 GraphNode node
= null;
879 if (selectedNode
instanceof BaseMessage
) {
880 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
881 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
883 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
885 } else if (selectedNode
instanceof Lifeline
) {
886 node
= fFrame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
887 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
888 node
= fFrame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
890 if (fFrame
.lifeLinesCount() > 0) {
891 Lifeline lifeline
= fFrame
.getLifeline(0);
892 node
= fFrame
.getNextLifelineMessage(lifeline
, null);
903 * Method to traverse to the end.
905 public void traverseEnd() {
906 Object selectedNode
= getFocusNode();
907 if (selectedNode
== null) {
911 if (selectedNode
instanceof BaseMessage
) {
912 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
913 } else if (selectedNode
instanceof Lifeline
) {
914 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
915 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
916 node
= fFrame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
918 if (fFrame
.lifeLinesCount() > 0) {
919 Lifeline lifeline
= fFrame
.getLifeline(0);
920 node
= fFrame
.getPrevLifelineMessage(lifeline
, null);
933 * Method to print UI.
935 * @param sdPrintDialog the sequence diagram printer dialog.
937 public void printUI(SDPrintDialogUI sdPrintDialog
) {
938 PrinterData data
= sdPrintDialog
.getPrinterData();
940 if ((data
== null) || (fFrame
== null)) {
944 fPrinter
= new Printer(data
);
946 String jobName
= MessageFormat
.format(Messages
.SequenceDiagram_plus
, new Object
[] { String
.valueOf(fSite
.getContentDescription()), String
.valueOf(fFrame
.getName()) });
947 fPrinter
.startJob(jobName
);
949 GC gc
= new GC(fPrinter
);
950 // Frame.setUserPref(SDViewPref.getInstance());
952 float lastZoom
= fZoomValue
;
954 Rectangle area
= getClientArea();
958 NGC context
= new NGC(this, gcim
);
960 // Set the metrics to use for lifeline text and message text
961 // using the Graphical Context
962 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
963 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
964 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
965 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
966 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
968 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
969 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
970 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
971 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
973 int messageFontHeight
= 0;
974 if (syncMessFontH
> syncMessRetFontH
) {
975 messageFontHeight
= syncMessFontH
;
977 messageFontHeight
= syncMessRetFontH
;
979 if (messageFontHeight
< asyncMessFontH
) {
980 messageFontHeight
= asyncMessFontH
;
982 if (messageFontHeight
< asyncMessRetFontH
) {
983 messageFontHeight
= asyncMessRetFontH
;
985 Metrics
.setMessageFontHeight(messageFontHeight
);
986 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
988 int width
= Math
.round((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
989 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
990 if (width
< area
.width
) {
993 if (height
< area
.height
) {
994 height
= area
.height
;
996 resizeContents(width
, height
);
998 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
999 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1000 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1001 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1002 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1003 gcim
.setLineWidth(1);
1005 fPrinter
.startPage();
1006 fZoomValue
= lastZoom
;
1008 int restoreX
= getContentsX();
1009 int restoreY
= getContentsY();
1011 float zh
= sdPrintDialog
.getStepY() * sdPrintDialog
.getZoomFactor();
1012 float zw
= sdPrintDialog
.getStepX() * sdPrintDialog
.getZoomFactor();
1014 float zoomValueH
= fPrinter
.getClientArea().height
/ zh
;
1015 float zoomValueW
= fPrinter
.getClientArea().width
/ zw
;
1016 if (zoomValueH
> zoomValueW
) {
1017 fPrinterZoom
= zoomValueH
;
1019 fPrinterZoom
= zoomValueW
;
1022 if (sdPrintDialog
.printSelection()) {
1023 int[] pagesList
= sdPrintDialog
.getPageList();
1025 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1026 printPage(pagesList
[pageIndex
], sdPrintDialog
, context
);
1028 } else if (sdPrintDialog
.printAll()) {
1029 for (int pageIndex
= 1; pageIndex
<= sdPrintDialog
.maxNumOfPages(); pageIndex
++) {
1030 printPage(pageIndex
, sdPrintDialog
, context
);
1032 } else if (sdPrintDialog
.printCurrent()) {
1033 printPage(getContentsX(), getContentsY(), sdPrintDialog
, context
, 1);
1034 } else if (sdPrintDialog
.printRange()) {
1035 for (int pageIndex
= sdPrintDialog
.getFrom(); pageIndex
<= sdPrintDialog
.maxNumOfPages() && pageIndex
<= sdPrintDialog
.getTo(); pageIndex
++) {
1036 printPage(pageIndex
, sdPrintDialog
, context
);
1041 fIsPrinting
= false;
1046 fZoomValue
= lastZoom
;
1048 setContentsPos(restoreX
, restoreY
);
1054 public void print() {
1055 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1057 if (sdPrinter
.open() != 0) {
1060 } catch (Exception e
) {
1061 Activator
.getDefault().logError("Error creating image", e
); //$NON-NLS-1$
1064 printUI(sdPrinter
.getDialogUI());
1068 * Method to print a page.
1070 * @param pageNum The page number
1071 * @param pd The sequence diagram print dialog
1072 * @param context The graphical context
1074 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1075 int j
= pageNum
/ pd
.getNbRow();
1076 int i
= pageNum
% pd
.getNbRow();
1086 i
= (int) (i
* pd
.getStepX());
1087 j
= (int) (j
* pd
.getStepY());
1089 printPage(i
, j
, pd
, context
, pageNum
);
1095 * Method to print page ranges.
1102 * The sequence diagram print dialog
1104 * The graphical context
1108 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1109 fIsPrinting
= false;
1110 int pageNumFontZoom
= fPrinter
.getClientArea().height
/ getVisibleHeight();
1113 setContentsPos(i
, j
);
1116 float lastZoom
= fZoomValue
;
1117 fZoomValue
= fPrinterZoom
* lastZoom
;
1119 fFrame
.draw(context
);
1121 fZoomValue
= pageNumFontZoom
;
1122 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1123 String currentPageNum
= String
.valueOf(pageNum
);
1124 int ii
= context
.textExtent(currentPageNum
);
1125 int jj
= context
.getCurrentFontHeight();
1126 // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1127 // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
1128 fZoomValue
= fPrinterZoom
* lastZoom
;
1129 context
.drawText(currentPageNum
, Math
.round(fPrinterX
+ getVisibleWidth() / fPrinterZoom
- ii
/ fPrinterZoom
), Math
.round(fPrinterY
+ getVisibleHeight() / fPrinterZoom
- jj
/ fPrinterZoom
), false);
1130 fIsPrinting
= false;
1131 fZoomValue
= lastZoom
;
1135 * Sets the collapse provider.
1137 * @param provider The collapse provider to set
1139 protected void setCollapseProvider(ISDCollapseProvider provider
) {
1140 fCollapseProvider
= provider
;
1145 * Checks for focus of children.
1147 * @param children Control to check
1148 * @return true if child is on focus else false
1150 protected boolean checkFocusOnChilds(Control children
) {
1151 if (children
instanceof Composite
) {
1152 Control
[] child
= ((Composite
) children
).getChildren();
1153 for (int i
= 0; i
< child
.length
; i
++) {
1154 if (child
[i
].isFocusControl()) {
1157 checkFocusOnChilds(child
[i
]);
1164 * A post action for a tooltip (before displaying).
1166 * @param accessible true if accessible else false
1167 * @return the tooltip text.
1169 protected String
getPostfixForTooltip(boolean accessible
) {
1170 StringBuffer postfix
= new StringBuffer();
1171 // Determine if the tooltip must show the time difference between the current mouse position and
1172 // the last selected graphNode
1173 if ((fCurrentGraphNode
!= null) &&
1174 (fCurrentGraphNode
instanceof ITimeRange
) &&
1175 (fToolTipNode
instanceof ITimeRange
) &&
1176 (fCurrentGraphNode
!= fToolTipNode
) &&
1177 ((ITimeRange
) fToolTipNode
).hasTimeInfo() &&
1178 ((ITimeRange
) fCurrentGraphNode
).hasTimeInfo()) {
1179 postfix
.append(" -> "); //$NON-NLS-1$
1180 postfix
.append(fCurrentGraphNode
.getName());
1181 postfix
.append("\n"); //$NON-NLS-1$
1182 postfix
.append(Messages
.SequenceDiagram_Delta
);
1183 postfix
.append(" "); //$NON-NLS-1$
1185 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1186 ITmfTimestamp firstTime
= ((ITimeRange
) fCurrentGraphNode
).getEndTime();
1187 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1188 ITmfTimestamp delta
= lastTime
.getDelta(firstTime
);
1189 postfix
.append(delta
.toString());
1192 if ((fToolTipNode
instanceof ITimeRange
) && ((ITimeRange
) fToolTipNode
).hasTimeInfo()) {
1193 postfix
.append("\n"); //$NON-NLS-1$
1194 ITmfTimestamp firstTime
= ((ITimeRange
) fToolTipNode
).getStartTime();
1195 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1197 if (firstTime
!= null) {
1198 if (lastTime
!= null && firstTime
.compareTo(lastTime
, true) != 0) {
1199 postfix
.append("start: "); //$NON-NLS-1$
1200 postfix
.append(firstTime
.toString());
1201 postfix
.append("\n"); //$NON-NLS-1$
1202 postfix
.append("end: "); //$NON-NLS-1$
1203 postfix
.append(lastTime
.toString());
1204 postfix
.append("\n"); //$NON-NLS-1$
1206 postfix
.append(firstTime
.toString());
1209 else if (lastTime
!= null) {
1210 postfix
.append(lastTime
.toString());
1214 return postfix
.toString();
1218 * Sets a new focused widget.
1220 * @param newFocusShape A new focus shape.
1222 protected void setFocus(int newFocusShape
) {
1223 fFocusedWidget
= newFocusShape
;
1224 if (fFocusedWidget
== -1) {
1225 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
1227 getViewControl().getAccessible().setFocus(fFocusedWidget
);
1232 * Highlight the given GraphNode<br>
1233 * The GraphNode is then displayed using the system default selection color
1235 * @param node the GraphNode to highlight
1237 protected void performSelection(GraphNode node
) {
1238 if ((fCtrlSelection
) || (fShiftSelection
)) {
1240 if (fSelectedNodeList
.contains(node
)) {
1241 removeSelection(node
);
1257 * Returns a draw buffer image.
1259 * @return a Image containing the draw buffer.
1261 protected Image
getDrawBuffer() {
1264 Rectangle area
= getClientArea();
1265 Image dbuffer
= null;
1269 dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
1270 } catch (Exception e
) {
1271 Activator
.getDefault().logError("Error creating image", e
); //$NON-NLS-1$
1274 gcim
= new GC(dbuffer
);
1276 NGC context
= new NGC(this, gcim
);
1278 // Set the metrics to use for lifeline text and message text
1279 // using the Graphical Context
1280 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1281 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1282 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1283 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1284 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1286 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
1287 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
1288 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
1289 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
1291 int messageFontHeight
= 0;
1292 if (syncMessFontH
> syncMessRetFontH
) {
1293 messageFontHeight
= syncMessFontH
;
1295 messageFontHeight
= syncMessRetFontH
;
1297 if (messageFontHeight
< asyncMessFontH
) {
1298 messageFontHeight
= asyncMessFontH
;
1300 if (messageFontHeight
< asyncMessRetFontH
) {
1301 messageFontHeight
= asyncMessRetFontH
;
1303 Metrics
.setMessageFontHeight(messageFontHeight
);
1304 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1306 int width
= (int) ((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
1307 int height
= (int) ((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1309 resizeContents(width
, height
);
1311 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1312 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1313 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1314 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1315 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1316 gcim
.setLineWidth(1);
1318 fFrame
.draw(context
);
1319 if (fDragAndDrop
!= null) {
1320 Lifeline node
= fDragAndDrop
;
1321 boolean isSelected
= fDragAndDrop
.isSelected();
1322 boolean hasFocus
= fDragAndDrop
.hasFocus();
1323 node
.setSelected(false);
1324 node
.setFocused(false);
1325 node
.draw(context
, fDragX
, fDragY
);
1326 node
.setSelected(isSelected
);
1327 node
.setFocused(hasFocus
);
1335 protected void keyPressedEvent(KeyEvent event
) {
1336 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1337 Control
[] child
= getParent().getChildren();
1338 for (int i
= 0; i
< child
.length
; i
++) {
1339 if ((child
[i
].isFocusControl())&& (!(child
[i
] instanceof ScrollView
))) {
1340 getViewControl().setFocus();
1347 if (event
.keyCode
== SWT
.CTRL
) {
1348 fCtrlSelection
= true;
1350 if (event
.keyCode
== SWT
.SHIFT
) {
1351 fShiftSelection
= true;
1352 fPrevList
= new ArrayList
<GraphNode
>();
1353 fPrevList
.addAll(getSelection());
1356 GraphNode prevNode
= getFocusNode();
1358 if (event
.keyCode
== SWT
.ARROW_RIGHT
) {
1362 if (event
.keyCode
== SWT
.ARROW_LEFT
) {
1366 if (event
.keyCode
== SWT
.ARROW_DOWN
) {
1370 if (event
.keyCode
== SWT
.ARROW_UP
) {
1374 if (event
.keyCode
== SWT
.HOME
) {
1378 if (event
.keyCode
== SWT
.END
) {
1382 if ((!fShiftSelection
) && (!fCtrlSelection
)) {
1383 fListStart
= fCurrentGraphNode
;
1386 if (event
.character
== ' ') {
1387 performSelection(fCurrentGraphNode
);
1388 if (!fShiftSelection
) {
1389 fListStart
= fCurrentGraphNode
;
1393 if ((fShiftSelection
) && (prevNode
!= getFocusNode())) {
1395 addSelection(fPrevList
);
1396 addSelection(fFrame
.getNodeList(fListStart
, getFocusNode()));
1397 if (getFocusNode() instanceof Lifeline
) {
1398 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1400 ensureVisible(getFocusNode());
1402 } else if ((!fCtrlSelection
) && (!fShiftSelection
)) {
1405 if (getFocusNode() != null) {
1406 addSelection(getFocusNode());
1408 if (getFocusNode() instanceof Lifeline
) {
1409 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1411 ensureVisible(getFocusNode());
1416 if (fCurrentGraphNode
!= null) {
1417 fCurrentGraphNode
.setFocused(true);
1421 if ((event
.character
== ' ') && ((fZoomInMode
) || (fZoomOutMode
))) {
1422 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue
);
1423 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue
);
1425 if (fZoomValue
< 64) {
1426 fZoomValue
= fZoomValue
* (float) 1.25;
1429 fZoomValue
= fZoomValue
/ (float) 1.25;
1431 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1432 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1433 setContentsPos(x
, y
);
1434 if (fTimeBar
!= null) {
1435 fTimeBar
.setZoom(fZoomValue
);
1437 // redraw also resize the scrollView content
1443 protected void keyReleasedEvent(KeyEvent event
) {
1445 if (event
.keyCode
== SWT
.CTRL
) {
1446 fCtrlSelection
= false;
1448 if (event
.keyCode
== SWT
.SHIFT
) {
1449 fShiftSelection
= false;
1451 super.keyReleasedEvent(event
);
1456 public boolean isFocusControl() {
1457 Control
[] child
= getChildren();
1458 for (int i
= 0; i
< child
.length
; i
++) {
1459 if (child
[i
].isFocusControl()) {
1462 checkFocusOnChilds(child
[i
]);
1468 public boolean setContentsPos(int x
, int y
) {
1478 if (fFrame
== null) {
1481 if (localX
+ getVisibleWidth() > getContentsWidth()) {
1482 localX
= getContentsWidth() - getVisibleWidth();
1484 if (localY
+ getVisibleHeight() > getContentsHeight()) {
1485 localY
= getContentsHeight() - getVisibleHeight();
1487 int x1
= Math
.round(localX
/ fZoomValue
);
1488 int y2
= Math
.round(localY
/ fZoomValue
);
1489 int width
= Math
.round(getVisibleWidth() / fZoomValue
);
1490 int height
= Math
.round(getVisibleHeight() / fZoomValue
);
1491 fFrame
.updateIndex(x1
, y2
, width
, height
);
1493 if (fInsertionCartet
!= null && fInsertionCartet
.isVisible()) {
1494 fInsertionCartet
.setVisible(false);
1497 return super.setContentsPos(localX
, localY
);
1501 protected void contentsMouseHover(MouseEvent event
) {
1502 GraphNode graphNode
= null;
1503 if (fFrame
!= null) {
1504 int x
= Math
.round(event
.x
/ fZoomValue
);
1505 int y
= Math
.round(event
.y
/ fZoomValue
);
1506 graphNode
= fFrame
.getNodeAt(x
, y
);
1507 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
1508 fToolTipNode
= graphNode
;
1509 String postfix
= getPostfixForTooltip(true);
1510 if (graphNode
instanceof Lifeline
) {
1511 Lifeline lifeline
= (Lifeline
) graphNode
;
1512 fToolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
1515 fToolTip
.showToolTip(graphNode
.getName() + postfix
);
1519 fToolTip
.hideToolTip();
1525 protected void contentsMouseMoveEvent(MouseEvent e
) {
1526 fScrollToolTip
.hideToolTip();
1527 fToolTip
.hideToolTip();
1528 // super.contentsMouseMoveEvent(e);
1529 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1530 Control
[] child
= getParent().getChildren();
1531 for (int i
= 0; i
< child
.length
; i
++) {
1532 if ((child
[i
].isFocusControl()) && (!(child
[i
] instanceof ScrollView
))) {
1533 getViewControl().setFocus();
1540 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((fDragAndDrop
!= null) || fIsDragAndDrop
) && (fReorderMode
|| fCollapseProvider
!= null)) {
1541 fIsDragAndDrop
= false;
1542 if (fCurrentGraphNode
instanceof Lifeline
) {
1543 fDragAndDrop
= (Lifeline
) fCurrentGraphNode
;
1545 if (fDragAndDrop
!= null) {
1548 if (e
.x
> getContentsX() + getVisibleWidth()) {
1549 dx
= e
.x
- (getContentsX() + getVisibleWidth());
1550 } else if (e
.x
< getContentsX()) {
1551 dx
= -getContentsX() + e
.x
;
1553 if (e
.y
> getContentsY() + getVisibleHeight()) {
1554 dy
= e
.y
- (getContentsY() + getVisibleHeight());
1555 } else if (e
.y
< getContentsY()) {
1556 dy
= -getContentsY() + e
.y
;
1560 if (dx
!= 0 || dy
!= 0) {
1561 if (fLocalAutoScroll
== null) {
1562 if (fLocalAutoScrollTimer
== null) {
1563 fLocalAutoScrollTimer
= new Timer(true);
1565 fLocalAutoScroll
= new AutoScroll(this, dx
, dy
);
1566 fLocalAutoScrollTimer
.schedule(fLocalAutoScroll
, 0, 75);
1568 fLocalAutoScroll
.fDeltaX
= dx
;
1569 fLocalAutoScroll
.fDeltaY
= dy
;
1571 } else if (fLocalAutoScroll
!= null) {
1572 fLocalAutoScroll
.cancel();
1573 fLocalAutoScroll
= null;
1575 fDragX
= Math
.round(e
.x
/ fZoomValue
);
1576 fDragY
= Math
.round(e
.y
/ fZoomValue
);
1578 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1579 if ((node
!= null) && (node
!= fDragAndDrop
)) {
1582 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
1583 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
1584 int x
= node
.getX();
1585 int width
= node
.getWidth();
1586 if (fFrame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
) {
1587 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * fZoomValue
));
1589 y
= Math
.round(height
* fZoomValue
);
1592 if (fFrame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
)) {
1593 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * fZoomValue
));
1595 y1
= Math
.round(height
* fZoomValue
);
1598 int rx
= Math
.round(x
* fZoomValue
);
1600 fInsertionCartet
.setVisible(true);
1601 if ((fInsertionCartet
.getImage() != null) && (!fInsertionCartet
.getImage().isDisposed())) {
1602 fInsertionCartet
.getImage().dispose();
1604 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* fZoomValue
)) >= e
.x
) {
1605 if (fCollapseProvider
!= null) {
1606 ImageData data
= fCollapaseCaretImg
.getImageData();
1607 data
= data
.scaledTo(Math
.round(fCollapaseCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fCollapaseCaretImg
.getBounds().height
* fZoomValue
));
1608 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1609 fInsertionCartet
.setImage(fCurrentCaretImage
);
1610 fInsertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y
);
1612 } else if (fReorderMode
) {
1614 if (node
.getIndex() > 1 && fFrame
.getLifeline(node
.getIndex() - 2) == fDragAndDrop
) {
1617 ImageData data
= fArrowUpCaretImg
.getImageData();
1618 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1619 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1620 fInsertionCartet
.setImage(fCurrentCaretImage
);
1621 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y1
);
1623 if (node
.getIndex() < fFrame
.lifeLinesCount() && fFrame
.getLifeline(node
.getIndex()) == fDragAndDrop
) {
1626 ImageData data
= fArrowUpCaretImg
.getImageData();
1627 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1628 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1629 fInsertionCartet
.setImage(fCurrentCaretImage
);
1630 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2 + 1, y1
);
1634 fInsertionCartet
.setVisible(false);
1638 super.contentsMouseMoveEvent(e
);
1643 protected void contentsMouseUpEvent(MouseEvent event
) {
1644 // Just in case the diagram highlight a time compression region
1645 // this region need to be released when clicking everywhere
1646 fInsertionCartet
.setVisible(false);
1647 if (fDragAndDrop
!= null) {
1648 if ((fOverView
!= null) && (!fOverView
.isDisposed())) {
1649 fOverView
.dispose();
1652 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1654 int rx
= Math
.round(node
.getX() * fZoomValue
);
1655 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * fZoomValue
)) >= event
.x
) {
1656 if ((fCollapseProvider
!= null) && (fDragAndDrop
!= node
)) {
1657 fCollapseProvider
.collapseTwoLifelines(fDragAndDrop
, node
);
1659 } else if (rx
< event
.x
) {
1660 fFrame
.insertLifelineAfter(fDragAndDrop
, node
);
1661 if (node
.getIndex() < fFrame
.lifeLinesCount()) {
1662 Lifeline temp
[] = { fDragAndDrop
, fFrame
.getLifeline(node
.getIndex()) };
1663 fReorderList
.add(temp
);
1665 Lifeline temp
[] = { fDragAndDrop
, null };
1666 fReorderList
.add(temp
);
1669 fFrame
.insertLifelineBefore(fDragAndDrop
, node
);
1670 Lifeline temp
[] = { fDragAndDrop
, node
};
1671 fReorderList
.add(temp
);
1675 fDragAndDrop
= null;
1677 if (fFrame
== null) {
1680 fFrame
.resetTimeCompression();
1682 // reset auto scroll if it's engaged
1683 if (fLocalAutoScroll
!= null) {
1684 fLocalAutoScroll
.cancel();
1685 fLocalAutoScroll
= null;
1687 super.contentsMouseUpEvent(event
);
1691 protected void contentsMouseDownEvent(MouseEvent event
) {
1692 if (fCurrentGraphNode
!= null) {
1693 fCurrentGraphNode
.setFocused(false);
1696 // Just in case the diagram highlight a time compression region
1697 // this region need to be released when clicking everywhere
1698 if (fFrame
== null) {
1702 fFrame
.resetTimeCompression();
1704 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
1705 fCtrlSelection
= true;
1707 fCtrlSelection
= false;
1710 if (((fZoomInMode
) || (fZoomOutMode
)) && (event
.button
== 1)) {
1711 int cx
= Math
.round(event
.x
/ fZoomValue
);
1712 int cy
= Math
.round(event
.y
/ fZoomValue
);
1714 if (fZoomValue
< 64) {
1715 fZoomValue
= fZoomValue
* (float) 1.25;
1718 fZoomValue
= fZoomValue
/ (float) 1.25;
1720 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1721 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1722 setContentsPos(x
, y
);
1723 if (fTimeBar
!= null) {
1724 fTimeBar
.setZoom(fZoomValue
);
1726 // redraw also resize the scrollView content
1728 } else {// if (event.button ==1)
1729 GraphNode node
= null;
1730 int x
= Math
.round(event
.x
/ fZoomValue
);
1731 int y
= Math
.round(event
.y
/ fZoomValue
);
1732 node
= fFrame
.getNodeAt(x
, y
);
1734 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
1735 if (!fShiftSelection
) {
1738 if (fShiftSelection
) {
1740 addSelection(fFrame
.getNodeList(fListStart
, node
));
1742 performSelection(node
);
1744 fCurrentGraphNode
= node
;
1746 node
.setFocused(true);
1751 if (fDragAndDrop
== null) {
1752 super.contentsMouseDownEvent(event
);
1754 fIsDragAndDrop
= (event
.button
== 1);
1759 * TimerTask for auto scroll feature.
1761 protected static class AutoScroll
extends TimerTask
{
1771 * Field sequence diagram reference.
1773 public SDWidget fSdWidget
;
1776 * Constructor for AutoScroll.
1777 * @param sv sequence diagram widget reference
1781 public AutoScroll(SDWidget sv
, int dx
, int dy
) {
1789 Display
.getDefault().asyncExec(new Runnable() {
1792 if (fSdWidget
.isDisposed()) {
1795 fSdWidget
.fDragX
+= fDeltaX
;
1796 fSdWidget
.fDragY
+= fDeltaY
;
1797 fSdWidget
.scrollBy(fDeltaX
, fDeltaY
);
1804 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1805 if (fFrame
== null) {
1806 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1807 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1811 // Frame.setUserPref(SDViewPref.getInstance());
1812 SDViewPref
.getInstance();
1814 Rectangle area
= getClientArea();
1815 Image dbuffer
= getDrawBuffer();
1816 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1819 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1820 } catch (Exception e
) {
1821 Activator
.getDefault().logError("Error drawin content", e
); //$NON-NLS-1$
1824 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * fZoomValue
));
1825 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * fZoomValue
));
1826 if ((fTimeBar
!= null) && (fFrame
.hasTimeInfo())) {
1827 fTimeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1828 fTimeBar
.setContentsPos(getContentsX(), getContentsY());
1832 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1833 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1834 if (yRatio
> xRatio
) {
1835 setOverviewSize((int) (getVisibleHeight() * 0.75));
1837 setOverviewSize((int) (getVisibleWidth() * 0.75));
1842 public void widgetDefaultSelected(SelectionEvent event
) {
1846 public void widgetSelected(SelectionEvent event
) {
1847 if (event
.widget
== fZoomIn
) {
1848 fZoomValue
= fZoomValue
* 2;
1849 } else if (event
.widget
== fZoomOut
) {
1850 fZoomValue
= fZoomValue
/ 2;
1856 * Called when property changed occurs in the preference page. "PREFOK" is
1857 * fired when the user press the ok or apply button
1860 public void propertyChange(PropertyChangeEvent e
) {
1861 if (fFrame
!= null && !isDisposed()) {
1862 fFrame
.resetTimeCompression();
1864 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1866 // Prepare the overview to be reused for the new
1867 // settings (especially the colors)
1868 if (fOverView
!= null) {
1869 fOverView
.dispose();
1877 public void widgetDisposed(DisposeEvent e
) {
1878 if (fOverView
!= null) {
1879 fOverView
.dispose();
1881 super.removeDisposeListener(this);
1882 if ((fCurrentCaretImage
!= null) && (!fCurrentCaretImage
.isDisposed())) {
1883 fCurrentCaretImage
.dispose();
1885 if ((fArrowUpCaretImg
!= null) && (!fArrowUpCaretImg
.isDisposed())) {
1886 fArrowUpCaretImg
.dispose();
1888 if ((fCollapaseCaretImg
!= null) && (!fCollapaseCaretImg
.isDisposed())) {
1889 fCollapaseCaretImg
.dispose();
1891 SDViewPref
.getInstance().removePropertyChangeListener(this);
1892 LoadersManager lm
= LoadersManager
.getInstance();
1893 if (fSite
instanceof SDView
) {
1894 ((SDView
) fSite
).resetProviders();
1896 lm
.resetLoader(((SDView
) fSite
).getViewSite().getId());
1902 protected void drawOverview(GC gc
, Rectangle r
) {
1903 float oldzoom
= fZoomValue
;
1904 if (getContentsWidth() > getContentsHeight()) {
1905 fZoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
1907 fZoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
1909 if ((fOverView
!= null) && ((r
.width
!= fOverView
.getBounds().width
) || (r
.height
!= fOverView
.getBounds().height
))) {
1910 fOverView
.dispose();
1913 if (fOverView
== null) {
1914 int backX
= getContentsX();
1915 int backY
= getContentsY();
1916 setContentsPos(0, 0);
1917 fOverView
= new Image(getDisplay(), r
.width
, r
.height
);
1918 GC gcim
= new GC(fOverView
);
1919 NGC context
= new NGC(this, gcim
);
1920 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1921 fFrame
.draw(context
);
1922 setContentsPos(backX
, backY
);
1926 if ((fOverView
!= null) && (r
.width
== fOverView
.getBounds().width
) && (r
.height
== fOverView
.getBounds().height
)) {
1927 gc
.drawImage(fOverView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
1930 fZoomValue
= oldzoom
;
1932 super.drawOverview(gc
, r
);
1936 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
1937 fFrame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
1938 ensureVisible(lifeline
);
1939 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
1940 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
1941 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
1947 public int getVisibleWidth() {
1949 return fPrinter
.getClientArea().width
;
1951 return super.getVisibleWidth();
1955 public int getVisibleHeight() {
1957 return fPrinter
.getClientArea().height
;
1959 return super.getVisibleHeight();
1963 public int contentsToViewX(int x
) {
1965 int v
= Math
.round(fPrinterX
* fPrinterZoom
);
1968 return x
- getContentsX();
1972 public int contentsToViewY(int y
) {
1974 int v
= Math
.round(fPrinterY
* fPrinterZoom
);
1977 return y
- getContentsY();
1981 public int getContentsX() {
1983 return Math
.round(fPrinterX
* fPrinterZoom
);
1985 return super.getContentsX();
1989 public int getContentsY() {
1991 return Math
.round(fPrinterY
* fPrinterZoom
);
1993 return super.getContentsY();
1997 * Traverse Listener implementation.
1999 protected static class LocalTraverseListener
implements TraverseListener
{
2001 public void keyTraversed(TraverseEvent e
) {
2002 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {