Commit | Line | Data |
---|---|---|
73005152 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2005, 2008, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * $Id: SDWidget.java,v 1.6 2008/12/12 22:21:46 jcayne Exp $ | |
8 | * | |
9 | * Contributors: | |
10 | * IBM - Initial API and implementation | |
11 | * Bernd Hufmann - Updated for TMF | |
12 | **********************************************************************/ | |
13 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd; | |
14 | ||
15 | import java.text.MessageFormat; | |
16 | import java.util.ArrayList; | |
17 | import java.util.List; | |
18 | import java.util.Timer; | |
19 | import java.util.TimerTask; | |
20 | ||
21 | import org.eclipse.jface.contexts.IContextIds; | |
22 | import org.eclipse.jface.util.IPropertyChangeListener; | |
23 | import org.eclipse.jface.util.PropertyChangeEvent; | |
24 | import org.eclipse.jface.viewers.ISelectionProvider; | |
25 | import org.eclipse.jface.viewers.StructuredSelection; | |
26 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
27 | import org.eclipse.linuxtools.tmf.ui.ITmfImageConstants; | |
28 | import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin; | |
29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage; | |
30 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicExecutionOccurrence; | |
31 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Frame; | |
32 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; | |
33 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange; | |
34 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; | |
35 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Metrics; | |
36 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; | |
37 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences; | |
38 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDCollapseProvider; | |
39 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager; | |
40 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
41 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages; | |
42 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDPrintDialog; | |
43 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDPrintDialogUI; | |
44 | import org.eclipse.swt.SWT; | |
45 | import org.eclipse.swt.accessibility.ACC; | |
46 | import org.eclipse.swt.accessibility.Accessible; | |
47 | import org.eclipse.swt.accessibility.AccessibleAdapter; | |
48 | import org.eclipse.swt.accessibility.AccessibleControlAdapter; | |
49 | import org.eclipse.swt.accessibility.AccessibleControlEvent; | |
50 | import org.eclipse.swt.accessibility.AccessibleEvent; | |
51 | import org.eclipse.swt.events.DisposeEvent; | |
52 | import org.eclipse.swt.events.DisposeListener; | |
53 | import org.eclipse.swt.events.FocusEvent; | |
54 | import org.eclipse.swt.events.FocusListener; | |
55 | import org.eclipse.swt.events.KeyEvent; | |
56 | import org.eclipse.swt.events.MouseEvent; | |
57 | import org.eclipse.swt.events.SelectionEvent; | |
58 | import org.eclipse.swt.events.SelectionListener; | |
59 | import org.eclipse.swt.events.TraverseEvent; | |
60 | import org.eclipse.swt.events.TraverseListener; | |
61 | import org.eclipse.swt.graphics.GC; | |
62 | import org.eclipse.swt.graphics.Image; | |
63 | import org.eclipse.swt.graphics.ImageData; | |
64 | import org.eclipse.swt.graphics.Rectangle; | |
65 | import org.eclipse.swt.printing.Printer; | |
66 | import org.eclipse.swt.printing.PrinterData; | |
67 | import org.eclipse.swt.widgets.Canvas; | |
68 | import org.eclipse.swt.widgets.Caret; | |
69 | import org.eclipse.swt.widgets.Composite; | |
70 | import org.eclipse.swt.widgets.Control; | |
71 | import org.eclipse.swt.widgets.Display; | |
72 | import org.eclipse.swt.widgets.Event; | |
73 | import org.eclipse.swt.widgets.Listener; | |
74 | import org.eclipse.swt.widgets.MenuItem; | |
75 | import org.eclipse.ui.contexts.IContextService; | |
76 | import org.eclipse.ui.part.ViewPart; | |
77 | ||
78 | /** | |
79 | * | |
80 | * @author sveyrier | |
81 | * | |
82 | */ | |
83 | public class SDWidget extends ScrollView implements SelectionListener, IPropertyChangeListener, DisposeListener, ITimeCompressionListener { | |
84 | ||
85 | protected Frame frame; | |
86 | protected Image overView = null; | |
87 | protected MenuItem zoomIn = null; | |
88 | protected MenuItem zoomOut = null; | |
89 | protected SDWidgetSelectionProvider selProvider = null; | |
90 | public float zoomValue = 1; | |
91 | protected boolean zoomInMode = false; | |
92 | protected boolean zoomOutMode = false; | |
93 | ||
94 | protected List<GraphNode> selectedNodeList = null; | |
95 | protected boolean ctrlSelection = false; | |
96 | ||
97 | protected ViewPart site = null; | |
98 | ||
99 | public GraphNode currentGraphNode = null; | |
100 | public GraphNode listStart = null; | |
101 | public ArrayList<GraphNode> prevList = null; | |
102 | ||
103 | protected TimeCompressionBar timeBar = null; | |
104 | ||
105 | protected DiagramToolTip toolTip = null; | |
106 | ||
107 | protected Accessible accessible = null; | |
108 | ||
109 | protected GraphNode toolTipNode; | |
110 | ||
111 | protected Lifeline dragAndDrop = null; | |
112 | ||
113 | protected int focusedWidget = -1; | |
114 | ||
115 | protected float printerZoom = 0; | |
116 | ||
117 | protected int printerY = 0; | |
118 | ||
119 | protected int printerX = 0; | |
120 | ||
121 | protected boolean getDragAndDrop = false; | |
122 | ||
123 | protected int dragX = 0; | |
124 | protected int dragY = 0; | |
125 | ||
126 | protected boolean reorderMode = false; | |
127 | ||
128 | Image collapaseCaretImg = null; | |
129 | Image arrowUpCaretImg = null; | |
130 | Image currentCaretImage = null; | |
131 | ||
132 | protected ISDCollapseProvider collapseProvider = null; | |
133 | ||
134 | protected Caret insertionCartet = null; | |
135 | ||
136 | protected ArrayList<Lifeline[]> reorderList = null; | |
137 | ||
138 | protected boolean printing = false; | |
139 | protected Printer printer = null; | |
140 | ||
141 | protected boolean shiftSelection = false; | |
142 | ||
143 | protected DiagramToolTip scrollToolTip = null; | |
144 | ||
145 | public SDWidget(Composite c, int s) { | |
146 | super(c, s | SWT.NO_BACKGROUND, true); | |
147 | setOverviewEnabled(true); | |
148 | selectedNodeList = new ArrayList<GraphNode>(); | |
149 | selProvider = new SDWidgetSelectionProvider(); | |
150 | SDViewPref.getInstance().addPropertyChangeListener(this); | |
151 | toolTip = new DiagramToolTip(getViewControl()); | |
152 | super.addDisposeListener(this); | |
153 | ||
154 | scrollToolTip = new DiagramToolTip(c); | |
155 | getVerticalBar().addListener(SWT.MouseUp, new Listener() { | |
156 | ||
157 | @Override | |
158 | public void handleEvent(Event event) { | |
159 | scrollToolTip.hideToolTip(); | |
160 | } | |
161 | ||
162 | }); | |
163 | // tooltip on vertical bar causes trouble when scrolling, because | |
164 | // tooltip is constantly updated and shown | |
165 | // getVerticalBar().addSelectionListener(new SelectionListener(){ | |
166 | // | |
167 | // public void widgetSelected(SelectionEvent e) { | |
168 | // scrollToolTip.hideToolTip(); | |
169 | // double minOcc=0; | |
170 | // boolean needInit=true; | |
171 | // GraphNode m=null; | |
172 | // for (int i=0;i<frame.lifeLinesCount();i++) | |
173 | // { | |
174 | // Lifeline lifeline=frame.getLifeline(i); | |
175 | // BasicExecutionOccurrence exec=frame.getFirstExecution(lifeline); | |
176 | // if (exec instanceof ExecutionOccurrence) { | |
177 | // ExecutionOccurrence occ=(ExecutionOccurrence)exec; | |
178 | // if ((occ.hasTimeInfo())&&(occ.getFirstTime()<minOcc||needInit)) | |
179 | // { | |
180 | // needInit=false; | |
181 | // minOcc=occ.getFirstTime(); | |
182 | // m=occ; | |
183 | // } | |
184 | // } | |
185 | // } | |
186 | // | |
187 | // | |
188 | // int z=frame.getFirstVisibleSyncMessage(); | |
189 | // if (m==null) | |
190 | // { | |
191 | // SyncMessage s=frame.getSyncMessage(z); | |
192 | // if (s.hasTimeInfo()) | |
193 | // m=s; | |
194 | // } | |
195 | // if (m==null) | |
196 | // return; | |
197 | // | |
198 | // scrollToolTip.showToolTip(MessageFormat.format(SDMessages._134, //$NON-NLS-1$ | |
199 | // new Object[] { formatTimeDate(frame.getSDMinTime()), | |
200 | // formatTimeDate(m), | |
201 | // formatTimeDate(frame.getSDMaxTime())} )); | |
202 | // } | |
203 | // | |
204 | // public void widgetDefaultSelected(SelectionEvent e) { | |
205 | // // scrollToolTip.showToolTip("Toto"); | |
206 | // } | |
207 | // | |
208 | // }); | |
209 | // | |
210 | ||
211 | accessible = getViewControl().getAccessible(); | |
212 | ||
213 | accessible.addAccessibleListener(new AccessibleAdapter() { | |
214 | @Override | |
215 | public void getName(AccessibleEvent e) { | |
216 | if (e.childID == ACC.CHILDID_SELF) { | |
217 | // e.result = ""; | |
218 | } | |
219 | // Case toolTip | |
220 | else if (e.childID == 0) { | |
221 | if (toolTipNode != null) { | |
222 | if (toolTipNode instanceof Lifeline) { | |
223 | Lifeline lifeline = (Lifeline) toolTipNode; | |
224 | e.result = lifeline.getToolTipText(); | |
225 | } else { | |
226 | e.result = toolTipNode.getName() + getPostfixForTooltip(true); | |
227 | } | |
228 | } | |
229 | } else { | |
230 | if (getFocusNode() != null) { | |
231 | if (getFocusNode() instanceof Lifeline) { | |
232 | e.result = MessageFormat.format(SDMessages._1, new Object[] { String.valueOf(getFocusNode().getName()) }); | |
233 | } | |
234 | if (getFocusNode() instanceof BaseMessage) { | |
235 | BaseMessage mes = (BaseMessage) getFocusNode(); | |
236 | if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() != null)) { | |
237 | e.result = MessageFormat.format( | |
238 | SDMessages._2, | |
239 | new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()), String.valueOf(mes.getEndLifeline().getName()), | |
240 | Integer.valueOf(mes.getEndOccurrence()) }); | |
241 | } else if ((mes.getStartLifeline() == null) && (mes.getEndLifeline() != null)) { | |
242 | e.result = MessageFormat.format(SDMessages._4, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getEndLifeline().getName()), Integer.valueOf(mes.getEndOccurrence()) }); | |
243 | } else if ((mes.getStartLifeline() != null) && (mes.getEndLifeline() == null)) { | |
244 | e.result = MessageFormat.format(SDMessages._3, new Object[] { String.valueOf(mes.getName()), String.valueOf(mes.getStartLifeline().getName()), Integer.valueOf(mes.getStartOccurrence()) }); | |
245 | } | |
246 | } else if (getFocusNode() instanceof BasicExecutionOccurrence) { | |
247 | BasicExecutionOccurrence exec = (BasicExecutionOccurrence) getFocusNode(); | |
248 | e.result = MessageFormat.format(SDMessages._5, | |
249 | new Object[] { String.valueOf(exec.getName()), String.valueOf(exec.getLifeline().getName()), Integer.valueOf(exec.getStartOccurrence()), Integer.valueOf(exec.getEndOccurrence()) }); | |
250 | } | |
251 | ||
252 | } | |
253 | // e.result =currentGraphNode.getName(); | |
254 | } | |
255 | } | |
256 | }); | |
257 | ||
258 | accessible.addAccessibleControlListener(new AccessibleControlAdapter() { | |
259 | @Override | |
260 | public void getFocus(AccessibleControlEvent e) { | |
261 | if (focusedWidget == -1) | |
262 | e.childID = ACC.CHILDID_SELF; | |
263 | else | |
264 | e.childID = focusedWidget; | |
265 | } | |
266 | ||
267 | @Override | |
268 | public void getRole(AccessibleControlEvent e) { | |
269 | switch (e.childID) { | |
270 | case ACC.CHILDID_SELF: | |
271 | e.detail = ACC.ROLE_CLIENT_AREA; | |
272 | break; | |
273 | case 0: | |
274 | e.detail = ACC.ROLE_TOOLTIP; | |
275 | break; | |
276 | case 1: | |
277 | e.detail = ACC.ROLE_LABEL; | |
278 | break; | |
279 | } | |
280 | } | |
281 | ||
282 | @Override | |
283 | public void getState(AccessibleControlEvent e) { | |
284 | e.detail = ACC.STATE_FOCUSABLE; | |
285 | if (e.childID == ACC.CHILDID_SELF) { | |
286 | e.detail |= ACC.STATE_FOCUSED; | |
287 | } else { | |
288 | e.detail |= ACC.STATE_SELECTABLE; | |
289 | if (e.childID == focusedWidget) | |
290 | e.detail |= ACC.STATE_FOCUSED | ACC.STATE_SELECTED | ACC.STATE_CHECKED; | |
291 | } | |
292 | } | |
293 | }); | |
294 | ||
295 | insertionCartet = new Caret((Canvas) getViewControl(), SWT.NONE); | |
296 | insertionCartet.setVisible(false); | |
297 | ||
298 | collapaseCaretImg = TmfUiPlugin.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_COLLAPSE_OBJ); | |
299 | arrowUpCaretImg = TmfUiPlugin.getDefault().getImageFromPath(ITmfImageConstants.IMG_UI_ARROW_UP_OBJ); | |
300 | ||
301 | reorderList = new ArrayList<Lifeline[]>(); | |
302 | getViewControl().addTraverseListener(new TraverseListener() { | |
303 | ||
304 | @Override | |
305 | public void keyTraversed(TraverseEvent e) { | |
306 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) | |
307 | e.doit = true; | |
308 | } | |
309 | ||
310 | }); | |
311 | ||
312 | addTraverseListener(new TraverseListener() { | |
313 | ||
314 | @Override | |
315 | public void keyTraversed(TraverseEvent e) { | |
316 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) | |
317 | e.doit = true; | |
318 | } | |
319 | ||
320 | }); | |
321 | ||
322 | getViewControl().addFocusListener(new FocusListener() { | |
323 | ||
324 | @Override | |
325 | public void focusGained(FocusEvent e) { | |
326 | // TODO Auto-generated method stub | |
327 | SDViewPref.getInstance().setNoFocusSelection(false); | |
328 | ctrlSelection = false; | |
329 | shiftSelection = false; | |
330 | redraw(); | |
331 | } | |
332 | ||
333 | @Override | |
334 | public void focusLost(FocusEvent e) { | |
335 | SDViewPref.getInstance().setNoFocusSelection(true); | |
336 | redraw(); | |
337 | } | |
338 | }); | |
339 | } | |
340 | ||
341 | public void setTimeBar(TimeCompressionBar bar) { | |
342 | if (bar != null) { | |
343 | timeBar = bar; | |
344 | timeBar.addTimeCompressionListener(this); | |
345 | } | |
346 | } | |
347 | ||
348 | protected void setCollapseProvider(ISDCollapseProvider provider) { | |
349 | collapseProvider = provider; | |
350 | } | |
351 | ||
352 | @Override | |
353 | protected void keyPressedEvent(KeyEvent event) { | |
354 | if (!(isFocusControl() || getViewControl().isFocusControl())) { | |
355 | Control[] child = getParent().getChildren(); | |
356 | for (int i = 0; i < child.length; i++) { | |
357 | if (child[i].isFocusControl()) { | |
358 | if (!(child[i] instanceof ScrollView)) { | |
359 | getViewControl().setFocus(); | |
360 | break; | |
361 | } | |
362 | } | |
363 | } | |
364 | } | |
365 | setFocus(-1); | |
366 | ||
367 | if (event.keyCode == SWT.CTRL) | |
368 | ctrlSelection = true; | |
369 | if (event.keyCode == SWT.SHIFT) { | |
370 | shiftSelection = true; | |
371 | prevList = new ArrayList<GraphNode>(); | |
372 | prevList.addAll(getSelection()); | |
373 | } | |
374 | ||
375 | GraphNode prevNode = getFocusNode(); | |
376 | ||
377 | if (event.keyCode == SWT.ARROW_RIGHT) | |
378 | traverseRight(); | |
379 | ||
380 | if (event.keyCode == SWT.ARROW_LEFT) | |
381 | traverseLeft(); | |
382 | ||
383 | if (event.keyCode == SWT.ARROW_DOWN) | |
384 | traverseDown(); | |
385 | ||
386 | if (event.keyCode == SWT.ARROW_UP) | |
387 | traverseUp(); | |
388 | ||
389 | if (event.keyCode == SWT.HOME) | |
390 | traverseHome(); | |
391 | ||
392 | if (event.keyCode == SWT.END) | |
393 | traverseEnd(); | |
394 | ||
395 | if ((!shiftSelection) && (!ctrlSelection)) | |
396 | listStart = currentGraphNode; | |
397 | ||
398 | if (event.character == ' ') { | |
399 | performSelection(currentGraphNode); | |
400 | if (!shiftSelection) | |
401 | listStart = currentGraphNode; | |
402 | } | |
403 | ||
404 | if ((shiftSelection) && (prevNode != getFocusNode())) { | |
405 | clearSelection(); | |
406 | addSelection(prevList); | |
407 | addSelection(frame.getNodeList(listStart, getFocusNode())); | |
408 | if (getFocusNode() instanceof Lifeline) | |
409 | ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true); | |
410 | else | |
411 | ensureVisible(getFocusNode()); | |
412 | } else if ((!ctrlSelection) && (!shiftSelection)) { | |
413 | ||
414 | clearSelection(); | |
415 | if (getFocusNode() != null) { | |
416 | addSelection(getFocusNode()); | |
417 | ||
418 | if (getFocusNode() instanceof Lifeline) | |
419 | ensureVisible(getFocusNode().getX(), getFocusNode().getY(), getFocusNode().getWidth(), getFocusNode().getHeight(), SWT.CENTER | SWT.VERTICAL, true); | |
420 | else | |
421 | ensureVisible(getFocusNode()); | |
422 | } | |
423 | } | |
424 | ||
425 | if (currentGraphNode != null) | |
426 | currentGraphNode.setFocused(true); | |
427 | redraw(); | |
428 | ||
429 | if ((event.character == ' ') && ((zoomInMode) || (zoomOutMode))) { | |
430 | int cx = Math.round((getContentsX() + getVisibleWidth() / 2) / zoomValue); | |
431 | int cy = Math.round((getContentsY() + getVisibleHeight() / 2) / zoomValue); | |
432 | if (zoomInMode) { | |
433 | if (zoomValue < 64) | |
434 | zoomValue = zoomValue * (float) 1.25; | |
435 | } else | |
436 | zoomValue = zoomValue / (float) 1.25; | |
437 | int x = Math.round(cx * zoomValue - getVisibleWidth() / (float) 2); | |
438 | int y = Math.round(cy * zoomValue - getVisibleHeight() / (float) 2); | |
439 | setContentsPos(x, y); | |
440 | if (timeBar != null) | |
441 | timeBar.setZoom(zoomValue); | |
442 | // redraw also resize the scrollView content | |
443 | redraw(); | |
444 | } | |
445 | } | |
446 | ||
447 | @Override | |
448 | protected void keyReleasedEvent(KeyEvent event) { | |
449 | setFocus(-1); | |
450 | if (event.keyCode == SWT.CTRL) | |
451 | ctrlSelection = false; | |
452 | if (event.keyCode == SWT.SHIFT) | |
453 | shiftSelection = false; | |
454 | super.keyReleasedEvent(event); | |
455 | setFocus(1); | |
456 | } | |
457 | ||
458 | /** | |
459 | * Resize the contents to insure the frame fit into the view | |
460 | * | |
461 | * @param frame the frame which will be drawn in the view | |
462 | */ | |
463 | public void resizeContents(Frame frame) { | |
464 | int width = Math.round((frame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * zoomValue); | |
465 | int height = Math.round((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * zoomValue); | |
466 | resizeContents(width, height); | |
467 | } | |
468 | ||
469 | protected boolean checkFocusOnChilds(Control childs) { | |
470 | if (childs instanceof Composite) { | |
471 | Control[] child = ((Composite) childs).getChildren(); | |
472 | for (int i = 0; i < child.length; i++) { | |
473 | if (child[i].isFocusControl()) { | |
474 | return true; | |
475 | } else | |
476 | checkFocusOnChilds(child[i]); | |
477 | } | |
478 | } | |
479 | return false; | |
480 | } | |
481 | ||
482 | @Override | |
483 | public boolean isFocusControl() { | |
484 | Control[] child = getChildren(); | |
485 | for (int i = 0; i < child.length; i++) { | |
486 | if (child[i].isFocusControl()) { | |
487 | return true; | |
488 | } else | |
489 | checkFocusOnChilds(child[i]); | |
490 | } | |
491 | return false; | |
492 | } | |
493 | ||
494 | /** | |
495 | * The frame to render (the sequence diagram) | |
496 | * | |
497 | * @param theFrame the frame to display | |
498 | */ | |
499 | public void setFrame(Frame theFrame, boolean resetPosition) { | |
500 | reorderList.clear(); | |
501 | selectedNodeList.clear(); | |
502 | selProvider.setSelection(new StructuredSelection()); | |
503 | frame = theFrame; | |
504 | if (resetPosition) { | |
505 | setContentsPos(0, 0); | |
506 | resizeContents(frame); | |
507 | redraw(); | |
508 | } | |
509 | // prepare the old overview to be reused | |
510 | if (overView != null) | |
511 | overView.dispose(); | |
512 | overView = null; | |
513 | resizeContents(frame); | |
514 | } | |
515 | ||
516 | /** | |
517 | * Returns the current Frame (the sequence diagram container) | |
518 | * | |
519 | * @return the frame | |
520 | */ | |
521 | public Frame getFrame() { | |
522 | return frame; | |
523 | } | |
524 | ||
525 | /** | |
526 | * Returns the selection provider for the current sequence diagram | |
527 | * | |
528 | * @return the selection provider | |
529 | */ | |
530 | public ISelectionProvider getSelectionProvider() { | |
531 | return selProvider; | |
532 | } | |
533 | ||
534 | @Override | |
535 | public boolean setContentsPos(int x, int y) { | |
536 | if (x < 0) | |
537 | x = 0; | |
538 | if (y < 0) | |
539 | y = 0; | |
540 | if (frame == null) | |
541 | return false; | |
542 | if (x + getVisibleWidth() > getContentsWidth()) | |
543 | x = getContentsWidth() - getVisibleWidth(); | |
544 | if (y + getVisibleHeight() > getContentsHeight()) | |
545 | y = getContentsHeight() - getVisibleHeight(); | |
546 | int x1 = Math.round(x / zoomValue); | |
547 | int y2 = Math.round(y / zoomValue); | |
548 | int width = Math.round(getVisibleWidth() / zoomValue); | |
549 | int height = Math.round(getVisibleHeight() / zoomValue); | |
550 | frame.updateIndex(x1, y2, width, height); | |
551 | ||
552 | if (insertionCartet != null && insertionCartet.isVisible()) | |
553 | insertionCartet.setVisible(false); | |
554 | ||
555 | return super.setContentsPos(x, y); | |
556 | } | |
557 | ||
558 | @Override | |
559 | protected void contentsMouseHover(MouseEvent event) { | |
560 | GraphNode graphNode = null; | |
561 | if (frame != null) { | |
562 | int x = Math.round(event.x / zoomValue); | |
563 | int y = Math.round(event.y / zoomValue); | |
564 | graphNode = frame.getNodeAt(x, y); | |
565 | if ((graphNode != null) && (SDViewPref.getInstance().tooltipEnabled())) { | |
566 | toolTipNode = graphNode; | |
567 | String postfix = getPostfixForTooltip(true); | |
568 | if (graphNode instanceof Lifeline) { | |
569 | Lifeline lifeline = (Lifeline) graphNode; | |
570 | toolTip.showToolTip(lifeline.getToolTipText() + postfix); | |
571 | setFocus(0); | |
572 | } else { | |
573 | toolTip.showToolTip(graphNode.getName() + postfix); | |
574 | setFocus(0); | |
575 | } | |
576 | } else | |
577 | toolTip.hideToolTip(); | |
578 | } | |
579 | } | |
580 | ||
581 | protected String getPostfixForTooltip(boolean accessible) { | |
582 | String postfix = "";//$NON-NLS-1$ | |
583 | // Determine if the tooltip must show the time difference between the current mouse position and | |
584 | // the last selected graphNode | |
585 | if ((currentGraphNode != null) && | |
586 | (currentGraphNode instanceof ITimeRange) && | |
587 | (toolTipNode instanceof ITimeRange) && | |
588 | (currentGraphNode != toolTipNode) && | |
589 | ((ITimeRange) toolTipNode).hasTimeInfo() && | |
590 | ((ITimeRange) currentGraphNode).hasTimeInfo()) { | |
591 | postfix = " -> " + currentGraphNode.getName() + "\n" + SDMessages._138 + " "; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
592 | ||
593 | //double delta = ((ITimeRange)toolTipNode).getLastTime()-((ITimeRange)currentGraphNode).getLastTime(); | |
594 | TmfTimestamp firstTime = ((ITimeRange) currentGraphNode).getEndTime(); | |
595 | TmfTimestamp lastTime = ((ITimeRange) toolTipNode).getEndTime(); | |
596 | TmfTimestamp delta = lastTime.getDelta(firstTime); | |
597 | postfix += delta.toString(); | |
598 | } else { | |
599 | if ((toolTipNode instanceof ITimeRange) && ((ITimeRange) toolTipNode).hasTimeInfo()) { | |
600 | postfix = "\n";//$NON-NLS-1$ | |
601 | TmfTimestamp firstTime = ((ITimeRange) toolTipNode).getStartTime(); | |
602 | TmfTimestamp lastTime = ((ITimeRange) toolTipNode).getEndTime(); | |
603 | ||
604 | if (firstTime != null) { | |
605 | if (lastTime != null && firstTime.compareTo(lastTime, true) != 0) { | |
606 | postfix += "start: " + firstTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ | |
607 | postfix += "end: " + lastTime + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ | |
608 | } else { | |
609 | postfix += firstTime.toString(); | |
610 | } | |
611 | } | |
612 | else if (lastTime != null) { | |
613 | postfix += lastTime.toString(); | |
614 | } | |
615 | } | |
616 | } | |
617 | return postfix; | |
618 | } | |
619 | ||
620 | protected void setFocus(int newFocusShape) { | |
621 | focusedWidget = newFocusShape; | |
622 | if (focusedWidget == -1) { | |
623 | getViewControl().getAccessible().setFocus(ACC.CHILDID_SELF); | |
624 | } else { | |
625 | getViewControl().getAccessible().setFocus(focusedWidget); | |
626 | } | |
627 | } | |
628 | ||
629 | /** Timer for auto_scroll feature */ | |
630 | protected AutoScroll local_auto_scroll_ = null; | |
631 | /** TimerTask for auto_scroll feature !=null when auto scroll is running */ | |
632 | protected Timer local_auto_scroll_timer_ = null; | |
633 | ||
634 | /** TimerTask for auto scroll feature. */ | |
635 | protected static class AutoScroll extends TimerTask { | |
636 | public int dx_, dy_; | |
637 | public SDWidget sv_; | |
638 | ||
639 | public AutoScroll(SDWidget _sv, int _dx, int _dy) { | |
640 | sv_ = _sv; | |
641 | dx_ = _dx; | |
642 | dy_ = _dy; | |
643 | } | |
644 | ||
645 | @Override | |
646 | public void run() { | |
647 | Display.getDefault().asyncExec(new Runnable() { | |
648 | @Override | |
649 | public void run() { | |
650 | if (sv_.isDisposed()) | |
651 | return; | |
652 | sv_.dragX += dx_; | |
653 | sv_.dragY += dy_; | |
654 | sv_.scrollBy(dx_, dy_); | |
655 | } | |
656 | }); | |
657 | } | |
658 | } | |
659 | ||
660 | @Override | |
661 | protected void contentsMouseMoveEvent(MouseEvent e) { | |
662 | scrollToolTip.hideToolTip(); | |
663 | toolTip.hideToolTip(); | |
664 | // super.contentsMouseMoveEvent(e); | |
665 | if (!(isFocusControl() || getViewControl().isFocusControl())) { | |
666 | Control[] child = getParent().getChildren(); | |
667 | for (int i = 0; i < child.length; i++) { | |
668 | if (child[i].isFocusControl()) { | |
669 | if (!(child[i] instanceof ScrollView)) { | |
670 | getViewControl().setFocus(); | |
671 | break; | |
672 | } | |
673 | } | |
674 | } | |
675 | } | |
676 | setFocus(-1); | |
677 | ||
678 | if (((e.stateMask & SWT.BUTTON_MASK) != 0) && ((dragAndDrop != null) || getDragAndDrop) && (reorderMode || collapseProvider != null)) { | |
679 | getDragAndDrop = false; | |
680 | if (currentGraphNode instanceof Lifeline) | |
681 | dragAndDrop = (Lifeline) currentGraphNode; | |
682 | if (dragAndDrop != null) { | |
683 | int dx = 0; | |
684 | int dy = 0; | |
685 | if (e.x > getContentsX() + getVisibleWidth()) { | |
686 | dx = e.x - (getContentsX() + getVisibleWidth()); | |
687 | } else if (e.x < getContentsX()) { | |
688 | dx = -getContentsX() + e.x; | |
689 | } | |
690 | if (e.y > getContentsY() + getVisibleHeight()) { | |
691 | dy = e.y - (getContentsY() + getVisibleHeight()); | |
692 | } else if (e.y < getContentsY()) { | |
693 | dy = -getContentsY() + e.y; | |
694 | } | |
695 | dragX = e.x; | |
696 | dragY = e.y; | |
697 | if (dx != 0 || dy != 0) { | |
698 | if (local_auto_scroll_ == null) { | |
699 | if (local_auto_scroll_timer_ == null) { | |
700 | local_auto_scroll_timer_ = new Timer(true); | |
701 | } | |
702 | local_auto_scroll_ = new AutoScroll(this, dx, dy); | |
703 | local_auto_scroll_timer_.schedule(local_auto_scroll_, 0, 75); | |
704 | } else { | |
705 | local_auto_scroll_.dx_ = dx; | |
706 | local_auto_scroll_.dy_ = dy; | |
707 | } | |
708 | } else if (local_auto_scroll_ != null) { | |
709 | local_auto_scroll_.cancel(); | |
710 | local_auto_scroll_ = null; | |
711 | } | |
712 | dragX = Math.round(e.x / zoomValue); | |
713 | dragY = Math.round(e.y / zoomValue); | |
714 | redraw(); | |
715 | Lifeline node = frame.getCloserLifeline(dragX); | |
716 | if ((node != null) && (node != dragAndDrop)) { | |
717 | int y = 0; | |
718 | int y1 = 0; | |
719 | int height = Metrics.getLifelineHeaderFontHeigth() + 2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN; | |
720 | int hMargin = Metrics.LIFELINE_VT_MAGIN / 4; | |
721 | int x = node.getX(); | |
722 | int width = node.getWidth(); | |
723 | if (frame.getVisibleAreaY() < node.getY() + node.getHeight() - height - hMargin) | |
724 | y = contentsToViewY(Math.round((node.getY() + node.getHeight()) * zoomValue)); | |
725 | else | |
726 | y = Math.round(height * zoomValue); | |
727 | ||
728 | if (frame.getVisibleAreaY() < contentsToViewY(node.getY() - hMargin)) | |
729 | y1 = contentsToViewY(Math.round((node.getY() - hMargin) * zoomValue)); | |
730 | else | |
731 | y1 = Math.round(height * zoomValue); | |
732 | ||
733 | int rx = Math.round(x * zoomValue); | |
734 | ||
735 | insertionCartet.setVisible(true); | |
736 | if ((insertionCartet.getImage() != null) && (!insertionCartet.getImage().isDisposed())) | |
737 | insertionCartet.getImage().dispose(); | |
738 | if (rx <= e.x && Math.round(rx + (width * zoomValue)) >= e.x) { | |
739 | if (collapseProvider != null) { | |
740 | ImageData data = collapaseCaretImg.getImageData(); | |
741 | data = data.scaledTo(Math.round(collapaseCaretImg.getBounds().width * zoomValue), Math.round(collapaseCaretImg.getBounds().height * zoomValue)); | |
742 | currentCaretImage = new Image(Display.getCurrent(), data); | |
743 | insertionCartet.setImage(currentCaretImage); | |
744 | insertionCartet.setLocation(contentsToViewX(rx + Math.round((width / (float) 2) * zoomValue)) - currentCaretImage.getBounds().width / 2, y); | |
745 | } | |
746 | } else if (reorderMode) { | |
747 | if (rx > e.x) { | |
748 | if (node.getIndex() > 1 && frame.getLifeline(node.getIndex() - 2) == dragAndDrop) | |
749 | return; | |
750 | ImageData data = arrowUpCaretImg.getImageData(); | |
751 | data = data.scaledTo(Math.round(arrowUpCaretImg.getBounds().width * zoomValue), Math.round(arrowUpCaretImg.getBounds().height * zoomValue)); | |
752 | currentCaretImage = new Image(Display.getCurrent(), data); | |
753 | insertionCartet.setImage(currentCaretImage); | |
754 | insertionCartet.setLocation(contentsToViewX(Math.round((x - Metrics.LIFELINE_SPACING / 2) * zoomValue)) - currentCaretImage.getBounds().width / 2, y1); | |
755 | } else { | |
756 | if (node.getIndex() < frame.lifeLinesCount() && frame.getLifeline(node.getIndex()) == dragAndDrop) | |
757 | return; | |
758 | ImageData data = arrowUpCaretImg.getImageData(); | |
759 | data = data.scaledTo(Math.round(arrowUpCaretImg.getBounds().width * zoomValue), Math.round(arrowUpCaretImg.getBounds().height * zoomValue)); | |
760 | currentCaretImage = new Image(Display.getCurrent(), data); | |
761 | insertionCartet.setImage(currentCaretImage); | |
762 | insertionCartet.setLocation(contentsToViewX(Math.round((x + width + Metrics.LIFELINE_SPACING / 2) * zoomValue)) - currentCaretImage.getBounds().width / 2 + 1, y1); | |
763 | } | |
764 | } | |
765 | } else | |
766 | insertionCartet.setVisible(false); | |
767 | } | |
768 | } else | |
769 | super.contentsMouseMoveEvent(e); | |
770 | } | |
771 | ||
772 | @Override | |
773 | protected void contentsMouseUpEvent(MouseEvent event) { | |
774 | // Just in case the diagram highlight a time compression region | |
775 | // this region need to be released when clicking everywhere | |
776 | insertionCartet.setVisible(false); | |
777 | if (dragAndDrop != null) { | |
778 | if ((overView != null) && (!overView.isDisposed())) | |
779 | overView.dispose(); | |
780 | overView = null; | |
781 | Lifeline node = frame.getCloserLifeline(dragX); | |
782 | if (node != null) { | |
783 | int rx = Math.round(node.getX() * zoomValue); | |
784 | if (rx <= event.x && Math.round(rx + (node.getWidth() * zoomValue)) >= event.x) { | |
785 | if ((collapseProvider != null) && (dragAndDrop != node)) | |
786 | collapseProvider.collapseTwoLifelines((Lifeline) dragAndDrop, node); | |
787 | } else if (rx < event.x) { | |
788 | frame.insertLifelineAfter((Lifeline) dragAndDrop, node); | |
789 | if (node.getIndex() < frame.lifeLinesCount()) { | |
790 | Lifeline temp[] = { (Lifeline) dragAndDrop, frame.getLifeline(node.getIndex()) }; | |
791 | reorderList.add(temp); | |
792 | } else { | |
793 | Lifeline temp[] = { (Lifeline) dragAndDrop, null }; | |
794 | reorderList.add(temp); | |
795 | } | |
796 | } else { | |
797 | frame.insertLifelineBefore((Lifeline) dragAndDrop, node); | |
798 | Lifeline temp[] = { (Lifeline) dragAndDrop, node }; | |
799 | reorderList.add(temp); | |
800 | } | |
801 | } | |
802 | } | |
803 | dragAndDrop = null; | |
804 | redraw(); | |
805 | if (frame == null) { | |
806 | return; | |
807 | } | |
808 | frame.resetTimeCompression(); | |
809 | ||
810 | // reset auto scroll if it's engaged | |
811 | if (local_auto_scroll_ != null) { | |
812 | local_auto_scroll_.cancel(); | |
813 | local_auto_scroll_ = null; | |
814 | } | |
815 | super.contentsMouseUpEvent(event); | |
816 | } | |
817 | ||
818 | @Override | |
819 | protected void contentsMouseDownEvent(MouseEvent event) { | |
820 | if (currentGraphNode != null) | |
821 | currentGraphNode.setFocused(false); | |
822 | // Just in case the diagram highlight a time compression region | |
823 | // this region need to be released when clicking everywhere | |
824 | if (frame == null) { | |
825 | return; | |
826 | } | |
827 | frame.resetTimeCompression(); | |
828 | ||
829 | if ((event.stateMask & SWT.CTRL) != 0) { | |
830 | ctrlSelection = true; | |
831 | } else | |
832 | ctrlSelection = false; | |
833 | ||
834 | if (((zoomInMode) || (zoomOutMode)) && (event.button == 1)) { | |
835 | int cx = Math.round(event.x / zoomValue); | |
836 | int cy = Math.round(event.y / zoomValue); | |
837 | if (zoomInMode) { | |
838 | if (zoomValue < 64) | |
839 | zoomValue = zoomValue * (float) 1.25; | |
840 | } else | |
841 | zoomValue = zoomValue / (float) 1.25; | |
842 | int x = Math.round(cx * zoomValue - getVisibleWidth() / (float) 2); | |
843 | int y = Math.round(cy * zoomValue - getVisibleHeight() / (float) 2); | |
844 | setContentsPos(x, y); | |
845 | if (timeBar != null) | |
846 | timeBar.setZoom(zoomValue); | |
847 | // redraw also resize the scrollView content | |
848 | redraw(); | |
849 | } else// if (event.button ==1) | |
850 | { | |
851 | GraphNode node = null; | |
852 | if (frame != null) { | |
853 | int x = Math.round(event.x / zoomValue); | |
854 | int y = Math.round(event.y / zoomValue); | |
855 | node = frame.getNodeAt(x, y); | |
856 | ||
857 | if ((event.button == 1) || ((node != null) && !node.isSelected())) { | |
858 | if (!shiftSelection) | |
859 | listStart = node; | |
860 | if (shiftSelection) { | |
861 | clearSelection(); | |
862 | addSelection(frame.getNodeList(listStart, node)); | |
863 | } else | |
864 | performSelection(node); | |
865 | currentGraphNode = node; | |
866 | if (node != null) | |
867 | node.setFocused(true); | |
868 | } | |
869 | redraw(); | |
870 | } | |
871 | } | |
872 | if (dragAndDrop == null) | |
873 | super.contentsMouseDownEvent(event); | |
874 | getDragAndDrop = (event.button == 1); | |
875 | ||
876 | } | |
877 | ||
878 | /** | |
879 | * Highlight the given GraphNode<br> | |
880 | * The GraphNode is then displayed using the system default selection color | |
881 | * | |
882 | * @param node the GraphNode to highlight | |
883 | */ | |
884 | protected void performSelection(GraphNode node) { | |
885 | if ((ctrlSelection) || (shiftSelection)) { | |
886 | if (node != null) { | |
887 | if (selectedNodeList.contains(node)) { | |
888 | removeSelection(node); | |
889 | } else { | |
890 | addSelection(node); | |
891 | } | |
892 | } else | |
893 | return; | |
894 | } else { | |
895 | clearSelection(); | |
896 | if (node != null) { | |
897 | addSelection(node); | |
898 | } | |
899 | } | |
900 | } | |
901 | ||
902 | public List<GraphNode> getSelection() { | |
903 | return selectedNodeList; | |
904 | } | |
905 | ||
906 | public void addSelection(GraphNode node) { | |
907 | if (node == null) | |
908 | return; | |
909 | selectedNodeList.add(node); | |
910 | node.setSelected(true); | |
911 | currentGraphNode = node; | |
912 | StructuredSelection selection = new StructuredSelection(selectedNodeList); | |
913 | selProvider.setSelection(selection); | |
914 | } | |
915 | ||
916 | public void addSelection(List<GraphNode> list) { | |
917 | // selectedNodeList.addAll(list); | |
918 | for (int i = 0; i < list.size(); i++) { | |
919 | if (!selectedNodeList.contains(list.get(i))) { | |
920 | selectedNodeList.add(list.get(i)); | |
921 | ((GraphNode) list.get(i)).setSelected(true); | |
922 | } | |
923 | } | |
924 | StructuredSelection selection = new StructuredSelection(selectedNodeList); | |
925 | selProvider.setSelection(selection); | |
926 | } | |
927 | ||
928 | public void removeSelection(GraphNode node) { | |
929 | selectedNodeList.remove(node); | |
930 | node.setSelected(false); | |
931 | node.setFocused(false); | |
932 | StructuredSelection selection = new StructuredSelection(selectedNodeList); | |
933 | selProvider.setSelection(selection); | |
934 | } | |
935 | ||
936 | public void removeSelection(List<GraphNode> list) { | |
937 | selectedNodeList.removeAll(list); | |
938 | for (int i = 0; i < list.size(); i++) { | |
939 | ((GraphNode) list.get(i)).setSelected(false); | |
940 | ((GraphNode) list.get(i)).setFocused(false); | |
941 | } | |
942 | StructuredSelection selection = new StructuredSelection(selectedNodeList); | |
943 | selProvider.setSelection(selection); | |
944 | } | |
945 | ||
946 | /** | |
947 | * Clear the list of GraphNodes which must be drawn selected | |
948 | * | |
949 | */ | |
950 | public void clearSelection() { | |
951 | for (int i = 0; i < selectedNodeList.size(); i++) { | |
952 | ((GraphNode) selectedNodeList.get(i)).setSelected(false); | |
953 | ((GraphNode) selectedNodeList.get(i)).setFocused(false); | |
954 | } | |
955 | currentGraphNode = null; | |
956 | selectedNodeList.clear(); | |
957 | selProvider.setSelection(new StructuredSelection()); | |
958 | } | |
959 | ||
960 | public void setSite(ViewPart viewSite) { | |
961 | site = viewSite; | |
962 | site.getSite().setSelectionProvider(selProvider); | |
963 | IContextService service = (IContextService) site.getSite().getWorkbenchWindow().getService(IContextService.class); | |
964 | service.activateContext("org.eclipse.linuxtools.tmf.ui.view.uml2sd.context"); //$NON-NLS-1$ | |
965 | service.activateContext(IContextIds.CONTEXT_ID_WINDOW); | |
966 | } | |
967 | ||
968 | protected Image getDrawBuffer(GC gc) { | |
969 | ||
970 | update(); | |
971 | Rectangle area = getClientArea(); | |
972 | Image dbuffer = null; | |
973 | GC gcim = null; | |
974 | ||
975 | try { | |
976 | // if (dbuffer!=null) | |
977 | // dbuffer.dispose(); | |
978 | dbuffer = new Image(getDisplay(), area.width, area.height); | |
979 | } catch (Exception e) { | |
980 | System.out.println(e.toString()); | |
981 | } | |
982 | gcim = new GC(dbuffer); | |
983 | ||
984 | NGC context = new NGC(this, gcim); | |
985 | ||
986 | // Set the metrics to use for lifeline text and message text | |
987 | // using the Graphical Context | |
988 | Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE))); | |
989 | Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE))); | |
990 | Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth()); | |
991 | Metrics.setFrameFontHeight(context.getFontHeight(Frame.getUserPref().getFont(ISDPreferences.PREF_FRAME_NAME))); | |
992 | Metrics.setLifelineHeaderFontHeight(context.getFontHeight(Frame.getUserPref().getFont(ISDPreferences.PREF_LIFELINE_HEADER))); | |
993 | ||
994 | int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS)); | |
995 | int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET)); | |
996 | int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS)); | |
997 | int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET)); | |
998 | ||
999 | int messageFontHeight = 0; | |
1000 | if (syncMessFontH > syncMessRetFontH) | |
1001 | messageFontHeight = syncMessFontH; | |
1002 | else | |
1003 | messageFontHeight = syncMessRetFontH; | |
1004 | if (messageFontHeight < asyncMessFontH) | |
1005 | messageFontHeight = asyncMessFontH; | |
1006 | if (messageFontHeight < asyncMessRetFontH) | |
1007 | messageFontHeight = asyncMessRetFontH; | |
1008 | Metrics.setMessageFontHeight(messageFontHeight); | |
1009 | context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)); | |
1010 | ||
1011 | int width = (int) ((frame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * zoomValue); | |
1012 | int height = (int) ((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * zoomValue); | |
1013 | // if (width<area.width) | |
1014 | // width=area.width; | |
1015 | // if (height<area.height) | |
1016 | // height=area.height; | |
1017 | resizeContents(width, height); | |
1018 | ||
1019 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
1020 | context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN); | |
1021 | context.fillRectangle(0, 0, frame.getX(), getContentsHeight()); | |
1022 | context.fillRectangle(frame.getX() + frame.getWidth() + 1, 0, getContentsWidth() - (frame.getX() + frame.getWidth() + 1), getContentsHeight()); | |
1023 | context.fillRectangle(0, frame.getY() + frame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame.getY() + frame.getHeight() + 1)); | |
1024 | gcim.setLineWidth(1); | |
1025 | ||
1026 | frame.draw(context); | |
1027 | if (dragAndDrop != null) { | |
1028 | Lifeline node = (Lifeline) dragAndDrop; | |
1029 | boolean isSelected = dragAndDrop.isSelected(); | |
1030 | boolean hasFocus = dragAndDrop.hasFocus(); | |
1031 | node.setSelected(false); | |
1032 | node.setFocused(false); | |
1033 | node.draw(context, dragX, dragY); | |
1034 | node.setSelected(isSelected); | |
1035 | node.setFocused(hasFocus); | |
1036 | } | |
1037 | gcim.dispose(); | |
1038 | context.dispose(); | |
1039 | return dbuffer; | |
1040 | } | |
1041 | ||
1042 | /** | |
1043 | * | |
1044 | * @param gc the context | |
1045 | */ | |
1046 | @Override | |
1047 | protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) { | |
1048 | if (frame == null) { | |
1049 | gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE)); | |
1050 | gc.fillRectangle(0, 0, getVisibleWidth(), getVisibleHeight()); | |
1051 | gc.dispose(); | |
1052 | return; | |
1053 | } else { | |
1054 | Frame.setUserPref(SDViewPref.getInstance()); | |
1055 | } | |
1056 | ||
1057 | Rectangle area = getClientArea(); | |
1058 | Image dbuffer = getDrawBuffer(gc); | |
1059 | int height = Math.round((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * zoomValue); | |
1060 | ||
1061 | try { | |
1062 | gc.drawImage(dbuffer, 0, 0, area.width, area.height, 0, 0, area.width, area.height); | |
1063 | } catch (Exception e) { | |
1064 | System.out.println(e.getMessage()); | |
1065 | } | |
1066 | dbuffer.dispose(); | |
1067 | setHScrollBarIncrement(Math.round(SDViewPref.getInstance().getLifelineWidth() / (float) 2 * zoomValue)); | |
1068 | setVScrollBarIncrement(Math.round(Metrics.getMessagesSpacing() * zoomValue)); | |
1069 | if ((timeBar != null) && (frame.hasTimeInfo())) { | |
1070 | timeBar.resizeContents(9, height + getHorizontalBarHeight()); | |
1071 | timeBar.setContentsPos(getContentsX(), getContentsY()); | |
1072 | timeBar.redraw(); | |
1073 | timeBar.update(); | |
1074 | } | |
1075 | float xRatio = getContentsWidth() / (float) getVisibleWidth(); | |
1076 | float yRatio = getContentsHeight() / (float) getVisibleHeight(); | |
1077 | if (yRatio > xRatio) { | |
1078 | setOverviewSize((int) (getVisibleHeight() * 0.75)); | |
1079 | } else { | |
1080 | setOverviewSize((int) (getVisibleWidth() * 0.75)); | |
1081 | } | |
1082 | } | |
1083 | ||
1084 | /** | |
1085 | * Returns the GraphNode overView the mouse if any | |
1086 | * | |
1087 | * @return the GraphNode | |
1088 | */ | |
1089 | public GraphNode getMouseOverNode() { | |
1090 | return currentGraphNode; | |
1091 | } | |
1092 | ||
1093 | @Override | |
1094 | public void widgetDefaultSelected(SelectionEvent event) { | |
1095 | } | |
1096 | ||
1097 | @Override | |
1098 | public void widgetSelected(SelectionEvent event) { | |
1099 | if (event.widget == zoomIn) | |
1100 | zoomValue = zoomValue * 2; | |
1101 | else if (event.widget == zoomOut) | |
1102 | zoomValue = zoomValue / 2; | |
1103 | else { | |
1104 | // SearchFilterDialog tt = new SearchFilterDialog(null);//display.getActiveShell()); | |
1105 | } | |
1106 | redraw(); | |
1107 | } | |
1108 | ||
1109 | public void setZoomInMode(boolean value) { | |
1110 | if (value) | |
1111 | setZoomOutMode(false); | |
1112 | zoomInMode = value; | |
1113 | } | |
1114 | ||
1115 | public void setZoomOutMode(boolean value) { | |
1116 | if (value) | |
1117 | setZoomInMode(false); | |
1118 | zoomOutMode = value; | |
1119 | } | |
1120 | ||
1121 | /** | |
1122 | * Moves the Sequence diagram to ensure the given node is visible and draw it selected | |
1123 | * | |
1124 | * @param node the GraphNode to move to | |
1125 | */ | |
1126 | public void moveTo(GraphNode node) { | |
1127 | if (node == null) | |
1128 | return; | |
1129 | clearSelection(); | |
1130 | addSelection(node); | |
1131 | ensureVisible(node); | |
1132 | } | |
1133 | ||
1134 | /** | |
1135 | * Moves the Sequence diagram to ensure the given node is visible | |
1136 | * | |
1137 | * @param node the GraphNode to move to | |
1138 | */ | |
1139 | public void ensureVisible(GraphNode node) { | |
1140 | if (node == null) | |
1141 | return; | |
1142 | int x = Math.round(node.getX() * zoomValue); | |
1143 | int y = Math.round(node.getY() * zoomValue); | |
1144 | int width = Math.round(node.getWidth() * zoomValue); | |
1145 | int height = Math.round(node.getHeight() * zoomValue); | |
1146 | if (node instanceof BaseMessage) { | |
1147 | if (height == 0) { | |
1148 | int header = Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN * 2 + Metrics.getLifelineHeaderFontHeigth(); | |
1149 | height = -Math.round((Metrics.getMessagesSpacing() + header) * zoomValue); | |
1150 | y = y + Math.round(Metrics.SYNC_INTERNAL_MESSAGE_HEIGHT * zoomValue); | |
1151 | } | |
1152 | } | |
1153 | if (node instanceof BasicExecutionOccurrence) { | |
1154 | width = 1; | |
1155 | height = 1; | |
1156 | } | |
1157 | if (node instanceof Lifeline) { | |
1158 | y = getContentsY(); | |
1159 | height = getVisibleHeight(); | |
1160 | } | |
1161 | ensureVisible(x, y, width, height, SWT.CENTER, true); | |
1162 | redraw(); | |
1163 | } | |
1164 | ||
1165 | public float getZoomFactor() { | |
1166 | return zoomValue; | |
1167 | } | |
1168 | ||
1169 | /** | |
1170 | * Called when property changed occurs in the preference page. "PREFOK" is fired when the user press the ok or apply | |
1171 | * button | |
1172 | * | |
1173 | * @param e the PropertyChangeEvent | |
1174 | */ | |
1175 | @Override | |
1176 | public void propertyChange(PropertyChangeEvent e) { | |
1177 | if (frame != null && !isDisposed()) { | |
1178 | frame.resetTimeCompression(); | |
1179 | } | |
1180 | if (e.getProperty().equals("PREFOK")) //$NON-NLS-1$ | |
1181 | { | |
1182 | // Prepare the overview to be reused for the new | |
1183 | // settings (especially the colors) | |
1184 | if (overView != null) | |
1185 | overView.dispose(); | |
1186 | overView = null; | |
1187 | redraw(); | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | @Override | |
1192 | public void widgetDisposed(DisposeEvent e) { | |
1193 | if (overView != null) | |
1194 | overView.dispose(); | |
1195 | super.removeDisposeListener(this); | |
1196 | if ((currentCaretImage != null) && (!currentCaretImage.isDisposed())) | |
1197 | currentCaretImage.dispose(); | |
1198 | if ((arrowUpCaretImg != null) && (!arrowUpCaretImg.isDisposed())) | |
1199 | arrowUpCaretImg.dispose(); | |
1200 | if ((collapaseCaretImg != null) && (!collapaseCaretImg.isDisposed())) | |
1201 | collapaseCaretImg.dispose(); | |
1202 | SDViewPref.getInstance().removePropertyChangeListener(this); | |
1203 | LoadersManager lm = LoadersManager.getInstance(); | |
1204 | if (site != null && site instanceof SDView) { | |
1205 | ((SDView) site).resetProviders(); | |
1206 | if (lm != null) | |
1207 | lm.resetLoader(((SDView) site).getViewSite().getId()); | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | public Image getOverview(Rectangle r) { | |
1212 | float oldzoom = zoomValue; | |
1213 | if ((overView != null) && ((r.width != overView.getBounds().width) || (r.height != overView.getBounds().height))) { | |
1214 | overView.dispose(); | |
1215 | overView = null; | |
1216 | } | |
1217 | if (overView == null) { | |
1218 | int backX = getContentsX(); | |
1219 | int backY = getContentsY(); | |
1220 | setContentsPos(0, 0); | |
1221 | overView = new Image(getDisplay(), r.width, r.height); | |
1222 | GC gcim = new GC(overView); | |
1223 | NGC context = new NGC(this, gcim); | |
1224 | context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME)); | |
1225 | frame.draw(context); | |
1226 | setContentsPos(backX, backY); | |
1227 | gcim.dispose(); | |
1228 | context.dispose(); | |
1229 | } | |
1230 | zoomValue = oldzoom; | |
1231 | return overView; | |
1232 | } | |
1233 | ||
1234 | @Override | |
1235 | protected void drawOverview(GC gc, Rectangle r) { | |
1236 | float oldzoom = zoomValue; | |
1237 | if (getContentsWidth() > getContentsHeight()) | |
1238 | zoomValue = (float) r.width / (float) getContentsWidth() * oldzoom; | |
1239 | else | |
1240 | zoomValue = (float) r.height / (float) getContentsHeight() * oldzoom; | |
1241 | if ((overView != null) && ((r.width != overView.getBounds().width) || (r.height != overView.getBounds().height))) { | |
1242 | overView.dispose(); | |
1243 | overView = null; | |
1244 | } | |
1245 | if (overView == null) { | |
1246 | int backX = getContentsX(); | |
1247 | int backY = getContentsY(); | |
1248 | setContentsPos(0, 0); | |
1249 | overView = new Image(getDisplay(), r.width, r.height); | |
1250 | GC gcim = new GC(overView); | |
1251 | NGC context = new NGC(this, gcim); | |
1252 | context.setBackground(SDViewPref.getInstance().getBackGroundColor(SDViewPref.PREF_FRAME)); | |
1253 | frame.draw(context); | |
1254 | setContentsPos(backX, backY); | |
1255 | gcim.dispose(); | |
1256 | context.dispose(); | |
1257 | } | |
1258 | if ((overView != null) && (r.width == overView.getBounds().width) && (r.height == overView.getBounds().height)) | |
1259 | gc.drawImage(overView, 0, 0, r.width, r.height, 0, 0, r.width, r.height); | |
1260 | ||
1261 | zoomValue = oldzoom; | |
1262 | ||
1263 | super.drawOverview(gc, r); | |
1264 | } | |
1265 | ||
1266 | @Override | |
1267 | public void deltaSelected(Lifeline lifeline, int startEvent, int nbEvent, IColor color) { | |
1268 | frame.highlightTimeCompression(lifeline, startEvent, nbEvent, color); | |
1269 | ensureVisible(lifeline); | |
1270 | int y1 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * startEvent; | |
1271 | int y2 = lifeline.getY() + lifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * (startEvent + nbEvent); | |
1272 | ensureVisible(lifeline.getX(), y1 - (Metrics.getLifelineHeaderFontHeigth() + +2 * Metrics.LIFELINE_HEARDER_TEXT_V_MARGIN), lifeline.getWidth(), y2 - y1 + 3, SWT.CENTER | SWT.VERTICAL, true); | |
1273 | redraw(); | |
1274 | update(); | |
1275 | } | |
1276 | ||
1277 | public void resetZoomFactor() { | |
1278 | int currentX = Math.round(getContentsX() / zoomValue); | |
1279 | int currentY = Math.round(getContentsY() / zoomValue); | |
1280 | zoomValue = 1; | |
1281 | if (timeBar != null && !timeBar.isDisposed()) { | |
1282 | timeBar.setZoom(zoomValue); | |
1283 | } | |
1284 | redraw(); | |
1285 | update(); | |
1286 | setContentsPos(currentX, currentY); | |
1287 | } | |
1288 | ||
1289 | /** | |
1290 | * Enable or disable the lifeline reodering using Drag and Drop | |
1291 | * | |
1292 | * @param mode - true to enable false otherwise | |
1293 | */ | |
1294 | public void setReorderMode(boolean mode) { | |
1295 | reorderMode = mode; | |
1296 | } | |
1297 | ||
1298 | /** | |
1299 | * Return the lifelines reorder sequence (using Drag and Drop) if the the reorder mode is turn on. Each ArryList | |
1300 | * element is of type Lifeline[2] with Lifeline[0] inserted before Lifeline[1] in the diagram | |
1301 | * | |
1302 | * @return - the re-odered sequence | |
1303 | */ | |
1304 | public ArrayList<Lifeline[]> getLifelineReoderList() { | |
1305 | return reorderList; | |
1306 | } | |
1307 | ||
1308 | public void setFocus(GraphNode node) { | |
1309 | if (node == null) | |
1310 | return; | |
1311 | if (currentGraphNode != null) | |
1312 | currentGraphNode.setFocused(false); | |
1313 | currentGraphNode = node; | |
1314 | node.setFocused(true); | |
1315 | ensureVisible(node); | |
1316 | setFocus(0); | |
1317 | } | |
1318 | ||
1319 | public GraphNode getFocusNode() { | |
1320 | return currentGraphNode; | |
1321 | } | |
1322 | ||
1323 | public void traverseRight() { | |
1324 | Object selectedNode = getFocusNode(); | |
1325 | if (selectedNode == null) | |
1326 | traverseLeft(); | |
1327 | GraphNode node = null; | |
1328 | if (selectedNode instanceof BaseMessage) { | |
1329 | if (((BaseMessage) selectedNode).getEndLifeline() != null) | |
1330 | node = frame.getCalledMessage((BaseMessage) selectedNode); | |
1331 | } | |
1332 | if (selectedNode instanceof BasicExecutionOccurrence) { | |
1333 | selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline(); | |
1334 | } | |
1335 | if ((node == null) && (selectedNode instanceof Lifeline)) { | |
1336 | // if (selectedNode instanceof BaseMessage) | |
1337 | // { | |
1338 | // if (((BaseMessage)selectedNode).getStartLifeline()!=null) | |
1339 | // selectedNode = ((BaseMessage)selectedNode).getStartLifeline(); | |
1340 | // } | |
1341 | for (int i = 0; i < frame.lifeLinesCount(); i++) { | |
1342 | if ((selectedNode == frame.getLifeline(i)) && (i < frame.lifeLinesCount() - 1)) { | |
1343 | node = frame.getLifeline(i + 1); | |
1344 | break; | |
1345 | } | |
1346 | } | |
1347 | } | |
1348 | if (node != null) { | |
1349 | setFocus(node); | |
1350 | redraw(); | |
1351 | } | |
1352 | } | |
1353 | ||
1354 | public void traverseLeft() { | |
1355 | Object selectedNode = getFocusNode(); | |
1356 | GraphNode node = null; | |
1357 | if (selectedNode instanceof BaseMessage) { | |
1358 | if (((BaseMessage) selectedNode).getStartLifeline() != null) | |
1359 | node = frame.getCallerMessage((BaseMessage) selectedNode); | |
1360 | } | |
1361 | if (selectedNode instanceof BasicExecutionOccurrence) { | |
1362 | selectedNode = ((BasicExecutionOccurrence) selectedNode).getLifeline(); | |
1363 | } | |
1364 | if (node == null) { | |
1365 | if (selectedNode instanceof BaseMessage) { | |
1366 | if (((BaseMessage) selectedNode).getEndLifeline() != null) | |
1367 | selectedNode = ((BaseMessage) selectedNode).getEndLifeline(); | |
1368 | } | |
1369 | for (int i = 0; i < frame.lifeLinesCount(); i++) { | |
1370 | if ((selectedNode == frame.getLifeline(i)) && (i > 0)) { | |
1371 | node = frame.getLifeline(i - 1); | |
1372 | break; | |
1373 | } | |
1374 | } | |
1375 | if ((frame.lifeLinesCount() > 0) && (node == null)) | |
1376 | node = frame.getLifeline(0); | |
1377 | } | |
1378 | if (node != null) { | |
1379 | setFocus(node); | |
1380 | redraw(); | |
1381 | } | |
1382 | } | |
1383 | ||
1384 | public void traverseUp() { | |
1385 | Object selectedNode = getFocusNode(); | |
1386 | if (selectedNode == null) | |
1387 | traverseLeft(); | |
1388 | GraphNode node = null; | |
1389 | if (selectedNode instanceof BaseMessage) | |
1390 | node = frame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode); | |
1391 | else if (selectedNode instanceof Lifeline) { | |
1392 | node = frame.getPrevLifelineMessage((Lifeline) selectedNode, null); | |
1393 | if (!(node instanceof Lifeline)) | |
1394 | node = null; | |
1395 | } else if (selectedNode instanceof BasicExecutionOccurrence) { | |
1396 | node = frame.getPrevExecOccurrence((BasicExecutionOccurrence) selectedNode); | |
1397 | if (node == null) | |
1398 | node = ((BasicExecutionOccurrence) selectedNode).getLifeline(); | |
1399 | } | |
1400 | if (node == null) { | |
1401 | if (selectedNode instanceof BaseMessage) { | |
1402 | if (((BaseMessage) selectedNode).getStartLifeline() != null) | |
1403 | node = ((BaseMessage) selectedNode).getStartLifeline(); | |
1404 | } | |
1405 | } | |
1406 | ||
1407 | if (node != null) { | |
1408 | setFocus(node); | |
1409 | redraw(); | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | public void traverseDown() { | |
1414 | Object selectedNode = getFocusNode(); | |
1415 | if (selectedNode == null) | |
1416 | traverseLeft(); | |
1417 | GraphNode node; | |
1418 | if (selectedNode instanceof BaseMessage) | |
1419 | node = frame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), (BaseMessage) selectedNode); | |
1420 | else if (selectedNode instanceof Lifeline) { | |
1421 | // node = frame.getNextLifelineMessage((Lifeline)selectedNode,null); | |
1422 | node = frame.getFirstExecution((Lifeline) selectedNode); | |
1423 | } else if (selectedNode instanceof BasicExecutionOccurrence) { | |
1424 | node = frame.getNextExecOccurrence((BasicExecutionOccurrence) selectedNode); | |
1425 | } else | |
1426 | return; | |
1427 | ||
1428 | if (node != null) { | |
1429 | setFocus(node); | |
1430 | redraw(); | |
1431 | } | |
1432 | } | |
1433 | ||
1434 | public void traverseHome() { | |
1435 | Object selectedNode = getFocusNode(); | |
1436 | if (selectedNode == null) | |
1437 | traverseLeft(); | |
1438 | GraphNode node = null; | |
1439 | /* | |
1440 | * if (selectedNode instanceof BaseMessage) { if (((BaseMessage)selectedNode).getStartLifeline()!=null) node = | |
1441 | * ((BaseMessage)selectedNode).getStartLifeline(); } | |
1442 | */ | |
1443 | if (selectedNode instanceof BaseMessage) { | |
1444 | if (((BaseMessage) selectedNode).getStartLifeline() != null) | |
1445 | node = frame.getNextLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null); | |
1446 | else | |
1447 | node = frame.getNextLifelineMessage(((BaseMessage) selectedNode).getEndLifeline(), null); | |
1448 | } else if (selectedNode instanceof Lifeline) | |
1449 | node = frame.getNextLifelineMessage((Lifeline) selectedNode, null); | |
1450 | else if (selectedNode instanceof BasicExecutionOccurrence) { | |
1451 | node = frame.getFirstExecution(((BasicExecutionOccurrence) selectedNode).getLifeline()); | |
1452 | } else { | |
1453 | if (frame.lifeLinesCount() > 0) { | |
1454 | Lifeline lifeline = frame.getLifeline(0); | |
1455 | node = frame.getNextLifelineMessage(lifeline, null); | |
1456 | } | |
1457 | } | |
1458 | ||
1459 | if (node != null) { | |
1460 | setFocus(node); | |
1461 | redraw(); | |
1462 | } | |
1463 | } | |
1464 | ||
1465 | public void traverseEnd() { | |
1466 | Object selectedNode = getFocusNode(); | |
1467 | if (selectedNode == null) | |
1468 | traverseLeft(); | |
1469 | GraphNode node; | |
1470 | if (selectedNode instanceof BaseMessage) | |
1471 | node = frame.getPrevLifelineMessage(((BaseMessage) selectedNode).getStartLifeline(), null); | |
1472 | else if (selectedNode instanceof Lifeline) | |
1473 | node = frame.getPrevLifelineMessage((Lifeline) selectedNode, null); | |
1474 | else if (selectedNode instanceof BasicExecutionOccurrence) { | |
1475 | node = frame.getLastExecOccurrence(((BasicExecutionOccurrence) selectedNode).getLifeline()); | |
1476 | } else { | |
1477 | if (frame.lifeLinesCount() > 0) { | |
1478 | Lifeline lifeline = frame.getLifeline(0); | |
1479 | node = frame.getPrevLifelineMessage(lifeline, null); | |
1480 | } else | |
1481 | return; | |
1482 | } | |
1483 | ||
1484 | if (node != null) { | |
1485 | setFocus(node); | |
1486 | redraw(); | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | public void printUI(SDPrintDialogUI sdPrinter) { | |
1491 | PrinterData data = sdPrinter.getPrinterData(); | |
1492 | ||
1493 | if ((data == null) || (frame == null)) { | |
1494 | return; | |
1495 | } | |
1496 | ||
1497 | printer = new Printer(data); | |
1498 | ||
1499 | String jobName = MessageFormat.format(SDMessages._116, new Object[] { String.valueOf(site.getContentDescription()), String.valueOf(frame.getName()) }); | |
1500 | printer.startJob(jobName); | |
1501 | ||
1502 | GC gc = new GC(printer); | |
1503 | Frame.setUserPref(SDViewPref.getInstance()); | |
1504 | ||
1505 | float lastZoom = zoomValue; | |
1506 | ||
1507 | Rectangle area = getClientArea(); | |
1508 | GC gcim = null; | |
1509 | ||
1510 | gcim = gc; | |
1511 | NGC context = new NGC(this, gcim); | |
1512 | ||
1513 | // Set the metrics to use for lifeline text and message text | |
1514 | // using the Graphical Context | |
1515 | Metrics.setLifelineFontHeight(context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE))); | |
1516 | Metrics.setLifelineFontWidth(context.getFontWidth(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE))); | |
1517 | Metrics.setLifelineWidth(SDViewPref.getInstance().getLifelineWidth()); | |
1518 | Metrics.setFrameFontHeight(context.getFontHeight(Frame.getUserPref().getFont(ISDPreferences.PREF_FRAME_NAME))); | |
1519 | Metrics.setLifelineHeaderFontHeight(context.getFontHeight(Frame.getUserPref().getFont(ISDPreferences.PREF_LIFELINE_HEADER))); | |
1520 | ||
1521 | int syncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS)); | |
1522 | int syncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_SYNC_MESS_RET)); | |
1523 | int asyncMessFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS)); | |
1524 | int asyncMessRetFontH = context.getFontHeight(SDViewPref.getInstance().getFont(SDViewPref.PREF_ASYNC_MESS_RET)); | |
1525 | ||
1526 | int messageFontHeight = 0; | |
1527 | if (syncMessFontH > syncMessRetFontH) | |
1528 | messageFontHeight = syncMessFontH; | |
1529 | else | |
1530 | messageFontHeight = syncMessRetFontH; | |
1531 | if (messageFontHeight < asyncMessFontH) | |
1532 | messageFontHeight = asyncMessFontH; | |
1533 | if (messageFontHeight < asyncMessRetFontH) | |
1534 | messageFontHeight = asyncMessRetFontH; | |
1535 | Metrics.setMessageFontHeight(messageFontHeight); | |
1536 | context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)); | |
1537 | ||
1538 | int width = Math.round((frame.getWidth() + 2 * Metrics.FRAME_H_MARGIN) * zoomValue); | |
1539 | int height = Math.round((frame.getHeight() + 2 * Metrics.FRAME_V_MARGIN) * zoomValue); | |
1540 | if (width < area.width) | |
1541 | width = area.width; | |
1542 | if (height < area.height) | |
1543 | height = area.height; | |
1544 | resizeContents(width, height); | |
1545 | ||
1546 | context.setBackground(Frame.getUserPref().getBackGroundColor(ISDPreferences.PREF_FRAME)); | |
1547 | context.fillRectangle(0, 0, getContentsWidth(), Metrics.FRAME_V_MARGIN); | |
1548 | context.fillRectangle(0, 0, frame.getX(), getContentsHeight()); | |
1549 | context.fillRectangle(frame.getX() + frame.getWidth() + 1, 0, getContentsWidth() - (frame.getX() + frame.getWidth() + 1), getContentsHeight()); | |
1550 | context.fillRectangle(0, frame.getY() + frame.getHeight() + 1, getContentsWidth(), getContentsHeight() - (frame.getY() + frame.getHeight() + 1)); | |
1551 | gcim.setLineWidth(1); | |
1552 | ||
1553 | printer.startPage(); | |
1554 | zoomValue = lastZoom; | |
1555 | ||
1556 | int restoreX = getContentsX(); | |
1557 | int restoreY = getContentsY(); | |
1558 | ||
1559 | float zh = getContentsHeight(); | |
1560 | float zw = getContentsWidth(); | |
1561 | ||
1562 | zh = sdPrinter.getStepY() * sdPrinter.getZoomFactor(); | |
1563 | zw = sdPrinter.getStepX() * sdPrinter.getZoomFactor(); | |
1564 | ||
1565 | float zoomValueH = printer.getClientArea().height / zh; | |
1566 | float zoomValueW = printer.getClientArea().width / zw; | |
1567 | if (zoomValueH > zoomValueW) | |
1568 | printerZoom = zoomValueH; | |
1569 | else | |
1570 | printerZoom = zoomValueW; | |
1571 | ||
1572 | if (sdPrinter.printSelection()) { | |
1573 | int[] pagesList = sdPrinter.getPageList(); | |
1574 | ||
1575 | for (int pageIndex = 0; pageIndex < pagesList.length; pageIndex++) { | |
1576 | printPage(pagesList[pageIndex], sdPrinter, context); | |
1577 | } | |
1578 | } else if (sdPrinter.printAll()) { | |
1579 | for (int pageIndex = 1; pageIndex <= sdPrinter.maxNumOfPages(); pageIndex++) { | |
1580 | printPage(pageIndex, sdPrinter, context); | |
1581 | } | |
1582 | } else if (sdPrinter.printCurrent()) { | |
1583 | printPage(getContentsX(), getContentsY(), sdPrinter, context, 1); | |
1584 | } else if (sdPrinter.printRange()) { | |
1585 | for (int pageIndex = sdPrinter.getFrom(); pageIndex <= sdPrinter.maxNumOfPages() && pageIndex <= sdPrinter.getTo(); pageIndex++) { | |
1586 | printPage(pageIndex, sdPrinter, context); | |
1587 | } | |
1588 | } | |
1589 | ||
1590 | printer.endJob(); | |
1591 | printing = false; | |
1592 | ||
1593 | gc.dispose(); | |
1594 | context.dispose(); | |
1595 | ||
1596 | zoomValue = lastZoom; | |
1597 | printer.dispose(); | |
1598 | setContentsPos(restoreX, restoreY); | |
1599 | ||
1600 | } | |
1601 | ||
1602 | public void print() { | |
1603 | SDPrintDialog sdPrinter = new SDPrintDialog(this.getShell(), this); | |
1604 | try { | |
1605 | if (sdPrinter.open() != 0) | |
1606 | return; | |
1607 | } catch (Exception e) { | |
1608 | ||
1609 | } | |
1610 | ||
1611 | printUI(sdPrinter.getDialogUI()); | |
1612 | } | |
1613 | ||
1614 | public void printPage(int pageNum, SDPrintDialogUI pd, NGC context) { | |
1615 | int j = pageNum / pd.getNbRow(); | |
1616 | int i = pageNum % pd.getNbRow(); | |
1617 | if (i != 0) | |
1618 | j++; | |
1619 | else | |
1620 | i = pd.getNbRow(); | |
1621 | ||
1622 | i--; | |
1623 | j--; | |
1624 | ||
1625 | i = (int) (i * pd.getStepX()); | |
1626 | j = (int) (j * pd.getStepY()); | |
1627 | ||
1628 | printPage(i, j, pd, context, pageNum); | |
1629 | ||
1630 | printer.endPage(); | |
1631 | } | |
1632 | ||
1633 | public void printPage(int i, int j, SDPrintDialogUI pd, NGC context, int pageNum) { | |
1634 | printing = false; | |
1635 | int pageNumFontZoom = printer.getClientArea().height / getVisibleHeight(); | |
1636 | printerX = i; | |
1637 | printerY = j; | |
1638 | setContentsPos(i, j); | |
1639 | update(); | |
1640 | printing = true; | |
1641 | float lastZoom = zoomValue; | |
1642 | zoomValue = printerZoom * lastZoom; | |
1643 | ||
1644 | frame.draw(context); | |
1645 | ||
1646 | zoomValue = pageNumFontZoom; | |
1647 | context.setFont(SDViewPref.getInstance().getFont(SDViewPref.PREF_LIFELINE)); | |
1648 | String currentPageNum = String.valueOf(pageNum); | |
1649 | int ii = context.textExtent(currentPageNum); | |
1650 | int jj = context.getCurrentFontHeight(); | |
1651 | // context.setBackground(ColorImpl.getSystemColor(SWT.COLOR_BLACK)); | |
1652 | // context.setForeground(ColorImpl.getSystemColor(SWT.COLOR_WHITE)); | |
1653 | zoomValue = printerZoom * lastZoom; | |
1654 | context.drawText(currentPageNum, Math.round(printerX + getVisibleWidth() / printerZoom - ii / printerZoom), Math.round(printerY + getVisibleHeight() / printerZoom - jj / printerZoom), false); | |
1655 | printing = false; | |
1656 | zoomValue = lastZoom; | |
1657 | } | |
1658 | ||
1659 | @Override | |
1660 | public int getVisibleWidth() { | |
1661 | if (printing) | |
1662 | return printer.getClientArea().width; | |
1663 | return super.getVisibleWidth(); | |
1664 | } | |
1665 | ||
1666 | @Override | |
1667 | public int getVisibleHeight() { | |
1668 | if (printing) | |
1669 | return printer.getClientArea().height; | |
1670 | return super.getVisibleHeight(); | |
1671 | } | |
1672 | ||
1673 | @Override | |
1674 | public int contentsToViewX(int _x) { | |
1675 | if (printing) { | |
1676 | int v = Math.round(printerX * printerZoom); | |
1677 | return _x - v; | |
1678 | } | |
1679 | return _x - getContentsX(); | |
1680 | } | |
1681 | ||
1682 | @Override | |
1683 | public int contentsToViewY(int _y) { | |
1684 | if (printing) { | |
1685 | int v = Math.round(printerY * printerZoom); | |
1686 | return _y - v; | |
1687 | } | |
1688 | return _y - getContentsY(); | |
1689 | } | |
1690 | ||
1691 | @Override | |
1692 | public int getContentsX() { | |
1693 | if (printing) | |
1694 | return Math.round(printerX * printerZoom); | |
1695 | return super.getContentsX(); | |
1696 | ||
1697 | } | |
1698 | ||
1699 | @Override | |
1700 | public int getContentsY() { | |
1701 | if (printing) | |
1702 | return Math.round(printerY * printerZoom); | |
1703 | return super.getContentsY(); | |
1704 | } | |
1705 | ||
1706 | public Printer getPrinter() { | |
1707 | return printer; | |
1708 | } | |
1709 | ||
1710 | public boolean isPrinting() { | |
1711 | return printing; | |
1712 | } | |
1713 | } |