Search in sources :

Example 6 with OutputElementStyle

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

the class StyleManager method getColorStyle.

/**
 * Get the style property color value for the specified element style. The
 * style hierarchy is traversed until a color and opacity value is found,
 * and the returned color value will be blended with the first
 * {@link StyleProperties#BLEND} suffixed modifier style that was found
 * along the way, if any.
 *
 * @param elementStyle
 *            the style
 * @param property
 *            the style property
 * @return the style value, or null
 */
@Nullable
public RGBAColor getColorStyle(OutputElementStyle elementStyle, String property) {
    String color = null;
    Float opacity = null;
    RGBAColor blend = null;
    OutputElementStyle style = elementStyle;
    Stack<String> styleQueue = new Stack<>();
    while (style != null) {
        Map<String, Object> styleValues = style.getStyleValues();
        if (blend == null) {
            Object value = styleValues.get(property + StyleProperties.BLEND);
            if (value instanceof String) {
                RGBAColor rgba = RGBAColor.fromString((String) value);
                if (rgba != null) {
                    blend = rgba;
                }
            }
        }
        if (opacity == null) {
            Object value = styleValues.get(StyleProperties.OPACITY);
            if (value instanceof Number) {
                opacity = ((Number) value).floatValue();
                if (color != null) {
                    break;
                }
            }
        }
        if (color == null) {
            Object value = styleValues.get(property);
            if (value instanceof String) {
                color = (String) value;
                if (opacity != null) {
                    break;
                }
            }
        }
        // Get the next style
        style = popNextStyle(style, styleQueue);
    }
    int alpha = (opacity == null) ? 255 : (int) (opacity * 255);
    RGBAColor rgba = (color == null) ? (opacity == null ? null : new RGBAColor(0, 0, 0, alpha)) : RGBAColor.fromString(color, alpha);
    return (rgba == null) ? null : (blend == null) ? rgba : blend(rgba, blend);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) Stack(java.util.Stack) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 7 with OutputElementStyle

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

the class StyleManager method popNextStyle.

@Nullable
private OutputElementStyle popNextStyle(OutputElementStyle style, Stack<String> styleQueue) {
    // Get the next style
    OutputElementStyle nextStyle = null;
    String parentKey = style.getParentKey();
    if (parentKey != null) {
        // $NON-NLS-1$
        String[] split = parentKey.split(",");
        styleQueue.addAll(Arrays.asList(split));
    }
    while (nextStyle == null && !styleQueue.isEmpty()) {
        nextStyle = fStyleMap.get(styleQueue.pop());
    }
    return nextStyle;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 8 with OutputElementStyle

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

the class XYChartLegendImageProvider method getLegendImage.

@Override
public Image getLegendImage(int imageHeight, int imageWidth, @NonNull Long id) {
    /*
         * If series exists in chart, then image legend match that series. Image will
         * make sense if series exists in chart. If it does not exists, an image will
         * still be created.
         */
    OutputElementStyle appearance = fChartViewer.getSeriesStyle(id);
    BaseXYPresentationProvider presProvider = fChartViewer.getPresentationProvider();
    RGBAColor rgb = presProvider.getColorStyleOrDefault(appearance, StyleProperties.COLOR, DEFAULT_COLOR);
    Color lineColor = new Color(Display.getDefault(), rgb.getRed(), rgb.getGreen(), rgb.getBlue());
    Color background = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    PaletteData palette = new PaletteData(background.getRGB(), lineColor.getRGB());
    ImageData imageData = new ImageData(imageWidth, imageHeight, 8, palette);
    imageData.transparentPixel = 0;
    Image image = new Image(Display.getDefault(), imageData);
    GC gc = new GC(image);
    gc.setBackground(background);
    gc.fillRectangle(0, 0, imageWidth, imageHeight);
    drawStyleLine(gc, lineColor, imageWidth, imageHeight, appearance);
    drawStyledDot(gc, lineColor, imageWidth, imageHeight, appearance);
    gc.dispose();
    lineColor.dispose();
    return image;
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 9 with OutputElementStyle

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

the class TmfFilteredXYChartViewer method handleCheckStateChangedEvent.

/**
 * Update the chart depending on the selected entries.
 *
 * @param entries
 *            Counters to display on the chart
 */
@Override
public void handleCheckStateChangedEvent(Collection<ITmfTreeViewerEntry> entries) {
    cancelUpdate();
    Iterable<TmfGenericTreeEntry> counterEntries = Iterables.filter(entries, TmfGenericTreeEntry.class);
    Collection<@NonNull Long> selectedIds = Sets.newHashSet(Iterables.transform(counterEntries, e -> e.getModel().getId()));
    if (!selectedIds.containsAll(fSelectedIds)) {
        clearContent();
    }
    fSelectedIds = selectedIds;
    // Update the styles as well
    BaseXYPresentationProvider presProvider = getPresentationProvider();
    for (ITmfTreeViewerEntry entry : entries) {
        if (entry instanceof TmfGenericTreeEntry) {
            TmfGenericTreeEntry<TmfTreeDataModel> genericEntry = (TmfGenericTreeEntry<TmfTreeDataModel>) entry;
            TmfTreeDataModel model = genericEntry.getModel();
            OutputElementStyle style = model.getStyle();
            if (style != null) {
                presProvider.setStyle(model.getId(), style);
            }
        }
    }
    updateContent();
}
Also used : Iterables(com.google.common.collect.Iterables) Chart(org.eclipse.swtchart.Chart) DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) HashMap(java.util.HashMap) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) ICheckboxTreeViewerListener(org.eclipse.tracecompass.tmf.ui.viewers.tree.ICheckboxTreeViewerListener) Multimap(com.google.common.collect.Multimap) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) Nullable(org.eclipse.jdt.annotation.Nullable) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) FetchParametersUtils(org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) Sets(com.google.common.collect.Sets) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) IYAppearance(org.eclipse.tracecompass.tmf.core.presentation.IYAppearance) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider) ITmfXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXYDataProvider) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) ITmfTreeViewerEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TmfGenericTreeEntry(org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) BaseXYPresentationProvider(org.eclipse.tracecompass.internal.provisional.tmf.ui.viewers.xychart.BaseXYPresentationProvider)

Example 10 with OutputElementStyle

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

the class ResourcesPresentationProvider method getSpecificEventStyle.

@Override
public Map<String, Object> getSpecificEventStyle(ITimeEvent event) {
    Map<String, Object> map = new HashMap<>(super.getSpecificEventStyle(event));
    if (isType(event.getEntry(), Type.CURRENT_THREAD) && event instanceof TimeEvent) {
        if (event instanceof MarkerEvent) {
            TimeEvent timeEvent = (TimeEvent) event;
            OutputElementStyle style = timeEvent.getModel().getStyle();
            if (style != null) {
                return style.getStyleValues();
            }
        } else {
            int threadEventValue = ((TimeEvent) event).getValue();
            RGBAColor color = PALETTE.get(Math.floorMod(threadEventValue + COLOR_DIFFERENCIATION_FACTOR, NUM_COLORS));
            map.put(StyleProperties.BACKGROUND_COLOR, ColorUtils.toHexColor(color.getRed(), color.getGreen(), color.getBlue()));
            map.put(StyleProperties.STYLE_NAME, String.valueOf(threadEventValue));
        }
    } else if (event.getEntry() instanceof TimeGraphEntry && ((TimeGraphEntry) event.getEntry()).getEntryModel() instanceof ITimeGraphEntryModelWeighted) {
        ITimeGraphEntryModelWeighted model = (ITimeGraphEntryModelWeighted) ((TimeGraphEntry) event.getEntry()).getEntryModel();
        int eventValue = ((TimeEvent) event).getValue();
        map.put(StyleProperties.HEIGHT, (float) model.getWeight(eventValue));
    }
    return map;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITimeGraphEntryModelWeighted(org.eclipse.tracecompass.internal.provisional.tmf.core.model.timegraph.ITimeGraphEntryModelWeighted) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) 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) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)

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