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