/*****************************************************************************
- * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.
+ * Copyright (c) 2007, 2013 Intel Corporation, Ericsson.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* Ruslan A. Scherbakov, Intel - Initial API and implementation
* Alvaro Sanchez-Leon - Updated for TMF
* Patrick Tasse - Refactoring
- *
*****************************************************************************/
package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTreeListener;
import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
*/
public class TimeGraphControl extends TimeGraphBaseControl implements FocusListener, KeyListener, MouseMoveListener, MouseListener, MouseWheelListener, ControlListener, SelectionListener, MouseTrackListener, TraverseListener, ISelectionProvider, MenuDetectListener {
+ /** Max scrollbar size */
+ public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
+
+ /** Resource manager */
+ protected LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
+
+ /** Color map for event types */
+ protected Color[] fEventColorMap = null;
+
private static final int DRAG_NONE = 0;
private static final int DRAG_TRACE_ITEM = 1;
private static final int DRAG_SPLIT_LINE = 2;
private static final int DRAG_ZOOM = 3;
- public static final boolean DEFAULT_DRAW_THREAD_JOIN = true;
- public static final boolean DEFAULT_DRAW_THREAD_WAIT = true;
- public static final boolean DEFAULT_DRAW_THREAD_RELEASE = true;
- public static final int H_SCROLLBAR_MAX = Integer.MAX_VALUE - 1;
+
private static final int CUSTOM_ITEM_HEIGHT = -1; // get item height from provider
private static final double zoomCoeff = 1.5;
private final List<MenuDetectListener> _timeEventMenuListeners = new ArrayList<MenuDetectListener>();
private final Cursor _dragCursor3;
private final Cursor _WaitCursor;
+ private final List<ViewerFilter> _filters = new ArrayList<ViewerFilter>();
// Vertical formatting formatting for the state control view
private final boolean _visibleVerticalScroll = true;
private Listener mouseScrollFilterListener;
- protected LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
- protected Color[] fEventColorMap = null;
-
private MouseScrollNotifier fMouseScrollNotifier;
private final Object fMouseScrollNotifierLock = new Object();
private class MouseScrollNotifier extends Thread {
boolean ensureVisibleItem(int idx, boolean redraw) {
boolean changed = false;
- if (idx < 0) {
- for (idx = 0; idx < _data._expandedItems.length; idx++) {
- if (_data._expandedItems[idx]._selected) {
+ int index = idx;
+ if (index < 0) {
+ for (index = 0; index < _data._expandedItems.length; index++) {
+ if (_data._expandedItems[index]._selected) {
break;
}
}
}
- if (idx >= _data._expandedItems.length) {
+ if (index >= _data._expandedItems.length) {
return changed;
}
- if (idx < _topIndex) {
- setTopIndex(idx);
+ if (index < _topIndex) {
+ setTopIndex(index);
//FIXME:getVerticalBar().setSelection(_topItem);
if (redraw) {
redraw();
changed = true;
} else {
int page = countPerPage();
- if (idx >= _topIndex + page) {
- setTopIndex(idx - page + 1);
+ if (index >= _topIndex + page) {
+ setTopIndex(index - page + 1);
//FIXME:getVerticalBar().setSelection(_topItem);
if (redraw) {
redraw();
* The index
*/
public void setTopIndex(int idx) {
- idx = Math.min(idx, _data._expandedItems.length - countPerPage());
- idx = Math.max(0, idx);
- _topIndex = idx;
+ int index = Math.min(idx, _data._expandedItems.length - countPerPage());
+ index = Math.max(0, index);
+ _topIndex = index;
redraw();
}
return idx >= 0 ? _data._expandedItems[idx]._trace : null;
}
- long getTimeAtX(int x) {
+ /**
+ * Return the x coordinate corresponding to a time
+ *
+ * @param time the time
+ * @return the x coordinate corresponding to the time
+ *
+ * @since 2.0
+ */
+ public int getXForTime(long time) {
+ if (null == _timeProvider) {
+ return -1;
+ }
+ long time0 = _timeProvider.getTime0();
+ long time1 = _timeProvider.getTime1();
+ int width = getCtrlSize().x;
+ int nameSpace = _timeProvider.getNameSpace();
+ double pixelsPerNanoSec = (width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (width - nameSpace - RIGHT_MARGIN) / (time1 - time0);
+ int x = getBounds().x + nameSpace + (int) ((time - time0) * pixelsPerNanoSec);
+ return x;
+ }
+
+ /**
+ * Return the time corresponding to an x coordinate
+ *
+ * @param coord The X coordinate
+ * @return The time corresponding to the x coordinate
+ *
+ * @since 2.0
+ */
+ public long getTimeAtX(int coord) {
if (null == _timeProvider) {
return -1;
}
long time0 = _timeProvider.getTime0();
long time1 = _timeProvider.getTime1();
int nameWidth = _timeProvider.getNameSpace();
- x -= nameWidth;
+ final int x = coord - nameWidth;
int timeWidth = size.x - nameWidth - RIGHT_MARGIN;
if (x >= 0 && size.x >= nameWidth) {
if (time1 - time0 > timeWidth) {
*
* @param item the item to draw
* @param bounds the container rectangle
+ * @param timeProvider Time provider
* @param i the item index
* @param nameSpace the name space
- * @param gc
+ * @param gc Graphics context
*/
protected void drawItem(Item item, Rectangle bounds, ITimeDataProvider timeProvider, int i, int nameSpace, GC gc) {
ITimeGraphEntry entry = item._trace;
gc.drawPoint(stateRect.x, stateRect.y - 2);
stateRect.x += 1;
}
- } else {
- lastX = x;
}
boolean timeSelected = selectedTime >= event.getTime() && selectedTime < event.getTime() + event.getDuration();
- drawState(_colors, event, stateRect, gc, selected, timeSelected);
+ if (drawState(_colors, event, stateRect, gc, selected, timeSelected)) {
+ lastX = x;
+ }
}
}
fTimeGraphProvider.postDrawEntry(entry, rect, gc);
}
+ /**
+ * Draw the name of an item.
+ *
+ * @param item
+ * Item object
+ * @param bounds
+ * Where to draw the name
+ * @param gc
+ * Graphics context
+ */
protected void drawName(Item item, Rectangle bounds, GC gc) {
boolean hasTimeEvents = item._trace.hasTimeEvents();
if (! hasTimeEvents) {
}
}
- protected void drawState(TimeGraphColorScheme colors, ITimeEvent event,
+ /**
+ * Draw the state (color fill)
+ *
+ * @param colors
+ * Color scheme
+ * @param event
+ * Time event for which we're drawing the state
+ * @param rect
+ * Where to draw
+ * @param gc
+ * Graphics context
+ * @param selected
+ * Is this time event currently selected (so it appears
+ * highlighted)
+ * @param timeSelected
+ * Is the timestamp currently selected
+ * @return true if the state was drawn
+ * @since 2.0
+ */
+ protected boolean drawState(TimeGraphColorScheme colors, ITimeEvent event,
Rectangle rect, GC gc, boolean selected, boolean timeSelected) {
int colorIdx = fTimeGraphProvider.getStateTableIndex(event);
- if (colorIdx < 0) {
- return;
+ if (colorIdx < 0 && colorIdx != ITimeGraphPresentationProvider.TRANSPARENT) {
+ return false;
}
boolean visible = rect.width == 0 ? false : true;
if (visible) {
+ if (colorIdx == ITimeGraphPresentationProvider.TRANSPARENT) {
+ // Only draw the top and bottom borders
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
+ gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
+ if (rect.width == 1) {
+ gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawPoint(rect.x, rect.y - 2);
+ }
+ return false;
+ }
Color stateColor = null;
if (colorIdx < fEventColorMap.length) {
stateColor = fEventColorMap[colorIdx];
stateColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
}
- timeSelected = timeSelected && selected;
- if (timeSelected) {
+ boolean reallySelected = timeSelected && selected;
+ if (reallySelected) {
// modify the color?
}
// fill all rect area
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
// draw bounds
- if (!timeSelected) {
+ if (!reallySelected) {
// Draw the top and bottom borders i.e. no side borders
- // top
gc.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
- // bottom
gc.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
}
} else {
gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
gc.drawPoint(rect.x, rect.y - 2);
- /*
- // selected rectangle area is not visible but can be represented
- // with a broken vertical line of specified width.
- int width = 1;
- rect.width = width;
- gc.setForeground(stateColor);
- int s = gc.getLineStyle();
- int w = gc.getLineWidth();
- gc.setLineStyle(SWT.LINE_DOT);
- gc.setLineWidth(width);
- // Trace.debug("Rectangle not visible, drawing vertical line with: "
- // + rect.x + "," + rect.y + "," + rect.x + "," + rect.y
- // + rect.height);
- gc.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1);
- gc.setLineStyle(s);
- gc.setLineWidth(w);
- if (!timeSelected) {
- gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
- gc.drawPoint(rect.x, rect.y);
- gc.drawPoint(rect.x, rect.y + rect.height - 1);
- }
- */
}
fTimeGraphProvider.postDrawEvent(event, rect, gc);
+ return visible;
}
+ /**
+ * Fill the space between two contiguous time events
+ *
+ * @param rect
+ * Rectangle to fill
+ * @param gc
+ * Graphics context
+ * @param selected
+ * Is this time event selected or not
+ */
protected void fillSpace(Rectangle rect, GC gc, boolean selected) {
gc.setBackground(_colors.getBkColor(selected, _isInFocus, false));
gc.fillRectangle(rect);
if (DRAG_NONE != _dragState) {
setCapture(false);
if (e.button == 1 && DRAG_TRACE_ITEM == _dragState) {
- // Notify time provider to check the need for listener
- // notification
- _timeProvider.notifyStartFinishTime();
if (_dragX == _dragX0) { // click without drag
long time = getTimeAtX(e.x);
_timeProvider.setSelectedTimeNotify(time, false);
+ } else {
+ // Notify time provider to check the need for listener
+ // notification
+ _timeProvider.notifyStartFinishTime();
}
_dragState = DRAG_NONE;
} else if (e.button == 1 && DRAG_SPLIT_LINE == _dragState) {
redraw();
_dragState = DRAG_NONE;
} else if (e.button == 3 && DRAG_ZOOM == _dragState) {
- Point size = getCtrlSize();
int nameWidth = _timeProvider.getNameSpace();
- int x = e.x - nameWidth;
if (Math.max(_dragX, _dragX0) > nameWidth && _dragX != _dragX0) {
long time0 = getTimeAtX(_dragX0);
long time1 = getTimeAtX(_dragX);
}
+ /**
+ * @param filter The filter object to be attached to the view
+ * @since 2.0
+ */
+ public void addFilter(ViewerFilter filter) {
+ if (!_filters.contains(filter)) {
+ _filters.add(filter);
+ }
+ }
+
+ /**
+ * @param filter The filter object to be attached to the view
+ * @since 2.0
+ */
+ public void removeFilter(ViewerFilter filter) {
+ _filters.remove(filter);
+ }
+
private class ItemData {
public Item[] _expandedItems = new Item[0];
public Item[] _items = new Item[0];
}
private void refreshExpanded(List<Item> expandedItemList, Item item) {
- expandedItemList.add(item);
- if (item._hasChildren && item._expanded) {
- for (Item child : item.children) {
- refreshExpanded(expandedItemList, child);
+ // Check for filters
+ boolean display = true;
+ for (ViewerFilter filter : _filters) {
+ if (!filter.select(null, item._trace.getParent(), item._trace)) {
+ display = false;
+ break;
+ }
+ }
+ if (display) {
+ expandedItemList.add(item);
+ if (item._hasChildren && item._expanded) {
+ for (Item child : item.children) {
+ refreshExpanded(expandedItemList, child);
+ }
}
}
}