use of java.awt.AlphaComposite 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.AlphaComposite in project litiengine by gurkenlabs.
the class MapRenderer method renderImageLayer.
protected static void renderImageLayer(Graphics2D g, IImageLayer layer, final IMap map, Rectangle2D viewport, float opacity) {
Spritesheet sprite = Resources.spritesheets().get(layer.getImage().getSource());
BufferedImage img;
if (sprite == null) {
img = Resources.images().get(layer.getImage().getAbsoluteSourcePath());
} else {
img = sprite.getImage();
}
if (img == null) {
return;
}
final Composite oldComp = g.getComposite();
final AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
g.setComposite(ac);
final double viewportOffsetX = layer.getOffset().x - viewport.getX();
final double viewportOffsetY = layer.getOffset().y - viewport.getY();
ImageRenderer.render(g, img, viewportOffsetX, viewportOffsetY);
g.setComposite(oldComp);
final LayerRenderEvent event = new LayerRenderEvent(g, map, layer);
for (LayerRenderedListener listener : layerRenderedListeners) {
listener.rendered(event);
}
}
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 sirix by sirixdb.
the class ProgressGlassPane method paintComponent.
@Override
protected void paintComponent(Graphics g) {
// enables anti-aliasing
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// gets the current clipping area
Rectangle clip = g.getClipBounds();
// sets a 65% translucent composite
AlphaComposite alpha = AlphaComposite.SrcOver.derive(0.65f);
Composite composite = g2.getComposite();
g2.setComposite(alpha);
// fills the background
g2.setColor(getBackground());
g2.fillRect(clip.x, clip.y, clip.width, clip.height);
// centers the progress bar on screen
FontMetrics metrics = g.getFontMetrics();
int x = (getWidth() - BAR_WIDTH) / 2;
int y = (getHeight() - BAR_HEIGHT - metrics.getDescent()) / 2;
// draws the text
g2.setColor(TEXT_COLOR);
g2.drawString(message, x, y);
// goes to the position of the progress bar
y += metrics.getDescent();
// computes the size of the progress indicator
int w = (int) (BAR_WIDTH * ((float) progress / 100.0f));
int h = BAR_HEIGHT;
// draws the content of the progress bar
Paint paint = g2.getPaint();
// bar's background
Paint gradient = new GradientPaint(x, y, GRADIENT_COLOR1, x, y + h, GRADIENT_COLOR2);
g2.setPaint(gradient);
g2.fillRect(x, y, BAR_WIDTH, BAR_HEIGHT);
// actual progress
gradient = new LinearGradientPaint(x, y, x, y + h, GRADIENT_FRACTIONS, GRADIENT_COLORS);
g2.setPaint(gradient);
g2.fillRect(x, y, w, h);
g2.setPaint(paint);
// draws the progress bar border
g2.drawRect(x, y, BAR_WIDTH, BAR_HEIGHT);
g2.setComposite(composite);
}
use of java.awt.AlphaComposite in project com.revolsys.open by revolsys.
the class GeoreferencedImageLayerRenderer method renderAlpha.
public static void renderAlpha(final Viewport2D viewport, final Graphics2D graphics, final GeoreferencedImage image, final boolean useTransform, final double alpha, Object interpolationMethod) {
final Composite composite = graphics.getComposite();
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, false)) {
AlphaComposite alphaComposite = AlphaComposite.SrcOver;
if (alpha < 1) {
alphaComposite = alphaComposite.derive((float) alpha);
}
graphics.setComposite(alphaComposite);
render(viewport, graphics, image, useTransform, interpolationMethod);
} finally {
graphics.setComposite(composite);
}
}
Aggregations