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