/**
* Paints background image.
*/
private void paintBackgroundImage(Graphics2D g2D, PaintMode paintMode) {
final BackgroundImage backgroundImage = this.home.getBackgroundImage();
if (backgroundImage != null && backgroundImage.isVisible()) {
if (this.backgroundImageCache == null && paintMode == PaintMode.PAINT) {
// Load background image in an executor
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
backgroundImageCache = readImage(backgroundImage.getImage());
revalidate();
}
});
} else {
// Paint image at specified scale with 0.7 alpha
AffineTransform previousTransform = g2D.getTransform();
g2D.translate(-backgroundImage.getXOrigin(), -backgroundImage.getYOrigin());
g2D.scale(backgroundImage.getScale(), backgroundImage.getScale());
Composite oldComposite = g2D.getComposite();
if (oldComposite instanceof AlphaComposite) {
g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
((AlphaComposite)oldComposite).getAlpha() * 0.7f));
} else {
g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
}
g2D.drawImage(this.backgroundImageCache != null
? this.backgroundImageCache
: readImage(backgroundImage.getImage()), 0, 0, this);
g2D.setComposite(oldComposite);
g2D.setTransform(previousTransform);
}
}
}