KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > ATransform


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    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.batik.svggen;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Graphics2D JavaDoc;
22 import java.awt.Rectangle JavaDoc;
23 import java.awt.RenderingHints JavaDoc;
24 import java.awt.Shape JavaDoc;
25
26 /**
27  * This test validates the convertion of Java 2D AffineTransform into SVG
28  * Shapes.
29  *
30  * @author <a HREF="mailto:cjolif@ilog.fr">Christophe Jolif</a>
31  * @author <a HREF="mailto:vhardy@eng.sun.com">Vincent Hardy</a>
32  * @version $Id: ATransform.java,v 1.4 2004/08/18 07:16:43 vhardy Exp $
33  */

34 public class ATransform implements Painter {
35     public void paint(Graphics2D JavaDoc g) {
36         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
37                            RenderingHints.VALUE_ANTIALIAS_ON);
38
39         g.setPaint(Color.black); // new Color(102, 102, 144));
40

41         int legendX = 10, legendY = 12;
42         g.translate(0, 30);
43
44         java.awt.geom.AffineTransform JavaDoc defaultTransform = g.getTransform();
45
46         // Define rectangle
47
Rectangle JavaDoc rect = new Rectangle JavaDoc(10, 20, 50, 30);
48
49         // Paint with default transform
50
g.drawString("Default transform", legendX, legendY);
51         g.fill(rect);
52
53         // Paint after translate
54
g.translate(0, 90);
55         g.drawString("Translate applied", legendX, legendY);
56         g.fill(rect);
57
58         // Rotate rectangle about its center
59
g.translate(0, 90);
60         g.rotate(Math.PI/2, 35, 35);
61         g.drawString("Rotate about center", legendX, legendY);
62         g.fill(rect);
63
64         // Restore default transform
65
g.setTransform(defaultTransform);
66
67         // Paint after scale
68
g.translate(150, 0);
69         g.drawString("Scale (sx=2, sy=1)", legendX, legendY);
70         g.scale(2, 1);
71         g.fill(rect);
72
73         // Paint after shear
74
g.setTransform(defaultTransform);
75         g.translate(150, 90);
76         g.drawString("Shear", legendX, legendY);
77         g.shear(.2, 1);
78         g.fill(rect);
79
80         java.awt.geom.AffineTransform JavaDoc txf = g.getTransform();
81         g.setTransform(new java.awt.geom.AffineTransform JavaDoc());
82         Shape JavaDoc shearBounds = txf.createTransformedShape(rect).getBounds();
83         g.setPaint(new Color JavaDoc(0, 0, 0, 128));
84         g.fill(shearBounds);
85     }
86 }
87
Popular Tags