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.
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 IContextService service
= (IContextService
) fSite
.getSite().getWorkbenchWindow().getService(IContextService
.class);
549 service
.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
550 service
.activateContext(IContextIds
.CONTEXT_ID_WINDOW
);
554 * Returns the GraphNode overView the mouse if any
556 * @return the current graph node
558 public GraphNode
getMouseOverNode() {
559 return fCurrentGraphNode
;
563 * Sets the zoom in mode.
566 * The mode value to set.
568 public void setZoomInMode(boolean value
) {
570 setZoomOutMode(false);
576 * Sets the zoom out mode.
579 * The mode value to set.
581 public void setZoomOutMode(boolean value
) {
583 setZoomInMode(false);
585 fZoomOutMode
= value
;
589 * Sets the current zoom value.
592 * 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
675 public GraphNode
getCurrentGraphNode() {
676 return fCurrentGraphNode
;
680 * Returns the current zoom value.
682 * @return the current zoom value
685 public float getZoomValue() {
690 * Gets the zoom in mode.
692 * @return the mode value to set.
695 public boolean getZoomInMode() {
701 * Gets the zoom out mode.
703 * @return the mode value to set.
706 public boolean getZoomOutMode() {
711 * Returns if ctrl selection
712 * @return true if ctrl selection else false
715 public boolean isCtrlSelection() {
716 return fCtrlSelection
;
720 * Returns if shift selection
721 * @return true if shift Selection else false
724 public boolean isShiftSelection() {
725 return fCtrlSelection
;
729 * Gets the overview image.
731 * @param rect Rectangle to include overview.
732 * @return the overview image
734 public Image
getOverview(Rectangle rect
) {
735 float oldzoom
= fZoomValue
;
736 if ((fOverView
!= null) && ((rect
.width
!= fOverView
.getBounds().width
) || (rect
.height
!= fOverView
.getBounds().height
))) {
740 if (fOverView
== null) {
741 int backX
= getContentsX();
742 int backY
= getContentsY();
743 setContentsPos(0, 0);
744 fOverView
= new Image(getDisplay(), rect
.width
, rect
.height
);
745 GC gcim
= new GC(fOverView
);
746 NGC context
= new NGC(this, gcim
);
747 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
748 fFrame
.draw(context
);
749 setContentsPos(backX
, backY
);
753 fZoomValue
= oldzoom
;
758 * Resets the zoom factor.
760 public void resetZoomFactor() {
761 int currentX
= Math
.round(getContentsX() / fZoomValue
);
762 int currentY
= Math
.round(getContentsY() / fZoomValue
);
764 if (fTimeBar
!= null && !fTimeBar
.isDisposed()) {
765 fTimeBar
.setZoom(fZoomValue
);
769 setContentsPos(currentX
, currentY
);
773 * Enable or disable the lifeline reodering using Drag and Drop
775 * @param mode - true to enable false otherwise
777 public void setReorderMode(boolean mode
) {
782 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
783 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
785 * @return - the re-odered sequence
787 public List
<Lifeline
[]> getLifelineReoderList() {
792 * Sets the focus on given graph node (current node).
795 * The graph node to focus on.
797 public void setFocus(GraphNode node
) {
801 if (fCurrentGraphNode
!= null) {
802 fCurrentGraphNode
.setFocused(false);
804 fCurrentGraphNode
= node
;
805 node
.setFocused(true);
811 * Returns the graph node focused on.
813 * @return the current graph node
815 public GraphNode
getFocusNode() {
816 return fCurrentGraphNode
;
820 * Method to traverse right.
822 public void traverseRight() {
823 Object selectedNode
= getFocusNode();
824 if (selectedNode
== null) {
827 GraphNode node
= null;
828 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
829 node
= fFrame
.getCalledMessage((BaseMessage
) selectedNode
);
831 if (selectedNode
instanceof BasicExecutionOccurrence
) {
832 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
834 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
835 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
836 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
< fFrame
.lifeLinesCount() - 1)) {
837 node
= fFrame
.getLifeline(i
+ 1);
849 * Method to traverse left.
851 public void traverseLeft() {
852 Object selectedNode
= getFocusNode();
853 GraphNode node
= null;
854 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
855 node
= fFrame
.getCallerMessage((BaseMessage
) selectedNode
);
857 if (selectedNode
instanceof BasicExecutionOccurrence
) {
858 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
861 if ((selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getEndLifeline() != null)) {
862 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
864 for (int i
= 0; i
< fFrame
.lifeLinesCount(); i
++) {
865 if ((selectedNode
== fFrame
.getLifeline(i
)) && (i
> 0)) {
866 node
= fFrame
.getLifeline(i
- 1);
870 if ((fFrame
.lifeLinesCount() > 0) && (node
== null)) {
871 node
= fFrame
.getLifeline(0);
881 * Method to traverse up.
883 public void traverseUp() {
884 Object selectedNode
= getFocusNode();
885 if (selectedNode
== null) {
888 GraphNode node
= null;
889 if (selectedNode
instanceof BaseMessage
) {
890 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
891 } else if (selectedNode
instanceof Lifeline
) {
892 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
893 if (!(node
instanceof Lifeline
)) {
896 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
897 node
= fFrame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
899 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
902 if ((node
== null) && (selectedNode
instanceof BaseMessage
) && (((BaseMessage
) selectedNode
).getStartLifeline() != null)) {
903 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
913 * Method to traverse down.
915 public void traverseDown() {
916 Object selectedNode
= getFocusNode();
917 if (selectedNode
== null) {
921 if (selectedNode
instanceof BaseMessage
) {
922 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
923 } else if (selectedNode
instanceof Lifeline
) {
924 node
= fFrame
.getFirstExecution((Lifeline
) selectedNode
);
925 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
926 node
= fFrame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
938 * Method to traverse home.
940 public void traverseHome() {
941 Object selectedNode
= getFocusNode();
942 if (selectedNode
== null) {
945 GraphNode node
= null;
947 if (selectedNode
instanceof BaseMessage
) {
948 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
949 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
951 node
= fFrame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
953 } else if (selectedNode
instanceof Lifeline
) {
954 node
= fFrame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
955 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
956 node
= fFrame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
958 if (fFrame
.lifeLinesCount() > 0) {
959 Lifeline lifeline
= fFrame
.getLifeline(0);
960 node
= fFrame
.getNextLifelineMessage(lifeline
, null);
971 * Method to traverse to the end.
973 public void traverseEnd() {
974 Object selectedNode
= getFocusNode();
975 if (selectedNode
== null) {
979 if (selectedNode
instanceof BaseMessage
) {
980 node
= fFrame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
981 } else if (selectedNode
instanceof Lifeline
) {
982 node
= fFrame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
983 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
984 node
= fFrame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
986 if (fFrame
.lifeLinesCount() > 0) {
987 Lifeline lifeline
= fFrame
.getLifeline(0);
988 node
= fFrame
.getPrevLifelineMessage(lifeline
, null);
1001 * Method to print UI.
1003 * @param sdPrintDialog the sequence diagram printer dialog.
1005 public void printUI(SDPrintDialogUI sdPrintDialog
) {
1006 PrinterData data
= sdPrintDialog
.getPrinterData();
1008 if ((data
== null) || (fFrame
== null)) {
1012 fPrinter
= new Printer(data
);
1014 String jobName
= MessageFormat
.format(Messages
.SequenceDiagram_plus
, new Object
[] { String
.valueOf(fSite
.getContentDescription()), String
.valueOf(fFrame
.getName()) });
1015 fPrinter
.startJob(jobName
);
1017 GC gc
= new GC(fPrinter
);
1019 float lastZoom
= fZoomValue
;
1021 Rectangle area
= getClientArea();
1025 NGC context
= new NGC(this, gcim
);
1027 // Set the metrics to use for lifeline text and message text
1028 // using the Graphical Context
1029 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1030 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1031 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1032 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1033 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1035 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
1036 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
1037 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
1038 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
1040 int messageFontHeight
= 0;
1041 if (syncMessFontH
> syncMessRetFontH
) {
1042 messageFontHeight
= syncMessFontH
;
1044 messageFontHeight
= syncMessRetFontH
;
1046 if (messageFontHeight
< asyncMessFontH
) {
1047 messageFontHeight
= asyncMessFontH
;
1049 if (messageFontHeight
< asyncMessRetFontH
) {
1050 messageFontHeight
= asyncMessRetFontH
;
1052 Metrics
.setMessageFontHeight(messageFontHeight
);
1053 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1055 int width
= Math
.round((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
1056 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1057 if (width
< area
.width
) {
1060 if (height
< area
.height
) {
1061 height
= area
.height
;
1063 resizeContents(width
, height
);
1065 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1066 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1067 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1068 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1069 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1070 gcim
.setLineWidth(1);
1072 fPrinter
.startPage();
1073 fZoomValue
= lastZoom
;
1075 int restoreX
= getContentsX();
1076 int restoreY
= getContentsY();
1078 float zh
= sdPrintDialog
.getStepY() * sdPrintDialog
.getZoomFactor();
1079 float zw
= sdPrintDialog
.getStepX() * sdPrintDialog
.getZoomFactor();
1081 float zoomValueH
= fPrinter
.getClientArea().height
/ zh
;
1082 float zoomValueW
= fPrinter
.getClientArea().width
/ zw
;
1083 if (zoomValueH
> zoomValueW
) {
1084 fPrinterZoom
= zoomValueH
;
1086 fPrinterZoom
= zoomValueW
;
1089 if (sdPrintDialog
.printSelection()) {
1090 int[] pagesList
= sdPrintDialog
.getPageList();
1092 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1093 printPage(pagesList
[pageIndex
], sdPrintDialog
, context
);
1095 } else if (sdPrintDialog
.printAll()) {
1096 for (int pageIndex
= 1; pageIndex
<= sdPrintDialog
.maxNumOfPages(); pageIndex
++) {
1097 printPage(pageIndex
, sdPrintDialog
, context
);
1099 } else if (sdPrintDialog
.printCurrent()) {
1100 printPage(getContentsX(), getContentsY(), sdPrintDialog
, context
, 1);
1101 } else if (sdPrintDialog
.printRange()) {
1102 for (int pageIndex
= sdPrintDialog
.getFrom(); pageIndex
<= sdPrintDialog
.maxNumOfPages() && pageIndex
<= sdPrintDialog
.getTo(); pageIndex
++) {
1103 printPage(pageIndex
, sdPrintDialog
, context
);
1108 fIsPrinting
= false;
1113 fZoomValue
= lastZoom
;
1115 setContentsPos(restoreX
, restoreY
);
1121 public void print() {
1122 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1124 if (sdPrinter
.open() != 0) {
1127 } catch (Exception e
) {
1128 Activator
.getDefault().logError("Error creating image", e
); //$NON-NLS-1$
1131 printUI(sdPrinter
.getDialogUI());
1135 * Method to print a page.
1137 * @param pageNum The page number
1138 * @param pd The sequence diagram print dialog
1139 * @param context The graphical context
1141 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1142 int j
= pageNum
/ pd
.getNbRow();
1143 int i
= pageNum
% pd
.getNbRow();
1153 i
= (int) (i
* pd
.getStepX());
1154 j
= (int) (j
* pd
.getStepY());
1156 printPage(i
, j
, pd
, context
, pageNum
);
1162 * Method to print page ranges.
1169 * The sequence diagram print dialog
1171 * The graphical context
1175 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1176 fIsPrinting
= false;
1177 int pageNumFontZoom
= fPrinter
.getClientArea().height
/ getVisibleHeight();
1180 setContentsPos(i
, j
);
1183 float lastZoom
= fZoomValue
;
1184 fZoomValue
= fPrinterZoom
* lastZoom
;
1186 fFrame
.draw(context
);
1188 fZoomValue
= pageNumFontZoom
;
1189 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1190 String currentPageNum
= String
.valueOf(pageNum
);
1191 int ii
= context
.textExtent(currentPageNum
);
1192 int jj
= context
.getCurrentFontHeight();
1193 fZoomValue
= fPrinterZoom
* lastZoom
;
1194 context
.drawText(currentPageNum
, Math
.round(fPrinterX
+ getVisibleWidth() / fPrinterZoom
- ii
/ fPrinterZoom
), Math
.round(fPrinterY
+ getVisibleHeight() / fPrinterZoom
- jj
/ fPrinterZoom
), false);
1195 fIsPrinting
= false;
1196 fZoomValue
= lastZoom
;
1200 * Sets the collapse provider.
1202 * @param provider The collapse provider to set
1204 protected void setCollapseProvider(ISDCollapseProvider provider
) {
1205 fCollapseProvider
= provider
;
1210 * Checks for focus of children.
1212 * @param children Control to check
1213 * @return true if child is on focus else false
1215 protected boolean checkFocusOnChilds(Control children
) {
1216 if (children
instanceof Composite
) {
1217 Control
[] child
= ((Composite
) children
).getChildren();
1218 for (int i
= 0; i
< child
.length
; i
++) {
1219 if (child
[i
].isFocusControl()) {
1222 checkFocusOnChilds(child
[i
]);
1229 * A post action for a tooltip (before displaying).
1231 * @param accessible true if accessible else false
1232 * @return the tooltip text.
1234 protected String
getPostfixForTooltip(boolean accessible
) {
1235 StringBuffer postfix
= new StringBuffer();
1236 // Determine if the tooltip must show the time difference between the current mouse position and
1237 // the last selected graphNode
1238 if ((fCurrentGraphNode
!= null) &&
1239 (fCurrentGraphNode
instanceof ITimeRange
) &&
1240 (fToolTipNode
instanceof ITimeRange
) &&
1241 (fCurrentGraphNode
!= fToolTipNode
) &&
1242 ((ITimeRange
) fToolTipNode
).hasTimeInfo() &&
1243 ((ITimeRange
) fCurrentGraphNode
).hasTimeInfo()) {
1244 postfix
.append(" -> "); //$NON-NLS-1$
1245 postfix
.append(fCurrentGraphNode
.getName());
1246 postfix
.append("\n"); //$NON-NLS-1$
1247 postfix
.append(Messages
.SequenceDiagram_Delta
);
1248 postfix
.append(" "); //$NON-NLS-1$
1250 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1251 ITmfTimestamp firstTime
= ((ITimeRange
) fCurrentGraphNode
).getEndTime();
1252 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1253 ITmfTimestamp delta
= lastTime
.getDelta(firstTime
);
1254 postfix
.append(delta
.toString());
1257 if ((fToolTipNode
instanceof ITimeRange
) && ((ITimeRange
) fToolTipNode
).hasTimeInfo()) {
1258 postfix
.append("\n"); //$NON-NLS-1$
1259 ITmfTimestamp firstTime
= ((ITimeRange
) fToolTipNode
).getStartTime();
1260 ITmfTimestamp lastTime
= ((ITimeRange
) fToolTipNode
).getEndTime();
1262 if (firstTime
!= null) {
1263 if (lastTime
!= null && firstTime
.compareTo(lastTime
, true) != 0) {
1264 postfix
.append("start: "); //$NON-NLS-1$
1265 postfix
.append(firstTime
.toString());
1266 postfix
.append("\n"); //$NON-NLS-1$
1267 postfix
.append("end: "); //$NON-NLS-1$
1268 postfix
.append(lastTime
.toString());
1269 postfix
.append("\n"); //$NON-NLS-1$
1271 postfix
.append(firstTime
.toString());
1274 else if (lastTime
!= null) {
1275 postfix
.append(lastTime
.toString());
1279 return postfix
.toString();
1283 * Sets a new focused widget.
1285 * @param newFocusShape A new focus shape.
1287 protected void setFocus(int newFocusShape
) {
1288 fFocusedWidget
= newFocusShape
;
1289 if (fFocusedWidget
== -1) {
1290 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
1292 getViewControl().getAccessible().setFocus(fFocusedWidget
);
1297 * Highlight the given GraphNode<br>
1298 * The GraphNode is then displayed using the system default selection color
1300 * @param node the GraphNode to highlight
1302 protected void performSelection(GraphNode node
) {
1303 if ((fCtrlSelection
) || (fShiftSelection
)) {
1305 if (fSelectedNodeList
.contains(node
)) {
1306 removeSelection(node
);
1322 * Returns a draw buffer image.
1324 * @return a Image containing the draw buffer.
1326 protected Image
getDrawBuffer() {
1329 Rectangle area
= getClientArea();
1330 Image dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
1331 GC gcim
= new GC(dbuffer
);
1332 NGC context
= new NGC(this, gcim
);
1334 // Set the metrics to use for lifeline text and message text
1335 // using the Graphical Context
1336 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1337 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
)));
1338 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1339 Metrics
.setFrameFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1340 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1342 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS
));
1343 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_SYNC_MESS_RET
));
1344 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS
));
1345 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_ASYNC_MESS_RET
));
1347 int messageFontHeight
= 0;
1348 if (syncMessFontH
> syncMessRetFontH
) {
1349 messageFontHeight
= syncMessFontH
;
1351 messageFontHeight
= syncMessRetFontH
;
1353 if (messageFontHeight
< asyncMessFontH
) {
1354 messageFontHeight
= asyncMessFontH
;
1356 if (messageFontHeight
< asyncMessRetFontH
) {
1357 messageFontHeight
= asyncMessRetFontH
;
1359 Metrics
.setMessageFontHeight(messageFontHeight
);
1360 context
.setFont(SDViewPref
.getInstance().getFont(ISDPreferences
.PREF_LIFELINE
));
1362 int width
= (int) ((fFrame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * fZoomValue
);
1363 int height
= (int) ((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1365 resizeContents(width
, height
);
1367 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1368 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1369 context
.fillRectangle(0, 0, fFrame
.getX(), getContentsHeight());
1370 context
.fillRectangle(fFrame
.getX() + fFrame
.getWidth() + 1, 0, getContentsWidth() - (fFrame
.getX() + fFrame
.getWidth() + 1), getContentsHeight());
1371 context
.fillRectangle(0, fFrame
.getY() + fFrame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame
.getY() + fFrame
.getHeight() + 1));
1372 gcim
.setLineWidth(1);
1374 fFrame
.draw(context
);
1375 if (fDragAndDrop
!= null) {
1376 Lifeline node
= fDragAndDrop
;
1377 boolean isSelected
= fDragAndDrop
.isSelected();
1378 boolean hasFocus
= fDragAndDrop
.hasFocus();
1379 node
.setSelected(false);
1380 node
.setFocused(false);
1381 node
.draw(context
, fDragX
, fDragY
);
1382 node
.setSelected(isSelected
);
1383 node
.setFocused(hasFocus
);
1391 protected void keyPressedEvent(KeyEvent event
) {
1392 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1393 Control
[] child
= getParent().getChildren();
1394 for (int i
= 0; i
< child
.length
; i
++) {
1395 if ((child
[i
].isFocusControl())&& (!(child
[i
] instanceof ScrollView
))) {
1396 getViewControl().setFocus();
1403 if (event
.keyCode
== SWT
.CTRL
) {
1404 fCtrlSelection
= true;
1406 if (event
.keyCode
== SWT
.SHIFT
) {
1407 fShiftSelection
= true;
1408 fPrevList
= new ArrayList
<>();
1409 fPrevList
.addAll(getSelection());
1412 GraphNode prevNode
= getFocusNode();
1414 if (event
.keyCode
== SWT
.ARROW_RIGHT
) {
1418 if (event
.keyCode
== SWT
.ARROW_LEFT
) {
1422 if (event
.keyCode
== SWT
.ARROW_DOWN
) {
1426 if (event
.keyCode
== SWT
.ARROW_UP
) {
1430 if (event
.keyCode
== SWT
.HOME
) {
1434 if (event
.keyCode
== SWT
.END
) {
1438 if ((!fShiftSelection
) && (!fCtrlSelection
)) {
1439 fListStart
= fCurrentGraphNode
;
1442 if (event
.character
== ' ') {
1443 performSelection(fCurrentGraphNode
);
1444 if (!fShiftSelection
) {
1445 fListStart
= fCurrentGraphNode
;
1449 if ((fShiftSelection
) && (prevNode
!= getFocusNode())) {
1451 addSelection(fPrevList
);
1452 addSelection(fFrame
.getNodeList(fListStart
, getFocusNode()));
1453 if (getFocusNode() instanceof Lifeline
) {
1454 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1456 ensureVisible(getFocusNode());
1458 } else if ((!fCtrlSelection
) && (!fShiftSelection
)) {
1461 if (getFocusNode() != null) {
1462 addSelection(getFocusNode());
1464 if (getFocusNode() instanceof Lifeline
) {
1465 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT
.CENTER
| SWT
.VERTICAL
, true);
1467 ensureVisible(getFocusNode());
1472 if (fCurrentGraphNode
!= null) {
1473 fCurrentGraphNode
.setFocused(true);
1477 if ((event
.character
== ' ') && ((fZoomInMode
) || (fZoomOutMode
))) {
1478 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue
);
1479 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue
);
1481 if (fZoomValue
< 64) {
1482 fZoomValue
= fZoomValue
* (float) 1.25;
1485 fZoomValue
= fZoomValue
/ (float) 1.25;
1487 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1488 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1489 setContentsPos(x
, y
);
1490 if (fTimeBar
!= null) {
1491 fTimeBar
.setZoom(fZoomValue
);
1493 // redraw also resize the scrollView content
1499 protected void keyReleasedEvent(KeyEvent event
) {
1501 if (event
.keyCode
== SWT
.CTRL
) {
1502 fCtrlSelection
= false;
1504 if (event
.keyCode
== SWT
.SHIFT
) {
1505 fShiftSelection
= false;
1507 super.keyReleasedEvent(event
);
1512 public boolean isFocusControl() {
1513 Control
[] child
= getChildren();
1514 for (int i
= 0; i
< child
.length
; i
++) {
1515 if (child
[i
].isFocusControl()) {
1518 checkFocusOnChilds(child
[i
]);
1524 public boolean setContentsPos(int x
, int y
) {
1534 if (fFrame
== null) {
1537 if (localX
+ getVisibleWidth() > getContentsWidth()) {
1538 localX
= getContentsWidth() - getVisibleWidth();
1540 if (localY
+ getVisibleHeight() > getContentsHeight()) {
1541 localY
= getContentsHeight() - getVisibleHeight();
1543 int x1
= Math
.round(localX
/ fZoomValue
);
1544 int y2
= Math
.round(localY
/ fZoomValue
);
1545 int width
= Math
.round(getVisibleWidth() / fZoomValue
);
1546 int height
= Math
.round(getVisibleHeight() / fZoomValue
);
1547 fFrame
.updateIndex(x1
, y2
, width
, height
);
1549 if (fInsertionCartet
!= null && fInsertionCartet
.isVisible()) {
1550 fInsertionCartet
.setVisible(false);
1553 return super.setContentsPos(localX
, localY
);
1557 protected void contentsMouseHover(MouseEvent event
) {
1558 GraphNode graphNode
= null;
1559 if (fFrame
!= null) {
1560 int x
= Math
.round(event
.x
/ fZoomValue
);
1561 int y
= Math
.round(event
.y
/ fZoomValue
);
1562 graphNode
= fFrame
.getNodeAt(x
, y
);
1563 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
1564 fToolTipNode
= graphNode
;
1565 String postfix
= getPostfixForTooltip(true);
1566 if (graphNode
instanceof Lifeline
) {
1567 Lifeline lifeline
= (Lifeline
) graphNode
;
1568 fToolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
1571 fToolTip
.showToolTip(graphNode
.getName() + postfix
);
1575 fToolTip
.hideToolTip();
1581 protected void contentsMouseMoveEvent(MouseEvent e
) {
1582 fScrollToolTip
.hideToolTip();
1583 fToolTip
.hideToolTip();
1584 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1585 Control
[] child
= getParent().getChildren();
1586 for (int i
= 0; i
< child
.length
; i
++) {
1587 if ((child
[i
].isFocusControl()) && (!(child
[i
] instanceof ScrollView
))) {
1588 getViewControl().setFocus();
1595 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((fDragAndDrop
!= null) || fIsDragAndDrop
) && (fReorderMode
|| fCollapseProvider
!= null)) {
1596 fIsDragAndDrop
= false;
1597 if (fCurrentGraphNode
instanceof Lifeline
) {
1598 fDragAndDrop
= (Lifeline
) fCurrentGraphNode
;
1600 if (fDragAndDrop
!= null) {
1603 if (e
.x
> getContentsX() + getVisibleWidth()) {
1604 dx
= e
.x
- (getContentsX() + getVisibleWidth());
1605 } else if (e
.x
< getContentsX()) {
1606 dx
= -getContentsX() + e
.x
;
1608 if (e
.y
> getContentsY() + getVisibleHeight()) {
1609 dy
= e
.y
- (getContentsY() + getVisibleHeight());
1610 } else if (e
.y
< getContentsY()) {
1611 dy
= -getContentsY() + e
.y
;
1615 if (dx
!= 0 || dy
!= 0) {
1616 if (fLocalAutoScroll
== null) {
1617 if (fLocalAutoScrollTimer
== null) {
1618 fLocalAutoScrollTimer
= new Timer(true);
1620 fLocalAutoScroll
= new AutoScroll(this, dx
, dy
);
1621 fLocalAutoScrollTimer
.schedule(fLocalAutoScroll
, 0, 75);
1623 fLocalAutoScroll
.fDeltaX
= dx
;
1624 fLocalAutoScroll
.fDeltaY
= dy
;
1626 } else if (fLocalAutoScroll
!= null) {
1627 fLocalAutoScroll
.cancel();
1628 fLocalAutoScroll
= null;
1630 fDragX
= Math
.round(e
.x
/ fZoomValue
);
1631 fDragY
= Math
.round(e
.y
/ fZoomValue
);
1633 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1634 if ((node
!= null) && (node
!= fDragAndDrop
)) {
1637 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
1638 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
1639 int x
= node
.getX();
1640 int width
= node
.getWidth();
1641 if (fFrame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
) {
1642 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * fZoomValue
));
1644 y
= Math
.round(height
* fZoomValue
);
1647 if (fFrame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
)) {
1648 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * fZoomValue
));
1650 y1
= Math
.round(height
* fZoomValue
);
1653 int rx
= Math
.round(x
* fZoomValue
);
1655 fInsertionCartet
.setVisible(true);
1656 if ((fInsertionCartet
.getImage() != null) && (!fInsertionCartet
.getImage().isDisposed())) {
1657 fInsertionCartet
.getImage().dispose();
1659 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* fZoomValue
)) >= e
.x
) {
1660 if (fCollapseProvider
!= null) {
1661 ImageData data
= fCollapaseCaretImg
.getImageData();
1662 data
= data
.scaledTo(Math
.round(fCollapaseCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fCollapaseCaretImg
.getBounds().height
* fZoomValue
));
1663 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1664 fInsertionCartet
.setImage(fCurrentCaretImage
);
1665 fInsertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y
);
1667 } else if (fReorderMode
) {
1669 if (node
.getIndex() > 1 && fFrame
.getLifeline(node
.getIndex() - 2) == fDragAndDrop
) {
1672 ImageData data
= fArrowUpCaretImg
.getImageData();
1673 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1674 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1675 fInsertionCartet
.setImage(fCurrentCaretImage
);
1676 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2, y1
);
1678 if (node
.getIndex() < fFrame
.lifeLinesCount() && fFrame
.getLifeline(node
.getIndex()) == fDragAndDrop
) {
1681 ImageData data
= fArrowUpCaretImg
.getImageData();
1682 data
= data
.scaledTo(Math
.round(fArrowUpCaretImg
.getBounds().width
* fZoomValue
), Math
.round(fArrowUpCaretImg
.getBounds().height
* fZoomValue
));
1683 fCurrentCaretImage
= new Image(Display
.getCurrent(), data
);
1684 fInsertionCartet
.setImage(fCurrentCaretImage
);
1685 fInsertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * fZoomValue
)) - fCurrentCaretImage
.getBounds().width
/ 2 + 1, y1
);
1689 fInsertionCartet
.setVisible(false);
1693 super.contentsMouseMoveEvent(e
);
1698 protected void contentsMouseUpEvent(MouseEvent event
) {
1699 // Just in case the diagram highlight a time compression region
1700 // this region need to be released when clicking everywhere
1701 fInsertionCartet
.setVisible(false);
1702 if (fDragAndDrop
!= null) {
1703 if ((fOverView
!= null) && (!fOverView
.isDisposed())) {
1704 fOverView
.dispose();
1707 Lifeline node
= fFrame
.getCloserLifeline(fDragX
);
1709 int rx
= Math
.round(node
.getX() * fZoomValue
);
1710 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * fZoomValue
)) >= event
.x
) {
1711 if ((fCollapseProvider
!= null) && (fDragAndDrop
!= node
)) {
1712 fCollapseProvider
.collapseTwoLifelines(fDragAndDrop
, node
);
1714 } else if (rx
< event
.x
) {
1715 fFrame
.insertLifelineAfter(fDragAndDrop
, node
);
1716 if (node
.getIndex() < fFrame
.lifeLinesCount()) {
1717 Lifeline temp
[] = { fDragAndDrop
, fFrame
.getLifeline(node
.getIndex()) };
1718 fReorderList
.add(temp
);
1720 Lifeline temp
[] = { fDragAndDrop
, null };
1721 fReorderList
.add(temp
);
1724 fFrame
.insertLifelineBefore(fDragAndDrop
, node
);
1725 Lifeline temp
[] = { fDragAndDrop
, node
};
1726 fReorderList
.add(temp
);
1730 fDragAndDrop
= null;
1732 if (fFrame
== null) {
1735 fFrame
.resetTimeCompression();
1737 // reset auto scroll if it's engaged
1738 if (fLocalAutoScroll
!= null) {
1739 fLocalAutoScroll
.cancel();
1740 fLocalAutoScroll
= null;
1742 super.contentsMouseUpEvent(event
);
1746 protected void contentsMouseDownEvent(MouseEvent event
) {
1747 if (fCurrentGraphNode
!= null) {
1748 fCurrentGraphNode
.setFocused(false);
1751 // Just in case the diagram highlight a time compression region
1752 // this region need to be released when clicking everywhere
1753 if (fFrame
== null) {
1757 fFrame
.resetTimeCompression();
1759 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
1760 fCtrlSelection
= true;
1762 fCtrlSelection
= false;
1765 if (((fZoomInMode
) || (fZoomOutMode
)) && (event
.button
== 1)) {
1766 int cx
= Math
.round(event
.x
/ fZoomValue
);
1767 int cy
= Math
.round(event
.y
/ fZoomValue
);
1769 if (fZoomValue
< 64) {
1770 fZoomValue
= fZoomValue
* (float) 1.25;
1773 fZoomValue
= fZoomValue
/ (float) 1.25;
1775 int x
= Math
.round(cx
* fZoomValue
- getVisibleWidth() / (float) 2);
1776 int y
= Math
.round(cy
* fZoomValue
- getVisibleHeight() / (float) 2);
1777 setContentsPos(x
, y
);
1778 if (fTimeBar
!= null) {
1779 fTimeBar
.setZoom(fZoomValue
);
1781 // redraw also resize the scrollView content
1784 GraphNode node
= null;
1785 int x
= Math
.round(event
.x
/ fZoomValue
);
1786 int y
= Math
.round(event
.y
/ fZoomValue
);
1787 node
= fFrame
.getNodeAt(x
, y
);
1789 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
1790 if (!fShiftSelection
) {
1793 if (fShiftSelection
) {
1795 addSelection(fFrame
.getNodeList(fListStart
, node
));
1797 performSelection(node
);
1799 fCurrentGraphNode
= node
;
1801 node
.setFocused(true);
1806 if (fDragAndDrop
== null) {
1807 super.contentsMouseDownEvent(event
);
1809 fIsDragAndDrop
= (event
.button
== 1);
1814 * TimerTask for auto scroll feature.
1816 protected static class AutoScroll
extends TimerTask
{
1826 * Field sequence diagram reference.
1828 public SDWidget fSdWidget
;
1831 * Constructor for AutoScroll.
1832 * @param sv sequence diagram widget reference
1836 public AutoScroll(SDWidget sv
, int dx
, int dy
) {
1844 Display display
= Display
.getDefault();
1845 if ((display
== null) || (display
.isDisposed())) {
1848 display
.asyncExec(new Runnable() {
1851 if (fSdWidget
.isDisposed()) {
1854 fSdWidget
.fDragX
+= fDeltaX
;
1855 fSdWidget
.fDragY
+= fDeltaY
;
1856 fSdWidget
.scrollBy(fDeltaX
, fDeltaY
);
1863 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1864 if (fFrame
== null) {
1865 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1866 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1870 SDViewPref
.getInstance();
1872 Rectangle area
= getClientArea();
1873 Image dbuffer
= getDrawBuffer();
1874 int height
= Math
.round((fFrame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * fZoomValue
);
1877 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1878 } catch (Exception e
) {
1879 Activator
.getDefault().logError("Error drawin content", e
); //$NON-NLS-1$
1882 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * fZoomValue
));
1883 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * fZoomValue
));
1884 if ((fTimeBar
!= null) && (fFrame
.hasTimeInfo())) {
1885 fTimeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1886 fTimeBar
.setContentsPos(getContentsX(), getContentsY());
1890 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1891 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1892 if (yRatio
> xRatio
) {
1893 setOverviewSize((int) (getVisibleHeight() * 0.75));
1895 setOverviewSize((int) (getVisibleWidth() * 0.75));
1900 public void widgetDefaultSelected(SelectionEvent event
) {
1904 public void widgetSelected(SelectionEvent event
) {
1905 if (event
.widget
== fZoomIn
) {
1906 fZoomValue
= fZoomValue
* 2;
1907 } else if (event
.widget
== fZoomOut
) {
1908 fZoomValue
= fZoomValue
/ 2;
1914 * Called when property changed occurs in the preference page. "PREFOK" is
1915 * fired when the user press the ok or apply button
1918 public void propertyChange(PropertyChangeEvent e
) {
1919 if (fFrame
!= null && !isDisposed()) {
1920 fFrame
.resetTimeCompression();
1922 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1924 // Prepare the overview to be reused for the new
1925 // settings (especially the colors)
1926 if (fOverView
!= null) {
1927 fOverView
.dispose();
1935 public void widgetDisposed(DisposeEvent e
) {
1936 if (fOverView
!= null) {
1937 fOverView
.dispose();
1939 super.removeDisposeListener(this);
1940 if ((fCurrentCaretImage
!= null) && (!fCurrentCaretImage
.isDisposed())) {
1941 fCurrentCaretImage
.dispose();
1943 if ((fArrowUpCaretImg
!= null) && (!fArrowUpCaretImg
.isDisposed())) {
1944 fArrowUpCaretImg
.dispose();
1946 if ((fCollapaseCaretImg
!= null) && (!fCollapaseCaretImg
.isDisposed())) {
1947 fCollapaseCaretImg
.dispose();
1949 SDViewPref
.getInstance().removePropertyChangeListener(this);
1950 LoadersManager lm
= LoadersManager
.getInstance();
1951 if (fSite
instanceof SDView
) {
1952 ((SDView
) fSite
).resetProviders();
1954 lm
.resetLoader(((SDView
) fSite
).getViewSite().getId());
1960 protected void drawOverview(GC gc
, Rectangle r
) {
1961 float oldzoom
= fZoomValue
;
1962 if (getContentsWidth() > getContentsHeight()) {
1963 fZoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
1965 fZoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
1967 if ((fOverView
!= null) && ((r
.width
!= fOverView
.getBounds().width
) || (r
.height
!= fOverView
.getBounds().height
))) {
1968 fOverView
.dispose();
1971 if (fOverView
== null) {
1972 int backX
= getContentsX();
1973 int backY
= getContentsY();
1974 setContentsPos(0, 0);
1975 fOverView
= new Image(getDisplay(), r
.width
, r
.height
);
1976 GC gcim
= new GC(fOverView
);
1977 NGC context
= new NGC(this, gcim
);
1978 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1979 fFrame
.draw(context
);
1980 setContentsPos(backX
, backY
);
1984 if ((fOverView
!= null) && (r
.width
== fOverView
.getBounds().width
) && (r
.height
== fOverView
.getBounds().height
)) {
1985 gc
.drawImage(fOverView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
1988 fZoomValue
= oldzoom
;
1990 super.drawOverview(gc
, r
);
1994 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
1995 fFrame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
1996 ensureVisible(lifeline
);
1997 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
1998 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
1999 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
2005 public int getVisibleWidth() {
2007 return fPrinter
.getClientArea().width
;
2009 return super.getVisibleWidth();
2013 public int getVisibleHeight() {
2015 return fPrinter
.getClientArea().height
;
2017 return super.getVisibleHeight();
2021 public int contentsToViewX(int x
) {
2023 int v
= Math
.round(fPrinterX
* fPrinterZoom
);
2026 return x
- getContentsX();
2030 public int contentsToViewY(int y
) {
2032 int v
= Math
.round(fPrinterY
* fPrinterZoom
);
2035 return y
- getContentsY();
2039 public int getContentsX() {
2041 return Math
.round(fPrinterX
* fPrinterZoom
);
2043 return super.getContentsX();
2047 public int getContentsY() {
2049 return Math
.round(fPrinterY
* fPrinterZoom
);
2051 return super.getContentsY();
2055 * Traverse Listener implementation.
2057 protected static class LocalTraverseListener
implements TraverseListener
{
2059 public void keyTraversed(TraverseEvent e
) {
2060 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {