use of java.awt.AlphaComposite in project EnrichmentMapApp by BaderLab.
the class AbstractChartLayer method draw.
@Override
public void draw(final Graphics2D g, final Shape shape, final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
// Give JFreeChart a larger area to draw into, so the proportions of the chart elements looks better
final double scale = 2.0;
Rectangle2D newBounds = new Rectangle2D.Double(bounds.getX() * scale, bounds.getY() * scale, bounds.getWidth() * scale, bounds.getHeight() * scale);
// Of course, we also have to ask Graphics2D to apply the inverse transformation
final double invScale = 1.0 / scale;
final AffineTransform at = new AffineTransform();
at.scale(invScale, invScale);
g.transform(at);
// Check to see if we have a current alpha composite
Composite comp = g.getComposite();
if (comp instanceof AlphaComposite) {
float alpha = ((AlphaComposite) comp).getAlpha();
JFreeChart fc = getChart();
Plot plot = fc.getPlot();
plot.setForegroundAlpha(alpha);
fc.draw(g, newBounds);
} else {
getChart().draw(g, newBounds);
}
// Make sure Graphics2D is "back to normal" before returning
try {
at.invert();
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
g.transform(at);
}
use of java.awt.AlphaComposite in project archi by archimatetool.
the class GraphicsToGraphics2DAdaptor method setAlpha.
@Override
public void setAlpha(int alpha) {
swtGraphics.setAlpha(alpha);
currentState.alpha = alpha;
Composite composite = getGraphics2D().getComposite();
if (composite instanceof AlphaComposite) {
AlphaComposite newComposite = AlphaComposite.getInstance(((AlphaComposite) composite).getRule(), (float) alpha / (float) 255);
getGraphics2D().setComposite(newComposite);
}
}
use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class BufferedMaskBlit method MaskBlit.
@Override
public void MaskBlit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int srcx, int srcy, int dstx, int dsty, int width, int height, byte[] mask, int maskoff, int maskscan) {
if (width <= 0 || height <= 0) {
return;
}
if (mask == null) {
// no mask involved; delegate to regular blit loop
if (blitop == null) {
blitop = Blit.getFromCache(src.getSurfaceType(), CompositeType.AnyAlpha, this.getDestType());
}
blitop.Blit(src, dst, comp, clip, srcx, srcy, dstx, dsty, width, height);
return;
}
AlphaComposite acomp = (AlphaComposite) comp;
if (acomp.getRule() != AlphaComposite.SRC_OVER) {
comp = AlphaComposite.SrcOver;
}
rq.lock();
try {
validateContext(dst, comp, clip);
RenderBuffer buf = rq.getBuffer();
int totalBytesRequired = 20 + (width * height * 4);
/*
* REMIND: we should fix this so that it works with tiles that
* are larger than the entire buffer, but the native
* OGL/D3DMaskBlit isn't even prepared for tiles larger
* than 32x32 pixels, so there's no urgency here...
*/
rq.ensureCapacity(totalBytesRequired);
// enqueue parameters and tile pixels
int newpos = enqueueTile(buf.getAddress(), buf.position(), src, src.getNativeOps(), srcTypeVal, mask, mask.length, maskoff, maskscan, srcx, srcy, dstx, dsty, width, height);
buf.position(newpos);
} finally {
rq.unlock();
}
}
use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class BufferedMaskFill method MaskFill.
@Override
public void MaskFill(SunGraphics2D sg2d, SurfaceData sData, Composite comp, final int x, final int y, final int w, final int h, final byte[] mask, final int maskoff, final int maskscan) {
AlphaComposite acomp = (AlphaComposite) comp;
if (acomp.getRule() != AlphaComposite.SRC_OVER) {
comp = AlphaComposite.SrcOver;
}
rq.lock();
try {
validateContext(sg2d, comp, BufferedContext.USE_MASK);
// we adjust the mask length so that the mask ends on a
// 4-byte boundary
int maskBytesRequired;
if (mask != null) {
// we adjust the mask length so that the mask ends on a
// 4-byte boundary
maskBytesRequired = (mask.length + 3) & (~3);
} else {
// mask not needed
maskBytesRequired = 0;
}
int totalBytesRequired = 32 + maskBytesRequired;
RenderBuffer buf = rq.getBuffer();
if (totalBytesRequired <= buf.capacity()) {
if (totalBytesRequired > buf.remaining()) {
// process the queue first and then enqueue the mask
rq.flushNow();
}
buf.putInt(MASK_FILL);
// enqueue parameters
buf.putInt(x).putInt(y).putInt(w).putInt(h);
buf.putInt(maskoff);
buf.putInt(maskscan);
buf.putInt(maskBytesRequired);
if (mask != null) {
// enqueue the mask
int padding = maskBytesRequired - mask.length;
buf.put(mask);
if (padding != 0) {
buf.position(buf.position() + padding);
}
}
} else {
// queue is too small to accommodate entire mask; perform
// the operation directly on the queue flushing thread
rq.flushAndInvokeNow(new Runnable() {
public void run() {
maskFill(x, y, w, h, maskoff, maskscan, mask.length, mask);
}
});
}
} finally {
rq.unlock();
}
}
use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class BufferedContext method setComposite.
private void setComposite(Composite comp, int flags) {
// assert rq.lock.isHeldByCurrentThread();
if (comp instanceof AlphaComposite) {
AlphaComposite ac = (AlphaComposite) comp;
rq.ensureCapacity(16);
buf.putInt(SET_ALPHA_COMPOSITE);
buf.putInt(ac.getRule());
buf.putFloat(ac.getAlpha());
buf.putInt(flags);
} else if (comp instanceof XORComposite) {
int xorPixel = ((XORComposite) comp).getXorPixel();
rq.ensureCapacity(8);
buf.putInt(SET_XOR_COMPOSITE);
buf.putInt(xorPixel);
} else {
throw new InternalError("not yet implemented");
}
}
Aggregations