1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.Graphics2D ; 22 import java.awt.Rectangle ; 23 import java.awt.RenderingHints ; 24 import java.awt.image.BufferedImage ; 25 26 34 public class Texture implements Painter { 35 public void paint(Graphics2D g) { 36 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 37 RenderingHints.VALUE_ANTIALIAS_ON); 38 Color labelColor = Color.black; 39 40 BufferedImage texture = new BufferedImage (20, 20, BufferedImage.TYPE_INT_RGB); 41 Graphics2D bg = texture.createGraphics(); 42 bg.setPaint(Color.red); 43 bg.fillRect(0, 0, 10, 10); 44 bg.setPaint(Color.yellow); 45 bg.fillRect(10, 10, 10, 10); 46 bg.dispose(); 47 48 Rectangle anchors[] = { new Rectangle (0, 0, texture.getWidth(), texture.getHeight()), 49 new Rectangle (texture.getWidth()/2, texture.getHeight()/2, texture.getWidth(), texture.getHeight()), 50 new Rectangle (0, 0, texture.getWidth()/2, texture.getHeight()/2) }; 51 52 String anchorDesc[] = { "Anchor matches texture image", 53 "Anchor offset to texture image center", 54 "Anchor half the size of texture" }; 55 56 59 g.translate(0, 20); 60 61 for(int i=0; i<anchors.length; i++){ 62 java.awt.TexturePaint texturePaint = new java.awt.TexturePaint (texture, anchors[i]); 63 g.setPaint(texturePaint); 64 g.fillRect(0, 0, texture.getWidth()*4, texture.getHeight()*4); 65 java.awt.geom.AffineTransform curTxf = g.getTransform(); 66 g.translate(150, 0); 67 g.shear(.5, 0); 68 g.fillRect(0, 0, texture.getWidth()*4, texture.getHeight()*4); 69 g.setTransform(curTxf); 70 g.setPaint(labelColor); 71 g.drawString(anchorDesc[i], 10, texture.getHeight()*4 + 20); 72 g.translate(0, texture.getHeight()*4 + 40); 73 } 74 } 75 } 76 | Popular Tags |