source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/optional/image/Arc.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: 3.3 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.BasicStroke;
21import java.awt.Graphics2D;
22import java.awt.geom.Arc2D;
23import java.awt.image.BufferedImage;
24
25public class Arc extends BasicShape implements DrawOperation {
26 protected int width = 0;
27 protected int height = 0;
28 protected int start = 0;
29 protected int stop = 0;
30 protected int type = Arc2D.OPEN;
31
32 public void setWidth(int width) {
33 this.width = width;
34 }
35
36 public void setHeight(int height) {
37 this.height = height;
38 }
39
40 public void setStart(int start) {
41 this.start = start;
42 }
43
44 public void setStop(int stop) {
45 this.stop = stop;
46 }
47
48 /**
49 * @todo refactor using an EnumeratedAttribute
50 */
51 public void setType(String str_type) {
52 if (str_type.toLowerCase().equals("open")) {
53 type = Arc2D.OPEN;
54 } else if (str_type.toLowerCase().equals("pie")) {
55 type = Arc2D.PIE;
56 } else if (str_type.toLowerCase().equals("chord")) {
57 type = Arc2D.CHORD;
58 }
59 }
60
61 public PlanarImage executeDrawOperation() {
62 BufferedImage bi = new BufferedImage(width + (stroke_width * 2),
63 height + (stroke_width * 2), BufferedImage.TYPE_4BYTE_ABGR_PRE);
64
65 Graphics2D graphics = (Graphics2D) bi.getGraphics();
66
67 if (!stroke.equals("transparent")) {
68 BasicStroke b_stroke = new BasicStroke(stroke_width);
69 graphics.setColor(ColorMapper.getColorByName(stroke));
70 graphics.setStroke(b_stroke);
71 graphics.draw(new Arc2D.Double(stroke_width, stroke_width, width,
72 height, start, stop, type));
73 }
74
75 if (!fill.equals("transparent")) {
76 graphics.setColor(ColorMapper.getColorByName(fill));
77 graphics.fill(new Arc2D.Double(stroke_width, stroke_width,
78 width, height, start, stop, type));
79 }
80
81
82 for (int i = 0; i < instructions.size(); i++) {
83 ImageOperation instr = ((ImageOperation) instructions.elementAt(i));
84 if (instr instanceof DrawOperation) {
85 PlanarImage img = ((DrawOperation) instr).executeDrawOperation();
86 graphics.drawImage(img.getAsBufferedImage(), null, 0, 0);
87 } else if (instr instanceof TransformOperation) {
88 graphics = (Graphics2D) bi.getGraphics();
89 PlanarImage image = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
90 bi = image.getAsBufferedImage();
91 }
92 }
93 return PlanarImage.wrapRenderedImage(bi);
94 }
95}
Note: See TracBrowser for help on using the repository browser.