Search in sources :

Example 16 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphPresentationProvider method getElementStyle.

@Override
@Nullable
public OutputElementStyle getElementStyle(ITimeEvent event) {
    if (event instanceof NullTimeEvent) {
        return null;
    }
    if (event instanceof TimeEvent) {
        IOutputElement model = ((TimeEvent) event).getModel();
        OutputElementStyle eventStyle = model.getStyle();
        if (eventStyle == null && event.getEntry() instanceof TimeGraphEntry) {
            eventStyle = ((TimeGraphEntry) event.getEntry()).getEntryModel().getStyle();
        }
        if (eventStyle != null) {
            return eventStyle;
        }
    }
    return TRANSPARENT_STYLE;
}
Also used : NullTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) NullTimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent) TimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent) ITimeEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent) IOutputElement(org.eclipse.tracecompass.tmf.core.model.IOutputElement) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 17 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphPresentationProvider method fetchStyles.

/**
 * Use the
 * {@link IOutputStyleProvider#fetchStyle(Map, org.eclipse.core.runtime.IProgressMonitor)}
 * to fetch the appropriate style for a specific provider ID given by
 * getProviderId. Everything is stored in a map of styles where the keys are
 * string that will be used in states and the value are
 * {@link OutputElementStyle}
 *
 * @return The style map
 */
private Map<@NonNull String, @NonNull OutputElementStyle> fetchStyles() {
    Map<String, OutputElementStyle> stylesMap = fStylesMap;
    if (stylesMap == null) {
        stylesMap = new LinkedHashMap<>();
        synchronized (fProviders) {
            for (ITimeGraphDataProvider<?> provider : fProviders.keySet()) {
                if (provider instanceof IOutputStyleProvider) {
                    TmfModelResponse<@NonNull OutputStyleModel> styleResponse = ((IOutputStyleProvider) provider).fetchStyle(getStyleParameters(), null);
                    OutputStyleModel styleModel = styleResponse.getModel();
                    if (styleModel != null) {
                        for (Entry<String, OutputElementStyle> entry : styleModel.getStyles().entrySet()) {
                            OutputElementStyle style = entry.getValue();
                            // Make sure the style values map is mutable
                            stylesMap.put(entry.getKey(), new OutputElementStyle(style.getParentKey(), Maps.newHashMap(style.getStyleValues())));
                        }
                    }
                }
            }
        }
        fStylesMap = stylesMap;
    }
    return stylesMap;
}
Also used : OutputStyleModel(org.eclipse.tracecompass.tmf.core.model.OutputStyleModel) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)

Example 18 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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 19 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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 20 with OutputElementStyle

use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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

OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)31 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)12 Nullable (org.eclipse.jdt.annotation.Nullable)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 NonNull (org.eclipse.jdt.annotation.NonNull)7 LinkedHashMap (java.util.LinkedHashMap)5 Point (org.eclipse.swt.graphics.Point)5 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)5 Color (org.eclipse.swt.graphics.Color)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)4 Collection (java.util.Collection)3 Stack (java.util.Stack)3 RGB (org.eclipse.swt.graphics.RGB)3 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)3 IOutputStyleProvider (org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)3 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)3 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)3