import org.eclipse.swt.widgets.Listener;\r
import org.eclipse.swt.widgets.ScrollBar;\r
\r
+/**\r
+ * Time graph control implementation\r
+ *\r
+ * @version 1.0\r
+ * @author Alvaro Sanchez-Leon\r
+ * @author Patrick Tasse\r
+ */\r
public class TimeGraphControl extends TimeGraphBaseControl implements FocusListener, KeyListener, MouseMoveListener, MouseListener, MouseWheelListener, ControlListener, SelectionListener, MouseTrackListener, TraverseListener, ISelectionProvider {\r
\r
private static final int DRAG_NONE = 0;\r
private ITimeGraphPresentationProvider fTimeGraphProvider = null;\r
private ItemData _data = null;\r
private List<SelectionListener> _selectionListeners;\r
- private List<ISelectionChangedListener> _selectionChangedListeners = new ArrayList<ISelectionChangedListener>();\r
- private List<ITimeGraphTreeListener> _treeListeners = new ArrayList<ITimeGraphTreeListener>();\r
- private Cursor _dragCursor3;\r
- private Cursor _WaitCursor;\r
+ private final List<ISelectionChangedListener> _selectionChangedListeners = new ArrayList<ISelectionChangedListener>();\r
+ private final List<ITimeGraphTreeListener> _treeListeners = new ArrayList<ITimeGraphTreeListener>();\r
+ private final Cursor _dragCursor3;\r
+ private final Cursor _WaitCursor;\r
\r
// Vertical formatting formatting for the state control view\r
- private boolean _visibleVerticalScroll = true;\r
+ private final boolean _visibleVerticalScroll = true;\r
private int _borderWidth = 0;\r
private int _headerHeight = 0;\r
\r
protected Color[] fEventColorMap = null;\r
\r
private MouseScrollNotifier fMouseScrollNotifier;\r
- private Object fMouseScrollNotifierLock = new Object();\r
+ private final Object fMouseScrollNotifierLock = new Object();\r
private class MouseScrollNotifier extends Thread {\r
private final static long DELAY = 400L;\r
private final static long POLLING_INTERVAL = 10L;\r
\r
/**\r
* Sets the timegraph provider used by this timegraph viewer.\r
- * \r
+ *\r
* @param timeGraphProvider the timegraph provider\r
*/\r
public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {\r
}\r
\r
public void addSelectionListener(SelectionListener listener) {\r
- if (listener == null)\r
+ if (listener == null) {\r
SWT.error(SWT.ERROR_NULL_ARGUMENT);\r
- if (null == _selectionListeners)\r
+ }\r
+ if (null == _selectionListeners) {\r
_selectionListeners = new ArrayList<SelectionListener>();\r
+ }\r
_selectionListeners.add(listener);\r
}\r
\r
public void removeSelectionListener(SelectionListener listener) {\r
- if (null != _selectionListeners)\r
+ if (null != _selectionListeners) {\r
_selectionListeners.remove(listener);\r
+ }\r
}\r
\r
public void fireSelectionChanged() {\r
boolean changed = false;\r
if (idx < 0) {\r
for (idx = 0; idx < _data._expandedItems.length; idx++) {\r
- if (((Item) _data._expandedItems[idx])._selected)\r
+ if (((Item) _data._expandedItems[idx])._selected) {\r
break;\r
+ }\r
}\r
}\r
- if (idx >= _data._expandedItems.length)\r
+ if (idx >= _data._expandedItems.length) {\r
return changed;\r
+ }\r
if (idx < _topIndex) {\r
setTopIndex(idx);\r
//FIXME:getVerticalBar().setSelection(_topItem);\r
- if (redraw)\r
+ if (redraw) {\r
redraw();\r
+ }\r
changed = true;\r
} else {\r
int page = countPerPage();\r
if (idx >= _topIndex + page) {\r
setTopIndex(idx - page + 1);\r
//FIXME:getVerticalBar().setSelection(_topItem);\r
- if (redraw)\r
+ if (redraw) {\r
redraw();\r
+ }\r
changed = true;\r
}\r
}\r
if (null != trace && null != _timeProvider) {\r
long selectedTime = _timeProvider.getSelectedTime();\r
ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);\r
- if (event != null)\r
+ if (event != null) {\r
sel.add(event);\r
- else\r
+ } else {\r
sel.add(trace);\r
+ }\r
}\r
return sel;\r
}\r
return sel;\r
}\r
\r
- \r
+\r
// TODO select implementation for selectTrace\r
// public void selectTrace(int n) {\r
// if (n != 1 && n != -1)\r
fireSelectionChanged();\r
}\r
}\r
- \r
+\r
public void selectEvent(int n) {\r
- if (null == _timeProvider)\r
+ if (null == _timeProvider) {\r
return;\r
+ }\r
ITimeGraphEntry trace = getSelectedTrace();\r
- if (trace == null)\r
+ if (trace == null) {\r
return;\r
+ }\r
long selectedTime = _timeProvider.getSelectedTime();\r
long endTime = _timeProvider.getEndTime();\r
ITimeEvent nextEvent;\r
- if (-1 == n && selectedTime > endTime)\r
+ if (-1 == n && selectedTime > endTime) {\r
nextEvent = Utils.findEvent(trace, selectedTime, 0);\r
- else\r
+ } else {\r
nextEvent = Utils.findEvent(trace, selectedTime, n);\r
- if (null == nextEvent && -1 == n)\r
+ }\r
+ if (null == nextEvent && -1 == n) {\r
nextEvent = Utils.getFirstEvent(trace);\r
+ }\r
if (null != nextEvent) {\r
long nextTime = nextEvent.getTime();\r
// If last event detected e.g. going back or not moving to a next\r
\r
/**\r
* Zoom based on mouse cursor location with mouse scrolling\r
- * \r
+ *\r
* @param zoomIn true to zoom in, false to zoom out\r
*/\r
public void zoom(boolean zoomIn) {\r
public ITimeGraphEntry getSelectedTrace() {\r
ITimeGraphEntry trace = null;\r
int idx = getSelectedIndex();\r
- if (idx >= 0)\r
+ if (idx >= 0) {\r
trace = _data._expandedItems[idx]._trace;\r
+ }\r
return trace;\r
}\r
\r
}\r
\r
boolean isOverSplitLine(int x) {\r
- if (x < 0 || null == _timeProvider)\r
+ if (x < 0 || null == _timeProvider) {\r
return false;\r
+ }\r
int w = 4;\r
int nameWidth = _timeProvider.getNameSpace();\r
if (x > nameWidth - w && x < nameWidth + w) {\r
}\r
\r
long getTimeAtX(int x) {\r
- if (null == _timeProvider)\r
+ if (null == _timeProvider) {\r
return -1;\r
+ }\r
long hitTime = -1;\r
Point size = getCtrlSize();\r
long time0 = _timeProvider.getTime0();\r
}\r
}\r
changed |= ensureVisibleItem(idx, true);\r
- if (changed)\r
+ if (changed) {\r
redraw();\r
+ }\r
}\r
\r
public void selectItem(ITimeGraphEntry trace, boolean addSelection) {\r
gc.setBackground(_colors.getColor(TimeGraphColorScheme.BACKGROUND));\r
drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height);\r
\r
- if (bounds.width < 2 || bounds.height < 2 || null == _timeProvider)\r
+ if (bounds.width < 2 || bounds.height < 2 || null == _timeProvider) {\r
return;\r
+ }\r
\r
_idealNameSpace = 0;\r
int nameSpace = _timeProvider.getNameSpace();\r
\r
/**\r
* Draws the item\r
- * \r
+ *\r
* @param item the item to draw\r
* @param bounds the container rectangle\r
* @param i the item index\r
} else {\r
stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);\r
}\r
- \r
+\r
timeSelected = timeSelected && selected;\r
if (timeSelected) {\r
// modify the color?\r
\r
@Override\r
public void keyTraversed(TraverseEvent e) {\r
- if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS))\r
+ if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {\r
e.doit = true;\r
+ }\r
}\r
\r
@Override\r
idx = _data._expandedItems.length - 1;\r
} else if (SWT.ARROW_DOWN == e.keyCode) {\r
idx = getSelectedIndex();\r
- if (idx < 0)\r
+ if (idx < 0) {\r
idx = 0;\r
- else if (idx < _data._expandedItems.length - 1)\r
+ } else if (idx < _data._expandedItems.length - 1) {\r
idx++;\r
+ }\r
} else if (SWT.ARROW_UP == e.keyCode) {\r
idx = getSelectedIndex();\r
- if (idx < 0)\r
+ if (idx < 0) {\r
idx = 0;\r
- else if (idx > 0)\r
+ } else if (idx > 0) {\r
idx--;\r
+ }\r
} else if (SWT.ARROW_LEFT == e.keyCode) {\r
selectPrevEvent();\r
} else if (SWT.ARROW_RIGHT == e.keyCode) {\r
} else if (SWT.PAGE_DOWN == e.keyCode) {\r
int page = countPerPage();\r
idx = getSelectedIndex();\r
- if (idx < 0)\r
+ if (idx < 0) {\r
idx = 0;\r
+ }\r
idx += page;\r
- if (idx >= _data._expandedItems.length)\r
+ if (idx >= _data._expandedItems.length) {\r
idx = _data._expandedItems.length - 1;\r
+ }\r
} else if (SWT.PAGE_UP == e.keyCode) {\r
int page = countPerPage();\r
idx = getSelectedIndex();\r
- if (idx < 0)\r
+ if (idx < 0) {\r
idx = 0;\r
+ }\r
idx -= page;\r
- if (idx < 0)\r
+ if (idx < 0) {\r
idx = 0;\r
+ }\r
} else if (SWT.CR == e.keyCode) {\r
idx = getSelectedIndex();\r
if (idx >= 0) {\r
/**\r
* Provide the possibilty to control the wait cursor externally e.g. data\r
* requests in progress\r
- * \r
+ *\r
* @param waitInd\r
*/\r
public void waitCursor(boolean waitInd) {\r
* ranges), then change the cursor to a drag cursor to indicate the user the\r
* possibility of resizing\r
* </p>\r
- * \r
+ *\r
* @param x\r
* @param y\r
*/\r
\r
@Override\r
public void mouseMove(MouseEvent e) {\r
- if (null == _timeProvider)\r
+ if (null == _timeProvider) {\r
return;\r
+ }\r
Point size = getCtrlSize();\r
if (DRAG_TRACE_ITEM == _dragState) {\r
int nameWidth = _timeProvider.getNameSpace();\r
long timeDelta = (long) ((pixelsPerNanoSec == 0) ? 0 : ((_dragX - _dragX0) / pixelsPerNanoSec));\r
long time1 = _time1bak - timeDelta;\r
long maxTime = _timeProvider.getMaxTime();\r
- if (time1 > maxTime)\r
+ if (time1 > maxTime) {\r
time1 = maxTime;\r
+ }\r
long time0 = time1 - (_time1bak - _time0bak);\r
if (time0 < _timeProvider.getMinTime()) {\r
time0 = _timeProvider.getMinTime();\r
\r
@Override\r
public void mouseDoubleClick(MouseEvent e) {\r
- if (null == _timeProvider)\r
+ if (null == _timeProvider) {\r
return;\r
+ }\r
if (1 == e.button) {\r
if (isOverSplitLine(e.x) && _timeProvider.getNameSpace() != 0) {\r
_timeProvider.setNameSpace(_idealNameSpace);\r
\r
@Override\r
public void mouseDown(MouseEvent e) {\r
- if (null == _timeProvider)\r
+ if (null == _timeProvider) {\r
return;\r
+ }\r
int idx;\r
if (1 == e.button) {\r
int nameSpace = _timeProvider.getNameSpace();\r
public Item[] _items = new Item[0];\r
private ITimeGraphEntry _traces[] = new ITimeGraphEntry[0];\r
private boolean traceFilter[] = new boolean[0];\r
- private Vector<ITimeGraphEntry> filteredOut = new Vector<ITimeGraphEntry>();\r
+ private final Vector<ITimeGraphEntry> filteredOut = new Vector<ITimeGraphEntry>();\r
public ITimeGraphPresentationProvider provider;\r
\r
public ItemData() {\r
}\r
\r
Item findItem(ITimeGraphEntry entry) {\r
- if (entry == null)\r
+ if (entry == null) {\r
return null;\r
+ }\r
\r
for (int i = 0; i < _items.length; i++) {\r
Item item = _items[i];\r
}\r
\r
int findItemIndex(ITimeGraphEntry trace) {\r
- if (trace == null)\r
+ if (trace == null) {\r
return -1;\r
+ }\r
\r
for (int i = 0; i < _expandedItems.length; i++) {\r
Item item = _expandedItems[i];\r
}\r
\r
public void expandItem(int idx) {\r
- if (idx < 0 || idx >= _expandedItems.length)\r
+ if (idx < 0 || idx >= _expandedItems.length) {\r
return;\r
+ }\r
Item item = (Item) _expandedItems[idx];\r
if (item._hasChildren && !item._expanded) {\r
item._expanded = true;\r