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