use of java.awt.Composite in project android_frameworks_base by crdroidandroid.
the class GcSnapshot method setComposite.
private void setComposite(Graphics2D g, Paint_Delegate paint, boolean usePaintAlpha, int forceMode) {
// the alpha for the composite. Always opaque if the normal paint color is used since
// it contains the alpha
int alpha = usePaintAlpha ? paint.getAlpha() : 0xFF;
if (forceMode != 0) {
g.setComposite(AlphaComposite.getInstance(forceMode, (float) alpha / 255.f));
return;
}
Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
if (xfermodeDelegate != null) {
if (xfermodeDelegate.isSupported()) {
Composite composite = xfermodeDelegate.getComposite(alpha);
assert composite != null;
if (composite != null) {
g.setComposite(composite);
return;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_XFERMODE, xfermodeDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// that will handle the alpha.
if (alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 255.f));
}
}
use of java.awt.Composite in project processdash by dtuma.
the class RadarPlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen
* or a printer).
* @param g2 The graphics device.
* @param plotArea The area within which the plot should be drawn.
*/
@Override
public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState state, PlotRenderingInfo info) {
// adjust for insets...
RectangleInsets insets = getInsets();
if (insets != null) {
plotArea.setRect(plotArea.getX() + insets.getLeft(), plotArea.getY() + insets.getTop(), plotArea.getWidth() - insets.getLeft() - insets.getRight(), plotArea.getHeight() - insets.getTop() - insets.getBottom());
}
if (info != null) {
info.setPlotArea(plotArea);
info.setDataArea(plotArea);
}
drawBackground(g2, plotArea);
drawOutline(g2, plotArea);
Shape savedClip = g2.getClip();
g2.clip(plotArea);
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
if (this.dataset != null) {
drawRadar(g2, plotArea, info, 0, this.dataset);
} else {
drawNoDataMessage(g2, plotArea);
}
g2.clip(savedClip);
g2.setComposite(originalComposite);
drawOutline(g2, plotArea);
}
use of java.awt.Composite in project processdash by dtuma.
the class DiscPlot method draw.
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// adjust for insets...
RectangleInsets insets = getInsets();
insets.trim(area);
if (info != null) {
info.setPlotArea(area);
info.setDataArea(area);
}
drawBackground(g2, area);
drawOutline(g2, area);
Shape savedClip = g2.getClip();
g2.clip(area);
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
if (!getDiscDistributor().isDatasetEmpty()) {
Rectangle2D dataArea = getDataArea(area);
drawDiscs(g2, dataArea, info);
drawLegendAxis(g2, dataArea, info);
} else {
drawNoDataMessage(g2, area);
}
g2.setClip(savedClip);
g2.setComposite(originalComposite);
drawOutline(g2, area);
}
use of java.awt.Composite in project gephi by gephi.
the class GradientSliderUI method paintTrack.
@Override
protected void paintTrack(Graphics2D g) {
Composite oldComposite = g.getComposite();
float alpha = slider.isEnabled() ? 1 : .5f;
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
Shape frame = getFrame();
boolean alwaysOpaque = getProperty(slider, "GradientSlider.showTranslucency", "true").equals("false");
if (alwaysOpaque == false) {
if (checkerPaint == null) {
createCheckerPaint();
}
g.setPaint(checkerPaint);
g.fill(frame);
}
TexturePaint tp = new TexturePaint(img, new Rectangle(trackRect.x, 0, img.getWidth(), 1));
g.setPaint(tp);
AffineTransform oldTransform = null;
oldTransform = g.getTransform();
AffineTransform transform = new AffineTransform();
if (slider.getOrientation() == GradientSlider.VERTICAL) {
if (slider.isInverted()) {
transform.rotate(Math.PI / 2, trackRect.x, trackRect.y);
} else {
transform.rotate(-Math.PI / 2, trackRect.x, trackRect.y + trackRect.height);
}
} else if (slider.isInverted()) {
//flip horizontal:
double x1 = trackRect.x;
double x2 = trackRect.x + trackRect.width;
//m00*x1+m02 = x2
//m00*x2+m02 = x1
double m00 = (x2 - x1) / (x1 - x2);
double m02 = x1 - m00 * x2;
transform.setTransform(m00, 0, 0, 1, m02, 0);
} else {
//no transform necessary
}
g.transform(transform);
try {
g.fill(transform.createInverse().createTransformedShape(trackRect));
} catch (NoninvertibleTransformException e) {
//this won't happen; unless a width/height
//is zero somewhere, in which case we have nothing to paint anyway.
}
if (oldTransform != null) {
g.setTransform(oldTransform);
}
if (getProperty(slider, "GradientSlider.useBevel", "false").equals("true")) {
PaintUtils.drawBevel(g, trackRect);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Shape oldClip = g.getClip();
int first, last;
Color[] colors = ((GradientSlider) slider).getColors();
float[] f = slider.getThumbPositions();
if ((slider.isInverted() == false && slider.getOrientation() == GradientSlider.HORIZONTAL) || (slider.isInverted() == true && slider.getOrientation() == GradientSlider.VERTICAL)) {
first = 0;
last = colors.length - 1;
while (f[first] < 0) {
first++;
}
while (f[last] > 1) {
last--;
}
} else {
last = 0;
first = colors.length - 1;
while (f[last] < 0) {
last++;
}
while (f[first] > 1) {
first--;
}
}
if (slider.getOrientation() == GradientSlider.HORIZONTAL) {
g.clip(frame);
g.setColor(colors[first]);
g.fillRect(0, 0, trackRect.x, slider.getHeight());
g.setColor(colors[last]);
g.fillRect(trackRect.x + trackRect.width, 0, slider.getWidth() - (trackRect.x + trackRect.width), slider.getHeight());
} else {
g.clip(frame);
g.setColor(colors[first]);
g.fillRect(0, 0, slider.getWidth(), trackRect.y);
g.setColor(colors[last]);
g.fillRect(0, trackRect.y + trackRect.height, slider.getWidth(), slider.getHeight() - (trackRect.y + trackRect.height));
}
g.setStroke(new BasicStroke(1));
g.setClip(oldClip);
g.setColor(new Color(0, 0, 0, 130));
g.draw(frame);
g.setColor(new Color(0, 0, 0, 130));
}
if (slider.isPaintTicks()) {
paintTick(g, .25f, 2);
paintTick(g, .5f, 2);
paintTick(g, .75f, 2);
paintTick(g, 0f, 2);
paintTick(g, 1f, 2);
}
g.setComposite(oldComposite);
}
use of java.awt.Composite in project smile by haifengl.
the class Graphics method fillPolygon.
/**
* Fill polygon. The coordinates are in logical coordinates. This also supports
* basic alpha compositing rules for combining source and destination
* colors to achieve blending and transparency effects with graphics and images.
*
* @param alpha the constant alpha to be multiplied with the alpha of the
* source. alpha must be a floating point number in the inclusive range
* [0.0, 1.0].
*/
public void fillPolygon(float alpha, double[]... coord) {
int[][] c = new int[coord.length][2];
for (int i = 0; i < coord.length; i++) {
c[i] = projection.screenProjection(coord[i]);
}
int[] x = new int[c.length];
for (int i = 0; i < c.length; i++) {
x[i] = c[i][0];
}
int[] y = new int[c.length];
for (int i = 0; i < c.length; i++) {
y[i] = c[i][1];
}
Composite cs = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g2d.fillPolygon(x, y, c.length);
g2d.setComposite(cs);
}
Aggregations