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);
}
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;
}
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;
}
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();
}
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;
}
Aggregations