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.image.BufferedImage ; 24 25 29 public class Rectangle extends BasicShape implements DrawOperation { 30 protected int width = 0; 32 protected int height = 0; 33 protected int arcwidth = 0; 34 protected int archeight = 0; 35 37 41 public void setWidth(int w) { 42 width = w; 43 } 44 45 49 public void setHeight(int h) { 50 height = h; 51 } 52 53 57 public void setArcwidth(int w) { 58 arcwidth = w; 59 } 60 61 65 public void setArcheight(int h) { 66 archeight = h; 67 } 68 69 70 public PlanarImage executeDrawOperation() { 71 log("\tCreating Rectangle w=" + width + " h=" + height + " arcw=" 72 + arcwidth + " arch=" + archeight); 73 BufferedImage bi = new BufferedImage (width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE); 74 75 Graphics2D graphics = (Graphics2D ) bi.getGraphics(); 76 77 if (!stroke.equals("transparent")) { 78 BasicStroke bStroke = new BasicStroke (stroke_width); 79 graphics.setColor(ColorMapper.getColorByName(stroke)); 80 graphics.setStroke(bStroke); 81 82 if ((arcwidth != 0) || (archeight != 0)) { 83 graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight); 84 } else { 85 graphics.drawRect(0, 0, width, height); 86 } 87 } 88 89 if (!fill.equals("transparent")) { 90 graphics.setColor(ColorMapper.getColorByName(fill)); 91 if ((arcwidth != 0) || (archeight != 0)) { 92 graphics.fillRoundRect(stroke_width, stroke_width, 93 width - (stroke_width * 2), height - (stroke_width * 2), 94 arcwidth, archeight); 95 } else { 96 graphics.fillRect(stroke_width, stroke_width, 97 width - (stroke_width * 2), height - (stroke_width * 2)); 98 } 99 } 100 101 102 for (int i = 0; i < instructions.size(); i++) { 103 ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); 104 if (instr instanceof DrawOperation) { 105 PlanarImage img = ((DrawOperation) instr).executeDrawOperation(); 106 graphics.drawImage(img.getAsBufferedImage(), null, 0, 0); 107 } else if (instr instanceof TransformOperation) { 108 graphics = (Graphics2D ) bi.getGraphics(); 109 PlanarImage image 110 = ((TransformOperation) instr) 111 .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); 112 bi = image.getAsBufferedImage(); 113 } 114 } 115 return PlanarImage.wrapRenderedImage(bi); 116 } 117 } 118 | Popular Tags |