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