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