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