Search in sources :

Example 1 with StyleManager

use of org.eclipse.tracecompass.tmf.ui.model.StyleManager in project tracecompass by tracecompass.

the class BaseXYPresentationProvider method refresh.

private void refresh() {
    fStylesMap = null;
    fStyleManager = new StyleManager(fetchStyles());
}
Also used : StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager)

Example 2 with StyleManager

use of org.eclipse.tracecompass.tmf.ui.model.StyleManager in project tracecompass by tracecompass.

the class TimeGraphControl method drawMarker.

/**
 * Draw a single marker
 *
 * @param marker
 *            The marker event
 * @param bounds
 *            The bounds of the control
 * @param timeProvider
 *            The time provider
 * @param nameSpace
 *            The width reserved for the name
 * @param gc
 *            Reference to the SWT GC object
 * @since 2.0
 */
protected void drawMarker(IMarkerEvent marker, Rectangle bounds, ITimeDataProvider timeProvider, int nameSpace, GC gc) {
    Rectangle rect = Utils.clone(bounds);
    if (marker.getEntry() != null) {
        int index = fItemData.findItemIndex(marker.getEntry());
        if (index == -1) {
            return;
        }
        rect = getStatesRect(bounds, index, nameSpace);
        if (rect.y < 0 || rect.y > bounds.height) {
            return;
        }
    }
    int x0 = getXForTime(marker.getTime());
    int x1 = getXForTime(marker.getTime() + marker.getDuration());
    if (x0 > bounds.width || x1 < nameSpace) {
        return;
    }
    rect.x = Math.max(nameSpace, Math.min(bounds.width, x0));
    rect.width = Math.max(1, Math.min(bounds.width, x1) - rect.x);
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(marker);
    if (elementStyle == null) {
        return;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    int colorInt = (rgba != null) ? rgba.toInt() : RGBAUtil.fromRGBA(marker.getColor());
    Color color = TimeGraphRender.getColor(colorInt);
    Object symbolType = styleManager.getStyle(elementStyle, StyleProperties.SYMBOL_TYPE);
    if (symbolType != null && symbolType != SymbolType.NONE) {
        gc.setAlpha(colorInt & 0xff);
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        heightFactor = (heightFactor != null) ? Math.max(0.0f, Math.min(1.0f, heightFactor)) : 1.0f;
        int symbolSize = (int) Math.ceil(rect.height * heightFactor / 2);
        Object verticalAlign = styleManager.getStyle(elementStyle, StyleProperties.VERTICAL_ALIGN);
        int y = rect.y + rect.height / 2;
        if (VerticalAlign.BOTTOM.equals(verticalAlign)) {
            y += Math.max(0, rect.height / 2 - symbolSize);
        } else if (VerticalAlign.TOP.equals(verticalAlign)) {
            y -= Math.max(0, rect.height / 2 - symbolSize);
        }
        switch(String.valueOf(symbolType)) {
            case SymbolType.CROSS:
                SymbolHelper.drawCross(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.PLUS:
                SymbolHelper.drawPlus(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.SQUARE:
                SymbolHelper.drawSquare(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.TRIANGLE:
                SymbolHelper.drawTriangle(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.INVERTED_TRIANGLE:
                SymbolHelper.drawInvertedTriangle(gc, color, symbolSize, rect.x, y);
                break;
            case SymbolType.CIRCLE:
                SymbolHelper.drawCircle(gc, color, symbolSize, rect.x, y);
                break;
            default:
                SymbolHelper.drawDiamond(gc, color, symbolSize, rect.x, y);
        }
        gc.setAlpha(OPAQUE);
        if (marker.getDuration() == 0) {
            return;
        }
    }
    oldDrawMarker(marker, gc, rect, colorInt);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Rectangle(org.eclipse.swt.graphics.Rectangle) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Example 3 with StyleManager

use of org.eclipse.tracecompass.tmf.ui.model.StyleManager in project tracecompass by tracecompass.

the class TimeGraphControl method drawLineGraphEntry.

private void drawLineGraphEntry(long time0, @NonNull Rectangle rect, double pixelsPerNanoSec, Iterator<ITimeEvent> iterator) {
    // clamp 0 - max positive
    long max = Long.MIN_VALUE;
    long min = 0;
    List<@NonNull List<@NonNull LongPoint>> seriesModel = new ArrayList<>();
    TimeLineEvent lastValid = null;
    while (iterator.hasNext()) {
        ITimeEvent event = iterator.next();
        if (!(event instanceof TimeLineEvent)) {
            continue;
        }
        int x = SaturatedArithmetic.add(rect.x, (int) ((event.getTime() - time0) * pixelsPerNanoSec));
        if (x >= rect.x + rect.width) {
            // event is out of bounds
            continue;
        }
        TimeLineEvent timeEvent = (TimeLineEvent) event;
        List<Long> values = timeEvent.getValues();
        for (int i = 0; i < values.size(); i++) {
            if (seriesModel.size() <= i) {
                seriesModel.add(new ArrayList<>());
            }
            Long val = values.get(i);
            if (val != null) {
                // get max and min, this is a relative scale.
                max = Math.max(Math.abs(val), max);
                min = 0;
                lastValid = timeEvent;
                seriesModel.get(i).add(new LongPoint(x, val));
            }
        }
    }
    if (lastValid == null) {
        return;
    }
    double scale = (max - min) == 0 ? 1.0 : (double) rect.height / (max - min);
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(lastValid);
    if (elementStyle == null) {
        return;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    fLines.add(new DeferredLine(rect, min, seriesModel, rgba == null ? BLACK : rgba, scale));
}
Also used : ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) DeferredLine(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) TimeLineEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent) NonNull(org.eclipse.jdt.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager)

Example 4 with StyleManager

use of org.eclipse.tracecompass.tmf.ui.model.StyleManager in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphPresentationProvider method refresh.

@Override
public void refresh() {
    fStylesMap = null;
    fStateTable = null;
    fStyleManager = new StyleManager(fetchStyles());
    super.refresh();
    updateStyles();
}
Also used : StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager)

Example 5 with StyleManager

use of org.eclipse.tracecompass.tmf.ui.model.StyleManager in project tracecompass by tracecompass.

the class TimeGraphControl method drawArrow.

/**
 * Draw an arrow
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the arrow
 * @param rect
 *            The arrow rectangle
 * @param gc
 *            Graphics context
 * @return true if the arrow was drawn
 */
protected boolean drawArrow(TimeGraphColorScheme colors, @NonNull ITimeEvent event, Rectangle rect, GC gc) {
    if (rect == null || ((rect.height == 0) && (rect.width == 0))) {
        return false;
    }
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.COLOR);
    rgba = (rgba != null) ? rgba : BLACK;
    int colorInt = rgba.toInt();
    Color color = TimeGraphRender.getColor(colorInt);
    int alpha = rgba.getAlpha();
    int prevAlpha = gc.getAlpha();
    gc.setAlpha(alpha);
    gc.setForeground(color);
    gc.setBackground(color);
    int old = gc.getLineWidth();
    Float widthFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.WIDTH);
    if (widthFactor == null) {
        Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
        widthFactor = (heightFactor != null) ? heightFactor * 10.0f : 1.0f;
    }
    widthFactor = Math.max(1.0f, Math.min(10.0f, widthFactor));
    gc.setLineWidth(widthFactor.intValue());
    /* Draw the arrow */
    Point newEndpoint = drawArrowHead(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height, widthFactor, gc);
    gc.drawLine(rect.x, rect.y, newEndpoint.x, newEndpoint.y);
    gc.setLineWidth(old);
    gc.setAlpha(prevAlpha);
    if (!Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated()))) {
        fPostDrawArrows.add(new PostDrawEvent(event, rect));
    }
    return true;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PostDrawEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Aggregations

StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)6 Point (org.eclipse.swt.graphics.Point)4 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)4 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)4 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)4 Color (org.eclipse.swt.graphics.Color)3 NonNull (org.eclipse.jdt.annotation.NonNull)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 PostDrawEvent (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 DeferredItem (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem)1 DeferredLine (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredLine)1 DeferredState (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredState)1 DeferredTinyState (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTinyState)1 DeferredTransparentState (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTransparentState)1 TimeLineEvent (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.model.TimeLineEvent)1 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)1