01: package org.zilonis.tool.ext.aerith.ui;
02:
03: import java.awt.AlphaComposite;
04: import java.awt.Composite;
05: import java.awt.Graphics;
06: import java.awt.Graphics2D;
07: import java.awt.Image;
08: import java.awt.LinearGradientPaint;
09: import java.awt.RenderingHints;
10: import java.awt.image.BufferedImage;
11:
12: import javax.swing.JPanel;
13:
14: import org.jdesktop.fuse.InjectedResource;
15: import org.jdesktop.fuse.ResourceInjector;
16: import org.zilonis.tool.ext.aerith.g2d.GraphicsUtil;
17:
18: public class ContentPanel extends JPanel {
19: ////////////////////////////////////////////////////////////////////////////
20: // THEME SPECIFIC FIELDS
21: ////////////////////////////////////////////////////////////////////////////
22: @InjectedResource
23: private LinearGradientPaint backgroundGradient;
24: @InjectedResource
25: private BufferedImage light;
26: @InjectedResource
27: private float lightOpacity;
28:
29: // Intermediate image to avoid gradient repaints
30: private Image gradientImage = null;
31:
32: public ContentPanel() {
33: ResourceInjector.get().inject(this );
34: }
35:
36: @Override
37: protected void paintComponent(Graphics g) {
38: if (!isVisible()) {
39: return;
40: }
41:
42: Graphics2D g2 = (Graphics2D) g;
43:
44: if (gradientImage == null) {
45: // Only create this once; this assumes that the size of this
46: // container never changes
47: gradientImage = GraphicsUtil.createCompatibleImage(
48: getWidth(), getHeight());
49: Graphics2D g2d = (Graphics2D) gradientImage.getGraphics();
50: Composite composite = g2.getComposite();
51: g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
52: RenderingHints.VALUE_INTERPOLATION_BILINEAR);
53: g2d.setPaint(backgroundGradient);
54: g2d.fillRect(0, 0, getWidth(), getHeight());
55: g2d.setComposite(AlphaComposite.getInstance(
56: AlphaComposite.SRC_OVER, lightOpacity));
57: g2d.drawImage(light, 0, 0, getWidth(), light.getHeight(),
58: null);
59: g2d.setComposite(composite);
60: g2d.dispose();
61: // !!! ONLY BECAUSE WE NEVER RECREATE THE INTERMEDIATE IMAGE
62: light = null;
63: }
64:
65: g2.drawImage(gradientImage, 0, 0, null);
66: }
67: }
|