001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.tools.ant.types.optional.image;
019:
020: import javax.media.jai.PlanarImage;
021: import java.awt.Graphics2D;
022: import java.awt.image.BufferedImage;
023:
024: /**
025: *
026: * @see org.apache.tools.ant.taskdefs.optional.image.Image
027: */
028: public class Draw extends TransformOperation {
029: // CheckStyle:VisibilityModifier OFF - bc
030: protected int xloc = 0;
031: protected int yloc = 0;
032:
033: // CheckStyle:VisibilityModifier ON
034:
035: /**
036: * Set the X location.
037: * @param x the value to use.
038: */
039: public void setXloc(int x) {
040: xloc = x;
041: }
042:
043: /**
044: * Set the Y location.
045: * @param y the value to use.
046: */
047: public void setYloc(int y) {
048: yloc = y;
049: }
050:
051: /** {@inheritDoc}. */
052: public void addRectangle(Rectangle rect) {
053: instructions.add(rect);
054: }
055:
056: /** {@inheritDoc}. */
057: public void addText(Text text) {
058: instructions.add(text);
059: }
060:
061: /**
062: * Add an ellipse.
063: * @param elip the ellipse to add.
064: */
065: public void addEllipse(Ellipse elip) {
066: instructions.add(elip);
067: }
068:
069: /**
070: * Add an arc.
071: * @param arc the arc to add.
072: */
073: public void addArc(Arc arc) {
074: instructions.add(arc);
075: }
076:
077: /** {@inheritDoc}. */
078: public PlanarImage executeTransformOperation(PlanarImage image) {
079: BufferedImage bi = image.getAsBufferedImage();
080: Graphics2D graphics = (Graphics2D) bi.getGraphics();
081:
082: for (int i = 0; i < instructions.size(); i++) {
083: ImageOperation instr = ((ImageOperation) instructions
084: .elementAt(i));
085: if (instr instanceof DrawOperation) {
086: PlanarImage op = ((DrawOperation) instr)
087: .executeDrawOperation();
088: log("\tDrawing to x=" + xloc + " y=" + yloc);
089: graphics.drawImage(op.getAsBufferedImage(), null, xloc,
090: yloc);
091: } else if (instr instanceof TransformOperation) {
092: PlanarImage op = ((TransformOperation) instr)
093: .executeTransformOperation(null);
094: BufferedImage child = op.getAsBufferedImage();
095: log("\tDrawing to x=" + xloc + " y=" + yloc);
096: graphics.drawImage(child, null, xloc, yloc);
097: PlanarImage.wrapRenderedImage(bi);
098: }
099: }
100: image = PlanarImage.wrapRenderedImage(bi);
101:
102: return image;
103: }
104: }
|