source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/optional/image/Draw.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 2.5 KB
Line 
1/*
2 * Copyright 2002-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.types.optional.image;
18
19import javax.media.jai.PlanarImage;
20import java.awt.Graphics2D;
21import java.awt.image.BufferedImage;
22
23/**
24 *
25 * @see org.apache.tools.ant.taskdefs.optional.image.Image
26 */
27public class Draw extends TransformOperation {
28 protected int xloc = 0;
29 protected int yloc = 0;
30
31 public void setXloc(int x) {
32 xloc = x;
33 }
34
35 public void setYloc(int y) {
36 yloc = y;
37 }
38
39 public void addRectangle(Rectangle rect) {
40 instructions.add(rect);
41 }
42
43 public void addText(Text text) {
44 instructions.add(text);
45 }
46
47 public void addEllipse(Ellipse elip) {
48 instructions.add(elip);
49 }
50
51 public void addArc(Arc arc) {
52 instructions.add(arc);
53 }
54
55
56 public PlanarImage executeTransformOperation(PlanarImage image) {
57 BufferedImage bi = image.getAsBufferedImage();
58 Graphics2D graphics = (Graphics2D) bi.getGraphics();
59
60 for (int i = 0; i < instructions.size(); i++) {
61 ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
62 if (instr instanceof DrawOperation) {
63 PlanarImage op = ((DrawOperation) instr).executeDrawOperation();
64 log("\tDrawing to x=" + xloc + " y=" + yloc);
65 graphics.drawImage(op.getAsBufferedImage(), null, xloc, yloc);
66 } else if (instr instanceof TransformOperation) {
67 PlanarImage op
68 = ((TransformOperation) instr).executeTransformOperation(null);
69 BufferedImage child = op.getAsBufferedImage();
70 log("\tDrawing to x=" + xloc + " y=" + yloc);
71 graphics.drawImage(child, null, xloc, yloc);
72 PlanarImage.wrapRenderedImage(bi);
73 }
74 }
75 image = PlanarImage.wrapRenderedImage(bi);
76
77 return image;
78 }
79}
Note: See TracBrowser for help on using the repository browser.