Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@475076 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
20b9f66d2d
11 changed files with 188 additions and 12 deletions
  1. +24
    -0
      src/main/org/apache/tools/ant/types/optional/image/Arc.java
  2. +18
    -0
      src/main/org/apache/tools/ant/types/optional/image/BasicShape.java
  3. +7
    -0
      src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java
  4. +21
    -1
      src/main/org/apache/tools/ant/types/optional/image/Draw.java
  5. +12
    -1
      src/main/org/apache/tools/ant/types/optional/image/Ellipse.java
  6. +23
    -1
      src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java
  7. +19
    -0
      src/main/org/apache/tools/ant/types/optional/image/Rectangle.java
  8. +9
    -2
      src/main/org/apache/tools/ant/types/optional/image/Rotate.java
  9. +23
    -4
      src/main/org/apache/tools/ant/types/optional/image/Scale.java
  10. +25
    -1
      src/main/org/apache/tools/ant/types/optional/image/Text.java
  11. +7
    -2
      src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java

+ 24
- 0
src/main/org/apache/tools/ant/types/optional/image/Arc.java View File

@@ -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);


+ 18
- 0
src/main/org/apache/tools/ant/types/optional/image/BasicShape.java View File

@@ -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;
}


+ 7
- 0
src/main/org/apache/tools/ant/types/optional/image/ColorMapper.java View File

@@ -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) {


+ 21
- 1
src/main/org/apache/tools/ant/types/optional/image/Draw.java View File

@@ -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();


+ 12
- 1
src/main/org/apache/tools/ant/types/optional/image/Ellipse.java View File

@@ -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);



+ 23
- 1
src/main/org/apache/tools/ant/types/optional/image/ImageOperation.java View File

@@ -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);
}
}
}

+ 19
- 0
src/main/org/apache/tools/ant/types/optional/image/Rectangle.java View File

@@ -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);


+ 9
- 2
src/main/org/apache/tools/ant/types/optional/image/Rotate.java View File

@@ -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++) {


+ 23
- 4
src/main/org/apache/tools/ant/types/optional/image/Scale.java View File

@@ -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));


+ 25
- 1
src/main/org/apache/tools/ant/types/optional/image/Text.java View File

@@ -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 + "\"");



+ 7
- 2
src/main/org/apache/tools/ant/types/optional/image/TransformOperation.java View File

@@ -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);
}

}
}

Loading…
Cancel
Save