1 18 package org.apache.tools.ant.types.optional.image; 19 20 import javax.media.jai.PlanarImage; 21 import java.awt.Graphics2D ; 22 import java.awt.image.BufferedImage ; 23 24 28 public class Draw extends TransformOperation { 29 protected int xloc = 0; 31 protected int yloc = 0; 32 34 38 public void setXloc(int x) { 39 xloc = x; 40 } 41 42 46 public void setYloc(int y) { 47 yloc = y; 48 } 49 50 51 public void addRectangle(Rectangle rect) { 52 instructions.add(rect); 53 } 54 55 56 public void addText(Text text) { 57 instructions.add(text); 58 } 59 60 64 public void addEllipse(Ellipse elip) { 65 instructions.add(elip); 66 } 67 68 72 public void addArc(Arc arc) { 73 instructions.add(arc); 74 } 75 76 77 public PlanarImage executeTransformOperation(PlanarImage image) { 78 BufferedImage bi = image.getAsBufferedImage(); 79 Graphics2D graphics = (Graphics2D ) bi.getGraphics(); 80 81 for (int i = 0; i < instructions.size(); i++) { 82 ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); 83 if (instr instanceof DrawOperation) { 84 PlanarImage op = ((DrawOperation) instr).executeDrawOperation(); 85 log("\tDrawing to x=" + xloc + " y=" + yloc); 86 graphics.drawImage(op.getAsBufferedImage(), null, xloc, yloc); 87 } else if (instr instanceof TransformOperation) { 88 PlanarImage op 89 = ((TransformOperation) instr).executeTransformOperation(null); 90 BufferedImage child = op.getAsBufferedImage(); 91 log("\tDrawing to x=" + xloc + " y=" + yloc); 92 graphics.drawImage(child, null, xloc, yloc); 93 PlanarImage.wrapRenderedImage(bi); 94 } 95 } 96 image = PlanarImage.wrapRenderedImage(bi); 97 98 return image; 99 } 100 } 101 | Popular Tags |