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