1 18 package org.apache.tools.ant.types.optional.image; 19 20 import javax.media.jai.PlanarImage; 21 import java.awt.BasicStroke ; 22 import java.awt.Graphics2D ; 23 import java.awt.geom.Ellipse2D ; 24 import java.awt.image.BufferedImage ; 25 26 30 public class Ellipse extends BasicShape implements DrawOperation { 31 protected int width = 0; 33 protected int height = 0; 34 36 40 public void setWidth(int width) { 41 this.width = width; 42 } 43 44 48 public void setHeight(int height) { 49 this.height = height; 50 } 51 52 53 public PlanarImage executeDrawOperation() { 54 BufferedImage bi = new BufferedImage (width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE); 55 56 Graphics2D graphics = (Graphics2D ) bi.getGraphics(); 57 58 if (!stroke.equals("transparent")) { 59 BasicStroke bStroke = new BasicStroke (stroke_width); 60 graphics.setColor(ColorMapper.getColorByName(stroke)); 61 graphics.setStroke(bStroke); 62 graphics.draw(new Ellipse2D.Double (0, 0, width, height)); 63 } 64 65 if (!fill.equals("transparent")) { 66 graphics.setColor(ColorMapper.getColorByName(fill)); 67 graphics.fill(new Ellipse2D.Double (0, 0, width, height)); 68 } 69 70 71 for (int i = 0; i < instructions.size(); i++) { 72 ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); 73 if (instr instanceof DrawOperation) { 74 PlanarImage img = ((DrawOperation) instr).executeDrawOperation(); 75 graphics.drawImage(img.getAsBufferedImage(), null, 0, 0); 76 } else if (instr instanceof TransformOperation) { 77 graphics = (Graphics2D ) bi.getGraphics(); 78 PlanarImage image = ((TransformOperation) instr) 79 .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); 80 bi = image.getAsBufferedImage(); 81 } 82 } 83 return PlanarImage.wrapRenderedImage(bi); 84 } 85 } 86 | Popular Tags |