use of java.awt.Composite in project SIMVA-SoS by SESoS.
the class DefaultPolarItemRenderer method drawSeries.
/**
* Plots the data for a given series.
*
* @param g2 the drawing surface.
* @param dataArea the data area.
* @param info collects plot rendering info.
* @param plot the plot.
* @param dataset the dataset.
* @param seriesIndex the series index.
*/
@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) {
final int numPoints = dataset.getItemCount(seriesIndex);
if (numPoints == 0) {
return;
}
GeneralPath poly = null;
ValueAxis axis = plot.getAxisForDataset(plot.indexOf(dataset));
for (int i = 0; i < numPoints; i++) {
double theta = dataset.getXValue(seriesIndex, i);
double radius = dataset.getYValue(seriesIndex, i);
Point p = plot.translateToJava2D(theta, radius, axis, dataArea);
if (poly == null) {
poly = new GeneralPath();
poly.moveTo(p.x, p.y);
} else {
poly.lineTo(p.x, p.y);
}
}
assert poly != null;
if (getConnectFirstAndLastPoint()) {
poly.closePath();
}
g2.setPaint(lookupSeriesPaint(seriesIndex));
g2.setStroke(lookupSeriesStroke(seriesIndex));
if (isSeriesFilled(seriesIndex)) {
Composite savedComposite = g2.getComposite();
g2.setComposite(this.fillComposite);
g2.fill(poly);
g2.setComposite(savedComposite);
if (this.drawOutlineWhenFilled) {
// draw the outline of the filled polygon
g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
g2.draw(poly);
}
} else {
// just the lines, no filling
g2.draw(poly);
}
// draw the item shapes
if (this.shapesVisible) {
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
PathIterator pi = poly.getPathIterator(null);
int i = 0;
while (!pi.isDone()) {
final float[] coords = new float[6];
final int segType = pi.currentSegment(coords);
pi.next();
if (segType != PathIterator.SEG_LINETO && segType != PathIterator.SEG_MOVETO) {
continue;
}
final int x = Math.round(coords[0]);
final int y = Math.round(coords[1]);
final Shape shape = ShapeUtilities.createTranslatedShape(getItemShape(seriesIndex, i++), x, y);
Paint paint;
if (useFillPaint) {
paint = lookupSeriesFillPaint(seriesIndex);
} else {
paint = lookupSeriesPaint(seriesIndex);
}
g2.setPaint(paint);
g2.fill(shape);
if (isSeriesFilled(seriesIndex) && this.drawOutlineWhenFilled) {
g2.setPaint(lookupSeriesOutlinePaint(seriesIndex));
g2.setStroke(lookupSeriesOutlineStroke(seriesIndex));
g2.draw(shape);
}
// data area...
if (entities != null && AbstractXYItemRenderer.isPointInRect(dataArea, x, y)) {
addEntity(entities, shape, dataset, seriesIndex, i - 1, x, y);
}
}
}
}
use of java.awt.Composite in project hale by halestudio.
the class CachingPainter method beginPainting.
/**
* Start the painting by creating a graphics object to paint on
*
* @param width the desired width
* @param height the desired height
* @param originX the translation of the origin in x-direction
* @param originY the translation of the origin in y-direction
* @return the graphics device to use for painting
*/
protected Graphics2D beginPainting(int width, int height, int originX, int originY) {
this.originX = originX;
this.originY = originY;
BufferedImage img = (cachedImage == null) ? (null) : (cachedImage.get());
clearCache();
boolean clear = true;
if (img == null || img.getWidth() != width || img.getHeight() != height) {
img = GraphicsUtilities.createCompatibleTranslucentImage(width, height);
cachedImage = new SoftReference<BufferedImage>(img);
clear = false;
}
Graphics2D gfx = img.createGraphics();
gfx.setClip(0, 0, width, height);
if (clear) {
Composite composite = gfx.getComposite();
gfx.setComposite(AlphaComposite.Clear);
gfx.fillRect(0, 0, width, height);
gfx.setComposite(composite);
}
gfx.translate(originX, originY);
configureGraphics(gfx);
return gfx;
}
use of java.awt.Composite in project omegat by omegat-org.
the class TransparentHighlightPainter method paint.
protected void paint(Graphics g, Rectangle rect, JTextComponent c) {
Graphics2D g2d = (Graphics2D) g;
Composite originalComposite = g2d.getComposite();
g2d.setComposite(alphaComposite);
g2d.setPaint(color);
g2d.fill(rect);
g2d.setComposite(originalComposite);
}
use of java.awt.Composite in project sulky by huxi.
the class GraphicsUtilities method drawHighlight.
/**
* Draws the highlight for the given shape. The highlight is painted using the current color of g2.
*
* @param g2 the graphics context.
* @param s the shape.
* @param size the size of the highlight.
* @param opacity the opacity of the highlight.
*/
public static void drawHighlight(Graphics2D g2, Shape s, int size, float opacity) {
if (Float.compare(opacity, 0.0f) == 0) {
// return if transparent
return;
}
final Logger logger = LoggerFactory.getLogger(GraphicsUtilities.class);
Composite c = g2.getComposite();
for (int i = -size; i <= size; i++) {
for (int j = -size; j <= size; j++) {
float distance = i * i + j * j;
float alpha = opacity;
if (Float.compare(distance, 0.0f) > 0) {
alpha = (1.0f / distance) * opacity * size;
if (logger.isDebugEnabled())
logger.debug("Calculated alpha: {}", alpha);
}
if (alpha > 1.0) {
if (logger.isDebugEnabled())
logger.debug("Corrected alpha: {}", alpha);
alpha = 1.0f;
}
// g2.setComposite(AlphaComposite.SrcOver.derive(alpha));
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g2.translate(i, j);
g2.fill(s);
g2.translate(-i, -j);
}
}
g2.setComposite(c);
}
use of java.awt.Composite in project litiengine by gurkenlabs.
the class SpriteParticle method render.
@Override
public void render(final Graphics2D g, final Point2D emitterOrigin) {
final Point2D renderLocation = getRenderLocation(emitterOrigin);
if (isAnimatingSprite()) {
currentImage = animation.getCurrentImage();
}
Composite oldComp = g.getComposite();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getOpacity()));
if (getAngle() != 0) {
ImageRenderer.renderRotated(g, currentImage, renderLocation, getAngle());
} else {
ImageRenderer.render(g, currentImage, renderLocation);
}
g.setComposite(oldComp);
}
Aggregations