Commit | Line | Data |
---|---|---|
b0d3496e ASL |
1 | /*****************************************************************************\r |
2 | * Copyright (c) 2007, 2008 Intel Corporation.\r | |
3 | * All rights reserved. This program and the accompanying materials\r | |
4 | * are made available under the terms of the Eclipse Public License v1.0\r | |
5 | * which accompanies this distribution, and is available at\r | |
6 | * http://www.eclipse.org/legal/epl-v10.html\r | |
7 | *\r | |
8 | * Contributors:\r | |
9 | * Intel Corporation - Initial API and implementation\r | |
10 | * Ruslan A. Scherbakov, Intel - Initial API and implementation\r | |
11 | * Alvaro Sanchex-Leon - Udpated for TMF\r | |
12 | *\r | |
13 | * $Id: ThreadStatesCtrl.java,v 1.15 2008/07/11 13:49:01 aalexeev Exp $ \r | |
14 | *****************************************************************************/\r | |
15 | \r | |
16 | package org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets;\r | |
17 | \r | |
18 | import java.util.ArrayList;\r | |
19 | import java.util.HashMap;\r | |
20 | import java.util.Iterator;\r | |
21 | import java.util.List;\r | |
22 | import java.util.Map;\r | |
23 | import java.util.Vector;\r | |
24 | \r | |
25 | import org.eclipse.jface.viewers.ISelection;\r | |
26 | import org.eclipse.jface.viewers.ISelectionChangedListener;\r | |
27 | import org.eclipse.jface.viewers.ISelectionProvider;\r | |
28 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.Messages;\r | |
29 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r | |
30 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r | |
31 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r | |
32 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.TimeEvent;\r | |
33 | import org.eclipse.osgi.util.NLS;\r | |
34 | import org.eclipse.swt.SWT;\r | |
35 | import org.eclipse.swt.events.ControlEvent;\r | |
36 | import org.eclipse.swt.events.ControlListener;\r | |
37 | import org.eclipse.swt.events.FocusEvent;\r | |
38 | import org.eclipse.swt.events.FocusListener;\r | |
39 | import org.eclipse.swt.events.KeyEvent;\r | |
40 | import org.eclipse.swt.events.KeyListener;\r | |
41 | import org.eclipse.swt.events.MouseEvent;\r | |
42 | import org.eclipse.swt.events.MouseListener;\r | |
43 | import org.eclipse.swt.events.MouseMoveListener;\r | |
44 | import org.eclipse.swt.events.MouseTrackListener;\r | |
45 | import org.eclipse.swt.events.MouseWheelListener;\r | |
46 | import org.eclipse.swt.events.PaintEvent;\r | |
47 | import org.eclipse.swt.events.SelectionEvent;\r | |
48 | import org.eclipse.swt.events.SelectionListener;\r | |
49 | import org.eclipse.swt.events.TraverseEvent;\r | |
50 | import org.eclipse.swt.events.TraverseListener;\r | |
51 | import org.eclipse.swt.graphics.Cursor;\r | |
52 | import org.eclipse.swt.graphics.GC;\r | |
53 | import org.eclipse.swt.graphics.Image;\r | |
54 | import org.eclipse.swt.graphics.Point;\r | |
55 | import org.eclipse.swt.graphics.Rectangle;\r | |
56 | import org.eclipse.swt.widgets.Composite;\r | |
a5823d5f ASL |
57 | import org.eclipse.swt.widgets.Event;\r |
58 | import org.eclipse.swt.widgets.Listener;\r | |
b0d3496e ASL |
59 | import org.eclipse.swt.widgets.ScrollBar;\r |
60 | \r | |
41dc35d0 FC |
61 | /**\r |
62 | * @author alvaro\r | |
63 | * \r | |
64 | */\r | |
b0d3496e ASL |
65 | public class TmfTimeStatesCtrl extends TraceCtrl implements FocusListener,\r |
66 | KeyListener, MouseMoveListener, MouseListener, MouseWheelListener,\r | |
67 | ControlListener, SelectionListener, MouseTrackListener,\r | |
68 | TraverseListener, ISelectionProvider {\r | |
69 | \r | |
70 | public static final boolean DEFAULT_DRAW_THREAD_JOIN = true;\r | |
71 | public static final boolean DEFAULT_DRAW_THREAD_WAIT = true;\r | |
72 | public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true;\r | |
a5823d5f | 73 | public static int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;\r |
b0d3496e ASL |
74 | \r |
75 | private final double zoomCoeff = 1.5;\r | |
76 | \r | |
77 | private ITimeDataProvider _timeProvider;\r | |
78 | private boolean _isInFocus = false;\r | |
79 | private boolean _isDragCursor3 = false;\r | |
41dc35d0 | 80 | private boolean _isWaitCursor = true;\r |
b0d3496e | 81 | private boolean _mouseHover = false;\r |
a5823d5f | 82 | private int _itemHeightDefault = 19;\r |
b0d3496e ASL |
83 | private int _itemHeight = _itemHeightDefault;\r |
84 | private int _topItem = 0;\r | |
85 | private int _dragState = 0;\r | |
86 | private int _hitIdx = 0;\r | |
87 | private int _dragX0 = 0;\r | |
88 | private int _dragX = 0;\r | |
89 | private int _idealNameWidth = 0;\r | |
90 | // private double _timeStep = 10000000;\r | |
91 | private long _time0bak;\r | |
92 | private long _time1bak;\r | |
93 | private TmfTimeAnalysisProvider utilImpl = null;\r | |
94 | private ItemData _data = null;\r | |
95 | private List<SelectionListener> _selectionListeners;\r | |
96 | private List<ISelectionChangedListener> _selectionChangedListeners = new ArrayList<ISelectionChangedListener>();\r | |
97 | private Rectangle _rect0 = new Rectangle(0, 0, 0, 0);\r | |
98 | private Rectangle _rect1 = new Rectangle(0, 0, 0, 0);\r | |
99 | private Cursor _dragCursor3;\r | |
41dc35d0 | 100 | private Cursor _WaitCursor;\r |
b0d3496e ASL |
101 | private boolean drawTracesInteraction = false;\r |
102 | private boolean drawTraceJoins = DEFAULT_DRAW_THREAD_JOIN;\r | |
103 | private boolean drawTraceWaits = DEFAULT_DRAW_THREAD_WAIT;\r | |
104 | private boolean drawTraceReleases = DEFAULT_DRAW_THREAD_RELEASE;\r | |
105 | \r | |
106 | // Vertical formatting formatting for the state control view\r | |
107 | private boolean _visibleVerticalScroll = true;\r | |
108 | private int _borderWidth = 0;\r | |
109 | private int _headerHeight = 0;\r | |
110 | \r | |
a5823d5f ASL |
111 | private Listener mouseScrollFilterListener;\r |
112 | \r | |
b0d3496e ASL |
113 | public TmfTimeStatesCtrl(Composite parent, TraceColorScheme colors,\r |
114 | TmfTimeAnalysisProvider rutilImp) {\r | |
115 | \r | |
116 | super(parent, colors, SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL\r | |
117 | | SWT.DOUBLE_BUFFERED);\r | |
118 | \r | |
119 | this.utilImpl = rutilImp;\r | |
120 | _data = new ItemData(utilImpl);\r | |
121 | \r | |
122 | addFocusListener(this);\r | |
123 | addMouseListener(this);\r | |
124 | addMouseMoveListener(this);\r | |
125 | addMouseTrackListener(this);\r | |
126 | addMouseWheelListener(this);\r | |
127 | addTraverseListener(this);\r | |
128 | addKeyListener(this);\r | |
129 | addControlListener(this);\r | |
130 | ScrollBar scrollVer = getVerticalBar();\r | |
131 | ScrollBar scrollHor = getHorizontalBar();\r | |
132 | if (scrollVer != null) {\r | |
133 | scrollVer.addSelectionListener(this);\r | |
134 | scrollVer.setVisible(_visibleVerticalScroll);\r | |
135 | }\r | |
136 | \r | |
137 | if (scrollHor != null) {\r | |
138 | scrollHor.addSelectionListener(this);\r | |
139 | }\r | |
a5823d5f ASL |
140 | mouseScrollFilterListener = new Listener() {\r |
141 | // This filter is used to prevent scrolling of the view when the\r | |
142 | // mouse wheel is used to zoom\r | |
d4011df2 | 143 | @Override\r |
a5823d5f ASL |
144 | public void handleEvent(Event event) {\r |
145 | event.doit = false;\r | |
146 | }\r | |
147 | };\r | |
b0d3496e ASL |
148 | \r |
149 | _dragCursor3 = new Cursor(super.getDisplay(), SWT.CURSOR_SIZEWE);\r | |
41dc35d0 | 150 | _WaitCursor = new Cursor(super.getDisplay(), SWT.CURSOR_WAIT);\r |
b0d3496e ASL |
151 | }\r |
152 | \r | |
4e3aa37d | 153 | @Override\r |
b0d3496e ASL |
154 | public void dispose() {\r |
155 | super.dispose();\r | |
156 | _dragCursor3.dispose();\r | |
41dc35d0 | 157 | _WaitCursor.dispose();\r |
b0d3496e ASL |
158 | }\r |
159 | \r | |
160 | public void setTimeProvider(ITimeDataProvider timeProvider) {\r | |
161 | _timeProvider = timeProvider;\r | |
162 | adjustScrolls();\r | |
163 | redraw();\r | |
164 | }\r | |
165 | \r | |
166 | public void addSelectionListener(SelectionListener listener) {\r | |
167 | if (listener == null)\r | |
168 | SWT.error(SWT.ERROR_NULL_ARGUMENT);\r | |
169 | if (null == _selectionListeners)\r | |
170 | _selectionListeners = new ArrayList<SelectionListener>();\r | |
171 | _selectionListeners.add(listener);\r | |
172 | }\r | |
173 | \r | |
174 | public void removeSelectionListener(SelectionListener listener) {\r | |
175 | if (null != _selectionListeners)\r | |
176 | _selectionListeners.remove(listener);\r | |
177 | }\r | |
178 | \r | |
179 | public void fireSelectionChanged() {\r | |
180 | if (null != _selectionListeners) {\r | |
181 | Iterator<SelectionListener> it = _selectionListeners.iterator();\r | |
182 | while (it.hasNext()) {\r | |
183 | SelectionListener listener = it.next();\r | |
184 | listener.widgetSelected(null);\r | |
185 | }\r | |
186 | }\r | |
187 | }\r | |
188 | \r | |
189 | public void fireDefaultSelection() {\r | |
190 | if (null != _selectionListeners) {\r | |
191 | Iterator<SelectionListener> it = _selectionListeners.iterator();\r | |
192 | while (it.hasNext()) {\r | |
193 | SelectionListener listener = it.next();\r | |
194 | listener.widgetDefaultSelected(null);\r | |
195 | }\r | |
196 | }\r | |
197 | }\r | |
198 | \r | |
199 | public Object[] getTraces() {\r | |
200 | return _data.getTraces();\r | |
201 | }\r | |
202 | \r | |
203 | public boolean[] getTraceFilter() {\r | |
204 | return _data.getTraceFilter();\r | |
205 | }\r | |
206 | \r | |
207 | public void refreshData() {\r | |
208 | _data.refreshData();\r | |
209 | adjustScrolls();\r | |
210 | redraw();\r | |
211 | }\r | |
212 | \r | |
213 | public void refreshData(Object traces[]) {\r | |
214 | _data.refreshData(traces);\r | |
215 | adjustScrolls();\r | |
216 | redraw();\r | |
217 | }\r | |
218 | \r | |
219 | public void refreshPartial(ITmfTimeAnalysisEntry parent, TimeEvent item) {\r | |
220 | _data.refreshPartial(parent, item);\r | |
221 | adjustScrolls();\r | |
222 | redraw();\r | |
223 | }\r | |
224 | \r | |
225 | public void adjustScrolls() {\r | |
226 | if (null == _timeProvider) {\r | |
227 | getVerticalBar().setValues(0, 1, 1, 1, 1, 1);\r | |
228 | getHorizontalBar().setValues(0, 1, 1, 1, 1, 1);\r | |
229 | return;\r | |
230 | }\r | |
71c964eb ASL |
231 | \r |
232 | // Vertical scroll bar\r | |
b0d3496e ASL |
233 | int page = countPerPage();\r |
234 | if (_topItem + page > _data._items.length)\r | |
235 | _topItem = _data._items.length - page;\r | |
236 | if (_topItem < 0)\r | |
237 | _topItem = 0;\r | |
238 | getVerticalBar().setValues(_topItem, 0, _data._items.length, page, 1,\r | |
239 | page);\r | |
71c964eb ASL |
240 | \r |
241 | // HORIZONTAL BAR\r | |
242 | // Visible window\r | |
b0d3496e ASL |
243 | long time0 = _timeProvider.getTime0();\r |
244 | long time1 = _timeProvider.getTime1();\r | |
71c964eb | 245 | // Time boundaries\r |
b0d3496e ASL |
246 | long timeMin = _timeProvider.getMinTime();\r |
247 | long timeMax = _timeProvider.getMaxTime();\r | |
248 | \r | |
249 | long delta = timeMax - timeMin;\r | |
250 | \r | |
251 | int timePos = 0;\r | |
a5823d5f | 252 | int thumb = H_SCROLLBAR_MAX;\r |
71c964eb | 253 | \r |
b0d3496e | 254 | if (delta != 0) {\r |
71c964eb | 255 | // Thumb size (page size)\r |
a5823d5f | 256 | thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));\r |
71c964eb ASL |
257 | // At the beginning of visible window\r |
258 | timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));\r | |
b0d3496e ASL |
259 | }\r |
260 | \r | |
71c964eb ASL |
261 | // position, minimum, maximum, thumb size, increment (half page)t, page\r |
262 | // increment size (full page)\r | |
263 | getHorizontalBar().setValues(timePos, 0, H_SCROLLBAR_MAX, thumb,\r | |
264 | Math.max(1, thumb / 2), Math.max(2, thumb));\r | |
b0d3496e ASL |
265 | }\r |
266 | \r | |
267 | boolean ensureVisibleItem(int idx, boolean redraw) {\r | |
268 | boolean changed = false;\r | |
269 | if (idx < 0) {\r | |
270 | for (idx = 0; idx < _data._items.length; idx++) {\r | |
271 | if (((Item) _data._items[idx])._selected)\r | |
272 | break;\r | |
273 | }\r | |
274 | }\r | |
275 | if (idx >= _data._items.length)\r | |
276 | return changed;\r | |
277 | if (idx < _topItem) {\r | |
278 | _topItem = idx;\r | |
279 | getVerticalBar().setSelection(_topItem);\r | |
280 | if (redraw)\r | |
281 | redraw();\r | |
282 | changed = true;\r | |
283 | } else {\r | |
284 | int page = countPerPage();\r | |
285 | if (idx >= _topItem + page) {\r | |
286 | _topItem = idx - page + 1;\r | |
287 | getVerticalBar().setSelection(_topItem);\r | |
288 | if (redraw)\r | |
289 | redraw();\r | |
290 | changed = true;\r | |
291 | }\r | |
292 | }\r | |
293 | return changed;\r | |
294 | }\r | |
295 | \r | |
d4011df2 | 296 | @Override\r |
b0d3496e ASL |
297 | public ISelection getSelection() {\r |
298 | PlainSelection sel = new PlainSelection();\r | |
299 | ITmfTimeAnalysisEntry trace = getSelectedTrace();\r | |
300 | if (null != trace && null != _timeProvider) {\r | |
301 | long selectedTime = _timeProvider.getSelectedTime();\r | |
302 | ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);\r | |
303 | if (event != null)\r | |
304 | sel.add(event);\r | |
305 | else\r | |
306 | sel.add(trace);\r | |
307 | }\r | |
308 | return sel;\r | |
309 | }\r | |
310 | \r | |
311 | public ISelection getSelectionTrace() {\r | |
312 | PlainSelection sel = new PlainSelection();\r | |
313 | ITmfTimeAnalysisEntry trace = getSelectedTrace();\r | |
314 | if (null != trace) {\r | |
315 | sel.add(trace);\r | |
316 | }\r | |
317 | return sel;\r | |
318 | }\r | |
319 | \r | |
320 | public void selectTrace(int n) {\r | |
321 | if (n != 1 && n != -1)\r | |
322 | return;\r | |
323 | boolean changed = false;\r | |
324 | int lastSelection = -1;\r | |
325 | for (int i = 0; i < _data._items.length; i++) {\r | |
326 | Item item = (Item) _data._items[i];\r | |
327 | if (item._selected) {\r | |
328 | lastSelection = i;\r | |
329 | if (1 == n && i < _data._items.length - 1) {\r | |
330 | item._selected = false;\r | |
331 | if (item._hasChildren)\r | |
332 | _data.expandItem(i, true);\r | |
333 | item = (Item) _data._items[i + 1];\r | |
334 | if (item._hasChildren) {\r | |
335 | _data.expandItem(i + 1, true);\r | |
336 | item = (Item) _data._items[i + 2];\r | |
337 | }\r | |
338 | item._selected = true;\r | |
339 | changed = true;\r | |
340 | } else if (-1 == n && i > 0) {\r | |
341 | i--;\r | |
342 | Item prevItem = (Item) _data._items[i];\r | |
343 | if (prevItem._hasChildren) {\r | |
344 | if (prevItem._expanded) {\r | |
345 | if (i > 0) {\r | |
346 | i--;\r | |
347 | prevItem = (Item) _data._items[i];\r | |
348 | }\r | |
349 | }\r | |
350 | if (!prevItem._expanded) {\r | |
351 | int added = _data.expandItem(i, true);\r | |
352 | prevItem = (Item) _data._items[i + added];\r | |
353 | item._selected = false;\r | |
354 | prevItem._selected = true;\r | |
355 | changed = true;\r | |
356 | }\r | |
357 | } else {\r | |
358 | item._selected = false;\r | |
359 | prevItem._selected = true;\r | |
360 | changed = true;\r | |
361 | }\r | |
362 | }\r | |
363 | break;\r | |
364 | }\r | |
365 | }\r | |
366 | if (lastSelection < 0 && _data._items.length > 0) {\r | |
367 | Item item = (Item) _data._items[0];\r | |
368 | if (item._hasChildren) {\r | |
369 | _data.expandItem(0, true);\r | |
370 | item = (Item) _data._items[1];\r | |
371 | item._selected = true;\r | |
372 | changed = true;\r | |
373 | } else {\r | |
374 | item._selected = true;\r | |
375 | changed = true;\r | |
376 | }\r | |
377 | }\r | |
378 | if (changed) {\r | |
379 | ensureVisibleItem(-1, false);\r | |
380 | redraw();\r | |
381 | fireSelectionChanged();\r | |
382 | }\r | |
383 | }\r | |
384 | \r | |
385 | public void selectEvent(int n) {\r | |
386 | if (null == _timeProvider)\r | |
387 | return;\r | |
388 | ITmfTimeAnalysisEntry trace = getSelectedTrace();\r | |
a5823d5f | 389 | if (trace == _timeProvider || trace == null)\r |
b0d3496e ASL |
390 | return;\r |
391 | long selectedTime = _timeProvider.getSelectedTime();\r | |
392 | long endTime = _timeProvider.getEndTime();\r | |
393 | ITimeEvent nextEvent;\r | |
a5823d5f | 394 | if (-1 == n && selectedTime > endTime)\r |
b0d3496e ASL |
395 | nextEvent = Utils.findEvent(trace, selectedTime, 0);\r |
396 | else\r | |
397 | nextEvent = Utils.findEvent(trace, selectedTime, n);\r | |
398 | if (null == nextEvent && -1 == n)\r | |
399 | nextEvent = Utils.getFirstEvent(trace);\r | |
400 | if (null != nextEvent) {\r | |
a72a38d9 ASL |
401 | long nextTime = nextEvent.getTime();\r |
402 | // If last event detected e.g. going back or not moving to a next event\r | |
403 | if (nextTime <= selectedTime && n == 1) {\r | |
404 | // Select to the end of this last event\r | |
405 | nextTime = nextEvent.getTime() + nextEvent.getDuration();\r | |
406 | // but not beyond the end of the trace\r | |
407 | if (nextTime > endTime) {\r | |
408 | nextTime = endTime;\r | |
409 | }\r | |
410 | }\r | |
411 | _timeProvider.setSelectedTimeInt(nextTime, true);\r | |
b0d3496e ASL |
412 | fireSelectionChanged();\r |
413 | } else if (1 == n) {\r | |
414 | _timeProvider.setSelectedTimeInt(endTime, true);\r | |
415 | fireSelectionChanged();\r | |
416 | }\r | |
417 | }\r | |
418 | \r | |
419 | public void selectNextEvent() {\r | |
420 | selectEvent(1);\r | |
a72a38d9 ASL |
421 | // Notify if visible time window has been adjusted\r |
422 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r | |
b0d3496e ASL |
423 | }\r |
424 | \r | |
425 | public void selectPrevEvent() {\r | |
426 | selectEvent(-1);\r | |
a72a38d9 ASL |
427 | // Notify if visible time window has been adjusted\r |
428 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r | |
b0d3496e ASL |
429 | }\r |
430 | \r | |
431 | public void selectNextTrace() {\r | |
432 | selectTrace(1);\r | |
433 | }\r | |
434 | \r | |
435 | public void selectPrevTrace() {\r | |
436 | selectTrace(-1);\r | |
437 | }\r | |
438 | \r | |
a5823d5f ASL |
439 | /**\r |
440 | * Zooming based on mouse cursor location with mouse scrolling\r | |
441 | * \r | |
442 | * @param zoomIn\r | |
443 | */\r | |
444 | public void zoom(boolean zoomIn) {\r | |
445 | int globalX = getDisplay().getCursorLocation().x;\r | |
446 | Point p = toControl(globalX, 0);\r | |
447 | int nameSpace = _timeProvider.getNameSpace();\r | |
448 | int timeSpace = _timeProvider.getTimeSpace();\r | |
449 | int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x));\r | |
450 | long time0 = _timeProvider.getTime0();\r | |
451 | long time1 = _timeProvider.getTime1();\r | |
452 | long interval = time1 - time0;\r | |
453 | if (interval == 0) {\r | |
454 | interval = 1;\r | |
455 | } // to allow getting out of single point interval\r | |
456 | long newInterval;\r | |
457 | if (zoomIn) {\r | |
458 | newInterval = Math.max(Math.round((double) interval * 0.8), _timeProvider.getMinTimeInterval());\r | |
459 | } else {\r | |
460 | newInterval = Math.round((double) interval * 1.25);\r | |
461 | }\r | |
462 | long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval));\r | |
463 | long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval);\r | |
464 | long newTime1 = newTime0 + newInterval;\r | |
465 | _timeProvider.setStartFinishTime(newTime0, newTime1);\r | |
466 | }\r | |
467 | \r | |
468 | /**\r | |
469 | * zoom in using single click\r | |
470 | */\r | |
b0d3496e ASL |
471 | public void zoomIn() {\r |
472 | long _time0 = _timeProvider.getTime0();\r | |
473 | long _time1 = _timeProvider.getTime1();\r | |
474 | long _range = _time1 - _time0;\r | |
475 | long selTime = _timeProvider.getSelectedTime();\r | |
476 | if (selTime <= _time0 || selTime >= _time1) {\r | |
477 | selTime = (_time0 + _time1) / 2;\r | |
478 | }\r | |
479 | long time0 = selTime - (long) ((selTime - _time0) / zoomCoeff);\r | |
480 | long time1 = selTime + (long) ((_time1 - selTime) / zoomCoeff);\r | |
481 | \r | |
482 | long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider\r | |
483 | .getMinTime())\r | |
484 | - (time1 - time0);\r | |
485 | \r | |
486 | // Trace.debug("selTime:" + selTime + " time0:" + time0 + " time1:"\r | |
487 | // + time1 + " inaccuracy:" + inaccuracy);\r | |
488 | \r | |
489 | if (inaccuracy > 0 && inaccuracy < 100) {\r | |
71c964eb | 490 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(),\r |
b0d3496e ASL |
491 | _timeProvider.getMaxTime());\r |
492 | return;\r | |
493 | }\r | |
494 | \r | |
495 | long m = _timeProvider.getMinTimeInterval();\r | |
496 | if ((time1 - time0) < m) {\r | |
497 | time0 = selTime - (long) ((selTime - _time0) * m / _range);\r | |
498 | time1 = time0 + m;\r | |
499 | }\r | |
500 | \r | |
71c964eb | 501 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r |
b0d3496e ASL |
502 | }\r |
503 | \r | |
a5823d5f ASL |
504 | /**\r |
505 | * zoom out using single click\r | |
506 | */\r | |
b0d3496e ASL |
507 | public void zoomOut() {\r |
508 | long _time0 = _timeProvider.getTime0();\r | |
509 | long _time1 = _timeProvider.getTime1();\r | |
510 | long selTime = _timeProvider.getSelectedTime();\r | |
511 | if (selTime <= _time0 || selTime >= _time1) {\r | |
512 | selTime = (_time0 + _time1) / 2;\r | |
513 | }\r | |
514 | long time0 = (long) (selTime - (selTime - _time0) * zoomCoeff);\r | |
515 | long time1 = (long) (selTime + (_time1 - selTime) * zoomCoeff);\r | |
516 | \r | |
517 | long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider\r | |
518 | .getMinTime())\r | |
519 | - (time1 - time0);\r | |
520 | if (inaccuracy > 0 && inaccuracy < 100) {\r | |
71c964eb | 521 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(),\r |
b0d3496e ASL |
522 | _timeProvider.getMaxTime());\r |
523 | return;\r | |
524 | }\r | |
525 | \r | |
71c964eb | 526 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r |
b0d3496e ASL |
527 | }\r |
528 | \r | |
529 | public void groupTraces(boolean on) {\r | |
530 | _data.groupTraces(on);\r | |
531 | adjustScrolls();\r | |
532 | redraw();\r | |
533 | }\r | |
534 | \r | |
535 | public void toggleTraceInteractionDrawing() {\r | |
536 | drawTracesInteraction = !drawTracesInteraction;\r | |
537 | redraw();\r | |
538 | }\r | |
539 | \r | |
540 | public void setTraceJoinDrawing(boolean on) {\r | |
541 | drawTraceJoins = on;\r | |
542 | drawTracesInteraction = true;\r | |
543 | redraw();\r | |
544 | }\r | |
545 | \r | |
546 | public void setTraceWaitDrawing(boolean on) {\r | |
547 | drawTraceWaits = on;\r | |
548 | drawTracesInteraction = true;\r | |
549 | redraw();\r | |
550 | }\r | |
551 | \r | |
552 | public void setTraceReleaseDrawing(boolean on) {\r | |
553 | drawTraceReleases = on;\r | |
554 | drawTracesInteraction = true;\r | |
555 | redraw();\r | |
556 | }\r | |
557 | \r | |
558 | public boolean getTracesInteractionDrawing() {\r | |
559 | return drawTracesInteraction;\r | |
560 | }\r | |
561 | \r | |
562 | public boolean getTraceJoinDrawing() {\r | |
563 | return drawTraceJoins;\r | |
564 | }\r | |
565 | \r | |
566 | public boolean getTraceWaitDrawing() {\r | |
567 | return drawTraceWaits;\r | |
568 | }\r | |
569 | \r | |
570 | public boolean getTraceReleaseDrawing() {\r | |
571 | return drawTraceReleases;\r | |
572 | }\r | |
573 | \r | |
574 | public ITmfTimeAnalysisEntry getSelectedTrace() {\r | |
575 | ITmfTimeAnalysisEntry trace = null;\r | |
576 | int idx = getSelectedIndex();\r | |
577 | if (idx >= 0 && _data._items[idx] instanceof TraceItem)\r | |
578 | trace = ((TraceItem) _data._items[idx])._trace;\r | |
579 | return trace;\r | |
580 | }\r | |
581 | \r | |
582 | public int getSelectedIndex() {\r | |
583 | int idx = -1;\r | |
584 | for (int i = 0; i < _data._items.length; i++) {\r | |
585 | Item item = (Item) _data._items[i];\r | |
586 | if (item._selected) {\r | |
587 | idx = i;\r | |
588 | break;\r | |
589 | }\r | |
590 | }\r | |
591 | return idx;\r | |
592 | }\r | |
593 | \r | |
594 | boolean toggle(int idx) {\r | |
595 | boolean toggled = false;\r | |
596 | if (idx >= 0 && idx < _data._items.length) {\r | |
597 | Item item = (Item) _data._items[idx];\r | |
598 | if (item._hasChildren) {\r | |
599 | item._expanded = !item._expanded;\r | |
600 | _data.updateItems();\r | |
601 | adjustScrolls();\r | |
602 | redraw();\r | |
603 | toggled = true;\r | |
604 | }\r | |
605 | }\r | |
606 | return toggled;\r | |
607 | }\r | |
608 | \r | |
609 | int hitTest(int x, int y) {\r | |
610 | if (x < 0 || y < 0)\r | |
611 | return -1;\r | |
612 | int hit = -1;\r | |
613 | int idx = y / _itemHeight;\r | |
614 | idx += _topItem;\r | |
615 | if (idx < _data._items.length)\r | |
616 | hit = idx;\r | |
617 | return hit;\r | |
618 | }\r | |
619 | \r | |
620 | int hitSplitTest(int x, int y) {\r | |
621 | if (x < 0 || y < 0 || null == _timeProvider)\r | |
622 | return -1;\r | |
623 | int w = 4;\r | |
624 | int hit = -1;\r | |
625 | int nameWidth = _timeProvider.getNameSpace();\r | |
626 | if (x > nameWidth - w && x < nameWidth + w)\r | |
627 | hit = 1;\r | |
628 | return hit;\r | |
629 | }\r | |
630 | \r | |
631 | public Item getItem(Point pt) {\r | |
632 | int idx = hitTest(pt.x, pt.y);\r | |
633 | return idx >= 0 ? (Item) _data._items[idx] : null;\r | |
634 | }\r | |
635 | \r | |
636 | long hitTimeTest(int x, int y) {\r | |
637 | if (null == _timeProvider)\r | |
638 | return -1;\r | |
639 | long hitTime = -1;\r | |
640 | Point size = getCtrlSize();\r | |
641 | long time0 = _timeProvider.getTime0();\r | |
642 | long time1 = _timeProvider.getTime1();\r | |
643 | int nameWidth = _timeProvider.getNameSpace();\r | |
644 | x -= nameWidth;\r | |
645 | if (x >= 0 && size.x >= nameWidth) {\r | |
8b9fa226 ASL |
646 | if (time1 - time0 > size.x - nameWidth - RIGHT_MARGIN) {\r |
647 | // get the last possible time represented by the pixel position\r | |
648 | // by taking the time of the next pixel position minus 1 nanosecond\r | |
649 | hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / (size.x - nameWidth - RIGHT_MARGIN))) - 1;\r | |
650 | } else {\r | |
651 | hitTime = time0 + (long) ((time1 - time0) * ((double) (x) / (size.x - nameWidth - RIGHT_MARGIN)));\r | |
652 | }\r | |
b0d3496e ASL |
653 | }\r |
654 | return hitTime;\r | |
655 | }\r | |
656 | \r | |
657 | void selectItem(int idx, boolean addSelection) {\r | |
658 | if (addSelection) {\r | |
659 | if (idx >= 0 && idx < _data._items.length) {\r | |
660 | Item item = (Item) _data._items[idx];\r | |
661 | item._selected = true;\r | |
662 | }\r | |
663 | } else {\r | |
664 | for (int i = 0; i < _data._items.length; i++) {\r | |
665 | Item item = (Item) _data._items[i];\r | |
666 | item._selected = i == idx;\r | |
667 | }\r | |
668 | }\r | |
669 | boolean changed = ensureVisibleItem(idx, true);\r | |
670 | if (!changed)\r | |
671 | redraw();\r | |
672 | }\r | |
673 | \r | |
674 | public void selectItem(ITmfTimeAnalysisEntry trace, boolean addSelection) {\r | |
675 | Integer idx = _data.findTraceItemIndex(trace);\r | |
676 | selectItem(idx, addSelection);\r | |
677 | }\r | |
678 | \r | |
679 | public int countPerPage() {\r | |
680 | int height = getCtrlSize().y;\r | |
681 | int count = 0;\r | |
682 | if (height > 0)\r | |
683 | count = height / _itemHeight;\r | |
684 | return count;\r | |
685 | }\r | |
686 | \r | |
687 | public int getTopIndex() {\r | |
688 | int idx = -1;\r | |
689 | if (_data._items.length > 0)\r | |
690 | idx = 0;\r | |
691 | return idx;\r | |
692 | }\r | |
693 | \r | |
694 | public int getBottomIndex() {\r | |
695 | int idx = _data._items.length - 1;\r | |
696 | return idx;\r | |
697 | }\r | |
698 | \r | |
699 | Point getCtrlSize() {\r | |
700 | Point size = getSize();\r | |
8b9fa226 ASL |
701 | if (getVerticalBar().isVisible()) {\r |
702 | size.x -= getVerticalBar().getSize().x;\r | |
703 | }\r | |
704 | if (getHorizontalBar().isVisible()) {\r | |
705 | size.y -= getHorizontalBar().getSize().y;\r | |
706 | }\r | |
b0d3496e ASL |
707 | return size;\r |
708 | }\r | |
709 | \r | |
710 | void getNameRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) {\r | |
711 | idx -= _topItem;\r | |
712 | rect.x = bound.x;\r | |
713 | rect.y = bound.y + idx * _itemHeight;\r | |
714 | rect.width = nameWidth;\r | |
715 | rect.height = _itemHeight;\r | |
716 | }\r | |
717 | \r | |
718 | void getStatesRect(Rectangle rect, Rectangle bound, int idx, int nameWidth) {\r | |
719 | idx -= _topItem;\r | |
720 | rect.x = bound.x + nameWidth;\r | |
721 | rect.y = bound.y + idx * _itemHeight;\r | |
722 | rect.width = bound.width - rect.x;\r | |
723 | rect.height = _itemHeight;\r | |
724 | }\r | |
725 | \r | |
726 | // private int getTraceNumber(int tid) {\r | |
727 | // int num = -1;\r | |
728 | //\r | |
729 | // Object[] items = _data._items;\r | |
730 | // for (int i = _topItem; i < items.length; i++) {\r | |
731 | // Item item = (Item) items[i];\r | |
732 | // if ((item instanceof TraceItem)) {\r | |
733 | // TsfTmTrace trace = ((TraceItem) item)._trace;\r | |
734 | // if (trace != null && trace.getId() == tid) {\r | |
735 | // num = i;\r | |
736 | // break;\r | |
737 | // }\r | |
738 | // }\r | |
739 | // }\r | |
740 | //\r | |
741 | // return num;\r | |
742 | // }\r | |
743 | \r | |
744 | // private void drawArrow(GC gc, int x0, int y0, int x1, int y1, Color c) {\r | |
745 | // gc.setForeground(c);\r | |
746 | // gc.drawLine(x0, y0, x1, y1);\r | |
747 | //\r | |
748 | // if (y1 > y0) {\r | |
749 | // gc.drawLine(x1 - 3, y1 - 3, x1, y1);\r | |
750 | // gc.drawLine(x1 + 3, y1 - 3, x1, y1);\r | |
751 | // } else {\r | |
752 | // gc.drawLine(x1 - 3, y1 + 3, x1, y1);\r | |
753 | // gc.drawLine(x1 + 3, y1 + 3, x1, y1);\r | |
754 | // }\r | |
755 | // }\r | |
756 | \r | |
757 | // TODO: CC: used in the removed functionality to draw thread interactions.\r | |
758 | // private void drawTraceThreadEvent(Rectangle bound, TsfTmEvent e,\r | |
759 | // TsfTmTrace trace, int nItem, int color, GC gc) {\r | |
760 | // if (trace == null)\r | |
761 | // return;\r | |
762 | //\r | |
763 | // int tid = trace.getId();\r | |
764 | // if (tid < 0 || getTraceNumber(tid) == -1)\r | |
765 | // return;\r | |
766 | //\r | |
767 | // int nameWidth = _timeProvider.getNameSpace();\r | |
768 | //\r | |
769 | // double time0 = _timeProvider.getTime0();\r | |
770 | // double time1 = _timeProvider.getTime1();\r | |
771 | // if (time0 == time1)\r | |
772 | // return;\r | |
773 | //\r | |
774 | // int xr = bound.x + nameWidth;\r | |
775 | // double K = (double) (bound.width - xr) / (time1 - time0);\r | |
776 | //\r | |
777 | // int x0 = xr + (int) ((e.getTime() - time0) * K);\r | |
778 | // if (x0 < xr)\r | |
779 | // x0 = xr;\r | |
780 | //\r | |
781 | // int x1 = xr + (int) ((trace.getStartTime() - time0) * K);\r | |
782 | // if (x1 < xr)\r | |
783 | // return;\r | |
784 | //\r | |
785 | // int y0 = bound.y + (nItem - _topItem) * _itemHeight + 3\r | |
786 | // + (_itemHeight - 6) / 2;\r | |
787 | // int y1 = bound.y + (getTraceNumber(tid) - _topItem) * _itemHeight + 3\r | |
788 | // + (_itemHeight - 6) / 2;\r | |
789 | //\r | |
790 | // drawArrow(gc, x0, y0, x1, y1, _colors.getColor(color));\r | |
791 | // }\r | |
792 | \r | |
793 | public void drawTraceEvent(Rectangle bound, ITimeEvent e, int nItem,\r | |
794 | int color, GC gc) {\r | |
795 | int nameWidth = _timeProvider.getNameSpace();\r | |
796 | \r | |
797 | long time0 = _timeProvider.getTime0();\r | |
798 | long time1 = _timeProvider.getTime1();\r | |
799 | if (time0 == time1)\r | |
800 | return;\r | |
801 | \r | |
802 | int xr = bound.x + nameWidth;\r | |
8b9fa226 ASL |
803 | double pixelsPerNanoSec = (bound.width - xr <= RIGHT_MARGIN) ? 0\r |
804 | : (double) (bound.width - xr - RIGHT_MARGIN) / (time1 - time0);\r | |
b0d3496e | 805 | \r |
a5823d5f | 806 | int x0 = xr + (int) ((e.getTime() - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
807 | if (x0 < xr)\r |
808 | return;\r | |
809 | \r | |
810 | int y0 = bound.y + (nItem - _topItem) * _itemHeight + 3;\r | |
811 | \r | |
812 | gc.setBackground(_colors.getColor(color));\r | |
813 | int c[] = { x0 - 3, y0 - 3, x0, y0, x0 + 3, y0 - 3 };\r | |
814 | gc.fillPolygon(c);\r | |
815 | }\r | |
816 | \r | |
817 | // TODO: CC:\r | |
818 | // private void drawExecEvent(Rectangle bound, TsfTmTraceExecEventImpl e,\r | |
819 | // int nitem, int color, GC gc) {\r | |
820 | // List runnings = e.getRunningEvents();\r | |
821 | // if (runnings == null)\r | |
822 | // return;\r | |
823 | //\r | |
824 | // int nameWidth = _timeProvider.getNameSpace();\r | |
825 | //\r | |
826 | // double time0 = _timeProvider.getTime0();\r | |
827 | // double time1 = _timeProvider.getTime1();\r | |
828 | // if (time0 == time1)\r | |
829 | // return;\r | |
830 | //\r | |
831 | // int xr = bound.x + nameWidth;\r | |
832 | // double K = (double) (bound.width - xr) / (time1 - time0);\r | |
833 | //\r | |
834 | // int x0 = xr + (int) ((e.getTime() - time0) * K);\r | |
835 | // if (x0 < xr)\r | |
836 | // x0 = xr;\r | |
837 | //\r | |
838 | // Iterator it = runnings.iterator();\r | |
839 | // while (it.hasNext()) {\r | |
840 | // TsfTmTraceRunningEventImpl re = (TsfTmTraceRunningEventImpl) it\r | |
841 | // .next();\r | |
842 | // int tid = re.getThread().getId();\r | |
843 | // if (tid < 0 || getThreadNumber(tid) == -1)\r | |
844 | // continue;\r | |
845 | //\r | |
846 | // int x1 = xr + (int) ((re.getTime() - time0) * K);\r | |
847 | // if (x1 < xr)\r | |
848 | // continue;\r | |
849 | //\r | |
850 | // int y0 = bound.y + (nitem - _topItem) * _itemHeight + 3\r | |
851 | // + (_itemHeight - 6) / 2;\r | |
852 | // int y1 = bound.y + (getThreadNumber(tid) - _topItem) * _itemHeight\r | |
853 | // + 3 + (_itemHeight - 6) / 2;\r | |
854 | //\r | |
855 | // drawArrow(gc, x0, y0, x1, y1, _colors.getColor(color));\r | |
856 | // }\r | |
857 | // }\r | |
858 | \r | |
859 | public void drawTraceInteractions(Rectangle bound, GC gc) {\r | |
860 | // int nameWidth = _timeProvider.getNameSpace();\r | |
861 | // Object[] items = _data._items;\r | |
862 | //\r | |
863 | // double time0 = _timeProvider.getTime0();\r | |
864 | // double time1 = _timeProvider.getTime1();\r | |
865 | //\r | |
866 | // if (time0 == time1)\r | |
867 | // return;\r | |
868 | //\r | |
869 | // int xr = bound.x + nameWidth;\r | |
870 | // double K = (double) (bound.width - xr) / (time1 - time0);\r | |
871 | \r | |
872 | // for (int i = 0; i < items.length; i++) {\r | |
873 | // Item item = (Item) items[i];\r | |
874 | // if (!(item instanceof TraceItem))\r | |
875 | // continue;\r | |
876 | //\r | |
877 | // TsfTmTrace trace = ((TraceItem) item)._trace;\r | |
878 | // if (trace == null)\r | |
879 | // continue;\r | |
880 | //\r | |
881 | // List<TsfTmEvent> list = trace.getTraceEvents();\r | |
882 | // Iterator<TsfTmEvent> it = list.iterator();\r | |
883 | // while (it.hasNext()) {\r | |
884 | // TsfTmEvent te = (TsfTmEvent) it.next();\r | |
885 | // TODO: CC: Thread Interactions,\r | |
886 | // This needs to be accessed externally via a specific\r | |
887 | // implementation.\r | |
888 | // if (te instanceof TsfTmTraceStartThreadEventImpl) {\r | |
889 | // TsfTmTrace child = ((TsfTmTraceStartThreadEventImpl) te)\r | |
890 | // .getStartedThread();\r | |
891 | // drawThreadThreadEvent(bound, te, child, i,\r | |
892 | // TraceColorScheme.TI_START_THREAD, gc);\r | |
893 | // } else if (te instanceof TsfTmTraceHandoffLockEventImpl) {\r | |
894 | // if (drawThreadReleases)\r | |
895 | // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i,\r | |
896 | // TraceColorScheme.TI_HANDOFF_LOCK, gc);\r | |
897 | // } else if (te instanceof TsfTmTraceNotifyAllEventImpl) {\r | |
898 | // if (drawThreadWaits)\r | |
899 | // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i,\r | |
900 | // TraceColorScheme.TI_NOTIFY_ALL, gc);\r | |
901 | // } else if (te instanceof TsfTmTraceNotifyEventImpl) {\r | |
902 | // if (drawThreadWaits)\r | |
903 | // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i,\r | |
904 | // TraceColorScheme.TI_NOTIFY, gc);\r | |
905 | // } else if (te instanceof\r | |
906 | // TsfTmTraceDeadAndNotifyJoinedEventImpl) {\r | |
907 | // if (drawThreadJoins)\r | |
908 | // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i,\r | |
909 | // TraceColorScheme.TI_NOTIFY_JOINED, gc);\r | |
910 | // } else if (te instanceof TsfTmTraceInterruptThreadEventImpl)\r | |
911 | // {\r | |
912 | // if (drawThreadWaits)\r | |
913 | // drawExecEvent(bound, (TsfTmTraceExecEventImpl) te, i,\r | |
914 | // TraceColorScheme.TI_INTERRUPT, gc);\r | |
915 | // } else if (te instanceof\r | |
916 | // TsfTmTraceWaitTimeoutExceedEventImpl) {\r | |
917 | // drawThreadEvent(bound, te, i,\r | |
918 | // TraceColorScheme.TI_WAIT_EXCEEDED, gc);\r | |
919 | // }\r | |
920 | // }\r | |
921 | // }\r | |
922 | }\r | |
923 | \r | |
4e3aa37d | 924 | @Override\r |
b0d3496e | 925 | void paint(Rectangle bound, PaintEvent e) {\r |
a5823d5f ASL |
926 | GC gc = e.gc;\r |
927 | gc.setBackground(_colors.getColor(TraceColorScheme.BACKGROUND));\r | |
928 | drawBackground(gc, bound.x, bound.y, bound.width, bound.height);\r | |
b0d3496e ASL |
929 | \r |
930 | if (bound.width < 2 || bound.height < 2 || null == _timeProvider)\r | |
931 | return;\r | |
932 | \r | |
933 | _idealNameWidth = 0;\r | |
934 | int nameWidth = _timeProvider.getNameSpace();\r | |
935 | long time0 = _timeProvider.getTime0();\r | |
936 | long time1 = _timeProvider.getTime1();\r | |
937 | long endTime = _timeProvider.getEndTime();\r | |
938 | long selectedTime = _timeProvider.getSelectedTime();\r | |
939 | // draw trace states\r | |
940 | Object[] items = _data._items;\r | |
941 | for (int i = _topItem; i < items.length; i++) {\r | |
942 | Item item = (Item) items[i];\r | |
6b4f40e9 | 943 | \r |
b0d3496e ASL |
944 | getNameRect(_rect0, bound, i, nameWidth);\r |
945 | if (_rect0.y >= bound.y + bound.height)\r | |
946 | break;\r | |
947 | \r | |
948 | if (item instanceof GroupItem) {\r | |
949 | getStatesRect(_rect1, bound, i, nameWidth);\r | |
950 | _rect0.width += _rect1.width;\r | |
951 | drawName(item, _rect0, gc);\r | |
952 | } else {\r | |
953 | drawName(item, _rect0, gc);\r | |
954 | }\r | |
955 | getStatesRect(_rect0, bound, i, nameWidth);\r | |
956 | drawItemDataDurations(item, _rect0, time0, time1, endTime,\r | |
957 | selectedTime, gc);\r | |
958 | }\r | |
959 | \r | |
960 | if (drawTracesInteraction)\r | |
961 | drawTraceInteractions(bound, e.gc);\r | |
962 | \r | |
963 | // draw drag line, no line if name space is 0.\r | |
964 | if (3 == _dragState) {\r | |
965 | gc.setForeground(_colors.getColor(TraceColorScheme.BLACK));\r | |
966 | gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth,\r | |
967 | bound.y + bound.height - 1);\r | |
968 | } else if (0 == _dragState && _mouseHover\r | |
969 | && _timeProvider.getNameSpace() > 0) {\r | |
970 | gc.setForeground(_colors.getColor(TraceColorScheme.RED));\r | |
971 | gc.drawLine(bound.x + nameWidth, bound.y, bound.x + nameWidth,\r | |
972 | bound.y + bound.height - 1);\r | |
973 | }\r | |
974 | }\r | |
975 | \r | |
976 | void drawName(Item item, Rectangle rect, GC gc) {\r | |
977 | // No name to be drawn\r | |
978 | if (_timeProvider.getNameSpace() == 0)\r | |
979 | return;\r | |
980 | boolean group = item instanceof GroupItem;\r | |
981 | \r | |
982 | int elemHeight = rect.height / 2;\r | |
983 | int elemWidth = elemHeight;\r | |
984 | String name = item._name;\r | |
985 | if (group) {\r | |
986 | gc.setBackground(_colors\r | |
987 | .getBkColorGroup(item._selected, _isInFocus));\r | |
988 | gc.fillRectangle(rect);\r | |
989 | if (item._selected && _isInFocus) {\r | |
990 | gc.setForeground(_colors.getBkColor(item._selected, _isInFocus,\r | |
991 | false));\r | |
992 | gc.drawRectangle(rect.x, rect.y, rect.width - 2,\r | |
993 | rect.height - 2);\r | |
994 | }\r | |
995 | gc.setForeground(_colors.getBkColor(false, false, false));\r | |
996 | gc.drawLine(rect.x, rect.y + rect.height - 1, rect.width - 1,\r | |
997 | rect.y + rect.height - 1);\r | |
998 | gc.setForeground(_colors.getFgColorGroup(false, false));\r | |
999 | gc.setBackground(_colors.getBkColor(false, false, false));\r | |
1000 | Utils.init(_rect1, rect);\r | |
1001 | _rect1.x += MARGIN;\r | |
1002 | _rect1.y += (rect.height - elemHeight) / 2;\r | |
1003 | _rect1.width = elemWidth;\r | |
1004 | _rect1.height = elemHeight;\r | |
1005 | // Get the icon rectangle in the group items\r | |
1006 | gc.fillRectangle(_rect1);\r | |
1007 | gc.drawRectangle(_rect1.x, _rect1.y, _rect1.width - 1,\r | |
1008 | _rect1.height - 1);\r | |
1009 | int p = _rect1.y + _rect1.height / 2;\r | |
1010 | gc.drawLine(_rect1.x + 2, p, _rect1.x + _rect1.width - 3, p);\r | |
1011 | if (!item._expanded) {\r | |
1012 | p = _rect1.x + _rect1.width / 2;\r | |
1013 | gc.drawLine(p, _rect1.y + 2, p, _rect1.y + _rect1.height - 3);\r | |
1014 | }\r | |
1015 | gc.setForeground(_colors\r | |
1016 | .getFgColorGroup(item._selected, _isInFocus));\r | |
1017 | elemWidth += MARGIN;\r | |
1018 | } else {\r | |
1019 | gc.setBackground(_colors.getBkColor(item._selected, _isInFocus,\r | |
1020 | true));\r | |
1021 | gc.setForeground(_colors.getFgColor(item._selected, _isInFocus));\r | |
1022 | gc.fillRectangle(rect);\r | |
1023 | Utils.init(_rect1, rect);\r | |
1024 | _rect1.x += MARGIN;\r | |
1025 | // draw icon\r | |
1026 | ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace;\r | |
1027 | Image img = utilImpl.getItemImage(trace);\r | |
1028 | if (null != img) {\r | |
1029 | _rect1.y += (rect.height - img.getImageData().height) / 2;\r | |
1030 | gc.drawImage(img, _rect1.x, _rect1.y);\r | |
1031 | }\r | |
1032 | elemWidth = SMALL_ICON_SIZE;\r | |
1033 | // cut long string with "..."\r | |
1034 | Point size = gc.stringExtent(name);\r | |
1035 | if (_idealNameWidth < size.x)\r | |
1036 | _idealNameWidth = size.x;\r | |
1037 | int width = rect.width - MARGIN - MARGIN - elemWidth;\r | |
1038 | int cuts = 0;\r | |
1039 | while (size.x > width && name.length() > 1) {\r | |
1040 | cuts++;\r | |
1041 | name = name.substring(0, name.length() - 1);\r | |
1042 | size = gc.stringExtent(name + "...");\r | |
1043 | }\r | |
1044 | if (cuts > 0)\r | |
1045 | name += "...";\r | |
1046 | elemWidth += MARGIN;\r | |
1047 | }\r | |
1048 | Utils.init(_rect1, rect);\r | |
1049 | int leftMargin = MARGIN + elemWidth;\r | |
1050 | _rect1.x += leftMargin;\r | |
1051 | _rect1.width -= leftMargin;\r | |
1052 | int textWidth = 0;\r | |
1053 | // draw text\r | |
1054 | if (_rect1.width > 0) {\r | |
1055 | _rect1.y += 2;\r | |
1056 | textWidth = Utils.drawText(gc, name, _rect1, true) + 8;\r | |
1057 | _rect1.y -= 2;\r | |
1058 | }\r | |
1059 | // draw middle line\r | |
1060 | if (_rect1.width > 0 && !group) {\r | |
1061 | Utils.init(_rect1, rect);\r | |
1062 | _rect1.x += leftMargin + textWidth;\r | |
1063 | _rect1.width -= textWidth;\r | |
1064 | gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE));\r | |
1065 | int midy = _rect1.y + _rect1.height / 2;\r | |
1066 | gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);\r | |
1067 | }\r | |
1068 | // gc.drawLine(_rect1.x + _rect1.width - 1, _rect1.y, _rect1.x +\r | |
1069 | // _rect1.width - 1, _rect1.y + _rect1.height);\r | |
1070 | }\r | |
1071 | \r | |
1072 | void drawItemData(Item item, Rectangle rect, long time0, long time1,\r | |
1073 | long endTime, long selectedTime, GC gc) {\r | |
1074 | if (rect.isEmpty())\r | |
1075 | return;\r | |
1076 | if (time1 <= time0) {\r | |
1077 | gc.setBackground(_colors.getBkColor(false, false, false));\r | |
1078 | gc.fillRectangle(rect);\r | |
1079 | return;\r | |
1080 | }\r | |
1081 | \r | |
1082 | Utils.init(_rect1, rect);\r | |
1083 | boolean selected = item._selected;\r | |
8b9fa226 ASL |
1084 | double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0\r |
1085 | : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0);\r | |
b0d3496e ASL |
1086 | boolean group = item instanceof GroupItem;\r |
1087 | \r | |
1088 | if (group) {\r | |
1089 | // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus));\r | |
1090 | // gc.fillRectangle(rect);\r | |
1091 | } else if (item instanceof TraceItem) {\r | |
1092 | ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace;\r | |
1093 | \r | |
1094 | int x0 = rect.x;\r | |
1095 | List<TimeEvent> list = trace.getTraceEvents();\r | |
1096 | // Iterator it = list.iterator();\r | |
1097 | int count = list.size();\r | |
1098 | ITimeEvent lastEvent = null;\r | |
1099 | if (count > 0) {\r | |
1100 | ITimeEvent currEvent = list.get(0);\r | |
1101 | ITimeEvent nextEvent = null;\r | |
1102 | long currEventTime = currEvent.getTime();\r | |
1103 | long nextEventTime = currEventTime;\r | |
a5823d5f ASL |
1104 | x0 = rect.x + (int) ((currEventTime - time0) * pixelsPerNanoSec);\r |
1105 | int xEnd = rect.x + (int) ((time1 - time0) * pixelsPerNanoSec);\r | |
b0d3496e ASL |
1106 | int x1 = -1;\r |
1107 | int idx = 1;\r | |
1108 | \r | |
1109 | // reduce rect\r | |
1110 | _rect1.y += 3;\r | |
1111 | _rect1.height -= 6;\r | |
1112 | fillSpace(rect, gc, selected, _rect1.x, x0, xEnd);\r | |
1113 | \r | |
1114 | // draw event states\r | |
1115 | while (x0 <= xEnd && null != currEvent) {\r | |
1116 | boolean stopped = false;// currEvent instanceof\r | |
1117 | // TsfTmTraceDeadEvent;\r | |
1118 | if (idx < count) {\r | |
1119 | nextEvent = list.get(idx);\r | |
1120 | nextEventTime = nextEvent.getTime();\r | |
1121 | idx++;\r | |
1122 | } else if (stopped) {\r | |
1123 | nextEvent = null;\r | |
1124 | nextEventTime = time1;\r | |
1125 | } else {\r | |
1126 | nextEvent = null;\r | |
1127 | nextEventTime = endTime;\r | |
1128 | }\r | |
a5823d5f | 1129 | x1 = rect.x + (int) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1130 | if (x1 >= rect.x) {\r |
1131 | _rect1.x = x0 >= rect.x ? x0 : rect.x;\r | |
1132 | _rect1.width = (x1 <= xEnd ? x1 : xEnd) - _rect1.x;\r | |
1133 | boolean timeSelected = currEventTime <= selectedTime\r | |
1134 | && selectedTime < nextEventTime;\r | |
1135 | // Trace.debug("Drawing rectangle: " + _rect1.x + ","\r | |
1136 | // + _rect1.y + "," + _rect1.height + ", "\r | |
1137 | // + _rect1.width + "-->"\r | |
1138 | // + ((int) _rect1.x + (int) _rect1.width));\r | |
1139 | utilImpl.drawState(_colors, currEvent, _rect1, gc,\r | |
1140 | selected, false, timeSelected);\r | |
1141 | }\r | |
1142 | lastEvent = currEvent;\r | |
1143 | currEvent = nextEvent;\r | |
1144 | currEventTime = nextEventTime;\r | |
1145 | x0 = x1;\r | |
1146 | }\r | |
1147 | }\r | |
1148 | \r | |
1149 | // fill space after last event\r | |
1150 | int xEnd = rect.x + rect.width;\r | |
1151 | if (x0 < xEnd) {\r | |
1152 | _rect1.x = x0 >= rect.x ? x0 : rect.x;\r | |
1153 | _rect1.width = xEnd - _rect1.x;\r | |
1154 | gc.setBackground(_colors\r | |
1155 | .getBkColor(selected, _isInFocus, false));\r | |
1156 | gc.fillRectangle(_rect1);\r | |
1157 | // draw middle line\r | |
1158 | gc.setForeground(_colors.getColor(utilImpl\r | |
1159 | .getEventColorVal(lastEvent)));\r | |
1160 | int midy = _rect1.y + _rect1.height / 2;\r | |
1161 | int lw = gc.getLineWidth();\r | |
1162 | gc.setLineWidth(2);\r | |
1163 | gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);\r | |
1164 | gc.setLineWidth(lw);\r | |
1165 | }\r | |
1166 | \r | |
1167 | // draw focus ares\r | |
1168 | Utils.init(_rect1, rect);\r | |
1169 | gc.setForeground(_colors.getBkColor(selected, _isInFocus, false));\r | |
1170 | int y = _rect1.y;\r | |
1171 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1172 | y++;\r | |
1173 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1174 | y++;\r | |
1175 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1176 | y = _rect1.y + _rect1.height - 1;\r | |
1177 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1178 | y--;\r | |
1179 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1180 | y--;\r | |
1181 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1182 | }\r | |
1183 | \r | |
1184 | // draw selected time\r | |
a5823d5f | 1185 | int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1186 | if (x >= rect.x && x < rect.x + rect.width) {\r |
1187 | gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r | |
1188 | if (group)\r | |
1189 | gc.drawLine(x, rect.y + rect.height - 1, x, rect.y\r | |
1190 | + rect.height);\r | |
1191 | else\r | |
1192 | gc.drawLine(x, rect.y, x, rect.y + rect.height);\r | |
1193 | }\r | |
1194 | }\r | |
1195 | \r | |
1196 | /**\r | |
1197 | * Represent the event in series of bursts rather than sequence of states\r | |
1198 | * \r | |
1199 | * @param item\r | |
1200 | * @param rect\r | |
1201 | * - The container rectangle to be colored to different states\r | |
1202 | * @param time0\r | |
1203 | * - Base time of all events\r | |
1204 | * @param time1\r | |
1205 | * - End time of all events\r | |
1206 | * @param endTime\r | |
1207 | * @param selectedTime\r | |
1208 | * @param gc\r | |
1209 | */\r | |
1210 | void drawItemDataBurst(Item item, Rectangle rect, long time0, long time1,\r | |
1211 | long endTime, long selectedTime, GC gc) {\r | |
1212 | if (rect.isEmpty())\r | |
1213 | return;\r | |
1214 | if (time1 <= time0) {\r | |
1215 | gc.setBackground(_colors.getBkColor(false, false, false));\r | |
1216 | gc.fillRectangle(rect);\r | |
1217 | return;\r | |
1218 | }\r | |
1219 | \r | |
1220 | // Initialize _rect1 to same values as enclosing rectangle rect\r | |
1221 | Utils.init(_rect1, rect);\r | |
1222 | boolean selected = item._selected;\r | |
1223 | // K pixels per second\r | |
8b9fa226 ASL |
1224 | double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0\r |
1225 | : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0);\r | |
b0d3496e ASL |
1226 | // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: "\r |
1227 | // + time0 + " time1:" + time1 + " endTime: " + endTime);\r | |
1228 | \r | |
1229 | boolean group = item instanceof GroupItem;\r | |
1230 | \r | |
1231 | if (group) {\r | |
1232 | // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus));\r | |
1233 | // gc.fillRectangle(rect);\r | |
1234 | // if (Trace.isDEBUG()) {\r | |
1235 | // Trace.debug("Group");\r | |
1236 | // }\r | |
1237 | } else if (item instanceof TraceItem) {\r | |
1238 | ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace;\r | |
1239 | \r | |
1240 | double x0 = rect.x;\r | |
1241 | List<TimeEvent> list = trace.getTraceEvents();\r | |
1242 | // Iterator it = list.iterator();\r | |
1243 | int count = list.size();\r | |
1244 | ITimeEvent lastEvent = null;\r | |
1245 | // Trace.debug("count is: " + count);\r | |
1246 | if (count > 0) {\r | |
1247 | ITimeEvent currEvent = list.get(0);\r | |
1248 | ITimeEvent nextEvent = null;\r | |
1249 | long currEventTime = currEvent.getTime();\r | |
1250 | long nextEventTime = currEventTime;\r | |
1251 | // x0 - Points to the beginning of the event being drawn\r | |
a5823d5f | 1252 | double step = (double) ((currEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1253 | x0 = rect.x + step;\r |
1254 | // xEnd - Points to the end of the events rectangle\r | |
a5823d5f | 1255 | double xEnd = rect.x + (double) ((time1 - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1256 | double x1 = -1;\r |
1257 | int idx = 1;\r | |
1258 | double xNext = 0;\r | |
1259 | \r | |
1260 | // Drawing rectangle is smaller than reserved space\r | |
1261 | _rect1.y += 3;\r | |
1262 | _rect1.height -= 6;\r | |
1263 | \r | |
1264 | // Clean up to empty line to draw on top\r | |
1265 | fillSpace(rect, gc, selected, _rect1.x, xEnd, xEnd);\r | |
1266 | // draw event states\r | |
1267 | while (x0 <= xEnd && null != currEvent) {\r | |
1268 | boolean stopped = false;// currEvent instanceof\r | |
1269 | // TsfTmTraceDeadEvent;\r | |
1270 | if (idx < count) {\r | |
1271 | nextEvent = list.get(idx);\r | |
1272 | nextEventTime = nextEvent.getTime();\r | |
1273 | idx++;\r | |
1274 | } else if (stopped) {\r | |
1275 | nextEvent = null;\r | |
1276 | nextEventTime = time1;\r | |
1277 | } else {\r | |
1278 | nextEvent = null;\r | |
1279 | nextEventTime = endTime;\r | |
1280 | // Trace\r | |
1281 | // .debug("nexEventTime is endTime: "\r | |
1282 | // + nextEventTime);\r | |
1283 | }\r | |
1284 | \r | |
1285 | // Draw it as a burst, one unit of width.\r | |
1286 | x1 = x0 + (int) 2;\r | |
1287 | if (x1 >= rect.x && x0 <= xEnd) {\r | |
1288 | // Fill with space until x0\r | |
1289 | _rect1.x = (int) (x0 >= rect.x ? x0 : rect.x);\r | |
1290 | _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - _rect1.x);\r | |
1291 | boolean timeSelected = currEventTime <= selectedTime\r | |
1292 | && selectedTime < nextEventTime;\r | |
1293 | utilImpl.drawState(_colors, currEvent, _rect1, gc,\r | |
1294 | selected, false, timeSelected);\r | |
1295 | // Trace.debug("Drawing rectangle: " + _rect1.x + ","\r | |
1296 | // + _rect1.y + "," + _rect1.height + ", "\r | |
1297 | // + _rect1.width + "-->"\r | |
1298 | // + ((int) _rect1.x + (int) _rect1.width));\r | |
1299 | // Advance rectangle to next start position and Fill\r | |
1300 | // with space until next event\r | |
1301 | _rect1.x += _rect1.width;\r | |
1302 | x0 = x1;\r | |
a5823d5f | 1303 | xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1304 | }\r |
1305 | // Fill space till next event\r | |
1306 | fillSpace(rect, gc, selected, x0, xNext, xEnd);\r | |
1307 | \r | |
1308 | lastEvent = currEvent;\r | |
1309 | currEvent = nextEvent;\r | |
1310 | currEventTime = nextEventTime;\r | |
1311 | // Move x0 to the beginning of next event\r | |
a5823d5f | 1312 | x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1313 | // Trace.debug("rect.x: " + rect.x + " + " +\r |
1314 | // "(nextEvenTime: "\r | |
1315 | // + nextEventTime + "- time0: " + time0 + ") * K: "\r | |
1316 | // + K + " = " + x0);\r | |
1317 | }\r | |
1318 | }\r | |
1319 | \r | |
1320 | // fill space after last event\r | |
1321 | int xEnd = rect.x + rect.width;\r | |
1322 | if (x0 < xEnd) {\r | |
1323 | // Trace.debug("Space after last event, x0: " + x0 + ", xEnd: "\r | |
1324 | // + xEnd);\r | |
1325 | _rect1.x = (int) (x0 >= rect.x ? x0 : rect.x);\r | |
1326 | _rect1.width = xEnd - _rect1.x;\r | |
1327 | gc.setBackground(_colors\r | |
1328 | .getBkColor(selected, _isInFocus, false));\r | |
1329 | gc.fillRectangle(_rect1);\r | |
1330 | // draw middle line\r | |
1331 | gc.setForeground(_colors.getColor(utilImpl\r | |
1332 | .getEventColorVal(lastEvent)));\r | |
1333 | int midy = _rect1.y + _rect1.height / 2;\r | |
1334 | int lw = gc.getLineWidth();\r | |
1335 | gc.setLineWidth(2);\r | |
1336 | gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);\r | |
1337 | gc.setLineWidth(lw);\r | |
1338 | }\r | |
1339 | \r | |
1340 | // draw focus area\r | |
1341 | Utils.init(_rect1, rect);\r | |
1342 | gc.setForeground(_colors.getBkColor(selected, _isInFocus, false));\r | |
1343 | int y = _rect1.y;\r | |
1344 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1345 | y++;\r | |
1346 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1347 | y++;\r | |
1348 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1349 | y = _rect1.y + _rect1.height - 1;\r | |
1350 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1351 | y--;\r | |
1352 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1353 | y--;\r | |
1354 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1355 | }\r | |
1356 | \r | |
1357 | // draw selected time\r | |
a5823d5f | 1358 | int x = rect.x + (int) ((selectedTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1359 | if (x >= rect.x && x < rect.x + rect.width) {\r |
1360 | gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r | |
1361 | if (group)\r | |
1362 | gc.drawLine(x, rect.y + rect.height - 1, x, rect.y\r | |
1363 | + rect.height);\r | |
1364 | else\r | |
1365 | gc.drawLine(x, rect.y, x, rect.y + rect.height);\r | |
1366 | }\r | |
1367 | }\r | |
1368 | \r | |
1369 | /**\r | |
1370 | * Represent the series of events with specified durations\r | |
1371 | * \r | |
1372 | * @param item\r | |
1373 | * @param rect\r | |
1374 | * - The container rectangle to be colored to different states\r | |
1375 | * @param time0\r | |
1376 | * - Base time of all events - start of visible window\r | |
1377 | * @param time1\r | |
1378 | * - End time of visible events - end time of visible window\r | |
1379 | * @param endTime\r | |
1380 | * - End time of all events - may not be visible in selected\r | |
1381 | * visible window\r | |
1382 | * @param selectedTime\r | |
1383 | * @param gc\r | |
1384 | */\r | |
1385 | void drawItemDataDurations(Item item, Rectangle rect, long time0,\r | |
1386 | long time1, long endTime, long selectedTime, GC gc) {\r | |
1387 | if (rect.isEmpty())\r | |
1388 | return;\r | |
1389 | if (time1 <= time0) {\r | |
1390 | gc.setBackground(_colors.getBkColor(false, false, false));\r | |
1391 | gc.fillRectangle(rect);\r | |
1392 | return;\r | |
1393 | }\r | |
1394 | \r | |
1395 | // Initialize _rect1 to same values as enclosing rectangle rect\r | |
1396 | Utils.init(_rect1, rect);\r | |
1397 | boolean selected = item._selected;\r | |
1398 | // K pixels per second\r | |
8b9fa226 ASL |
1399 | double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0\r |
1400 | : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0);\r | |
b0d3496e ASL |
1401 | // Trace.debug("Value of K: " + K + " width:" + rect.width + " time0: "\r |
1402 | // + time0 + " time1:" + time1 + " endTime: " + endTime);\r | |
1403 | \r | |
1404 | boolean group = item instanceof GroupItem;\r | |
1405 | \r | |
1406 | if (group) {\r | |
1407 | // gc.setBackground(_colors.getBkColorGroup(selected, _isInFocus));\r | |
1408 | // gc.fillRectangle(rect);\r | |
1409 | } else if (item instanceof TraceItem) {\r | |
1410 | ITmfTimeAnalysisEntry trace = ((TraceItem) item)._trace;\r | |
1411 | \r | |
1412 | double x0 = rect.x;\r | |
1413 | List<TimeEvent> list = trace.getTraceEvents();\r | |
1414 | // Iterator it = list.iterator();\r | |
1415 | int count = list.size();\r | |
a5823d5f | 1416 | // ITimeEvent lastEvent = null;\r |
b0d3496e ASL |
1417 | // if (Trace.isDEBUG()) {\r |
1418 | // Trace.debug("\n\t\t\tTrace: " + trace.getName()\r | |
1419 | // + utilImpl.getTraceClassName(trace));\r | |
1420 | // }\r | |
1421 | // Trace.debug("count is: " + count);\r | |
a5823d5f ASL |
1422 | // Drawing rectangle is smaller than reserved space\r |
1423 | _rect1.y += 3;\r | |
1424 | _rect1.height -= 6;\r | |
1425 | \r | |
1426 | // Clean up to empty line to draw on top\r | |
1427 | int xEnd = rect.x + rect.width;\r | |
1428 | fillSpace(rect, gc, selected, _rect1.x, xEnd, xEnd);\r | |
b0d3496e ASL |
1429 | if (count > 0) {\r |
1430 | ITimeEvent currEvent = list.get(0);\r | |
1431 | ITimeEvent nextEvent = null;\r | |
1432 | long currEventTime = currEvent.getTime();\r | |
1433 | long currEventDuration = currEvent.getDuration();\r | |
1434 | // initial value\r | |
1435 | long nextEventTime = currEventTime;\r | |
1436 | // x0 - Points to the beginning of the event being drawn\r | |
a5823d5f | 1437 | double step = (double) ((currEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1438 | x0 = rect.x + step;\r |
1439 | // xEnd - Points to the end of the events rectangle\r | |
1440 | double x1 = -1;\r | |
1441 | int idx = 1;\r | |
1442 | double xNext = 0;\r | |
1443 | \r | |
1444 | // draw event states\r | |
a5823d5f | 1445 | while (/* x0 <= xEnd &&*/ null != currEvent) {\r |
b0d3496e ASL |
1446 | boolean stopped = false;// currEvent instanceof\r |
1447 | // refresh current event duration as the loop moves\r | |
1448 | currEventDuration = currEvent.getDuration();\r | |
1449 | // TsfTmTraceDeadEvent;\r | |
1450 | if (idx < count) {\r | |
1451 | nextEvent = list.get(idx);\r | |
1452 | nextEventTime = nextEvent.getTime();\r | |
1453 | idx++;\r | |
1454 | } else if (stopped) {\r | |
1455 | nextEvent = null;\r | |
1456 | nextEventTime = time1;\r | |
1457 | } else {\r | |
1458 | nextEvent = null;\r | |
1459 | nextEventTime = endTime;\r | |
1460 | // Trace\r | |
1461 | // .debug("nexEventTime is endTime: "\r | |
1462 | // + nextEventTime);\r | |
1463 | }\r | |
1464 | \r | |
1465 | // Calculate position to next event\r | |
a5823d5f | 1466 | xNext = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1467 | \r |
1468 | // Calculate end position of current event\r | |
1469 | if (currEventDuration < 0) {\r | |
a5823d5f ASL |
1470 | x1 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
1471 | } else if (currEventDuration == 0) {\r | |
1472 | x1 = x0;\r | |
b0d3496e | 1473 | } else {\r |
a5823d5f | 1474 | x1 = x0 + (double) ((currEventDuration) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1475 | }\r |
1476 | \r | |
1477 | // If event end position x1 further away than start position\r | |
1478 | // of\r | |
1479 | // next event, cut width till next event\r | |
1480 | // Trace.debug("Next Event Pos: " + xNext\r | |
1481 | // + " End Of Current at: " + x1 + " Event Duration: "\r | |
1482 | // + currEventDuration);\r | |
a5823d5f ASL |
1483 | if (currEventDuration != 0) {\r |
1484 | x1 = x1 > xNext ? xNext : x1;\r | |
1485 | }\r | |
b0d3496e ASL |
1486 | // if event end boundary is within time range\r |
1487 | if (x1 >= rect.x && x0 <= xEnd) {\r | |
a5823d5f ASL |
1488 | if (currEventDuration != 0) {\r |
1489 | x0 = (double) (x0 >= rect.x ? x0 : rect.x);\r | |
8b9fa226 | 1490 | _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0);\r |
a5823d5f | 1491 | } else {\r |
8b9fa226 | 1492 | _rect1.width = 2; // make punctual events 2 pixels wide\r |
a5823d5f | 1493 | }\r |
b0d3496e ASL |
1494 | _rect1.x = (int) x0;\r |
1495 | boolean timeSelected = currEventTime <= selectedTime\r | |
1496 | && selectedTime < nextEventTime;\r | |
1497 | utilImpl.drawState(_colors, currEvent, _rect1, gc,\r | |
1498 | selected, false, timeSelected);\r | |
1499 | // Trace.debug("Drawing rectangle: " + _rect1.x + ","\r | |
1500 | // + _rect1.y + "," + _rect1.height + ", "\r | |
1501 | // + _rect1.width + "-->"\r | |
1502 | // + ((int) _rect1.x + (int) _rect1.width));\r | |
1503 | // Advance rectangle to next start position and Fill\r | |
1504 | // with space until next event\r | |
1505 | _rect1.x += _rect1.width;\r | |
1506 | x0 = _rect1.x;\r | |
1507 | }\r | |
1508 | \r | |
1509 | // Fill space till next event\r | |
a5823d5f | 1510 | // fillSpace(rect, gc, selected, x0, xNext, xEnd);\r |
b0d3496e | 1511 | \r |
a5823d5f | 1512 | // lastEvent = currEvent;\r |
b0d3496e ASL |
1513 | currEvent = nextEvent;\r |
1514 | currEventTime = nextEventTime;\r | |
1515 | // Move x0 to the beginning of next event\r | |
a5823d5f | 1516 | x0 = rect.x + (double) ((nextEventTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1517 | // Trace.debug("rect.x: " + rect.x + " + " +\r |
1518 | // "(nextEvenTime: "\r | |
1519 | // + nextEventTime + "- time0: " + time0 + ") * K: "\r | |
1520 | // + K + " = " + x0);\r | |
1521 | }\r | |
1522 | }\r | |
1523 | \r | |
1524 | // draw focus area\r | |
1525 | Utils.init(_rect1, rect);\r | |
1526 | gc.setForeground(_colors.getBkColor(selected, _isInFocus, false));\r | |
1527 | int y = _rect1.y;\r | |
1528 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1529 | y++;\r | |
1530 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1531 | y++;\r | |
1532 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1533 | y = _rect1.y + _rect1.height - 1;\r | |
1534 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1535 | y--;\r | |
1536 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1537 | y--;\r | |
1538 | gc.drawLine(_rect1.x, y, _rect1.x + _rect1.width, y);\r | |
1539 | }\r | |
1540 | \r | |
1541 | // draw selected time\r | |
a5823d5f | 1542 | int x = rect.x + (int) ((double) (selectedTime - time0) * pixelsPerNanoSec);\r |
b0d3496e ASL |
1543 | if (x >= rect.x && x < rect.x + rect.width) {\r |
1544 | gc.setForeground(_colors.getColor(TraceColorScheme.SELECTED_TIME));\r | |
1545 | if (group)\r | |
1546 | gc.drawLine(x, rect.y + rect.height - 1, x, rect.y\r | |
1547 | + rect.height);\r | |
1548 | else\r | |
1549 | gc.drawLine(x, rect.y, x, rect.y + rect.height);\r | |
1550 | }\r | |
1551 | }\r | |
1552 | \r | |
1553 | private void fillSpace(Rectangle rect, GC gc, boolean selected, double x0,\r | |
1554 | double x1, double xEnd) {\r | |
1555 | // fill space before first event\r | |
1556 | if (x0 >= rect.x && x0 < xEnd) {\r | |
1557 | // _rect1.width = (int) ((x1 <= xEnd ? x1 : xEnd) - x0);\r | |
1558 | // Trace.debug("Drawing Space: " + _rect1.x + "," + _rect1.y + ","\r | |
1559 | // + _rect1.height + ", " + _rect1.width + "--> "\r | |
1560 | // + ((int) _rect1.x + (int) _rect1.width));\r | |
1561 | \r | |
1562 | // if (_rect1.width < 0) {\r | |
1563 | // Trace.debug("Incorrect width:" + _rect1.width);\r | |
1564 | // }\r | |
1565 | gc.setBackground(_colors.getBkColor(selected, _isInFocus, false));\r | |
1566 | gc.fillRectangle(_rect1);\r | |
1567 | // draw middle line\r | |
1568 | gc.setForeground(_colors.getColor(TraceColorScheme.MID_LINE));\r | |
1569 | int midy = _rect1.y + _rect1.height / 2;\r | |
1570 | gc.drawLine(_rect1.x, midy, _rect1.x + _rect1.width, midy);\r | |
1571 | } else {\r | |
1572 | // Trace.debug("No space added since, x0 is out of range " + x0\r | |
1573 | // + " rect.x: " + rect.x + " xEnd: " + xEnd);\r | |
1574 | }\r | |
1575 | }\r | |
1576 | \r | |
d4011df2 | 1577 | @Override\r |
b0d3496e ASL |
1578 | public void keyTraversed(TraverseEvent e) {\r |
1579 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT)\r | |
1580 | || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS))\r | |
1581 | e.doit = true;\r | |
1582 | }\r | |
1583 | \r | |
d4011df2 | 1584 | @Override\r |
b0d3496e ASL |
1585 | public void keyPressed(KeyEvent e) {\r |
1586 | int idx = -1;\r | |
1587 | if (SWT.HOME == e.keyCode) {\r | |
1588 | idx = getTopIndex();\r | |
1589 | } else if (SWT.END == e.keyCode) {\r | |
1590 | idx = getBottomIndex();\r | |
1591 | } else if (SWT.ARROW_DOWN == e.keyCode) {\r | |
1592 | idx = getSelectedIndex();\r | |
1593 | if (idx < 0)\r | |
1594 | idx = 0;\r | |
1595 | else if (idx < _data._items.length - 1)\r | |
1596 | idx++;\r | |
1597 | } else if (SWT.ARROW_UP == e.keyCode) {\r | |
1598 | idx = getSelectedIndex();\r | |
1599 | if (idx < 0)\r | |
1600 | idx = 0;\r | |
1601 | else if (idx > 0)\r | |
1602 | idx--;\r | |
1603 | } else if (SWT.ARROW_LEFT == e.keyCode) {\r | |
1604 | selectPrevEvent();\r | |
1605 | } else if (SWT.ARROW_RIGHT == e.keyCode) {\r | |
1606 | selectNextEvent();\r | |
1607 | } else if (SWT.PAGE_DOWN == e.keyCode) {\r | |
1608 | int page = countPerPage();\r | |
1609 | idx = getSelectedIndex();\r | |
1610 | if (idx < 0)\r | |
1611 | idx = 0;\r | |
1612 | idx += page;\r | |
1613 | if (idx >= _data._items.length)\r | |
1614 | idx = _data._items.length - 1;\r | |
1615 | } else if (SWT.PAGE_UP == e.keyCode) {\r | |
1616 | int page = countPerPage();\r | |
1617 | idx = getSelectedIndex();\r | |
1618 | if (idx < 0)\r | |
1619 | idx = 0;\r | |
1620 | idx -= page;\r | |
1621 | if (idx < 0)\r | |
1622 | idx = 0;\r | |
1623 | } else if (SWT.CR == e.keyCode) {\r | |
1624 | idx = getSelectedIndex();\r | |
1625 | if (idx >= 0) {\r | |
1626 | if (_data._items[idx] instanceof TraceItem)\r | |
1627 | fireDefaultSelection();\r | |
1628 | else if (_data._items[idx] instanceof GroupItem)\r | |
1629 | toggle(idx);\r | |
1630 | }\r | |
1631 | idx = -1;\r | |
1632 | }\r | |
1633 | if (idx >= 0) {\r | |
1634 | selectItem(idx, false);\r | |
1635 | fireSelectionChanged();\r | |
1636 | }\r | |
1637 | }\r | |
1638 | \r | |
d4011df2 | 1639 | @Override\r |
b0d3496e ASL |
1640 | public void keyReleased(KeyEvent e) {\r |
1641 | }\r | |
1642 | \r | |
d4011df2 | 1643 | @Override\r |
b0d3496e ASL |
1644 | public void focusGained(FocusEvent e) {\r |
1645 | _isInFocus = true;\r | |
1646 | redraw();\r | |
a5823d5f | 1647 | getDisplay().addFilter(SWT.MouseWheel, mouseScrollFilterListener);\r |
b0d3496e ASL |
1648 | }\r |
1649 | \r | |
d4011df2 | 1650 | @Override\r |
b0d3496e ASL |
1651 | public void focusLost(FocusEvent e) {\r |
1652 | _isInFocus = false;\r | |
1653 | if (0 != _dragState) {\r | |
1654 | setCapture(false);\r | |
1655 | _dragState = 0;\r | |
1656 | }\r | |
1657 | redraw();\r | |
a5823d5f | 1658 | getDisplay().removeFilter(SWT.MouseWheel, mouseScrollFilterListener);\r |
b0d3496e ASL |
1659 | }\r |
1660 | \r | |
1661 | public boolean isInFocus() {\r | |
1662 | return _isInFocus;\r | |
1663 | }\r | |
1664 | \r | |
d4011df2 | 1665 | @Override\r |
b0d3496e ASL |
1666 | public void mouseMove(MouseEvent e) {\r |
1667 | if (null == _timeProvider)\r | |
1668 | return;\r | |
1669 | Point size = getCtrlSize();\r | |
1670 | if (1 == _dragState) {\r | |
1671 | int nameWidth = _timeProvider.getNameSpace();\r | |
1672 | int x = e.x - nameWidth;\r | |
1673 | if (x > 0 && size.x > nameWidth && _dragX != x) {\r | |
1674 | _dragX = x;\r | |
8b9fa226 ASL |
1675 | double pixelsPerNanoSec = (size.x - nameWidth <= RIGHT_MARGIN) ? 0\r |
1676 | : (double) (size.x - nameWidth - RIGHT_MARGIN) / (_time1bak - _time0bak);\r | |
a5823d5f | 1677 | long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec));\r |
b0d3496e ASL |
1678 | long time1 = _time1bak - timeDelta;\r |
1679 | long maxTime = _timeProvider.getMaxTime();\r | |
1680 | if (time1 > maxTime)\r | |
1681 | time1 = maxTime;\r | |
1682 | long time0 = time1 - (_time1bak - _time0bak);\r | |
1683 | if (time0 < _timeProvider.getMinTime()) {\r | |
1684 | time0 = _timeProvider.getMinTime();\r | |
1685 | time1 = time0 + (_time1bak - _time0bak);\r | |
1686 | }\r | |
1687 | _timeProvider.setStartFinishTime(time0, time1);\r | |
1688 | }\r | |
1689 | } else if (3 == _dragState) {\r | |
1690 | _dragX = e.x;\r | |
1691 | _timeProvider.setNameSpace(_hitIdx + _dragX - _dragX0);\r | |
1692 | } else if (0 == _dragState) {\r | |
1693 | boolean mouseHover = hitSplitTest(e.x, e.y) > 0;\r | |
1694 | if (_mouseHover != mouseHover)\r | |
1695 | redraw();\r | |
1696 | _mouseHover = mouseHover;\r | |
a5823d5f ASL |
1697 | // Make sure any time changes are notified to the application e.g.\r |
1698 | // getting back from the horizontal scroll bar or zoomed using the\r | |
1699 | // mouse wheel\r | |
8b9fa226 | 1700 | _timeProvider.notifyStartFinishTime();\r |
b0d3496e ASL |
1701 | }\r |
1702 | updateCursor(e.x, e.y);\r | |
1703 | }\r | |
1704 | \r | |
d4011df2 | 1705 | @Override\r |
b0d3496e ASL |
1706 | public void mouseDoubleClick(MouseEvent e) {\r |
1707 | if (null == _timeProvider)\r | |
1708 | return;\r | |
1709 | if (1 == e.button) {\r | |
1710 | int idx = hitSplitTest(e.x, e.y);\r | |
1711 | if (idx >= 0) {\r | |
1712 | _timeProvider.setNameSpace(_idealNameWidth + 3 * MARGIN\r | |
1713 | + SMALL_ICON_SIZE);\r | |
1714 | return;\r | |
1715 | }\r | |
1716 | idx = hitTest(e.x, e.y);\r | |
1717 | if (idx >= 0) {\r | |
1718 | selectItem(idx, false);\r | |
1719 | if (_data._items[idx] instanceof TraceItem) {\r | |
1720 | fireDefaultSelection();\r | |
1721 | }\r | |
1722 | }\r | |
1723 | }\r | |
1724 | }\r | |
1725 | \r | |
41dc35d0 FC |
1726 | /**\r |
1727 | * <p>\r | |
1728 | * If the x, y position is over the vertical split line (name to time\r | |
1729 | * ranges), then change the cursor to a drag cursor to indicate the user the\r | |
1730 | * possibility of resizing\r | |
1731 | * </p>\r | |
1732 | * \r | |
1733 | * @param x\r | |
1734 | * @param y\r | |
1735 | */\r | |
b0d3496e | 1736 | void updateCursor(int x, int y) {\r |
41dc35d0 FC |
1737 | // if Wait cursor not active, check for the need to change to a drag\r |
1738 | // cursor\r | |
1739 | if (_isWaitCursor == false) {\r | |
1740 | int idx = hitSplitTest(x, y);\r | |
1741 | // No dragcursor is name space is fixed to zero\r | |
1742 | if (idx > 0 && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) {\r | |
1743 | setCursor(_dragCursor3);\r | |
1744 | _isDragCursor3 = true;\r | |
1745 | } else if (idx <= 0 && _isDragCursor3) {\r | |
1746 | setCursor(null);\r | |
1747 | _isDragCursor3 = false;\r | |
1748 | }\r | |
1749 | }\r | |
1750 | }\r | |
1751 | \r | |
1752 | /**\r | |
1753 | * Provide the possibilty to control the wait cursor externally e.g. data\r | |
1754 | * requests in progress\r | |
1755 | * \r | |
1756 | * @param waitInd\r | |
1757 | */\r | |
1758 | public void waitCursor(boolean waitInd) {\r | |
1759 | // Update cursor as indicated\r | |
1760 | if (waitInd) {\r | |
1761 | setCursor(_WaitCursor);\r | |
1762 | _isWaitCursor = true;\r | |
1763 | } else {\r | |
b0d3496e | 1764 | setCursor(null);\r |
41dc35d0 | 1765 | _isWaitCursor = false;\r |
b0d3496e | 1766 | }\r |
41dc35d0 FC |
1767 | \r |
1768 | // Get ready for next mouse move\r | |
1769 | _isDragCursor3 = false;\r | |
b0d3496e ASL |
1770 | }\r |
1771 | \r | |
d4011df2 | 1772 | @Override\r |
b0d3496e ASL |
1773 | public void mouseDown(MouseEvent e) {\r |
1774 | if (null == _timeProvider)\r | |
1775 | return;\r | |
1776 | int idx;\r | |
1777 | if (1 == e.button) {\r | |
1778 | int namewidth = _timeProvider.getNameSpace();\r | |
1779 | if (namewidth != 0) {\r | |
1780 | idx = hitSplitTest(e.x, e.y);\r | |
1781 | if (idx > 0) {\r | |
1782 | _dragState = 3;\r | |
1783 | _dragX = _dragX0 = e.x;\r | |
1784 | _hitIdx = _timeProvider.getNameSpace();\r | |
1785 | ;\r | |
1786 | _time0bak = _timeProvider.getTime0();\r | |
1787 | _time1bak = _timeProvider.getTime1();\r | |
1788 | redraw();\r | |
1789 | return;\r | |
1790 | }\r | |
1791 | }\r | |
1792 | \r | |
1793 | idx = hitTest(e.x, e.y);\r | |
1794 | if (idx >= 0) {\r | |
1795 | if (_data._items[idx] instanceof TraceItem) {\r | |
1796 | long hitTime = hitTimeTest(e.x, e.y);\r | |
1797 | if (hitTime >= 0) {\r | |
1798 | _timeProvider.setSelectedTimeInt(hitTime, false);\r | |
1799 | setCapture(true);\r | |
1800 | _dragState = 1;\r | |
1801 | _dragX = _dragX0 = e.x - _timeProvider.getNameSpace();\r | |
1802 | _time0bak = _timeProvider.getTime0();\r | |
1803 | _time1bak = _timeProvider.getTime1();\r | |
1804 | }\r | |
1805 | } else if (_data._items[idx] instanceof GroupItem) {\r | |
1806 | _hitIdx = idx;\r | |
1807 | _dragState = 2;\r | |
1808 | }\r | |
1809 | selectItem(idx, false);\r | |
1810 | fireSelectionChanged();\r | |
a5823d5f ASL |
1811 | } else {\r |
1812 | selectItem(idx, false); // clear selection\r | |
b0d3496e ASL |
1813 | }\r |
1814 | }\r | |
1815 | }\r | |
1816 | \r | |
d4011df2 | 1817 | @Override\r |
b0d3496e ASL |
1818 | public void mouseUp(MouseEvent e) {\r |
1819 | if (0 != _dragState) {\r | |
1820 | setCapture(false);\r | |
8b9fa226 ASL |
1821 | if (1 == _dragState) {\r |
1822 | // Notify time provider to check the need for listener notification\r | |
1823 | _timeProvider.notifyStartFinishTime();\r | |
1824 | } else if (2 == _dragState) {\r | |
b0d3496e ASL |
1825 | if (hitTest(e.x, e.y) == _hitIdx)\r |
1826 | toggle(_hitIdx);\r | |
1827 | } else if (3 == _dragState) {\r | |
1828 | redraw();\r | |
1829 | }\r | |
1830 | _dragState = 0;\r | |
1831 | }\r | |
1832 | }\r | |
1833 | \r | |
d4011df2 | 1834 | @Override\r |
b0d3496e ASL |
1835 | public void controlMoved(ControlEvent e) {\r |
1836 | }\r | |
1837 | \r | |
d4011df2 | 1838 | @Override\r |
b0d3496e ASL |
1839 | public void controlResized(ControlEvent e) {\r |
1840 | adjustScrolls();\r | |
1841 | }\r | |
1842 | \r | |
d4011df2 | 1843 | @Override\r |
b0d3496e ASL |
1844 | public void widgetDefaultSelected(SelectionEvent e) {\r |
1845 | }\r | |
1846 | \r | |
d4011df2 | 1847 | @Override\r |
b0d3496e ASL |
1848 | public void widgetSelected(SelectionEvent e) {\r |
1849 | if (e.widget == getVerticalBar()) {\r | |
1850 | _topItem = getVerticalBar().getSelection();\r | |
1851 | if (_topItem < 0)\r | |
1852 | _topItem = 0;\r | |
1853 | redraw();\r | |
1854 | } else if (e.widget == getHorizontalBar() && null != _timeProvider) {\r | |
a5823d5f | 1855 | int start = getHorizontalBar().getSelection();\r |
b0d3496e ASL |
1856 | long time0 = _timeProvider.getTime0();\r |
1857 | long time1 = _timeProvider.getTime1();\r | |
1858 | long timeMin = _timeProvider.getMinTime();\r | |
1859 | long timeMax = _timeProvider.getMaxTime();\r | |
1860 | long delta = timeMax - timeMin;\r | |
1861 | \r | |
1862 | long range = time1 - time0;\r | |
1863 | // _timeRangeFixed = true;\r | |
a5823d5f | 1864 | time0 = timeMin + (long) (delta * ((double) start / H_SCROLLBAR_MAX));\r |
b0d3496e | 1865 | time1 = time0 + range;\r |
a5823d5f ASL |
1866 | \r |
1867 | // TODO: Follow-up with Bug 310310\r | |
1868 | // In Linux SWT.DRAG is the only value received\r | |
1869 | // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310\r | |
1870 | if (e.detail == SWT.DRAG) {\r | |
1871 | _timeProvider.setStartFinishTime(time0, time1);\r | |
1872 | } else {\r | |
1873 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r | |
1874 | }\r | |
b0d3496e ASL |
1875 | }\r |
1876 | }\r | |
1877 | \r | |
d4011df2 | 1878 | @Override\r |
b0d3496e ASL |
1879 | public void mouseEnter(MouseEvent e) {\r |
1880 | }\r | |
1881 | \r | |
d4011df2 | 1882 | @Override\r |
b0d3496e ASL |
1883 | public void mouseExit(MouseEvent e) {\r |
1884 | if (_mouseHover) {\r | |
1885 | _mouseHover = false;\r | |
1886 | redraw();\r | |
1887 | }\r | |
1888 | }\r | |
1889 | \r | |
d4011df2 | 1890 | @Override\r |
b0d3496e ASL |
1891 | public void mouseHover(MouseEvent e) {\r |
1892 | }\r | |
1893 | \r | |
d4011df2 | 1894 | @Override\r |
b0d3496e | 1895 | public void mouseScrolled(MouseEvent e) {\r |
a5823d5f ASL |
1896 | if (!_isInFocus)\r |
1897 | return;\r | |
b0d3496e | 1898 | if (e.count > 0) {\r |
a5823d5f | 1899 | zoom(true);\r |
b0d3496e | 1900 | } else if (e.count < 0) {\r |
a5823d5f | 1901 | zoom(false);\r |
b0d3496e ASL |
1902 | }\r |
1903 | }\r | |
1904 | \r | |
1905 | public boolean isVisibleVerticalScroll() {\r | |
1906 | return _visibleVerticalScroll;\r | |
1907 | }\r | |
1908 | \r | |
1909 | public void setVisibleVerticalScroll(boolean visibleVerticalScroll) {\r | |
1910 | ScrollBar scrollVer = getVerticalBar();\r | |
1911 | if (scrollVer != null) {\r | |
1912 | scrollVer.setVisible(visibleVerticalScroll);\r | |
1913 | }\r | |
1914 | this._visibleVerticalScroll = visibleVerticalScroll;\r | |
1915 | }\r | |
1916 | \r | |
4e3aa37d | 1917 | @Override\r |
b0d3496e ASL |
1918 | public int getBorderWidth() {\r |
1919 | return _borderWidth;\r | |
1920 | }\r | |
1921 | \r | |
1922 | public void setBorderWidth(int borderWidth) {\r | |
1923 | this._borderWidth = borderWidth;\r | |
1924 | }\r | |
1925 | \r | |
1926 | public int getHeaderHeight() {\r | |
1927 | return _headerHeight;\r | |
1928 | }\r | |
1929 | \r | |
1930 | public void setHeaderHeight(int headerHeight) {\r | |
1931 | this._headerHeight = headerHeight;\r | |
1932 | }\r | |
1933 | \r | |
1934 | public int getItemHeight() {\r | |
1935 | return _itemHeight;\r | |
1936 | }\r | |
1937 | \r | |
1938 | public void setItemHeight(int rowHeight) {\r | |
1939 | this._itemHeight = rowHeight;\r | |
1940 | }\r | |
1941 | \r | |
1942 | public Vector<ITmfTimeAnalysisEntry> getFilteredOut() {\r | |
1943 | return _data.getFilteredOut();\r | |
1944 | }\r | |
1945 | \r | |
1946 | // @Override\r | |
d4011df2 | 1947 | @Override\r |
b0d3496e ASL |
1948 | public void addSelectionChangedListener(ISelectionChangedListener listener) {\r |
1949 | if (listener != null) {\r | |
1950 | if (!_selectionChangedListeners.contains(listener)) {\r | |
1951 | _selectionChangedListeners.add(listener);\r | |
1952 | }\r | |
1953 | }\r | |
1954 | }\r | |
1955 | \r | |
1956 | // @Override\r | |
d4011df2 | 1957 | @Override\r |
b0d3496e ASL |
1958 | public void removeSelectionChangedListener(\r |
1959 | ISelectionChangedListener listener) {\r | |
1960 | if (listener != null) {\r | |
1961 | _selectionChangedListeners.remove(listener);\r | |
1962 | }\r | |
1963 | }\r | |
1964 | \r | |
1965 | // @Override\r | |
d4011df2 | 1966 | @Override\r |
b0d3496e ASL |
1967 | public void setSelection(ISelection selection) {\r |
1968 | if (selection instanceof PlainSelection) {\r | |
1969 | PlainSelection sel = (PlainSelection) selection;\r | |
1970 | Object ob = sel.getFirstElement();\r | |
1971 | if (ob instanceof ITmfTimeAnalysisEntry) {\r | |
1972 | ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) ob;\r | |
1973 | selectItem(trace, false);\r | |
1974 | }\r | |
1975 | }\r | |
1976 | \r | |
1977 | }\r | |
1978 | }\r | |
1979 | \r | |
1980 | class Item {\r | |
1981 | public boolean _expanded;\r | |
1982 | public boolean _selected;\r | |
1983 | public boolean _hasChildren;\r | |
1984 | public String _name;\r | |
1985 | \r | |
1986 | Item(String name) {\r | |
1987 | _name = name;\r | |
1988 | }\r | |
1989 | \r | |
4e3aa37d | 1990 | @Override\r |
b0d3496e ASL |
1991 | public String toString() {\r |
1992 | return _name;\r | |
1993 | }\r | |
1994 | }\r | |
1995 | \r | |
1996 | class TraceItem extends Item {\r | |
1997 | public ITmfTimeAnalysisEntry _trace;\r | |
1998 | \r | |
1999 | TraceItem(ITmfTimeAnalysisEntry trace, String name) {\r | |
2000 | super(name);\r | |
2001 | _trace = trace;\r | |
2002 | }\r | |
2003 | }\r | |
2004 | \r | |
2005 | class GroupItem extends Item {\r | |
2006 | public List<ITmfTimeAnalysisEntry> _traces;\r | |
2007 | \r | |
2008 | GroupItem(String name) {\r | |
2009 | super(name);\r | |
2010 | _traces = new ArrayList<ITmfTimeAnalysisEntry>();\r | |
2011 | _hasChildren = true;\r | |
2012 | }\r | |
2013 | \r | |
2014 | void add(ITmfTimeAnalysisEntry trace) {\r | |
2015 | _traces.add(trace);\r | |
2016 | }\r | |
2017 | }\r | |
2018 | \r | |
2019 | class ItemData {\r | |
2020 | public Object[] _items = new Object[0];\r | |
2021 | private Object _traces[] = new Object[0];\r | |
2022 | private boolean traceFilter[] = new boolean[0];\r | |
2023 | private Map<String, GroupItem> _groupTable = new HashMap<String, GroupItem>();\r | |
2024 | private boolean _flatList = false;\r | |
2025 | private TmfTimeAnalysisProvider utilsImp;\r | |
2026 | private Vector<ITmfTimeAnalysisEntry> filteredOut = new Vector<ITmfTimeAnalysisEntry>();\r | |
2027 | \r | |
2028 | public ItemData(TmfTimeAnalysisProvider utils) {\r | |
2029 | this.utilsImp = utils;\r | |
2030 | }\r | |
2031 | \r | |
2032 | protected void groupTraces(boolean on) {\r | |
2033 | if (_flatList == on) {\r | |
2034 | _flatList = !on;\r | |
2035 | updateItems();\r | |
2036 | }\r | |
2037 | }\r | |
2038 | \r | |
2039 | void clearGroups() {\r | |
2040 | Iterator<GroupItem> it = _groupTable.values().iterator();\r | |
2041 | while (it.hasNext()) {\r | |
2042 | GroupItem group = it.next();\r | |
2043 | group._traces.clear();\r | |
2044 | }\r | |
2045 | }\r | |
2046 | \r | |
2047 | void deleteEmptyGroups() {\r | |
2048 | Iterator<GroupItem> it = _groupTable.values().iterator();\r | |
2049 | while (it.hasNext()) {\r | |
2050 | GroupItem group = it.next();\r | |
2051 | if (group._traces.size() == 0)\r | |
2052 | it.remove();\r | |
2053 | }\r | |
2054 | }\r | |
2055 | \r | |
2056 | TraceItem findTraceItem(ITmfTimeAnalysisEntry trace) {\r | |
2057 | if (trace == null)\r | |
2058 | return null;\r | |
2059 | \r | |
2060 | int traceId = trace.getId();\r | |
2061 | TraceItem traceItem = null;\r | |
2062 | \r | |
2063 | for (int i = 0; i < _items.length; i++) {\r | |
2064 | Object item = _items[i];\r | |
2065 | if (item instanceof TraceItem) {\r | |
2066 | TraceItem ti = (TraceItem) item;\r | |
2067 | if (ti._trace.getId() == traceId) {\r | |
2068 | traceItem = ti;\r | |
2069 | break;\r | |
2070 | }\r | |
2071 | }\r | |
2072 | }\r | |
2073 | \r | |
2074 | return traceItem;\r | |
2075 | }\r | |
2076 | \r | |
2077 | Integer findTraceItemIndex(ITmfTimeAnalysisEntry trace) {\r | |
2078 | if (trace == null)\r | |
2079 | return null;\r | |
2080 | \r | |
2081 | int traceId = trace.getId();\r | |
2082 | \r | |
2083 | Integer idx = null;\r | |
2084 | for (int i = 0; i < _items.length; i++) {\r | |
2085 | idx = i;\r | |
2086 | Object item = _items[i];\r | |
2087 | if (item instanceof TraceItem) {\r | |
2088 | TraceItem ti = (TraceItem) item;\r | |
2089 | if (ti._trace.getId() == traceId) {\r | |
2090 | break;\r | |
2091 | }\r | |
2092 | }\r | |
2093 | }\r | |
2094 | \r | |
2095 | return idx;\r | |
2096 | }\r | |
2097 | \r | |
2098 | public void updateItems() {\r | |
2099 | List<Item> itemList = new ArrayList<Item>();\r | |
2100 | String name = "";\r | |
2101 | \r | |
2102 | Iterator<GroupItem> it = _groupTable.values().iterator();\r | |
2103 | while (it.hasNext()) {\r | |
2104 | GroupItem group = it.next();\r | |
2105 | if (!_flatList)\r | |
2106 | itemList.add(group);\r | |
2107 | \r | |
2108 | if (_flatList || group._expanded) {\r | |
2109 | Iterator<ITmfTimeAnalysisEntry> it2 = group._traces.iterator();\r | |
2110 | while (it2.hasNext()) {\r | |
2111 | ITmfTimeAnalysisEntry trace = it2.next();\r | |
2112 | TraceItem traceItem = findTraceItem(trace);\r | |
2113 | name = utilsImp.composeTraceName(trace, false);\r | |
2114 | traceItem = new TraceItem(trace, name);\r | |
2115 | itemList.add(traceItem);\r | |
2116 | }\r | |
2117 | }\r | |
2118 | }\r | |
2119 | _items = itemList.toArray();\r | |
2120 | }\r | |
2121 | \r | |
2122 | public int expandItem(int idx, boolean expand) {\r | |
2123 | if (idx < 0 || idx >= _items.length)\r | |
2124 | return 0;\r | |
2125 | int ret = 0;\r | |
2126 | Item item = (Item) _items[idx];\r | |
2127 | if (item._hasChildren && !item._expanded) {\r | |
2128 | item._expanded = expand;\r | |
2129 | ret = _items.length;\r | |
2130 | updateItems();\r | |
2131 | ret = _items.length - ret;\r | |
2132 | }\r | |
2133 | return ret;\r | |
2134 | }\r | |
2135 | \r | |
2136 | public void refreshData(Object traces[]) {\r | |
2137 | if (traces == null || traces.length == 0) {\r | |
2138 | traceFilter = null;\r | |
2139 | } else if (traceFilter == null || traces.length != traceFilter.length) {\r | |
2140 | traceFilter = new boolean[traces.length];\r | |
2141 | java.util.Arrays.fill(traceFilter, true);\r | |
2142 | }\r | |
2143 | \r | |
2144 | _traces = traces;\r | |
2145 | refreshData();\r | |
2146 | }\r | |
2147 | \r | |
2148 | /**\r | |
2149 | * Allows to update the GUI from a stream of events handling addition one by\r | |
2150 | * one over known TmfTaTrace parents.\r | |
2151 | * \r | |
2152 | * @param parent\r | |
2153 | * @param childItem\r | |
2154 | */\r | |
2155 | public void refreshPartial(ITmfTimeAnalysisEntry parent, TimeEvent childItem) {\r | |
2156 | // Find the Trace item within the current list\r | |
2157 | TraceItem item = findTraceItem(parent);\r | |
2158 | \r | |
bbeafe9d FC |
2159 | // This method is not used (yet) so this code can be commented out for now\r |
2160 | // FIXME: Arrays.copyOf is a Java6 feature\r | |
2161 | // if (item == null) {\r | |
2162 | // // If the parent item is not found, make room for it in the current\r | |
2163 | // // array\r | |
2164 | // int length = 1;\r | |
2165 | // Object[] traces;\r | |
2166 | // if (_traces != null) {\r | |
2167 | // length = _traces.length + 1;\r | |
2168 | // traces = Arrays.copyOf(_traces, length);\r | |
2169 | // } else {\r | |
2170 | // traces = new Object[length];\r | |
2171 | // }\r | |
2172 | //\r | |
2173 | // // Add the new parent element to the end of the array.\r | |
2174 | // traces[length - 1] = parent;\r | |
2175 | //\r | |
2176 | // // update the filter array to accomodate a postion to the new\r | |
2177 | // // element\r | |
2178 | // traceFilter = new boolean[traces.length];\r | |
2179 | // java.util.Arrays.fill(traceFilter, true);\r | |
2180 | //\r | |
2181 | // // rebuild internal data\r | |
2182 | // _traces = traces;\r | |
2183 | // refreshData();\r | |
2184 | //\r | |
2185 | // // item must be there\r | |
2186 | // item = findTraceItem(parent);\r | |
2187 | // }\r | |
b0d3496e ASL |
2188 | \r |
2189 | ITmfTimeAnalysisEntry localTraceItem = item._trace;\r | |
2190 | // Local trace found\r | |
2191 | Vector<TimeEvent> children = localTraceItem.getTraceEvents();\r | |
2192 | TimeEvent lastChildIn = children.lastElement();\r | |
2193 | long lastChildSTime = lastChildIn.getTime();\r | |
2194 | long newChildSTime = childItem.getTime();\r | |
2195 | if (newChildSTime < lastChildSTime) {\r | |
2196 | // The children are expected to arrive sorted by time\r | |
2197 | // since the new time is earlier than the last child\r | |
2198 | // The infomation is being refreshed from start, remove all\r | |
2199 | // children and start over\r | |
2200 | children.clear();\r | |
2201 | }\r | |
2202 | // Add the new item\r | |
2203 | children.add(childItem);\r | |
2204 | \r | |
2205 | }\r | |
2206 | \r | |
2207 | public void refreshData() {\r | |
2208 | clearGroups();\r | |
2209 | filteredOut.clear();\r | |
2210 | String undef = Messages._UNDEFINED_GROUP;\r | |
2211 | List<GroupItem> groupList = new ArrayList<GroupItem>();\r | |
2212 | for (int i = 0; i < _traces.length; i++) {\r | |
2213 | ITmfTimeAnalysisEntry trace = (ITmfTimeAnalysisEntry) _traces[i];\r | |
2214 | if (!traceFilter[i]) {\r | |
2215 | filteredOut.add(trace);\r | |
2216 | continue;\r | |
2217 | }\r | |
2218 | \r | |
2219 | String groupName = trace.getGroupName();\r | |
2220 | if (null == groupName)\r | |
2221 | groupName = undef;\r | |
2222 | \r | |
2223 | GroupItem group = _groupTable.get(groupName);\r | |
2224 | if (null == group) {\r | |
2225 | group = new GroupItem(NLS.bind(Messages._TRACE_GROUP_LABEL,\r | |
2226 | groupName));\r | |
2227 | group._expanded = !groupName.equalsIgnoreCase("system")\r | |
2228 | && !groupName.equalsIgnoreCase(undef);\r | |
2229 | _groupTable.put(groupName, group);\r | |
2230 | groupList.add(group);\r | |
2231 | }\r | |
2232 | group.add(trace);\r | |
2233 | }\r | |
2234 | \r | |
2235 | deleteEmptyGroups();\r | |
2236 | updateItems();\r | |
2237 | }\r | |
2238 | \r | |
2239 | public Object[] getTraces() {\r | |
2240 | return _traces;\r | |
2241 | }\r | |
2242 | \r | |
2243 | public boolean[] getTraceFilter() {\r | |
2244 | return traceFilter;\r | |
2245 | }\r | |
2246 | \r | |
2247 | public Vector<ITmfTimeAnalysisEntry> getFilteredOut() {\r | |
2248 | return filteredOut;\r | |
2249 | }\r | |
2250 | }\r |