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