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