diff --git a/src/main/org/apache/tools/ant/types/optional/image/Arc.java b/src/main/org/apache/tools/ant/types/optional/image/Arc.java index 4615868a0..6f64d1aea 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Arc.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Arc.java @@ -23,30 +23,53 @@ import java.awt.Graphics2D; import java.awt.geom.Arc2D; import java.awt.image.BufferedImage; +/** + * Draw an arc. + */ public class Arc extends BasicShape implements DrawOperation { + // CheckStyle:VisibilityModifier OFF - bc protected int width = 0; protected int height = 0; protected int start = 0; protected int stop = 0; protected int type = Arc2D.OPEN; + // CheckStyle:VisibilityModifier ON + /** + * Set the width. + * @param width the width of the arc. + */ public void setWidth(int width) { this.width = width; } + /** + * Set the height. + * @param height the height of the arc. + */ public void setHeight(int height) { this.height = height; } + /** + * Set the start of the arc. + * @param start the start of the arc. + */ public void setStart(int start) { this.start = start; } + /** + * Set the stop of the arc. + * @param stop the stop of the arc. + */ public void setStop(int stop) { this.stop = stop; } /** + * Set the type of arc. + * @param strType the type to use - open, pie or chord. * @todo refactor using an EnumeratedAttribute */ public void setType(String strType) { @@ -59,6 +82,7 @@ public class Arc extends BasicShape implements DrawOperation { } } + /** {@inheritDoc}. */ public PlanarImage executeDrawOperation() { BufferedImage bi = new BufferedImage(width + (stroke_width * 2), height + (stroke_width * 2), BufferedImage.TYPE_4BYTE_ABGR_PRE); diff --git a/src/main/org/apache/tools/ant/types/optional/image/BasicShape.java b/src/main/org/apache/tools/ant/types/optional/image/BasicShape.java index f6eb1d287..ee2113a71 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/BasicShape.java +++ b/src/main/org/apache/tools/ant/types/optional/image/BasicShape.java @@ -17,20 +17,38 @@ */ package org.apache.tools.ant.types.optional.image; + +/** Draw a basic shape */ public abstract class BasicShape extends ImageOperation implements DrawOperation { + // CheckStyle:VisibilityModifier OFF - bc + // CheckStyle:MemberNameCheck OFF - bc protected int stroke_width = 0; + // CheckStyle:MemberNameCheck ON protected String fill = "transparent"; protected String stroke = "black"; + // CheckStyle:VisibilityModifier ON + /** + * Set the fill attribute. + * @param col the color value to use. + */ public void setFill(String col) { fill = col; } + /** + * Set the stroke attribute. + * @param col the color value to use. + */ public void setStroke(String col) { stroke = col; } + /** + * Set the stroke width attribute. + * @param width the value to use. + */ public void setStrokewidth(int width) { stroke_width = width; } diff --git a/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java b/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java index 8eade9901..ec01a8d52 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java +++ b/src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java @@ -24,6 +24,10 @@ import java.awt.Color; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public final class ColorMapper { + /** private constructor for Utility class */ + private ColorMapper() { + } + /** black string */ public static final String COLOR_BLACK = "black"; /** blue string */ @@ -59,6 +63,9 @@ public final class ColorMapper { public static final String COLOR_YELLOW = "yellow"; /** + * Convert a color name to a color value. + * @param colorName a string repr of the color. + * @return the color value. * @todo refactor to use an EnumeratedAttribute (maybe?) */ public static Color getColorByName(String colorName) { diff --git a/src/main/org/apache/tools/ant/types/optional/image/Draw.java b/src/main/org/apache/tools/ant/types/optional/image/Draw.java index d1bd8be20..b46ae41dd 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Draw.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Draw.java @@ -26,34 +26,54 @@ import java.awt.image.BufferedImage; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Draw extends TransformOperation { + // CheckStyle:VisibilityModifier OFF - bc protected int xloc = 0; protected int yloc = 0; + // CheckStyle:VisibilityModifier ON + /** + * Set the X location. + * @param x the value to use. + */ public void setXloc(int x) { xloc = x; } + /** + * Set the Y location. + * @param y the value to use. + */ public void setYloc(int y) { yloc = y; } + /** {@inheritDoc}. */ public void addRectangle(Rectangle rect) { instructions.add(rect); } + /** {@inheritDoc}. */ public void addText(Text text) { instructions.add(text); } + /** + * Add an ellipse. + * @param elip the ellipse to add. + */ public void addEllipse(Ellipse elip) { instructions.add(elip); } + /** + * Add an arc. + * @param arc the arc to add. + */ public void addArc(Arc arc) { instructions.add(arc); } - + /** {@inheritDoc}. */ public PlanarImage executeTransformOperation(PlanarImage image) { BufferedImage bi = image.getAsBufferedImage(); Graphics2D graphics = (Graphics2D) bi.getGraphics(); diff --git a/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java b/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java index 3f1958c2d..f4701e1f3 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Ellipse.java @@ -24,21 +24,32 @@ import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; /** - * + * Draw an ellipse. * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Ellipse extends BasicShape implements DrawOperation { + // CheckStyle:VisibilityModifier OFF - bc protected int width = 0; protected int height = 0; + // CheckStyle:VisibilityModifier ON + /** + * Set the width. + * @param width the width of the elipse. + */ public void setWidth(int width) { this.width = width; } + /** + * Set the height. + * @param height the height of the elipse. + */ public void setHeight(int height) { this.height = height; } + /** {@inheritDoc}. */ public PlanarImage executeDrawOperation() { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE); diff --git a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java index 377ad710d..df6c84812 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java +++ b/src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java @@ -25,25 +25,47 @@ import java.util.Vector; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public abstract class ImageOperation extends DataType { + // CheckStyle:VisibilityModifier OFF - bc protected Vector instructions = new Vector(); + // CheckStyle:VisibilityModifier ON + /** + * Add a rotate to the operation. + * @param instr the rotate to add. + */ public void addRotate(Rotate instr) { instructions.add(instr); } + /** + * Add a draw to the operation. + * @param instr the draw to add. + */ public void addDraw(Draw instr) { instructions.add(instr); } + /** + * Add a rectangle to the operation. + * @param instr the rectangle to add. + */ public void addRectangle(Rectangle instr) { instructions.add(instr); } + /** + * Add text to the operation. + * @param instr the text to add. + */ public void addText(Text instr) { instructions.add(instr); } + /** + * Add a scale to the operation. + * @param instr the scale to add. + */ public void addScale(Scale instr) { instructions.add(instr); } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java b/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java index b2e3cc1f9..f3204e760 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Rectangle.java @@ -27,27 +27,46 @@ import java.awt.image.BufferedImage; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Rectangle extends BasicShape implements DrawOperation { + // CheckStyle:VisibilityModifier OFF - bc protected int width = 0; protected int height = 0; protected int arcwidth = 0; protected int archeight = 0; + // CheckStyle:VisibilityModifier ON + /** + * Set the width. + * @param w the value to use. + */ public void setWidth(int w) { width = w; } + /** + * Set the height. + * @param h the value to use. + */ public void setHeight(int h) { height = h; } + /** + * Set the arc width. + * @param w the value to use. + */ public void setArcwidth(int w) { arcwidth = w; } + /** + * Set the arc height. + * @param h the value to use. + */ public void setArcheight(int h) { archeight = h; } + /** {@inheritDoc}. */ public PlanarImage executeDrawOperation() { log("\tCreating Rectangle w=" + width + " h=" + height + " arcw=" + arcwidth + " arch=" + archeight); diff --git a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java index 51c972f26..68e77b53d 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Rotate.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Rotate.java @@ -30,7 +30,11 @@ import java.awt.Graphics2D; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Rotate extends TransformOperation implements DrawOperation { + private static final float HALF_CIRCLE = 180.0F; + + // CheckStyle:VisibilityModifier OFF - bc protected float angle = 0.0F; + // CheckStyle:VisibilityModifier ON /** * Sets the angle of rotation in degrees. @@ -41,8 +45,9 @@ public class Rotate extends TransformOperation implements DrawOperation { } + /** {@inheritDoc}. */ public PlanarImage performRotate(PlanarImage image) { - float tAngle = (float) (angle * (Math.PI / 180.0F)); + float tAngle = (float) (angle * (Math.PI / HALF_CIRCLE)); ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.add(0.0F); @@ -54,8 +59,9 @@ public class Rotate extends TransformOperation implements DrawOperation { /** - * Performs the image rotation when being handled as a TransformOperation. + * Performs the image rotation when being handled as a TransformOperation. * @param image The image to perform the transformation on. + * @return the transformed image. */ public PlanarImage executeTransformOperation(PlanarImage image) { BufferedImage bi = null; @@ -89,6 +95,7 @@ public class Rotate extends TransformOperation implements DrawOperation { * It absolutely requires that there be a DrawOperation nested beneath it, * but only the FIRST DrawOperation will be handled since it can only return * ONE image. + * @return the image. */ public PlanarImage executeDrawOperation() { for (int i = 0; i < instructions.size(); i++) { diff --git a/src/main/org/apache/tools/ant/types/optional/image/Scale.java b/src/main/org/apache/tools/ant/types/optional/image/Scale.java index 13aa22f1e..a8c1b9fe1 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Scale.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Scale.java @@ -29,6 +29,7 @@ import java.awt.image.renderable.ParameterBlock; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Scale extends TransformOperation implements DrawOperation { + private static final int HUNDRED = 100; private String widthStr = "100%"; private String heightStr = "100%"; @@ -36,7 +37,9 @@ public class Scale extends TransformOperation implements DrawOperation { private boolean yPercent = true; private String proportions = "ignore"; + /** Enumerated class for proportions attribute. */ public static class ProportionsAttribute extends EnumeratedAttribute { + /** {@inheritDoc}. */ public String[] getValues() { return new String[] {"ignore", "width", "height", "cover", "fit"}; } @@ -44,13 +47,16 @@ public class Scale extends TransformOperation implements DrawOperation { /** * Sets the behaviour regarding the image proportions. + * @param pa the enumerated value. */ public void setProportions(ProportionsAttribute pa) { proportions = pa.getValue(); } /** - * Sets the width of the image, either as an integer or a %. Defaults to 100%. + * Sets the width of the image, either as an integer or a %. + * Defaults to 100%. + * @param width the value to use. */ public void setWidth(String width) { widthStr = width; @@ -58,36 +64,46 @@ public class Scale extends TransformOperation implements DrawOperation { /** * Sets the height of the image, either as an integer or a %. Defaults to 100%. + * @param height the value to use. */ public void setHeight(String height) { heightStr = height; } + /** + * Get the width. + * @return the value converted from the width string. + */ public float getWidth() { float width = 0.0F; int percIndex = widthStr.indexOf('%'); if (percIndex > 0) { width = Float.parseFloat(widthStr.substring(0, percIndex)); xPercent = true; - return width / 100; + return width / HUNDRED; } else { xPercent = false; return Float.parseFloat(widthStr); } } + /** + * Get the height. + * @return the value converted from the height string. + */ public float getHeight() { int percIndex = heightStr.indexOf('%'); if (percIndex > 0) { float height = Float.parseFloat(heightStr.substring(0, percIndex)); yPercent = true; - return height / 100; + return height / HUNDRED; } else { yPercent = false; return Float.parseFloat(heightStr); } } + /** {@inheritDoc}. */ public PlanarImage performScale(PlanarImage image) { ParameterBlock pb = new ParameterBlock(); pb.addSource(image); @@ -116,12 +132,14 @@ public class Scale extends TransformOperation implements DrawOperation { pb.add(new Float(xFl)); pb.add(new Float(yFl)); - log("\tScaling to " + (xFl * 100) + "% x " + (yFl * 100) + "%"); + log("\tScaling to " + (xFl * HUNDRED) + "% x " + + (yFl * HUNDRED) + "%"); return JAI.create("scale", pb); } + /** {@inheritDoc}. */ public PlanarImage executeTransformOperation(PlanarImage image) { BufferedImage bi = null; for (int i = 0; i < instructions.size(); i++) { @@ -139,6 +157,7 @@ public class Scale extends TransformOperation implements DrawOperation { } + /** {@inheritDoc}. */ public PlanarImage executeDrawOperation() { for (int i = 0; i < instructions.size(); i++) { ImageOperation instr = ((ImageOperation) instructions.elementAt(i)); diff --git a/src/main/org/apache/tools/ant/types/optional/image/Text.java b/src/main/org/apache/tools/ant/types/optional/image/Text.java index 1053eecd9..27ec5f666 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/Text.java +++ b/src/main/org/apache/tools/ant/types/optional/image/Text.java @@ -30,31 +30,50 @@ import java.awt.image.BufferedImage; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Text extends ImageOperation implements DrawOperation { + private static final int DEFAULT_POINT = 10; + private String strText = ""; private String font = "Arial"; - private int point = 10; + private int point = DEFAULT_POINT; private boolean bold = false; private boolean italic = false; private String color = "black"; + /** + * Set the string to be used as text. + * @param str the string to be used. + */ public void setString(String str) { strText = str; } + /** + * Set the font to be used to draw the text. + * @param f the font to be used. + */ public void setFont(String f) { font = f; } + /** + * Set the number of points to be used. + * @param p an integer value as a string. + */ public void setPoint(String p) { point = Integer.parseInt(p); } + /** + * Set the color of the text. + * @param c the color name. + */ public void setColor(String c) { color = c; } /** * @todo is this used? + * @param state not used at the moment. */ public void setBold(boolean state) { bold = state; @@ -62,11 +81,16 @@ public class Text extends ImageOperation implements DrawOperation { /** * @todo is this used? + * @param state not used at the moment. */ public void setItalic(boolean state) { italic = state; } + /** + * Draw the text. + * @return the resultant image. + */ public PlanarImage executeDrawOperation() { log("\tCreating Text \"" + strText + "\""); diff --git a/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java b/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java index 1570d8ba3..fa50a233a 100644 --- a/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java +++ b/src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java @@ -23,10 +23,15 @@ import javax.media.jai.PlanarImage; * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public abstract class TransformOperation extends ImageOperation { + /** + * Performs the transformations. + * @param img The image to perform the transformation on. + * @return the transformed image. + */ public abstract PlanarImage executeTransformOperation(PlanarImage img); + /** {@inheritDoc}. */ public void addRectangle(Rectangle instr) { instructions.add(instr); } - -} \ No newline at end of file +}