Search in sources :

Example 21 with OutputElementStyle

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

the class TimeGraphControl method drawState.

/**
 * Draw the state (color fill)
 *
 * @param colors
 *            Color scheme
 * @param event
 *            Time event for which we're drawing the state
 * @param rect
 *            The state rectangle
 * @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
 */
protected boolean drawState(TimeGraphColorScheme colors, @NonNull ITimeEvent event, Rectangle rect, GC gc, boolean selected, boolean timeSelected) {
    StyleManager styleManager = getStyleManager();
    OutputElementStyle elementStyle = getElementStyle(event);
    if (elementStyle == null) {
        return false;
    }
    boolean transparent = elementStyle.getParentKey() == null && elementStyle.getStyleValues().isEmpty();
    boolean visible = rect.width <= 0 ? false : true;
    rect.width = Math.max(1, rect.width);
    Float heightFactor = styleManager.getFactorStyle(elementStyle, StyleProperties.HEIGHT);
    heightFactor = (heightFactor != null) ? Math.max(0.0f, Math.min(1.0f, heightFactor)) : DEFAULT_STATE_WIDTH;
    int height = 0;
    if (heightFactor != 0.0f && rect.height != 0) {
        height = Math.max(1, (int) (rect.height * heightFactor));
    }
    Rectangle drawRect = new Rectangle(rect.x, rect.y + ((rect.height - height) / 2), rect.width, height);
    Color black = TimeGraphRender.getColor(BLACK.toInt());
    gc.setForeground(black);
    List<DeferredItem> states = fCurrentDeferredEntry.getItems();
    if (transparent) {
        if (visible) {
            // Avoid overlapping transparent states
            int x = Math.max(fLastTransparentX, drawRect.x);
            drawRect.width = drawRect.x + drawRect.width - x;
            if (drawRect.width > 0) {
                // Draw transparent background
                RGBAColor bgColor = fTransparentGrayColor;
                DeferredItem deferredItem = new DeferredTransparentState(drawRect, bgColor);
                if (states.isEmpty() || !states.get(states.size() - 1).getBounds().intersects(drawRect)) {
                    states.add(deferredItem);
                    deferredItem.add(new PostDrawEvent(event, drawRect));
                }
                fLastTransparentX = Math.max(fLastTransparentX, drawRect.x + drawRect.width);
            } else {
                // clamp it to 0, just in case
                drawRect.width = 0;
            }
            if (drawRect.width <= 2) {
                // Draw point over state
                addPoint(fPoints, rect.x, rect.y - 2);
                if (drawRect.width == 2) {
                    addPoint(fPoints, rect.x + 1, rect.y - 2);
                }
            }
        } else {
            addPoint(fPoints, rect.x, rect.y - 2);
        }
        return false;
    }
    int arc = Math.min(drawRect.height + 1, drawRect.width) / 2;
    RGBAColor rgba = styleManager.getColorStyle(elementStyle, StyleProperties.BACKGROUND_COLOR);
    @NonNull RGBAColor bgColor = (rgba != null) ? rgba : BLACK;
    boolean reallySelected = timeSelected && selected;
    // fill all rect area
    boolean draw = visible || fBlendSubPixelEvents;
    DeferredItem last = null;
    if (draw) {
        if (!states.isEmpty()) {
            DeferredItem state = states.get(states.size() - 1);
            while ((state instanceof DeferredTransparentState) && (state.getBounds().x == drawRect.x)) {
                states.remove(states.size() - 1);
                state = states.isEmpty() ? null : states.get(states.size() - 1);
            }
        }
        RGBAColor borderColor = BLACK;
        int lineWidth = DeferredItem.NO_BORDER;
        Object borderStyle = styleManager.getStyle(elementStyle, StyleProperties.BORDER_STYLE);
        boolean hasBorders = borderStyle != null && !BorderStyle.NONE.equals(borderStyle);
        if (hasBorders) {
            Object borderWidth = styleManager.getStyle(elementStyle, StyleProperties.BORDER_WIDTH);
            lineWidth = 1;
            if (borderWidth instanceof Integer) {
                lineWidth = (int) borderWidth;
            }
            borderColor = styleManager.getColorStyle(elementStyle, StyleProperties.BORDER_COLOR);
            if (borderColor == null) {
                borderColor = BLACK;
            }
        }
        /*
             * This has been tested in Linux and Windows, results may vary. The
             * rounded rectangle is not noticeable for adjacent states of the
             * same color until width=6 (arc=3) with antialiasing, or width=8
             * (arc=4) without antialiasing.
             *
             * In other words, only draw rounded rectangles if the arc is
             * noticeable.
             */
        if (arc >= 2) {
            last = new DeferredState(drawRect, bgColor, Objects.requireNonNull(borderColor), arc, lineWidth, fLabelsVisible ? event.getLabel() : null);
            states.add(last);
        } else {
            DeferredTinyState tinyCandidate = new DeferredTinyState(drawRect, bgColor, Objects.requireNonNull(borderColor), lineWidth);
            boolean skipState = false;
            if (!states.isEmpty()) {
                DeferredItem prev = states.get(states.size() - 1);
                if (prev instanceof DeferredTinyState) {
                    DeferredTinyState tinyState = (DeferredTinyState) prev;
                    if (fBlendSubPixelEvents) {
                        skipState = tinyState.squash(tinyCandidate);
                    } else if (tinyState.extend(tinyCandidate)) {
                        skipState = true;
                    }
                }
            }
            if (!skipState) {
                states.add(tinyCandidate);
            }
            last = tinyCandidate;
        }
    }
    if (reallySelected) {
        fSelectedRectangles.add(drawRect);
    }
    if (!visible) {
        addPoint(fPoints, rect.x, rect.y - 2);
    }
    if (visible && !Boolean.TRUE.equals(styleManager.getStyle(elementStyle, ITimeEventStyleStrings.annotated())) && last != null) {
        last.add(new PostDrawEvent(event, drawRect));
    }
    return visible && !event.isPropertyActive(IFilterProperty.DIMMED);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) DeferredItem(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredItem) DeferredTinyState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTinyState) 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) DeferredState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredState) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) PostDrawEvent(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.PostDrawEvent) NonNull(org.eclipse.jdt.annotation.NonNull) StyleManager(org.eclipse.tracecompass.tmf.ui.model.StyleManager) DeferredTransparentState(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.DeferredTransparentState)

Example 22 with OutputElementStyle

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

the class TimeGraphControl method getElementStyle.

@Nullable
private OutputElementStyle getElementStyle(@NonNull ITimeEvent event) {
    OutputElementStyle elementStyle;
    if (fTimeGraphProvider instanceof ITimeGraphStylePresentationProvider) {
        ITimeGraphStylePresentationProvider provider = (ITimeGraphStylePresentationProvider) fTimeGraphProvider;
        elementStyle = provider.getElementStyle(event);
        if (elementStyle == null) {
            return null;
        }
        if (elementStyle.getParentKey() == null && elementStyle.getStyleValues().isEmpty()) {
            return elementStyle;
        }
        return new OutputElementStyle(elementStyle.getParentKey(), applyEventStyleProperties(new HashMap<>(elementStyle.getStyleValues()), event));
    }
    if (!(event instanceof MarkerEvent)) {
        int colorIdx = fTimeGraphProvider.getStateTableIndex(event);
        if (colorIdx == ITimeGraphPresentationProvider.INVISIBLE) {
            return null;
        }
        if (colorIdx == ITimeGraphPresentationProvider.TRANSPARENT) {
            return new OutputElementStyle(null, new HashMap<>());
        }
    }
    Map<@NonNull String, @NonNull Object> styleMap = StylePropertiesUtils.updateEventStyleProperties(fTimeGraphProvider.getEventStyle(event));
    return new OutputElementStyle(null, applyEventStyleProperties(styleMap, event));
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint) ITimeGraphStylePresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.ITimeGraphStylePresentationProvider) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 23 with OutputElementStyle

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

the class StyleManager method getStyle.

/**
 * Get the style property value for the specified element style. The style
 * hierarchy is traversed until a value is found.
 *
 * @param elementStyle
 *            the style
 * @param property
 *            the style property
 * @return the style value, or null
 */
@Nullable
public Object getStyle(OutputElementStyle elementStyle, String property) {
    OutputElementStyle style = elementStyle;
    Stack<String> styleQueue = new Stack<>();
    while (style != null) {
        Map<String, Object> styleValues = style.getStyleValues();
        Object value = styleValues.get(property);
        if (value != null) {
            return value;
        }
        // Get the next style
        style = popNextStyle(style, styleQueue);
    }
    return null;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) Stack(java.util.Stack) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 24 with OutputElementStyle

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

the class TmfTimeGraphCompositeDataProvider method fetchStyle.

@Override
public TmfModelResponse<OutputStyleModel> fetchStyle(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Map<String, OutputElementStyle> styles = new HashMap<>();
    for (P dataProvider : getProviders()) {
        if (dataProvider instanceof IOutputStyleProvider) {
            TmfModelResponse<OutputStyleModel> response = ((IOutputStyleProvider) dataProvider).fetchStyle(fetchParameters, monitor);
            OutputStyleModel model = response.getModel();
            if (model != null) {
                styles.putAll(model.getStyles());
            }
        }
    }
    if (styles.isEmpty()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(new OutputStyleModel(styles), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : OutputStyleModel(org.eclipse.tracecompass.tmf.core.model.OutputStyleModel) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 25 with OutputElementStyle

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

the class CriticalPathDataProvider method getMatchingState.

@NonNull
private static OutputElementStyle getMatchingState(EdgeType type, boolean arrow) {
    String parentStyleName = type.name();
    parentStyleName = STATE_MAP.containsKey(parentStyleName) ? parentStyleName : EdgeType.UNKNOWN.name();
    parentStyleName = arrow ? parentStyleName + ARROW_SUFFIX : parentStyleName;
    return STYLE_MAP.computeIfAbsent(type.name(), style -> new OutputElementStyle(style));
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) NonNull(org.eclipse.jdt.annotation.NonNull)

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