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