KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicStroke JavaDoc;
22 import java.awt.Graphics2D JavaDoc;
23 import java.awt.geom.Ellipse2D JavaDoc;
24 import java.awt.image.BufferedImage JavaDoc;
25
26 /**
27  * Draw an ellipse.
28  * @see org.apache.tools.ant.taskdefs.optional.image.Image
29  */

30 public class Ellipse extends BasicShape implements DrawOperation {
31     // CheckStyle:VisibilityModifier OFF - bc
32
protected int width = 0;
33     protected int height = 0;
34     // CheckStyle:VisibilityModifier ON
35

36     /**
37      * Set the width.
38      * @param width the width of the elipse.
39      */

40     public void setWidth(int width) {
41         this.width = width;
42     }
43
44     /**
45      * Set the height.
46      * @param height the height of the elipse.
47      */

48     public void setHeight(int height) {
49         this.height = height;
50     }
51
52     /** {@inheritDoc}. */
53     public PlanarImage executeDrawOperation() {
54         BufferedImage JavaDoc bi = new BufferedImage JavaDoc(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
55
56         Graphics2D JavaDoc graphics = (Graphics2D JavaDoc) bi.getGraphics();
57
58         if (!stroke.equals("transparent")) {
59             BasicStroke JavaDoc bStroke = new BasicStroke JavaDoc(stroke_width);
60             graphics.setColor(ColorMapper.getColorByName(stroke));
61             graphics.setStroke(bStroke);
62             graphics.draw(new Ellipse2D.Double JavaDoc(0, 0, width, height));
63         }
64
65         if (!fill.equals("transparent")) {
66             graphics.setColor(ColorMapper.getColorByName(fill));
67             graphics.fill(new Ellipse2D.Double JavaDoc(0, 0, width, height));
68         }
69
70
71         for (int i = 0; i < instructions.size(); i++) {
72             ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
73             if (instr instanceof DrawOperation) {
74                 PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
75                 graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
76             } else if (instr instanceof TransformOperation) {
77                 graphics = (Graphics2D JavaDoc) bi.getGraphics();
78                 PlanarImage image = ((TransformOperation) instr)
79                     .executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
80                 bi = image.getAsBufferedImage();
81             }
82         }
83         return PlanarImage.wrapRenderedImage(bi);
84     }
85 }
86
Popular Tags