089ebc0e498b50f3610d9bc927e66534705164a4
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / SDWidget.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 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 IContextService service = (IContextService) fSite.getSite().getWorkbenchWindow().getService(IContextService.class);
549 service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$
550 service.activateContext(IContextIds.CONTEXT_ID_WINDOW);
551 }
552
553 /**
554 * Returns the GraphNode overView the mouse if any
555 *
556 * @return the current graph node
557 * */
558 public GraphNode getMouseOverNode() {
559 return fCurrentGraphNode;
560 }
561
562 /**
563 * Sets the zoom in mode.
564 *
565 * @param value
566 * The mode value to set.
567 */
568 public void setZoomInMode(boolean value) {
569 if (value) {
570 setZoomOutMode(false);
571 }
572 fZoomInMode = value;
573 }
574
575 /**
576 * Sets the zoom out mode.
577 *
578 * @param value
579 * The mode value to set.
580 */
581 public void setZoomOutMode(boolean value) {
582 if (value) {
583 setZoomInMode(false);
584 }
585 fZoomOutMode = value;
586 }
587
588 /**
589 * Sets the current zoom value.
590 *
591 * @param zoomValue
592 * The current zoom value
593 * @since 2.0
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 * @since 2.0
674 */
675 public GraphNode getCurrentGraphNode() {
676 return fCurrentGraphNode;
677 }
678
679 /**
680 * Returns the current zoom value.
681 *
682 * @return the current zoom value
683 * @since 2.0
684 */
685 public float getZoomValue() {
686 return fZoomValue;
687 }
688
689 /**
690 * Gets the zoom in mode.
691 *
692 * @return the mode value to set.
693 * @since 2.0
694 */
695 public boolean getZoomInMode() {
696 return fZoomInMode;
697 }
698
699
700 /**
701 * Gets the zoom out mode.
702 *
703 * @return the mode value to set.
704 * @since 2.0
705 */
706 public boolean getZoomOutMode() {
707 return fZoomOutMode;
708 }
709
710 /**
711 * Returns if ctrl selection
712 * @return true if ctrl selection else false
713 * @since 2.0
714 */
715 public boolean isCtrlSelection() {
716 return fCtrlSelection;
717 }
718
719 /**
720 * Returns if shift selection
721 * @return true if shift Selection else false
722 * @since 2.0
723 */
724 public boolean isShiftSelection() {
725 return fCtrlSelection;
726 }
727
728 /**
729 * Gets the overview image.
730 *
731 * @param rect Rectangle to include overview.
732 * @return the overview image
733 */
734 public Image getOverview(Rectangle rect) {
735 float oldzoom = fZoomValue;
736 if ((fOverView != null) && ((rect.width != fOverView.getBounds().width) || (rect.height != fOverView.getBounds().height))) {
737 fOverView.dispose();
738 fOverView = null;
739 }
740 if (fOverView == null) {
741 int backX = getContentsX();
742 int backY = getContentsY();
743 setContentsPos(0, 0);
744 fOverView = new Image(getDisplay(), rect.width, rect.height);
745 GC gcim = new GC(fOverView);
746 NGC context = new NGC(this, gcim);
747 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
748 fFrame.draw(context);
749 setContentsPos(backX, backY);
750 gcim.dispose();
751 context.dispose();
752 }
753 fZoomValue = oldzoom;
754 return fOverView;
755 }
756
757 /**
758 * Resets the zoom factor.
759 */
760 public void resetZoomFactor() {
761 int currentX = Math.round(getContentsX() / fZoomValue);
762 int currentY = Math.round(getContentsY() / fZoomValue);
763 fZoomValue = 1;
764 if (fTimeBar != null && !fTimeBar.isDisposed()) {
765 fTimeBar.setZoom(fZoomValue);
766 }
767 redraw();
768 update();
769 setContentsPos(currentX, currentY);
770 }
771
772 /**
773 * Enable or disable the lifeline reodering using Drag and Drop
774 *
775 * @param mode - true to enable false otherwise
776 */
777 public void setReorderMode(boolean mode) {
778 fReorderMode = mode;
779 }
780
781 /**
782 * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList
783 * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram
784 *
785 * @return - the re-odered sequence
786 */
787 public List<Lifeline[]> getLifelineReoderList() {
788 return fReorderList;
789 }
790
791 /**
792 * Sets the focus on given graph node (current node).
793 *
794 * @param node
795 * The graph node to focus on.
796 */
797 public void setFocus(GraphNode node) {
798 if (node == null) {
799 return;
800 }
801 if (fCurrentGraphNode != null) {
802 fCurrentGraphNode.setFocused(false);
803 }
804 fCurrentGraphNode = node;
805 node.setFocused(true);
806 ensureVisible(node);
807 setFocus(0);
808 }
809
810 /**
811 * Returns the graph node focused on.
812 *
813 * @return the current graph node
814 */
815 public GraphNode getFocusNode() {
816 return fCurrentGraphNode;
817 }
818
819 /**
820 * Method to traverse right.
821 */
822 public void traverseRight() {
823 Object selectedNode = getFocusNode();
824 if (selectedNode == null) {
825 traverseLeft();
826 }
827 GraphNode node = null;
828 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
829 node = fFrame.getCalledMessage((BaseMessage) selectedNode);
830 }
831 if (selectedNode instanceof BasicExecutionOccurrence) {
832 selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
833 }
834 if ((node == null) && (selectedNode instanceof Lifeline)) {
835 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
836 if ((selectedNode == fFrame.getLifeline(i)) && (i < fFrame.lifeLinesCount() - 1)) {
837 node = fFrame.getLifeline(i + 1);
838 break;
839 }
840 }
841 }
842 if (node != null) {
843 setFocus(node);
844 redraw();
845 }
846 }
847
848 /**
849 * Method to traverse left.
850 */
851 public void traverseLeft() {
852 Object selectedNode = getFocusNode();
853 GraphNode node = null;
854 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
855 node = fFrame.getCallerMessage((BaseMessage) selectedNode);
856 }
857 if (selectedNode instanceof BasicExecutionOccurrence) {
858 selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline();
859 }
860 if (node == null) {
861 if ((selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getEndLifeline() != null)) {
862 selectedNode = ((BaseMessage) selectedNode).getEndLifeline();
863 }
864 for (int i = 0; i < fFrame.lifeLinesCount(); i++) {
865 if ((selectedNode == fFrame.getLifeline(i)) && (i > 0)) {
866 node = fFrame.getLifeline(i - 1);
867 break;
868 }
869 }
870 if ((fFrame.lifeLinesCount() > 0) && (node == null)) {
871 node = fFrame.getLifeline(0);
872 }
873 }
874 if (node != null) {
875 setFocus(node);
876 redraw();
877 }
878 }
879
880 /**
881 * Method to traverse up.
882 */
883 public void traverseUp() {
884 Object selectedNode = getFocusNode();
885 if (selectedNode == null) {
886 traverseLeft();
887 }
888 GraphNode node = null;
889 if (selectedNode instanceof BaseMessage) {
890 node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
891 } else if (selectedNode instanceof Lifeline) {
892 node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
893 if (!(node instanceof Lifeline)) {
894 node = null;
895 }
896 } else if (selectedNode instanceof BasicExecutionOccurrence) {
897 node = fFrame.getPrevExecOccurrence((BasicExecutionOccurrence) selectedNode);
898 if (node == null) {
899 node = ((BasicExecutionOccurrence) selectedNode).getLifeline();
900 }
901 }
902 if ((node == null) && (selectedNode instanceof BaseMessage) && (((BaseMessage) selectedNode).getStartLifeline() != null)) {
903 node = ((BaseMessage) selectedNode).getStartLifeline();
904 }
905
906 if (node != null) {
907 setFocus(node);
908 redraw();
909 }
910 }
911
912 /**
913 * Method to traverse down.
914 */
915 public void traverseDown() {
916 Object selectedNode = getFocusNode();
917 if (selectedNode == null) {
918 traverseLeft();
919 }
920 GraphNode node;
921 if (selectedNode instanceof BaseMessage) {
922 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode);
923 } else if (selectedNode instanceof Lifeline) {
924 node = fFrame.getFirstExecution((Lifeline) selectedNode);
925 } else if (selectedNode instanceof BasicExecutionOccurrence) {
926 node = fFrame.getNextExecOccurrence((BasicExecutionOccurrence) selectedNode);
927 } else {
928 return;
929 }
930
931 if (node != null) {
932 setFocus(node);
933 redraw();
934 }
935 }
936
937 /**
938 * Method to traverse home.
939 */
940 public void traverseHome() {
941 Object selectedNode = getFocusNode();
942 if (selectedNode == null) {
943 traverseLeft();
944 }
945 GraphNode node = null;
946
947 if (selectedNode instanceof BaseMessage) {
948 if (((BaseMessage) selectedNode).getStartLifeline() != null) {
949 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
950 } else {
951 node = fFrame.getNextLifelineMessage(((BaseMessage) selectedNode).getEndLifeline(), null);
952 }
953 } else if (selectedNode instanceof Lifeline) {
954 node = fFrame.getNextLifelineMessage((Lifeline) selectedNode, null);
955 } else if (selectedNode instanceof BasicExecutionOccurrence) {
956 node = fFrame.getFirstExecution(((BasicExecutionOccurrence) selectedNode).getLifeline());
957 } else {
958 if (fFrame.lifeLinesCount() > 0) {
959 Lifeline lifeline = fFrame.getLifeline(0);
960 node = fFrame.getNextLifelineMessage(lifeline, null);
961 }
962 }
963
964 if (node != null) {
965 setFocus(node);
966 redraw();
967 }
968 }
969
970 /**
971 * Method to traverse to the end.
972 */
973 public void traverseEnd() {
974 Object selectedNode = getFocusNode();
975 if (selectedNode == null) {
976 traverseLeft();
977 }
978 GraphNode node;
979 if (selectedNode instanceof BaseMessage) {
980 node = fFrame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null);
981 } else if (selectedNode instanceof Lifeline) {
982 node = fFrame.getPrevLifelineMessage((Lifeline) selectedNode, null);
983 } else if (selectedNode instanceof BasicExecutionOccurrence) {
984 node = fFrame.getLastExecOccurrence(((BasicExecutionOccurrence) selectedNode).getLifeline());
985 } else {
986 if (fFrame.lifeLinesCount() > 0) {
987 Lifeline lifeline = fFrame.getLifeline(0);
988 node = fFrame.getPrevLifelineMessage(lifeline, null);
989 } else {
990 return;
991 }
992 }
993
994 if (node != null) {
995 setFocus(node);
996 redraw();
997 }
998 }
999
1000 /**
1001 * Method to print UI.
1002 *
1003 * @param sdPrintDialog the sequence diagram printer dialog.
1004 */
1005 public void printUI(SDPrintDialogUI sdPrintDialog) {
1006 PrinterData data = sdPrintDialog.getPrinterData();
1007
1008 if ((data == null) || (fFrame == null)) {
1009 return;
1010 }
1011
1012 fPrinter = new Printer(data);
1013
1014 String jobName = MessageFormat.format(Messages.SequenceDiagram_plus, new Object[] { String.valueOf(fSite.getContentDescription()), String.valueOf(fFrame.getName()) });
1015 fPrinter.startJob(jobName);
1016
1017 GC gc = new GC(fPrinter);
1018
1019 float lastZoom = fZoomValue;
1020
1021 Rectangle area = getClientArea();
1022 GC gcim = null;
1023
1024 gcim = gc;
1025 NGC context = new NGC(this, gcim);
1026
1027 // Set the metrics to use for lifeline text and message text
1028 // using the Graphical Context
1029 Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE)));
1030 Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE)));
1031 Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
1032 Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
1033 Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
1034
1035 int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_SYNC_MESS));
1036 int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_SYNC_MESS_RET));
1037 int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_ASYNC_MESS));
1038 int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_ASYNC_MESS_RET));
1039
1040 int messageFontHeight = 0;
1041 if (syncMessFontH > syncMessRetFontH) {
1042 messageFontHeight = syncMessFontH;
1043 } else {
1044 messageFontHeight = syncMessRetFontH;
1045 }
1046 if (messageFontHeight < asyncMessFontH) {
1047 messageFontHeight = asyncMessFontH;
1048 }
1049 if (messageFontHeight < asyncMessRetFontH) {
1050 messageFontHeight = asyncMessRetFontH;
1051 }
1052 Metrics.setMessageFontHeight(messageFontHeight);
1053 context.setFont(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE));
1054
1055 int width = Math.round((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1056 int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1057 if (width < area.width) {
1058 width = area.width;
1059 }
1060 if (height < area.height) {
1061 height = area.height;
1062 }
1063 resizeContents(width, height);
1064
1065 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
1066 context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
1067 context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1068 context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1069 context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
1070 gcim.setLineWidth(1);
1071
1072 fPrinter.startPage();
1073 fZoomValue = lastZoom;
1074
1075 int restoreX = getContentsX();
1076 int restoreY = getContentsY();
1077
1078 float zh = sdPrintDialog.getStepY() * sdPrintDialog.getZoomFactor();
1079 float zw = sdPrintDialog.getStepX() * sdPrintDialog.getZoomFactor();
1080
1081 float zoomValueH = fPrinter.getClientArea().height / zh;
1082 float zoomValueW = fPrinter.getClientArea().width / zw;
1083 if (zoomValueH > zoomValueW) {
1084 fPrinterZoom = zoomValueH;
1085 } else {
1086 fPrinterZoom = zoomValueW;
1087 }
1088
1089 if (sdPrintDialog.printSelection()) {
1090 int[] pagesList = sdPrintDialog.getPageList();
1091
1092 for (int pageIndex = 0; pageIndex < pagesList.length; pageIndex++) {
1093 printPage(pagesList[pageIndex], sdPrintDialog, context);
1094 }
1095 } else if (sdPrintDialog.printAll()) {
1096 for (int pageIndex = 1; pageIndex <= sdPrintDialog.maxNumOfPages(); pageIndex++) {
1097 printPage(pageIndex, sdPrintDialog, context);
1098 }
1099 } else if (sdPrintDialog.printCurrent()) {
1100 printPage(getContentsX(), getContentsY(), sdPrintDialog, context, 1);
1101 } else if (sdPrintDialog.printRange()) {
1102 for (int pageIndex = sdPrintDialog.getFrom(); pageIndex <= sdPrintDialog.maxNumOfPages() && pageIndex <= sdPrintDialog.getTo(); pageIndex++) {
1103 printPage(pageIndex, sdPrintDialog, context);
1104 }
1105 }
1106
1107 fPrinter.endJob();
1108 fIsPrinting = false;
1109
1110 gc.dispose();
1111 context.dispose();
1112
1113 fZoomValue = lastZoom;
1114 fPrinter.dispose();
1115 setContentsPos(restoreX, restoreY);
1116 }
1117
1118 /**
1119 * Method to print.
1120 */
1121 public void print() {
1122 SDPrintDialog sdPrinter = new SDPrintDialog(this.getShell(), this);
1123 try {
1124 if (sdPrinter.open() != 0) {
1125 return;
1126 }
1127 } catch (Exception e) {
1128 Activator.getDefault().logError("Error creating image", e); //$NON-NLS-1$
1129 return;
1130 }
1131 printUI(sdPrinter.getDialogUI());
1132 }
1133
1134 /**
1135 * Method to print a page.
1136 *
1137 * @param pageNum The page number
1138 * @param pd The sequence diagram print dialog
1139 * @param context The graphical context
1140 */
1141 public void printPage(int pageNum, SDPrintDialogUI pd, NGC context) {
1142 int j = pageNum / pd.getNbRow();
1143 int i = pageNum % pd.getNbRow();
1144 if (i != 0) {
1145 j++;
1146 } else {
1147 i = pd.getNbRow();
1148 }
1149
1150 i--;
1151 j--;
1152
1153 i = (int) (i * pd.getStepX());
1154 j = (int) (j * pd.getStepY());
1155
1156 printPage(i, j, pd, context, pageNum);
1157
1158 fPrinter.endPage();
1159 }
1160
1161 /**
1162 * Method to print page ranges.
1163 *
1164 * @param i
1165 * The start page
1166 * @param j
1167 * The end page
1168 * @param pd
1169 * The sequence diagram print dialog
1170 * @param context
1171 * The graphical context
1172 * @param pageNum
1173 * The current page
1174 */
1175 public void printPage(int i, int j, SDPrintDialogUI pd, NGC context, int pageNum) {
1176 fIsPrinting = false;
1177 int pageNumFontZoom = fPrinter.getClientArea().height / getVisibleHeight();
1178 fPrinterX = i;
1179 fPrinterY = j;
1180 setContentsPos(i, j);
1181 update();
1182 fIsPrinting = true;
1183 float lastZoom = fZoomValue;
1184 fZoomValue = fPrinterZoom * lastZoom;
1185
1186 fFrame.draw(context);
1187
1188 fZoomValue = pageNumFontZoom;
1189 context.setFont(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE));
1190 String currentPageNum = String.valueOf(pageNum);
1191 int ii = context.textExtent(currentPageNum);
1192 int jj = context.getCurrentFontHeight();
1193 fZoomValue = fPrinterZoom * lastZoom;
1194 context.drawText(currentPageNum, Math.round(fPrinterX + getVisibleWidth() / fPrinterZoom - ii / fPrinterZoom), Math.round(fPrinterY + getVisibleHeight() / fPrinterZoom - jj / fPrinterZoom), false);
1195 fIsPrinting = false;
1196 fZoomValue = lastZoom;
1197 }
1198
1199 /**
1200 * Sets the collapse provider.
1201 *
1202 * @param provider The collapse provider to set
1203 */
1204 protected void setCollapseProvider(ISDCollapseProvider provider) {
1205 fCollapseProvider = provider;
1206 }
1207
1208
1209 /**
1210 * Checks for focus of children.
1211 *
1212 * @param children Control to check
1213 * @return true if child is on focus else false
1214 */
1215 protected boolean checkFocusOnChilds(Control children) {
1216 if (children instanceof Composite) {
1217 Control[] child = ((Composite) children).getChildren();
1218 for (int i = 0; i < child.length; i++) {
1219 if (child[i].isFocusControl()) {
1220 return true;
1221 }
1222 checkFocusOnChilds(child[i]);
1223 }
1224 }
1225 return false;
1226 }
1227
1228 /**
1229 * A post action for a tooltip (before displaying).
1230 *
1231 * @param accessible true if accessible else false
1232 * @return the tooltip text.
1233 */
1234 protected String getPostfixForTooltip(boolean accessible) {
1235 StringBuffer postfix = new StringBuffer();
1236 // Determine if the tooltip must show the time difference between the current mouse position and
1237 // the last selected graphNode
1238 if ((fCurrentGraphNode != null) &&
1239 (fCurrentGraphNode instanceof ITimeRange) &&
1240 (fToolTipNode instanceof ITimeRange) &&
1241 (fCurrentGraphNode != fToolTipNode) &&
1242 ((ITimeRange) fToolTipNode).hasTimeInfo() &&
1243 ((ITimeRange) fCurrentGraphNode).hasTimeInfo()) {
1244 postfix.append(" -> "); //$NON-NLS-1$
1245 postfix.append(fCurrentGraphNode.getName());
1246 postfix.append("\n"); //$NON-NLS-1$
1247 postfix.append(Messages.SequenceDiagram_Delta);
1248 postfix.append(" "); //$NON-NLS-1$
1249
1250 //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime();
1251 ITmfTimestamp firstTime = ((ITimeRange) fCurrentGraphNode).getEndTime();
1252 ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
1253 ITmfTimestamp delta = lastTime.getDelta(firstTime);
1254 postfix.append(delta.toString());
1255
1256 } else {
1257 if ((fToolTipNode instanceof ITimeRange) && ((ITimeRange) fToolTipNode).hasTimeInfo()) {
1258 postfix.append("\n"); //$NON-NLS-1$
1259 ITmfTimestamp firstTime = ((ITimeRange) fToolTipNode).getStartTime();
1260 ITmfTimestamp lastTime = ((ITimeRange) fToolTipNode).getEndTime();
1261
1262 if (firstTime != null) {
1263 if (lastTime != null && firstTime.compareTo(lastTime, true) != 0) {
1264 postfix.append("start: "); //$NON-NLS-1$
1265 postfix.append(firstTime.toString());
1266 postfix.append("\n"); //$NON-NLS-1$
1267 postfix.append("end: "); //$NON-NLS-1$
1268 postfix.append(lastTime.toString());
1269 postfix.append("\n"); //$NON-NLS-1$
1270 } else {
1271 postfix.append(firstTime.toString());
1272 }
1273 }
1274 else if (lastTime != null) {
1275 postfix.append(lastTime.toString());
1276 }
1277 }
1278 }
1279 return postfix.toString();
1280 }
1281
1282 /**
1283 * Sets a new focused widget.
1284 *
1285 * @param newFocusShape A new focus shape.
1286 */
1287 protected void setFocus(int newFocusShape) {
1288 fFocusedWidget = newFocusShape;
1289 if (fFocusedWidget == -1) {
1290 getViewControl().getAccessible().setFocus(ACC.CHILDID_SELF);
1291 } else {
1292 getViewControl().getAccessible().setFocus(fFocusedWidget);
1293 }
1294 }
1295
1296 /**
1297 * Highlight the given GraphNode<br>
1298 * The GraphNode is then displayed using the system default selection color
1299 *
1300 * @param node the GraphNode to highlight
1301 */
1302 protected void performSelection(GraphNode node) {
1303 if ((fCtrlSelection) || (fShiftSelection)) {
1304 if (node != null) {
1305 if (fSelectedNodeList.contains(node)) {
1306 removeSelection(node);
1307 } else {
1308 addSelection(node);
1309 }
1310 } else {
1311 return;
1312 }
1313 } else {
1314 clearSelection();
1315 if (node != null) {
1316 addSelection(node);
1317 }
1318 }
1319 }
1320
1321 /**
1322 * Returns a draw buffer image.
1323 *
1324 * @return a Image containing the draw buffer.
1325 */
1326 protected Image getDrawBuffer() {
1327
1328 update();
1329 Rectangle area = getClientArea();
1330 Image dbuffer = new Image(getDisplay(), area.width, area.height);
1331 GC gcim = new GC(dbuffer);
1332 NGC context = new NGC(this, gcim);
1333
1334 // Set the metrics to use for lifeline text and message text
1335 // using the Graphical Context
1336 Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE)));
1337 Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE)));
1338 Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth());
1339 Metrics.setFrameFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_FRAME_NAME)));
1340 Metrics.setLifelineHeaderFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE_HEADER)));
1341
1342 int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_SYNC_MESS));
1343 int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_SYNC_MESS_RET));
1344 int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_ASYNC_MESS));
1345 int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(ISDPreferences.PREF_ASYNC_MESS_RET));
1346
1347 int messageFontHeight = 0;
1348 if (syncMessFontH > syncMessRetFontH) {
1349 messageFontHeight = syncMessFontH;
1350 } else {
1351 messageFontHeight = syncMessRetFontH;
1352 }
1353 if (messageFontHeight < asyncMessFontH) {
1354 messageFontHeight = asyncMessFontH;
1355 }
1356 if (messageFontHeight < asyncMessRetFontH) {
1357 messageFontHeight = asyncMessRetFontH;
1358 }
1359 Metrics.setMessageFontHeight(messageFontHeight);
1360 context.setFont(SDViewPref.getInstance().getFont(ISDPreferences.PREF_LIFELINE));
1361
1362 int width = (int) ((fFrame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * fZoomValue);
1363 int height = (int) ((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1364
1365 resizeContents(width, height);
1366
1367 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
1368 context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN);
1369 context.fillRectangle(0, 0, fFrame.getX(), getContentsHeight());
1370 context.fillRectangle(fFrame.getX() + fFrame.getWidth() + 1, 0, getContentsWidth() - (fFrame.getX() + fFrame.getWidth() + 1), getContentsHeight());
1371 context.fillRectangle(0, fFrame.getY() + fFrame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (fFrame.getY() + fFrame.getHeight() + 1));
1372 gcim.setLineWidth(1);
1373
1374 fFrame.draw(context);
1375 if (fDragAndDrop != null) {
1376 Lifeline node = fDragAndDrop;
1377 boolean isSelected = fDragAndDrop.isSelected();
1378 boolean hasFocus = fDragAndDrop.hasFocus();
1379 node.setSelected(false);
1380 node.setFocused(false);
1381 node.draw(context, fDragX, fDragY);
1382 node.setSelected(isSelected);
1383 node.setFocused(hasFocus);
1384 }
1385 gcim.dispose();
1386 context.dispose();
1387 return dbuffer;
1388 }
1389
1390 @Override
1391 protected void keyPressedEvent(KeyEvent event) {
1392 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1393 Control[] child = getParent().getChildren();
1394 for (int i = 0; i < child.length; i++) {
1395 if ((child[i].isFocusControl())&& (!(child[i] instanceof ScrollView))) {
1396 getViewControl().setFocus();
1397 break;
1398 }
1399 }
1400 }
1401 setFocus(-1);
1402
1403 if (event.keyCode == SWT.CTRL) {
1404 fCtrlSelection = true;
1405 }
1406 if (event.keyCode == SWT.SHIFT) {
1407 fShiftSelection = true;
1408 fPrevList = new ArrayList<>();
1409 fPrevList.addAll(getSelection());
1410 }
1411
1412 GraphNode prevNode = getFocusNode();
1413
1414 if (event.keyCode == SWT.ARROW_RIGHT) {
1415 traverseRight();
1416 }
1417
1418 if (event.keyCode == SWT.ARROW_LEFT) {
1419 traverseLeft();
1420 }
1421
1422 if (event.keyCode == SWT.ARROW_DOWN) {
1423 traverseDown();
1424 }
1425
1426 if (event.keyCode == SWT.ARROW_UP) {
1427 traverseUp();
1428 }
1429
1430 if (event.keyCode == SWT.HOME) {
1431 traverseHome();
1432 }
1433
1434 if (event.keyCode == SWT.END) {
1435 traverseEnd();
1436 }
1437
1438 if ((!fShiftSelection) && (!fCtrlSelection)) {
1439 fListStart = fCurrentGraphNode;
1440 }
1441
1442 if (event.character == ' ') {
1443 performSelection(fCurrentGraphNode);
1444 if (!fShiftSelection) {
1445 fListStart = fCurrentGraphNode;
1446 }
1447 }
1448
1449 if ((fShiftSelection) && (prevNode != getFocusNode())) {
1450 clearSelection();
1451 addSelection(fPrevList);
1452 addSelection(fFrame.getNodeList(fListStart, getFocusNode()));
1453 if (getFocusNode() instanceof Lifeline) {
1454 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
1455 } else {
1456 ensureVisible(getFocusNode());
1457 }
1458 } else if ((!fCtrlSelection) && (!fShiftSelection)) {
1459
1460 clearSelection();
1461 if (getFocusNode() != null) {
1462 addSelection(getFocusNode());
1463
1464 if (getFocusNode() instanceof Lifeline) {
1465 ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true);
1466 } else {
1467 ensureVisible(getFocusNode());
1468 }
1469 }
1470 }
1471
1472 if (fCurrentGraphNode != null) {
1473 fCurrentGraphNode.setFocused(true);
1474 }
1475 redraw();
1476
1477 if ((event.character == ' ') && ((fZoomInMode) || (fZoomOutMode))) {
1478 int cx = Math.round((getContentsX() + getVisibleWidth() / 2) / fZoomValue);
1479 int cy = Math.round((getContentsY() + getVisibleHeight() / 2) / fZoomValue);
1480 if (fZoomInMode) {
1481 if (fZoomValue < 64) {
1482 fZoomValue = fZoomValue * (float) 1.25;
1483 }
1484 } else {
1485 fZoomValue = fZoomValue / (float) 1.25;
1486 }
1487 int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1488 int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
1489 setContentsPos(x, y);
1490 if (fTimeBar != null) {
1491 fTimeBar.setZoom(fZoomValue);
1492 }
1493 // redraw also resize the scrollView content
1494 redraw();
1495 }
1496 }
1497
1498 @Override
1499 protected void keyReleasedEvent(KeyEvent event) {
1500 setFocus(-1);
1501 if (event.keyCode == SWT.CTRL) {
1502 fCtrlSelection = false;
1503 }
1504 if (event.keyCode == SWT.SHIFT) {
1505 fShiftSelection = false;
1506 }
1507 super.keyReleasedEvent(event);
1508 setFocus(1);
1509 }
1510
1511 @Override
1512 public boolean isFocusControl() {
1513 Control[] child = getChildren();
1514 for (int i = 0; i < child.length; i++) {
1515 if (child[i].isFocusControl()) {
1516 return true;
1517 }
1518 checkFocusOnChilds(child[i]);
1519 }
1520 return false;
1521 }
1522
1523 @Override
1524 public boolean setContentsPos(int x, int y) {
1525 int localX = x;
1526 int localY = y;
1527
1528 if (localX < 0) {
1529 localX = 0;
1530 }
1531 if (localY < 0) {
1532 localY = 0;
1533 }
1534 if (fFrame == null) {
1535 return false;
1536 }
1537 if (localX + getVisibleWidth() > getContentsWidth()) {
1538 localX = getContentsWidth() - getVisibleWidth();
1539 }
1540 if (localY + getVisibleHeight() > getContentsHeight()) {
1541 localY = getContentsHeight() - getVisibleHeight();
1542 }
1543 int x1 = Math.round(localX / fZoomValue);
1544 int y2 = Math.round(localY / fZoomValue);
1545 int width = Math.round(getVisibleWidth() / fZoomValue);
1546 int height = Math.round(getVisibleHeight() / fZoomValue);
1547 fFrame.updateIndex(x1, y2, width, height);
1548
1549 if (fInsertionCartet != null && fInsertionCartet.isVisible()) {
1550 fInsertionCartet.setVisible(false);
1551 }
1552
1553 return super.setContentsPos(localX, localY);
1554 }
1555
1556 @Override
1557 protected void contentsMouseHover(MouseEvent event) {
1558 GraphNode graphNode = null;
1559 if (fFrame != null) {
1560 int x = Math.round(event.x / fZoomValue);
1561 int y = Math.round(event.y / fZoomValue);
1562 graphNode = fFrame.getNodeAt(x, y);
1563 if ((graphNode != null) && (SDViewPref.getInstance().tooltipEnabled())) {
1564 fToolTipNode = graphNode;
1565 String postfix = getPostfixForTooltip(true);
1566 if (graphNode instanceof Lifeline) {
1567 Lifeline lifeline = (Lifeline) graphNode;
1568 fToolTip.showToolTip(lifeline.getToolTipText() + postfix);
1569 setFocus(0);
1570 } else {
1571 fToolTip.showToolTip(graphNode.getName() + postfix);
1572 setFocus(0);
1573 }
1574 } else {
1575 fToolTip.hideToolTip();
1576 }
1577 }
1578 }
1579
1580 @Override
1581 protected void contentsMouseMoveEvent(MouseEvent e) {
1582 fScrollToolTip.hideToolTip();
1583 fToolTip.hideToolTip();
1584 if (!(isFocusControl() || getViewControl().isFocusControl())) {
1585 Control[] child = getParent().getChildren();
1586 for (int i = 0; i < child.length; i++) {
1587 if ((child[i].isFocusControl()) && (!(child[i] instanceof ScrollView))) {
1588 getViewControl().setFocus();
1589 break;
1590 }
1591 }
1592 }
1593 setFocus(-1);
1594
1595 if (((e.stateMask & SWT.BUTTON_MASK) != 0) && ((fDragAndDrop != null) || fIsDragAndDrop) && (fReorderMode || fCollapseProvider != null)) {
1596 fIsDragAndDrop = false;
1597 if (fCurrentGraphNode instanceof Lifeline) {
1598 fDragAndDrop = (Lifeline) fCurrentGraphNode;
1599 }
1600 if (fDragAndDrop != null) {
1601 int dx = 0;
1602 int dy = 0;
1603 if (e.x > getContentsX() + getVisibleWidth()) {
1604 dx = e.x - (getContentsX() + getVisibleWidth());
1605 } else if (e.x < getContentsX()) {
1606 dx = -getContentsX() + e.x;
1607 }
1608 if (e.y > getContentsY() + getVisibleHeight()) {
1609 dy = e.y - (getContentsY() + getVisibleHeight());
1610 } else if (e.y < getContentsY()) {
1611 dy = -getContentsY() + e.y;
1612 }
1613 fDragX = e.x;
1614 fDragY = e.y;
1615 if (dx != 0 || dy != 0) {
1616 if (fLocalAutoScroll == null) {
1617 if (fLocalAutoScrollTimer == null) {
1618 fLocalAutoScrollTimer = new Timer(true);
1619 }
1620 fLocalAutoScroll = new AutoScroll(this, dx, dy);
1621 fLocalAutoScrollTimer.schedule(fLocalAutoScroll, 0, 75);
1622 } else {
1623 fLocalAutoScroll.fDeltaX = dx;
1624 fLocalAutoScroll.fDeltaY = dy;
1625 }
1626 } else if (fLocalAutoScroll != null) {
1627 fLocalAutoScroll.cancel();
1628 fLocalAutoScroll = null;
1629 }
1630 fDragX = Math.round(e.x / fZoomValue);
1631 fDragY = Math.round(e.y / fZoomValue);
1632 redraw();
1633 Lifeline node = fFrame.getCloserLifeline(fDragX);
1634 if ((node != null) && (node != fDragAndDrop)) {
1635 int y = 0;
1636 int y1 = 0;
1637 int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN;
1638 int hMargin = Metrics.LIFELINE_VT_MAGIN / 4;
1639 int x = node.getX();
1640 int width = node.getWidth();
1641 if (fFrame.getVisibleAreaY() < node.getY() + node.getHeight() - height - hMargin) {
1642 y = contentsToViewY(Math.round((node.getY() + node.getHeight()) * fZoomValue));
1643 } else {
1644 y = Math.round(height * fZoomValue);
1645 }
1646
1647 if (fFrame.getVisibleAreaY() < contentsToViewY(node.getY() - hMargin)) {
1648 y1 = contentsToViewY(Math.round((node.getY() - hMargin) * fZoomValue));
1649 } else {
1650 y1 = Math.round(height * fZoomValue);
1651 }
1652
1653 int rx = Math.round(x * fZoomValue);
1654
1655 fInsertionCartet.setVisible(true);
1656 if ((fInsertionCartet.getImage() != null) && (!fInsertionCartet.getImage().isDisposed())) {
1657 fInsertionCartet.getImage().dispose();
1658 }
1659 if (rx <= e.x && Math.round(rx + (width * fZoomValue)) >= e.x) {
1660 if (fCollapseProvider != null) {
1661 ImageData data = fCollapaseCaretImg.getImageData();
1662 data = data.scaledTo(Math.round(fCollapaseCaretImg.getBounds().width * fZoomValue), Math.round(fCollapaseCaretImg.getBounds().height * fZoomValue));
1663 fCurrentCaretImage = new Image(Display.getCurrent(), data);
1664 fInsertionCartet.setImage(fCurrentCaretImage);
1665 fInsertionCartet.setLocation(contentsToViewX(rx + Math.round((width / (float) 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y);
1666 }
1667 } else if (fReorderMode) {
1668 if (rx > e.x) {
1669 if (node.getIndex() > 1 && fFrame.getLifeline(node.getIndex() - 2) == fDragAndDrop) {
1670 return;
1671 }
1672 ImageData data = fArrowUpCaretImg.getImageData();
1673 data = data.scaledTo(Math.round(fArrowUpCaretImg.getBounds().width * fZoomValue), Math.round(fArrowUpCaretImg.getBounds().height * fZoomValue));
1674 fCurrentCaretImage = new Image(Display.getCurrent(), data);
1675 fInsertionCartet.setImage(fCurrentCaretImage);
1676 fInsertionCartet.setLocation(contentsToViewX(Math.round((x - Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2, y1);
1677 } else {
1678 if (node.getIndex() < fFrame.lifeLinesCount() && fFrame.getLifeline(node.getIndex()) == fDragAndDrop) {
1679 return;
1680 }
1681 ImageData data = fArrowUpCaretImg.getImageData();
1682 data = data.scaledTo(Math.round(fArrowUpCaretImg.getBounds().width * fZoomValue), Math.round(fArrowUpCaretImg.getBounds().height * fZoomValue));
1683 fCurrentCaretImage = new Image(Display.getCurrent(), data);
1684 fInsertionCartet.setImage(fCurrentCaretImage);
1685 fInsertionCartet.setLocation(contentsToViewX(Math.round((x + width + Metrics.LIFELINE_SPACING / 2) * fZoomValue)) - fCurrentCaretImage.getBounds().width / 2 + 1, y1);
1686 }
1687 }
1688 } else {
1689 fInsertionCartet.setVisible(false);
1690 }
1691 }
1692 } else {
1693 super.contentsMouseMoveEvent(e);
1694 }
1695 }
1696
1697 @Override
1698 protected void contentsMouseUpEvent(MouseEvent event) {
1699 // Just in case the diagram highlight a time compression region
1700 // this region need to be released when clicking everywhere
1701 fInsertionCartet.setVisible(false);
1702 if (fDragAndDrop != null) {
1703 if ((fOverView != null) && (!fOverView.isDisposed())) {
1704 fOverView.dispose();
1705 }
1706 fOverView = null;
1707 Lifeline node = fFrame.getCloserLifeline(fDragX);
1708 if (node != null) {
1709 int rx = Math.round(node.getX() * fZoomValue);
1710 if (rx <= event.x && Math.round(rx + (node.getWidth() * fZoomValue)) >= event.x) {
1711 if ((fCollapseProvider != null) && (fDragAndDrop != node)) {
1712 fCollapseProvider.collapseTwoLifelines(fDragAndDrop, node);
1713 }
1714 } else if (rx < event.x) {
1715 fFrame.insertLifelineAfter(fDragAndDrop, node);
1716 if (node.getIndex() < fFrame.lifeLinesCount()) {
1717 Lifeline temp[] = { fDragAndDrop, fFrame.getLifeline(node.getIndex()) };
1718 fReorderList.add(temp);
1719 } else {
1720 Lifeline temp[] = { fDragAndDrop, null };
1721 fReorderList.add(temp);
1722 }
1723 } else {
1724 fFrame.insertLifelineBefore(fDragAndDrop, node);
1725 Lifeline temp[] = { fDragAndDrop, node };
1726 fReorderList.add(temp);
1727 }
1728 }
1729 }
1730 fDragAndDrop = null;
1731 redraw();
1732 if (fFrame == null) {
1733 return;
1734 }
1735 fFrame.resetTimeCompression();
1736
1737 // reset auto scroll if it's engaged
1738 if (fLocalAutoScroll != null) {
1739 fLocalAutoScroll.cancel();
1740 fLocalAutoScroll = null;
1741 }
1742 super.contentsMouseUpEvent(event);
1743 }
1744
1745 @Override
1746 protected void contentsMouseDownEvent(MouseEvent event) {
1747 if (fCurrentGraphNode != null) {
1748 fCurrentGraphNode.setFocused(false);
1749 }
1750
1751 // Just in case the diagram highlight a time compression region
1752 // this region need to be released when clicking everywhere
1753 if (fFrame == null) {
1754 return;
1755 }
1756
1757 fFrame.resetTimeCompression();
1758
1759 if ((event.stateMask & SWT.CTRL) != 0) {
1760 fCtrlSelection = true;
1761 } else {
1762 fCtrlSelection = false;
1763 }
1764
1765 if (((fZoomInMode) || (fZoomOutMode)) && (event.button == 1)) {
1766 int cx = Math.round(event.x / fZoomValue);
1767 int cy = Math.round(event.y / fZoomValue);
1768 if (fZoomInMode) {
1769 if (fZoomValue < 64) {
1770 fZoomValue = fZoomValue * (float) 1.25;
1771 }
1772 } else {
1773 fZoomValue = fZoomValue / (float) 1.25;
1774 }
1775 int x = Math.round(cx * fZoomValue - getVisibleWidth() / (float) 2);
1776 int y = Math.round(cy * fZoomValue - getVisibleHeight() / (float) 2);
1777 setContentsPos(x, y);
1778 if (fTimeBar != null) {
1779 fTimeBar.setZoom(fZoomValue);
1780 }
1781 // redraw also resize the scrollView content
1782 redraw();
1783 } else {
1784 GraphNode node = null;
1785 int x = Math.round(event.x / fZoomValue);
1786 int y = Math.round(event.y / fZoomValue);
1787 node = fFrame.getNodeAt(x, y);
1788
1789 if ((event.button == 1) || ((node != null) && !node.isSelected())) {
1790 if (!fShiftSelection) {
1791 fListStart = node;
1792 }
1793 if (fShiftSelection) {
1794 clearSelection();
1795 addSelection(fFrame.getNodeList(fListStart, node));
1796 } else {
1797 performSelection(node);
1798 }
1799 fCurrentGraphNode = node;
1800 if (node != null) {
1801 node.setFocused(true);
1802 }
1803 }
1804 redraw();
1805 }
1806 if (fDragAndDrop == null) {
1807 super.contentsMouseDownEvent(event);
1808 }
1809 fIsDragAndDrop = (event.button == 1);
1810
1811 }
1812
1813 /**
1814 * TimerTask for auto scroll feature.
1815 */
1816 protected static class AutoScroll extends TimerTask {
1817 /**
1818 * Field delta x.
1819 */
1820 public int fDeltaX;
1821 /**
1822 * Field delta y.
1823 */
1824 public int fDeltaY;
1825 /**
1826 * Field sequence diagram reference.
1827 */
1828 public SDWidget fSdWidget;
1829
1830 /**
1831 * Constructor for AutoScroll.
1832 * @param sv sequence diagram widget reference
1833 * @param dx delta x
1834 * @param dy delta y
1835 */
1836 public AutoScroll(SDWidget sv, int dx, int dy) {
1837 fSdWidget = sv;
1838 fDeltaX = dx;
1839 fDeltaY = dy;
1840 }
1841
1842 @Override
1843 public void run() {
1844 Display display = Display.getDefault();
1845 if ((display == null) || (display.isDisposed())) {
1846 return;
1847 }
1848 display.asyncExec(new Runnable() {
1849 @Override
1850 public void run() {
1851 if (fSdWidget.isDisposed()) {
1852 return;
1853 }
1854 fSdWidget.fDragX += fDeltaX;
1855 fSdWidget.fDragY += fDeltaY;
1856 fSdWidget.scrollBy(fDeltaX, fDeltaY);
1857 }
1858 });
1859 }
1860 }
1861
1862 @Override
1863 protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) {
1864 if (fFrame == null) {
1865 gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
1866 gc.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight());
1867 gc.dispose();
1868 return;
1869 }
1870 SDViewPref.getInstance();
1871
1872 Rectangle area = getClientArea();
1873 Image dbuffer = getDrawBuffer();
1874 int height = Math.round((fFrame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * fZoomValue);
1875
1876 try {
1877 gc.drawImage(dbuffer, 0, 0, area.width, area.height, 0, 0, area.width, area.height);
1878 } catch (Exception e) {
1879 Activator.getDefault().logError("Error drawin content", e); //$NON-NLS-1$
1880 }
1881 dbuffer.dispose();
1882 setHScrollBarIncrement(Math.round(SDViewPref.getInstance().getLifelineWidth() / (float) 2 * fZoomValue));
1883 setVScrollBarIncrement(Math.round(Metrics.getMessagesSpacing() * fZoomValue));
1884 if ((fTimeBar != null) && (fFrame.hasTimeInfo())) {
1885 fTimeBar.resizeContents(9, height + getHorizontalBarHeight());
1886 fTimeBar.setContentsPos(getContentsX(), getContentsY());
1887 fTimeBar.redraw();
1888 fTimeBar.update();
1889 }
1890 float xRatio = getContentsWidth() / (float) getVisibleWidth();
1891 float yRatio = getContentsHeight() / (float) getVisibleHeight();
1892 if (yRatio > xRatio) {
1893 setOverviewSize((int) (getVisibleHeight() * 0.75));
1894 } else {
1895 setOverviewSize((int) (getVisibleWidth() * 0.75));
1896 }
1897 }
1898
1899 @Override
1900 public void widgetDefaultSelected(SelectionEvent event) {
1901 }
1902
1903 @Override
1904 public void widgetSelected(SelectionEvent event) {
1905 if (event.widget == fZoomIn) {
1906 fZoomValue = fZoomValue * 2;
1907 } else if (event.widget == fZoomOut) {
1908 fZoomValue = fZoomValue / 2;
1909 }
1910 redraw();
1911 }
1912
1913 /**
1914 * Called when property changed occurs in the preference page. "PREFOK" is
1915 * fired when the user press the ok or apply button
1916 */
1917 @Override
1918 public void propertyChange(PropertyChangeEvent e) {
1919 if (fFrame != null && !isDisposed()) {
1920 fFrame.resetTimeCompression();
1921 }
1922 if (e.getProperty().equals("PREFOK")) //$NON-NLS-1$
1923 {
1924 // Prepare the overview to be reused for the new
1925 // settings (especially the colors)
1926 if (fOverView != null) {
1927 fOverView.dispose();
1928 }
1929 fOverView = null;
1930 redraw();
1931 }
1932 }
1933
1934 @Override
1935 public void widgetDisposed(DisposeEvent e) {
1936 if (fOverView != null) {
1937 fOverView.dispose();
1938 }
1939 super.removeDisposeListener(this);
1940 if ((fCurrentCaretImage != null) && (!fCurrentCaretImage.isDisposed())) {
1941 fCurrentCaretImage.dispose();
1942 }
1943 if ((fArrowUpCaretImg != null) && (!fArrowUpCaretImg.isDisposed())) {
1944 fArrowUpCaretImg.dispose();
1945 }
1946 if ((fCollapaseCaretImg != null) && (!fCollapaseCaretImg.isDisposed())) {
1947 fCollapaseCaretImg.dispose();
1948 }
1949 SDViewPref.getInstance().removePropertyChangeListener(this);
1950 LoadersManager lm = LoadersManager.getInstance();
1951 if (fSite instanceof SDView) {
1952 ((SDView) fSite).resetProviders();
1953 if (lm != null) {
1954 lm.resetLoader(((SDView) fSite).getViewSite().getId());
1955 }
1956 }
1957 }
1958
1959 @Override
1960 protected void drawOverview(GC gc, Rectangle r) {
1961 float oldzoom = fZoomValue;
1962 if (getContentsWidth() > getContentsHeight()) {
1963 fZoomValue = (float) r.width / (float) getContentsWidth() * oldzoom;
1964 } else {
1965 fZoomValue = (float) r.height / (float) getContentsHeight() * oldzoom;
1966 }
1967 if ((fOverView != null) && ((r.width != fOverView.getBounds().width) || (r.height != fOverView.getBounds().height))) {
1968 fOverView.dispose();
1969 fOverView = null;
1970 }
1971 if (fOverView == null) {
1972 int backX = getContentsX();
1973 int backY = getContentsY();
1974 setContentsPos(0, 0);
1975 fOverView = new Image(getDisplay(), r.width, r.height);
1976 GC gcim = new GC(fOverView);
1977 NGC context = new NGC(this, gcim);
1978 context.setBackground(SDViewPref.getInstance().getBackGroundColor(ISDPreferences.PREF_FRAME));
1979 fFrame.draw(context);
1980 setContentsPos(backX, backY);
1981 gcim.dispose();
1982 context.dispose();
1983 }
1984 if ((fOverView != null) && (r.width == fOverView.getBounds().width) && (r.height == fOverView.getBounds().height)) {
1985 gc.drawImage(fOverView, 0, 0, r.width, r.height, 0, 0, r.width, r.height);
1986 }
1987
1988 fZoomValue = oldzoom;
1989
1990 super.drawOverview(gc, r);
1991 }
1992
1993 @Override
1994 public void deltaSelected(Lifeline lifeline, int startEvent, int nbEvent, IColor color) {
1995 fFrame.highlightTimeCompression(lifeline, startEvent, nbEvent, color);
1996 ensureVisible(lifeline);
1997 int y1 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent;
1998 int y2 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * (startEvent + nbEvent);
1999 ensureVisible(lifeline.getX(), y1 - (Metrics.getLifelineHeaderFontHeigth() + +2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN), lifeline.getWidth(), y2 - y1 + 3, SWT.CENTER | SWT.VERTICAL, true);
2000 redraw();
2001 update();
2002 }
2003
2004 @Override
2005 public int getVisibleWidth() {
2006 if (fIsPrinting) {
2007 return fPrinter.getClientArea().width;
2008 }
2009 return super.getVisibleWidth();
2010 }
2011
2012 @Override
2013 public int getVisibleHeight() {
2014 if (fIsPrinting) {
2015 return fPrinter.getClientArea().height;
2016 }
2017 return super.getVisibleHeight();
2018 }
2019
2020 @Override
2021 public int contentsToViewX(int x) {
2022 if (fIsPrinting) {
2023 int v = Math.round(fPrinterX * fPrinterZoom);
2024 return x - v;
2025 }
2026 return x - getContentsX();
2027 }
2028
2029 @Override
2030 public int contentsToViewY(int y) {
2031 if (fIsPrinting) {
2032 int v = Math.round(fPrinterY * fPrinterZoom);
2033 return y - v;
2034 }
2035 return y - getContentsY();
2036 }
2037
2038 @Override
2039 public int getContentsX() {
2040 if (fIsPrinting) {
2041 return Math.round(fPrinterX * fPrinterZoom);
2042 }
2043 return super.getContentsX();
2044 }
2045
2046 @Override
2047 public int getContentsY() {
2048 if (fIsPrinting) {
2049 return Math.round(fPrinterY * fPrinterZoom);
2050 }
2051 return super.getContentsY();
2052 }
2053
2054 /**
2055 * Traverse Listener implementation.
2056 */
2057 protected static class LocalTraverseListener implements TraverseListener {
2058 @Override
2059 public void keyTraversed(TraverseEvent e) {
2060 if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
2061 e.doit = true;
2062 }
2063 }
2064 }
2065
2066 }
This page took 0.128266 seconds and 5 git commands to generate.