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