KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > optional > image > Draw


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.optional.image;
19
20 import javax.media.jai.PlanarImage;
21 import java.awt.Graphics2D JavaDoc;
22 import java.awt.image.BufferedImage JavaDoc;
23
24 /**
25  *
26  * @see org.apache.tools.ant.taskdefs.optional.image.Image
27  */

28 public class Draw extends TransformOperation {
29     // CheckStyle:VisibilityModifier OFF - bc
30
protected int xloc = 0;
31     protected int yloc = 0;
32     // CheckStyle:VisibilityModifier ON
33

34     /**
35      * Set the X location.
36      * @param x the value to use.
37      */

38     public void setXloc(int x) {
39         xloc = x;
40     }
41
42     /**
43      * Set the Y location.
44      * @param y the value to use.
45      */

46     public void setYloc(int y) {
47         yloc = y;
48     }
49
50     /** {@inheritDoc}. */
51     public void addRectangle(Rectangle rect) {
52         instructions.add(rect);
53     }
54
55     /** {@inheritDoc}. */
56     public void addText(Text text) {
57         instructions.add(text);
58     }
59
60     /**
61      * Add an ellipse.
62      * @param elip the ellipse to add.
63      */

64     public void addEllipse(Ellipse elip) {
65         instructions.add(elip);
66     }
67
68     /**
69      * Add an arc.
70      * @param arc the arc to add.
71      */

72     public void addArc(Arc arc) {
73         instructions.add(arc);
74     }
75
76     /** {@inheritDoc}. */
77     public PlanarImage executeTransformOperation(PlanarImage image) {
78         BufferedImage JavaDoc bi = image.getAsBufferedImage();
79         Graphics2D JavaDoc graphics = (Graphics2D JavaDoc) bi.getGraphics();
80
81         for (int i = 0; i < instructions.size(); i++) {
82             ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
83             if (instr instanceof DrawOperation) {
84                 PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
85                 log("\tDrawing to x=" + xloc + " y=" + yloc);
86                 graphics.drawImage(op.getAsBufferedImage(), null, xloc, yloc);
87             } else if (instr instanceof TransformOperation) {
88                 PlanarImage op
89                     = ((TransformOperation) instr).executeTransformOperation(null);
90                 BufferedImage JavaDoc child = op.getAsBufferedImage();
91                 log("\tDrawing to x=" + xloc + " y=" + yloc);
92                 graphics.drawImage(child, null, xloc, yloc);
93                 PlanarImage.wrapRenderedImage(bi);
94             }
95         }
96         image = PlanarImage.wrapRenderedImage(bi);
97
98         return image;
99     }
100 }
101
Popular Tags