1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
;
16 import java
.text
.MessageFormat
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
19 import java
.util
.Timer
;
20 import java
.util
.TimerTask
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.jface
.contexts
.IContextIds
;
25 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
26 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
27 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
28 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
29 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.ITmfImageConstants
;
30 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BaseMessage
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ITimeRange
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Metrics
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.SDPrintDialog
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.SDPrintDialogUI
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IColor
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDCollapseProvider
;
44 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
45 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
46 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
47 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
48 import org
.eclipse
.swt
.SWT
;
49 import org
.eclipse
.swt
.accessibility
.ACC
;
50 import org
.eclipse
.swt
.accessibility
.Accessible
;
51 import org
.eclipse
.swt
.accessibility
.AccessibleAdapter
;
52 import org
.eclipse
.swt
.accessibility
.AccessibleControlAdapter
;
53 import org
.eclipse
.swt
.accessibility
.AccessibleControlEvent
;
54 import org
.eclipse
.swt
.accessibility
.AccessibleEvent
;
55 import org
.eclipse
.swt
.events
.DisposeEvent
;
56 import org
.eclipse
.swt
.events
.DisposeListener
;
57 import org
.eclipse
.swt
.events
.FocusEvent
;
58 import org
.eclipse
.swt
.events
.FocusListener
;
59 import org
.eclipse
.swt
.events
.KeyEvent
;
60 import org
.eclipse
.swt
.events
.MouseEvent
;
61 import org
.eclipse
.swt
.events
.SelectionEvent
;
62 import org
.eclipse
.swt
.events
.SelectionListener
;
63 import org
.eclipse
.swt
.events
.TraverseEvent
;
64 import org
.eclipse
.swt
.events
.TraverseListener
;
65 import org
.eclipse
.swt
.graphics
.GC
;
66 import org
.eclipse
.swt
.graphics
.Image
;
67 import org
.eclipse
.swt
.graphics
.ImageData
;
68 import org
.eclipse
.swt
.graphics
.Rectangle
;
69 import org
.eclipse
.swt
.printing
.Printer
;
70 import org
.eclipse
.swt
.printing
.PrinterData
;
71 import org
.eclipse
.swt
.widgets
.Canvas
;
72 import org
.eclipse
.swt
.widgets
.Caret
;
73 import org
.eclipse
.swt
.widgets
.Composite
;
74 import org
.eclipse
.swt
.widgets
.Control
;
75 import org
.eclipse
.swt
.widgets
.Display
;
76 import org
.eclipse
.swt
.widgets
.Event
;
77 import org
.eclipse
.swt
.widgets
.Listener
;
78 import org
.eclipse
.swt
.widgets
.MenuItem
;
79 import org
.eclipse
.ui
.contexts
.IContextService
;
80 import org
.eclipse
.ui
.part
.ViewPart
;
84 * This class implements sequence diagram widget used in the sequence diagram view.
91 public class SDWidget
extends ScrollView
implements SelectionListener
, IPropertyChangeListener
, DisposeListener
, ITimeCompressionListener
{
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * The frame to display in the sequence diagram widget.
100 protected Frame frame
;
102 * The overview image to display.
104 protected Image overView
= null;
106 * The zoom in menu item.
108 protected MenuItem zoomIn
= null;
110 * The zoom out menu item.
112 protected MenuItem zoomOut
= null;
114 * The sequence diagram selection provider.
116 protected SDWidgetSelectionProvider selProvider
= null;
118 * The current zoom value.
120 public float zoomValue
= 1;
122 * The current zoomInMode (true for zoom in).
124 protected boolean zoomInMode
= false;
126 * The current zoomOutMode (true for zoom out).
128 protected boolean zoomOutMode
= false;
130 * The current list of selected graph nodes.
132 protected List
<GraphNode
> selectedNodeList
= null;
134 * Flag whether ctrl button is selected or not.
136 protected boolean ctrlSelection
= false;
138 * A reference to the view site.
140 protected ViewPart site
= null;
142 * The current graph node (the last selected one).
144 public GraphNode currentGraphNode
= null;
146 * The first graph node in list (multiple selection).
148 public GraphNode listStart
= null;
150 * The previous graph node (multiple selection).
152 public ArrayList
<GraphNode
> prevList
= null;
154 * The time compression bar.
156 protected TimeCompressionBar timeBar
= null;
158 * The current diagram tool tip.
160 protected DiagramToolTip toolTip
= null;
162 * The accessible object reference of view control.
164 protected Accessible accessible
= null;
166 * The current node for the tooltip to display.
168 protected GraphNode toolTipNode
;
170 * The life line to drag and drop.
172 protected Lifeline dragAndDrop
= null;
174 * The number of focused widgets.
176 protected int focusedWidget
= -1;
180 protected float printerZoom
= 0;
182 * Y coordinate for printer.
184 protected int printerY
= 0;
186 * X coordinate for printer.
188 protected int printerX
= 0;
190 * Flag whether drag and drop is enabled or not.
192 protected boolean getDragAndDrop
= false;
194 * The x coordinate for drag.
196 protected int dragX
= 0;
198 * The y coordinate for drag.
200 protected int dragY
= 0;
204 protected boolean reorderMode
= false;
206 * The collapse caret image.
208 protected Image collapaseCaretImg
= null;
210 * The arrow up caret image.
212 protected Image arrowUpCaretImg
= null;
214 * The current caret image.
216 protected Image currentCaretImage
= null;
218 * A sequence diagramm collapse provider (for collapsing graph nodes)
220 protected ISDCollapseProvider collapseProvider
= null;
222 * The insertion caret.
224 protected Caret insertionCartet
= null;
227 * The reorder list when in reorder mode.
229 protected ArrayList
<Lifeline
[]> reorderList
= null;
231 * Flag to specify whether in printing mode or not.
233 protected boolean printing
= false;
235 * A printer reference.
237 protected Printer printer
= null;
239 * Flag whether shift was selected or not.
241 protected boolean shiftSelection
= false;
243 * The scroll tooltip.
245 protected DiagramToolTip scrollToolTip
= null;
247 * Timer for auto_scroll feature
249 protected AutoScroll local_auto_scroll_
= null;
251 * TimerTask for auto_scroll feature !=null when auto scroll is running
253 protected Timer local_auto_scroll_timer_
= null;
255 // ------------------------------------------------------------------------
257 // ------------------------------------------------------------------------
259 * Constructor for SDWidget.
260 * @param c The parent composite
263 public SDWidget(Composite c
, int s
) {
264 super(c
, s
| SWT
.NO_BACKGROUND
, true);
265 setOverviewEnabled(true);
266 selectedNodeList
= new ArrayList
<GraphNode
>();
267 selProvider
= new SDWidgetSelectionProvider();
268 SDViewPref
.getInstance().addPropertyChangeListener(this);
269 toolTip
= new DiagramToolTip(getViewControl());
270 super.addDisposeListener(this);
272 scrollToolTip
= new DiagramToolTip(c
);
273 getVerticalBar().addListener(SWT
.MouseUp
, new Listener() {
276 public void handleEvent(Event event
) {
277 scrollToolTip
.hideToolTip();
281 accessible
= getViewControl().getAccessible();
283 accessible
.addAccessibleListener(new AccessibleAdapter() {
286 * @see org.eclipse.swt.accessibility.AccessibleAdapter#getName(org.eclipse.swt.accessibility.AccessibleEvent)
289 public void getName(AccessibleEvent e
) {
291 if (e
.childID
== 0) {
292 if (toolTipNode
!= null) {
293 if (toolTipNode
instanceof Lifeline
) {
294 Lifeline lifeline
= (Lifeline
) toolTipNode
;
295 e
.result
= lifeline
.getToolTipText();
297 e
.result
= toolTipNode
.getName() + getPostfixForTooltip(true);
301 if (getFocusNode() != null) {
302 if (getFocusNode() instanceof Lifeline
) {
303 e
.result
= MessageFormat
.format(SDMessages
._1
, new Object
[] { String
.valueOf(getFocusNode().getName()) });
305 if (getFocusNode() instanceof BaseMessage
) {
306 BaseMessage mes
= (BaseMessage
) getFocusNode();
307 if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() != null)) {
308 e
.result
= MessageFormat
.format(
310 new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()), String
.valueOf(mes
.getEndLifeline().getName()),
311 Integer
.valueOf(mes
.getEndOccurrence()) });
312 } else if ((mes
.getStartLifeline() == null) && (mes
.getEndLifeline() != null)) {
313 e
.result
= MessageFormat
.format(SDMessages
._4
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getEndLifeline().getName()), Integer
.valueOf(mes
.getEndOccurrence()) });
314 } else if ((mes
.getStartLifeline() != null) && (mes
.getEndLifeline() == null)) {
315 e
.result
= MessageFormat
.format(SDMessages
._3
, new Object
[] { String
.valueOf(mes
.getName()), String
.valueOf(mes
.getStartLifeline().getName()), Integer
.valueOf(mes
.getStartOccurrence()) });
317 } else if (getFocusNode() instanceof BasicExecutionOccurrence
) {
318 BasicExecutionOccurrence exec
= (BasicExecutionOccurrence
) getFocusNode();
319 e
.result
= MessageFormat
.format(SDMessages
._5
,
320 new Object
[] { String
.valueOf(exec
.getName()), String
.valueOf(exec
.getLifeline().getName()), Integer
.valueOf(exec
.getStartOccurrence()), Integer
.valueOf(exec
.getEndOccurrence()) });
328 accessible
.addAccessibleControlListener(new AccessibleControlAdapter() {
331 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getFocus(org.eclipse.swt.accessibility.AccessibleControlEvent)
334 public void getFocus(AccessibleControlEvent e
) {
335 if (focusedWidget
== -1) {
336 e
.childID
= ACC
.CHILDID_SELF
;
338 e
.childID
= focusedWidget
;
344 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getRole(org.eclipse.swt.accessibility.AccessibleControlEvent)
347 public void getRole(AccessibleControlEvent e
) {
349 case ACC
.CHILDID_SELF
:
350 e
.detail
= ACC
.ROLE_CLIENT_AREA
;
353 e
.detail
= ACC
.ROLE_TOOLTIP
;
356 e
.detail
= ACC
.ROLE_LABEL
;
363 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getState(org.eclipse.swt.accessibility.AccessibleControlEvent)
366 public void getState(AccessibleControlEvent e
) {
367 e
.detail
= ACC
.STATE_FOCUSABLE
;
368 if (e
.childID
== ACC
.CHILDID_SELF
) {
369 e
.detail
|= ACC
.STATE_FOCUSED
;
371 e
.detail
|= ACC
.STATE_SELECTABLE
;
372 if (e
.childID
== focusedWidget
)
373 e
.detail
|= ACC
.STATE_FOCUSED
| ACC
.STATE_SELECTED
| ACC
.STATE_CHECKED
;
378 insertionCartet
= new Caret((Canvas
) getViewControl(), SWT
.NONE
);
379 insertionCartet
.setVisible(false);
381 collapaseCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_COLLAPSE_OBJ
);
382 arrowUpCaretImg
= TmfUiPlugin
.getDefault().getImageFromPath(ITmfImageConstants
.IMG_UI_ARROW_UP_OBJ
);
384 reorderList
= new ArrayList
<Lifeline
[]>();
385 getViewControl().addTraverseListener(new TraverseListener() {
389 * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
392 public void keyTraversed(TraverseEvent e
) {
393 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {
400 addTraverseListener(new TraverseListener() {
404 * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
407 public void keyTraversed(TraverseEvent e
) {
408 if ((e
.detail
== SWT
.TRAVERSE_TAB_NEXT
) || (e
.detail
== SWT
.TRAVERSE_TAB_PREVIOUS
)) {
415 getViewControl().addFocusListener(new FocusListener() {
419 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
422 public void focusGained(FocusEvent e
) {
423 // TODO Auto-generated method stub
424 SDViewPref
.getInstance().setNoFocusSelection(false);
425 ctrlSelection
= false;
426 shiftSelection
= false;
432 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
435 public void focusLost(FocusEvent e
) {
436 SDViewPref
.getInstance().setNoFocusSelection(true);
442 // ------------------------------------------------------------------------
444 // ------------------------------------------------------------------------
446 * Sets the time compression bar.
448 * @param bar The time compression bar to set
450 public void setTimeBar(TimeCompressionBar bar
) {
453 timeBar
.addTimeCompressionListener(this);
458 * Resize the contents to insure the frame fit into the view
460 * @param frame the frame which will be drawn in the view
462 public void resizeContents(Frame frame
) {
463 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
464 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
465 resizeContents(width
, height
);
469 * The frame to render (the sequence diagram)
471 * @param theFrame the frame to display
472 * @param resetPosition boolean
474 public void setFrame(Frame theFrame
, boolean resetPosition
) {
476 selectedNodeList
.clear();
477 selProvider
.setSelection(new StructuredSelection());
480 setContentsPos(0, 0);
481 resizeContents(frame
);
484 // prepare the old overview to be reused
485 if (overView
!= null) {
489 resizeContents(frame
);
493 * Returns the current Frame (the sequence diagram container)
497 public Frame
getFrame() {
502 * Returns the selection provider for the current sequence diagram
504 * @return the selection provider
506 public ISelectionProvider
getSelectionProvider() {
511 * Returns a list of selected graph nodes.
513 * @return a list of selected graph nodes.
515 public List
<GraphNode
> getSelection() {
516 return selectedNodeList
;
520 * Adds a graph node to the selected nodes list.
522 * @param node A graph node
524 public void addSelection(GraphNode node
) {
528 selectedNodeList
.add(node
);
529 node
.setSelected(true);
530 currentGraphNode
= node
;
531 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
532 selProvider
.setSelection(selection
);
536 * Adds a list of node to the selected nodes list.
538 * @param list of graph nodes
540 public void addSelection(List
<GraphNode
> list
) {
541 // selectedNodeList.addAll(list);
542 for (int i
= 0; i
< list
.size(); i
++) {
543 if (!selectedNodeList
.contains(list
.get(i
))) {
544 selectedNodeList
.add(list
.get(i
));
545 ((GraphNode
) list
.get(i
)).setSelected(true);
548 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
549 selProvider
.setSelection(selection
);
553 * Removes a node from the selected nodes list.
555 * @param node to remove
557 public void removeSelection(GraphNode node
) {
558 selectedNodeList
.remove(node
);
559 node
.setSelected(false);
560 node
.setFocused(false);
561 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
562 selProvider
.setSelection(selection
);
566 * Removes a list of graph nodes from the selected nodes list.
568 * @param list of nodes to remove.
570 public void removeSelection(List
<GraphNode
> list
) {
571 selectedNodeList
.removeAll(list
);
572 for (int i
= 0; i
< list
.size(); i
++) {
573 ((GraphNode
) list
.get(i
)).setSelected(false);
574 ((GraphNode
) list
.get(i
)).setFocused(false);
576 StructuredSelection selection
= new StructuredSelection(selectedNodeList
);
577 selProvider
.setSelection(selection
);
581 * Clear the list of GraphNodes which must be drawn selected.
583 public void clearSelection() {
584 for (int i
= 0; i
< selectedNodeList
.size(); i
++) {
585 ((GraphNode
) selectedNodeList
.get(i
)).setSelected(false);
586 ((GraphNode
) selectedNodeList
.get(i
)).setFocused(false);
588 currentGraphNode
= null;
589 selectedNodeList
.clear();
590 selProvider
.setSelection(new StructuredSelection());
596 * @param viewSite The view part to set
598 public void setSite(ViewPart viewSite
) {
600 site
.getSite().setSelectionProvider(selProvider
);
601 IContextService service
= (IContextService
) site
.getSite().getWorkbenchWindow().getService(IContextService
.class);
602 service
.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
603 service
.activateContext(IContextIds
.CONTEXT_ID_WINDOW
);
607 * Returns the GraphNode overView the mouse if any
609 * @return the current graph node
611 public GraphNode
getMouseOverNode() {
612 return currentGraphNode
;
616 * Sets the zoom in mode.
618 * @param The mode value to set.
620 public void setZoomInMode(boolean value
) {
622 setZoomOutMode(false);
628 * Sets the zoom out mode.
630 * @param The mode value to set.
632 public void setZoomOutMode(boolean value
) {
634 setZoomInMode(false);
640 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
642 * @param node the GraphNode to move to
644 public void moveTo(GraphNode node
) {
654 * Moves the Sequence diagram to ensure the given node is visible
656 * @param node the GraphNode to move to
658 public void ensureVisible(GraphNode node
) {
662 int x
= Math
.round(node
.getX() * zoomValue
);
663 int y
= Math
.round(node
.getY() * zoomValue
);
664 int width
= Math
.round(node
.getWidth() * zoomValue
);
665 int height
= Math
.round(node
.getHeight() * zoomValue
);
666 if (node
instanceof BaseMessage
) {
668 int header
= Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
* 2 + Metrics
.getLifelineHeaderFontHeigth();
669 height
= -Math
.round((Metrics
.getMessagesSpacing() + header
) * zoomValue
);
670 y
= y
+ Math
.round(Metrics
.SYNC_INTERNAL_MESSAGE_HEIGHT
* zoomValue
);
673 if (node
instanceof BasicExecutionOccurrence
) {
677 if (node
instanceof Lifeline
) {
679 height
= getVisibleHeight();
681 ensureVisible(x
, y
, width
, height
, SWT
.CENTER
, true);
686 * Returns the current zoom factor.
687 * @return the current zoom factor.
689 public float getZoomFactor() {
694 * Returns teh printer reference.
696 * @return the printer reference
698 public Printer
getPrinter() {
703 * Returns whether the widget is used for printing or not.
705 * @return whether the widget is used for printing or not
707 public boolean isPrinting() {
712 * Gets the overview image.
714 * @param rect Rectangle to include overview.
715 * @return the overview image
717 public Image
getOverview(Rectangle rect
) {
718 float oldzoom
= zoomValue
;
719 if ((overView
!= null) && ((rect
.width
!= overView
.getBounds().width
) || (rect
.height
!= overView
.getBounds().height
))) {
723 if (overView
== null) {
724 int backX
= getContentsX();
725 int backY
= getContentsY();
726 setContentsPos(0, 0);
727 overView
= new Image(getDisplay(), rect
.width
, rect
.height
);
728 GC gcim
= new GC(overView
);
729 NGC context
= new NGC(this, gcim
);
730 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
732 setContentsPos(backX
, backY
);
741 * Resets the zoom factor.
743 public void resetZoomFactor() {
744 int currentX
= Math
.round(getContentsX() / zoomValue
);
745 int currentY
= Math
.round(getContentsY() / zoomValue
);
747 if (timeBar
!= null && !timeBar
.isDisposed()) {
748 timeBar
.setZoom(zoomValue
);
752 setContentsPos(currentX
, currentY
);
756 * Enable or disable the lifeline reodering using Drag and Drop
758 * @param mode - true to enable false otherwise
760 public void setReorderMode(boolean mode
) {
765 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
766 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
768 * @return - the re-odered sequence
770 public ArrayList
<Lifeline
[]> getLifelineReoderList() {
775 * Sets the focus on given graph node (current node).
777 * @param the graph node to focus on.
779 public void setFocus(GraphNode node
) {
783 if (currentGraphNode
!= null) {
784 currentGraphNode
.setFocused(false);
786 currentGraphNode
= node
;
787 node
.setFocused(true);
793 * Returns the graph node focused on.
795 * @return the current graph node
797 public GraphNode
getFocusNode() {
798 return currentGraphNode
;
802 * Method to traverse right.
804 public void traverseRight() {
805 Object selectedNode
= getFocusNode();
806 if (selectedNode
== null) {
809 GraphNode node
= null;
810 if (selectedNode
instanceof BaseMessage
) {
811 if (((BaseMessage
) selectedNode
).getEndLifeline() != null) {
812 node
= frame
.getCalledMessage((BaseMessage
) selectedNode
);
815 if (selectedNode
instanceof BasicExecutionOccurrence
) {
816 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
818 if ((node
== null) && (selectedNode
instanceof Lifeline
)) {
819 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
820 if ((selectedNode
== frame
.getLifeline(i
)) && (i
< frame
.lifeLinesCount() - 1)) {
821 node
= frame
.getLifeline(i
+ 1);
833 * Method to traverse left.
835 public void traverseLeft() {
836 Object selectedNode
= getFocusNode();
837 GraphNode node
= null;
838 if (selectedNode
instanceof BaseMessage
) {
839 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
840 node
= frame
.getCallerMessage((BaseMessage
) selectedNode
);
843 if (selectedNode
instanceof BasicExecutionOccurrence
) {
844 selectedNode
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
847 if (selectedNode
instanceof BaseMessage
) {
848 if (((BaseMessage
) selectedNode
).getEndLifeline() != null) {
849 selectedNode
= ((BaseMessage
) selectedNode
).getEndLifeline();
852 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
853 if ((selectedNode
== frame
.getLifeline(i
)) && (i
> 0)) {
854 node
= frame
.getLifeline(i
- 1);
858 if ((frame
.lifeLinesCount() > 0) && (node
== null)) {
859 node
= frame
.getLifeline(0);
869 * Method to traverse up.
871 public void traverseUp() {
872 Object selectedNode
= getFocusNode();
873 if (selectedNode
== null) {
876 GraphNode node
= null;
877 if (selectedNode
instanceof BaseMessage
) {
878 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
879 } else if (selectedNode
instanceof Lifeline
) {
880 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
881 if (!(node
instanceof Lifeline
)) {
884 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
885 node
= frame
.getPrevExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
887 node
= ((BasicExecutionOccurrence
) selectedNode
).getLifeline();
891 if (selectedNode
instanceof BaseMessage
) {
892 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
893 node
= ((BaseMessage
) selectedNode
).getStartLifeline();
905 * Method to traverse down.
907 public void traverseDown() {
908 Object selectedNode
= getFocusNode();
909 if (selectedNode
== null) {
913 if (selectedNode
instanceof BaseMessage
) {
914 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), (BaseMessage
) selectedNode
);
915 } else if (selectedNode
instanceof Lifeline
) {
916 // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
917 node
= frame
.getFirstExecution((Lifeline
) selectedNode
);
918 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
919 node
= frame
.getNextExecOccurrence((BasicExecutionOccurrence
) selectedNode
);
931 * Method to traverse home.
933 public void traverseHome() {
934 Object selectedNode
= getFocusNode();
935 if (selectedNode
== null) {
938 GraphNode node
= null;
940 if (selectedNode
instanceof BaseMessage
) {
941 if (((BaseMessage
) selectedNode
).getStartLifeline() != null) {
942 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
944 node
= frame
.getNextLifelineMessage(((BaseMessage
) selectedNode
).getEndLifeline(), null);
946 } else if (selectedNode
instanceof Lifeline
) {
947 node
= frame
.getNextLifelineMessage((Lifeline
) selectedNode
, null);
948 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
949 node
= frame
.getFirstExecution(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
951 if (frame
.lifeLinesCount() > 0) {
952 Lifeline lifeline
= frame
.getLifeline(0);
953 node
= frame
.getNextLifelineMessage(lifeline
, null);
964 * Method to traverse to the end.
966 public void traverseEnd() {
967 Object selectedNode
= getFocusNode();
968 if (selectedNode
== null) {
972 if (selectedNode
instanceof BaseMessage
) {
973 node
= frame
.getPrevLifelineMessage(((BaseMessage
) selectedNode
).getStartLifeline(), null);
974 } else if (selectedNode
instanceof Lifeline
) {
975 node
= frame
.getPrevLifelineMessage((Lifeline
) selectedNode
, null);
976 } else if (selectedNode
instanceof BasicExecutionOccurrence
) {
977 node
= frame
.getLastExecOccurrence(((BasicExecutionOccurrence
) selectedNode
).getLifeline());
979 if (frame
.lifeLinesCount() > 0) {
980 Lifeline lifeline
= frame
.getLifeline(0);
981 node
= frame
.getPrevLifelineMessage(lifeline
, null);
994 * Method to print UI.
996 * @param sdPrintDialog the sequence diagram printer dialog.
998 public void printUI(SDPrintDialogUI sdPrintDialog
) {
999 PrinterData data
= sdPrintDialog
.getPrinterData();
1001 if ((data
== null) || (frame
== null)) {
1005 printer
= new Printer(data
);
1007 String jobName
= MessageFormat
.format(SDMessages
._116
, new Object
[] { String
.valueOf(site
.getContentDescription()), String
.valueOf(frame
.getName()) });
1008 printer
.startJob(jobName
);
1010 GC gc
= new GC(printer
);
1011 Frame
.setUserPref(SDViewPref
.getInstance());
1013 float lastZoom
= zoomValue
;
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(SDViewPref
.PREF_LIFELINE
)));
1024 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1025 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1026 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1027 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1029 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
1030 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
1031 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
1032 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.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(SDViewPref
.PREF_LIFELINE
));
1049 int width
= Math
.round((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1050 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1051 if (width
< area
.width
) {
1054 if (height
< area
.height
) {
1055 height
= area
.height
;
1057 resizeContents(width
, height
);
1059 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1060 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1061 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1062 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1063 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1064 gcim
.setLineWidth(1);
1066 printer
.startPage();
1067 zoomValue
= lastZoom
;
1069 int restoreX
= getContentsX();
1070 int restoreY
= getContentsY();
1072 float zh
= getContentsHeight();
1073 float zw
= getContentsWidth();
1075 zh
= sdPrintDialog
.getStepY() * sdPrintDialog
.getZoomFactor();
1076 zw
= sdPrintDialog
.getStepX() * sdPrintDialog
.getZoomFactor();
1078 float zoomValueH
= printer
.getClientArea().height
/ zh
;
1079 float zoomValueW
= printer
.getClientArea().width
/ zw
;
1080 if (zoomValueH
> zoomValueW
) {
1081 printerZoom
= zoomValueH
;
1083 printerZoom
= zoomValueW
;
1086 if (sdPrintDialog
.printSelection()) {
1087 int[] pagesList
= sdPrintDialog
.getPageList();
1089 for (int pageIndex
= 0; pageIndex
< pagesList
.length
; pageIndex
++) {
1090 printPage(pagesList
[pageIndex
], sdPrintDialog
, context
);
1092 } else if (sdPrintDialog
.printAll()) {
1093 for (int pageIndex
= 1; pageIndex
<= sdPrintDialog
.maxNumOfPages(); pageIndex
++) {
1094 printPage(pageIndex
, sdPrintDialog
, context
);
1096 } else if (sdPrintDialog
.printCurrent()) {
1097 printPage(getContentsX(), getContentsY(), sdPrintDialog
, context
, 1);
1098 } else if (sdPrintDialog
.printRange()) {
1099 for (int pageIndex
= sdPrintDialog
.getFrom(); pageIndex
<= sdPrintDialog
.maxNumOfPages() && pageIndex
<= sdPrintDialog
.getTo(); pageIndex
++) {
1100 printPage(pageIndex
, sdPrintDialog
, context
);
1110 zoomValue
= lastZoom
;
1112 setContentsPos(restoreX
, restoreY
);
1118 public void print() {
1119 SDPrintDialog sdPrinter
= new SDPrintDialog(this.getShell(), this);
1121 if (sdPrinter
.open() != 0) {
1124 } catch (Exception e
) {
1125 TmfUiPlugin
.getDefault().getLog().log(new Status(IStatus
.ERROR
,TmfUiPlugin
.PLUGIN_ID
, "Error creating image", e
)); //$NON-NLS-1$
1128 printUI(sdPrinter
.getDialogUI());
1132 * Method to print a page.
1134 * @param pageNum The page number
1135 * @param pd The sequence diagram print dialog
1136 * @param context The graphical context
1138 public void printPage(int pageNum
, SDPrintDialogUI pd
, NGC context
) {
1139 int j
= pageNum
/ pd
.getNbRow();
1140 int i
= pageNum
% pd
.getNbRow();
1150 i
= (int) (i
* pd
.getStepX());
1151 j
= (int) (j
* pd
.getStepY());
1153 printPage(i
, j
, pd
, context
, pageNum
);
1159 * Method to print page ranges.
1161 * @param i The start page
1162 * @param j The end page
1163 * @param pd The sequence diagram print dialog
1164 * @param context The graphical context
1165 * @param pageNum int the current page
1167 public void printPage(int i
, int j
, SDPrintDialogUI pd
, NGC context
, int pageNum
) {
1169 int pageNumFontZoom
= printer
.getClientArea().height
/ getVisibleHeight();
1172 setContentsPos(i
, j
);
1175 float lastZoom
= zoomValue
;
1176 zoomValue
= printerZoom
* lastZoom
;
1178 frame
.draw(context
);
1180 zoomValue
= pageNumFontZoom
;
1181 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1182 String currentPageNum
= String
.valueOf(pageNum
);
1183 int ii
= context
.textExtent(currentPageNum
);
1184 int jj
= context
.getCurrentFontHeight();
1185 // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1186 // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
1187 zoomValue
= printerZoom
* lastZoom
;
1188 context
.drawText(currentPageNum
, Math
.round(printerX
+ getVisibleWidth() / printerZoom
- ii
/ printerZoom
), Math
.round(printerY
+ getVisibleHeight() / printerZoom
- jj
/ printerZoom
), false);
1190 zoomValue
= lastZoom
;
1194 * Sets the collapse provider.
1196 * @param provider The collapse provider to set
1198 protected void setCollapseProvider(ISDCollapseProvider provider
) {
1199 collapseProvider
= 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
]);
1224 * A post action for a tooltip (before displaying).
1226 * @param accessible true if accessible else false
1227 * @return the tooltip text.
1229 protected String
getPostfixForTooltip(boolean accessible
) {
1230 String postfix
= "";//$NON-NLS-1$
1231 // Determine if the tooltip must show the time difference between the current mouse position and
1232 // the last selected graphNode
1233 if ((currentGraphNode
!= null) &&
1234 (currentGraphNode
instanceof ITimeRange
) &&
1235 (toolTipNode
instanceof ITimeRange
) &&
1236 (currentGraphNode
!= toolTipNode
) &&
1237 ((ITimeRange
) toolTipNode
).hasTimeInfo() &&
1238 ((ITimeRange
) currentGraphNode
).hasTimeInfo()) {
1239 postfix
= " -> " + currentGraphNode
.getName() + "\n" + SDMessages
._138
+ " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1241 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1242 ITmfTimestamp firstTime
= ((ITimeRange
) currentGraphNode
).getEndTime();
1243 ITmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
1244 TmfTimestamp delta
= (TmfTimestamp
) lastTime
.getDelta(firstTime
);
1245 postfix
+= delta
.toString();
1247 if ((toolTipNode
instanceof ITimeRange
) && ((ITimeRange
) toolTipNode
).hasTimeInfo()) {
1248 postfix
= "\n";//$NON-NLS-1$
1249 ITmfTimestamp firstTime
= ((ITimeRange
) toolTipNode
).getStartTime();
1250 ITmfTimestamp lastTime
= ((ITimeRange
) toolTipNode
).getEndTime();
1252 if (firstTime
!= null) {
1253 if (lastTime
!= null && firstTime
.compareTo(lastTime
, true) != 0) {
1254 postfix
+= "start: " + firstTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
1255 postfix
+= "end: " + lastTime
+ "\n"; //$NON-NLS-1$ //$NON-NLS-2$
1257 postfix
+= firstTime
.toString();
1260 else if (lastTime
!= null) {
1261 postfix
+= lastTime
.toString();
1269 * Sets a new focused widget.
1271 * @param newFocusShape A new focus shape.
1273 protected void setFocus(int newFocusShape
) {
1274 focusedWidget
= newFocusShape
;
1275 if (focusedWidget
== -1) {
1276 getViewControl().getAccessible().setFocus(ACC
.CHILDID_SELF
);
1278 getViewControl().getAccessible().setFocus(focusedWidget
);
1283 * Highlight the given GraphNode<br>
1284 * The GraphNode is then displayed using the system default selection color
1286 * @param node the GraphNode to highlight
1288 protected void performSelection(GraphNode node
) {
1289 if ((ctrlSelection
) || (shiftSelection
)) {
1291 if (selectedNodeList
.contains(node
)) {
1292 removeSelection(node
);
1308 * Returns a draw buffer image.
1310 * @return a Image containing the draw buffer.
1312 protected Image
getDrawBuffer() {
1315 Rectangle area
= getClientArea();
1316 Image dbuffer
= null;
1320 dbuffer
= new Image(getDisplay(), area
.width
, area
.height
);
1321 } catch (Exception e
) {
1322 TmfUiPlugin
.getDefault().getLog().log(new Status(IStatus
.ERROR
,TmfUiPlugin
.PLUGIN_ID
, "Error creating image", e
)); //$NON-NLS-1$
1325 gcim
= new GC(dbuffer
);
1327 NGC context
= new NGC(this, gcim
);
1329 // Set the metrics to use for lifeline text and message text
1330 // using the Graphical Context
1331 Metrics
.setLifelineFontHeight(context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1332 Metrics
.setLifelineFontWidth(context
.getFontWidth(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
)));
1333 Metrics
.setLifelineWidth(SDViewPref
.getInstance().getLifelineWidth());
1334 Metrics
.setFrameFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_FRAME_NAME
)));
1335 Metrics
.setLifelineHeaderFontHeight(context
.getFontHeight(Frame
.getUserPref().getFont(ISDPreferences
.PREF_LIFELINE_HEADER
)));
1337 int syncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS
));
1338 int syncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_SYNC_MESS_RET
));
1339 int asyncMessFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS
));
1340 int asyncMessRetFontH
= context
.getFontHeight(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_ASYNC_MESS_RET
));
1342 int messageFontHeight
= 0;
1343 if (syncMessFontH
> syncMessRetFontH
) {
1344 messageFontHeight
= syncMessFontH
;
1346 messageFontHeight
= syncMessRetFontH
;
1348 if (messageFontHeight
< asyncMessFontH
) {
1349 messageFontHeight
= asyncMessFontH
;
1351 if (messageFontHeight
< asyncMessRetFontH
) {
1352 messageFontHeight
= asyncMessRetFontH
;
1354 Metrics
.setMessageFontHeight(messageFontHeight
);
1355 context
.setFont(SDViewPref
.getInstance().getFont(SDViewPref
.PREF_LIFELINE
));
1357 int width
= (int) ((frame
.getWidth() + 2 * Metrics
.FRAME_H_MARGIN
) * zoomValue
);
1358 int height
= (int) ((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1360 resizeContents(width
, height
);
1362 context
.setBackground(Frame
.getUserPref().getBackGroundColor(ISDPreferences
.PREF_FRAME
));
1363 context
.fillRectangle(0, 0, getContentsWidth(), Metrics
.FRAME_V_MARGIN
);
1364 context
.fillRectangle(0, 0, frame
.getX(), getContentsHeight());
1365 context
.fillRectangle(frame
.getX() + frame
.getWidth() + 1, 0, getContentsWidth() - (frame
.getX() + frame
.getWidth() + 1), getContentsHeight());
1366 context
.fillRectangle(0, frame
.getY() + frame
.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame
.getY() + frame
.getHeight() + 1));
1367 gcim
.setLineWidth(1);
1369 frame
.draw(context
);
1370 if (dragAndDrop
!= null) {
1371 Lifeline node
= (Lifeline
) dragAndDrop
;
1372 boolean isSelected
= dragAndDrop
.isSelected();
1373 boolean hasFocus
= dragAndDrop
.hasFocus();
1374 node
.setSelected(false);
1375 node
.setFocused(false);
1376 node
.draw(context
, dragX
, dragY
);
1377 node
.setSelected(isSelected
);
1378 node
.setFocused(hasFocus
);
1387 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyPressedEvent(org.eclipse.swt.events.KeyEvent)
1390 protected void keyPressedEvent(KeyEvent event
) {
1391 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1392 Control
[] child
= getParent().getChildren();
1393 for (int i
= 0; i
< child
.length
; i
++) {
1394 if (child
[i
].isFocusControl()) {
1395 if (!(child
[i
] instanceof ScrollView
)) {
1396 getViewControl().setFocus();
1404 if (event
.keyCode
== SWT
.CTRL
) {
1405 ctrlSelection
= true;
1407 if (event
.keyCode
== SWT
.SHIFT
) {
1408 shiftSelection
= true;
1409 prevList
= new ArrayList
<GraphNode
>();
1410 prevList
.addAll(getSelection());
1413 GraphNode prevNode
= getFocusNode();
1415 if (event
.keyCode
== SWT
.ARROW_RIGHT
) {
1419 if (event
.keyCode
== SWT
.ARROW_LEFT
) {
1423 if (event
.keyCode
== SWT
.ARROW_DOWN
) {
1427 if (event
.keyCode
== SWT
.ARROW_UP
) {
1431 if (event
.keyCode
== SWT
.HOME
) {
1435 if (event
.keyCode
== SWT
.END
) {
1439 if ((!shiftSelection
) && (!ctrlSelection
)) {
1440 listStart
= currentGraphNode
;
1443 if (event
.character
== ' ') {
1444 performSelection(currentGraphNode
);
1445 if (!shiftSelection
)
1446 listStart
= currentGraphNode
;
1449 if ((shiftSelection
) && (prevNode
!= getFocusNode())) {
1451 addSelection(prevList
);
1452 addSelection(frame
.getNodeList(listStart
, 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 ((!ctrlSelection
) && (!shiftSelection
)) {
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 (currentGraphNode
!= null) {
1473 currentGraphNode
.setFocused(true);
1477 if ((event
.character
== ' ') && ((zoomInMode
) || (zoomOutMode
))) {
1478 int cx
= Math
.round((getContentsX() + getVisibleWidth() / 2) / zoomValue
);
1479 int cy
= Math
.round((getContentsY() + getVisibleHeight() / 2) / zoomValue
);
1481 if (zoomValue
< 64) {
1482 zoomValue
= zoomValue
* (float) 1.25;
1485 zoomValue
= zoomValue
/ (float) 1.25;
1487 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
1488 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
1489 setContentsPos(x
, y
);
1490 if (timeBar
!= null) {
1491 timeBar
.setZoom(zoomValue
);
1493 // redraw also resize the scrollView content
1500 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyReleasedEvent(org.eclipse.swt.events.KeyEvent)
1503 protected void keyReleasedEvent(KeyEvent event
) {
1505 if (event
.keyCode
== SWT
.CTRL
)
1506 ctrlSelection
= false;
1507 if (event
.keyCode
== SWT
.SHIFT
)
1508 shiftSelection
= false;
1509 super.keyReleasedEvent(event
);
1515 * @see org.eclipse.swt.widgets.Control#isFocusControl()
1518 public boolean isFocusControl() {
1519 Control
[] child
= getChildren();
1520 for (int i
= 0; i
< child
.length
; i
++) {
1521 if (child
[i
].isFocusControl()) {
1524 checkFocusOnChilds(child
[i
]);
1532 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#setContentsPos(int, int)
1535 public boolean setContentsPos(int x
, int y
) {
1542 if (frame
== null) {
1545 if (x
+ getVisibleWidth() > getContentsWidth()) {
1546 x
= getContentsWidth() - getVisibleWidth();
1548 if (y
+ getVisibleHeight() > getContentsHeight()) {
1549 y
= getContentsHeight() - getVisibleHeight();
1551 int x1
= Math
.round(x
/ zoomValue
);
1552 int y2
= Math
.round(y
/ zoomValue
);
1553 int width
= Math
.round(getVisibleWidth() / zoomValue
);
1554 int height
= Math
.round(getVisibleHeight() / zoomValue
);
1555 frame
.updateIndex(x1
, y2
, width
, height
);
1557 if (insertionCartet
!= null && insertionCartet
.isVisible()) {
1558 insertionCartet
.setVisible(false);
1561 return super.setContentsPos(x
, y
);
1566 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseHover(org.eclipse.swt.events.MouseEvent)
1569 protected void contentsMouseHover(MouseEvent event
) {
1570 GraphNode graphNode
= null;
1571 if (frame
!= null) {
1572 int x
= Math
.round(event
.x
/ zoomValue
);
1573 int y
= Math
.round(event
.y
/ zoomValue
);
1574 graphNode
= frame
.getNodeAt(x
, y
);
1575 if ((graphNode
!= null) && (SDViewPref
.getInstance().tooltipEnabled())) {
1576 toolTipNode
= graphNode
;
1577 String postfix
= getPostfixForTooltip(true);
1578 if (graphNode
instanceof Lifeline
) {
1579 Lifeline lifeline
= (Lifeline
) graphNode
;
1580 toolTip
.showToolTip(lifeline
.getToolTipText() + postfix
);
1583 toolTip
.showToolTip(graphNode
.getName() + postfix
);
1587 toolTip
.hideToolTip();
1594 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseMoveEvent(org.eclipse.swt.events.MouseEvent)
1597 protected void contentsMouseMoveEvent(MouseEvent e
) {
1598 scrollToolTip
.hideToolTip();
1599 toolTip
.hideToolTip();
1600 // super.contentsMouseMoveEvent(e);
1601 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1602 Control
[] child
= getParent().getChildren();
1603 for (int i
= 0; i
< child
.length
; i
++) {
1604 if (child
[i
].isFocusControl()) {
1605 if (!(child
[i
] instanceof ScrollView
)) {
1606 getViewControl().setFocus();
1614 if (((e
.stateMask
& SWT
.BUTTON_MASK
) != 0) && ((dragAndDrop
!= null) || getDragAndDrop
) && (reorderMode
|| collapseProvider
!= null)) {
1615 getDragAndDrop
= false;
1616 if (currentGraphNode
instanceof Lifeline
) {
1617 dragAndDrop
= (Lifeline
) currentGraphNode
;
1619 if (dragAndDrop
!= null) {
1622 if (e
.x
> getContentsX() + getVisibleWidth()) {
1623 dx
= e
.x
- (getContentsX() + getVisibleWidth());
1624 } else if (e
.x
< getContentsX()) {
1625 dx
= -getContentsX() + e
.x
;
1627 if (e
.y
> getContentsY() + getVisibleHeight()) {
1628 dy
= e
.y
- (getContentsY() + getVisibleHeight());
1629 } else if (e
.y
< getContentsY()) {
1630 dy
= -getContentsY() + e
.y
;
1634 if (dx
!= 0 || dy
!= 0) {
1635 if (local_auto_scroll_
== null) {
1636 if (local_auto_scroll_timer_
== null) {
1637 local_auto_scroll_timer_
= new Timer(true);
1639 local_auto_scroll_
= new AutoScroll(this, dx
, dy
);
1640 local_auto_scroll_timer_
.schedule(local_auto_scroll_
, 0, 75);
1642 local_auto_scroll_
.dx_
= dx
;
1643 local_auto_scroll_
.dy_
= dy
;
1645 } else if (local_auto_scroll_
!= null) {
1646 local_auto_scroll_
.cancel();
1647 local_auto_scroll_
= null;
1649 dragX
= Math
.round(e
.x
/ zoomValue
);
1650 dragY
= Math
.round(e
.y
/ zoomValue
);
1652 Lifeline node
= frame
.getCloserLifeline(dragX
);
1653 if ((node
!= null) && (node
!= dragAndDrop
)) {
1656 int height
= Metrics
.getLifelineHeaderFontHeigth() + 2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
;
1657 int hMargin
= Metrics
.LIFELINE_VT_MAGIN
/ 4;
1658 int x
= node
.getX();
1659 int width
= node
.getWidth();
1660 if (frame
.getVisibleAreaY() < node
.getY() + node
.getHeight() - height
- hMargin
) {
1661 y
= contentsToViewY(Math
.round((node
.getY() + node
.getHeight()) * zoomValue
));
1663 y
= Math
.round(height
* zoomValue
);
1666 if (frame
.getVisibleAreaY() < contentsToViewY(node
.getY() - hMargin
)) {
1667 y1
= contentsToViewY(Math
.round((node
.getY() - hMargin
) * zoomValue
));
1669 y1
= Math
.round(height
* zoomValue
);
1672 int rx
= Math
.round(x
* zoomValue
);
1674 insertionCartet
.setVisible(true);
1675 if ((insertionCartet
.getImage() != null) && (!insertionCartet
.getImage().isDisposed())) {
1676 insertionCartet
.getImage().dispose();
1678 if (rx
<= e
.x
&& Math
.round(rx
+ (width
* zoomValue
)) >= e
.x
) {
1679 if (collapseProvider
!= null) {
1680 ImageData data
= collapaseCaretImg
.getImageData();
1681 data
= data
.scaledTo(Math
.round(collapaseCaretImg
.getBounds().width
* zoomValue
), Math
.round(collapaseCaretImg
.getBounds().height
* zoomValue
));
1682 currentCaretImage
= new Image(Display
.getCurrent(), data
);
1683 insertionCartet
.setImage(currentCaretImage
);
1684 insertionCartet
.setLocation(contentsToViewX(rx
+ Math
.round((width
/ (float) 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y
);
1686 } else if (reorderMode
) {
1688 if (node
.getIndex() > 1 && frame
.getLifeline(node
.getIndex() - 2) == dragAndDrop
) {
1691 ImageData data
= arrowUpCaretImg
.getImageData();
1692 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
1693 currentCaretImage
= new Image(Display
.getCurrent(), data
);
1694 insertionCartet
.setImage(currentCaretImage
);
1695 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
- Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2, y1
);
1697 if (node
.getIndex() < frame
.lifeLinesCount() && frame
.getLifeline(node
.getIndex()) == dragAndDrop
) {
1700 ImageData data
= arrowUpCaretImg
.getImageData();
1701 data
= data
.scaledTo(Math
.round(arrowUpCaretImg
.getBounds().width
* zoomValue
), Math
.round(arrowUpCaretImg
.getBounds().height
* zoomValue
));
1702 currentCaretImage
= new Image(Display
.getCurrent(), data
);
1703 insertionCartet
.setImage(currentCaretImage
);
1704 insertionCartet
.setLocation(contentsToViewX(Math
.round((x
+ width
+ Metrics
.LIFELINE_SPACING
/ 2) * zoomValue
)) - currentCaretImage
.getBounds().width
/ 2 + 1, y1
);
1708 insertionCartet
.setVisible(false);
1712 super.contentsMouseMoveEvent(e
);
1718 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseUpEvent(org.eclipse.swt.events.MouseEvent)
1721 protected void contentsMouseUpEvent(MouseEvent event
) {
1722 // Just in case the diagram highlight a time compression region
1723 // this region need to be released when clicking everywhere
1724 insertionCartet
.setVisible(false);
1725 if (dragAndDrop
!= null) {
1726 if ((overView
!= null) && (!overView
.isDisposed())) {
1730 Lifeline node
= frame
.getCloserLifeline(dragX
);
1732 int rx
= Math
.round(node
.getX() * zoomValue
);
1733 if (rx
<= event
.x
&& Math
.round(rx
+ (node
.getWidth() * zoomValue
)) >= event
.x
) {
1734 if ((collapseProvider
!= null) && (dragAndDrop
!= node
)) {
1735 collapseProvider
.collapseTwoLifelines((Lifeline
) dragAndDrop
, node
);
1737 } else if (rx
< event
.x
) {
1738 frame
.insertLifelineAfter((Lifeline
) dragAndDrop
, node
);
1739 if (node
.getIndex() < frame
.lifeLinesCount()) {
1740 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, frame
.getLifeline(node
.getIndex()) };
1741 reorderList
.add(temp
);
1743 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, null };
1744 reorderList
.add(temp
);
1747 frame
.insertLifelineBefore((Lifeline
) dragAndDrop
, node
);
1748 Lifeline temp
[] = { (Lifeline
) dragAndDrop
, node
};
1749 reorderList
.add(temp
);
1755 if (frame
== null) {
1758 frame
.resetTimeCompression();
1760 // reset auto scroll if it's engaged
1761 if (local_auto_scroll_
!= null) {
1762 local_auto_scroll_
.cancel();
1763 local_auto_scroll_
= null;
1765 super.contentsMouseUpEvent(event
);
1770 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseDownEvent(org.eclipse.swt.events.MouseEvent)
1773 protected void contentsMouseDownEvent(MouseEvent event
) {
1774 if (currentGraphNode
!= null) {
1775 currentGraphNode
.setFocused(false);
1778 // Just in case the diagram highlight a time compression region
1779 // this region need to be released when clicking everywhere
1780 if (frame
== null) {
1783 frame
.resetTimeCompression();
1785 if ((event
.stateMask
& SWT
.CTRL
) != 0) {
1786 ctrlSelection
= true;
1788 ctrlSelection
= false;
1791 if (((zoomInMode
) || (zoomOutMode
)) && (event
.button
== 1)) {
1792 int cx
= Math
.round(event
.x
/ zoomValue
);
1793 int cy
= Math
.round(event
.y
/ zoomValue
);
1795 if (zoomValue
< 64) {
1796 zoomValue
= zoomValue
* (float) 1.25;
1799 zoomValue
= zoomValue
/ (float) 1.25;
1801 int x
= Math
.round(cx
* zoomValue
- getVisibleWidth() / (float) 2);
1802 int y
= Math
.round(cy
* zoomValue
- getVisibleHeight() / (float) 2);
1803 setContentsPos(x
, y
);
1804 if (timeBar
!= null) {
1805 timeBar
.setZoom(zoomValue
);
1807 // redraw also resize the scrollView content
1809 } else {// if (event.button ==1)
1810 GraphNode node
= null;
1811 if (frame
!= null) {
1812 int x
= Math
.round(event
.x
/ zoomValue
);
1813 int y
= Math
.round(event
.y
/ zoomValue
);
1814 node
= frame
.getNodeAt(x
, y
);
1816 if ((event
.button
== 1) || ((node
!= null) && !node
.isSelected())) {
1817 if (!shiftSelection
) {
1820 if (shiftSelection
) {
1822 addSelection(frame
.getNodeList(listStart
, node
));
1824 performSelection(node
);
1826 currentGraphNode
= node
;
1828 node
.setFocused(true);
1834 if (dragAndDrop
== null) {
1835 super.contentsMouseDownEvent(event
);
1837 getDragAndDrop
= (event
.button
== 1);
1842 * TimerTask for auto scroll feature.
1844 protected static class AutoScroll
extends TimerTask
{
1854 * Field sequence diagram reference.
1856 public SDWidget sv_
;
1859 * Constructor for AutoScroll.
1860 * @param _sv sequence diagram widget reference
1861 * @param _dx delta x
1862 * @param _dy delta y
1864 public AutoScroll(SDWidget _sv
, int _dx
, int _dy
) {
1872 * @see java.util.TimerTask#run()
1876 Display
.getDefault().asyncExec(new Runnable() {
1879 if (sv_
.isDisposed())
1883 sv_
.scrollBy(dx_
, dy_
);
1891 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int)
1894 protected void drawContents(GC gc
, int clipx
, int clipy
, int clipw
, int cliph
) {
1895 if (frame
== null) {
1896 gc
.setBackground(getDisplay().getSystemColor(SWT
.COLOR_WHITE
));
1897 gc
.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1901 Frame
.setUserPref(SDViewPref
.getInstance());
1904 Rectangle area
= getClientArea();
1905 Image dbuffer
= getDrawBuffer();
1906 int height
= Math
.round((frame
.getHeight() + 2 * Metrics
.FRAME_V_MARGIN
) * zoomValue
);
1909 gc
.drawImage(dbuffer
, 0, 0, area
.width
, area
.height
, 0, 0, area
.width
, area
.height
);
1910 } catch (Exception e
) {
1911 System
.out
.println(e
.getMessage());
1914 setHScrollBarIncrement(Math
.round(SDViewPref
.getInstance().getLifelineWidth() / (float) 2 * zoomValue
));
1915 setVScrollBarIncrement(Math
.round(Metrics
.getMessagesSpacing() * zoomValue
));
1916 if ((timeBar
!= null) && (frame
.hasTimeInfo())) {
1917 timeBar
.resizeContents(9, height
+ getHorizontalBarHeight());
1918 timeBar
.setContentsPos(getContentsX(), getContentsY());
1922 float xRatio
= getContentsWidth() / (float) getVisibleWidth();
1923 float yRatio
= getContentsHeight() / (float) getVisibleHeight();
1924 if (yRatio
> xRatio
) {
1925 setOverviewSize((int) (getVisibleHeight() * 0.75));
1927 setOverviewSize((int) (getVisibleWidth() * 0.75));
1933 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
1936 public void widgetDefaultSelected(SelectionEvent event
) {
1941 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
1944 public void widgetSelected(SelectionEvent event
) {
1945 if (event
.widget
== zoomIn
) {
1946 zoomValue
= zoomValue
* 2;
1947 } else if (event
.widget
== zoomOut
) {
1948 zoomValue
= zoomValue
/ 2;
1954 * Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply button
1957 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
1960 public void propertyChange(PropertyChangeEvent e
) {
1961 if (frame
!= null && !isDisposed()) {
1962 frame
.resetTimeCompression();
1964 if (e
.getProperty().equals("PREFOK")) //$NON-NLS-1$
1966 // Prepare the overview to be reused for the new
1967 // settings (especially the colors)
1968 if (overView
!= null)
1977 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
1980 public void widgetDisposed(DisposeEvent e
) {
1981 if (overView
!= null) {
1984 super.removeDisposeListener(this);
1985 if ((currentCaretImage
!= null) && (!currentCaretImage
.isDisposed())) {
1986 currentCaretImage
.dispose();
1988 if ((arrowUpCaretImg
!= null) && (!arrowUpCaretImg
.isDisposed())) {
1989 arrowUpCaretImg
.dispose();
1991 if ((collapaseCaretImg
!= null) && (!collapaseCaretImg
.isDisposed())) {
1992 collapaseCaretImg
.dispose();
1994 SDViewPref
.getInstance().removePropertyChangeListener(this);
1995 LoadersManager lm
= LoadersManager
.getInstance();
1996 if (site
!= null && site
instanceof SDView
) {
1997 ((SDView
) site
).resetProviders();
1999 lm
.resetLoader(((SDView
) site
).getViewSite().getId());
2006 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawOverview(org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle)
2009 protected void drawOverview(GC gc
, Rectangle r
) {
2010 float oldzoom
= zoomValue
;
2011 if (getContentsWidth() > getContentsHeight()) {
2012 zoomValue
= (float) r
.width
/ (float) getContentsWidth() * oldzoom
;
2014 zoomValue
= (float) r
.height
/ (float) getContentsHeight() * oldzoom
;
2016 if ((overView
!= null) && ((r
.width
!= overView
.getBounds().width
) || (r
.height
!= overView
.getBounds().height
))) {
2020 if (overView
== null) {
2021 int backX
= getContentsX();
2022 int backY
= getContentsY();
2023 setContentsPos(0, 0);
2024 overView
= new Image(getDisplay(), r
.width
, r
.height
);
2025 GC gcim
= new GC(overView
);
2026 NGC context
= new NGC(this, gcim
);
2027 context
.setBackground(SDViewPref
.getInstance().getBackGroundColor(SDViewPref
.PREF_FRAME
));
2028 frame
.draw(context
);
2029 setContentsPos(backX
, backY
);
2033 if ((overView
!= null) && (r
.width
== overView
.getBounds().width
) && (r
.height
== overView
.getBounds().height
)) {
2034 gc
.drawImage(overView
, 0, 0, r
.width
, r
.height
, 0, 0, r
.width
, r
.height
);
2037 zoomValue
= oldzoom
;
2039 super.drawOverview(gc
, r
);
2044 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ITimeCompressionListener#deltaSelected(org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline, int, int, org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor)
2047 public void deltaSelected(Lifeline lifeline
, int startEvent
, int nbEvent
, IColor color
) {
2048 frame
.highlightTimeCompression(lifeline
, startEvent
, nbEvent
, color
);
2049 ensureVisible(lifeline
);
2050 int y1
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * startEvent
;
2051 int y2
= lifeline
.getY() + lifeline
.getHeight() + (Metrics
.getMessageFontHeigth() + Metrics
.getMessagesSpacing()) * (startEvent
+ nbEvent
);
2052 ensureVisible(lifeline
.getX(), y1
- (Metrics
.getLifelineHeaderFontHeigth() + +2 * Metrics
.LIFELINE_HEARDER_TEXT_V_MARGIN
), lifeline
.getWidth(), y2
- y1
+ 3, SWT
.CENTER
| SWT
.VERTICAL
, true);
2059 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleWidth()
2062 public int getVisibleWidth() {
2064 return printer
.getClientArea().width
;
2066 return super.getVisibleWidth();
2071 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleHeight()
2074 public int getVisibleHeight() {
2076 return printer
.getClientArea().height
;
2078 return super.getVisibleHeight();
2083 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewX(int)
2086 public int contentsToViewX(int _x
) {
2088 int v
= Math
.round(printerX
* printerZoom
);
2091 return _x
- getContentsX();
2096 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewY(int)
2099 public int contentsToViewY(int _y
) {
2101 int v
= Math
.round(printerY
* printerZoom
);
2104 return _y
- getContentsY();
2109 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsX()
2112 public int getContentsX() {
2114 return Math
.round(printerX
* printerZoom
);
2116 return super.getContentsX();
2122 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsY()
2125 public int getContentsY() {
2127 return Math
.round(printerY
* printerZoom
);
2129 return super.getContentsY();