| 1 | /*****************************************************************************\r |
| 2 | * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.\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 Sanchez-Leon - Updated for TMF\r |
| 12 | * Patrick Tasse - Refactoring\r |
| 13 | *\r |
| 14 | *****************************************************************************/\r |
| 15 | \r |
| 16 | package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r |
| 17 | \r |
| 18 | import java.util.ArrayList;\r |
| 19 | import java.util.Iterator;\r |
| 20 | import java.util.List;\r |
| 21 | import java.util.Vector;\r |
| 22 | \r |
| 23 | import org.eclipse.jface.resource.JFaceResources;\r |
| 24 | import org.eclipse.jface.resource.LocalResourceManager;\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.widgets.timegraph.ITimeGraphPresentationProvider;\r |
| 29 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTreeListener;\r |
| 30 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r |
| 31 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTreeExpansionEvent;\r |
| 32 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r |
| 33 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\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.Color;\r |
| 52 | import org.eclipse.swt.graphics.Cursor;\r |
| 53 | import org.eclipse.swt.graphics.GC;\r |
| 54 | import org.eclipse.swt.graphics.Image;\r |
| 55 | import org.eclipse.swt.graphics.Point;\r |
| 56 | import org.eclipse.swt.graphics.Rectangle;\r |
| 57 | import org.eclipse.swt.widgets.Composite;\r |
| 58 | import org.eclipse.swt.widgets.Display;\r |
| 59 | import org.eclipse.swt.widgets.Event;\r |
| 60 | import org.eclipse.swt.widgets.Listener;\r |
| 61 | import org.eclipse.swt.widgets.ScrollBar;\r |
| 62 | \r |
| 63 | public class TimeGraphControl extends TimeGraphBaseControl implements FocusListener, KeyListener, MouseMoveListener, MouseListener, MouseWheelListener, ControlListener, SelectionListener, MouseTrackListener, TraverseListener, ISelectionProvider {\r |
| 64 | \r |
| 65 | private static final int DRAG_NONE = 0;\r |
| 66 | private static final int DRAG_TRACE_ITEM = 1;\r |
| 67 | private static final int DRAG_SPLIT_LINE = 2;\r |
| 68 | public static final boolean DEFAULT_DRAW_THREAD_JOIN = true;\r |
| 69 | public static final boolean DEFAULT_DRAW_THREAD_WAIT = true;\r |
| 70 | public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true;\r |
| 71 | public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;\r |
| 72 | private static final int CUSTOM_ITEM_HEIGHT = -1; // get item height from provider\r |
| 73 | \r |
| 74 | private static final double zoomCoeff = 1.5;\r |
| 75 | \r |
| 76 | private ITimeDataProvider _timeProvider;\r |
| 77 | private boolean _isInFocus = false;\r |
| 78 | private boolean _isDragCursor3 = false;\r |
| 79 | private boolean _isWaitCursor = true;\r |
| 80 | private boolean _mouseOverSplitLine = false;\r |
| 81 | private int _itemHeight = CUSTOM_ITEM_HEIGHT;\r |
| 82 | private int _minimumItemWidth = 0;\r |
| 83 | private int _topIndex = 0;\r |
| 84 | private int _dragState = DRAG_NONE;\r |
| 85 | private int _dragX0 = 0;\r |
| 86 | private int _dragX = 0;\r |
| 87 | private int _idealNameSpace = 0;\r |
| 88 | // private double _timeStep = 10000000;\r |
| 89 | private long _time0bak;\r |
| 90 | private long _time1bak;\r |
| 91 | private ITimeGraphPresentationProvider fTimeGraphProvider = null;\r |
| 92 | private ItemData _data = null;\r |
| 93 | private List<SelectionListener> _selectionListeners;\r |
| 94 | private List<ISelectionChangedListener> _selectionChangedListeners = new ArrayList<ISelectionChangedListener>();\r |
| 95 | private List<ITimeGraphTreeListener> _treeListeners = new ArrayList<ITimeGraphTreeListener>();\r |
| 96 | private Cursor _dragCursor3;\r |
| 97 | private Cursor _WaitCursor;\r |
| 98 | \r |
| 99 | // Vertical formatting formatting for the state control view\r |
| 100 | private boolean _visibleVerticalScroll = true;\r |
| 101 | private int _borderWidth = 0;\r |
| 102 | private int _headerHeight = 0;\r |
| 103 | \r |
| 104 | private Listener mouseScrollFilterListener;\r |
| 105 | \r |
| 106 | protected LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());\r |
| 107 | protected Color[] fEventColorMap = null;\r |
| 108 | \r |
| 109 | public TimeGraphControl(Composite parent, TimeGraphColorScheme colors) {\r |
| 110 | \r |
| 111 | super(parent, colors, SWT.NO_BACKGROUND | SWT.H_SCROLL | SWT.DOUBLE_BUFFERED);\r |
| 112 | \r |
| 113 | _data = new ItemData();\r |
| 114 | \r |
| 115 | addFocusListener(this);\r |
| 116 | addMouseListener(this);\r |
| 117 | addMouseMoveListener(this);\r |
| 118 | addMouseTrackListener(this);\r |
| 119 | addMouseWheelListener(this);\r |
| 120 | addTraverseListener(this);\r |
| 121 | addKeyListener(this);\r |
| 122 | addControlListener(this);\r |
| 123 | ScrollBar scrollHor = getHorizontalBar();\r |
| 124 | \r |
| 125 | if (scrollHor != null) {\r |
| 126 | scrollHor.addSelectionListener(this);\r |
| 127 | }\r |
| 128 | \r |
| 129 | _dragCursor3 = new Cursor(super.getDisplay(), SWT.CURSOR_SIZEWE);\r |
| 130 | _WaitCursor = new Cursor(super.getDisplay(), SWT.CURSOR_WAIT);\r |
| 131 | }\r |
| 132 | \r |
| 133 | @Override\r |
| 134 | public void dispose() {\r |
| 135 | super.dispose();\r |
| 136 | _dragCursor3.dispose();\r |
| 137 | _WaitCursor.dispose();\r |
| 138 | fResourceManager.dispose();\r |
| 139 | }\r |
| 140 | \r |
| 141 | /**\r |
| 142 | * Sets the timegraph provider used by this timegraph viewer.\r |
| 143 | * \r |
| 144 | * @param timeGraphProvider the timegraph provider\r |
| 145 | */\r |
| 146 | public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {\r |
| 147 | fTimeGraphProvider = timeGraphProvider;\r |
| 148 | _data.provider = timeGraphProvider;\r |
| 149 | // RGB[] eventColorTable = fTimeGraphProvider.getEventColorTable();\r |
| 150 | // if (eventColorTable != null) {\r |
| 151 | // fEventColorMap = new Color[eventColorTable.length];\r |
| 152 | // for (int i = 0; i < eventColorTable.length; i++) {\r |
| 153 | // fEventColorMap[i] = fResourceManager.createColor(eventColorTable[i]);\r |
| 154 | // }\r |
| 155 | // } else {\r |
| 156 | // fEventColorMap = new Color[] { };\r |
| 157 | // }\r |
| 158 | \r |
| 159 | StateItem[] stateItems = fTimeGraphProvider.getStateTable();\r |
| 160 | if (stateItems != null) {\r |
| 161 | fEventColorMap = new Color[stateItems.length];\r |
| 162 | for (int i = 0; i < stateItems.length; i++) {\r |
| 163 | fEventColorMap[i] = fResourceManager.createColor(stateItems[i].getStateColor());\r |
| 164 | }\r |
| 165 | } else {\r |
| 166 | fEventColorMap = new Color[] { };\r |
| 167 | }\r |
| 168 | \r |
| 169 | \r |
| 170 | }\r |
| 171 | \r |
| 172 | public void setTimeProvider(ITimeDataProvider timeProvider) {\r |
| 173 | _timeProvider = timeProvider;\r |
| 174 | adjustScrolls();\r |
| 175 | redraw();\r |
| 176 | }\r |
| 177 | \r |
| 178 | public void addSelectionListener(SelectionListener listener) {\r |
| 179 | if (listener == null)\r |
| 180 | SWT.error(SWT.ERROR_NULL_ARGUMENT);\r |
| 181 | if (null == _selectionListeners)\r |
| 182 | _selectionListeners = new ArrayList<SelectionListener>();\r |
| 183 | _selectionListeners.add(listener);\r |
| 184 | }\r |
| 185 | \r |
| 186 | public void removeSelectionListener(SelectionListener listener) {\r |
| 187 | if (null != _selectionListeners)\r |
| 188 | _selectionListeners.remove(listener);\r |
| 189 | }\r |
| 190 | \r |
| 191 | public void fireSelectionChanged() {\r |
| 192 | if (null != _selectionListeners) {\r |
| 193 | Iterator<SelectionListener> it = _selectionListeners.iterator();\r |
| 194 | while (it.hasNext()) {\r |
| 195 | SelectionListener listener = it.next();\r |
| 196 | listener.widgetSelected(null);\r |
| 197 | }\r |
| 198 | }\r |
| 199 | }\r |
| 200 | \r |
| 201 | public void fireDefaultSelection() {\r |
| 202 | if (null != _selectionListeners) {\r |
| 203 | Iterator<SelectionListener> it = _selectionListeners.iterator();\r |
| 204 | while (it.hasNext()) {\r |
| 205 | SelectionListener listener = it.next();\r |
| 206 | listener.widgetDefaultSelected(null);\r |
| 207 | }\r |
| 208 | }\r |
| 209 | }\r |
| 210 | \r |
| 211 | public ITimeGraphEntry[] getTraces() {\r |
| 212 | return _data.getTraces();\r |
| 213 | }\r |
| 214 | \r |
| 215 | public boolean[] getTraceFilter() {\r |
| 216 | return _data.getTraceFilter();\r |
| 217 | }\r |
| 218 | \r |
| 219 | public void refreshData() {\r |
| 220 | _data.refreshData();\r |
| 221 | adjustScrolls();\r |
| 222 | redraw();\r |
| 223 | }\r |
| 224 | \r |
| 225 | public void refreshData(ITimeGraphEntry traces[]) {\r |
| 226 | _data.refreshData(traces);\r |
| 227 | adjustScrolls();\r |
| 228 | redraw();\r |
| 229 | }\r |
| 230 | \r |
| 231 | public void adjustScrolls() {\r |
| 232 | if (null == _timeProvider) {\r |
| 233 | getHorizontalBar().setValues(0, 1, 1, 1, 1, 1);\r |
| 234 | return;\r |
| 235 | }\r |
| 236 | \r |
| 237 | // HORIZONTAL BAR\r |
| 238 | // Visible window\r |
| 239 | long time0 = _timeProvider.getTime0();\r |
| 240 | long time1 = _timeProvider.getTime1();\r |
| 241 | // Time boundaries\r |
| 242 | long timeMin = _timeProvider.getMinTime();\r |
| 243 | long timeMax = _timeProvider.getMaxTime();\r |
| 244 | \r |
| 245 | long delta = timeMax - timeMin;\r |
| 246 | \r |
| 247 | int timePos = 0;\r |
| 248 | int thumb = H_SCROLLBAR_MAX;\r |
| 249 | \r |
| 250 | if (delta != 0) {\r |
| 251 | // Thumb size (page size)\r |
| 252 | thumb = Math.max(1, (int) (H_SCROLLBAR_MAX * ((double) (time1 - time0) / delta)));\r |
| 253 | // At the beginning of visible window\r |
| 254 | timePos = (int) (H_SCROLLBAR_MAX * ((double) (time0 - timeMin) / delta));\r |
| 255 | }\r |
| 256 | \r |
| 257 | // position, minimum, maximum, thumb size, increment (half page)t, page\r |
| 258 | // increment size (full page)\r |
| 259 | getHorizontalBar().setValues(timePos, 0, H_SCROLLBAR_MAX, thumb, Math.max(1, thumb / 2), Math.max(2, thumb));\r |
| 260 | }\r |
| 261 | \r |
| 262 | boolean ensureVisibleItem(int idx, boolean redraw) {\r |
| 263 | boolean changed = false;\r |
| 264 | if (idx < 0) {\r |
| 265 | for (idx = 0; idx < _data._expandedItems.length; idx++) {\r |
| 266 | if (((TimeGraphItem) _data._expandedItems[idx])._selected)\r |
| 267 | break;\r |
| 268 | }\r |
| 269 | }\r |
| 270 | if (idx >= _data._expandedItems.length)\r |
| 271 | return changed;\r |
| 272 | if (idx < _topIndex) {\r |
| 273 | setTopIndex(idx);\r |
| 274 | //FIXME:getVerticalBar().setSelection(_topItem);\r |
| 275 | if (redraw)\r |
| 276 | redraw();\r |
| 277 | changed = true;\r |
| 278 | } else {\r |
| 279 | int page = countPerPage();\r |
| 280 | if (idx >= _topIndex + page) {\r |
| 281 | setTopIndex(idx - page + 1);\r |
| 282 | //FIXME:getVerticalBar().setSelection(_topItem);\r |
| 283 | if (redraw)\r |
| 284 | redraw();\r |
| 285 | changed = true;\r |
| 286 | }\r |
| 287 | }\r |
| 288 | return changed;\r |
| 289 | }\r |
| 290 | \r |
| 291 | public void setTopIndex(int idx) {\r |
| 292 | idx = Math.min(idx, _data._expandedItems.length - countPerPage());\r |
| 293 | idx = Math.max(0, idx);\r |
| 294 | _topIndex = idx;\r |
| 295 | redraw();\r |
| 296 | }\r |
| 297 | \r |
| 298 | public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {\r |
| 299 | TimeGraphItem item = _data.findItem(entry);\r |
| 300 | if (item != null && item._expanded != expanded) {\r |
| 301 | item._expanded = expanded;\r |
| 302 | _data.updateExpandedItems();\r |
| 303 | redraw();\r |
| 304 | }\r |
| 305 | }\r |
| 306 | \r |
| 307 | public void addTreeListener (ITimeGraphTreeListener listener) {\r |
| 308 | if (!_treeListeners.contains(listener)) {\r |
| 309 | _treeListeners.add(listener);\r |
| 310 | }\r |
| 311 | }\r |
| 312 | \r |
| 313 | public void removeTreeListener (ITimeGraphTreeListener listener) {\r |
| 314 | if (_treeListeners.contains(listener)) {\r |
| 315 | _treeListeners.remove(listener);\r |
| 316 | }\r |
| 317 | }\r |
| 318 | \r |
| 319 | public void fireTreeEvent(ITimeGraphEntry entry, boolean expanded) {\r |
| 320 | TimeGraphTreeExpansionEvent event = new TimeGraphTreeExpansionEvent(this, entry);\r |
| 321 | for (ITimeGraphTreeListener listener : _treeListeners) {\r |
| 322 | if (expanded) {\r |
| 323 | listener.treeExpanded(event);\r |
| 324 | } else {\r |
| 325 | listener.treeCollapsed(event);\r |
| 326 | }\r |
| 327 | }\r |
| 328 | }\r |
| 329 | \r |
| 330 | @Override\r |
| 331 | public ISelection getSelection() {\r |
| 332 | TimeGraphSelection sel = new TimeGraphSelection();\r |
| 333 | ITimeGraphEntry trace = getSelectedTrace();\r |
| 334 | if (null != trace && null != _timeProvider) {\r |
| 335 | long selectedTime = _timeProvider.getSelectedTime();\r |
| 336 | ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);\r |
| 337 | if (event != null)\r |
| 338 | sel.add(event);\r |
| 339 | else\r |
| 340 | sel.add(trace);\r |
| 341 | }\r |
| 342 | return sel;\r |
| 343 | }\r |
| 344 | \r |
| 345 | public ISelection getSelectionTrace() {\r |
| 346 | TimeGraphSelection sel = new TimeGraphSelection();\r |
| 347 | ITimeGraphEntry trace = getSelectedTrace();\r |
| 348 | if (null != trace) {\r |
| 349 | sel.add(trace);\r |
| 350 | }\r |
| 351 | return sel;\r |
| 352 | }\r |
| 353 | \r |
| 354 | public void selectTrace(int n) {\r |
| 355 | if (n != 1 && n != -1)\r |
| 356 | return;\r |
| 357 | boolean changed = false;\r |
| 358 | int lastSelection = -1;\r |
| 359 | for (int i = 0; i < _data._expandedItems.length; i++) {\r |
| 360 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r |
| 361 | if (item._selected) {\r |
| 362 | lastSelection = i;\r |
| 363 | if (1 == n && i < _data._expandedItems.length - 1) {\r |
| 364 | item._selected = false;\r |
| 365 | if (item._hasChildren) {\r |
| 366 | _data.expandItem(i);\r |
| 367 | fireTreeEvent(item._trace, item._expanded);\r |
| 368 | }\r |
| 369 | item = (TimeGraphItem) _data._expandedItems[i + 1];\r |
| 370 | if (item._hasChildren) {\r |
| 371 | _data.expandItem(i + 1);\r |
| 372 | fireTreeEvent(item._trace, item._expanded);\r |
| 373 | item = (TimeGraphItem) _data._expandedItems[i + 2];\r |
| 374 | }\r |
| 375 | item._selected = true;\r |
| 376 | changed = true;\r |
| 377 | } else if (-1 == n && i > 0) {\r |
| 378 | i--;\r |
| 379 | TimeGraphItem prevItem = (TimeGraphItem) _data._expandedItems[i];\r |
| 380 | if (prevItem._hasChildren) {\r |
| 381 | if (prevItem._expanded) {\r |
| 382 | if (i > 0) {\r |
| 383 | i--;\r |
| 384 | prevItem = (TimeGraphItem) _data._expandedItems[i];\r |
| 385 | }\r |
| 386 | }\r |
| 387 | if (!prevItem._expanded) {\r |
| 388 | _data.expandItem(i);\r |
| 389 | fireTreeEvent(prevItem._trace, prevItem._expanded);\r |
| 390 | prevItem = (TimeGraphItem) _data._expandedItems[i + prevItem.children.size()];\r |
| 391 | item._selected = false;\r |
| 392 | prevItem._selected = true;\r |
| 393 | changed = true;\r |
| 394 | }\r |
| 395 | } else {\r |
| 396 | item._selected = false;\r |
| 397 | prevItem._selected = true;\r |
| 398 | changed = true;\r |
| 399 | }\r |
| 400 | }\r |
| 401 | break;\r |
| 402 | }\r |
| 403 | }\r |
| 404 | if (lastSelection < 0 && _data._expandedItems.length > 0) {\r |
| 405 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[0];\r |
| 406 | if (item._hasChildren) {\r |
| 407 | _data.expandItem(0);\r |
| 408 | fireTreeEvent(item._trace, item._expanded);\r |
| 409 | item = (TimeGraphItem) _data._expandedItems[1];\r |
| 410 | item._selected = true;\r |
| 411 | changed = true;\r |
| 412 | } else {\r |
| 413 | item._selected = true;\r |
| 414 | changed = true;\r |
| 415 | }\r |
| 416 | }\r |
| 417 | if (changed) {\r |
| 418 | ensureVisibleItem(-1, false);\r |
| 419 | redraw();\r |
| 420 | fireSelectionChanged();\r |
| 421 | }\r |
| 422 | }\r |
| 423 | \r |
| 424 | public void selectEvent(int n) {\r |
| 425 | if (null == _timeProvider)\r |
| 426 | return;\r |
| 427 | ITimeGraphEntry trace = getSelectedTrace();\r |
| 428 | if (trace == null)\r |
| 429 | return;\r |
| 430 | long selectedTime = _timeProvider.getSelectedTime();\r |
| 431 | long endTime = _timeProvider.getEndTime();\r |
| 432 | ITimeEvent nextEvent;\r |
| 433 | if (-1 == n && selectedTime > endTime)\r |
| 434 | nextEvent = Utils.findEvent(trace, selectedTime, 0);\r |
| 435 | else\r |
| 436 | nextEvent = Utils.findEvent(trace, selectedTime, n);\r |
| 437 | if (null == nextEvent && -1 == n)\r |
| 438 | nextEvent = Utils.getFirstEvent(trace);\r |
| 439 | if (null != nextEvent) {\r |
| 440 | long nextTime = nextEvent.getTime();\r |
| 441 | // If last event detected e.g. going back or not moving to a next\r |
| 442 | // event\r |
| 443 | if (nextTime <= selectedTime && n == 1) {\r |
| 444 | // Select to the end of this last event\r |
| 445 | nextTime = nextEvent.getTime() + nextEvent.getDuration();\r |
| 446 | // but not beyond the end of the trace\r |
| 447 | if (nextTime > endTime) {\r |
| 448 | nextTime = endTime;\r |
| 449 | }\r |
| 450 | }\r |
| 451 | _timeProvider.setSelectedTimeInt(nextTime, true);\r |
| 452 | fireSelectionChanged();\r |
| 453 | } else if (1 == n) {\r |
| 454 | _timeProvider.setSelectedTimeInt(endTime, true);\r |
| 455 | fireSelectionChanged();\r |
| 456 | }\r |
| 457 | }\r |
| 458 | \r |
| 459 | public void selectNextEvent() {\r |
| 460 | selectEvent(1);\r |
| 461 | // Notify if visible time window has been adjusted\r |
| 462 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r |
| 463 | }\r |
| 464 | \r |
| 465 | public void selectPrevEvent() {\r |
| 466 | selectEvent(-1);\r |
| 467 | // Notify if visible time window has been adjusted\r |
| 468 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getTime0(), _timeProvider.getTime1());\r |
| 469 | }\r |
| 470 | \r |
| 471 | public void selectNextTrace() {\r |
| 472 | selectTrace(1);\r |
| 473 | }\r |
| 474 | \r |
| 475 | public void selectPrevTrace() {\r |
| 476 | selectTrace(-1);\r |
| 477 | }\r |
| 478 | \r |
| 479 | /**\r |
| 480 | * Zooming based on mouse cursor location with mouse scrolling\r |
| 481 | * \r |
| 482 | * @param zoomIn\r |
| 483 | */\r |
| 484 | public void zoom(boolean zoomIn) {\r |
| 485 | int globalX = getDisplay().getCursorLocation().x;\r |
| 486 | Point p = toControl(globalX, 0);\r |
| 487 | int nameSpace = _timeProvider.getNameSpace();\r |
| 488 | int timeSpace = _timeProvider.getTimeSpace();\r |
| 489 | int xPos = Math.max(nameSpace, Math.min(nameSpace + timeSpace, p.x));\r |
| 490 | long time0 = _timeProvider.getTime0();\r |
| 491 | long time1 = _timeProvider.getTime1();\r |
| 492 | long interval = time1 - time0;\r |
| 493 | if (interval == 0) {\r |
| 494 | interval = 1;\r |
| 495 | } // to allow getting out of single point interval\r |
| 496 | long newInterval;\r |
| 497 | if (zoomIn) {\r |
| 498 | newInterval = Math.max(Math.round((double) interval * 0.8), _timeProvider.getMinTimeInterval());\r |
| 499 | } else {\r |
| 500 | newInterval = (long) Math.ceil((double) interval * 1.25);\r |
| 501 | }\r |
| 502 | long center = time0 + Math.round(((double) (xPos - nameSpace) / timeSpace * interval));\r |
| 503 | long newTime0 = center - Math.round((double) newInterval * (center - time0) / interval);\r |
| 504 | long newTime1 = newTime0 + newInterval;\r |
| 505 | _timeProvider.setStartFinishTime(newTime0, newTime1);\r |
| 506 | }\r |
| 507 | \r |
| 508 | /**\r |
| 509 | * zoom in using single click\r |
| 510 | */\r |
| 511 | public void zoomIn() {\r |
| 512 | long _time0 = _timeProvider.getTime0();\r |
| 513 | long _time1 = _timeProvider.getTime1();\r |
| 514 | long _range = _time1 - _time0;\r |
| 515 | long selTime = _timeProvider.getSelectedTime();\r |
| 516 | if (selTime <= _time0 || selTime >= _time1) {\r |
| 517 | selTime = (_time0 + _time1) / 2;\r |
| 518 | }\r |
| 519 | long time0 = selTime - (long) ((selTime - _time0) / zoomCoeff);\r |
| 520 | long time1 = selTime + (long) ((_time1 - selTime) / zoomCoeff);\r |
| 521 | \r |
| 522 | long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0);\r |
| 523 | \r |
| 524 | // Trace.debug("selTime:" + selTime + " time0:" + time0 + " time1:"\r |
| 525 | // + time1 + " inaccuracy:" + inaccuracy);\r |
| 526 | \r |
| 527 | if (inaccuracy > 0 && inaccuracy < 100) {\r |
| 528 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime());\r |
| 529 | return;\r |
| 530 | }\r |
| 531 | \r |
| 532 | long m = _timeProvider.getMinTimeInterval();\r |
| 533 | if ((time1 - time0) < m) {\r |
| 534 | time0 = selTime - (long) ((selTime - _time0) * m / _range);\r |
| 535 | time1 = time0 + m;\r |
| 536 | }\r |
| 537 | \r |
| 538 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r |
| 539 | }\r |
| 540 | \r |
| 541 | /**\r |
| 542 | * zoom out using single click\r |
| 543 | */\r |
| 544 | public void zoomOut() {\r |
| 545 | long _time0 = _timeProvider.getTime0();\r |
| 546 | long _time1 = _timeProvider.getTime1();\r |
| 547 | long selTime = _timeProvider.getSelectedTime();\r |
| 548 | if (selTime <= _time0 || selTime >= _time1) {\r |
| 549 | selTime = (_time0 + _time1) / 2;\r |
| 550 | }\r |
| 551 | long time0 = (long) (selTime - (selTime - _time0) * zoomCoeff);\r |
| 552 | long time1 = (long) (selTime + (_time1 - selTime) * zoomCoeff);\r |
| 553 | \r |
| 554 | long inaccuracy = (_timeProvider.getMaxTime() - _timeProvider.getMinTime()) - (time1 - time0);\r |
| 555 | if (inaccuracy > 0 && inaccuracy < 100) {\r |
| 556 | _timeProvider.setStartFinishTimeNotify(_timeProvider.getMinTime(), _timeProvider.getMaxTime());\r |
| 557 | return;\r |
| 558 | }\r |
| 559 | \r |
| 560 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r |
| 561 | }\r |
| 562 | \r |
| 563 | public ITimeGraphEntry getSelectedTrace() {\r |
| 564 | ITimeGraphEntry trace = null;\r |
| 565 | int idx = getSelectedIndex();\r |
| 566 | if (idx >= 0)\r |
| 567 | trace = _data._expandedItems[idx]._trace;\r |
| 568 | return trace;\r |
| 569 | }\r |
| 570 | \r |
| 571 | public int getSelectedIndex() {\r |
| 572 | int idx = -1;\r |
| 573 | for (int i = 0; i < _data._expandedItems.length; i++) {\r |
| 574 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r |
| 575 | if (item._selected) {\r |
| 576 | idx = i;\r |
| 577 | break;\r |
| 578 | }\r |
| 579 | }\r |
| 580 | return idx;\r |
| 581 | }\r |
| 582 | \r |
| 583 | boolean toggle(int idx) {\r |
| 584 | boolean toggled = false;\r |
| 585 | if (idx >= 0 && idx < _data._expandedItems.length) {\r |
| 586 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx];\r |
| 587 | if (item._hasChildren) {\r |
| 588 | item._expanded = !item._expanded;\r |
| 589 | _data.updateExpandedItems();\r |
| 590 | adjustScrolls();\r |
| 591 | redraw();\r |
| 592 | toggled = true;\r |
| 593 | fireTreeEvent(item._trace, item._expanded);\r |
| 594 | }\r |
| 595 | }\r |
| 596 | return toggled;\r |
| 597 | }\r |
| 598 | \r |
| 599 | int getItemIndexAtY(int y) {\r |
| 600 | if (y < 0) {\r |
| 601 | return -1;\r |
| 602 | }\r |
| 603 | if (_itemHeight == CUSTOM_ITEM_HEIGHT) {\r |
| 604 | int ySum = 0;\r |
| 605 | for (int idx = _topIndex; idx < _data._expandedItems.length; idx++) {\r |
| 606 | ySum += _data._expandedItems[idx].itemHeight;\r |
| 607 | if (y < ySum) {\r |
| 608 | return idx;\r |
| 609 | }\r |
| 610 | }\r |
| 611 | return -1;\r |
| 612 | }\r |
| 613 | int idx = y / _itemHeight;\r |
| 614 | idx += _topIndex;\r |
| 615 | if (idx < _data._expandedItems.length) {\r |
| 616 | return idx;\r |
| 617 | }\r |
| 618 | return -1;\r |
| 619 | }\r |
| 620 | \r |
| 621 | boolean isOverSplitLine(int x) {\r |
| 622 | if (x < 0 || null == _timeProvider)\r |
| 623 | return false;\r |
| 624 | int w = 4;\r |
| 625 | int nameWidth = _timeProvider.getNameSpace();\r |
| 626 | if (x > nameWidth - w && x < nameWidth + w) {\r |
| 627 | return true;\r |
| 628 | } else {\r |
| 629 | return false;\r |
| 630 | }\r |
| 631 | }\r |
| 632 | \r |
| 633 | TimeGraphItem getItem(Point pt) {\r |
| 634 | int idx = getItemIndexAtY(pt.y);\r |
| 635 | return idx >= 0 ? (TimeGraphItem) _data._expandedItems[idx] : null;\r |
| 636 | }\r |
| 637 | \r |
| 638 | long getTimeAtX(int x) {\r |
| 639 | if (null == _timeProvider)\r |
| 640 | return -1;\r |
| 641 | long hitTime = -1;\r |
| 642 | Point size = getCtrlSize();\r |
| 643 | long time0 = _timeProvider.getTime0();\r |
| 644 | long time1 = _timeProvider.getTime1();\r |
| 645 | int nameWidth = _timeProvider.getNameSpace();\r |
| 646 | x -= nameWidth;\r |
| 647 | if (x >= 0 && size.x >= nameWidth) {\r |
| 648 | if (time1 - time0 > size.x - nameWidth - RIGHT_MARGIN) {\r |
| 649 | // get the last possible time represented by the pixel position\r |
| 650 | // by taking the time of the next pixel position minus 1\r |
| 651 | // nanosecond\r |
| 652 | hitTime = time0 + (long) ((time1 - time0) * ((double) (x + 1) / (size.x - nameWidth - RIGHT_MARGIN))) - 1;\r |
| 653 | } else {\r |
| 654 | hitTime = time0 + (long) ((time1 - time0) * ((double) (x) / (size.x - nameWidth - RIGHT_MARGIN)));\r |
| 655 | }\r |
| 656 | }\r |
| 657 | return hitTime;\r |
| 658 | }\r |
| 659 | \r |
| 660 | void selectItem(int idx, boolean addSelection) {\r |
| 661 | boolean changed = false;\r |
| 662 | if (addSelection) {\r |
| 663 | if (idx >= 0 && idx < _data._expandedItems.length) {\r |
| 664 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[idx];\r |
| 665 | changed = (item._selected == false);\r |
| 666 | item._selected = true;\r |
| 667 | }\r |
| 668 | } else {\r |
| 669 | for (int i = 0; i < _data._expandedItems.length; i++) {\r |
| 670 | TimeGraphItem item = (TimeGraphItem) _data._expandedItems[i];\r |
| 671 | if ((i == idx && !item._selected) || (idx == -1 && item._selected)) {\r |
| 672 | changed = true;\r |
| 673 | }\r |
| 674 | item._selected = i == idx;\r |
| 675 | }\r |
| 676 | }\r |
| 677 | changed |= ensureVisibleItem(idx, true);\r |
| 678 | if (changed)\r |
| 679 | redraw();\r |
| 680 | }\r |
| 681 | \r |
| 682 | public void selectItem(ITimeGraphEntry trace, boolean addSelection) {\r |
| 683 | int idx = _data.findItemIndex(trace);\r |
| 684 | selectItem(idx, addSelection);\r |
| 685 | }\r |
| 686 | \r |
| 687 | public int countPerPage() {\r |
| 688 | int height = getCtrlSize().y;\r |
| 689 | int count = 0;\r |
| 690 | if (_itemHeight == CUSTOM_ITEM_HEIGHT) {\r |
| 691 | int ySum = 0;\r |
| 692 | for (int idx = _topIndex; idx < _data._expandedItems.length; idx++) {\r |
| 693 | ySum += _data._expandedItems[idx].itemHeight;\r |
| 694 | if (ySum >= height) {\r |
| 695 | return count;\r |
| 696 | }\r |
| 697 | count++;\r |
| 698 | }\r |
| 699 | for (int idx = _topIndex - 1; idx >= 0; idx--) {\r |
| 700 | ySum += _data._expandedItems[idx].itemHeight;\r |
| 701 | if (ySum >= height) {\r |
| 702 | return count;\r |
| 703 | }\r |
| 704 | count++;\r |
| 705 | }\r |
| 706 | return count;\r |
| 707 | }\r |
| 708 | if (height > 0) {\r |
| 709 | count = height / _itemHeight;\r |
| 710 | }\r |
| 711 | return count;\r |
| 712 | }\r |
| 713 | \r |
| 714 | public int getTopIndex() {\r |
| 715 | return _topIndex;\r |
| 716 | }\r |
| 717 | \r |
| 718 | public int getExpandedElementCount() {\r |
| 719 | return _data._expandedItems.length;\r |
| 720 | }\r |
| 721 | \r |
| 722 | Point getCtrlSize() {\r |
| 723 | Point size = getSize();\r |
| 724 | if (getHorizontalBar().isVisible()) {\r |
| 725 | size.y -= getHorizontalBar().getSize().y;\r |
| 726 | }\r |
| 727 | return size;\r |
| 728 | }\r |
| 729 | \r |
| 730 | Rectangle getNameRect(Rectangle bound, int idx, int nameWidth) {\r |
| 731 | int x = bound.x;\r |
| 732 | int y = bound.y + (idx - _topIndex) * _itemHeight;\r |
| 733 | int width = nameWidth;\r |
| 734 | int height = _itemHeight;\r |
| 735 | if (_itemHeight == CUSTOM_ITEM_HEIGHT) {\r |
| 736 | int ySum = 0;\r |
| 737 | for (int i = _topIndex; i < idx; i++) {\r |
| 738 | ySum += _data._expandedItems[i].itemHeight;\r |
| 739 | }\r |
| 740 | y = bound.y + ySum;\r |
| 741 | height = _data._expandedItems[idx].itemHeight;\r |
| 742 | }\r |
| 743 | return new Rectangle(x, y, width, height);\r |
| 744 | }\r |
| 745 | \r |
| 746 | Rectangle getStatesRect(Rectangle bound, int idx, int nameWidth) {\r |
| 747 | int x = bound.x + nameWidth;\r |
| 748 | int y = bound.y + (idx - _topIndex) * _itemHeight;\r |
| 749 | int width = bound.width - x;\r |
| 750 | int height = _itemHeight;\r |
| 751 | if (_itemHeight == CUSTOM_ITEM_HEIGHT) {\r |
| 752 | int ySum = 0;\r |
| 753 | for (int i = _topIndex; i < idx; i++) {\r |
| 754 | ySum += _data._expandedItems[i].itemHeight;\r |
| 755 | }\r |
| 756 | y = bound.y + ySum;\r |
| 757 | height = _data._expandedItems[idx].itemHeight;\r |
| 758 | }\r |
| 759 | return new Rectangle(x, y, width, height);\r |
| 760 | }\r |
| 761 | \r |
| 762 | @Override\r |
| 763 | void paint(Rectangle bounds, PaintEvent e) {\r |
| 764 | GC gc = e.gc;\r |
| 765 | gc.setBackground(_colors.getColor(TimeGraphColorScheme.BACKGROUND));\r |
| 766 | drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height);\r |
| 767 | \r |
| 768 | if (bounds.width < 2 || bounds.height < 2 || null == _timeProvider)\r |
| 769 | return;\r |
| 770 | \r |
| 771 | _idealNameSpace = 0;\r |
| 772 | int nameSpace = _timeProvider.getNameSpace();\r |
| 773 | \r |
| 774 | // draw empty name space background\r |
| 775 | gc.setBackground(_colors.getBkColor(false, false, true));\r |
| 776 | drawBackground(gc, bounds.x, bounds.y, nameSpace, bounds.height);\r |
| 777 | \r |
| 778 | drawItems(bounds, _timeProvider, _data._expandedItems, _topIndex, nameSpace, gc);\r |
| 779 | \r |
| 780 | // draw selected time\r |
| 781 | long time0 = _timeProvider.getTime0();\r |
| 782 | long time1 = _timeProvider.getTime1();\r |
| 783 | long selectedTime = _timeProvider.getSelectedTime();\r |
| 784 | double pixelsPerNanoSec = (bounds.width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (bounds.width - nameSpace - RIGHT_MARGIN) / (time1 - time0);\r |
| 785 | int x = bounds.x + nameSpace + (int) ((double) (selectedTime - time0) * pixelsPerNanoSec);\r |
| 786 | if (x >= nameSpace && x < bounds.x + bounds.width) {\r |
| 787 | gc.setForeground(_colors.getColor(TimeGraphColorScheme.SELECTED_TIME));\r |
| 788 | gc.drawLine(x, bounds.y, x, bounds.y + bounds.height);\r |
| 789 | }\r |
| 790 | \r |
| 791 | // draw drag line, no line if name space is 0.\r |
| 792 | if (DRAG_SPLIT_LINE == _dragState) {\r |
| 793 | gc.setForeground(_colors.getColor(TimeGraphColorScheme.BLACK));\r |
| 794 | gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1);\r |
| 795 | } else if (DRAG_NONE == _dragState && _mouseOverSplitLine && _timeProvider.getNameSpace() > 0) {\r |
| 796 | gc.setForeground(_colors.getColor(TimeGraphColorScheme.RED));\r |
| 797 | gc.drawLine(bounds.x + nameSpace, bounds.y, bounds.x + nameSpace, bounds.y + bounds.height - 1);\r |
| 798 | }\r |
| 799 | }\r |
| 800 | \r |
| 801 | public void drawItems(Rectangle bounds, ITimeDataProvider timeProvider, TimeGraphItem[] items, int topIndex, int nameSpace, GC gc) {\r |
| 802 | for (int i = topIndex; i < items.length; i++) {\r |
| 803 | TimeGraphItem item = (TimeGraphItem) items[i];\r |
| 804 | drawItem(item, bounds, timeProvider, i, nameSpace, gc);\r |
| 805 | }\r |
| 806 | fTimeGraphProvider.postDrawControl(bounds, gc);\r |
| 807 | }\r |
| 808 | \r |
| 809 | /**\r |
| 810 | * Draws the item\r |
| 811 | * \r |
| 812 | * @param item the item to draw\r |
| 813 | * @param bounds the container rectangle\r |
| 814 | * @param i the item index\r |
| 815 | * @param nameSpace the name space\r |
| 816 | * @param gc\r |
| 817 | */\r |
| 818 | protected void drawItem(TimeGraphItem item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) {\r |
| 819 | ITimeGraphEntry entry = item._trace;\r |
| 820 | long time0 = timeProvider.getTime0();\r |
| 821 | long time1 = timeProvider.getTime1();\r |
| 822 | long selectedTime = timeProvider.getSelectedTime();\r |
| 823 | \r |
| 824 | Rectangle nameRect = getNameRect(bounds, i, nameSpace);\r |
| 825 | if (nameRect.y >= bounds.y + bounds.height) {\r |
| 826 | return;\r |
| 827 | }\r |
| 828 | \r |
| 829 | if (item._trace.getTimeEventsIterator() == null) {\r |
| 830 | Rectangle statesRect = getStatesRect(bounds, i, nameSpace);\r |
| 831 | nameRect.width += statesRect.width;\r |
| 832 | drawName(item, nameRect, gc);\r |
| 833 | } else {\r |
| 834 | drawName(item, nameRect, gc);\r |
| 835 | }\r |
| 836 | Rectangle rect = getStatesRect(bounds, i, nameSpace);\r |
| 837 | if (rect.isEmpty()) {\r |
| 838 | fTimeGraphProvider.postDrawEntry(entry, bounds, gc);\r |
| 839 | return;\r |
| 840 | }\r |
| 841 | if (time1 <= time0) {\r |
| 842 | gc.setBackground(_colors.getBkColor(false, false, false));\r |
| 843 | gc.fillRectangle(rect);\r |
| 844 | fTimeGraphProvider.postDrawEntry(entry, bounds, gc);\r |
| 845 | return;\r |
| 846 | }\r |
| 847 | \r |
| 848 | // Initialize _rect1 to same values as enclosing rectangle rect\r |
| 849 | Rectangle stateRect = Utils.clone(rect);\r |
| 850 | boolean selected = item._selected;\r |
| 851 | // K pixels per second\r |
| 852 | double pixelsPerNanoSec = (rect.width <= RIGHT_MARGIN) ? 0 : (double) (rect.width - RIGHT_MARGIN) / (time1 - time0);\r |
| 853 | \r |
| 854 | boolean group = item._trace.getTimeEventsIterator() == null;\r |
| 855 | \r |
| 856 | if (!group) {\r |
| 857 | fillSpace(rect, gc, selected);\r |
| 858 | // Drawing rectangle is smaller than reserved space\r |
| 859 | stateRect.y += 3;\r |
| 860 | stateRect.height -= 6;\r |
| 861 | \r |
| 862 | long maxDuration = (timeProvider.getTimeSpace() == 0) ? Long.MAX_VALUE : 1 * (time1 - time0) / timeProvider.getTimeSpace();\r |
| 863 | Iterator<ITimeEvent> iterator = entry.getTimeEventsIterator(time0, time1, maxDuration);\r |
| 864 | \r |
| 865 | int lastX = -1;\r |
| 866 | while (iterator.hasNext()) {\r |
| 867 | ITimeEvent event = iterator.next();\r |
| 868 | int x = rect.x + (int) ((event.getTime() - time0) * pixelsPerNanoSec);\r |
| 869 | int xEnd = rect.x + (int) ((event.getTime() + event.getDuration() - time0) * pixelsPerNanoSec);\r |
| 870 | if (x >= rect.x + rect.width || xEnd < rect.x) {\r |
| 871 | // event is out of bounds\r |
| 872 | continue;\r |
| 873 | }\r |
| 874 | xEnd = Math.min(rect.x + rect.width, xEnd);\r |
| 875 | stateRect.x = Math.max(rect.x, x);\r |
| 876 | stateRect.width = Math.max(0, xEnd - stateRect.x + 1);\r |
| 877 | if (stateRect.x == lastX) {\r |
| 878 | stateRect.width -= 1;\r |
| 879 | if (stateRect.width > 0) {\r |
| 880 | gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r |
| 881 | gc.drawPoint(stateRect.x, stateRect.y - 2);\r |
| 882 | stateRect.x += 1;\r |
| 883 | }\r |
| 884 | } else {\r |
| 885 | lastX = x;\r |
| 886 | }\r |
| 887 | boolean timeSelected = selectedTime >= event.getTime() && selectedTime < event.getTime() + event.getDuration();\r |
| 888 | drawState(_colors, event, stateRect, gc, selected, timeSelected);\r |
| 889 | }\r |
| 890 | }\r |
| 891 | fTimeGraphProvider.postDrawEntry(entry, bounds, gc);\r |
| 892 | }\r |
| 893 | \r |
| 894 | protected void drawName(TimeGraphItem item, Rectangle bounds, GC gc) {\r |
| 895 | boolean group = item._trace.getTimeEventsIterator() == null;\r |
| 896 | if (group) {\r |
| 897 | gc.setBackground(_colors.getBkColorGroup(item._selected, _isInFocus));\r |
| 898 | gc.fillRectangle(bounds);\r |
| 899 | if (item._selected && _isInFocus) {\r |
| 900 | gc.setForeground(_colors.getBkColor(item._selected, _isInFocus, false));\r |
| 901 | gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);\r |
| 902 | }\r |
| 903 | } else {\r |
| 904 | gc.setBackground(_colors.getBkColor(item._selected, _isInFocus, true));\r |
| 905 | gc.setForeground(_colors.getFgColor(item._selected, _isInFocus));\r |
| 906 | gc.fillRectangle(bounds);\r |
| 907 | }\r |
| 908 | \r |
| 909 | // No name to be drawn\r |
| 910 | if (_timeProvider.getNameSpace() == 0) {\r |
| 911 | return;\r |
| 912 | }\r |
| 913 | \r |
| 914 | int leftMargin = MARGIN + item.level * EXPAND_SIZE;\r |
| 915 | if (item._hasChildren) {\r |
| 916 | gc.setForeground(_colors.getFgColorGroup(false, false));\r |
| 917 | gc.setBackground(_colors.getBkColor(false, false, false));\r |
| 918 | Rectangle rect = Utils.clone(bounds);\r |
| 919 | rect.x += leftMargin;\r |
| 920 | rect.y += (bounds.height - EXPAND_SIZE) / 2;\r |
| 921 | rect.width = EXPAND_SIZE;\r |
| 922 | rect.height = EXPAND_SIZE;\r |
| 923 | gc.fillRectangle(rect);\r |
| 924 | gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);\r |
| 925 | int midy = rect.y + rect.height / 2;\r |
| 926 | gc.drawLine(rect.x + 2, midy, rect.x + rect.width - 3, midy);\r |
| 927 | if (!item._expanded) {\r |
| 928 | int midx = rect.x + rect.width / 2;\r |
| 929 | gc.drawLine(midx, rect.y + 2, midx, rect.y + rect.height - 3);\r |
| 930 | }\r |
| 931 | }\r |
| 932 | leftMargin += EXPAND_SIZE + MARGIN;\r |
| 933 | \r |
| 934 | Image img = fTimeGraphProvider.getItemImage(item._trace);\r |
| 935 | if (img != null) {\r |
| 936 | // draw icon\r |
| 937 | int imgHeight = img.getImageData().height;\r |
| 938 | int imgWidth = img.getImageData().width;\r |
| 939 | int x = leftMargin;\r |
| 940 | int y = bounds.y + (bounds.height - imgHeight) / 2;\r |
| 941 | gc.drawImage(img, x, y);\r |
| 942 | leftMargin += imgWidth + MARGIN;\r |
| 943 | }\r |
| 944 | String name = item._name;\r |
| 945 | Point size = gc.stringExtent(name);\r |
| 946 | if (_idealNameSpace < leftMargin + size.x + MARGIN) {\r |
| 947 | _idealNameSpace = leftMargin + size.x + MARGIN;\r |
| 948 | }\r |
| 949 | if (!group) {\r |
| 950 | // cut long string with "..."\r |
| 951 | int width = bounds.width - leftMargin;\r |
| 952 | int cuts = 0;\r |
| 953 | while (size.x > width && name.length() > 1) {\r |
| 954 | cuts++;\r |
| 955 | name = name.substring(0, name.length() - 1);\r |
| 956 | size = gc.stringExtent(name + "..."); //$NON-NLS-1$\r |
| 957 | }\r |
| 958 | if (cuts > 0) {\r |
| 959 | name += "..."; //$NON-NLS-1$\r |
| 960 | }\r |
| 961 | }\r |
| 962 | Rectangle rect = Utils.clone(bounds);\r |
| 963 | rect.x += leftMargin;\r |
| 964 | rect.width -= leftMargin;\r |
| 965 | // draw text\r |
| 966 | if (rect.width > 0) {\r |
| 967 | rect.y += (bounds.height - gc.stringExtent(name).y) / 2;\r |
| 968 | gc.setForeground(_colors.getFgColor(item._selected, _isInFocus));\r |
| 969 | int textWidth = Utils.drawText(gc, name, rect, true);\r |
| 970 | leftMargin += textWidth + MARGIN;\r |
| 971 | rect.y -= 2;\r |
| 972 | \r |
| 973 | if (!group) {\r |
| 974 | // draw middle line\r |
| 975 | int x = bounds.x + leftMargin;\r |
| 976 | int width = bounds.width - x;\r |
| 977 | int midy = bounds.y + bounds.height / 2;\r |
| 978 | gc.setForeground(_colors.getColor(TimeGraphColorScheme.MID_LINE));\r |
| 979 | gc.drawLine(x, midy, x + width, midy);\r |
| 980 | }\r |
| 981 | }\r |
| 982 | }\r |
| 983 | \r |
| 984 | protected void drawState(TimeGraphColorScheme colors, ITimeEvent event,\r |
| 985 | Rectangle rect, GC gc, boolean selected, boolean timeSelected) {\r |
| 986 | \r |
| 987 | int colorIdx = fTimeGraphProvider.getEventTableIndex(event);\r |
| 988 | if (colorIdx < 0) {\r |
| 989 | return;\r |
| 990 | }\r |
| 991 | boolean visible = rect.width == 0 ? false : true;\r |
| 992 | \r |
| 993 | if (visible) {\r |
| 994 | Color stateColor = null;\r |
| 995 | if (colorIdx < fEventColorMap.length) {\r |
| 996 | stateColor = fEventColorMap[colorIdx];\r |
| 997 | } else {\r |
| 998 | stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);\r |
| 999 | }\r |
| 1000 | \r |
| 1001 | timeSelected = timeSelected && selected;\r |
| 1002 | if (timeSelected) {\r |
| 1003 | // modify the color?\r |
| 1004 | }\r |
| 1005 | // fill all rect area\r |
| 1006 | gc.setBackground(stateColor);\r |
| 1007 | gc.fillRectangle(rect);\r |
| 1008 | // get the border color?\r |
| 1009 | gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r |
| 1010 | \r |
| 1011 | // draw bounds\r |
| 1012 | if (!timeSelected) {\r |
| 1013 | // Draw the top and bottom borders i.e. no side borders\r |
| 1014 | // top\r |
| 1015 | gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);\r |
| 1016 | // bottom\r |
| 1017 | gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);\r |
| 1018 | }\r |
| 1019 | } else {\r |
| 1020 | gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r |
| 1021 | gc.drawPoint(rect.x, rect.y - 2);\r |
| 1022 | /*\r |
| 1023 | // selected rectangle area is not visible but can be represented\r |
| 1024 | // with a broken vertical line of specified width.\r |
| 1025 | int width = 1;\r |
| 1026 | rect.width = width;\r |
| 1027 | gc.setForeground(stateColor);\r |
| 1028 | int s = gc.getLineStyle();\r |
| 1029 | int w = gc.getLineWidth();\r |
| 1030 | gc.setLineStyle(SWT.LINE_DOT);\r |
| 1031 | gc.setLineWidth(width);\r |
| 1032 | // Trace.debug("Rectangle not visible, drawing vertical line with: "\r |
| 1033 | // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y\r |
| 1034 | // + rect.height);\r |
| 1035 | gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1);\r |
| 1036 | gc.setLineStyle(s);\r |
| 1037 | gc.setLineWidth(w);\r |
| 1038 | if (!timeSelected) {\r |
| 1039 | gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));\r |
| 1040 | gc.drawPoint(rect.x, rect.y);\r |
| 1041 | gc.drawPoint(rect.x, rect.y + rect.height - 1);\r |
| 1042 | }\r |
| 1043 | */\r |
| 1044 | }\r |
| 1045 | fTimeGraphProvider.postDrawEvent(event, rect, gc);\r |
| 1046 | }\r |
| 1047 | \r |
| 1048 | protected void fillSpace(Rectangle rect, GC gc, boolean selected) {\r |
| 1049 | gc.setBackground(_colors.getBkColor(selected, _isInFocus, false));\r |
| 1050 | gc.fillRectangle(rect);\r |
| 1051 | // draw middle line\r |
| 1052 | gc.setForeground(_colors.getColor(TimeGraphColorScheme.MID_LINE));\r |
| 1053 | int midy = rect.y + rect.height / 2;\r |
| 1054 | gc.drawLine(rect.x, midy, rect.x + rect.width, midy);\r |
| 1055 | }\r |
| 1056 | \r |
| 1057 | @Override\r |
| 1058 | public void keyTraversed(TraverseEvent e) {\r |
| 1059 | if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS))\r |
| 1060 | e.doit = true;\r |
| 1061 | }\r |
| 1062 | \r |
| 1063 | @Override\r |
| 1064 | public void keyPressed(KeyEvent e) {\r |
| 1065 | int idx = -1;\r |
| 1066 | if (_data._expandedItems.length == 0) {\r |
| 1067 | return;\r |
| 1068 | }\r |
| 1069 | if (SWT.HOME == e.keyCode) {\r |
| 1070 | idx = 0;\r |
| 1071 | } else if (SWT.END == e.keyCode) {\r |
| 1072 | idx = _data._expandedItems.length - 1;\r |
| 1073 | } else if (SWT.ARROW_DOWN == e.keyCode) {\r |
| 1074 | idx = getSelectedIndex();\r |
| 1075 | if (idx < 0)\r |
| 1076 | idx = 0;\r |
| 1077 | else if (idx < _data._expandedItems.length - 1)\r |
| 1078 | idx++;\r |
| 1079 | } else if (SWT.ARROW_UP == e.keyCode) {\r |
| 1080 | idx = getSelectedIndex();\r |
| 1081 | if (idx < 0)\r |
| 1082 | idx = 0;\r |
| 1083 | else if (idx > 0)\r |
| 1084 | idx--;\r |
| 1085 | } else if (SWT.ARROW_LEFT == e.keyCode) {\r |
| 1086 | selectPrevEvent();\r |
| 1087 | } else if (SWT.ARROW_RIGHT == e.keyCode) {\r |
| 1088 | selectNextEvent();\r |
| 1089 | } else if (SWT.PAGE_DOWN == e.keyCode) {\r |
| 1090 | int page = countPerPage();\r |
| 1091 | idx = getSelectedIndex();\r |
| 1092 | if (idx < 0)\r |
| 1093 | idx = 0;\r |
| 1094 | idx += page;\r |
| 1095 | if (idx >= _data._expandedItems.length)\r |
| 1096 | idx = _data._expandedItems.length - 1;\r |
| 1097 | } else if (SWT.PAGE_UP == e.keyCode) {\r |
| 1098 | int page = countPerPage();\r |
| 1099 | idx = getSelectedIndex();\r |
| 1100 | if (idx < 0)\r |
| 1101 | idx = 0;\r |
| 1102 | idx -= page;\r |
| 1103 | if (idx < 0)\r |
| 1104 | idx = 0;\r |
| 1105 | } else if (SWT.CR == e.keyCode) {\r |
| 1106 | idx = getSelectedIndex();\r |
| 1107 | if (idx >= 0) {\r |
| 1108 | if (_data._expandedItems[idx]._hasChildren) {\r |
| 1109 | toggle(idx);\r |
| 1110 | } else {\r |
| 1111 | fireDefaultSelection();\r |
| 1112 | }\r |
| 1113 | }\r |
| 1114 | idx = -1;\r |
| 1115 | }\r |
| 1116 | if (idx >= 0) {\r |
| 1117 | selectItem(idx, false);\r |
| 1118 | fireSelectionChanged();\r |
| 1119 | }\r |
| 1120 | }\r |
| 1121 | \r |
| 1122 | @Override\r |
| 1123 | public void keyReleased(KeyEvent e) {\r |
| 1124 | }\r |
| 1125 | \r |
| 1126 | @Override\r |
| 1127 | public void focusGained(FocusEvent e) {\r |
| 1128 | _isInFocus = true;\r |
| 1129 | redraw();\r |
| 1130 | }\r |
| 1131 | \r |
| 1132 | @Override\r |
| 1133 | public void focusLost(FocusEvent e) {\r |
| 1134 | _isInFocus = false;\r |
| 1135 | if (DRAG_NONE != _dragState) {\r |
| 1136 | setCapture(false);\r |
| 1137 | _dragState = DRAG_NONE;\r |
| 1138 | }\r |
| 1139 | redraw();\r |
| 1140 | }\r |
| 1141 | \r |
| 1142 | public boolean isInFocus() {\r |
| 1143 | return _isInFocus;\r |
| 1144 | }\r |
| 1145 | \r |
| 1146 | /**\r |
| 1147 | * Provide the possibilty to control the wait cursor externally e.g. data\r |
| 1148 | * requests in progress\r |
| 1149 | * \r |
| 1150 | * @param waitInd\r |
| 1151 | */\r |
| 1152 | public void waitCursor(boolean waitInd) {\r |
| 1153 | // Update cursor as indicated\r |
| 1154 | if (waitInd) {\r |
| 1155 | setCursor(_WaitCursor);\r |
| 1156 | _isWaitCursor = true;\r |
| 1157 | } else {\r |
| 1158 | setCursor(null);\r |
| 1159 | _isWaitCursor = false;\r |
| 1160 | }\r |
| 1161 | \r |
| 1162 | // Get ready for next mouse move\r |
| 1163 | _isDragCursor3 = false;\r |
| 1164 | }\r |
| 1165 | \r |
| 1166 | /**\r |
| 1167 | * <p>\r |
| 1168 | * If the x, y position is over the vertical split line (name to time\r |
| 1169 | * ranges), then change the cursor to a drag cursor to indicate the user the\r |
| 1170 | * possibility of resizing\r |
| 1171 | * </p>\r |
| 1172 | * \r |
| 1173 | * @param x\r |
| 1174 | * @param y\r |
| 1175 | */\r |
| 1176 | void updateCursor(int x, int y) {\r |
| 1177 | // if Wait cursor not active, check for the need to change to a drag\r |
| 1178 | // cursor\r |
| 1179 | if (_isWaitCursor == false) {\r |
| 1180 | boolean isSplitLine = isOverSplitLine(x);\r |
| 1181 | // No dragcursor is name space is fixed to zero\r |
| 1182 | if (isSplitLine && !_isDragCursor3 && _timeProvider.getNameSpace() > 0) {\r |
| 1183 | setCursor(_dragCursor3);\r |
| 1184 | _isDragCursor3 = true;\r |
| 1185 | } else if (!isSplitLine && _isDragCursor3) {\r |
| 1186 | setCursor(null);\r |
| 1187 | _isDragCursor3 = false;\r |
| 1188 | }\r |
| 1189 | }\r |
| 1190 | }\r |
| 1191 | \r |
| 1192 | @Override\r |
| 1193 | public void mouseMove(MouseEvent e) {\r |
| 1194 | if (null == _timeProvider)\r |
| 1195 | return;\r |
| 1196 | Point size = getCtrlSize();\r |
| 1197 | if (DRAG_TRACE_ITEM == _dragState) {\r |
| 1198 | int nameWidth = _timeProvider.getNameSpace();\r |
| 1199 | int x = e.x - nameWidth;\r |
| 1200 | if (x > 0 && size.x > nameWidth && _dragX != x) {\r |
| 1201 | _dragX = x;\r |
| 1202 | double pixelsPerNanoSec = (size.x - nameWidth <= RIGHT_MARGIN) ? 0 : (double) (size.x - nameWidth - RIGHT_MARGIN) / (_time1bak - _time0bak);\r |
| 1203 | long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec));\r |
| 1204 | long time1 = _time1bak - timeDelta;\r |
| 1205 | long maxTime = _timeProvider.getMaxTime();\r |
| 1206 | if (time1 > maxTime)\r |
| 1207 | time1 = maxTime;\r |
| 1208 | long time0 = time1 - (_time1bak - _time0bak);\r |
| 1209 | if (time0 < _timeProvider.getMinTime()) {\r |
| 1210 | time0 = _timeProvider.getMinTime();\r |
| 1211 | time1 = time0 + (_time1bak - _time0bak);\r |
| 1212 | }\r |
| 1213 | _timeProvider.setStartFinishTime(time0, time1);\r |
| 1214 | }\r |
| 1215 | } else if (DRAG_SPLIT_LINE == _dragState) {\r |
| 1216 | _dragX = e.x;\r |
| 1217 | _timeProvider.setNameSpace(e.x);\r |
| 1218 | } else if (DRAG_NONE == _dragState) {\r |
| 1219 | boolean mouseOverSplitLine = isOverSplitLine(e.x);\r |
| 1220 | if (_mouseOverSplitLine != mouseOverSplitLine) {\r |
| 1221 | redraw();\r |
| 1222 | }\r |
| 1223 | _mouseOverSplitLine = mouseOverSplitLine;\r |
| 1224 | // Make sure any time changes are notified to the application e.g.\r |
| 1225 | // getting back from the horizontal scroll bar or zoomed using the\r |
| 1226 | // mouse wheel\r |
| 1227 | _timeProvider.notifyStartFinishTime();\r |
| 1228 | }\r |
| 1229 | updateCursor(e.x, e.y);\r |
| 1230 | }\r |
| 1231 | \r |
| 1232 | @Override\r |
| 1233 | public void mouseDoubleClick(MouseEvent e) {\r |
| 1234 | if (null == _timeProvider)\r |
| 1235 | return;\r |
| 1236 | if (1 == e.button) {\r |
| 1237 | if (isOverSplitLine(e.x) && _timeProvider.getNameSpace() != 0) {\r |
| 1238 | _timeProvider.setNameSpace(_idealNameSpace);\r |
| 1239 | boolean mouseOverSplitLine = isOverSplitLine(e.x);\r |
| 1240 | if (_mouseOverSplitLine != mouseOverSplitLine) {\r |
| 1241 | redraw();\r |
| 1242 | }\r |
| 1243 | _mouseOverSplitLine = mouseOverSplitLine;\r |
| 1244 | return;\r |
| 1245 | }\r |
| 1246 | int idx = getItemIndexAtY(e.y);\r |
| 1247 | if (idx >= 0) {\r |
| 1248 | selectItem(idx, false);\r |
| 1249 | fireDefaultSelection();\r |
| 1250 | }\r |
| 1251 | }\r |
| 1252 | }\r |
| 1253 | \r |
| 1254 | @Override\r |
| 1255 | public void mouseDown(MouseEvent e) {\r |
| 1256 | if (null == _timeProvider)\r |
| 1257 | return;\r |
| 1258 | int idx;\r |
| 1259 | if (1 == e.button) {\r |
| 1260 | int nameSpace = _timeProvider.getNameSpace();\r |
| 1261 | if (nameSpace != 0) {\r |
| 1262 | if (isOverSplitLine(e.x)) {\r |
| 1263 | _dragState = DRAG_SPLIT_LINE;\r |
| 1264 | _dragX = _dragX0 = e.x;\r |
| 1265 | _time0bak = _timeProvider.getTime0();\r |
| 1266 | _time1bak = _timeProvider.getTime1();\r |
| 1267 | redraw();\r |
| 1268 | return;\r |
| 1269 | }\r |
| 1270 | }\r |
| 1271 | \r |
| 1272 | idx = getItemIndexAtY(e.y);\r |
| 1273 | if (idx >= 0) {\r |
| 1274 | TimeGraphItem item = _data._expandedItems[idx];\r |
| 1275 | if (item._hasChildren && e.x < nameSpace && e.x < MARGIN + (item.level + 1) * EXPAND_SIZE) {\r |
| 1276 | toggle(idx);\r |
| 1277 | } else {\r |
| 1278 | long hitTime = getTimeAtX(e.x);\r |
| 1279 | if (hitTime >= 0) {\r |
| 1280 | // _timeProvider.setSelectedTimeInt(hitTime, false);\r |
| 1281 | setCapture(true);\r |
| 1282 | _dragState = DRAG_TRACE_ITEM;\r |
| 1283 | _dragX = _dragX0 = e.x - nameSpace;\r |
| 1284 | _time0bak = _timeProvider.getTime0();\r |
| 1285 | _time1bak = _timeProvider.getTime1();\r |
| 1286 | }\r |
| 1287 | }\r |
| 1288 | selectItem(idx, false);\r |
| 1289 | fireSelectionChanged();\r |
| 1290 | } else {\r |
| 1291 | selectItem(idx, false); // clear selection\r |
| 1292 | redraw();\r |
| 1293 | fireSelectionChanged();\r |
| 1294 | }\r |
| 1295 | }\r |
| 1296 | }\r |
| 1297 | \r |
| 1298 | @Override\r |
| 1299 | public void mouseUp(MouseEvent e) {\r |
| 1300 | if (DRAG_NONE != _dragState) {\r |
| 1301 | setCapture(false);\r |
| 1302 | if (DRAG_TRACE_ITEM == _dragState) {\r |
| 1303 | // Notify time provider to check the need for listener\r |
| 1304 | // notification\r |
| 1305 | _timeProvider.notifyStartFinishTime();\r |
| 1306 | if (_dragX == _dragX0) { // click without drag\r |
| 1307 | long time = getTimeAtX(e.x);\r |
| 1308 | _timeProvider.setSelectedTimeInt(time, false);\r |
| 1309 | }\r |
| 1310 | } else if (DRAG_SPLIT_LINE == _dragState) {\r |
| 1311 | redraw();\r |
| 1312 | }\r |
| 1313 | _dragState = DRAG_NONE;\r |
| 1314 | }\r |
| 1315 | }\r |
| 1316 | \r |
| 1317 | @Override\r |
| 1318 | public void mouseEnter(MouseEvent e) {\r |
| 1319 | if (mouseScrollFilterListener == null) {\r |
| 1320 | mouseScrollFilterListener = new Listener() {\r |
| 1321 | // This filter is used to prevent scrolling of the view when the\r |
| 1322 | // mouse wheel is used to zoom\r |
| 1323 | @Override\r |
| 1324 | public void handleEvent(Event event) {\r |
| 1325 | event.doit = false;\r |
| 1326 | }\r |
| 1327 | };\r |
| 1328 | getDisplay().addFilter(SWT.MouseWheel, mouseScrollFilterListener);\r |
| 1329 | }\r |
| 1330 | }\r |
| 1331 | \r |
| 1332 | @Override\r |
| 1333 | public void mouseExit(MouseEvent e) {\r |
| 1334 | if (mouseScrollFilterListener != null) {\r |
| 1335 | getDisplay().removeFilter(SWT.MouseWheel, mouseScrollFilterListener);\r |
| 1336 | mouseScrollFilterListener = null;\r |
| 1337 | }\r |
| 1338 | if (_mouseOverSplitLine) {\r |
| 1339 | _mouseOverSplitLine = false;\r |
| 1340 | redraw();\r |
| 1341 | }\r |
| 1342 | }\r |
| 1343 | \r |
| 1344 | @Override\r |
| 1345 | public void mouseHover(MouseEvent e) {\r |
| 1346 | }\r |
| 1347 | \r |
| 1348 | @Override\r |
| 1349 | public void mouseScrolled(MouseEvent e) {\r |
| 1350 | if ((mouseScrollFilterListener == null) || _dragState != DRAG_NONE) {\r |
| 1351 | return;\r |
| 1352 | }\r |
| 1353 | if (e.x < _timeProvider.getNameSpace() || e.x > getSize().x) {\r |
| 1354 | setTopIndex(getTopIndex() - e.count);\r |
| 1355 | } else if (_timeProvider.getTime0() != _timeProvider.getTime1()) {\r |
| 1356 | if (e.count > 0) {\r |
| 1357 | zoom(true);\r |
| 1358 | } else if (e.count < 0) {\r |
| 1359 | zoom(false);\r |
| 1360 | }\r |
| 1361 | }\r |
| 1362 | }\r |
| 1363 | \r |
| 1364 | @Override\r |
| 1365 | public void controlMoved(ControlEvent e) {\r |
| 1366 | }\r |
| 1367 | \r |
| 1368 | @Override\r |
| 1369 | public void controlResized(ControlEvent e) {\r |
| 1370 | adjustScrolls();\r |
| 1371 | }\r |
| 1372 | \r |
| 1373 | @Override\r |
| 1374 | public void widgetDefaultSelected(SelectionEvent e) {\r |
| 1375 | }\r |
| 1376 | \r |
| 1377 | @Override\r |
| 1378 | public void widgetSelected(SelectionEvent e) {\r |
| 1379 | if (e.widget == getVerticalBar()) {\r |
| 1380 | setTopIndex(getVerticalBar().getSelection());\r |
| 1381 | } else if (e.widget == getHorizontalBar() && null != _timeProvider) {\r |
| 1382 | int start = getHorizontalBar().getSelection();\r |
| 1383 | long time0 = _timeProvider.getTime0();\r |
| 1384 | long time1 = _timeProvider.getTime1();\r |
| 1385 | long timeMin = _timeProvider.getMinTime();\r |
| 1386 | long timeMax = _timeProvider.getMaxTime();\r |
| 1387 | long delta = timeMax - timeMin;\r |
| 1388 | \r |
| 1389 | long range = time1 - time0;\r |
| 1390 | // _timeRangeFixed = true;\r |
| 1391 | time0 = timeMin + Math.round(delta * ((double) start / H_SCROLLBAR_MAX));\r |
| 1392 | time1 = time0 + range;\r |
| 1393 | \r |
| 1394 | // TODO: Follow-up with Bug 310310\r |
| 1395 | // In Linux SWT.DRAG is the only value received\r |
| 1396 | // https://bugs.eclipse.org/bugs/show_bug.cgi?id=310310\r |
| 1397 | if (e.detail == SWT.DRAG) {\r |
| 1398 | _timeProvider.setStartFinishTime(time0, time1);\r |
| 1399 | } else {\r |
| 1400 | _timeProvider.setStartFinishTimeNotify(time0, time1);\r |
| 1401 | }\r |
| 1402 | }\r |
| 1403 | }\r |
| 1404 | \r |
| 1405 | public boolean isVisibleVerticalScroll() {\r |
| 1406 | return _visibleVerticalScroll;\r |
| 1407 | }\r |
| 1408 | \r |
| 1409 | @Override\r |
| 1410 | public int getBorderWidth() {\r |
| 1411 | return _borderWidth;\r |
| 1412 | }\r |
| 1413 | \r |
| 1414 | public void setBorderWidth(int borderWidth) {\r |
| 1415 | this._borderWidth = borderWidth;\r |
| 1416 | }\r |
| 1417 | \r |
| 1418 | public int getHeaderHeight() {\r |
| 1419 | return _headerHeight;\r |
| 1420 | }\r |
| 1421 | \r |
| 1422 | public void setHeaderHeight(int headerHeight) {\r |
| 1423 | this._headerHeight = headerHeight;\r |
| 1424 | }\r |
| 1425 | \r |
| 1426 | public int getItemHeight() {\r |
| 1427 | return _itemHeight;\r |
| 1428 | }\r |
| 1429 | \r |
| 1430 | public void setItemHeight(int rowHeight) {\r |
| 1431 | this._itemHeight = rowHeight;\r |
| 1432 | }\r |
| 1433 | \r |
| 1434 | public void setMinimumItemWidth(int width) {\r |
| 1435 | this._minimumItemWidth = width;\r |
| 1436 | }\r |
| 1437 | \r |
| 1438 | public int getMinimumItemWidth() {\r |
| 1439 | return _minimumItemWidth;\r |
| 1440 | }\r |
| 1441 | \r |
| 1442 | public Vector<ITimeGraphEntry> getFilteredOut() {\r |
| 1443 | return _data.getFilteredOut();\r |
| 1444 | }\r |
| 1445 | \r |
| 1446 | // @Override\r |
| 1447 | @Override\r |
| 1448 | public void addSelectionChangedListener(ISelectionChangedListener listener) {\r |
| 1449 | if (listener != null) {\r |
| 1450 | if (!_selectionChangedListeners.contains(listener)) {\r |
| 1451 | _selectionChangedListeners.add(listener);\r |
| 1452 | }\r |
| 1453 | }\r |
| 1454 | }\r |
| 1455 | \r |
| 1456 | // @Override\r |
| 1457 | @Override\r |
| 1458 | public void removeSelectionChangedListener(ISelectionChangedListener listener) {\r |
| 1459 | if (listener != null) {\r |
| 1460 | _selectionChangedListeners.remove(listener);\r |
| 1461 | }\r |
| 1462 | }\r |
| 1463 | \r |
| 1464 | // @Override\r |
| 1465 | @Override\r |
| 1466 | public void setSelection(ISelection selection) {\r |
| 1467 | if (selection instanceof TimeGraphSelection) {\r |
| 1468 | TimeGraphSelection sel = (TimeGraphSelection) selection;\r |
| 1469 | Object ob = sel.getFirstElement();\r |
| 1470 | if (ob instanceof ITimeGraphEntry) {\r |
| 1471 | ITimeGraphEntry trace = (ITimeGraphEntry) ob;\r |
| 1472 | selectItem(trace, false);\r |
| 1473 | }\r |
| 1474 | }\r |
| 1475 | \r |
| 1476 | }\r |
| 1477 | \r |
| 1478 | }\r |
| 1479 | \r |
| 1480 | class ItemData {\r |
| 1481 | public TimeGraphItem[] _expandedItems = new TimeGraphItem[0];\r |
| 1482 | public TimeGraphItem[] _items = new TimeGraphItem[0];\r |
| 1483 | private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0];\r |
| 1484 | private boolean traceFilter[] = new boolean[0];\r |
| 1485 | private Vector<ITimeGraphEntry> filteredOut = new Vector<ITimeGraphEntry>();\r |
| 1486 | public ITimeGraphPresentationProvider provider;\r |
| 1487 | \r |
| 1488 | public ItemData() {\r |
| 1489 | }\r |
| 1490 | \r |
| 1491 | TimeGraphItem findItem(ITimeGraphEntry entry) {\r |
| 1492 | if (entry == null)\r |
| 1493 | return null;\r |
| 1494 | \r |
| 1495 | for (int i = 0; i < _items.length; i++) {\r |
| 1496 | TimeGraphItem item = _items[i];\r |
| 1497 | if (item._trace == entry) {\r |
| 1498 | return item;\r |
| 1499 | }\r |
| 1500 | }\r |
| 1501 | \r |
| 1502 | return null;\r |
| 1503 | }\r |
| 1504 | \r |
| 1505 | int findItemIndex(ITimeGraphEntry trace) {\r |
| 1506 | if (trace == null)\r |
| 1507 | return -1;\r |
| 1508 | \r |
| 1509 | for (int i = 0; i < _expandedItems.length; i++) {\r |
| 1510 | TimeGraphItem item = _expandedItems[i];\r |
| 1511 | if (item._trace == trace) {\r |
| 1512 | return i;\r |
| 1513 | }\r |
| 1514 | }\r |
| 1515 | \r |
| 1516 | return -1;\r |
| 1517 | }\r |
| 1518 | \r |
| 1519 | public void refreshData() {\r |
| 1520 | List<TimeGraphItem> itemList = new ArrayList<TimeGraphItem>();\r |
| 1521 | filteredOut.clear();\r |
| 1522 | for (int i = 0; i < _traces.length; i++) {\r |
| 1523 | ITimeGraphEntry entry = _traces[i];\r |
| 1524 | refreshData(itemList, null, 0, entry);\r |
| 1525 | }\r |
| 1526 | _items = itemList.toArray(new TimeGraphItem[0]);\r |
| 1527 | updateExpandedItems();\r |
| 1528 | }\r |
| 1529 | \r |
| 1530 | private void refreshData(List<TimeGraphItem> itemList, TimeGraphItem parent, int level, ITimeGraphEntry entry) {\r |
| 1531 | TimeGraphItem item = new TimeGraphItem(entry, entry.getName(), level);\r |
| 1532 | if (parent != null) {\r |
| 1533 | parent.children.add(item);\r |
| 1534 | }\r |
| 1535 | item.itemHeight = provider.getItemHeight(entry);\r |
| 1536 | itemList.add(item);\r |
| 1537 | if (entry.hasChildren()) {\r |
| 1538 | item._expanded = true;\r |
| 1539 | item._hasChildren = true;\r |
| 1540 | for (ITimeGraphEntry child : entry.getChildren()) {\r |
| 1541 | refreshData(itemList, item, level + 1, child);\r |
| 1542 | }\r |
| 1543 | }\r |
| 1544 | }\r |
| 1545 | \r |
| 1546 | public void updateExpandedItems() {\r |
| 1547 | List<TimeGraphItem> expandedItemList = new ArrayList<TimeGraphItem>();\r |
| 1548 | for (int i = 0; i < _traces.length; i++) {\r |
| 1549 | ITimeGraphEntry entry = _traces[i];\r |
| 1550 | TimeGraphItem item = findItem(entry);\r |
| 1551 | refreshExpanded(expandedItemList, item);\r |
| 1552 | }\r |
| 1553 | _expandedItems = expandedItemList.toArray(new TimeGraphItem[0]);\r |
| 1554 | }\r |
| 1555 | \r |
| 1556 | private void refreshExpanded(List<TimeGraphItem> expandedItemList, TimeGraphItem item) {\r |
| 1557 | expandedItemList.add(item);\r |
| 1558 | if (item._hasChildren && item._expanded) {\r |
| 1559 | for (TimeGraphItem child : item.children) {\r |
| 1560 | refreshExpanded(expandedItemList, child);\r |
| 1561 | }\r |
| 1562 | }\r |
| 1563 | }\r |
| 1564 | \r |
| 1565 | public void expandItem(int idx) {\r |
| 1566 | if (idx < 0 || idx >= _expandedItems.length)\r |
| 1567 | return;\r |
| 1568 | TimeGraphItem item = (TimeGraphItem) _expandedItems[idx];\r |
| 1569 | if (item._hasChildren && !item._expanded) {\r |
| 1570 | item._expanded = true;\r |
| 1571 | updateExpandedItems();\r |
| 1572 | }\r |
| 1573 | }\r |
| 1574 | \r |
| 1575 | public void refreshData(ITimeGraphEntry traces[]) {\r |
| 1576 | if (traces == null || traces.length == 0) {\r |
| 1577 | traceFilter = null;\r |
| 1578 | } else if (traceFilter == null || traces.length != traceFilter.length) {\r |
| 1579 | traceFilter = new boolean[traces.length];\r |
| 1580 | java.util.Arrays.fill(traceFilter, true);\r |
| 1581 | }\r |
| 1582 | \r |
| 1583 | _traces = traces;\r |
| 1584 | refreshData();\r |
| 1585 | }\r |
| 1586 | \r |
| 1587 | public ITimeGraphEntry[] getTraces() {\r |
| 1588 | return _traces;\r |
| 1589 | }\r |
| 1590 | \r |
| 1591 | public boolean[] getTraceFilter() {\r |
| 1592 | return traceFilter;\r |
| 1593 | }\r |
| 1594 | \r |
| 1595 | public Vector<ITimeGraphEntry> getFilteredOut() {\r |
| 1596 | return filteredOut;\r |
| 1597 | }\r |
| 1598 | }\r |