tmf: Simple warning fixes in tmf.core and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / SDWidget.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4
BH
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
013a5f1c 4 *
73005152
BH
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
013a5f1c
AM
9 *
10 * Contributors:
73005152
BH
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14package org.eclipse.linuxtools.tmf.ui.views.uml2sd;
15
16import java.text.MessageFormat;
17import java.util.ArrayList;
18import java.util.List;
19import java.util.Timer;
20import java.util.TimerTask;
21
22import org.eclipse.jface.contexts.IContextIds;
23import org.eclipse.jface.util.IPropertyChangeListener;
24import org.eclipse.jface.util.PropertyChangeEvent;
25import org.eclipse.jface.viewers.ISelectionProvider;
26import org.eclipse.jface.viewers.StructuredSelection;
8fd82db5 27import org.eclipse.linuxtools.internal.tmf.ui.Activator;
d34665f9 28import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
4df4581d 29import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b 30import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
73005152
BH
31import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage;
32import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence;
33import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame;
34import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
35import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange;
36import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
37import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Metrics;
df0b8ff4
BH
38import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.SDPrintDialog;
39import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.SDPrintDialogUI;
73005152 40import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
73005152
BH
41import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDCollapseProvider;
42import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager;
df0b8ff4 43import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
73005152
BH
44import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
45import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
73005152
BH
46import org.eclipse.swt.SWT;
47import org.eclipse.swt.accessibility.ACC;
48import org.eclipse.swt.accessibility.Accessible;
49import org.eclipse.swt.accessibility.AccessibleAdapter;
50import org.eclipse.swt.accessibility.AccessibleControlAdapter;
51import org.eclipse.swt.accessibility.AccessibleControlEvent;
52import org.eclipse.swt.accessibility.AccessibleEvent;
53import org.eclipse.swt.events.DisposeEvent;
54import org.eclipse.swt.events.DisposeListener;
55import org.eclipse.swt.events.FocusEvent;
56import org.eclipse.swt.events.FocusListener;
57import org.eclipse.swt.events.KeyEvent;
58import org.eclipse.swt.events.MouseEvent;
59import org.eclipse.swt.events.SelectionEvent;
60import org.eclipse.swt.events.SelectionListener;
61import org.eclipse.swt.events.TraverseEvent;
62import org.eclipse.swt.events.TraverseListener;
63import org.eclipse.swt.graphics.GC;
64import org.eclipse.swt.graphics.Image;
65import org.eclipse.swt.graphics.ImageData;
66import org.eclipse.swt.graphics.Rectangle;
67import org.eclipse.swt.printing.Printer;
68import org.eclipse.swt.printing.PrinterData;
69import org.eclipse.swt.widgets.Canvas;
70import org.eclipse.swt.widgets.Caret;
71import org.eclipse.swt.widgets.Composite;
72import org.eclipse.swt.widgets.Control;
73import org.eclipse.swt.widgets.Display;
74import org.eclipse.swt.widgets.Event;
75import org.eclipse.swt.widgets.Listener;
76import org.eclipse.swt.widgets.MenuItem;
77import org.eclipse.ui.contexts.IContextService;
78import org.eclipse.ui.part.ViewPart;
79
80/**
df0b8ff4
BH
81 * <p>
82 * This class implements sequence diagram widget used in the sequence diagram view.
83 * </p>
013a5f1c
AM
84 *
85 * @version 1.0
73005152 86 * @author sveyrier
73005152 87 */
a55887ca
AM
88public class SDWidget extends ScrollView implements SelectionListener,
89 IPropertyChangeListener, DisposeListener, ITimeCompressionListener {
73005152 90
df0b8ff4
BH
91 // ------------------------------------------------------------------------
92 // Attributes
93 // ------------------------------------------------------------------------
94
95 /**
96 * The frame to display in the sequence diagram widget.
97 */
eb63f5ff 98 protected Frame fFrame;
df0b8ff4
BH
99 /**
100 * The overview image to display.
101 */
eb63f5ff 102 protected Image fOverView = null;
df0b8ff4 103 /**
013a5f1c 104 * The zoom in menu item.
df0b8ff4 105 */
eb63f5ff 106 protected MenuItem fZoomIn = null;
df0b8ff4 107 /**
013a5f1c 108 * The zoom out menu item.
df0b8ff4 109 */
eb63f5ff 110 protected MenuItem fZoomOut = null;
df0b8ff4 111 /**
013a5f1c 112 * The sequence diagram selection provider.
df0b8ff4 113 */
eb63f5ff 114 protected SDWidgetSelectionProvider fSelProvider = null;
df0b8ff4 115 /**
013a5f1c 116 * The current zoom value.
df0b8ff4 117 */
eb63f5ff 118 public float fZoomValue = 1;
df0b8ff4 119 /**
013a5f1c 120 * The current zoomInMode (true for zoom in).
df0b8ff4 121 */
eb63f5ff 122 protected boolean fZoomInMode = false;
df0b8ff4 123 /**
013a5f1c 124 * The current zoomOutMode (true for zoom out).
df0b8ff4 125 */
eb63f5ff 126 protected boolean fZoomOutMode = false;
df0b8ff4 127 /**
013a5f1c 128 * The current list of selected graph nodes.
df0b8ff4 129 */
eb63f5ff 130 protected List<GraphNode> fSelectedNodeList = null;
df0b8ff4 131 /**
013a5f1c 132 * Flag whether ctrl button is selected or not.
df0b8ff4 133 */
eb63f5ff 134 protected boolean fCtrlSelection = false;
df0b8ff4 135 /**
013a5f1c 136 * A reference to the view site.
df0b8ff4 137 */
eb63f5ff 138 protected ViewPart fSite = null;
df0b8ff4 139 /**
013a5f1c 140 * The current graph node (the last selected one).
df0b8ff4 141 */
eb63f5ff 142 public GraphNode fCurrentGraphNode = null;
df0b8ff4 143 /**
013a5f1c 144 * The first graph node in list (multiple selection).
df0b8ff4 145 */
eb63f5ff 146 public GraphNode fListStart = null;
df0b8ff4 147 /**
013a5f1c 148 * The previous graph node (multiple selection).
df0b8ff4 149 */
eb63f5ff 150 public List<GraphNode> fPrevList = null;
df0b8ff4 151 /**
013a5f1c 152 * The time compression bar.
df0b8ff4 153 */
eb63f5ff 154 protected TimeCompressionBar fTimeBar = null;
df0b8ff4 155 /**
013a5f1c 156 * The current diagram tool tip.
df0b8ff4 157 */
eb63f5ff 158 protected DiagramToolTip fToolTip = null;
df0b8ff4
BH
159 /**
160 * The accessible object reference of view control.
161 */
eb63f5ff 162 protected Accessible fAccessible = null;
df0b8ff4
BH
163 /**
164 * The current node for the tooltip to display.
165 */
eb63f5ff 166 protected GraphNode fToolTipNode;
df0b8ff4
BH
167 /**
168 * The life line to drag and drop.
169 */
eb63f5ff 170 protected Lifeline fDragAndDrop = null;
df0b8ff4 171 /**
013a5f1c 172 * The number of focused widgets.
df0b8ff4 173 */
eb63f5ff 174 protected int fFocusedWidget = -1;
df0b8ff4
BH
175 /**
176 * The printer zoom.
177 */
eb63f5ff 178 protected float fPrinterZoom = 0;
df0b8ff4
BH
179 /**
180 * Y coordinate for printer.
181 */
eb63f5ff 182 protected int fPrinterY = 0;
df0b8ff4
BH
183 /**
184 * X coordinate for printer.
185 */
eb63f5ff 186 protected int fPrinterX = 0;
df0b8ff4 187 /**
013a5f1c 188 * Flag whether drag and drop is enabled or not.
df0b8ff4 189 */
eb63f5ff 190 protected boolean fIsDragAndDrop = false;
df0b8ff4
BH
191 /**
192 * The x coordinate for drag.
193 */
eb63f5ff 194 protected int fDragX = 0;
df0b8ff4
BH
195 /**
196 * The y coordinate for drag.
197 */
eb63f5ff 198 protected int fDragY = 0;
df0b8ff4
BH
199 /**
200 * The reorder mode.
201 */
eb63f5ff 202 protected boolean fReorderMode = false;
df0b8ff4
BH
203 /**
204 * The collapse caret image.
205 */
eb63f5ff 206 protected Image fCollapaseCaretImg = null;
df0b8ff4
BH
207 /**
208 * The arrow up caret image.
209 */
eb63f5ff 210 protected Image fArrowUpCaretImg = null;
df0b8ff4
BH
211 /**
212 * The current caret image.
213 */
eb63f5ff 214 protected Image fCurrentCaretImage = null;
df0b8ff4
BH
215 /**
216 * A sequence diagramm collapse provider (for collapsing graph nodes)
217 */
eb63f5ff 218 protected ISDCollapseProvider fCollapseProvider = null;
df0b8ff4
BH
219 /**
220 * The insertion caret.
221 */
eb63f5ff 222 protected Caret fInsertionCartet = null;
df0b8ff4
BH
223 /**
224 * The reorder list when in reorder mode.
225 */
3145ec83 226 protected List<Lifeline[]> fReorderList = null;
df0b8ff4
BH
227 /**
228 * Flag to specify whether in printing mode or not.
229 */
eb63f5ff 230 protected boolean fIsPrinting = false;
df0b8ff4
BH
231 /**
232 * A printer reference.
233 */
eb63f5ff 234 protected Printer fPrinter = null;
df0b8ff4 235 /**
013a5f1c 236 * Flag whether shift was selected or not.
df0b8ff4 237 */
eb63f5ff 238 protected boolean fShiftSelection = false;
df0b8ff4 239 /**
013a5f1c 240 * The scroll tooltip.
df0b8ff4 241 */
eb63f5ff 242 protected DiagramToolTip fScrollToolTip = null;
013a5f1c
AM
243 /**
244 * Timer for auto_scroll feature
df0b8ff4 245 */
eb63f5ff 246 protected AutoScroll fLocalAutoScroll = null;
df0b8ff4 247 /**
013a5f1c 248 * TimerTask for auto_scroll feature !=null when auto scroll is running
df0b8ff4 249 */
eb63f5ff 250 protected Timer fLocalAutoScrollTimer = null;
73005152 251
df0b8ff4
BH
252 // ------------------------------------------------------------------------
253 // Constructor
254 // ------------------------------------------------------------------------
255 /**
256 * Constructor for SDWidget.
257 * @param c The parent composite
258 * @param s The style
259 */
73005152
BH
260 public SDWidget(Composite c, int s) {
261 super(c, s | SWT.NO_BACKGROUND, true);
262 setOverviewEnabled(true);
eb63f5ff
BH
263 fSelectedNodeList = new ArrayList<GraphNode>();
264 fSelProvider = new SDWidgetSelectionProvider();
73005152 265 SDViewPref.getInstance().addPropertyChangeListener(this);
eb63f5ff 266 fToolTip = new DiagramToolTip(getViewControl());
73005152
BH
267 super.addDisposeListener(this);
268
eb63f5ff 269 fScrollToolTip = new DiagramToolTip(c);
73005152
BH
270 getVerticalBar().addListener(SWT.MouseUp, new Listener() {
271
272 @Override
273 public void handleEvent(Event event) {
eb63f5ff 274 fScrollToolTip.hideToolTip();
73005152
BH
275 }
276
277 });
eb63f5ff 278 fAccessible = getViewControl().getAccessible();
73005152 279
eb63f5ff 280 fAccessible.addAccessibleListener(new AccessibleAdapter() {
df0b8ff4
BH
281 /*
282 * (non-Javadoc)
283 * @see org.eclipse.swt.accessibility.AccessibleAdapter#getName(org.eclipse.swt.accessibility.AccessibleEvent)
284 */
73005152
BH
285 @Override
286 public void getName(AccessibleEvent e) {
73005152 287 // Case toolTip
df0b8ff4 288 if (e.childID == 0) {
eb63f5ff
BH
289 if (fToolTipNode != null) {
290 if (fToolTipNode instanceof Lifeline) {
291 Lifeline lifeline = (Lifeline) fToolTipNode;
73005152
BH
292 e.result = lifeline.getToolTipText();
293 } else {
eb63f5ff 294 e.result = fToolTipNode.getName() + getPostfixForTooltip(true);
73005152
BH
295 }
296 }
297 } else {
298 if (getFocusNode() != null) {
299 if (getFocusNode() instanceof Lifeline) {
300 e.result = MessageFormat.format(SDMessages._1, new Object[] { String.valueOf(getFocusNode().getName()) });
301 }
302 if (getFocusNode() instanceof BaseMessage) {
303 BaseMessage mes = (BaseMessage) getFocusNode();
304 if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() != null)) {
305 e.result = MessageFormat.format(
306 SDMessages._2,
307 new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()), String.valueOf(mes.getEndLifeline().getName()),
308 Integer.valueOf(mes.getEndOccurrence()) });
309 } else if ((mes.getStartLifeline() == null) && (mes.getEndLifeline() != null)) {
310 e.result = MessageFormat.format(SDMessages._4, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getEndLifeline().getName()), Integer.valueOf(mes.getEndOccurrence()) });
311 } else if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() == null)) {
312 e.result = MessageFormat.format(SDMessages._3, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()) });
313 }
314 } else if (getFocusNode() instanceof BasicExecutionOccurrence) {
315 BasicExecutionOccurrence exec = (BasicExecutionOccurrence) getFocusNode();
316 e.result = MessageFormat.format(SDMessages._5,
317 new Object[] { String.valueOf(exec.getName()), String.valueOf(exec.getLifeline().getName()), Integer.valueOf(exec.getStartOccurrence()), Integer.valueOf(exec.getEndOccurrence()) });
318 }
319
320 }
73005152
BH
321 }
322 }
323 });
324
eb63f5ff 325 fAccessible.addAccessibleControlListener(new AccessibleControlAdapter() {
df0b8ff4
BH
326 /*
327 * (non-Javadoc)
328 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getFocus(org.eclipse.swt.accessibility.AccessibleControlEvent)
329 */
73005152
BH
330 @Override
331 public void getFocus(AccessibleControlEvent e) {
eb63f5ff 332 if (fFocusedWidget == -1) {
73005152 333 e.childID = ACC.CHILDID_SELF;
df0b8ff4 334 } else {
eb63f5ff 335 e.childID = fFocusedWidget;
df0b8ff4 336 }
73005152
BH
337 }
338
df0b8ff4
BH
339 /*
340 * (non-Javadoc)
341 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getRole(org.eclipse.swt.accessibility.AccessibleControlEvent)
342 */
73005152
BH
343 @Override
344 public void getRole(AccessibleControlEvent e) {
345 switch (e.childID) {
346 case ACC.CHILDID_SELF:
347 e.detail = ACC.ROLE_CLIENT_AREA;
348 break;
349 case 0:
350 e.detail = ACC.ROLE_TOOLTIP;
351 break;
352 case 1:
353 e.detail = ACC.ROLE_LABEL;
354 break;
eb63f5ff
BH
355 default:
356 break;
73005152
BH
357 }
358 }
359
df0b8ff4
BH
360 /*
361 * (non-Javadoc)
362 * @see org.eclipse.swt.accessibility.AccessibleControlAdapter#getState(org.eclipse.swt.accessibility.AccessibleControlEvent)
363 */
73005152
BH
364 @Override
365 public void getState(AccessibleControlEvent e) {
366 e.detail = ACC.STATE_FOCUSABLE;
367 if (e.childID == ACC.CHILDID_SELF) {
368 e.detail |= ACC.STATE_FOCUSED;
369 } else {
370 e.detail |= ACC.STATE_SELECTABLE;
013a5f1c 371 if (e.childID == fFocusedWidget) {
73005152 372 e.detail |= ACC.STATE_FOCUSED | ACC.STATE_SELECTED | ACC.STATE_CHECKED;
013a5f1c 373 }
73005152
BH
374 }
375 }
376 });
377
eb63f5ff
BH
378 fInsertionCartet = new Caret((Canvas) getViewControl(), SWT.NONE);
379 fInsertionCartet.setVisible(false);
73005152 380
8fd82db5
FC
381 fCollapaseCaretImg = Activator.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_COLLAPSE_OBJ);
382 fArrowUpCaretImg = Activator.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_UP_OBJ);
73005152 383
eb63f5ff 384 fReorderList = new ArrayList<Lifeline[]>();
3145ec83 385 getViewControl().addTraverseListener(new LocalTraverseListener());
73005152 386
3145ec83 387 addTraverseListener(new LocalTraverseListener());
73005152
BH
388
389 getViewControl().addFocusListener(new FocusListener() {
390
df0b8ff4
BH
391 /*
392 * (non-Javadoc)
393 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
394 */
73005152
BH
395 @Override
396 public void focusGained(FocusEvent e) {
73005152 397 SDViewPref.getInstance().setNoFocusSelection(false);
eb63f5ff
BH
398 fCtrlSelection = false;
399 fShiftSelection = false;
73005152
BH
400 redraw();
401 }
402
df0b8ff4
BH
403 /*
404 * (non-Javadoc)
405 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
406 */
73005152
BH
407 @Override
408 public void focusLost(FocusEvent e) {
409 SDViewPref.getInstance().setNoFocusSelection(true);
410 redraw();
411 }
412 });
413 }
013a5f1c 414
df0b8ff4
BH
415 // ------------------------------------------------------------------------
416 // Operations
417 // ------------------------------------------------------------------------
418 /**
419 * Sets the time compression bar.
013a5f1c 420 *
df0b8ff4
BH
421 * @param bar The time compression bar to set
422 */
73005152
BH
423 public void setTimeBar(TimeCompressionBar bar) {
424 if (bar != null) {
eb63f5ff
BH
425 fTimeBar = bar;
426 fTimeBar.addTimeCompressionListener(this);
73005152
BH
427 }
428 }
013a5f1c 429
73005152
BH
430 /**
431 * Resize the contents to insure the frame fit into the view
013a5f1c 432 *
73005152
BH
433 * @param frame the frame which will be drawn in the view
434 */
435 public void resizeContents(Frame frame) {
eb63f5ff
BH
436 int width = Math.round((frame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
437 int height = Math.round((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
73005152
BH
438 resizeContents(width, height);
439 }
440
73005152
BH
441 /**
442 * The frame to render (the sequence diagram)
013a5f1c 443 *
73005152 444 * @param theFrame the frame to display
df0b8ff4 445 * @param resetPosition boolean
73005152
BH
446 */
447 public void setFrame(Frame theFrame, boolean resetPosition) {
eb63f5ff
BH
448 fReorderList.clear();
449 fSelectedNodeList.clear();
450 fSelProvider.setSelection(new StructuredSelection());
451 fFrame = theFrame;
73005152
BH
452 if (resetPosition) {
453 setContentsPos(0, 0);
eb63f5ff 454 resizeContents(fFrame);
73005152
BH
455 redraw();
456 }
457 // prepare the old overview to be reused
eb63f5ff
BH
458 if (fOverView != null) {
459 fOverView.dispose();
df0b8ff4 460 }
eb63f5ff
BH
461 fOverView = null;
462 resizeContents(fFrame);
73005152
BH
463 }
464
465 /**
466 * Returns the current Frame (the sequence diagram container)
013a5f1c
AM
467 *
468 * @return the frame
73005152
BH
469 */
470 public Frame getFrame() {
eb63f5ff 471 return fFrame;
73005152
BH
472 }
473
474 /**
475 * Returns the selection provider for the current sequence diagram
013a5f1c
AM
476 *
477 * @return the selection provider
73005152
BH
478 */
479 public ISelectionProvider getSelectionProvider() {
eb63f5ff 480 return fSelProvider;
73005152 481 }
013a5f1c 482
df0b8ff4
BH
483 /**
484 * Returns a list of selected graph nodes.
013a5f1c 485 *
df0b8ff4
BH
486 * @return a list of selected graph nodes.
487 */
488 public List<GraphNode> getSelection() {
eb63f5ff 489 return fSelectedNodeList;
73005152
BH
490 }
491
df0b8ff4
BH
492 /**
493 * Adds a graph node to the selected nodes list.
013a5f1c 494 *
df0b8ff4
BH
495 * @param node A graph node
496 */
497 public void addSelection(GraphNode node) {
498 if (node == null) {
499 return;
500 }
eb63f5ff 501 fSelectedNodeList.add(node);
df0b8ff4 502 node.setSelected(true);
eb63f5ff
BH
503 fCurrentGraphNode = node;
504 StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
505 fSelProvider.setSelection(selection);
df0b8ff4
BH
506 }
507
508 /**
509 * Adds a list of node to the selected nodes list.
013a5f1c 510 *
df0b8ff4
BH
511 * @param list of graph nodes
512 */
513 public void addSelection(List<GraphNode> list) {
514 // selectedNodeList.addAll(list);
515 for (int i = 0; i < list.size(); i++) {
eb63f5ff
BH
516 if (!fSelectedNodeList.contains(list.get(i))) {
517 fSelectedNodeList.add(list.get(i));
df0b8ff4
BH
518 ((GraphNode) list.get(i)).setSelected(true);
519 }
520 }
eb63f5ff
BH
521 StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
522 fSelProvider.setSelection(selection);
df0b8ff4
BH
523 }
524
525 /**
526 * Removes a node from the selected nodes list.
013a5f1c 527 *
df0b8ff4
BH
528 * @param node to remove
529 */
530 public void removeSelection(GraphNode node) {
eb63f5ff 531 fSelectedNodeList.remove(node);
df0b8ff4
BH
532 node.setSelected(false);
533 node.setFocused(false);
eb63f5ff
BH
534 StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
535 fSelProvider.setSelection(selection);
df0b8ff4
BH
536 }
537
538 /**
539 * Removes a list of graph nodes from the selected nodes list.
013a5f1c 540 *
df0b8ff4
BH
541 * @param list of nodes to remove.
542 */
543 public void removeSelection(List<GraphNode> list) {
eb63f5ff 544 fSelectedNodeList.removeAll(list);
df0b8ff4
BH
545 for (int i = 0; i < list.size(); i++) {
546 ((GraphNode) list.get(i)).setSelected(false);
547 ((GraphNode) list.get(i)).setFocused(false);
548 }
eb63f5ff
BH
549 StructuredSelection selection = new StructuredSelection(fSelectedNodeList);
550 fSelProvider.setSelection(selection);
df0b8ff4
BH
551 }
552
553 /**
554 * Clear the list of GraphNodes which must be drawn selected.
555 */
556 public void clearSelection() {
eb63f5ff
BH
557 for (int i = 0; i < fSelectedNodeList.size(); i++) {
558 ((GraphNode) fSelectedNodeList.get(i)).setSelected(false);
559 ((GraphNode) fSelectedNodeList.get(i)).setFocused(false);
df0b8ff4 560 }
eb63f5ff
BH
561 fCurrentGraphNode = null;
562 fSelectedNodeList.clear();
563 fSelProvider.setSelection(new StructuredSelection());
df0b8ff4
BH
564 }
565
566 /**
567 * Sets view part.
013a5f1c 568 *
df0b8ff4
BH
569 * @param viewSite The view part to set
570 */
571 public void setSite(ViewPart viewSite) {
eb63f5ff
BH
572 fSite = viewSite;
573 fSite.getSite().setSelectionProvider(fSelProvider);
574 IContextService service = (IContextService) fSite.getSite().getWorkbenchWindow().getService(IContextService.class);
df0b8ff4
BH
575 service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
576 service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
577 }
578
579 /**
580 * Returns the GraphNode overView the mouse if any
013a5f1c
AM
581 *
582 * @return the current graph node
df0b8ff4
BH
583 * */
584 public GraphNode getMouseOverNode() {
eb63f5ff 585 return fCurrentGraphNode;
df0b8ff4 586 }
013a5f1c 587
df0b8ff4
BH
588 /**
589 * Sets the zoom in mode.
013a5f1c 590 *
a55887ca
AM
591 * @param value
592 * The mode value to set.
df0b8ff4
BH
593 */
594 public void setZoomInMode(boolean value) {
595 if (value) {
596 setZoomOutMode(false);
597 }
eb63f5ff 598 fZoomInMode = value;
df0b8ff4
BH
599 }
600
601 /**
602 * Sets the zoom out mode.
013a5f1c 603 *
a55887ca
AM
604 * @param value
605 * The mode value to set.
df0b8ff4
BH
606 */
607 public void setZoomOutMode(boolean value) {
608 if (value) {
609 setZoomInMode(false);
610 }
eb63f5ff 611 fZoomOutMode = value;
df0b8ff4
BH
612 }
613
614 /**
615 * Moves the Sequence diagram to ensure the given node is visible and draw it selected
013a5f1c 616 *
df0b8ff4
BH
617 * @param node the GraphNode to move to
618 */
619 public void moveTo(GraphNode node) {
620 if (node == null) {
621 return;
622 }
623 clearSelection();
624 addSelection(node);
625 ensureVisible(node);
626 }
627
628 /**
629 * Moves the Sequence diagram to ensure the given node is visible
013a5f1c 630 *
df0b8ff4
BH
631 * @param node the GraphNode to move to
632 */
633 public void ensureVisible(GraphNode node) {
634 if (node == null) {
635 return;
636 }
eb63f5ff
BH
637 int x = Math.round(node.getX() * fZoomValue);
638 int y = Math.round(node.getY() * fZoomValue);
639 int width = Math.round(node.getWidth() * fZoomValue);
640 int height = Math.round(node.getHeight() * fZoomValue);
641 if ((node instanceof BaseMessage) && (height == 0)) {
642 int header = Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN * 2 + Metrics.getLifelineHeaderFontHeigth();
643 height = -Math.round((Metrics.getMessagesSpacing() + header) * fZoomValue);
644 y = y + Math.round(Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT * fZoomValue);
df0b8ff4
BH
645 }
646 if (node instanceof BasicExecutionOccurrence) {
647 width = 1;
648 height = 1;
649 }
650 if (node instanceof Lifeline) {
651 y = getContentsY();
652 height = getVisibleHeight();
653 }
654 ensureVisible(x, y, width, height, SWT.CENTER, true);
655 redraw();
656 }
657
658 /**
659 * Returns the current zoom factor.
660 * @return the current zoom factor.
661 */
662 public float getZoomFactor() {
eb63f5ff 663 return fZoomValue;
df0b8ff4
BH
664 }
665
666 /**
667 * Returns teh printer reference.
013a5f1c 668 *
df0b8ff4
BH
669 * @return the printer reference
670 */
671 public Printer getPrinter() {
eb63f5ff 672 return fPrinter;
df0b8ff4
BH
673 }
674
675 /**
676 * Returns whether the widget is used for printing or not.
013a5f1c 677 *
df0b8ff4
BH
678 * @return whether the widget is used for printing or not
679 */
680 public boolean isPrinting() {
eb63f5ff 681 return fIsPrinting;
df0b8ff4
BH
682 }
683
684 /**
685 * Gets the overview image.
013a5f1c 686 *
df0b8ff4
BH
687 * @param rect Rectangle to include overview.
688 * @return the overview image
689 */
690 public Image getOverview(Rectangle rect) {
eb63f5ff
BH
691 float oldzoom = fZoomValue;
692 if ((fOverView != null) && ((rect.width != fOverView.getBounds().width) || (rect.height != fOverView.getBounds().height))) {
693 fOverView.dispose();
694 fOverView = null;
df0b8ff4 695 }
eb63f5ff 696 if (fOverView == null) {
df0b8ff4
BH
697 int backX = getContentsX();
698 int backY = getContentsY();
699 setContentsPos(0, 0);
eb63f5ff
BH
700 fOverView = new Image(getDisplay(), rect.width, rect.height);
701 GC gcim = new GC(fOverView);
df0b8ff4
BH
702 NGC context = new NGC(this, gcim);
703 context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME));
eb63f5ff 704 fFrame.draw(context);
df0b8ff4
BH
705 setContentsPos(backX, backY);
706 gcim.dispose();
707 context.dispose();
708 }
eb63f5ff
BH
709 fZoomValue = oldzoom;
710 return fOverView;
df0b8ff4 711 }
013a5f1c 712
df0b8ff4
BH
713 /**
714 * Resets the zoom factor.
715 */
716 public void resetZoomFactor() {
eb63f5ff
BH
717 int currentX = Math.round(getContentsX() / fZoomValue);
718 int currentY = Math.round(getContentsY() / fZoomValue);
719 fZoomValue = 1;
720 if (fTimeBar != null && !fTimeBar.isDisposed()) {
721 fTimeBar.setZoom(fZoomValue);
df0b8ff4
BH
722 }
723 redraw();
724 update();
725 setContentsPos(currentX, currentY);
726 }
727
728 /**
729 * Enable or disable the lifeline reodering using Drag and Drop
013a5f1c 730 *
df0b8ff4
BH
731 * @param mode - true to enable false otherwise
732 */
733 public void setReorderMode(boolean mode) {
eb63f5ff 734 fReorderMode = mode;
df0b8ff4
BH
735 }
736
737 /**
738 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
739 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
013a5f1c
AM
740 *
741 * @return - the re-odered sequence
df0b8ff4 742 */
3145ec83 743 public List<Lifeline[]> getLifelineReoderList() {
eb63f5ff 744 return fReorderList;
df0b8ff4
BH
745 }
746
747 /**
748 * Sets the focus on given graph node (current node).
013a5f1c 749 *
a55887ca
AM
750 * @param node
751 * The graph node to focus on.
df0b8ff4
BH
752 */
753 public void setFocus(GraphNode node) {
754 if (node == null) {
755 return;
756 }
eb63f5ff
BH
757 if (fCurrentGraphNode != null) {
758 fCurrentGraphNode.setFocused(false);
df0b8ff4 759 }
eb63f5ff 760 fCurrentGraphNode = node;
df0b8ff4
BH
761 node.setFocused(true);
762 ensureVisible(node);
763 setFocus(0);
764 }
765
766 /**
767 * Returns the graph node focused on.
013a5f1c 768 *
df0b8ff4
BH
769 * @return the current graph node
770 */
771 public GraphNode getFocusNode() {
eb63f5ff 772 return fCurrentGraphNode;
df0b8ff4
BH
773 }
774
775 /**
776 * Method to traverse right.
777 */
778 public void traverseRight() {
779 Object selectedNode = getFocusNode();
780 if (selectedNode == null) {
781 traverseLeft();
782 }
783 GraphNode node = null;
eb63f5ff
BH
784 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
785 node = fFrame.getCalledMessage((BaseMessage) selectedNode);
df0b8ff4
BH
786 }
787 if (selectedNode instanceof BasicExecutionOccurrence) {
788 selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
789 }
790 if ((node == null) && (selectedNode instanceof Lifeline)) {
eb63f5ff
BH
791 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
792 if ((selectedNode == fFrame.getLifeline(i)) && (i < fFrame.lifeLinesCount() - 1)) {
793 node = fFrame.getLifeline(i + 1);
df0b8ff4
BH
794 break;
795 }
796 }
797 }
798 if (node != null) {
799 setFocus(node);
800 redraw();
801 }
802 }
803
804 /**
805 * Method to traverse left.
806 */
807 public void traverseLeft() {
808 Object selectedNode = getFocusNode();
809 GraphNode node = null;
eb63f5ff
BH
810 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
811 node = fFrame.getCallerMessage((BaseMessage) selectedNode);
df0b8ff4
BH
812 }
813 if (selectedNode instanceof BasicExecutionOccurrence) {
814 selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
815 }
816 if (node == null) {
eb63f5ff
BH
817 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
818 selectedNode = ((BaseMessage) selectedNode).getEndLifeline();
df0b8ff4 819 }
eb63f5ff
BH
820 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
821 if ((selectedNode == fFrame.getLifeline(i)) && (i > 0)) {
822 node = fFrame.getLifeline(i - 1);
df0b8ff4
BH
823 break;
824 }
825 }
eb63f5ff
BH
826 if ((fFrame.lifeLinesCount() > 0) && (node == null)) {
827 node = fFrame.getLifeline(0);
df0b8ff4
BH
828 }
829 }
830 if (node != null) {
831 setFocus(node);
832 redraw();
833 }
834 }
835
836 /**
837 * Method to traverse up.
838 */
839 public void traverseUp() {
840 Object selectedNode = getFocusNode();
841 if (selectedNode == null) {
842 traverseLeft();
843 }
844 GraphNode node = null;
845 if (selectedNode instanceof BaseMessage) {
eb63f5ff 846 node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
df0b8ff4 847 } else if (selectedNode instanceof Lifeline) {
eb63f5ff 848 node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
df0b8ff4
BH
849 if (!(node instanceof Lifeline)) {
850 node = null;
851 }
852 } else if (selectedNode instanceof BasicExecutionOccurrence) {
eb63f5ff 853 node = fFrame.getPrevExecOccurrence((BasicExecutionOccurrence) selectedNode);
df0b8ff4
BH
854 if (node == null) {
855 node = ((BasicExecutionOccurrence) selectedNode).getLifeline();
856 }
857 }
eb63f5ff
BH
858 if ((node == null) && (selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
859 node = ((BaseMessage) selectedNode).getStartLifeline();
df0b8ff4
BH
860 }
861
862 if (node != null) {
863 setFocus(node);
864 redraw();
865 }
866 }
867
868 /**
869 * Method to traverse down.
870 */
871 public void traverseDown() {
872 Object selectedNode = getFocusNode();
873 if (selectedNode == null) {
874 traverseLeft();
875 }
876 GraphNode node;
877 if (selectedNode instanceof BaseMessage) {
eb63f5ff 878 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
df0b8ff4
BH
879 } else if (selectedNode instanceof Lifeline) {
880 // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null);
eb63f5ff 881 node = fFrame.getFirstExecution((Lifeline) selectedNode);
df0b8ff4 882 } else if (selectedNode instanceof BasicExecutionOccurrence) {
eb63f5ff 883 node = fFrame.getNextExecOccurrence((BasicExecutionOccurrence) selectedNode);
df0b8ff4
BH
884 } else {
885 return;
886 }
887
888 if (node != null) {
889 setFocus(node);
890 redraw();
891 }
892 }
893
894 /**
895 * Method to traverse home.
896 */
897 public void traverseHome() {
898 Object selectedNode = getFocusNode();
899 if (selectedNode == null) {
900 traverseLeft();
901 }
902 GraphNode node = null;
013a5f1c 903
df0b8ff4
BH
904 if (selectedNode instanceof BaseMessage) {
905 if (((BaseMessage) selectedNode).getStartLifeline() != null) {
eb63f5ff 906 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
df0b8ff4 907 } else {
eb63f5ff 908 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getEndLifeline(), null);
df0b8ff4
BH
909 }
910 } else if (selectedNode instanceof Lifeline) {
eb63f5ff 911 node = fFrame.getNextLifelineMessage((Lifeline) selectedNode, null);
df0b8ff4 912 } else if (selectedNode instanceof BasicExecutionOccurrence) {
eb63f5ff 913 node = fFrame.getFirstExecution(((BasicExecutionOccurrence) selectedNode).getLifeline());
df0b8ff4 914 } else {
eb63f5ff
BH
915 if (fFrame.lifeLinesCount() > 0) {
916 Lifeline lifeline = fFrame.getLifeline(0);
917 node = fFrame.getNextLifelineMessage(lifeline, null);
df0b8ff4
BH
918 }
919 }
920
921 if (node != null) {
922 setFocus(node);
923 redraw();
924 }
925 }
926
927 /**
928 * Method to traverse to the end.
929 */
930 public void traverseEnd() {
931 Object selectedNode = getFocusNode();
932 if (selectedNode == null) {
933 traverseLeft();
934 }
935 GraphNode node;
936 if (selectedNode instanceof BaseMessage) {
eb63f5ff 937 node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
df0b8ff4 938 } else if (selectedNode instanceof Lifeline) {
eb63f5ff 939 node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
df0b8ff4 940 } else if (selectedNode instanceof BasicExecutionOccurrence) {
eb63f5ff 941 node = fFrame.getLastExecOccurrence(((BasicExecutionOccurrence) selectedNode).getLifeline());
df0b8ff4 942 } else {
eb63f5ff
BH
943 if (fFrame.lifeLinesCount() > 0) {
944 Lifeline lifeline = fFrame.getLifeline(0);
945 node = fFrame.getPrevLifelineMessage(lifeline, null);
df0b8ff4
BH
946 } else {
947 return;
948 }
949 }
950
951 if (node != null) {
952 setFocus(node);
953 redraw();
954 }
955 }
956
957 /**
958 * Method to print UI.
013a5f1c 959 *
df0b8ff4
BH
960 * @param sdPrintDialog the sequence diagram printer dialog.
961 */
962 public void printUI(SDPrintDialogUI sdPrintDialog) {
963 PrinterData data = sdPrintDialog.getPrinterData();
964
eb63f5ff 965 if ((data == null) || (fFrame == null)) {
df0b8ff4
BH
966 return;
967 }
013a5f1c 968
eb63f5ff 969 fPrinter = new Printer(data);
013a5f1c 970
eb63f5ff
BH
971 String jobName = MessageFormat.format(SDMessages._116, new Object[] { String.valueOf(fSite.getContentDescription()), String.valueOf(fFrame.getName()) });
972 fPrinter.startJob(jobName);
013a5f1c 973
eb63f5ff 974 GC gc = new GC(fPrinter);
3145ec83 975// Frame.setUserPref(SDViewPref.getInstance());
df0b8ff4 976
eb63f5ff 977 float lastZoom = fZoomValue;
df0b8ff4
BH
978
979 Rectangle area = getClientArea();
980 GC gcim = null;
981
982 gcim = gc;
983 NGC context = new NGC(this, gcim);
984
985 // Set the metrics to use for lifeline text and message text
986 // using the Graphical Context
987 Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
988 Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
989 Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
3145ec83
BH
990 Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
991 Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
df0b8ff4
BH
992
993 int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS));
994 int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET));
995 int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS));
996 int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET));
997
998 int messageFontHeight = 0;
999 if (syncMessFontH > syncMessRetFontH) {
1000 messageFontHeight = syncMessFontH;
1001 } else {
1002 messageFontHeight = syncMessRetFontH;
1003 }
1004 if (messageFontHeight < asyncMessFontH) {
1005 messageFontHeight = asyncMessFontH;
1006 }
1007 if (messageFontHeight < asyncMessRetFontH) {
1008 messageFontHeight = asyncMessRetFontH;
1009 }
1010 Metrics.setMessageFontHeight(messageFontHeight);
1011 context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1012
eb63f5ff
BH
1013 int width = Math.round((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1014 int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
df0b8ff4
BH
1015 if (width < area.width) {
1016 width = area.width;
1017 }
1018 if (height < area.height) {
1019 height = area.height;
1020 }
1021 resizeContents(width, height);
1022
3145ec83 1023 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
df0b8ff4 1024 context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
eb63f5ff
BH
1025 context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1026 context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1027 context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
df0b8ff4
BH
1028 gcim.setLineWidth(1);
1029
eb63f5ff
BH
1030 fPrinter.startPage();
1031 fZoomValue = lastZoom;
df0b8ff4
BH
1032
1033 int restoreX = getContentsX();
1034 int restoreY = getContentsY();
1035
eb63f5ff
BH
1036 float zh = sdPrintDialog.getStepY() * sdPrintDialog.getZoomFactor();
1037 float zw = sdPrintDialog.getStepX() * sdPrintDialog.getZoomFactor();
df0b8ff4 1038
eb63f5ff
BH
1039 float zoomValueH = fPrinter.getClientArea().height / zh;
1040 float zoomValueW = fPrinter.getClientArea().width / zw;
df0b8ff4 1041 if (zoomValueH > zoomValueW) {
eb63f5ff 1042 fPrinterZoom = zoomValueH;
df0b8ff4 1043 } else {
eb63f5ff 1044 fPrinterZoom = zoomValueW;
df0b8ff4
BH
1045 }
1046
1047 if (sdPrintDialog.printSelection()) {
1048 int[] pagesList = sdPrintDialog.getPageList();
1049
1050 for (int pageIndex = 0; pageIndex < pagesList.length; pageIndex++) {
1051 printPage(pagesList[pageIndex], sdPrintDialog, context);
1052 }
1053 } else if (sdPrintDialog.printAll()) {
1054 for (int pageIndex = 1; pageIndex <= sdPrintDialog.maxNumOfPages(); pageIndex++) {
1055 printPage(pageIndex, sdPrintDialog, context);
1056 }
1057 } else if (sdPrintDialog.printCurrent()) {
1058 printPage(getContentsX(), getContentsY(), sdPrintDialog, context, 1);
1059 } else if (sdPrintDialog.printRange()) {
1060 for (int pageIndex = sdPrintDialog.getFrom(); pageIndex <= sdPrintDialog.maxNumOfPages() && pageIndex <= sdPrintDialog.getTo(); pageIndex++) {
1061 printPage(pageIndex, sdPrintDialog, context);
1062 }
1063 }
1064
eb63f5ff
BH
1065 fPrinter.endJob();
1066 fIsPrinting = false;
df0b8ff4
BH
1067
1068 gc.dispose();
1069 context.dispose();
1070
eb63f5ff
BH
1071 fZoomValue = lastZoom;
1072 fPrinter.dispose();
df0b8ff4
BH
1073 setContentsPos(restoreX, restoreY);
1074 }
1075
1076 /**
1077 * Method to print.
1078 */
1079 public void print() {
1080 SDPrintDialog sdPrinter = new SDPrintDialog(this.getShell(), this);
1081 try {
1082 if (sdPrinter.open() != 0) {
1083 return;
1084 }
1085 } catch (Exception e) {
8fd82db5 1086 Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
df0b8ff4
BH
1087 return;
1088 }
1089 printUI(sdPrinter.getDialogUI());
1090 }
1091
1092 /**
1093 * Method to print a page.
013a5f1c 1094 *
df0b8ff4
BH
1095 * @param pageNum The page number
1096 * @param pd The sequence diagram print dialog
1097 * @param context The graphical context
1098 */
1099 public void printPage(int pageNum, SDPrintDialogUI pd, NGC context) {
1100 int j = pageNum / pd.getNbRow();
1101 int i = pageNum % pd.getNbRow();
1102 if (i != 0) {
1103 j++;
1104 } else {
1105 i = pd.getNbRow();
1106 }
1107
1108 i--;
1109 j--;
1110
1111 i = (int) (i * pd.getStepX());
1112 j = (int) (j * pd.getStepY());
1113
1114 printPage(i, j, pd, context, pageNum);
1115
eb63f5ff 1116 fPrinter.endPage();
df0b8ff4
BH
1117 }
1118
1119 /**
1120 * Method to print page ranges.
013a5f1c 1121 *
a55887ca
AM
1122 * @param i
1123 * The start page
1124 * @param j
1125 * The end page
1126 * @param pd
1127 * The sequence diagram print dialog
1128 * @param context
1129 * The graphical context
1130 * @param pageNum
1131 * The current page
df0b8ff4
BH
1132 */
1133 public void printPage(int i, int j, SDPrintDialogUI pd, NGC context, int pageNum) {
eb63f5ff
BH
1134 fIsPrinting = false;
1135 int pageNumFontZoom = fPrinter.getClientArea().height / getVisibleHeight();
1136 fPrinterX = i;
1137 fPrinterY = j;
df0b8ff4
BH
1138 setContentsPos(i, j);
1139 update();
eb63f5ff
BH
1140 fIsPrinting = true;
1141 float lastZoom = fZoomValue;
1142 fZoomValue = fPrinterZoom * lastZoom;
df0b8ff4 1143
eb63f5ff 1144 fFrame.draw(context);
df0b8ff4 1145
eb63f5ff 1146 fZoomValue = pageNumFontZoom;
df0b8ff4
BH
1147 context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1148 String currentPageNum = String.valueOf(pageNum);
1149 int ii = context.textExtent(currentPageNum);
1150 int jj = context.getCurrentFontHeight();
1151 // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK));
1152 // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE));
eb63f5ff
BH
1153 fZoomValue = fPrinterZoom * lastZoom;
1154 context.drawText(currentPageNum, Math.round(fPrinterX + getVisibleWidth() / fPrinterZoom - ii / fPrinterZoom), Math.round(fPrinterY + getVisibleHeight() / fPrinterZoom - jj / fPrinterZoom), false);
1155 fIsPrinting = false;
1156 fZoomValue = lastZoom;
df0b8ff4 1157 }
013a5f1c 1158
df0b8ff4
BH
1159 /**
1160 * Sets the collapse provider.
013a5f1c 1161 *
df0b8ff4
BH
1162 * @param provider The collapse provider to set
1163 */
1164 protected void setCollapseProvider(ISDCollapseProvider provider) {
eb63f5ff 1165 fCollapseProvider = provider;
df0b8ff4
BH
1166 }
1167
013a5f1c 1168
df0b8ff4
BH
1169 /**
1170 * Checks for focus of children.
013a5f1c 1171 *
df0b8ff4
BH
1172 * @param children Control to check
1173 * @return true if child is on focus else false
1174 */
1175 protected boolean checkFocusOnChilds(Control children) {
1176 if (children instanceof Composite) {
1177 Control[] child = ((Composite) children).getChildren();
1178 for (int i = 0; i < child.length; i++) {
1179 if (child[i].isFocusControl()) {
1180 return true;
73005152 1181 } else {
df0b8ff4 1182 checkFocusOnChilds(child[i]);
73005152 1183 }
df0b8ff4 1184 }
73005152 1185 }
df0b8ff4 1186 return false;
73005152
BH
1187 }
1188
df0b8ff4
BH
1189 /**
1190 * A post action for a tooltip (before displaying).
013a5f1c 1191 *
df0b8ff4
BH
1192 * @param accessible true if accessible else false
1193 * @return the tooltip text.
1194 */
73005152 1195 protected String getPostfixForTooltip(boolean accessible) {
3145ec83
BH
1196 StringBuffer postfix = new StringBuffer();
1197// String postfix = "";//$NON-NLS-1$
73005152
BH
1198 // Determine if the tooltip must show the time difference between the current mouse position and
1199 // the last selected graphNode
013a5f1c
AM
1200 if ((fCurrentGraphNode != null) &&
1201 (fCurrentGraphNode instanceof ITimeRange) &&
1202 (fToolTipNode instanceof ITimeRange) &&
1203 (fCurrentGraphNode != fToolTipNode) &&
1204 ((ITimeRange) fToolTipNode).hasTimeInfo() &&
eb63f5ff 1205 ((ITimeRange) fCurrentGraphNode).hasTimeInfo()) {
3145ec83
BH
1206 postfix.append(" -> "); //$NON-NLS-1$
1207 postfix.append(fCurrentGraphNode.getName());
1208 postfix.append("\n"); //$NON-NLS-1$
1209 postfix.append(SDMessages._138);
1210 postfix.append(" "); //$NON-NLS-1$
013a5f1c
AM
1211
1212// postfix = " -> " + fCurrentGraphNode.getName() + "\n" + SDMessages._138 + " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1213
73005152 1214 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
eb63f5ff
BH
1215 ITmfTimestamp firstTime = ((ITimeRange) fCurrentGraphNode).getEndTime();
1216 ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
5179fc01 1217 TmfTimestamp delta = (TmfTimestamp) lastTime.getDelta(firstTime);
3145ec83
BH
1218 postfix.append(delta.toString());
1219
1220// postfix += delta.toString();
73005152 1221 } else {
eb63f5ff 1222 if ((fToolTipNode instanceof ITimeRange) && ((ITimeRange) fToolTipNode).hasTimeInfo()) {
3145ec83
BH
1223 postfix.append("\n"); //$NON-NLS-1$
1224// postfix = "\n";//$NON-NLS-1$
eb63f5ff 1225 ITmfTimestamp firstTime = ((ITimeRange) fToolTipNode).getStartTime();
013a5f1c
AM
1226 ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
1227
73005152
BH
1228 if (firstTime != null) {
1229 if (lastTime != null && firstTime.compareTo(lastTime, true) != 0) {
3145ec83
BH
1230 postfix.append("start: "); //$NON-NLS-1$
1231 postfix.append(firstTime.toString());
1232 postfix.append("\n"); //$NON-NLS-1$
013a5f1c 1233 postfix.append("end: "); //$NON-NLS-1$
3145ec83
BH
1234 postfix.append(lastTime.toString());
1235 postfix.append("\n"); //$NON-NLS-1$
1236// postfix += "start: " + firstTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
1237// postfix += "end: " + lastTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
df0b8ff4 1238 } else {
3145ec83 1239 postfix.append(firstTime.toString());
013a5f1c 1240// postfix += firstTime.toString();
df0b8ff4
BH
1241 }
1242 }
1243 else if (lastTime != null) {
3145ec83
BH
1244 postfix.append(lastTime.toString());
1245// postfix += lastTime.toString();
73005152 1246 }
73005152
BH
1247 }
1248 }
3145ec83 1249 return postfix.toString();
df0b8ff4 1250 }
73005152 1251
df0b8ff4
BH
1252 /**
1253 * Sets a new focused widget.
013a5f1c 1254 *
df0b8ff4
BH
1255 * @param newFocusShape A new focus shape.
1256 */
1257 protected void setFocus(int newFocusShape) {
eb63f5ff
BH
1258 fFocusedWidget = newFocusShape;
1259 if (fFocusedWidget == -1) {
df0b8ff4
BH
1260 getViewControl().getAccessible().setFocus(ACC.CHILDID_SELF);
1261 } else {
eb63f5ff 1262 getViewControl().getAccessible().setFocus(fFocusedWidget);
df0b8ff4 1263 }
73005152
BH
1264 }
1265
1266 /**
1267 * Highlight the given GraphNode<br>
1268 * The GraphNode is then displayed using the system default selection color
013a5f1c 1269 *
73005152
BH
1270 * @param node the GraphNode to highlight
1271 */
1272 protected void performSelection(GraphNode node) {
eb63f5ff 1273 if ((fCtrlSelection) || (fShiftSelection)) {
73005152 1274 if (node != null) {
eb63f5ff 1275 if (fSelectedNodeList.contains(node)) {
73005152
BH
1276 removeSelection(node);
1277 } else {
1278 addSelection(node);
1279 }
df0b8ff4 1280 } else {
73005152 1281 return;
df0b8ff4 1282 }
73005152
BH
1283 } else {
1284 clearSelection();
1285 if (node != null) {
1286 addSelection(node);
1287 }
1288 }
1289 }
1290
73005152 1291 /**
df0b8ff4 1292 * Returns a draw buffer image.
013a5f1c
AM
1293 *
1294 * @return a Image containing the draw buffer.
73005152 1295 */
df0b8ff4 1296 protected Image getDrawBuffer() {
73005152
BH
1297
1298 update();
1299 Rectangle area = getClientArea();
1300 Image dbuffer = null;
1301 GC gcim = null;
1302
1303 try {
73005152
BH
1304 dbuffer = new Image(getDisplay(), area.width, area.height);
1305 } catch (Exception e) {
8fd82db5 1306 Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
73005152 1307 }
df0b8ff4 1308
73005152
BH
1309 gcim = new GC(dbuffer);
1310
1311 NGC context = new NGC(this, gcim);
1312
1313 // Set the metrics to use for lifeline text and message text
1314 // using the Graphical Context
1315 Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
1316 Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)));
1317 Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
3145ec83
BH
1318 Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
1319 Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
73005152
BH
1320
1321 int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS));
1322 int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET));
1323 int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS));
1324 int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET));
1325
1326 int messageFontHeight = 0;
df0b8ff4 1327 if (syncMessFontH > syncMessRetFontH) {
73005152 1328 messageFontHeight = syncMessFontH;
df0b8ff4 1329 } else {
73005152 1330 messageFontHeight = syncMessRetFontH;
df0b8ff4
BH
1331 }
1332 if (messageFontHeight < asyncMessFontH) {
73005152 1333 messageFontHeight = asyncMessFontH;
df0b8ff4
BH
1334 }
1335 if (messageFontHeight < asyncMessRetFontH) {
73005152 1336 messageFontHeight = asyncMessRetFontH;
df0b8ff4 1337 }
73005152
BH
1338 Metrics.setMessageFontHeight(messageFontHeight);
1339 context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE));
1340
eb63f5ff
BH
1341 int width = (int) ((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1342 int height = (int) ((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
df0b8ff4 1343
73005152
BH
1344 resizeContents(width, height);
1345
3145ec83 1346 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
73005152 1347 context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
eb63f5ff
BH
1348 context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1349 context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1350 context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
73005152
BH
1351 gcim.setLineWidth(1);
1352
eb63f5ff
BH
1353 fFrame.draw(context);
1354 if (fDragAndDrop != null) {
1355 Lifeline node = (Lifeline) fDragAndDrop;
1356 boolean isSelected = fDragAndDrop.isSelected();
1357 boolean hasFocus = fDragAndDrop.hasFocus();
73005152
BH
1358 node.setSelected(false);
1359 node.setFocused(false);
eb63f5ff 1360 node.draw(context, fDragX, fDragY);
73005152
BH
1361 node.setSelected(isSelected);
1362 node.setFocused(hasFocus);
1363 }
1364 gcim.dispose();
1365 context.dispose();
1366 return dbuffer;
1367 }
013a5f1c 1368
df0b8ff4
BH
1369 /*
1370 * (non-Javadoc)
1371 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyPressedEvent(org.eclipse.swt.events.KeyEvent)
73005152
BH
1372 */
1373 @Override
df0b8ff4
BH
1374 protected void keyPressedEvent(KeyEvent event) {
1375 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1376 Control[] child = getParent().getChildren();
1377 for (int i = 0; i < child.length; i++) {
eb63f5ff
BH
1378 if ((child[i].isFocusControl())&& (!(child[i] instanceof ScrollView))) {
1379 getViewControl().setFocus();
1380 break;
df0b8ff4
BH
1381 }
1382 }
73005152 1383 }
df0b8ff4 1384 setFocus(-1);
73005152 1385
df0b8ff4 1386 if (event.keyCode == SWT.CTRL) {
eb63f5ff 1387 fCtrlSelection = true;
df0b8ff4
BH
1388 }
1389 if (event.keyCode == SWT.SHIFT) {
eb63f5ff
BH
1390 fShiftSelection = true;
1391 fPrevList = new ArrayList<GraphNode>();
1392 fPrevList.addAll(getSelection());
df0b8ff4 1393 }
73005152 1394
df0b8ff4
BH
1395 GraphNode prevNode = getFocusNode();
1396
1397 if (event.keyCode == SWT.ARROW_RIGHT) {
1398 traverseRight();
73005152 1399 }
df0b8ff4
BH
1400
1401 if (event.keyCode == SWT.ARROW_LEFT) {
1402 traverseLeft();
73005152 1403 }
df0b8ff4
BH
1404
1405 if (event.keyCode == SWT.ARROW_DOWN) {
1406 traverseDown();
73005152 1407 }
73005152 1408
df0b8ff4
BH
1409 if (event.keyCode == SWT.ARROW_UP) {
1410 traverseUp();
1411 }
73005152 1412
df0b8ff4
BH
1413 if (event.keyCode == SWT.HOME) {
1414 traverseHome();
1415 }
73005152 1416
df0b8ff4
BH
1417 if (event.keyCode == SWT.END) {
1418 traverseEnd();
73005152 1419 }
73005152 1420
eb63f5ff
BH
1421 if ((!fShiftSelection) && (!fCtrlSelection)) {
1422 fListStart = fCurrentGraphNode;
df0b8ff4 1423 }
73005152 1424
df0b8ff4 1425 if (event.character == ' ') {
eb63f5ff 1426 performSelection(fCurrentGraphNode);
013a5f1c 1427 if (!fShiftSelection) {
eb63f5ff 1428 fListStart = fCurrentGraphNode;
013a5f1c 1429 }
df0b8ff4 1430 }
73005152 1431
eb63f5ff 1432 if ((fShiftSelection) && (prevNode != getFocusNode())) {
df0b8ff4 1433 clearSelection();
eb63f5ff
BH
1434 addSelection(fPrevList);
1435 addSelection(fFrame.getNodeList(fListStart, getFocusNode()));
df0b8ff4
BH
1436 if (getFocusNode() instanceof Lifeline) {
1437 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
013a5f1c 1438 } else {
df0b8ff4
BH
1439 ensureVisible(getFocusNode());
1440 }
eb63f5ff 1441 } else if ((!fCtrlSelection) && (!fShiftSelection)) {
73005152 1442
df0b8ff4
BH
1443 clearSelection();
1444 if (getFocusNode() != null) {
1445 addSelection(getFocusNode());
1446
1447 if (getFocusNode() instanceof Lifeline) {
1448 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
1449 } else {
1450 ensureVisible(getFocusNode());
1451 }
73005152
BH
1452 }
1453 }
df0b8ff4 1454
eb63f5ff
BH
1455 if (fCurrentGraphNode != null) {
1456 fCurrentGraphNode.setFocused(true);
73005152 1457 }
73005152 1458 redraw();
73005152 1459
eb63f5ff
BH
1460 if ((event.character == ' ') && ((fZoomInMode) || (fZoomOutMode))) {
1461 int cx = Math.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue);
1462 int cy = Math.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue);
1463 if (fZoomInMode) {
1464 if (fZoomValue < 64) {
1465 fZoomValue = fZoomValue * (float) 1.25;
df0b8ff4
BH
1466 }
1467 } else {
eb63f5ff 1468 fZoomValue = fZoomValue / (float) 1.25;
df0b8ff4 1469 }
eb63f5ff
BH
1470 int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1471 int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
df0b8ff4 1472 setContentsPos(x, y);
eb63f5ff
BH
1473 if (fTimeBar != null) {
1474 fTimeBar.setZoom(fZoomValue);
df0b8ff4
BH
1475 }
1476 // redraw also resize the scrollView content
1477 redraw();
1478 }
73005152
BH
1479 }
1480
df0b8ff4
BH
1481 /*
1482 * (non-Javadoc)
1483 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#keyReleasedEvent(org.eclipse.swt.events.KeyEvent)
73005152
BH
1484 */
1485 @Override
df0b8ff4
BH
1486 protected void keyReleasedEvent(KeyEvent event) {
1487 setFocus(-1);
013a5f1c 1488 if (event.keyCode == SWT.CTRL) {
eb63f5ff 1489 fCtrlSelection = false;
013a5f1c
AM
1490 }
1491 if (event.keyCode == SWT.SHIFT) {
eb63f5ff 1492 fShiftSelection = false;
013a5f1c 1493 }
df0b8ff4
BH
1494 super.keyReleasedEvent(event);
1495 setFocus(1);
73005152
BH
1496 }
1497
df0b8ff4
BH
1498 /*
1499 * (non-Javadoc)
1500 * @see org.eclipse.swt.widgets.Control#isFocusControl()
1501 */
73005152 1502 @Override
df0b8ff4
BH
1503 public boolean isFocusControl() {
1504 Control[] child = getChildren();
1505 for (int i = 0; i < child.length; i++) {
1506 if (child[i].isFocusControl()) {
1507 return true;
1508 } else {
1509 checkFocusOnChilds(child[i]);
1510 }
73005152 1511 }
df0b8ff4 1512 return false;
73005152
BH
1513 }
1514
df0b8ff4
BH
1515 /*
1516 * (non-Javadoc)
1517 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#setContentsPos(int, int)
1518 */
1519 @Override
1520 public boolean setContentsPos(int x, int y) {
eb63f5ff
BH
1521 int localX = x;
1522 int localY = y;
013a5f1c 1523
eb63f5ff
BH
1524 if (localX < 0) {
1525 localX = 0;
73005152 1526 }
eb63f5ff
BH
1527 if (localY < 0) {
1528 localY = 0;
73005152 1529 }
eb63f5ff 1530 if (fFrame == null) {
df0b8ff4 1531 return false;
73005152 1532 }
eb63f5ff
BH
1533 if (localX + getVisibleWidth() > getContentsWidth()) {
1534 localX = getContentsWidth() - getVisibleWidth();
73005152 1535 }
eb63f5ff
BH
1536 if (localY + getVisibleHeight() > getContentsHeight()) {
1537 localY = getContentsHeight() - getVisibleHeight();
df0b8ff4 1538 }
eb63f5ff
BH
1539 int x1 = Math.round(localX / fZoomValue);
1540 int y2 = Math.round(localY / fZoomValue);
1541 int width = Math.round(getVisibleWidth() / fZoomValue);
1542 int height = Math.round(getVisibleHeight() / fZoomValue);
1543 fFrame.updateIndex(x1, y2, width, height);
73005152 1544
eb63f5ff
BH
1545 if (fInsertionCartet != null && fInsertionCartet.isVisible()) {
1546 fInsertionCartet.setVisible(false);
df0b8ff4 1547 }
73005152 1548
eb63f5ff 1549 return super.setContentsPos(localX, localY);
73005152
BH
1550 }
1551
df0b8ff4
BH
1552 /*
1553 * (non-Javadoc)
1554 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseHover(org.eclipse.swt.events.MouseEvent)
1555 */
73005152 1556 @Override
df0b8ff4
BH
1557 protected void contentsMouseHover(MouseEvent event) {
1558 GraphNode graphNode = null;
eb63f5ff
BH
1559 if (fFrame != null) {
1560 int x = Math.round(event.x / fZoomValue);
1561 int y = Math.round(event.y / fZoomValue);
1562 graphNode = fFrame.getNodeAt(x, y);
df0b8ff4 1563 if ((graphNode != null) && (SDViewPref.getInstance().tooltipEnabled())) {
eb63f5ff 1564 fToolTipNode = graphNode;
df0b8ff4
BH
1565 String postfix = getPostfixForTooltip(true);
1566 if (graphNode instanceof Lifeline) {
1567 Lifeline lifeline = (Lifeline) graphNode;
eb63f5ff 1568 fToolTip.showToolTip(lifeline.getToolTipText() + postfix);
df0b8ff4
BH
1569 setFocus(0);
1570 } else {
eb63f5ff 1571 fToolTip.showToolTip(graphNode.getName() + postfix);
df0b8ff4
BH
1572 setFocus(0);
1573 }
1574 } else {
eb63f5ff 1575 fToolTip.hideToolTip();
df0b8ff4 1576 }
73005152 1577 }
73005152
BH
1578 }
1579
df0b8ff4
BH
1580 /*
1581 * (non-Javadoc)
1582 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseMoveEvent(org.eclipse.swt.events.MouseEvent)
73005152 1583 */
df0b8ff4
BH
1584 @Override
1585 protected void contentsMouseMoveEvent(MouseEvent e) {
eb63f5ff
BH
1586 fScrollToolTip.hideToolTip();
1587 fToolTip.hideToolTip();
df0b8ff4
BH
1588 // super.contentsMouseMoveEvent(e);
1589 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1590 Control[] child = getParent().getChildren();
1591 for (int i = 0; i < child.length; i++) {
eb63f5ff
BH
1592 if ((child[i].isFocusControl()) && (!(child[i] instanceof ScrollView))) {
1593 getViewControl().setFocus();
1594 break;
df0b8ff4
BH
1595 }
1596 }
1597 }
1598 setFocus(-1);
73005152 1599
eb63f5ff
BH
1600 if (((e.stateMask & SWT.BUTTON_MASK) != 0) && ((fDragAndDrop != null) || fIsDragAndDrop) && (fReorderMode || fCollapseProvider != null)) {
1601 fIsDragAndDrop = false;
1602 if (fCurrentGraphNode instanceof Lifeline) {
1603 fDragAndDrop = (Lifeline) fCurrentGraphNode;
df0b8ff4 1604 }
eb63f5ff 1605 if (fDragAndDrop != null) {
df0b8ff4
BH
1606 int dx = 0;
1607 int dy = 0;
1608 if (e.x > getContentsX() + getVisibleWidth()) {
1609 dx = e.x - (getContentsX() + getVisibleWidth());
1610 } else if (e.x < getContentsX()) {
1611 dx = -getContentsX() + e.x;
1612 }
1613 if (e.y > getContentsY() + getVisibleHeight()) {
1614 dy = e.y - (getContentsY() + getVisibleHeight());
1615 } else if (e.y < getContentsY()) {
1616 dy = -getContentsY() + e.y;
1617 }
eb63f5ff
BH
1618 fDragX = e.x;
1619 fDragY = e.y;
df0b8ff4 1620 if (dx != 0 || dy != 0) {
eb63f5ff
BH
1621 if (fLocalAutoScroll == null) {
1622 if (fLocalAutoScrollTimer == null) {
1623 fLocalAutoScrollTimer = new Timer(true);
df0b8ff4 1624 }
eb63f5ff
BH
1625 fLocalAutoScroll = new AutoScroll(this, dx, dy);
1626 fLocalAutoScrollTimer.schedule(fLocalAutoScroll, 0, 75);
df0b8ff4 1627 } else {
eb63f5ff
BH
1628 fLocalAutoScroll.fDeltaX = dx;
1629 fLocalAutoScroll.fDeltaY = dy;
df0b8ff4 1630 }
eb63f5ff
BH
1631 } else if (fLocalAutoScroll != null) {
1632 fLocalAutoScroll.cancel();
1633 fLocalAutoScroll = null;
df0b8ff4 1634 }
eb63f5ff
BH
1635 fDragX = Math.round(e.x / fZoomValue);
1636 fDragY = Math.round(e.y / fZoomValue);
df0b8ff4 1637 redraw();
eb63f5ff
BH
1638 Lifeline node = fFrame.getCloserLifeline(fDragX);
1639 if ((node != null) && (node != fDragAndDrop)) {
df0b8ff4
BH
1640 int y = 0;
1641 int y1 = 0;
1642 int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
1643 int hMargin = Metrics.LIFELINE_VT_MAGIN / 4;
1644 int x = node.getX();
1645 int width = node.getWidth();
eb63f5ff
BH
1646 if (fFrame.getVisibleAreaY() < node.getY() + node.getHeight() - height - hMargin) {
1647 y = contentsToViewY(Math.round((node.getY() + node.getHeight()) * fZoomValue));
df0b8ff4 1648 } else {
eb63f5ff 1649 y = Math.round(height * fZoomValue);
df0b8ff4 1650 }
73005152 1651
eb63f5ff
BH
1652 if (fFrame.getVisibleAreaY() < contentsToViewY(node.getY() - hMargin)) {
1653 y1 = contentsToViewY(Math.round((node.getY() - hMargin) * fZoomValue));
df0b8ff4 1654 } else {
eb63f5ff 1655 y1 = Math.round(height * fZoomValue);
df0b8ff4
BH
1656 }
1657
eb63f5ff 1658 int rx = Math.round(x * fZoomValue);
df0b8ff4 1659
eb63f5ff
BH
1660 fInsertionCartet.setVisible(true);
1661 if ((fInsertionCartet.getImage() != null) && (!fInsertionCartet.getImage().isDisposed())) {
1662 fInsertionCartet.getImage().dispose();
df0b8ff4 1663 }
eb63f5ff
BH
1664 if (rx <= e.x && Math.round(rx + (width * fZoomValue)) >= e.x) {
1665 if (fCollapseProvider != null) {
1666 ImageData data = fCollapaseCaretImg.getImageData();
1667 data = data.scaledTo(Math.round(fCollapaseCaretImg.getBounds().width * fZoomValue), Math.round(fCollapaseCaretImg.getBounds().height * fZoomValue));
1668 fCurrentCaretImage = new Image(Display.getCurrent(), data);
1669 fInsertionCartet.setImage(fCurrentCaretImage);
1670 fInsertionCartet.setLocation(contentsToViewX(rx + Math.round((width / (float) 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y);
df0b8ff4 1671 }
eb63f5ff 1672 } else if (fReorderMode) {
df0b8ff4 1673 if (rx > e.x) {
eb63f5ff 1674 if (node.getIndex() > 1 && fFrame.getLifeline(node.getIndex() - 2) == fDragAndDrop) {
df0b8ff4
BH
1675 return;
1676 }
eb63f5ff
BH
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 - Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y1);
df0b8ff4 1682 } else {
eb63f5ff 1683 if (node.getIndex() < fFrame.lifeLinesCount() && fFrame.getLifeline(node.getIndex()) == fDragAndDrop) {
df0b8ff4
BH
1684 return;
1685 }
eb63f5ff
BH
1686 ImageData data = fArrowUpCaretImg.getImageData();
1687 data = data.scaledTo(Math.round(fArrowUpCaretImg.getBounds().width * fZoomValue), Math.round(fArrowUpCaretImg.getBounds().height * fZoomValue));
1688 fCurrentCaretImage = new Image(Display.getCurrent(), data);
1689 fInsertionCartet.setImage(fCurrentCaretImage);
1690 fInsertionCartet.setLocation(contentsToViewX(Math.round((x + width + Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2 + 1, y1);
df0b8ff4
BH
1691 }
1692 }
1693 } else {
eb63f5ff 1694 fInsertionCartet.setVisible(false);
73005152
BH
1695 }
1696 }
df0b8ff4
BH
1697 } else {
1698 super.contentsMouseMoveEvent(e);
73005152
BH
1699 }
1700 }
1701
df0b8ff4
BH
1702 /*
1703 * (non-Javadoc)
1704 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseUpEvent(org.eclipse.swt.events.MouseEvent)
1705 */
1706 @Override
1707 protected void contentsMouseUpEvent(MouseEvent event) {
1708 // Just in case the diagram highlight a time compression region
1709 // this region need to be released when clicking everywhere
eb63f5ff
BH
1710 fInsertionCartet.setVisible(false);
1711 if (fDragAndDrop != null) {
1712 if ((fOverView != null) && (!fOverView.isDisposed())) {
1713 fOverView.dispose();
73005152 1714 }
eb63f5ff
BH
1715 fOverView = null;
1716 Lifeline node = fFrame.getCloserLifeline(fDragX);
df0b8ff4 1717 if (node != null) {
eb63f5ff
BH
1718 int rx = Math.round(node.getX() * fZoomValue);
1719 if (rx <= event.x && Math.round(rx + (node.getWidth() * fZoomValue)) >= event.x) {
1720 if ((fCollapseProvider != null) && (fDragAndDrop != node)) {
1721 fCollapseProvider.collapseTwoLifelines((Lifeline) fDragAndDrop, node);
df0b8ff4
BH
1722 }
1723 } else if (rx < event.x) {
eb63f5ff
BH
1724 fFrame.insertLifelineAfter((Lifeline) fDragAndDrop, node);
1725 if (node.getIndex() < fFrame.lifeLinesCount()) {
1726 Lifeline temp[] = { (Lifeline) fDragAndDrop, fFrame.getLifeline(node.getIndex()) };
1727 fReorderList.add(temp);
df0b8ff4 1728 } else {
eb63f5ff
BH
1729 Lifeline temp[] = { (Lifeline) fDragAndDrop, null };
1730 fReorderList.add(temp);
df0b8ff4
BH
1731 }
1732 } else {
eb63f5ff
BH
1733 fFrame.insertLifelineBefore((Lifeline) fDragAndDrop, node);
1734 Lifeline temp[] = { (Lifeline) fDragAndDrop, node };
1735 fReorderList.add(temp);
73005152
BH
1736 }
1737 }
73005152 1738 }
eb63f5ff 1739 fDragAndDrop = null;
df0b8ff4 1740 redraw();
eb63f5ff 1741 if (fFrame == null) {
73005152 1742 return;
73005152 1743 }
eb63f5ff 1744 fFrame.resetTimeCompression();
73005152 1745
df0b8ff4 1746 // reset auto scroll if it's engaged
eb63f5ff
BH
1747 if (fLocalAutoScroll != null) {
1748 fLocalAutoScroll.cancel();
1749 fLocalAutoScroll = null;
73005152 1750 }
df0b8ff4 1751 super.contentsMouseUpEvent(event);
73005152
BH
1752 }
1753
df0b8ff4
BH
1754 /*
1755 * (non-Javadoc)
1756 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsMouseDownEvent(org.eclipse.swt.events.MouseEvent)
1757 */
1758 @Override
1759 protected void contentsMouseDownEvent(MouseEvent event) {
eb63f5ff
BH
1760 if (fCurrentGraphNode != null) {
1761 fCurrentGraphNode.setFocused(false);
73005152 1762 }
73005152 1763
df0b8ff4
BH
1764 // Just in case the diagram highlight a time compression region
1765 // this region need to be released when clicking everywhere
eb63f5ff 1766 if (fFrame == null) {
73005152
BH
1767 return;
1768 }
eb63f5ff
BH
1769
1770 fFrame.resetTimeCompression();
73005152 1771
df0b8ff4 1772 if ((event.stateMask & SWT.CTRL) != 0) {
eb63f5ff 1773 fCtrlSelection = true;
df0b8ff4 1774 } else {
eb63f5ff 1775 fCtrlSelection = false;
df0b8ff4 1776 }
73005152 1777
eb63f5ff
BH
1778 if (((fZoomInMode) || (fZoomOutMode)) && (event.button == 1)) {
1779 int cx = Math.round(event.x / fZoomValue);
1780 int cy = Math.round(event.y / fZoomValue);
1781 if (fZoomInMode) {
1782 if (fZoomValue < 64) {
1783 fZoomValue = fZoomValue * (float) 1.25;
df0b8ff4
BH
1784 }
1785 } else {
eb63f5ff 1786 fZoomValue = fZoomValue / (float) 1.25;
73005152 1787 }
eb63f5ff
BH
1788 int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1789 int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
df0b8ff4 1790 setContentsPos(x, y);
eb63f5ff
BH
1791 if (fTimeBar != null) {
1792 fTimeBar.setZoom(fZoomValue);
73005152 1793 }
df0b8ff4
BH
1794 // redraw also resize the scrollView content
1795 redraw();
1796 } else {// if (event.button ==1)
1797 GraphNode node = null;
eb63f5ff
BH
1798 int x = Math.round(event.x / fZoomValue);
1799 int y = Math.round(event.y / fZoomValue);
1800 node = fFrame.getNodeAt(x, y);
1801
1802 if ((event.button == 1) || ((node != null) && !node.isSelected())) {
1803 if (!fShiftSelection) {
1804 fListStart = node;
1805 }
1806 if (fShiftSelection) {
1807 clearSelection();
1808 addSelection(fFrame.getNodeList(fListStart, node));
1809 } else {
1810 performSelection(node);
1811 }
1812 fCurrentGraphNode = node;
1813 if (node != null) {
1814 node.setFocused(true);
df0b8ff4 1815 }
73005152 1816 }
eb63f5ff 1817 redraw();
73005152 1818 }
eb63f5ff 1819 if (fDragAndDrop == null) {
df0b8ff4
BH
1820 super.contentsMouseDownEvent(event);
1821 }
eb63f5ff 1822 fIsDragAndDrop = (event.button == 1);
73005152 1823
df0b8ff4 1824 }
013a5f1c
AM
1825
1826 /**
1827 * TimerTask for auto scroll feature.
df0b8ff4
BH
1828 */
1829 protected static class AutoScroll extends TimerTask {
1830 /**
1831 * Field delta x.
1832 */
eb63f5ff 1833 public int fDeltaX;
df0b8ff4
BH
1834 /**
1835 * Field delta y.
1836 */
eb63f5ff 1837 public int fDeltaY;
df0b8ff4
BH
1838 /**
1839 * Field sequence diagram reference.
1840 */
eb63f5ff 1841 public SDWidget fSdWidget;
73005152 1842
df0b8ff4
BH
1843 /**
1844 * Constructor for AutoScroll.
013a5f1c 1845 * @param sv sequence diagram widget reference
eb63f5ff
BH
1846 * @param dx delta x
1847 * @param dy delta y
df0b8ff4 1848 */
eb63f5ff
BH
1849 public AutoScroll(SDWidget sv, int dx, int dy) {
1850 fSdWidget = sv;
1851 fDeltaX = dx;
1852 fDeltaY = dy;
df0b8ff4 1853 }
73005152 1854
df0b8ff4
BH
1855 /*
1856 * (non-Javadoc)
1857 * @see java.util.TimerTask#run()
1858 */
1859 @Override
1860 public void run() {
1861 Display.getDefault().asyncExec(new Runnable() {
1862 @Override
1863 public void run() {
013a5f1c 1864 if (fSdWidget.isDisposed()) {
df0b8ff4 1865 return;
013a5f1c 1866 }
eb63f5ff
BH
1867 fSdWidget.fDragX += fDeltaX;
1868 fSdWidget.fDragY += fDeltaY;
1869 fSdWidget.scrollBy(fDeltaX, fDeltaY);
df0b8ff4
BH
1870 }
1871 });
1872 }
73005152
BH
1873 }
1874
df0b8ff4
BH
1875 /*
1876 * (non-Javadoc)
1877 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int)
1878 */
1879 @Override
1880 protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) {
eb63f5ff 1881 if (fFrame == null) {
df0b8ff4
BH
1882 gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
1883 gc.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1884 gc.dispose();
1885 return;
1886 } else {
3145ec83
BH
1887// Frame.setUserPref(SDViewPref.getInstance());
1888 SDViewPref.getInstance();
df0b8ff4
BH
1889 }
1890
1891 Rectangle area = getClientArea();
1892 Image dbuffer = getDrawBuffer();
eb63f5ff 1893 int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
df0b8ff4 1894
73005152 1895 try {
df0b8ff4 1896 gc.drawImage(dbuffer, 0, 0, area.width, area.height, 0, 0, area.width, area.height);
73005152 1897 } catch (Exception e) {
8fd82db5 1898 Activator.getDefault().logError("Error drawin content", e); //$NON-NLS-1$
df0b8ff4
BH
1899 }
1900 dbuffer.dispose();
eb63f5ff
BH
1901 setHScrollBarIncrement(Math.round(SDViewPref.getInstance().getLifelineWidth() / (float) 2 * fZoomValue));
1902 setVScrollBarIncrement(Math.round(Metrics.getMessagesSpacing() * fZoomValue));
1903 if ((fTimeBar != null) && (fFrame.hasTimeInfo())) {
1904 fTimeBar.resizeContents(9, height + getHorizontalBarHeight());
1905 fTimeBar.setContentsPos(getContentsX(), getContentsY());
1906 fTimeBar.redraw();
1907 fTimeBar.update();
73005152 1908 }
df0b8ff4
BH
1909 float xRatio = getContentsWidth() / (float) getVisibleWidth();
1910 float yRatio = getContentsHeight() / (float) getVisibleHeight();
1911 if (yRatio > xRatio) {
1912 setOverviewSize((int) (getVisibleHeight() * 0.75));
1913 } else {
1914 setOverviewSize((int) (getVisibleWidth() * 0.75));
1915 }
1916 }
73005152 1917
df0b8ff4
BH
1918 /*
1919 * (non-Javadoc)
1920 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
1921 */
1922 @Override
1923 public void widgetDefaultSelected(SelectionEvent event) {
73005152
BH
1924 }
1925
df0b8ff4
BH
1926 /*
1927 * (non-Javadoc)
1928 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
1929 */
1930 @Override
1931 public void widgetSelected(SelectionEvent event) {
eb63f5ff
BH
1932 if (event.widget == fZoomIn) {
1933 fZoomValue = fZoomValue * 2;
1934 } else if (event.widget == fZoomOut) {
1935 fZoomValue = fZoomValue / 2;
df0b8ff4
BH
1936 }
1937 redraw();
1938 }
73005152 1939
df0b8ff4
BH
1940 /*
1941 * Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply button
013a5f1c 1942 *
df0b8ff4
BH
1943 * (non-Javadoc)
1944 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
1945 */
1946 @Override
1947 public void propertyChange(PropertyChangeEvent e) {
eb63f5ff
BH
1948 if (fFrame != null && !isDisposed()) {
1949 fFrame.resetTimeCompression();
df0b8ff4
BH
1950 }
1951 if (e.getProperty().equals("PREFOK")) //$NON-NLS-1$
1952 {
1953 // Prepare the overview to be reused for the new
1954 // settings (especially the colors)
013a5f1c 1955 if (fOverView != null) {
eb63f5ff 1956 fOverView.dispose();
013a5f1c 1957 }
eb63f5ff 1958 fOverView = null;
df0b8ff4
BH
1959 redraw();
1960 }
1961 }
73005152 1962
df0b8ff4
BH
1963 /*
1964 * (non-Javadoc)
1965 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
1966 */
1967 @Override
1968 public void widgetDisposed(DisposeEvent e) {
eb63f5ff
BH
1969 if (fOverView != null) {
1970 fOverView.dispose();
df0b8ff4
BH
1971 }
1972 super.removeDisposeListener(this);
eb63f5ff
BH
1973 if ((fCurrentCaretImage != null) && (!fCurrentCaretImage.isDisposed())) {
1974 fCurrentCaretImage.dispose();
df0b8ff4 1975 }
eb63f5ff
BH
1976 if ((fArrowUpCaretImg != null) && (!fArrowUpCaretImg.isDisposed())) {
1977 fArrowUpCaretImg.dispose();
df0b8ff4 1978 }
eb63f5ff
BH
1979 if ((fCollapaseCaretImg != null) && (!fCollapaseCaretImg.isDisposed())) {
1980 fCollapaseCaretImg.dispose();
df0b8ff4
BH
1981 }
1982 SDViewPref.getInstance().removePropertyChangeListener(this);
1983 LoadersManager lm = LoadersManager.getInstance();
eb63f5ff
BH
1984 if (fSite instanceof SDView) {
1985 ((SDView) fSite).resetProviders();
df0b8ff4 1986 if (lm != null) {
eb63f5ff 1987 lm.resetLoader(((SDView) fSite).getViewSite().getId());
df0b8ff4
BH
1988 }
1989 }
1990 }
73005152 1991
df0b8ff4
BH
1992 /*
1993 * (non-Javadoc)
1994 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#drawOverview(org.eclipse.swt.graphics.GC, org.eclipse.swt.graphics.Rectangle)
1995 */
1996 @Override
1997 protected void drawOverview(GC gc, Rectangle r) {
eb63f5ff 1998 float oldzoom = fZoomValue;
df0b8ff4 1999 if (getContentsWidth() > getContentsHeight()) {
eb63f5ff 2000 fZoomValue = (float) r.width / (float) getContentsWidth() * oldzoom;
df0b8ff4 2001 } else {
eb63f5ff 2002 fZoomValue = (float) r.height / (float) getContentsHeight() * oldzoom;
df0b8ff4 2003 }
eb63f5ff
BH
2004 if ((fOverView != null) && ((r.width != fOverView.getBounds().width) || (r.height != fOverView.getBounds().height))) {
2005 fOverView.dispose();
2006 fOverView = null;
df0b8ff4 2007 }
eb63f5ff 2008 if (fOverView == null) {
df0b8ff4
BH
2009 int backX = getContentsX();
2010 int backY = getContentsY();
2011 setContentsPos(0, 0);
eb63f5ff
BH
2012 fOverView = new Image(getDisplay(), r.width, r.height);
2013 GC gcim = new GC(fOverView);
df0b8ff4
BH
2014 NGC context = new NGC(this, gcim);
2015 context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME));
eb63f5ff 2016 fFrame.draw(context);
df0b8ff4
BH
2017 setContentsPos(backX, backY);
2018 gcim.dispose();
2019 context.dispose();
2020 }
eb63f5ff
BH
2021 if ((fOverView != null) && (r.width == fOverView.getBounds().width) && (r.height == fOverView.getBounds().height)) {
2022 gc.drawImage(fOverView, 0, 0, r.width, r.height, 0, 0, r.width, r.height);
df0b8ff4 2023 }
73005152 2024
eb63f5ff 2025 fZoomValue = oldzoom;
df0b8ff4
BH
2026
2027 super.drawOverview(gc, r);
73005152
BH
2028 }
2029
df0b8ff4
BH
2030 /*
2031 * (non-Javadoc)
2032 * @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)
2033 */
2034 @Override
2035 public void deltaSelected(Lifeline lifeline, int startEvent, int nbEvent, IColor color) {
eb63f5ff 2036 fFrame.highlightTimeCompression(lifeline, startEvent, nbEvent, color);
df0b8ff4
BH
2037 ensureVisible(lifeline);
2038 int y1 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent;
2039 int y2 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * (startEvent + nbEvent);
2040 ensureVisible(lifeline.getX(), y1 - (Metrics.getLifelineHeaderFontHeigth() + +2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN), lifeline.getWidth(), y2 - y1 + 3, SWT.CENTER | SWT.VERTICAL, true);
2041 redraw();
73005152 2042 update();
73005152
BH
2043 }
2044
df0b8ff4
BH
2045 /*
2046 * (non-Javadoc)
2047 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleWidth()
2048 */
73005152
BH
2049 @Override
2050 public int getVisibleWidth() {
eb63f5ff
BH
2051 if (fIsPrinting) {
2052 return fPrinter.getClientArea().width;
df0b8ff4 2053 }
73005152
BH
2054 return super.getVisibleWidth();
2055 }
2056
df0b8ff4
BH
2057 /*
2058 * (non-Javadoc)
2059 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getVisibleHeight()
2060 */
73005152
BH
2061 @Override
2062 public int getVisibleHeight() {
eb63f5ff
BH
2063 if (fIsPrinting) {
2064 return fPrinter.getClientArea().height;
df0b8ff4 2065 }
73005152
BH
2066 return super.getVisibleHeight();
2067 }
2068
df0b8ff4
BH
2069 /*
2070 * (non-Javadoc)
2071 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewX(int)
2072 */
73005152 2073 @Override
eb63f5ff
BH
2074 public int contentsToViewX(int x) {
2075 if (fIsPrinting) {
2076 int v = Math.round(fPrinterX * fPrinterZoom);
2077 return x - v;
73005152 2078 }
eb63f5ff 2079 return x - getContentsX();
73005152
BH
2080 }
2081
df0b8ff4
BH
2082 /*
2083 * (non-Javadoc)
2084 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#contentsToViewY(int)
2085 */
73005152 2086 @Override
eb63f5ff
BH
2087 public int contentsToViewY(int y) {
2088 if (fIsPrinting) {
2089 int v = Math.round(fPrinterY * fPrinterZoom);
2090 return y - v;
73005152 2091 }
eb63f5ff 2092 return y - getContentsY();
73005152
BH
2093 }
2094
df0b8ff4
BH
2095 /*
2096 * (non-Javadoc)
2097 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsX()
2098 */
73005152
BH
2099 @Override
2100 public int getContentsX() {
eb63f5ff
BH
2101 if (fIsPrinting) {
2102 return Math.round(fPrinterX * fPrinterZoom);
df0b8ff4 2103 }
73005152
BH
2104 return super.getContentsX();
2105
2106 }
2107
df0b8ff4
BH
2108 /*
2109 * (non-Javadoc)
2110 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.ScrollView#getContentsY()
2111 */
73005152
BH
2112 @Override
2113 public int getContentsY() {
eb63f5ff
BH
2114 if (fIsPrinting) {
2115 return Math.round(fPrinterY * fPrinterZoom);
df0b8ff4 2116 }
73005152
BH
2117 return super.getContentsY();
2118 }
013a5f1c 2119
3145ec83
BH
2120 /**
2121 * Traverse Listener implementation.
2122 */
2123 protected static class LocalTraverseListener implements TraverseListener {
2124
2125 /*
2126 * (non-Javadoc)
2127 * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
2128 */
2129 @Override
2130 public void keyTraversed(TraverseEvent e) {
2131 if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
2132 e.doit = true;
2133 }
2134 }
2135 }
2136
73005152 2137}
This page took 0.14362 seconds and 5 git commands to generate.