Java源码示例:org.eclipse.swt.graphics.RGBA
示例1
@Override
protected @NonNull List<IMarkerEvent> getViewMarkerList(long startTime, long endTime, long resolution, @NonNull IProgressMonitor monitor) {
ITmfTrace trace = getTrace();
if (trace == null) {
return Collections.emptyList();
}
long start = trace.getStartTime().toNanos();
return Arrays.<IMarkerEvent> asList(
(IMarkerEvent) new MarkerEvent(fHead1, 120 + start, 50, MARKER_GROUP, new RGBA(33, 33, 33, 33), "Wind", true),
(IMarkerEvent) new MarkerEvent(fRow4, 20 + start, 60, MARKER_GROUP, new RGBA(22, 33, 44, 22), "Speed", false),
(IMarkerEvent) new MarkerEvent(fRow2, 20 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", false, 0),
(IMarkerEvent) new MarkerEvent(fRow2, 26 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", false, 1),
(IMarkerEvent) new MarkerEvent(fRow2, 32 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", false, 2),
(IMarkerEvent) new MarkerEvent(fRow2, 38 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", false, 3),
(IMarkerEvent) new MarkerEvent(fRow2, 44 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", false, 4),
(IMarkerEvent) new MarkerEvent(fRow2, 50 + start, 0, MARKER_GROUP, new RGBA(22, 33, 44, 22), "", true, 5));
}
示例2
private PeriodicMarkerEventSource(String category, Reference reference, double period, long rollover, boolean foreground, RGBA color1, @Nullable RGBA color2) {
if (period <= 0) {
throw new IllegalArgumentException("period cannot be less than or equal to zero"); //$NON-NLS-1$
}
if (rollover < 0) {
throw new IllegalArgumentException("rollover cannot be less than zero"); //$NON-NLS-1$
}
fCategory = category;
fReference = reference;
fPeriod = period;
fPeriodInteger = (long) period;
try {
fPeriodFraction = Fraction.getFraction(fPeriod - fPeriodInteger);
} catch (ArithmeticException e) {
/* can't convert to fraction, use floating-point arithmetic */
fPeriodFraction = null;
}
fRollover = rollover;
fColor1 = color1;
fColor2 = color2;
fForeground = foreground;
}
示例3
private void configure(Marker marker) {
if (marker instanceof PeriodicMarker) {
PeriodicMarker periodicMarker = (PeriodicMarker) marker;
String referenceId = periodicMarker.getReferenceId();
Reference baseReference = null;
if (fTrace instanceof IAdaptable && !referenceId.isEmpty()) {
@Nullable IMarkerReferenceProvider adapter = ((IAdaptable) fTrace).getAdapter(IMarkerReferenceProvider.class);
if (adapter != null) {
baseReference = adapter.getReference(referenceId);
}
}
if (baseReference == null) {
baseReference = Reference.ZERO;
}
long rollover = periodicMarker.getRange().hasUpperBound() ? (periodicMarker.getRange().upperEndpoint() - periodicMarker.getRange().lowerEndpoint() + 1) : 0;
RGBA evenColor = getColor(periodicMarker);
RGBA oddColor = getOddColor(evenColor);
double period = convertToNanos(periodicMarker.getPeriod(), periodicMarker.getUnit());
Reference reference = new Reference(baseReference.getTime() + Math.round(convertToNanos(periodicMarker.getOffset(), periodicMarker.getUnit())), baseReference.getIndex());
ConfigurablePeriodicMarkerEventSource markerEventSource = new ConfigurablePeriodicMarkerEventSource(marker, checkNotNull(periodicMarker.getName()), reference, period, rollover, evenColor, oddColor, false, periodicMarker.getRange().lowerEndpoint(), checkNotNull(periodicMarker.getLabel()), periodicMarker.getIndexRange());
fMarkerEventSources.add(markerEventSource);
}
}
示例4
private void getSubMarkerList(SplitMarker splitMarker, IMarkerEvent markerEvent, @NonNull List<@NonNull IMarkerEvent> markerList, long startTime, long endTime, long minDuration) {
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();
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)) {
RGBA color = (labelIndex & 1) == 0 ? getColor(splitMarker) : getOddColor(getColor(splitMarker));
IMarkerEvent subMarkerEvent = new MarkerEvent(null, start, end - start, splitMarker.getName(), color, String.format(splitMarker.getLabel(), labelIndex), false);
for (SubMarker subMarker : splitMarker.getSubMarkers()) {
getSubMarkerList(subMarker, subMarkerEvent, markerList, startTime, endTime, minDuration);
}
markerList.add(subMarkerEvent);
}
if (start >= endTime) {
break;
}
start = end;
}
}
示例5
private static void validateMarker(IMarkerEvent marker, long time, long duration, String category, String label, RGBA color) {
assertEquals(time, marker.getTime());
assertEquals(duration, marker.getDuration());
assertEquals(category, marker.getCategory());
assertEquals(label, marker.getLabel());
assertEquals(color, marker.getColor());
assertEquals(false, marker.isForeground());
}
示例6
private @NonNull ISeries<?> createDimmedSeriesFromModel(ISeriesModel yModel) {
ISeriesSet seriesSet = getSwtChart().getSeriesSet();
String seriesName = yModel.getName() + DIMMED_SERIES_SUFFIX;
OutputElementStyle appearance = getSeriesStyle(yModel.getId());
BaseXYPresentationProvider presProvider = getPresentationProvider();
String type = (String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_TYPE, StyleProperties.SeriesType.LINE);
RGBAColor rgbaColor = presProvider.getColorStyleOrDefault(appearance, StyleProperties.COLOR, DEFAULT_COLOR);
float[] rgb = rgbaColor.getHSBA();
COLOR_REGISTRY.put(rgb.toString(), new RGBA(rgb[0], rgb[1] * 0.5f, rgb[2] * 0.5f, rgb[3]).rgb);
Color color = COLOR_REGISTRY.get(rgb.toString());
String symbolType = (String) presProvider.getStyle(appearance, StyleProperties.SYMBOL_TYPE);
if (type.equals(IYAppearance.Type.BAR)) {
IBarSeries<?> barSeries = (IBarSeries<?>) seriesSet.createSeries(SeriesType.BAR, seriesName);
barSeries.setBarColor(color);
barSeries.setBarPadding(0);
barSeries.setVisible(true);
return barSeries;
}
/**
* Default is line chart
*/
ILineSeries<?> lineSeries = (ILineSeries<?>) seriesSet.createSeries(SeriesType.LINE, seriesName);
lineSeries.enableArea(StyleProperties.SeriesType.AREA.equals(type));
lineSeries.setLineStyle(LineStyle.valueOf((String) presProvider.getStyle(appearance, StyleProperties.SERIES_STYLE)));
lineSeries.setSymbolType(SYMBOL_MAP.getOrDefault(symbolType, ILineSeries.PlotSymbolType.NONE));
lineSeries.setLineColor(color);
lineSeries.setSymbolColor(color);
lineSeries.setVisible(true);
lineSeries.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
return lineSeries;
}
示例7
private @NonNull ISeries createDimmedSeriesFromModel(ISeriesModel yModel) {
ISeriesSet seriesSet = getSwtChart().getSeriesSet();
String seriesName = yModel.getName() + DIMMED_SERIES_SUFFIX;
OutputElementStyle appearance = getSeriesStyle(yModel.getId());
BaseXYPresentationProvider presProvider = getPresentationProvider2();
String type = (String) presProvider.getStyleOrDefault(appearance, StyleProperties.SERIES_TYPE, StyleProperties.SeriesType.LINE);
RGBAColor rgbaColor = presProvider.getColorStyleOrDefault(appearance, StyleProperties.COLOR, DEFAULT_COLOR);
float[] rgb = rgbaColor.getHSBA();
COLOR_REGISTRY.put(rgb.toString(), new RGBA(rgb[0], rgb[1] * 0.5f, rgb[2] * 0.5f, rgb[3]).rgb);
Color color = COLOR_REGISTRY.get(rgb.toString());
String symbolType = (String) presProvider.getStyle(appearance, StyleProperties.SYMBOL_TYPE);
if (type.equals(StyleProperties.SeriesType.BAR)) {
IBarSeries barSeries = (IBarSeries) seriesSet.createSeries(SeriesType.BAR, seriesName);
barSeries.enableStack(true);
barSeries.setBarColor(color);
barSeries.setBarPadding(0);
barSeries.setVisible(true);
return barSeries;
}
/**
* Default is line chart
*/
ILineSeries lineSeries = (ILineSeries) seriesSet.createSeries(SeriesType.LINE, seriesName);
lineSeries.enableArea(StyleProperties.SeriesType.AREA.equals(type));
lineSeries.setLineStyle(LineStyle.valueOf((String) presProvider.getStyle(appearance, StyleProperties.SERIES_STYLE)));
lineSeries.setSymbolType(SYMBOL_MAP.getOrDefault(symbolType, ILineSeries.PlotSymbolType.NONE));
lineSeries.setLineColor(color);
lineSeries.setSymbolColor(color);
lineSeries.setVisible(true);
lineSeries.setLineWidth(((Number) presProvider.getFloatStyleOrDefault(appearance, StyleProperties.WIDTH, 1.0f)).intValue());
return lineSeries;
}
示例8
private @NonNull RGBA getColor(Marker marker) {
RGBA color = fColors.get(marker);
if (color == null) {
color = parseColor(marker.getColor());
fColors.put(marker, color);
}
return color;
}
示例9
public ConfigurablePeriodicMarkerEventSource(Marker marker, @NonNull String category, @NonNull Reference reference, double period, long rollover, @NonNull RGBA evenColor, @NonNull RGBA oddColor, boolean foreground, long startIndex, @NonNull String label, RangeSet<Long> indexRange) {
super(category, reference, period, rollover, evenColor, oddColor, foreground);
fMarker = marker;
fStartIndex = startIndex;
fLabel = label;
fIndexRange = indexRange;
fMaxDuration = period;
}
示例10
@Override
public List<IMarkerEvent> getMarkerList(String category, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
if (startTime > endTime) {
return Collections.emptyList();
}
List<IMarkerEvent> markers = new ArrayList<>();
/* Subtract 1.5 periods to ensure previous marker is included */
long time = startTime - Math.max(Math.round(1.5 * fPeriod), resolution);
Reference reference = adjustReference(fReference, time);
IMarkerEvent markerEvent = null;
while (true) {
long index = Math.round((time - reference.time) / fPeriod) + reference.index;
time = Math.round((index - reference.index) * fPeriod) + reference.time;
long duration = (fColor2 == null) ? 0 : Math.round((index + 1 - reference.index) * fPeriod) + reference.time - time;
long labelIndex = index;
if (fRollover != 0) {
labelIndex %= fRollover;
if (labelIndex < 0) {
labelIndex += fRollover;
}
}
/* Add previous marker if current is visible */
if ((time >= startTime || time + duration > startTime) && markerEvent != null) {
markers.add(markerEvent);
}
if (isApplicable(labelIndex)) {
RGBA color = (fColor2 == null) ? fColor1 : (index % 2 == 0) ? fColor1 : fColor2;
markerEvent = new MarkerEvent(null, time, duration, fCategory, color, getMarkerLabel(labelIndex), fForeground);
} else {
markerEvent = null;
}
if (time > endTime) {
if (markerEvent != null) {
/* The next marker out of range is included */
markers.add(markerEvent);
}
break;
}
time += Math.max(Math.round(fPeriod), resolution);
}
return markers;
}
示例11
@Override
public RGBA getColor() {
return fColor;
}
示例12
private static @NonNull RGBA getOddColor(RGBA color) {
return new RGBA(color.rgb.red, color.rgb.green, color.rgb.blue, 0);
}
示例13
public void setColor(String key, RGBA color) {
this.factory.getColors().createColor(key, color.rgb);
}
示例14
public static Color get(int r, int g, int b) {
return get(new RGBA(r, g, b, 255));
}
示例15
public static Color get(RGB rgb) {
RGBA rgba = new RGBA(rgb.red, rgb.green, rgb.blue, 255);
return get(rgba);
}
示例16
public static Color get(int r, int g, int b, int a) {
return get(new RGBA(r, g, b, a));
}
示例17
/**
* Standard constructor
*
* @param entry
* The entry of the marker, or null
* @param time
* The timestamp of this marker
* @param duration
* The duration of the marker
* @param category
* The category of the marker
* @param color
* The marker color
* @param label
* The label of the marker, or null
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
*/
public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, RGBA color, String label, boolean foreground) {
super(entry, time, duration);
fCategory = category;
fColor = color;
fLabel = label;
fForeground = foreground;
}
示例18
/**
* Constructor
*
* @param entry
* The entry of the marker, or null
* @param time
* The timestamp of this marker
* @param duration
* The duration of the marker
* @param category
* The category of the marker
* @param color
* The marker color
* @param label
* The label of the marker, or null
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
* @param value
* The value of the marker
*/
public MarkerEvent(ITimeGraphEntry entry, long time, long duration, String category, RGBA color, String label, boolean foreground, int value) {
super(entry, time, duration, value);
fCategory = category;
fColor = color;
fLabel = label;
fForeground = foreground;
}
示例19
/**
* Constructor
*
* @param annotation
* {@link IAnnotation} that represent this marker event
* @param entry
* The entry to which this marker event is assigned
* @param category
* The category of the marker
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
* @since 5.2
*/
public MarkerEvent(IAnnotation annotation, ITimeGraphEntry entry, String category, boolean foreground) {
super(entry, annotation);
fCategory = category;
fLabel = annotation.getLabel();
fColor = new RGBA(0, 0, 0, 255);
fForeground = foreground;
}
示例20
/**
* Constructs a periodic marker event source with line markers at period
* boundaries.
* <p>
* The markers will have the given category and color. The reference defines
* the marker with the given index to be at the specified time.
*
* @param category
* the marker category
* @param reference
* the reference marker time and index
* @param period
* the period in time units
* @param rollover
* the number of periods before the index rolls-over to 0, or 0
* for no roll-over
* @param color
* the marker color
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
*/
public PeriodicMarkerEventSource(String category, Reference reference, double period, long rollover, RGBA color, boolean foreground) {
this(category, reference, period, rollover, foreground, color, null);
}
示例21
/**
* Constructs a periodic marker event source with alternating shading
* markers.
* <p>
* The markers will have the given category. Periods will be shaded with the
* first and second colors alternatively. The reference defines the marker
* with the given index to be at the specified time. The reference will be
* shaded with the first color if its index is even, or the second color
* if it is odd.
*
* @param category
* the marker category
* @param reference
* the reference marker time and index
* @param period
* the period in time units
* @param rollover
* the number of periods before the index rolls-over to 0, or 0
* for no roll-over
* @param color1
* the first marker color
* @param color2
* the second marker color
* @param foreground
* true if the marker is drawn in foreground, and false otherwise
*/
public PeriodicMarkerEventSource(String category, Reference reference, double period, long rollover, RGBA color1, RGBA color2, boolean foreground) {
this(category, reference, period, rollover, foreground, color1, color2);
}
示例22
/**
* Get this marker's color.
*
* @return The color
*/
RGBA getColor();
示例23
/**
* Get a color resource for the specified RGBA color descriptor
*
* @param rgba
* the color descriptor
* @return a color resource
* @since 2.0
*/
public Color getColor(RGBA rgba) {
return fColorMap.computeIfAbsent(rgba, colorRgba -> new Color(Display.getDefault(), colorRgba));
}
示例24
/**
* Convert to an RGBA from an integer
*
* @param value
* the integer encoded RGBA
* @return the RGBA
*/
public static RGBA fromInt(int value) {
return new RGBA((value >> 24) & 0xff, (value >> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff);
}
示例25
/**
* Convert to an integer from a RGBA
*
* @param value
* the RGBA
* @return the integer encoded RGBA
*/
public static int fromRGBA(RGBA value) {
RGB rgb = value.rgb;
return (rgb.red << 24) | (rgb.green << 16) | (rgb.blue << 8) | value.alpha;
}
示例26
/**
* Convert from an RGBAColor to an RGBA, useful for dealing with palettes.
*
* @param color The {@link RGBAColor}
* @return an {@link RGBA}
*/
public static RGBA fromRGBAColor(RGBAColor color) {
return fromInt(color.toInt());
}
示例27
/**
* Returns the color selected in this dialog.
*
* @return the color RGBA value
*/
public RGBA getColorValue() {
RGB rgb = fColorSelector.getColorValue();
return new RGBA(rgb.red, rgb.green, rgb.blue, fAlpha);
}