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