01: package test;
02:
03: import java.awt.*;
04: import java.awt.geom.Area;
05: import java.awt.image.BufferedImage;
06:
07: import javax.swing.JFrame;
08: import javax.swing.JPanel;
09:
10: import org.jvnet.substance.button.BaseButtonShaper;
11: import org.jvnet.substance.color.ColorScheme;
12: import org.jvnet.substance.color.MetallicColorScheme;
13: import org.jvnet.substance.painter.SimplisticGradientPainter;
14: import org.jvnet.substance.utils.SubstanceCoreUtilities;
15:
16: public class TestMix extends JFrame {
17:
18: public TestMix() {
19: this .setSize(new Dimension(200, 100));
20: this .setLocationRelativeTo(null);
21: this .setLayout(new BorderLayout());
22: this .add(new GradPanel(), BorderLayout.CENTER);
23: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24: this .setVisible(true);
25: }
26:
27: public static final class GradPanel extends JPanel {
28: @Override
29: public void paint(Graphics g) {
30: Graphics2D graphics = (Graphics2D) g;
31: int w = getWidth();
32: int h = getHeight();
33: BufferedImage im1 = new BufferedImage(w, h,
34: BufferedImage.TYPE_INT_ARGB);
35: Graphics g1 = im1.getGraphics();
36: g1.setColor(Color.red);
37: g1.fillRect(0, 0, w, h);
38: BufferedImage im2 = new BufferedImage(w, h,
39: BufferedImage.TYPE_INT_ARGB);
40: Graphics g2 = im2.getGraphics();
41: g2.setColor(Color.blue);
42: g2.fillRect(0, 0, w, h);
43:
44: BufferedImage mixImage = SubstanceCoreUtilities
45: .blendImagesHorizontal(im1, im2, 0.0, 1.0);
46: Graphics2D mixGraphics = mixImage.createGraphics();
47: int width = 100;
48: int height = 20;
49: int radius = 10;
50: ColorScheme mainScheme = new MetallicColorScheme();
51: Shape shape = BaseButtonShaper.getBaseOutline(width,
52: height, radius, null);
53: BufferedImage opaque = new SimplisticGradientPainter()
54: .getContourBackground(width, height, shape, false,
55: mainScheme, mainScheme, 0, true, false);
56:
57: mixGraphics.drawImage(opaque, 0, 0, null);
58:
59: graphics.setColor(new Color(0, 255, 0, 50));
60: graphics.fillRect(0, 0, w, h);
61:
62: Area area = new Area(new Rectangle(0, 0, w, h));
63: area.subtract(new Area(shape));
64:
65: // graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
66: // RenderingHints.VALUE_ANTIALIAS_ON);
67: // Shape clip = g.getClip();
68: // graphics.setClip(area);
69: // graphics.drawImage(mixImage, 0, 0, null);
70: //
71: // graphics.setClip(clip);
72: // graphics.setComposite(AlphaComposite.getInstance(
73: // AlphaComposite.SRC_OVER, 0.3f));
74: // graphics.drawImage(opaque, 0, 0, null);
75: //
76: graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
77: RenderingHints.VALUE_ANTIALIAS_ON);
78: graphics.drawImage(mixImage, 0, 0, null);
79:
80: graphics.setComposite(AlphaComposite.getInstance(
81: AlphaComposite.DST_OUT, 0.3f));
82: graphics.drawImage(opaque, 0, 0, null);
83:
84: graphics.dispose();
85: }
86: }
87:
88: public static void main(String[] args) {
89: new TestMix();
90: }
91:
92: }
|