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 | */
|
---|
17 | package org.apache.tools.ant.types.optional.image;
|
---|
18 |
|
---|
19 | import javax.media.jai.PlanarImage;
|
---|
20 | import java.awt.BasicStroke;
|
---|
21 | import java.awt.Graphics2D;
|
---|
22 | import java.awt.geom.Ellipse2D;
|
---|
23 | import java.awt.image.BufferedImage;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | *
|
---|
27 | * @see org.apache.tools.ant.taskdefs.optional.image.Image
|
---|
28 | */
|
---|
29 | public class Ellipse extends BasicShape implements DrawOperation {
|
---|
30 | protected int width = 0;
|
---|
31 | protected int height = 0;
|
---|
32 |
|
---|
33 | public void setWidth(int width) {
|
---|
34 | this.width = width;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void setHeight(int height) {
|
---|
38 | this.height = height;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public PlanarImage executeDrawOperation() {
|
---|
42 | BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
|
---|
43 |
|
---|
44 | Graphics2D graphics = (Graphics2D) bi.getGraphics();
|
---|
45 |
|
---|
46 | if (!stroke.equals("transparent")) {
|
---|
47 | BasicStroke b_stroke = new BasicStroke(stroke_width);
|
---|
48 | graphics.setColor(ColorMapper.getColorByName(stroke));
|
---|
49 | graphics.setStroke(b_stroke);
|
---|
50 | graphics.draw(new Ellipse2D.Double(0, 0, width, height));
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (!fill.equals("transparent")) {
|
---|
54 | graphics.setColor(ColorMapper.getColorByName(fill));
|
---|
55 | graphics.fill(new Ellipse2D.Double(0, 0, width, height));
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | for (int i = 0; i < instructions.size(); i++) {
|
---|
60 | ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
|
---|
61 | if (instr instanceof DrawOperation) {
|
---|
62 | PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
|
---|
63 | graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
|
---|
64 | } else if (instr instanceof TransformOperation) {
|
---|
65 | graphics = (Graphics2D) bi.getGraphics();
|
---|
66 | PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
|
---|
67 | bi = image.getAsBufferedImage();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | return PlanarImage.wrapRenderedImage(bi);
|
---|
71 | }
|
---|
72 | }
|
---|