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