Search in sources :

Example 21 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class CallStackPresentationProvider method getStateTable.

@Override
public StateItem[] getStateTable() {
    if (STATE_TABLE[1] == null) {
        int i = 1;
        for (RGBAColor color : fPalette.get()) {
            STATE_TABLE[i] = new StateItem(RGBAUtil.fromRGBAColor(color).rgb, color.toString());
            i++;
        }
    }
    return STATE_TABLE;
}
Also used : RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) StateItem(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)

Example 22 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class CustomAnnotationProvider method getSubMarkerList.

private void getSubMarkerList(SplitMarker splitMarker, Annotation markerEvent, Map<String, Collection<@NonNull Annotation>> annotationMap, long startTime, long endTime, long minDuration, Long[] times) {
    if (markerEvent.getTime() > endTime || markerEvent.getTime() + markerEvent.getDuration() < startTime) {
        return;
    }
    long lower = splitMarker.getRange().lowerEndpoint();
    long upper = splitMarker.getRange().upperEndpoint();
    long segments = upper - lower + 1;
    long start = markerEvent.getTime();
    List<@NonNull Annotation> annotationList = new ArrayList<>();
    for (int i = 0; i < segments; i++) {
        long end = markerEvent.getTime() + Math.round((double) (i + 1) / segments * markerEvent.getDuration());
        long duration = end - start;
        long labelIndex = lower + i;
        if (end >= startTime && duration > minDuration && splitMarker.getIndexRange().contains(labelIndex)) {
            RGBAColor color = (labelIndex & 1) == 0 ? getColor(splitMarker) : getOddColor(getColor(splitMarker));
            OutputElementStyle outputStyle = getOutputStyle(color);
            Annotation subAnnotation = new Annotation(start, end - start, -1, String.format(splitMarker.getLabel(), labelIndex), outputStyle);
            for (SubMarker subMarker : splitMarker.getSubMarkers()) {
                getSubMarkerList(Objects.requireNonNull(subMarker), subAnnotation, annotationMap, startTime, endTime, minDuration, times);
            }
            annotationList.add(subAnnotation);
        }
        if (start >= endTime) {
            break;
        }
        start = end;
    }
    populateMap(annotationMap, annotationList, Objects.requireNonNull(splitMarker.getName()));
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) ArrayList(java.util.ArrayList) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)

Example 23 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class CustomAnnotationProvider method configure.

private CustomPeriodicAnnotationProvider configure(Marker marker) {
    if (marker instanceof PeriodicMarker) {
        PeriodicMarker periodicMarker = (PeriodicMarker) marker;
        long rollover = periodicMarker.getRange().hasUpperBound() ? (periodicMarker.getRange().upperEndpoint() - periodicMarker.getRange().lowerEndpoint() + 1) : 0;
        RGBAColor evenColor = getColor(marker);
        RGBAColor oddColor = getOddColor(evenColor);
        ITmfTrace trace = fTrace;
        double period = IMarkerConstants.convertToNanos(periodicMarker.getPeriod(), periodicMarker.getUnit(), trace);
        String referenceId = periodicMarker.getReferenceId();
        ITimeReference baseReference = null;
        if (trace instanceof IAdaptable && !referenceId.isEmpty()) {
            ITimeReferenceProvider adapter = ((IAdaptable) trace).getAdapter(ITimeReferenceProvider.class);
            if (adapter != null) {
                baseReference = adapter.apply(referenceId);
            }
        }
        if (baseReference == null) {
            baseReference = ITimeReference.ZERO;
        }
        ITimeReference reference = new TimeReference(baseReference.getTime() + Math.round(IMarkerConstants.convertToNanos(periodicMarker.getOffset(), periodicMarker.getUnit(), trace)), baseReference.getIndex());
        return new CustomPeriodicAnnotationProvider(periodicMarker, reference, period, rollover, evenColor, oddColor);
    }
    // $NON-NLS-1$
    throw new IllegalArgumentException("Marker must be of type PeriodicMarker or SubMarker");
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) IAdaptable(org.eclipse.core.runtime.IAdaptable) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) TimeReference(org.eclipse.tracecompass.tmf.core.markers.TimeReference) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) ITimeReferenceProvider(org.eclipse.tracecompass.tmf.core.markers.ITimeReferenceProvider)

Example 24 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class StylePropertiesUtils method updateEventStyleProperties.

/**
 * Transforms deprecated {@link ITimeEventStyleStrings} methods to the
 * proper styles. It will create the new properties out of the deprecated
 * ones only if such properties do not exist yet.
 *
 * @param styleMap
 *            The original style map.
 * @return A new map of style. This map is not immutable.
 */
@SuppressWarnings("deprecation")
@NonNull
public static Map<@NonNull String, @NonNull Object> updateEventStyleProperties(@Nullable Map<String, Object> styleMap) {
    if (styleMap == null) {
        return new HashMap<>();
    }
    @NonNull Map<@NonNull String, @NonNull Object> updatedStyles = new HashMap<>(styleMap);
    Object object = styleMap.get(ITimeEventStyleStrings.label());
    if (object != null && !styleMap.containsKey(StyleProperties.STYLE_NAME)) {
        updatedStyles.put(StyleProperties.STYLE_NAME, object);
    }
    object = styleMap.get(ITimeEventStyleStrings.heightFactor());
    if (object != null && !styleMap.containsKey(StyleProperties.HEIGHT)) {
        updatedStyles.put(StyleProperties.HEIGHT, object);
    }
    object = styleMap.get(ITimeEventStyleStrings.fillStyle());
    if (object != null && !styleMap.containsKey(StyleProperties.LINEAR_GRADIENT)) {
        if (object.equals(ITimeEventStyleStrings.gradientColorFillStyle())) {
            updatedStyles.put(StyleProperties.LINEAR_GRADIENT, true);
        } else {
            updatedStyles.put(StyleProperties.LINEAR_GRADIENT, false);
        }
    }
    object = styleMap.get(ITimeEventStyleStrings.fillColor());
    if (object != null && (object instanceof Integer)) {
        RGBAColor rgba = new RGBAColor((int) object);
        String hexColor = ColorUtils.toHexColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue());
        float opacity = (float) rgba.getAlpha() / 255;
        if (!styleMap.containsKey(StyleProperties.BACKGROUND_COLOR)) {
            updatedStyles.put(StyleProperties.BACKGROUND_COLOR, hexColor);
        }
        if (!styleMap.containsKey(StyleProperties.COLOR)) {
            updatedStyles.put(StyleProperties.COLOR, hexColor);
        }
        if (!styleMap.containsKey(StyleProperties.OPACITY)) {
            updatedStyles.put(StyleProperties.OPACITY, opacity);
        }
    }
    object = styleMap.get(ITimeEventStyleStrings.fillColorEnd());
    if (object != null && !styleMap.containsKey(StyleProperties.LINEAR_GRADIENT_COLOR_END)) {
        if (object instanceof Integer) {
            RGBAColor rgba = new RGBAColor((int) object);
            updatedStyles.put(StyleProperties.LINEAR_GRADIENT_COLOR_END, ColorUtils.toHexColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue()));
        }
    }
    object = styleMap.get(ITimeEventStyleStrings.borderEnable());
    if (object != null && !styleMap.containsKey(StyleProperties.BORDER_STYLE)) {
        if (object instanceof Boolean && (Boolean) object) {
            updatedStyles.put(StyleProperties.BORDER_STYLE, BorderStyle.SOLID);
        } else {
            updatedStyles.put(StyleProperties.BORDER_STYLE, BorderStyle.NONE);
        }
    }
    object = styleMap.get(ITimeEventStyleStrings.borderColor());
    if (object != null && !styleMap.containsKey(StyleProperties.BORDER_COLOR)) {
        if (object instanceof Integer) {
            RGBAColor rgba = new RGBAColor((int) object);
            updatedStyles.put(StyleProperties.BORDER_COLOR, ColorUtils.toHexColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue()));
        }
    }
    object = styleMap.get(ITimeEventStyleStrings.borderThickness());
    if (object != null && !styleMap.containsKey(StyleProperties.BORDER_WIDTH)) {
        updatedStyles.put(StyleProperties.BORDER_WIDTH, object);
    }
    object = styleMap.get(ITimeEventStyleStrings.symbolStyle());
    if (object != null && !styleMap.containsKey(StyleProperties.SYMBOL_TYPE)) {
        String symbolType = ITimeEventStyleStrings.SYMBOL_TYPES.get(object);
        if (symbolType != null) {
            updatedStyles.put(StyleProperties.SYMBOL_TYPE, symbolType);
        }
    }
    return updatedStyles;
}
Also used : HashMap(java.util.HashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) NonNull(org.eclipse.jdt.annotation.NonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 25 with RGBAColor

use of org.eclipse.tracecompass.tmf.core.presentation.RGBAColor in project tracecompass by tracecompass.

the class TimeGraphStyleUtil method loadValue.

/**
 * Load default values into the state item from a preference store
 *
 * @param presentationProvider
 *            the presentation provider
 * @param stateItem
 *            the state item
 */
public static void loadValue(ITimeGraphPresentationProvider presentationProvider, StateItem stateItem) {
    IPreferenceStore store = getStore();
    String oldFillColorKey = getPreferenceName(presentationProvider, stateItem, ITimeEventStyleStrings.fillColor());
    String oldHeightFactorKey = getPreferenceName(presentationProvider, stateItem, ITimeEventStyleStrings.heightFactor());
    String bgColorKey = getPreferenceName(presentationProvider, stateItem, StyleProperties.BACKGROUND_COLOR);
    String colorKey = getPreferenceName(presentationProvider, stateItem, StyleProperties.COLOR);
    String heightFactorKey = getPreferenceName(presentationProvider, stateItem, StyleProperties.HEIGHT);
    String widthKey = getPreferenceName(presentationProvider, stateItem, StyleProperties.WIDTH);
    Map<String, Object> styleMap = stateItem.getStyleMap();
    String prefBgColor = store.getString(bgColorKey);
    if (!prefBgColor.isEmpty()) {
        styleMap.put(StyleProperties.BACKGROUND_COLOR, prefBgColor);
    } else {
        // Update the new value with the old
        String oldPrefRgbColor = store.getString(oldFillColorKey);
        if (!oldPrefRgbColor.isEmpty()) {
            RGBAColor prefRgba = RGBAColor.fromString(oldPrefRgbColor);
            if (prefRgba != null) {
                String hexColor = ColorUtils.toHexColor(prefRgba.getRed(), prefRgba.getGreen(), prefRgba.getBlue());
                styleMap.put(StyleProperties.BACKGROUND_COLOR, hexColor);
                store.setValue(bgColorKey, hexColor);
            }
        }
    }
    String prefColor = store.getString(colorKey);
    if (!prefColor.isEmpty()) {
        styleMap.put(StyleProperties.COLOR, prefColor);
    }
    store.setDefault(heightFactorKey, -1.0f);
    store.setDefault(oldHeightFactorKey, -1.0f);
    float prefHeightFactor = store.getFloat(heightFactorKey);
    if (prefHeightFactor != -1.0f) {
        styleMap.put(StyleProperties.HEIGHT, prefHeightFactor);
    } else {
        // Update the new value with the old
        prefHeightFactor = store.getFloat(oldHeightFactorKey);
        if (prefHeightFactor != -1.0f) {
            styleMap.put(StyleProperties.HEIGHT, prefHeightFactor);
            store.setValue(heightFactorKey, prefHeightFactor);
        }
    }
    store.setDefault(widthKey, -1);
    int prefWidth = store.getInt(widthKey);
    if (prefWidth != -1) {
        styleMap.put(StyleProperties.WIDTH, prefWidth);
    }
}
Also used : RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)25 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)12 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 NonNull (org.eclipse.jdt.annotation.NonNull)5 Color (org.eclipse.swt.graphics.Color)5 Point (org.eclipse.swt.graphics.Point)5 RGB (org.eclipse.swt.graphics.RGB)5 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)5 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)5 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Marker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker)4 MarkerSet (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet)4 SplitMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker)4 WeightedMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker)4 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 Test (org.junit.Test)4