source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/optional/image/Rectangle.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.4 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.image.BufferedImage;
23
24/**
25 *
26 * @see org.apache.tools.ant.taskdefs.optional.image.Image
27 */
28public class Rectangle extends BasicShape implements DrawOperation {
29 protected int width = 0;
30 protected int height = 0;
31 protected int arcwidth = 0;
32 protected int archeight = 0;
33
34 public void setWidth(int w) {
35 width = w;
36 }
37
38 public void setHeight(int h) {
39 height = h;
40 }
41
42 public void setArcwidth(int w) {
43 arcwidth = w;
44 }
45
46 public void setArcheight(int h) {
47 archeight = h;
48 }
49
50 public PlanarImage executeDrawOperation() {
51 log("\tCreating Rectangle w=" + width + " h=" + height + " arcw="
52 + arcwidth + " arch=" + archeight);
53 BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
54
55 Graphics2D graphics = (Graphics2D) bi.getGraphics();
56
57 if (!stroke.equals("transparent")) {
58 BasicStroke b_stroke = new BasicStroke(stroke_width);
59 graphics.setColor(ColorMapper.getColorByName(stroke));
60 graphics.setStroke(b_stroke);
61
62 if ((arcwidth != 0) || (archeight != 0)) {
63 graphics.drawRoundRect(0, 0, width, height, arcwidth, archeight);
64 } else {
65 graphics.drawRect(0, 0, width, height);
66 }
67 }
68
69 if (!fill.equals("transparent")) {
70 graphics.setColor(ColorMapper.getColorByName(fill));
71 if ((arcwidth != 0) || (archeight != 0)) {
72 graphics.fillRoundRect(stroke_width, stroke_width,
73 width - (stroke_width * 2), height - (stroke_width * 2),
74 arcwidth, archeight);
75 } else {
76 graphics.fillRect(stroke_width, stroke_width,
77 width - (stroke_width * 2), height - (stroke_width * 2));
78 }
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
90 = ((TransformOperation) instr).executeTransformOperation(PlanarImage.wrapRenderedImage(bi));
91 bi = image.getAsBufferedImage();
92 }
93 }
94 return PlanarImage.wrapRenderedImage(bi);
95 }
96}
Note: See TracBrowser for help on using the repository browser.