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.jface.contexts.IContextIds;
23
import org.eclipse.jface.util.IPropertyChangeListener;
24
import org.eclipse.jface.util.PropertyChangeEvent;
25
import org.eclipse.jface.viewers.ISelectionProvider;
26
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
28
import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
29
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
30
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
31
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
32
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence;
33
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
34
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
35
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange;
36
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
37
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Metrics;
38
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.SDPrintDialog;
39
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.SDPrintDialogUI;
40
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
41
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDCollapseProvider;
42
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager;
43
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
44
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
45
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
46
import org.eclipse.swt.SWT;
47
import org.eclipse.swt.accessibility.ACC;
48
import org.eclipse.swt.accessibility.Accessible;
49
import org.eclipse.swt.accessibility.AccessibleAdapter;
50
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
51
import org.eclipse.swt.accessibility.AccessibleControlEvent;
52
import org.eclipse.swt.accessibility.AccessibleEvent;
53
import org.eclipse.swt.events.DisposeEvent;
54
import org.eclipse.swt.events.DisposeListener;
55
import org.eclipse.swt.events.FocusEvent;
56
import org.eclipse.swt.events.FocusListener;
57
import org.eclipse.swt.events.KeyEvent;
58
import org.eclipse.swt.events.MouseEvent;
59
import org.eclipse.swt.events.SelectionEvent;
60
import org.eclipse.swt.events.SelectionListener;
61
import org.eclipse.swt.events.TraverseEvent;
62
import org.eclipse.swt.events.TraverseListener;
63
import org.eclipse.swt.graphics.GC;
64
import org.eclipse.swt.graphics.Image;
65
import org.eclipse.swt.graphics.ImageData;
66
import org.eclipse.swt.graphics.Rectangle;
67
import org.eclipse.swt.printing.Printer;
68
import org.eclipse.swt.printing.PrinterData;
69
import org.eclipse.swt.widgets.Canvas;
70
import org.eclipse.swt.widgets.Caret;
71
import org.eclipse.swt.widgets.Composite;
72
import org.eclipse.swt.widgets.Control;
73
import org.eclipse.swt.widgets.Display;
74
import org.eclipse.swt.widgets.Event;
75
import org.eclipse.swt.widgets.Listener;
76
import org.eclipse.swt.widgets.MenuItem;
77
import org.eclipse.ui.contexts.IContextService;
78
import org.eclipse.ui.part.ViewPart;
82
* This class implements sequence diagram widget used in the sequence diagram view.
88
public class SDWidget extends ScrollView implements SelectionListener, IPropertyChangeListener, DisposeListener, ITimeCompressionListener {
90
// ------------------------------------------------------------------------
92
// ------------------------------------------------------------------------
95
* The frame to display in the sequence diagram widget.
97
protected Frame fFrame;
99
* The overview image to display.
101
protected Image fOverView = null;
103
* The zoom in menu item.
105
protected MenuItem fZoomIn = null;
107
* The zoom out menu item.
109
protected MenuItem fZoomOut = null;
111
* The sequence diagram selection provider.
113
protected SDWidgetSelectionProvider fSelProvider = null;
115
* The current zoom value.
117
public float fZoomValue = 1;
119
* The current zoomInMode (true for zoom in).
121
protected boolean fZoomInMode = false;
123
* The current zoomOutMode (true for zoom out).
125
protected boolean fZoomOutMode = false;
127
* The current list of selected graph nodes.
129
protected List<GraphNode> fSelectedNodeList = null;
131
* Flag whether ctrl button is selected or not.
133
protected boolean fCtrlSelection = false;
135
* A reference to the view site.
137
protected ViewPart fSite = null;
139
* The current graph node (the last selected one).
141
public GraphNode fCurrentGraphNode = null;
143
* The first graph node in list (multiple selection).
145
public GraphNode fListStart = null;
147
* The previous graph node (multiple selection).
149
public List<GraphNode> fPrevList = null;
151
* The time compression bar.
153
protected TimeCompressionBar fTimeBar = null;
155
* The current diagram tool tip.
157
protected DiagramToolTip fToolTip = null;
159
* The accessible object reference of view control.
161
protected Accessible fAccessible = null;
163
* The current node for the tooltip to display.
165
protected GraphNode fToolTipNode;
167
* The life line to drag and drop.
169
protected Lifeline fDragAndDrop = null;
171
* The number of focused widgets.
173
protected int fFocusedWidget = -1;
177
protected float fPrinterZoom = 0;
179
* Y coordinate for printer.
181
protected int fPrinterY = 0;
183
* X coordinate for printer.
185
protected int fPrinterX = 0;
187
* Flag whether drag and drop is enabled or not.
189
protected boolean fIsDragAndDrop = false;
191
* The x coordinate for drag.
193
protected int fDragX = 0;
195
* The y coordinate for drag.
197
protected int fDragY = 0;
201
protected boolean fReorderMode = false;
203
* The collapse caret image.
205
protected Image fCollapaseCaretImg = null;
207
* The arrow up caret image.
209
protected Image fArrowUpCaretImg = null;
211
* The current caret image.
213
protected Image fCurrentCaretImage = null;
215
* A sequence diagramm collapse provider (for collapsing graph nodes)
217
protected ISDCollapseProvider fCollapseProvider = null;
219
* The insertion caret.
221
protected Caret fInsertionCartet = null;
223
* The reorder list when in reorder mode.
225
protected List<Lifeline[]> fReorderList = null;
227
* Flag to specify whether in printing mode or not.
229
protected boolean fIsPrinting = false;
231
* A printer reference.
233
protected Printer fPrinter = null;
235
* Flag whether shift was selected or not.
237
protected boolean fShiftSelection = false;
239
* The scroll tooltip.
241
protected DiagramToolTip fScrollToolTip = null;
243
* Timer for auto_scroll feature
245
protected AutoScroll fLocalAutoScroll = null;
247
* TimerTask for auto_scroll feature !=null when auto scroll is running
249
protected Timer fLocalAutoScrollTimer = null;
251
// ------------------------------------------------------------------------
253
// ------------------------------------------------------------------------
255
* Constructor for SDWidget.
256
* @param c The parent composite
259
public SDWidget(Composite c, int s) {
260
super(c, s | SWT.NO_BACKGROUND, true);
261
setOverviewEnabled(true);
262
fSelectedNodeList = new ArrayList<GraphNode>();
263
fSelProvider = new SDWidgetSelectionProvider();
264
SDViewPref.getInstance().addPropertyChangeListener(this);
265
fToolTip = new DiagramToolTip(getViewControl());
266
super.addDisposeListener(this);
268
fScrollToolTip = new DiagramToolTip(c);
269
getVerticalBar().addListener(SWT.MouseUp, new Listener() {
272
public void handleEvent(Event event) {
273
fScrollToolTip.hideToolTip();
277
fAccessible = getViewControl().getAccessible();
279
fAccessible.addAccessibleListener(new AccessibleAdapter() {
282
* @see org.eclipse.swt.accessibility.AccessibleAdapter#getName(org.eclipse.swt.accessibility.AccessibleEvent)
285
public void getName(AccessibleEvent e) {
287
if (e.childID == 0) {
288
if (fToolTipNode != null) {
289
if (fToolTipNode instanceof Lifeline) {
290
Lifeline lifeline = (Lifeline) fToolTipNode;
291
e.result = lifeline.getToolTipText();
293
e.result = fToolTipNode.getName() + getPostfixForTooltip(true);
297
if (getFocusNode() != null) {
298
if (getFocusNode() instanceof Lifeline) {
299
e.result = MessageFormat.format(SDMessages._1, new Object[] { String.valueOf(getFocusNode().getName()) });
301
if (getFocusNode() instanceof BaseMessage) {
302
BaseMessage mes = (BaseMessage) getFocusNode();
303
if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() != null)) {
304
e.result = MessageFormat.format(
306
new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()), String.valueOf(mes.getEndLifeline().getName()),
307
Integer.valueOf(mes.getEndOccurrence()) });
308
} else if ((mes.getStartLifeline() == null) && (mes.getEndLifeline() != null)) {
309
e.result = MessageFormat.format(SDMessages._4, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getEndLifeline().getName()), Integer.valueOf(mes.getEndOccurrence()) });
310
} else if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() == null)) {
311
e.result = MessageFormat.format(SDMessages._3, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()) });
313
} else if (getFocusNode() instanceof BasicExecutionOccurrence) {
314
BasicExecutionOccurrence exec = (BasicExecutionOccurrence) getFocusNode();
315
e.result = MessageFormat.format(SDMessages._5,
316
new Object[] { String.valueOf(exec.getName()), String.valueOf(exec.getLifeline().getName()), Integer.valueOf(exec.getStartOccurrence()), Integer.valueOf(exec.getEndOccurrence()) });
324
fAccessible.addAccessibleControlListener(new AccessibleControlAdapter() {
327
* @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getFocus(org.eclipse.swt.accessibility.AccessibleControlEvent)
330
public void getFocus(AccessibleControlEvent e) {
331
if (fFocusedWidget == -1) {
332
e.childID = ACC.CHILDID_SELF;
334
e.childID = fFocusedWidget;
340
* @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getRole(org.eclipse.swt.accessibility.AccessibleControlEvent)
343
public void getRole(AccessibleControlEvent e) {
345
case ACC.CHILDID_SELF:
346
e.detail = ACC.ROLE_CLIENT_AREA;
349
e.detail = ACC.ROLE_TOOLTIP;
352
e.detail = ACC.ROLE_LABEL;
361
* @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getState(org.eclipse.swt.accessibility.AccessibleControlEvent)
364
public void getState(AccessibleControlEvent e) {
365
e.detail = ACC.STATE_FOCUSABLE;
366
if (e.childID == ACC.CHILDID_SELF) {
367
e.detail |= ACC.STATE_FOCUSED;
369
e.detail |= ACC.STATE_SELECTABLE;
370
if (e.childID == fFocusedWidget) {
371
e.detail |= ACC.STATE_FOCUSED | ACC.STATE_SELECTED | ACC.STATE_CHECKED;
377
fInsertionCartet = new Caret((Canvas) getViewControl(), SWT.NONE);
378
fInsertionCartet.setVisible(false);
380
fCollapaseCaretImg = Activator.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_COLLAPSE_OBJ);
381
fArrowUpCaretImg = Activator.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_UP_OBJ);
383
fReorderList = new ArrayList<Lifeline[]>();
384
getViewControl().addTraverseListener(new LocalTraverseListener());
386
addTraverseListener(new LocalTraverseListener());
388
getViewControl().addFocusListener(new FocusListener() {
392
* @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
395
public void focusGained(FocusEvent e) {
396
SDViewPref.getInstance().setNoFocusSelection(false);
397
fCtrlSelection = false;
398
fShiftSelection = false;
404
* @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
407
public void focusLost(FocusEvent e) {
408
SDViewPref.getInstance().setNoFocusSelection(true);
414
// ------------------------------------------------------------------------
416
// ------------------------------------------------------------------------
418
* Sets the time compression bar.
420
* @param bar The time compression bar to set
422
public void setTimeBar(TimeCompressionBar bar) {
425
fTimeBar.addTimeCompressionListener(this);
430
* Resize the contents to insure the frame fit into the view
432
* @param frame the frame which will be drawn in the view
434
public void resizeContents(Frame frame) {
435
int width = Math.round((frame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
436
int height = Math.round((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
437
resizeContents(width, height);
441
* The frame to render (the sequence diagram)
443
* @param theFrame the frame to display
444
* @param resetPosition boolean
446
public void setFrame(Frame theFrame, boolean resetPosition) {
447
fReorderList.clear();
448
fSelectedNodeList.clear();
449
fSelProvider.setSelection(new StructuredSelection());
452
setContentsPos(0, 0);
453
resizeContents(fFrame);
456
// prepare the old overview to be reused
457
if (fOverView != null) {
461
resizeContents(fFrame);
465
* Returns the current Frame (the sequence diagram container)
469
public Frame getFrame() {
474
* Returns the selection provider for the current sequence diagram
476
* @return the selection provider
478
public ISelectionProvider getSelectionProvider() {
483
* Returns a list of selected graph nodes.
485
* @return a list of selected graph nodes.
487
public List<GraphNode> getSelection() {
488
return fSelectedNodeList;
492
* Adds a graph node to the selected nodes list.
494
* @param node A graph node
496
public void addSelection(GraphNode node) {
500
fSelectedNodeList.add(node);
501
node.setSelected(true);
502
fCurrentGraphNode = node;
503
StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
504
fSelProvider.setSelection(selection);
508
* Adds a list of node to the selected nodes list.
510
* @param list of graph nodes
512
public void addSelection(List<GraphNode> list) {
513
// selectedNodeList.addAll(list);
514
for (int i = 0; i < list.size(); i++) {
515
if (!fSelectedNodeList.contains(list.get(i))) {
516
fSelectedNodeList.add(list.get(i));
517
((GraphNode) list.get(i)).setSelected(true);
520
StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
521
fSelProvider.setSelection(selection);
525
* Removes a node from the selected nodes list.
527
* @param node to remove
529
public void removeSelection(GraphNode node) {
530
fSelectedNodeList.remove(node);
531
node.setSelected(false);
532
node.setFocused(false);
533
StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
534
fSelProvider.setSelection(selection);
538
* Removes a list of graph nodes from the selected nodes list.
540
* @param list of nodes to remove.
542
public void removeSelection(List<GraphNode> list) {
543
fSelectedNodeList.removeAll(list);
544
for (int i = 0; i < list.size(); i++) {
545
((GraphNode) list.get(i)).setSelected(false);
546
((GraphNode) list.get(i)).setFocused(false);
548
StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
549
fSelProvider.setSelection(selection);
553
* Clear the list of GraphNodes which must be drawn selected.
555
public void clearSelection() {
556
for (int i = 0; i < fSelectedNodeList.size(); i++) {
557
((GraphNode) fSelectedNodeList.get(i)).setSelected(false);
558
((GraphNode) fSelectedNodeList.get(i)).setFocused(false);
560
fCurrentGraphNode = null;
561
fSelectedNodeList.clear();
562
fSelProvider.setSelection(new StructuredSelection());
568
* @param viewSite The view part to set
570
public void setSite(ViewPart viewSite) {
572
fSite.getSite().setSelectionProvider(fSelProvider);
573
IContextService service = (IContextService) fSite.getSite().getWorkbenchWindow().getService(IContextService.class);
574
service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
575
service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
579
* Returns the GraphNode overView the mouse if any
581
* @return the current graph node
583
public GraphNode getMouseOverNode() {
584
return fCurrentGraphNode;
588
* Sets the zoom in mode.
590
* @param The mode value to set.
592
public void setZoomInMode(boolean value) {
594
setZoomOutMode(false);
600
* Sets the zoom out mode.
602
* @param The mode value to set.
604
public void setZoomOutMode(boolean value) {
606
setZoomInMode(false);
608
fZoomOutMode = value;
612
* Moves the Sequence diagram to ensure the given node is visible and draw it selected
614
* @param node the GraphNode to move to
616
public void moveTo(GraphNode node) {
626
* Moves the Sequence diagram to ensure the given node is visible
628
* @param node the GraphNode to move to
630
public void ensureVisible(GraphNode node) {
634
int x = Math.round(node.getX() * fZoomValue);
635
int y = Math.round(node.getY() * fZoomValue);
636
int width = Math.round(node.getWidth() * fZoomValue);
637
int height = Math.round(node.getHeight() * fZoomValue);
638
if ((node instanceof BaseMessage) && (height == 0)) {
639
int header = Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN * 2 + Metrics.getLifelineHeaderFontHeigth();
640
height = -Math.round((Metrics.getMessagesSpacing() + header) * fZoomValue);
641
y = y + Math.round(Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT * fZoomValue);
643
if (node instanceof BasicExecutionOccurrence) {
647
if (node instanceof Lifeline) {
649
height = getVisibleHeight();
651
ensureVisible(x, y, width, height, SWT.CENTER, true);
656
* Returns the current zoom factor.
657
* @return the current zoom factor.
659
public float getZoomFactor() {
664
* Returns teh printer reference.
666
* @return the printer reference
668
public Printer getPrinter() {
673
* Returns whether the widget is used for printing or not.
675
* @return whether the widget is used for printing or not
677
public boolean isPrinting() {
682
* Gets the overview image.
684
* @param rect Rectangle to include overview.
685
* @return the overview image
687
public Image getOverview(Rectangle rect) {
688
float oldzoom = fZoomValue;
689
if ((fOverView != null) && ((rect.width != fOverView.getBounds().width) || (rect.height != fOverView.getBounds().height))) {
693
if (fOverView == null) {
694
int backX = getContentsX();
695
int backY = getContentsY();
696
setContentsPos(0, 0);
697
fOverView = new Image(getDisplay(), rect.width, rect.height);
698
GC gcim = new GC(fOverView);
699
NGC context = new NGC(this, gcim);
700
context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME));
701
fFrame.draw(context);
702
setContentsPos(backX, backY);
706
fZoomValue = oldzoom;
711
* Resets the zoom factor.
713
public void resetZoomFactor() {
714
int currentX = Math.round(getContentsX() / fZoomValue);
715
int currentY = Math.round(getContentsY() / fZoomValue);
717
if (fTimeBar != null && !fTimeBar.isDisposed()) {
718
fTimeBar.setZoom(fZoomValue);
722
setContentsPos(currentX, currentY);
726
* Enable or disable the lifeline reodering using Drag and Drop
728
* @param mode - true to enable false otherwise
730
public void setReorderMode(boolean mode) {
735
* Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
736
* element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
738
* @return - the re-odered sequence
740
public List<Lifeline[]> getLifelineReoderList() {
745
* Sets the focus on given graph node (current node).
747
* @param the graph node to focus on.
749
public void setFocus(GraphNode node) {
753
if (fCurrentGraphNode != null) {
754
fCurrentGraphNode.setFocused(false);
756
fCurrentGraphNode = node;
757
node.setFocused(true);
763
* Returns the graph node focused on.
765
* @return the current graph node
767
public GraphNode getFocusNode() {
768
return fCurrentGraphNode;
772
* Method to traverse right.
774
public void traverseRight() {
775
Object selectedNode = getFocusNode();
776
if (selectedNode == null) {
779
GraphNode node = null;
780
if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
781
node = fFrame.getCalledMessage((BaseMessage) selectedNode);
783
if (selectedNode instanceof BasicExecutionOccurrence) {
784
selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
786
if ((node == null) && (selectedNode instanceof Lifeline)) {
787
for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
788
if ((selectedNode == fFrame.getLifeline(i)) && (i < fFrame.lifeLinesCount() - 1)) {
789
node = fFrame.getLifeline(i + 1);
801
* Method to traverse left.
803
public void traverseLeft() {
804
Object selectedNode = getFocusNode();
805
GraphNode node = null;
806
if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
807
node = fFrame.getCallerMessage((BaseMessage) selectedNode);
809
if (selectedNode instanceof BasicExecutionOccurrence) {
810
selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
813
if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
814
selectedNode = ((BaseMessage) selectedNode).getEndLifeline();
816
for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
817
if ((selectedNode == fFrame.getLifeline(i)) && (i > 0)) {
818
node = fFrame.getLifeline(i - 1);
822
if ((fFrame.lifeLinesCount() > 0) && (node == null)) {
823
node = fFrame.getLifeline(0);
833
* Method to traverse up.
835
public void traverseUp() {
836
Object selectedNode = getFocusNode();
837
if (selectedNode == null) {
840
GraphNode node = null;
841
if (selectedNode instanceof BaseMessage) {
842
node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
843
} else if (selectedNode instanceof Lifeline) {
844
node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
845
if (!(node instanceof Lifeline)) {
848
} else if (selectedNode instanceof BasicExecutionOccurrence) {
849
node = fFrame.getPrevExecOccurrence((BasicExecutionOccurrence) selectedNode);
851
node = ((BasicExecutionOccurrence) selectedNode).getLifeline();
854
if ((node == null) && (selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
855
node = ((BaseMessage) selectedNode).getStartLifeline();
865
* Method to traverse down.
867
public void traverseDown() {
868
Object selectedNode = getFocusNode();
869
if (selectedNode == null) {
873
if (selectedNode instanceof BaseMessage) {
874
node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
875
} else if (selectedNode instanceof Lifeline) {
876
// node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
877
node = fFrame.getFirstExecution((Lifeline) selectedNode);
878
} else if (selectedNode instanceof BasicExecutionOccurrence) {
879
node = fFrame.getNextExecOccurrence((BasicExecutionOccurrence) selectedNode);
891
* Method to traverse home.
893
public void traverseHome() {
894
Object selectedNode = getFocusNode();
895
if (selectedNode == null) {
898
GraphNode node = null;
900
if (selectedNode instanceof BaseMessage) {
901
if (((BaseMessage) selectedNode).getStartLifeline() != null) {
902
node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
904
node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getEndLifeline(), null);
906
} else if (selectedNode instanceof Lifeline) {
907
node = fFrame.getNextLifelineMessage((Lifeline) selectedNode, null);
908
} else if (selectedNode instanceof BasicExecutionOccurrence) {
909
node = fFrame.getFirstExecution(((BasicExecutionOccurrence) selectedNode).getLifeline());
911
if (fFrame.lifeLinesCount() > 0) {
912
Lifeline lifeline = fFrame.getLifeline(0);
913
node = fFrame.getNextLifelineMessage(lifeline, null);
924
* Method to traverse to the end.
926
public void traverseEnd() {
927
Object selectedNode = getFocusNode();
928
if (selectedNode == null) {
932
if (selectedNode instanceof BaseMessage) {
933
node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
934
} else if (selectedNode instanceof Lifeline) {
935
node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
936
} else if (selectedNode instanceof BasicExecutionOccurrence) {
937
node = fFrame.getLastExecOccurrence(((BasicExecutionOccurrence) selectedNode).getLifeline());
939
if (fFrame.lifeLinesCount() > 0) {
940
Lifeline lifeline = fFrame.getLifeline(0);
941
node = fFrame.getPrevLifelineMessage(lifeline, null);
954
* Method to print UI.
956
* @param sdPrintDialog the sequence diagram printer dialog.
958
public void printUI(SDPrintDialogUI sdPrintDialog) {
959
PrinterData data = sdPrintDialog.getPrinterData();
961
if ((data == null) || (fFrame == null)) {
965
fPrinter = new Printer(data);
967
String jobName = MessageFormat.format(SDMessages._116, new Object[] { String.valueOf(fSite.getContentDescription()), String.valueOf(fFrame.getName()) });
968
fPrinter.startJob(jobName);
970
GC gc = new GC(fPrinter);
971
// Frame.setUserPref(SDViewPref.getInstance());
973
float lastZoom = fZoomValue;
975
Rectangle area = getClientArea();
979
NGC context = new NGC(this, gcim);
981
// Set the metrics to use for lifeline text and message text
982
// using the Graphical Context
983
Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
984
Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
985
Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
986
Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
987
Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
989
int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS));
990
int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET));
991
int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS));
992
int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET));
994
int messageFontHeight = 0;
995
if (syncMessFontH > syncMessRetFontH) {
996
messageFontHeight = syncMessFontH;
998
messageFontHeight = syncMessRetFontH;
1000
if (messageFontHeight < asyncMessFontH) {
1001
messageFontHeight = asyncMessFontH;
1003
if (messageFontHeight < asyncMessRetFontH) {
1004
messageFontHeight = asyncMessRetFontH;
1006
Metrics.setMessageFontHeight(messageFontHeight);
1007
context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1009
int width = Math.round((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1010
int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1011
if (width < area.width) {
1014
if (height < area.height) {
1015
height = area.height;
1017
resizeContents(width, height);
1019
context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
1020
context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
1021
context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1022
context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1023
context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
1024
gcim.setLineWidth(1);
1026
fPrinter.startPage();
1027
fZoomValue = lastZoom;
1029
int restoreX = getContentsX();
1030
int restoreY = getContentsY();
1032
float zh = sdPrintDialog.getStepY() * sdPrintDialog.getZoomFactor();
1033
float zw = sdPrintDialog.getStepX() * sdPrintDialog.getZoomFactor();
1035
float zoomValueH = fPrinter.getClientArea().height / zh;
1036
float zoomValueW = fPrinter.getClientArea().width / zw;
1037
if (zoomValueH > zoomValueW) {
1038
fPrinterZoom = zoomValueH;
1040
fPrinterZoom = zoomValueW;
1043
if (sdPrintDialog.printSelection()) {
1044
int[] pagesList = sdPrintDialog.getPageList();
1046
for (int pageIndex = 0; pageIndex < pagesList.length; pageIndex++) {
1047
printPage(pagesList[pageIndex], sdPrintDialog, context);
1049
} else if (sdPrintDialog.printAll()) {
1050
for (int pageIndex = 1; pageIndex <= sdPrintDialog.maxNumOfPages(); pageIndex++) {
1051
printPage(pageIndex, sdPrintDialog, context);
1053
} else if (sdPrintDialog.printCurrent()) {
1054
printPage(getContentsX(), getContentsY(), sdPrintDialog, context, 1);
1055
} else if (sdPrintDialog.printRange()) {
1056
for (int pageIndex = sdPrintDialog.getFrom(); pageIndex <= sdPrintDialog.maxNumOfPages() && pageIndex <= sdPrintDialog.getTo(); pageIndex++) {
1057
printPage(pageIndex, sdPrintDialog, context);
1062
fIsPrinting = false;
1067
fZoomValue = lastZoom;
1069
setContentsPos(restoreX, restoreY);
1075
public void print() {
1076
SDPrintDialog sdPrinter = new SDPrintDialog(this.getShell(), this);
1078
if (sdPrinter.open() != 0) {
1081
} catch (Exception e) {
1082
Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
1085
printUI(sdPrinter.getDialogUI());
1089
* Method to print a page.
1091
* @param pageNum The page number
1092
* @param pd The sequence diagram print dialog
1093
* @param context The graphical context
1095
public void printPage(int pageNum, SDPrintDialogUI pd, NGC context) {
1096
int j = pageNum / pd.getNbRow();
1097
int i = pageNum % pd.getNbRow();
1107
i = (int) (i * pd.getStepX());
1108
j = (int) (j * pd.getStepY());
1110
printPage(i, j, pd, context, pageNum);
1116
* Method to print page ranges.
1118
* @param i The start page
1119
* @param j The end page
1120
* @param pd The sequence diagram print dialog
1121
* @param context The graphical context
1122
* @param pageNum int the current page
1124
public void printPage(int i, int j, SDPrintDialogUI pd, NGC context, int pageNum) {
1125
fIsPrinting = false;
1126
int pageNumFontZoom = fPrinter.getClientArea().height / getVisibleHeight();
1129
setContentsPos(i, j);
1132
float lastZoom = fZoomValue;
1133
fZoomValue = fPrinterZoom * lastZoom;
1135
fFrame.draw(context);
1137
fZoomValue = pageNumFontZoom;
1138
context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1139
String currentPageNum = String.valueOf(pageNum);
1140
int ii = context.textExtent(currentPageNum);
1141
int jj = context.getCurrentFontHeight();
1142
// context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1143
// context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
1144
fZoomValue = fPrinterZoom * lastZoom;
1145
context.drawText(currentPageNum, Math.round(fPrinterX + getVisibleWidth() / fPrinterZoom - ii / fPrinterZoom), Math.round(fPrinterY + getVisibleHeight() / fPrinterZoom - jj / fPrinterZoom), false);
1146
fIsPrinting = false;
1147
fZoomValue = lastZoom;
1151
* Sets the collapse provider.
1153
* @param provider The collapse provider to set
1155
protected void setCollapseProvider(ISDCollapseProvider provider) {
1156
fCollapseProvider = provider;
1161
* Checks for focus of children.
1163
* @param children Control to check
1164
* @return true if child is on focus else false
1166
protected boolean checkFocusOnChilds(Control children) {
1167
if (children instanceof Composite) {
1168
Control[] child = ((Composite) children).getChildren();
1169
for (int i = 0; i < child.length; i++) {
1170
if (child[i].isFocusControl()) {
1173
checkFocusOnChilds(child[i]);
1181
* A post action for a tooltip (before displaying).
1183
* @param accessible true if accessible else false
1184
* @return the tooltip text.
1186
protected String getPostfixForTooltip(boolean accessible) {
1187
StringBuffer postfix = new StringBuffer();
1188
// String postfix = "";//$NON-NLS-1$
1189
// Determine if the tooltip must show the time difference between the current mouse position and
1190
// the last selected graphNode
1191
if ((fCurrentGraphNode != null) &&
1192
(fCurrentGraphNode instanceof ITimeRange) &&
1193
(fToolTipNode instanceof ITimeRange) &&
1194
(fCurrentGraphNode != fToolTipNode) &&
1195
((ITimeRange) fToolTipNode).hasTimeInfo() &&
1196
((ITimeRange) fCurrentGraphNode).hasTimeInfo()) {
1197
postfix.append(" -> "); //$NON-NLS-1$
1198
postfix.append(fCurrentGraphNode.getName());
1199
postfix.append("\n"); //$NON-NLS-1$
1200
postfix.append(SDMessages._138);
1201
postfix.append(" "); //$NON-NLS-1$
1203
// postfix = " -> " + fCurrentGraphNode.getName() + "\n" + SDMessages._138 + " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1205
//double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1206
ITmfTimestamp firstTime = ((ITimeRange) fCurrentGraphNode).getEndTime();
1207
ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
1208
TmfTimestamp delta = (TmfTimestamp) lastTime.getDelta(firstTime);
1209
postfix.append(delta.toString());
1211
// postfix += delta.toString();
1213
if ((fToolTipNode instanceof ITimeRange) && ((ITimeRange) fToolTipNode).hasTimeInfo()) {
1214
postfix.append("\n"); //$NON-NLS-1$
1215
// postfix = "\n";//$NON-NLS-1$
1216
ITmfTimestamp firstTime = ((ITimeRange) fToolTipNode).getStartTime();
1217
ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
1219
if (firstTime != null) {
1220
if (lastTime != null && firstTime.compareTo(lastTime, true) != 0) {
1221
postfix.append("start: "); //$NON-NLS-1$
1222
postfix.append(firstTime.toString());
1223
postfix.append("\n"); //$NON-NLS-1$
1224
postfix.append("end: "); //$NON-NLS-1$
1225
postfix.append(lastTime.toString());
1226
postfix.append("\n"); //$NON-NLS-1$
1227
// postfix += "start: " + firstTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
1228
// postfix += "end: " + lastTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
1230
postfix.append(firstTime.toString());
1231
// postfix += firstTime.toString();
1234
else if (lastTime != null) {
1235
postfix.append(lastTime.toString());
1236
// postfix += lastTime.toString();
1240
return postfix.toString();
1244
* Sets a new focused widget.
1246
* @param newFocusShape A new focus shape.
1248
protected void setFocus(int newFocusShape) {
1249
fFocusedWidget = newFocusShape;
1250
if (fFocusedWidget == -1) {
1251
getViewControl().getAccessible().setFocus(ACC.CHILDID_SELF);
1253
getViewControl().getAccessible().setFocus(fFocusedWidget);
1258
* Highlight the given GraphNode<br>
1259
* The GraphNode is then displayed using the system default selection color
1261
* @param node the GraphNode to highlight
1263
protected void performSelection(GraphNode node) {
1264
if ((fCtrlSelection) || (fShiftSelection)) {
1266
if (fSelectedNodeList.contains(node)) {
1267
removeSelection(node);
1283
* Returns a draw buffer image.
1285
* @return a Image containing the draw buffer.
1287
protected Image getDrawBuffer() {
1290
Rectangle area = getClientArea();
1291
Image dbuffer = null;
1295
dbuffer = new Image(getDisplay(), area.width, area.height);
1296
} catch (Exception e) {
1297
Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
1300
gcim = new GC(dbuffer);
1302
NGC context = new NGC(this, gcim);
1304
// Set the metrics to use for lifeline text and message text
1305
// using the Graphical Context
1306
Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
1307
Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
1308
Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
1309
Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
1310
Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
1312
int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS));
1313
int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET));
1314
int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS));
1315
int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET));
1317
int messageFontHeight = 0;
1318
if (syncMessFontH > syncMessRetFontH) {
1319
messageFontHeight = syncMessFontH;
1321
messageFontHeight = syncMessRetFontH;
1323
if (messageFontHeight < asyncMessFontH) {
1324
messageFontHeight = asyncMessFontH;
1326
if (messageFontHeight < asyncMessRetFontH) {
1327
messageFontHeight = asyncMessRetFontH;
1329
Metrics.setMessageFontHeight(messageFontHeight);
1330
context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1332
int width = (int) ((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1333
int height = (int) ((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1335
resizeContents(width, height);
1337
context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
1338
context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
1339
context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1340
context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1341
context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
1342
gcim.setLineWidth(1);
1344
fFrame.draw(context);
1345
if (fDragAndDrop != null) {
1346
Lifeline node = (Lifeline) fDragAndDrop;
1347
boolean isSelected = fDragAndDrop.isSelected();
1348
boolean hasFocus = fDragAndDrop.hasFocus();
1349
node.setSelected(false);
1350
node.setFocused(false);
1351
node.draw(context, fDragX, fDragY);
1352
node.setSelected(isSelected);
1353
node.setFocused(hasFocus);
1362
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyPressedEvent(org.eclipse.swt.events.KeyEvent)
1365
protected void keyPressedEvent(KeyEvent event) {
1366
if (!(isFocusControl() || getViewControl().isFocusControl())) {
1367
Control[] child = getParent().getChildren();
1368
for (int i = 0; i < child.length; i++) {
1369
if ((child[i].isFocusControl())&& (!(child[i] instanceof ScrollView))) {
1370
getViewControl().setFocus();
1377
if (event.keyCode == SWT.CTRL) {
1378
fCtrlSelection = true;
1380
if (event.keyCode == SWT.SHIFT) {
1381
fShiftSelection = true;
1382
fPrevList = new ArrayList<GraphNode>();
1383
fPrevList.addAll(getSelection());
1386
GraphNode prevNode = getFocusNode();
1388
if (event.keyCode == SWT.ARROW_RIGHT) {
1392
if (event.keyCode == SWT.ARROW_LEFT) {
1396
if (event.keyCode == SWT.ARROW_DOWN) {
1400
if (event.keyCode == SWT.ARROW_UP) {
1404
if (event.keyCode == SWT.HOME) {
1408
if (event.keyCode == SWT.END) {
1412
if ((!fShiftSelection) && (!fCtrlSelection)) {
1413
fListStart = fCurrentGraphNode;
1416
if (event.character == ' ') {
1417
performSelection(fCurrentGraphNode);
1418
if (!fShiftSelection) {
1419
fListStart = fCurrentGraphNode;
1423
if ((fShiftSelection) && (prevNode != getFocusNode())) {
1425
addSelection(fPrevList);
1426
addSelection(fFrame.getNodeList(fListStart, getFocusNode()));
1427
if (getFocusNode() instanceof Lifeline) {
1428
ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
1430
ensureVisible(getFocusNode());
1432
} else if ((!fCtrlSelection) && (!fShiftSelection)) {
1435
if (getFocusNode() != null) {
1436
addSelection(getFocusNode());
1438
if (getFocusNode() instanceof Lifeline) {
1439
ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
1441
ensureVisible(getFocusNode());
1446
if (fCurrentGraphNode != null) {
1447
fCurrentGraphNode.setFocused(true);
1451
if ((event.character == ' ') && ((fZoomInMode) || (fZoomOutMode))) {
1452
int cx = Math.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue);
1453
int cy = Math.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue);
1455
if (fZoomValue < 64) {
1456
fZoomValue = fZoomValue * (float) 1.25;
1459
fZoomValue = fZoomValue / (float) 1.25;
1461
int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1462
int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
1463
setContentsPos(x, y);
1464
if (fTimeBar != null) {
1465
fTimeBar.setZoom(fZoomValue);
1467
// redraw also resize the scrollView content
1474
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyReleasedEvent(org.eclipse.swt.events.KeyEvent)
1477
protected void keyReleasedEvent(KeyEvent event) {
1479
if (event.keyCode == SWT.CTRL) {
1480
fCtrlSelection = false;
1482
if (event.keyCode == SWT.SHIFT) {
1483
fShiftSelection = false;
1485
super.keyReleasedEvent(event);
1491
* @see org.eclipse.swt.widgets.Control#isFocusControl()
1494
public boolean isFocusControl() {
1495
Control[] child = getChildren();
1496
for (int i = 0; i < child.length; i++) {
1497
if (child[i].isFocusControl()) {
1500
checkFocusOnChilds(child[i]);
1508
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#setContentsPos(int, int)
1511
public boolean setContentsPos(int x, int y) {
1521
if (fFrame == null) {
1524
if (localX + getVisibleWidth() > getContentsWidth()) {
1525
localX = getContentsWidth() - getVisibleWidth();
1527
if (localY + getVisibleHeight() > getContentsHeight()) {
1528
localY = getContentsHeight() - getVisibleHeight();
1530
int x1 = Math.round(localX / fZoomValue);
1531
int y2 = Math.round(localY / fZoomValue);
1532
int width = Math.round(getVisibleWidth() / fZoomValue);
1533
int height = Math.round(getVisibleHeight() / fZoomValue);
1534
fFrame.updateIndex(x1, y2, width, height);
1536
if (fInsertionCartet != null && fInsertionCartet.isVisible()) {
1537
fInsertionCartet.setVisible(false);
1540
return super.setContentsPos(localX, localY);
1545
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseHover(org.eclipse.swt.events.MouseEvent)
1548
protected void contentsMouseHover(MouseEvent event) {
1549
GraphNode graphNode = null;
1550
if (fFrame != null) {
1551
int x = Math.round(event.x / fZoomValue);
1552
int y = Math.round(event.y / fZoomValue);
1553
graphNode = fFrame.getNodeAt(x, y);
1554
if ((graphNode != null) && (SDViewPref.getInstance().tooltipEnabled())) {
1555
fToolTipNode = graphNode;
1556
String postfix = getPostfixForTooltip(true);
1557
if (graphNode instanceof Lifeline) {
1558
Lifeline lifeline = (Lifeline) graphNode;
1559
fToolTip.showToolTip(lifeline.getToolTipText() + postfix);
1562
fToolTip.showToolTip(graphNode.getName() + postfix);
1566
fToolTip.hideToolTip();
1573
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseMoveEvent(org.eclipse.swt.events.MouseEvent)
1576
protected void contentsMouseMoveEvent(MouseEvent e) {
1577
fScrollToolTip.hideToolTip();
1578
fToolTip.hideToolTip();
1579
// super.contentsMouseMoveEvent(e);
1580
if (!(isFocusControl() || getViewControl().isFocusControl())) {
1581
Control[] child = getParent().getChildren();
1582
for (int i = 0; i < child.length; i++) {
1583
if ((child[i].isFocusControl()) && (!(child[i] instanceof ScrollView))) {
1584
getViewControl().setFocus();
1591
if (((e.stateMask & SWT.BUTTON_MASK) != 0) && ((fDragAndDrop != null) || fIsDragAndDrop) && (fReorderMode || fCollapseProvider != null)) {
1592
fIsDragAndDrop = false;
1593
if (fCurrentGraphNode instanceof Lifeline) {
1594
fDragAndDrop = (Lifeline) fCurrentGraphNode;
1596
if (fDragAndDrop != null) {
1599
if (e.x > getContentsX() + getVisibleWidth()) {
1600
dx = e.x - (getContentsX() + getVisibleWidth());
1601
} else if (e.x < getContentsX()) {
1602
dx = -getContentsX() + e.x;
1604
if (e.y > getContentsY() + getVisibleHeight()) {
1605
dy = e.y - (getContentsY() + getVisibleHeight());
1606
} else if (e.y < getContentsY()) {
1607
dy = -getContentsY() + e.y;
1611
if (dx != 0 || dy != 0) {
1612
if (fLocalAutoScroll == null) {
1613
if (fLocalAutoScrollTimer == null) {
1614
fLocalAutoScrollTimer = new Timer(true);
1616
fLocalAutoScroll = new AutoScroll(this, dx, dy);
1617
fLocalAutoScrollTimer.schedule(fLocalAutoScroll, 0, 75);
1619
fLocalAutoScroll.fDeltaX = dx;
1620
fLocalAutoScroll.fDeltaY = dy;
1622
} else if (fLocalAutoScroll != null) {
1623
fLocalAutoScroll.cancel();
1624
fLocalAutoScroll = null;
1626
fDragX = Math.round(e.x / fZoomValue);
1627
fDragY = Math.round(e.y / fZoomValue);
1629
Lifeline node = fFrame.getCloserLifeline(fDragX);
1630
if ((node != null) && (node != fDragAndDrop)) {
1633
int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
1634
int hMargin = Metrics.LIFELINE_VT_MAGIN / 4;
1635
int x = node.getX();
1636
int width = node.getWidth();
1637
if (fFrame.getVisibleAreaY() < node.getY() + node.getHeight() - height - hMargin) {
1638
y = contentsToViewY(Math.round((node.getY() + node.getHeight()) * fZoomValue));
1640
y = Math.round(height * fZoomValue);
1643
if (fFrame.getVisibleAreaY() < contentsToViewY(node.getY() - hMargin)) {
1644
y1 = contentsToViewY(Math.round((node.getY() - hMargin) * fZoomValue));
1646
y1 = Math.round(height * fZoomValue);
1649
int rx = Math.round(x * fZoomValue);
1651
fInsertionCartet.setVisible(true);
1652
if ((fInsertionCartet.getImage() != null) && (!fInsertionCartet.getImage().isDisposed())) {
1653
fInsertionCartet.getImage().dispose();
1655
if (rx <= e.x && Math.round(rx + (width * fZoomValue)) >= e.x) {
1656
if (fCollapseProvider != null) {
1657
ImageData data = fCollapaseCaretImg.getImageData();
1658
data = data.scaledTo(Math.round(fCollapaseCaretImg.getBounds().width * fZoomValue), Math.round(fCollapaseCaretImg.getBounds().height * fZoomValue));
1659
fCurrentCaretImage = new Image(Display.getCurrent(), data);
1660
fInsertionCartet.setImage(fCurrentCaretImage);
1661
fInsertionCartet.setLocation(contentsToViewX(rx + Math.round((width / (float) 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y);
1663
} else if (fReorderMode) {
1665
if (node.getIndex() > 1 && fFrame.getLifeline(node.getIndex() - 2) == fDragAndDrop) {
1668
ImageData data = fArrowUpCaretImg.getImageData();
1669
data = data.scaledTo(Math.round(fArrowUpCaretImg.getBounds().width * fZoomValue), Math.round(fArrowUpCaretImg.getBounds().height * fZoomValue));
1670
fCurrentCaretImage = new Image(Display.getCurrent(), data);
1671
fInsertionCartet.setImage(fCurrentCaretImage);
1672
fInsertionCartet.setLocation(contentsToViewX(Math.round((x - Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y1);
1674
if (node.getIndex() < fFrame.lifeLinesCount() && fFrame.getLifeline(node.getIndex()) == fDragAndDrop) {
1677
ImageData data = fArrowUpCaretImg.getImageData();
1678
data = data.scaledTo(Math.round(fArrowUpCaretImg.getBounds().width * fZoomValue), Math.round(fArrowUpCaretImg.getBounds().height * fZoomValue));
1679
fCurrentCaretImage = new Image(Display.getCurrent(), data);
1680
fInsertionCartet.setImage(fCurrentCaretImage);
1681
fInsertionCartet.setLocation(contentsToViewX(Math.round((x + width + Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2 + 1, y1);
1685
fInsertionCartet.setVisible(false);
1689
super.contentsMouseMoveEvent(e);
1695
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseUpEvent(org.eclipse.swt.events.MouseEvent)
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((Lifeline) fDragAndDrop, node);
1714
} else if (rx < event.x) {
1715
fFrame.insertLifelineAfter((Lifeline) fDragAndDrop, node);
1716
if (node.getIndex() < fFrame.lifeLinesCount()) {
1717
Lifeline temp[] = { (Lifeline) fDragAndDrop, fFrame.getLifeline(node.getIndex()) };
1718
fReorderList.add(temp);
1720
Lifeline temp[] = { (Lifeline) fDragAndDrop, null };
1721
fReorderList.add(temp);
1724
fFrame.insertLifelineBefore((Lifeline) fDragAndDrop, node);
1725
Lifeline temp[] = { (Lifeline) 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);
1747
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseDownEvent(org.eclipse.swt.events.MouseEvent)
1750
protected void contentsMouseDownEvent(MouseEvent event) {
1751
if (fCurrentGraphNode != null) {
1752
fCurrentGraphNode.setFocused(false);
1755
// Just in case the diagram highlight a time compression region
1756
// this region need to be released when clicking everywhere
1757
if (fFrame == null) {
1761
fFrame.resetTimeCompression();
1763
if ((event.stateMask & SWT.CTRL) != 0) {
1764
fCtrlSelection = true;
1766
fCtrlSelection = false;
1769
if (((fZoomInMode) || (fZoomOutMode)) && (event.button == 1)) {
1770
int cx = Math.round(event.x / fZoomValue);
1771
int cy = Math.round(event.y / fZoomValue);
1773
if (fZoomValue < 64) {
1774
fZoomValue = fZoomValue * (float) 1.25;
1777
fZoomValue = fZoomValue / (float) 1.25;
1779
int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1780
int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
1781
setContentsPos(x, y);
1782
if (fTimeBar != null) {
1783
fTimeBar.setZoom(fZoomValue);
1785
// redraw also resize the scrollView content
1787
} else {// if (event.button ==1)
1788
GraphNode node = null;
1789
int x = Math.round(event.x / fZoomValue);
1790
int y = Math.round(event.y / fZoomValue);
1791
node = fFrame.getNodeAt(x, y);
1793
if ((event.button == 1) || ((node != null) && !node.isSelected())) {
1794
if (!fShiftSelection) {
1797
if (fShiftSelection) {
1799
addSelection(fFrame.getNodeList(fListStart, node));
1801
performSelection(node);
1803
fCurrentGraphNode = node;
1805
node.setFocused(true);
1810
if (fDragAndDrop == null) {
1811
super.contentsMouseDownEvent(event);
1813
fIsDragAndDrop = (event.button == 1);
1818
* TimerTask for auto scroll feature.
1820
protected static class AutoScroll extends TimerTask {
1830
* Field sequence diagram reference.
1832
public SDWidget fSdWidget;
1835
* Constructor for AutoScroll.
1836
* @param sv sequence diagram widget reference
1840
public AutoScroll(SDWidget sv, int dx, int dy) {
1848
* @see java.util.TimerTask#run()
1852
Display.getDefault().asyncExec(new Runnable() {
1855
if (fSdWidget.isDisposed()) {
1858
fSdWidget.fDragX += fDeltaX;
1859
fSdWidget.fDragY += fDeltaY;
1860
fSdWidget.scrollBy(fDeltaX, fDeltaY);
1868
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int)
1871
protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) {
1872
if (fFrame == null) {
1873
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
1874
gc.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1878
// Frame.setUserPref(SDViewPref.getInstance());
1879
SDViewPref.getInstance();
1882
Rectangle area = getClientArea();
1883
Image dbuffer = getDrawBuffer();
1884
int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1887
gc.drawImage(dbuffer, 0, 0, area.width, area.height, 0, 0, area.width, area.height);
1888
} catch (Exception e) {
1889
Activator.getDefault().logError("Error drawin content", e); //$NON-NLS-1$
1892
setHScrollBarIncrement(Math.round(SDViewPref.getInstance().getLifelineWidth() / (float) 2 * fZoomValue));
1893
setVScrollBarIncrement(Math.round(Metrics.getMessagesSpacing() * fZoomValue));
1894
if ((fTimeBar != null) && (fFrame.hasTimeInfo())) {
1895
fTimeBar.resizeContents(9, height + getHorizontalBarHeight());
1896
fTimeBar.setContentsPos(getContentsX(), getContentsY());
1900
float xRatio = getContentsWidth() / (float) getVisibleWidth();
1901
float yRatio = getContentsHeight() / (float) getVisibleHeight();
1902
if (yRatio > xRatio) {
1903
setOverviewSize((int) (getVisibleHeight() * 0.75));
1905
setOverviewSize((int) (getVisibleWidth() * 0.75));
1911
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
1914
public void widgetDefaultSelected(SelectionEvent event) {
1919
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
1922
public void widgetSelected(SelectionEvent event) {
1923
if (event.widget == fZoomIn) {
1924
fZoomValue = fZoomValue * 2;
1925
} else if (event.widget == fZoomOut) {
1926
fZoomValue = fZoomValue / 2;
1932
* Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply button
1935
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
1938
public void propertyChange(PropertyChangeEvent e) {
1939
if (fFrame != null && !isDisposed()) {
1940
fFrame.resetTimeCompression();
1942
if (e.getProperty().equals("PREFOK")) //$NON-NLS-1$
1944
// Prepare the overview to be reused for the new
1945
// settings (especially the colors)
1946
if (fOverView != null) {
1947
fOverView.dispose();
1956
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
1959
public void widgetDisposed(DisposeEvent e) {
1960
if (fOverView != null) {
1961
fOverView.dispose();
1963
super.removeDisposeListener(this);
1964
if ((fCurrentCaretImage != null) && (!fCurrentCaretImage.isDisposed())) {
1965
fCurrentCaretImage.dispose();
1967
if ((fArrowUpCaretImg != null) && (!fArrowUpCaretImg.isDisposed())) {
1968
fArrowUpCaretImg.dispose();
1970
if ((fCollapaseCaretImg != null) && (!fCollapaseCaretImg.isDisposed())) {
1971
fCollapaseCaretImg.dispose();
1973
SDViewPref.getInstance().removePropertyChangeListener(this);
1974
LoadersManager lm = LoadersManager.getInstance();
1975
if (fSite instanceof SDView) {
1976
((SDView) fSite).resetProviders();
1978
lm.resetLoader(((SDView) fSite).getViewSite().getId());
1985
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawOverview(org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle)
1988
protected void drawOverview(GC gc, Rectangle r) {
1989
float oldzoom = fZoomValue;
1990
if (getContentsWidth() > getContentsHeight()) {
1991
fZoomValue = (float) r.width / (float) getContentsWidth() * oldzoom;
1993
fZoomValue = (float) r.height / (float) getContentsHeight() * oldzoom;
1995
if ((fOverView != null) && ((r.width != fOverView.getBounds().width) || (r.height != fOverView.getBounds().height))) {
1996
fOverView.dispose();
1999
if (fOverView == null) {
2000
int backX = getContentsX();
2001
int backY = getContentsY();
2002
setContentsPos(0, 0);
2003
fOverView = new Image(getDisplay(), r.width, r.height);
2004
GC gcim = new GC(fOverView);
2005
NGC context = new NGC(this, gcim);
2006
context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME));
2007
fFrame.draw(context);
2008
setContentsPos(backX, backY);
2012
if ((fOverView != null) && (r.width == fOverView.getBounds().width) && (r.height == fOverView.getBounds().height)) {
2013
gc.drawImage(fOverView, 0, 0, r.width, r.height, 0, 0, r.width, r.height);
2016
fZoomValue = oldzoom;
2018
super.drawOverview(gc, r);
2023
* @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)
2026
public void deltaSelected(Lifeline lifeline, int startEvent, int nbEvent, IColor color) {
2027
fFrame.highlightTimeCompression(lifeline, startEvent, nbEvent, color);
2028
ensureVisible(lifeline);
2029
int y1 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent;
2030
int y2 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * (startEvent + nbEvent);
2031
ensureVisible(lifeline.getX(), y1 - (Metrics.getLifelineHeaderFontHeigth() + +2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN), lifeline.getWidth(), y2 - y1 + 3, SWT.CENTER | SWT.VERTICAL, true);
2038
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleWidth()
2041
public int getVisibleWidth() {
2043
return fPrinter.getClientArea().width;
2045
return super.getVisibleWidth();
2050
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleHeight()
2053
public int getVisibleHeight() {
2055
return fPrinter.getClientArea().height;
2057
return super.getVisibleHeight();
2062
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewX(int)
2065
public int contentsToViewX(int x) {
2067
int v = Math.round(fPrinterX * fPrinterZoom);
2070
return x - getContentsX();
2075
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewY(int)
2078
public int contentsToViewY(int y) {
2080
int v = Math.round(fPrinterY * fPrinterZoom);
2083
return y - getContentsY();
2088
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsX()
2091
public int getContentsX() {
2093
return Math.round(fPrinterX * fPrinterZoom);
2095
return super.getContentsX();
2101
* @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsY()
2104
public int getContentsY() {
2106
return Math.round(fPrinterY * fPrinterZoom);
2108
return super.getContentsY();
2112
* Traverse Listener implementation.
2114
protected static class LocalTraverseListener implements TraverseListener {
2118
* @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
2121
public void keyTraversed(TraverseEvent e) {
2122
if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {