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.Arc2D ; 24 import java.awt.image.BufferedImage ; 25 26 29 public class Arc extends BasicShape implements DrawOperation { 30 protected int width = 0; 32 protected int height = 0; 33 protected int start = 0; 34 protected int stop = 0; 35 protected int type = Arc2D.OPEN; 36 38 42 public void setWidth(int width) { 43 this.width = width; 44 } 45 46 50 public void setHeight(int height) { 51 this.height = height; 52 } 53 54 58 public void setStart(int start) { 59 this.start = start; 60 } 61 62 66 public void setStop(int stop) { 67 this.stop = stop; 68 } 69 70 75 public void setType(String strType) { 76 if (strType.toLowerCase().equals("open")) { 77 type = Arc2D.OPEN; 78 } else if (strType.toLowerCase().equals("pie")) { 79 type = Arc2D.PIE; 80 } else if (strType.toLowerCase().equals("chord")) { 81 type = Arc2D.CHORD; 82 } 83 } 84 85 86 public PlanarImage executeDrawOperation() { 87 BufferedImage bi = new BufferedImage (width + (stroke_width * 2), 88 height + (stroke_width * 2), BufferedImage.TYPE_4BYTE_ABGR_PRE); 89 90 Graphics2D graphics = (Graphics2D ) bi.getGraphics(); 91 92 if (!stroke.equals("transparent")) { 93 BasicStroke bStroke = new BasicStroke (stroke_width); 94 graphics.setColor(ColorMapper.getColorByName(stroke)); 95 graphics.setStroke(bStroke); 96 graphics.draw(new Arc2D.Double (stroke_width, stroke_width, width, 97 height, start, stop, type)); 98 } 99 100 if (!fill.equals("transparent")) { 101 graphics.setColor(ColorMapper.getColorByName(fill)); 102 graphics.fill(new Arc2D.Double (stroke_width, stroke_width, 103 width, height, start, stop, type)); 104 } 105 106 107 for (int i = 0; i < instructions.size(); i++) { 108 ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); 109 if (instr instanceof DrawOperation) { 110 PlanarImage img = ((DrawOperation) instr).executeDrawOperation(); 111 graphics.drawImage(img.getAsBufferedImage(), null, 0, 0); 112 } else if (instr instanceof TransformOperation) { 113 graphics = (Graphics2D ) bi.getGraphics(); 114 PlanarImage image = ((TransformOperation) instr) 115 .executeTransformOperation(PlanarImage.wrapRenderedImage(bi)); 116 bi = image.getAsBufferedImage(); 117 } 118 } 119 return PlanarImage.wrapRenderedImage(bi); 120 } 121 } 122 | Popular Tags |