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