1 18 package org.apache.batik.svggen; 19 20 import java.awt.AlphaComposite ; 21 import java.awt.BasicStroke ; 22 import java.awt.Color ; 23 import java.awt.Graphics2D ; 24 import java.awt.Rectangle ; 25 import java.awt.RenderingHints ; 26 27 35 public class Color2 implements Painter { 36 public void paint(Graphics2D g) { 37 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 38 RenderingHints.VALUE_ANTIALIAS_ON); 39 40 Color blue = Color.blue; 42 Color green = Color.green; 43 Color transparentBlue = new Color (0, 0, 255, 128); 44 Color transparentGreen = new Color (0, 255, 0, 128); 45 46 AlphaComposite srcOver = AlphaComposite.SrcOver; 48 AlphaComposite srcOverTransparent = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f); 49 50 Rectangle rect = new Rectangle (10, 40, 100, 50); 52 53 BasicStroke thickStroke = new BasicStroke (5); 55 56 g.setPaint(Color.black); 58 g.drawString("Opaque Colors, Half Transparent AlphaComposite", 10, 30); 59 60 g.setComposite(srcOverTransparent); 61 g.setStroke(thickStroke); 62 g.setPaint(blue); 63 g.fill(rect); 64 g.setPaint(green); 65 g.draw(rect); 66 g.setPaint(Color.black); 67 g.fill(rect); 68 69 g.translate(0, 90); 70 71 g.setPaint(Color.black); 73 g.setComposite(srcOver); 74 g.drawString("Transparent Colors, Opaque AlphaComposite SrcOver", 10, 30); 75 76 g.setPaint(transparentBlue); 77 g.fill(rect); 78 g.setPaint(transparentGreen); 79 g.draw(rect); 80 } 81 } 82 | Popular Tags |