1 /**********************************************************************
2 * Copyright (c) 2005, 2014 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
.tracecompass
.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
.swt
.SWT
;
27 import org
.eclipse
.swt
.accessibility
.ACC
;
28 import org
.eclipse
.swt
.accessibility
.Accessible
;
29 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
30 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
31 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
32 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
33 import org
.eclipse
.swt
.events
.DisposeEvent
;
34 import org
.eclipse
.swt
.events
.DisposeListener
;
35 import org
.eclipse
.swt
.events
.FocusEvent
;
36 import org
.eclipse
.swt
.events
.FocusListener
;
37 import org
.eclipse
.swt
.events
.KeyEvent
;
38 import org
.eclipse
.swt
.events
.MouseEvent
;
39 import org
.eclipse
.swt
.events
.SelectionEvent
;
40 import org
.eclipse
.swt
.events
.SelectionListener
;
41 import org
.eclipse
.swt
.events
.TraverseEvent
;
42 import org
.eclipse
.swt
.events
.TraverseListener
;
43 import org
.eclipse
.swt
.graphics
.GC
;
44 import org
.eclipse
.swt
.graphics
.Image
;
45 import org
.eclipse
.swt
.graphics
.ImageData
;
46 import org
.eclipse
.swt
.graphics
.Rectangle
;
47 import org
.eclipse
.swt
.printing
.Printer
;
48 import org
.eclipse
.swt
.printing
.PrinterData
;
49 import org
.eclipse
.swt
.widgets
.Canvas
;
50 import org
.eclipse
.swt
.widgets
.Caret
;
51 import org
.eclipse
.swt
.widgets
.Composite
;
52 import org
.eclipse
.swt
.widgets
.Control
;
53 import org
.eclipse
.swt
.widgets
.Display
;
54 import org
.eclipse
.swt
.widgets
.Event
;
55 import org
.eclipse
.swt
.widgets
.Listener
;
56 import org
.eclipse
.swt
.widgets
.MenuItem
;
57 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
58 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
59 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
60 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
61 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
62 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
63 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.SDPrintDialog
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.SDPrintDialogUI
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDCollapseProvider
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
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.
98 * The overview image to display.
100 private Image fOverView
= null;
102 * The zoom in menu item.
104 private MenuItem fZoomIn
= null;
106 * The zoom out menu item.
108 private MenuItem fZoomOut
= null;
110 * The sequence diagram selection provider.
112 private SDWidgetSelectionProvider fSelProvider
= null;
114 * The current zoom value.
116 private float fZoomValue
= 1;
118 * The current zoomInMode (true for zoom in).
120 private boolean fZoomInMode
= false;
122 * The current zoomOutMode (true for zoom out).
124 private boolean fZoomOutMode
= false;
126 * The current list of selected graph nodes.
128 private List
<GraphNode
> fSelectedNodeList
= null;
130 * Flag whether ctrl button is selected or not.
132 private boolean fCtrlSelection
= false;
134 * A reference to the view site.
136 private ViewPart fSite
= null;
138 * The current graph node (the last selected one).
140 private GraphNode fCurrentGraphNode
= null;
142 * The first graph node in list (multiple selection).
144 private GraphNode fListStart
= null;
146 * The previous graph node (multiple selection).
148 private List
<GraphNode
> fPrevList
= null;
150 * The time compression bar.
152 private TimeCompressionBar fTimeBar
= null;
154 * The current diagram tool tip.
156 private DiagramToolTip fToolTip
= null;
158 * The accessible object reference of view control.
160 private Accessible fAccessible
= null;
162 * The current node for the tooltip to display.
164 private GraphNode fToolTipNode
;
166 * The life line to drag and drop.
168 private Lifeline fDragAndDrop
= null;
170 * The number of focused widgets.
172 private int fFocusedWidget
= -1;
176 private float fPrinterZoom
= 0;
178 * Y coordinate for printer.
180 private int fPrinterY
= 0;
182 * X coordinate for printer.
184 private int fPrinterX
= 0;
186 * Flag whether drag and drop is enabled or not.
188 private boolean fIsDragAndDrop
= false;
190 * The x coordinate for drag.
192 private int fDragX
= 0;
194 * The y coordinate for drag.
196 private int fDragY
= 0;
200 private boolean fReorderMode
= false;
202 * The collapse caret image.
204 private Image fCollapaseCaretImg
= null;
206 * The arrow up caret image.
208 private Image fArrowUpCaretImg
= null;
210 * The current caret image.
212 private Image fCurrentCaretImage
= null;
214 * A sequence diagramm collapse provider (for collapsing graph nodes)
216 private ISDCollapseProvider fCollapseProvider
= null;
218 * The insertion caret.
220 private Caret fInsertionCartet
= null;
222 * The reorder list when in reorder mode.
224 private List
<Lifeline
[]> fReorderList
= null;
226 * Flag to specify whether in printing mode or not.
228 private boolean fIsPrinting
= false;
230 * A printer reference.
232 private Printer fPrinter
= null;
234 * Flag whether shift was selected or not.
236 private boolean fShiftSelection
= false;
238 * The scroll tooltip.
240 private DiagramToolTip fScrollToolTip
= null;
242 * Timer for auto_scroll feature
244 private AutoScroll fLocalAutoScroll
= null;
246 * TimerTask for auto_scroll feature !=null when auto scroll is running
248 private 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
<>();
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
<>();
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 for (int i
= 0; i
< list
.size(); i
++) {
490 if (!fSelectedNodeList
.contains(list
.get(i
))) {
491 fSelectedNodeList
.add(list
.get(i
));
492 list
.get(i
).setSelected(true);
495 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
496 fSelProvider
.setSelection(selection
);
500 * Removes a node from the selected nodes list.
502 * @param node to remove
504 public void removeSelection(GraphNode node
) {
505 fSelectedNodeList
.remove(node
);
506 node
.setSelected(false);
507 node
.setFocused(false);
508 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
509 fSelProvider
.setSelection(selection
);
513 * Removes a list of graph nodes from the selected nodes list.
515 * @param list of nodes to remove.
517 public void removeSelection(List
<GraphNode
> list
) {
518 fSelectedNodeList
.removeAll(list
);
519 for (int i
= 0; i
< list
.size(); i
++) {
520 list
.get(i
).setSelected(false);
521 list
.get(i
).setFocused(false);
523 StructuredSelection selection
= new StructuredSelection(fSelectedNodeList
);
524 fSelProvider
.setSelection(selection
);
528 * Clear the list of GraphNodes which must be drawn selected.
530 public void clearSelection() {
531 for (int i
= 0; i
< fSelectedNodeList
.size(); i
++) {
532 fSelectedNodeList
.get(i
).setSelected(false);
533 fSelectedNodeList
.get(i
).setFocused(false);
535 fCurrentGraphNode
= null;
536 fSelectedNodeList
.clear();
537 fSelProvider
.setSelection(new StructuredSelection());
543 * @param viewSite The view part to set
545 public void setSite(ViewPart viewSite
) {
547 fSite
.getSite().setSelectionProvider(fSelProvider
);
548 Object serviceObject
= fSite
.getSite().getWorkbenchWindow().getService(IContextService
.class);
549 IContextService service
= (IContextService
) serviceObject
;
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 * Sets the current zoom value.
593 * The current zoom value
595 public void setZoomValue(float zoomValue
) {
596 fZoomValue
= zoomValue
;
600 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
602 * @param node the GraphNode to move to
604 public void moveTo(GraphNode node
) {
614 * Moves the Sequence diagram to ensure the given node is visible
616 * @param node the GraphNode to move to
618 public void ensureVisible(GraphNode node
) {
622 int x
= Math
.round(node
.getX() * fZoomValue
);
623 int y
= Math
.round(node
.getY() * fZoomValue
);
624 int width
= Math
.round(node
.getWidth() * fZoomValue
);
625 int height
= Math
.round(node
.getHeight() * fZoomValue
);
626 if ((node
instanceof BaseMessage
) && (height
== 0)) {
627 int header
= Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
* 2 + Metrics
.getLifelineHeaderFontHeigth();
628 height
= -Math
.round((Metrics
.getMessagesSpacing() + header
) * fZoomValue
);
629 y
= y
+ Math
.round(Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
* fZoomValue
);
631 if (node
instanceof BasicExecutionOccurrence
) {
635 if (node
instanceof Lifeline
) {
637 height
= getVisibleHeight();
639 ensureVisible(x
, y
, width
, height
, SWT
.CENTER
, true);
644 * Returns the current zoom factor.
645 * @return the current zoom factor.
647 public float getZoomFactor() {
652 * Returns teh printer reference.
654 * @return the printer reference
656 public Printer
getPrinter() {
661 * Returns whether the widget is used for printing or not.
663 * @return whether the widget is used for printing or not
665 public boolean isPrinting() {
670 * Returns the current graph node.
672 * @return the current graph node
674 public GraphNode
getCurrentGraphNode() {
675 return fCurrentGraphNode
;
679 * Returns the current zoom value.
681 * @return the current zoom value
683 public float getZoomValue() {
688 * Gets the zoom in mode.
690 * @return the mode value to set.
692 public boolean getZoomInMode() {
698 * Gets the zoom out mode.
700 * @return the mode value to set.
702 public boolean getZoomOutMode() {
707 * Returns if ctrl selection
708 * @return true if ctrl selection else false
710 public boolean isCtrlSelection() {
711 return fCtrlSelection
;
715 * Returns if shift selection
716 * @return true if shift Selection else false
718 public boolean isShiftSelection() {
719 return fCtrlSelection
;
723 * Gets the overview image.
725 * @param rect Rectangle to include overview.
726 * @return the overview image
728 public Image
getOverview(Rectangle rect
) {
729 float oldzoom
= fZoomValue
;
730 if ((fOverView
!= null) && ((rect
.width
!= fOverView
.getBounds().width
) || (rect
.height
!= fOverView
.getBounds().height
))) {
734 if (fOverView
== null) {
735 int backX
= getContentsX();
736 int backY
= getContentsY();
737 setContentsPos(0, 0);
738 fOverView
= new Image(getDisplay(), rect
.width
, rect
.height
);
739 GC gcim
= new GC(fOverView
);
740 NGC context
= new NGC(this, gcim
);
741 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
742 fFrame
.draw(context
);
743 setContentsPos(backX
, backY
);
747 fZoomValue
= oldzoom
;
752 * Resets the zoom factor.
754 public void resetZoomFactor() {
755 int currentX
= Math
.round(getContentsX() / fZoomValue
);
756 int currentY
= Math
.round(getContentsY() / fZoomValue
);
758 if (fTimeBar
!= null && !fTimeBar
.isDisposed()) {
759 fTimeBar
.setZoom(fZoomValue
);
763 setContentsPos(currentX
, currentY
);
767 * Enable or disable the lifeline reodering using Drag and Drop
769 * @param mode - true to enable false otherwise
771 public void setReorderMode(boolean mode
) {
776 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
777 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
779 * @return - the re-odered sequence
781 public List
<Lifeline
[]> getLifelineReoderList() {
786 * Sets the focus on given graph node (current node).
789 * The graph node to focus on.
791 public void setFocus(GraphNode node
) {
795 if (fCurrentGraphNode
!= null) {
796 fCurrentGraphNode
.setFocused(false);
798 fCurrentGraphNode
= node
;
799 node
.setFocused(true);
805 * Returns the graph node focused on.
807 * @return the current graph node
809 public GraphNode
getFocusNode() {
810 return fCurrentGraphNode
;
814 * Method to traverse right.
816 public void traverseRight() {
817 Object selectedNode
= getFocusNode();
818 if (selectedNode
== null) {
821 GraphNode node
= null;
822 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
823 node
= fFrame
.getCalledMessage((BaseMessage
) selectedNode
);
825 if (selectedNode
instanceof BasicExecutionOccurrence
) {
826 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
828 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
829 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
830 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
< fFrame
.lifeLinesCount() - 1)) {
831 node
= fFrame
.getLifeline(i
+ 1);
843 * Method to traverse left.
845 public void traverseLeft() {
846 Object selectedNode
= getFocusNode();
847 GraphNode node
= null;
848 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
849 node
= fFrame
.getCallerMessage((BaseMessage
) selectedNode
);
851 if (selectedNode
instanceof BasicExecutionOccurrence
) {
852 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
855 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
856 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
858 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
859 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
> 0)) {
860 node
= fFrame
.getLifeline(i
- 1);
864 if ((fFrame
.lifeLinesCount() > 0) && (node
== null)) {
865 node
= fFrame
.getLifeline(0);
875 * Method to traverse up.
877 public void traverseUp() {
878 Object selectedNode
= getFocusNode();
879 if (selectedNode
== null) {
882 GraphNode node
= null;
883 if (selectedNode
instanceof BaseMessage
) {
884 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
885 } else if (selectedNode
instanceof Lifeline
) {
886 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
887 if (!(node
instanceof Lifeline
)) {
890 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
891 node
= fFrame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
893 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
896 if ((node
== null) && (selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
897 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
907 * Method to traverse down.
909 public void traverseDown() {
910 Object selectedNode
= getFocusNode();
911 if (selectedNode
== null) {
915 if (selectedNode
instanceof BaseMessage
) {
916 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
917 } else if (selectedNode
instanceof Lifeline
) {
918 node
= fFrame
.getFirstExecution((Lifeline
) selectedNode
);
919 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
920 node
= fFrame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
932 * Method to traverse home.
934 public void traverseHome() {
935 Object selectedNode
= getFocusNode();
936 if (selectedNode
== null) {
939 GraphNode node
= null;
941 if (selectedNode
instanceof BaseMessage
) {
942 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
943 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
945 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
947 } else if (selectedNode
instanceof Lifeline
) {
948 node
= fFrame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
949 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
950 node
= fFrame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
952 if (fFrame
.lifeLinesCount() > 0) {
953 Lifeline lifeline
= fFrame
.getLifeline(0);
954 node
= fFrame
.getNextLifelineMessage(lifeline
, null);
965 * Method to traverse to the end.
967 public void traverseEnd() {
968 Object selectedNode
= getFocusNode();
969 if (selectedNode
== null) {
973 if (selectedNode
instanceof BaseMessage
) {
974 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
975 } else if (selectedNode
instanceof Lifeline
) {
976 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
977 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
978 node
= fFrame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
980 if (fFrame
.lifeLinesCount() > 0) {
981 Lifeline lifeline
= fFrame
.getLifeline(0);
982 node
= fFrame
.getPrevLifelineMessage(lifeline
, null);
995 * Method to print UI.
997 * @param sdPrintDialog the sequence diagram printer dialog.
999 public void printUI(SDPrintDialogUI sdPrintDialog
) {
1000 PrinterData data
= sdPrintDialog
.getPrinterData();
1002 if ((data
== null) || (fFrame
== null)) {
1006 fPrinter
= new Printer(data
);
1008 String jobName
= MessageFormat
.format(Messages
.SequenceDiagram_plus
, new Object
[] { String
.valueOf(fSite
.getContentDescription()), String
.valueOf(fFrame
.getName()) });
1009 fPrinter
.startJob(jobName
);
1011 GC gc
= new GC(fPrinter
);
1013 float lastZoom
= fZoomValue
;
1015 Rectangle area
= getClientArea();
1019 NGC context
= new NGC(this, gcim
);
1021 // Set the metrics to use for lifeline text and message text
1022 // using the Graphical Context
1023 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1024 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1025 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1026 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1027 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1029 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
1030 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
1031 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
1032 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
1034 int messageFontHeight
= 0;
1035 if (syncMessFontH
> syncMessRetFontH
) {
1036 messageFontHeight
= syncMessFontH
;
1038 messageFontHeight
= syncMessRetFontH
;
1040 if (messageFontHeight
< asyncMessFontH
) {
1041 messageFontHeight
= asyncMessFontH
;
1043 if (messageFontHeight
< asyncMessRetFontH
) {
1044 messageFontHeight
= asyncMessRetFontH
;
1046 Metrics
.setMessageFontHeight(messageFontHeight
);
1047 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1049 int width
= Math
.round((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
1050 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1051 if (width
< area
.width
) {
1054 if (height
< area
.height
) {
1055 height
= area
.height
;
1057 resizeContents(width
, height
);
1059 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1060 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1061 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1062 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1063 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1064 gcim
.setLineWidth(1);
1066 fPrinter
.startPage();
1067 fZoomValue
= lastZoom
;
1069 int restoreX
= getContentsX();
1070 int restoreY
= getContentsY();
1072 float zh
= sdPrintDialog
.getStepY() * sdPrintDialog
.getZoomFactor();
1073 float zw
= sdPrintDialog
.getStepX() * sdPrintDialog
.getZoomFactor();
1075 float zoomValueH
= fPrinter
.getClientArea().height
/ zh
;
1076 float zoomValueW
= fPrinter
.getClientArea().width
/ zw
;
1077 if (zoomValueH
> zoomValueW
) {
1078 fPrinterZoom
= zoomValueH
;
1080 fPrinterZoom
= zoomValueW
;
1083 if (sdPrintDialog
.printSelection()) {
1084 int[] pagesList
= sdPrintDialog
.getPageList();
1086 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1087 printPage(pagesList
[pageIndex
], sdPrintDialog
, context
);
1089 } else if (sdPrintDialog
.printAll()) {
1090 for (int pageIndex
= 1; pageIndex
<= sdPrintDialog
.maxNumOfPages(); pageIndex
++) {
1091 printPage(pageIndex
, sdPrintDialog
, context
);
1093 } else if (sdPrintDialog
.printCurrent()) {
1094 printPage(getContentsX(), getContentsY(), sdPrintDialog
, context
, 1);
1095 } else if (sdPrintDialog
.printRange()) {
1096 for (int pageIndex
= sdPrintDialog
.getFrom(); pageIndex
<= sdPrintDialog
.maxNumOfPages() && pageIndex
<= sdPrintDialog
.getTo(); pageIndex
++) {
1097 printPage(pageIndex
, sdPrintDialog
, context
);
1102 fIsPrinting
= false;
1107 fZoomValue
= lastZoom
;
1109 setContentsPos(restoreX
, restoreY
);
1115 public void print() {
1116 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1118 if (sdPrinter
.open() != 0) {
1121 } catch (Exception e
) {
1122 Activator
.getDefault().logError("Error creating image", e
); //$NON-NLS-1$
1125 printUI(sdPrinter
.getDialogUI());
1129 * Method to print a page.
1131 * @param pageNum The page number
1132 * @param pd The sequence diagram print dialog
1133 * @param context The graphical context
1135 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1136 int j
= pageNum
/ pd
.getNbRow();
1137 int i
= pageNum
% pd
.getNbRow();
1147 i
= (int) (i
* pd
.getStepX());
1148 j
= (int) (j
* pd
.getStepY());
1150 printPage(i
, j
, pd
, context
, pageNum
);
1156 * Method to print page ranges.
1163 * The sequence diagram print dialog
1165 * The graphical context
1169 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1170 fIsPrinting
= false;
1171 int pageNumFontZoom
= fPrinter
.getClientArea().height
/ getVisibleHeight();
1174 setContentsPos(i
, j
);
1177 float lastZoom
= fZoomValue
;
1178 fZoomValue
= fPrinterZoom
* lastZoom
;
1180 fFrame
.draw(context
);
1182 fZoomValue
= pageNumFontZoom
;
1183 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1184 String currentPageNum
= String
.valueOf(pageNum
);
1185 int ii
= context
.textExtent(currentPageNum
);
1186 int jj
= context
.getCurrentFontHeight();
1187 fZoomValue
= fPrinterZoom
* lastZoom
;
1188 context
.drawText(currentPageNum
, Math
.round(fPrinterX
+ getVisibleWidth() / fPrinterZoom
- ii
/ fPrinterZoom
), Math
.round(fPrinterY
+ getVisibleHeight() / fPrinterZoom
- jj
/ fPrinterZoom
), false);
1189 fIsPrinting
= false;
1190 fZoomValue
= lastZoom
;
1194 * Sets the collapse provider.
1196 * @param provider The collapse provider to set
1198 protected void setCollapseProvider(ISDCollapseProvider provider
) {
1199 fCollapseProvider
= provider
;
1204 * Checks for focus of children.
1206 * @param children Control to check
1207 * @return true if child is on focus else false
1209 protected boolean checkFocusOnChilds(Control children
) {
1210 if (children
instanceof Composite
) {
1211 Control
[] child
= ((Composite
) children
).getChildren();
1212 for (int i
= 0; i
< child
.length
; i
++) {
1213 if (child
[i
].isFocusControl()) {
1216 checkFocusOnChilds(child
[i
]);
1223 * A post action for a tooltip (before displaying).
1225 * @param accessible true if accessible else false
1226 * @return the tooltip text.
1228 protected String
getPostfixForTooltip(boolean accessible
) {
1229 StringBuffer postfix
= new StringBuffer();
1230 // Determine if the tooltip must show the time difference between the current mouse position and
1231 // the last selected graphNode
1232 if ((fCurrentGraphNode
!= null) &&
1233 (fCurrentGraphNode
instanceof ITimeRange
) &&
1234 (fToolTipNode
instanceof ITimeRange
) &&
1235 (fCurrentGraphNode
!= fToolTipNode
) &&
1236 ((ITimeRange
) fToolTipNode
).hasTimeInfo() &&
1237 ((ITimeRange
) fCurrentGraphNode
).hasTimeInfo()) {
1238 postfix
.append(" -> "); //$NON-NLS-1$
1239 postfix
.append(fCurrentGraphNode
.getName());
1240 postfix
.append("\n"); //$NON-NLS-1$
1241 postfix
.append(Messages
.SequenceDiagram_Delta
);
1242 postfix
.append(" "); //$NON-NLS-1$
1244 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1245 ITmfTimestamp firstTime
= ((ITimeRange
) fCurrentGraphNode
).getEndTime();
1246 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1247 ITmfTimestamp delta
= lastTime
.getDelta(firstTime
);
1248 postfix
.append(delta
.toString());
1251 if ((fToolTipNode
instanceof ITimeRange
) && ((ITimeRange
) fToolTipNode
).hasTimeInfo()) {
1252 postfix
.append("\n"); //$NON-NLS-1$
1253 ITmfTimestamp firstTime
= ((ITimeRange
) fToolTipNode
).getStartTime();
1254 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1256 if (firstTime
!= null) {
1257 if (lastTime
!= null && firstTime
.compareTo(lastTime
) != 0) {
1258 postfix
.append("start: "); //$NON-NLS-1$
1259 postfix
.append(firstTime
.toString());
1260 postfix
.append("\n"); //$NON-NLS-1$
1261 postfix
.append("end: "); //$NON-NLS-1$
1262 postfix
.append(lastTime
.toString());
1263 postfix
.append("\n"); //$NON-NLS-1$
1265 postfix
.append(firstTime
.toString());
1268 else if (lastTime
!= null) {
1269 postfix
.append(lastTime
.toString());
1273 return postfix
.toString();
1277 * Sets a new focused widget.
1279 * @param newFocusShape A new focus shape.
1281 protected void setFocus(int newFocusShape
) {
1282 fFocusedWidget
= newFocusShape
;
1283 if (fFocusedWidget
== -1) {
1284 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
1286 getViewControl().getAccessible().setFocus(fFocusedWidget
);
1291 * Highlight the given GraphNode<br>
1292 * The GraphNode is then displayed using the system default selection color
1294 * @param node the GraphNode to highlight
1296 protected void performSelection(GraphNode node
) {
1297 if ((fCtrlSelection
) || (fShiftSelection
)) {
1299 if (fSelectedNodeList
.contains(node
)) {
1300 removeSelection(node
);
1316 * Returns a draw buffer image.
1318 * @return a Image containing the draw buffer.
1320 protected Image
getDrawBuffer() {
1323 Rectangle area
= getClientArea();
1324 Image dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
1325 GC gcim
= new GC(dbuffer
);
1326 NGC context
= new NGC(this, gcim
);
1328 // Set the metrics to use for lifeline text and message text
1329 // using the Graphical Context
1330 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1331 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1332 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1333 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1334 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1336 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
1337 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
1338 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
1339 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
1341 int messageFontHeight
= 0;
1342 if (syncMessFontH
> syncMessRetFontH
) {
1343 messageFontHeight
= syncMessFontH
;
1345 messageFontHeight
= syncMessRetFontH
;
1347 if (messageFontHeight
< asyncMessFontH
) {
1348 messageFontHeight
= asyncMessFontH
;
1350 if (messageFontHeight
< asyncMessRetFontH
) {
1351 messageFontHeight
= asyncMessRetFontH
;
1353 Metrics
.setMessageFontHeight(messageFontHeight
);
1354 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1356 int width
= (int) ((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
1357 int height
= (int) ((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1359 resizeContents(width
, height
);
1361 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1362 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1363 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1364 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1365 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1366 gcim
.setLineWidth(1);
1368 fFrame
.draw(context
);
1369 if (fDragAndDrop
!= null) {
1370 Lifeline node
= fDragAndDrop
;
1371 boolean isSelected
= fDragAndDrop
.isSelected();
1372 boolean hasFocus
= fDragAndDrop
.hasFocus();
1373 node
.setSelected(false);
1374 node
.setFocused(false);
1375 node
.draw(context
, fDragX
, fDragY
);
1376 node
.setSelected(isSelected
);
1377 node
.setFocused(hasFocus
);
1385 protected void keyPressedEvent(KeyEvent event
) {
1386 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1387 Control
[] child
= getParent().getChildren();
1388 for (int i
= 0; i
< child
.length
; i
++) {
1389 if ((child
[i
].isFocusControl())&& (!(child
[i
] instanceof ScrollView
))) {
1390 getViewControl().setFocus();
1397 if (event
.keyCode
== SWT
.CTRL
) {
1398 fCtrlSelection
= true;
1400 if (event
.keyCode
== SWT
.SHIFT
) {
1401 fShiftSelection
= true;
1402 fPrevList
= new ArrayList
<>();
1403 fPrevList
.addAll(getSelection());
1406 GraphNode prevNode
= getFocusNode();
1408 if (event
.keyCode
== SWT
.ARROW_RIGHT
) {
1412 if (event
.keyCode
== SWT
.ARROW_LEFT
) {
1416 if (event
.keyCode
== SWT
.ARROW_DOWN
) {
1420 if (event
.keyCode
== SWT
.ARROW_UP
) {
1424 if (event
.keyCode
== SWT
.HOME
) {
1428 if (event
.keyCode
== SWT
.END
) {
1432 if ((!fShiftSelection
) && (!fCtrlSelection
)) {
1433 fListStart
= fCurrentGraphNode
;
1436 if (event
.character
== ' ') {
1437 performSelection(fCurrentGraphNode
);
1438 if (!fShiftSelection
) {
1439 fListStart
= fCurrentGraphNode
;
1443 if ((fShiftSelection
) && (prevNode
!= getFocusNode())) {
1445 addSelection(fPrevList
);
1446 addSelection(fFrame
.getNodeList(fListStart
, getFocusNode()));
1447 if (getFocusNode() instanceof Lifeline
) {
1448 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1450 ensureVisible(getFocusNode());
1452 } else if ((!fCtrlSelection
) && (!fShiftSelection
)) {
1455 if (getFocusNode() != null) {
1456 addSelection(getFocusNode());
1458 if (getFocusNode() instanceof Lifeline
) {
1459 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1461 ensureVisible(getFocusNode());
1466 if (fCurrentGraphNode
!= null) {
1467 fCurrentGraphNode
.setFocused(true);
1471 if ((event
.character
== ' ') && ((fZoomInMode
) || (fZoomOutMode
))) {
1472 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue
);
1473 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue
);
1475 if (fZoomValue
< 64) {
1476 fZoomValue
= fZoomValue
* (float) 1.25;
1479 fZoomValue
= fZoomValue
/ (float) 1.25;
1481 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1482 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1483 setContentsPos(x
, y
);
1484 if (fTimeBar
!= null) {
1485 fTimeBar
.setZoom(fZoomValue
);
1487 // redraw also resize the scrollView content
1493 protected void keyReleasedEvent(KeyEvent event
) {
1495 if (event
.keyCode
== SWT
.CTRL
) {
1496 fCtrlSelection
= false;
1498 if (event
.keyCode
== SWT
.SHIFT
) {
1499 fShiftSelection
= false;
1501 super.keyReleasedEvent(event
);
1506 public boolean isFocusControl() {
1507 Control
[] child
= getChildren();
1508 for (int i
= 0; i
< child
.length
; i
++) {
1509 if (child
[i
].isFocusControl()) {
1512 checkFocusOnChilds(child
[i
]);
1518 public boolean setContentsPos(int x
, int y
) {
1528 if (fFrame
== null) {
1531 if (localX
+ getVisibleWidth() > getContentsWidth()) {
1532 localX
= getContentsWidth() - getVisibleWidth();
1534 if (localY
+ getVisibleHeight() > getContentsHeight()) {
1535 localY
= getContentsHeight() - getVisibleHeight();
1537 int x1
= Math
.round(localX
/ fZoomValue
);
1538 int y2
= Math
.round(localY
/ fZoomValue
);
1539 int width
= Math
.round(getVisibleWidth() / fZoomValue
);
1540 int height
= Math
.round(getVisibleHeight() / fZoomValue
);
1541 fFrame
.updateIndex(x1
, y2
, width
, height
);
1543 if (fInsertionCartet
!= null && fInsertionCartet
.isVisible()) {
1544 fInsertionCartet
.setVisible(false);
1547 return super.setContentsPos(localX
, localY
);
1551 protected void contentsMouseHover(MouseEvent event
) {
1552 GraphNode graphNode
= null;
1553 if (fFrame
!= null) {
1554 int x
= Math
.round(event
.x
/ fZoomValue
);
1555 int y
= Math
.round(event
.y
/ fZoomValue
);
1556 graphNode
= fFrame
.getNodeAt(x
, y
);
1557 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
1558 fToolTipNode
= graphNode
;
1559 String postfix
= getPostfixForTooltip(true);
1560 if (graphNode
instanceof Lifeline
) {
1561 Lifeline lifeline
= (Lifeline
) graphNode
;
1562 fToolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
1565 fToolTip
.showToolTip(graphNode
.getName() + postfix
);
1569 fToolTip
.hideToolTip();
1575 protected void contentsMouseMoveEvent(MouseEvent e
) {
1576 fScrollToolTip
.hideToolTip();
1577 fToolTip
.hideToolTip();
1578 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1579 Control
[] child
= getParent().getChildren();
1580 for (int i
= 0; i
< child
.length
; i
++) {
1581 if ((child
[i
].isFocusControl()) && (!(child
[i
] instanceof ScrollView
))) {
1582 getViewControl().setFocus();
1589 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((fDragAndDrop
!= null) || fIsDragAndDrop
) && (fReorderMode
|| fCollapseProvider
!= null)) {
1590 fIsDragAndDrop
= false;
1591 if (fCurrentGraphNode
instanceof Lifeline
) {
1592 fDragAndDrop
= (Lifeline
) fCurrentGraphNode
;
1594 if (fDragAndDrop
!= null) {
1597 if (e
.x
> getContentsX() + getVisibleWidth()) {
1598 dx
= e
.x
- (getContentsX() + getVisibleWidth());
1599 } else if (e
.x
< getContentsX()) {
1600 dx
= -getContentsX() + e
.x
;
1602 if (e
.y
> getContentsY() + getVisibleHeight()) {
1603 dy
= e
.y
- (getContentsY() + getVisibleHeight());
1604 } else if (e
.y
< getContentsY()) {
1605 dy
= -getContentsY() + e
.y
;
1609 if (dx
!= 0 || dy
!= 0) {
1610 if (fLocalAutoScroll
== null) {
1611 if (fLocalAutoScrollTimer
== null) {
1612 fLocalAutoScrollTimer
= new Timer(true);
1614 fLocalAutoScroll
= new AutoScroll(this, dx
, dy
);
1615 fLocalAutoScrollTimer
.schedule(fLocalAutoScroll
, 0, 75);
1617 fLocalAutoScroll
.fDeltaX
= dx
;
1618 fLocalAutoScroll
.fDeltaY
= dy
;
1620 } else if (fLocalAutoScroll
!= null) {
1621 fLocalAutoScroll
.cancel();
1622 fLocalAutoScroll
= null;
1624 fDragX
= Math
.round(e
.x
/ fZoomValue
);
1625 fDragY
= Math
.round(e
.y
/ fZoomValue
);
1627 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1628 if ((node
!= null) && (node
!= fDragAndDrop
)) {
1631 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
1632 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
1633 int x
= node
.getX();
1634 int width
= node
.getWidth();
1635 if (fFrame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
) {
1636 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * fZoomValue
));
1638 y
= Math
.round(height
* fZoomValue
);
1641 if (fFrame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
)) {
1642 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * fZoomValue
));
1644 y1
= Math
.round(height
* fZoomValue
);
1647 int rx
= Math
.round(x
* fZoomValue
);
1649 fInsertionCartet
.setVisible(true);
1650 if ((fInsertionCartet
.getImage() != null) && (!fInsertionCartet
.getImage().isDisposed())) {
1651 fInsertionCartet
.getImage().dispose();
1653 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* fZoomValue
)) >= e
.x
) {
1654 if (fCollapseProvider
!= null) {
1655 ImageData data
= fCollapaseCaretImg
.getImageData();
1656 data
= data
.scaledTo(Math
.round(fCollapaseCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fCollapaseCaretImg
.getBounds().height
* fZoomValue
));
1657 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1658 fInsertionCartet
.setImage(fCurrentCaretImage
);
1659 fInsertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y
);
1661 } else if (fReorderMode
) {
1663 if (node
.getIndex() > 1 && fFrame
.getLifeline(node
.getIndex() - 2) == fDragAndDrop
) {
1666 ImageData data
= fArrowUpCaretImg
.getImageData();
1667 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1668 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1669 fInsertionCartet
.setImage(fCurrentCaretImage
);
1670 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y1
);
1672 if (node
.getIndex() < fFrame
.lifeLinesCount() && fFrame
.getLifeline(node
.getIndex()) == fDragAndDrop
) {
1675 ImageData data
= fArrowUpCaretImg
.getImageData();
1676 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1677 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1678 fInsertionCartet
.setImage(fCurrentCaretImage
);
1679 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2 + 1, y1
);
1683 fInsertionCartet
.setVisible(false);
1687 super.contentsMouseMoveEvent(e
);
1692 protected void contentsMouseUpEvent(MouseEvent event
) {
1693 // Just in case the diagram highlight a time compression region
1694 // this region need to be released when clicking everywhere
1695 fInsertionCartet
.setVisible(false);
1696 if (fDragAndDrop
!= null) {
1697 if ((fOverView
!= null) && (!fOverView
.isDisposed())) {
1698 fOverView
.dispose();
1701 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1703 int rx
= Math
.round(node
.getX() * fZoomValue
);
1704 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * fZoomValue
)) >= event
.x
) {
1705 if ((fCollapseProvider
!= null) && (fDragAndDrop
!= node
)) {
1706 fCollapseProvider
.collapseTwoLifelines(fDragAndDrop
, node
);
1708 } else if (rx
< event
.x
) {
1709 fFrame
.insertLifelineAfter(fDragAndDrop
, node
);
1710 if (node
.getIndex() < fFrame
.lifeLinesCount()) {
1711 Lifeline temp
[] = { fDragAndDrop
, fFrame
.getLifeline(node
.getIndex()) };
1712 fReorderList
.add(temp
);
1714 Lifeline temp
[] = { fDragAndDrop
, null };
1715 fReorderList
.add(temp
);
1718 fFrame
.insertLifelineBefore(fDragAndDrop
, node
);
1719 Lifeline temp
[] = { fDragAndDrop
, node
};
1720 fReorderList
.add(temp
);
1724 fDragAndDrop
= null;
1726 if (fFrame
== null) {
1729 fFrame
.resetTimeCompression();
1731 // reset auto scroll if it's engaged
1732 if (fLocalAutoScroll
!= null) {
1733 fLocalAutoScroll
.cancel();
1734 fLocalAutoScroll
= null;
1736 super.contentsMouseUpEvent(event
);
1740 protected void contentsMouseDownEvent(MouseEvent event
) {
1741 if (fCurrentGraphNode
!= null) {
1742 fCurrentGraphNode
.setFocused(false);
1745 // Just in case the diagram highlight a time compression region
1746 // this region need to be released when clicking everywhere
1747 if (fFrame
== null) {
1751 fFrame
.resetTimeCompression();
1753 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
1754 fCtrlSelection
= true;
1756 fCtrlSelection
= false;
1759 if (((fZoomInMode
) || (fZoomOutMode
)) && (event
.button
== 1)) {
1760 int cx
= Math
.round(event
.x
/ fZoomValue
);
1761 int cy
= Math
.round(event
.y
/ fZoomValue
);
1763 if (fZoomValue
< 64) {
1764 fZoomValue
= fZoomValue
* (float) 1.25;
1767 fZoomValue
= fZoomValue
/ (float) 1.25;
1769 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1770 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1771 setContentsPos(x
, y
);
1772 if (fTimeBar
!= null) {
1773 fTimeBar
.setZoom(fZoomValue
);
1775 // redraw also resize the scrollView content
1778 GraphNode node
= null;
1779 int x
= Math
.round(event
.x
/ fZoomValue
);
1780 int y
= Math
.round(event
.y
/ fZoomValue
);
1781 node
= fFrame
.getNodeAt(x
, y
);
1783 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
1784 if (!fShiftSelection
) {
1787 if (fShiftSelection
) {
1789 addSelection(fFrame
.getNodeList(fListStart
, node
));
1791 performSelection(node
);
1793 fCurrentGraphNode
= node
;
1795 node
.setFocused(true);
1800 if (fDragAndDrop
== null) {
1801 super.contentsMouseDownEvent(event
);
1803 fIsDragAndDrop
= (event
.button
== 1);
1808 * TimerTask for auto scroll feature.
1810 protected static class AutoScroll
extends TimerTask
{
1820 * Field sequence diagram reference.
1822 public SDWidget fSdWidget
;
1825 * Constructor for AutoScroll.
1826 * @param sv sequence diagram widget reference
1830 public AutoScroll(SDWidget sv
, int dx
, int dy
) {
1838 Display display
= Display
.getDefault();
1839 if ((display
== null) || (display
.isDisposed())) {
1842 display
.asyncExec(new Runnable() {
1845 if (fSdWidget
.isDisposed()) {
1848 fSdWidget
.fDragX
+= fDeltaX
;
1849 fSdWidget
.fDragY
+= fDeltaY
;
1850 fSdWidget
.scrollBy(fDeltaX
, fDeltaY
);
1857 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1858 if (fFrame
== null) {
1859 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1860 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1864 SDViewPref
.getInstance();
1866 Rectangle area
= getClientArea();
1867 Image dbuffer
= getDrawBuffer();
1868 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1871 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1872 } catch (Exception e
) {
1873 Activator
.getDefault().logError("Error drawin content", e
); //$NON-NLS-1$
1876 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * fZoomValue
));
1877 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * fZoomValue
));
1878 if ((fTimeBar
!= null) && (fFrame
.hasTimeInfo())) {
1879 fTimeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1880 fTimeBar
.setContentsPos(getContentsX(), getContentsY());
1884 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1885 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1886 if (yRatio
> xRatio
) {
1887 setOverviewSize((int) (getVisibleHeight() * 0.75));
1889 setOverviewSize((int) (getVisibleWidth() * 0.75));
1894 public void widgetDefaultSelected(SelectionEvent event
) {
1898 public void widgetSelected(SelectionEvent event
) {
1899 if (event
.widget
== fZoomIn
) {
1900 fZoomValue
= fZoomValue
* 2;
1901 } else if (event
.widget
== fZoomOut
) {
1902 fZoomValue
= fZoomValue
/ 2;
1908 * Called when property changed occurs in the preference page. "PREFOK" is
1909 * fired when the user press the ok or apply button
1912 public void propertyChange(PropertyChangeEvent e
) {
1913 if (fFrame
!= null && !isDisposed()) {
1914 fFrame
.resetTimeCompression();
1916 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1918 // Prepare the overview to be reused for the new
1919 // settings (especially the colors)
1920 if (fOverView
!= null) {
1921 fOverView
.dispose();
1929 public void widgetDisposed(DisposeEvent e
) {
1930 if (fOverView
!= null) {
1931 fOverView
.dispose();
1933 super.removeDisposeListener(this);
1934 if ((fCurrentCaretImage
!= null) && (!fCurrentCaretImage
.isDisposed())) {
1935 fCurrentCaretImage
.dispose();
1937 if ((fArrowUpCaretImg
!= null) && (!fArrowUpCaretImg
.isDisposed())) {
1938 fArrowUpCaretImg
.dispose();
1940 if ((fCollapaseCaretImg
!= null) && (!fCollapaseCaretImg
.isDisposed())) {
1941 fCollapaseCaretImg
.dispose();
1943 SDViewPref
.getInstance().removePropertyChangeListener(this);
1944 LoadersManager lm
= LoadersManager
.getInstance();
1945 if (fSite
instanceof SDView
) {
1946 ((SDView
) fSite
).resetProviders();
1948 lm
.resetLoader(((SDView
) fSite
).getViewSite().getId());
1954 protected void drawOverview(GC gc
, Rectangle r
) {
1955 float oldzoom
= fZoomValue
;
1956 if (getContentsWidth() > getContentsHeight()) {
1957 fZoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
1959 fZoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
1961 if ((fOverView
!= null) && ((r
.width
!= fOverView
.getBounds().width
) || (r
.height
!= fOverView
.getBounds().height
))) {
1962 fOverView
.dispose();
1965 if (fOverView
== null) {
1966 int backX
= getContentsX();
1967 int backY
= getContentsY();
1968 setContentsPos(0, 0);
1969 fOverView
= new Image(getDisplay(), r
.width
, r
.height
);
1970 GC gcim
= new GC(fOverView
);
1971 NGC context
= new NGC(this, gcim
);
1972 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1973 fFrame
.draw(context
);
1974 setContentsPos(backX
, backY
);
1978 if ((fOverView
!= null) && (r
.width
== fOverView
.getBounds().width
) && (r
.height
== fOverView
.getBounds().height
)) {
1979 gc
.drawImage(fOverView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
1982 fZoomValue
= oldzoom
;
1984 super.drawOverview(gc
, r
);
1988 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
1989 fFrame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
1990 ensureVisible(lifeline
);
1991 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
1992 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
1993 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
1999 public int getVisibleWidth() {
2001 return fPrinter
.getClientArea().width
;
2003 return super.getVisibleWidth();
2007 public int getVisibleHeight() {
2009 return fPrinter
.getClientArea().height
;
2011 return super.getVisibleHeight();
2015 public int contentsToViewX(int x
) {
2017 int v
= Math
.round(fPrinterX
* fPrinterZoom
);
2020 return x
- getContentsX();
2024 public int contentsToViewY(int y
) {
2026 int v
= Math
.round(fPrinterY
* fPrinterZoom
);
2029 return y
- getContentsY();
2033 public int getContentsX() {
2035 return Math
.round(fPrinterX
* fPrinterZoom
);
2037 return super.getContentsX();
2041 public int getContentsY() {
2043 return Math
.round(fPrinterY
* fPrinterZoom
);
2045 return super.getContentsY();
2049 * Traverse Listener implementation.
2051 protected static class LocalTraverseListener
implements TraverseListener
{
2053 public void keyTraversed(TraverseEvent e
) {
2054 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {