View Javadoc

1   // University of California, Santa Cruz, USA and
2   // CERN, Geneva, Switzerland, Copyright (c) 2000
3   package org.freehep.graphicsio.test;
4   
5   import java.awt.BasicStroke;
6   import java.awt.Color;
7   import java.awt.Graphics;
8   import java.awt.Stroke;
9   import java.awt.geom.AffineTransform;
10  import java.awt.geom.GeneralPath;
11  
12  import org.freehep.graphics2d.VectorGraphics;
13  
14  /**
15   * @author Charles Loomis
16   * @version $Id: TestTransforms.java 8584 2006-08-10 23:06:37Z duns $
17   */
18  public class TestTransforms extends TestingPanel {
19  
20      static Stroke stroke = new BasicStroke(5.f, BasicStroke.CAP_ROUND,
21              BasicStroke.JOIN_ROUND);
22  
23      public TestTransforms(String[] args) throws Exception {
24          super(args);
25          setName("Transformations");
26      }
27  
28      public void paintComponent(Graphics g) {
29  
30          VectorGraphics vg = VectorGraphics.create(g);
31          AffineTransform transform = vg.getTransform();
32  
33          vg.setColor(Color.white);
34          vg.fillRect(0, 0, getWidth(), getHeight());
35  
36          int size = 50;
37          GeneralPath sshape = new GeneralPath();
38          sshape.moveTo((float)0*size,   (float)0*size);
39          sshape.lineTo((float).5*size,  (float)size);
40          sshape.lineTo((float)-.5*size, (float)size);
41          sshape.lineTo((float).5*size,  (float)-size);
42          sshape.lineTo((float)-.5*size, (float)-size);
43          sshape.closePath();
44  
45          vg.setColor(Color.black);
46  
47          Graphics subgraphics = vg.create();
48          VectorGraphics svg = VectorGraphics.create(subgraphics);
49          svg.setStroke(stroke);
50          svg.translate(100, 100);
51          svg.draw(sshape);
52          svg.dispose();
53  
54          subgraphics = vg.create();
55          svg = VectorGraphics.create(subgraphics);
56          svg.setStroke(stroke);
57          svg.translate(300, 100);
58          svg.rotate(Math.PI / 4.);
59          svg.fill(sshape);
60          svg.dispose();
61  
62          subgraphics = vg.create();
63          svg = VectorGraphics.create(subgraphics);
64          svg.setStroke(stroke);
65          svg.translate(500, 100);
66          svg.scale(2., 0.5);
67          svg.fillAndDraw(sshape, Color.red);
68          svg.dispose();
69  
70          subgraphics = vg.create();
71          svg = VectorGraphics.create(subgraphics);
72          svg.setStroke(stroke);
73          svg.translate(100, 300);
74          svg.shear(1., 0.);
75          svg.draw(sshape);
76          svg.dispose();
77  
78          subgraphics = vg.create();
79          svg = VectorGraphics.create(subgraphics);
80          svg.setStroke(stroke);
81          svg.translate(300, 300);
82          svg.shear(0., 1.);
83          svg.draw(sshape);
84          svg.dispose();
85  
86          subgraphics = vg.create();
87          svg = VectorGraphics.create(subgraphics);
88          svg.setStroke(stroke);
89          svg.translate(500, 300);
90          svg.rotate(-Math.PI / 4., 50., 50.);
91          svg.draw(sshape);
92          svg.dispose();
93  
94          subgraphics = vg.create();
95          svg = VectorGraphics.create(subgraphics);
96          svg.setStroke(stroke);
97          svg.translate(100, 500);
98          svg.transform(new AffineTransform(2., 0., 1., 0.5, 50., 0.));
99          svg.draw(sshape);
100         svg.dispose();
101 
102         subgraphics = vg.create();
103         svg = VectorGraphics.create(subgraphics);
104         svg.setStroke(stroke);
105         svg.translate(300, 500);
106         svg.transform(new AffineTransform(0.5, 1., 0., 2., 50., -50.));
107         svg.draw(sshape);
108         svg.dispose();
109 
110         vg.setTransform(new AffineTransform(1., 0., 0., 1., 400., 400.));
111 
112         subgraphics = vg.create();
113         svg = VectorGraphics.create(subgraphics);
114         svg.setStroke(stroke);
115         svg.transform(new AffineTransform(0.5, 1., 0., 1., 0., 0.));
116         svg.draw(sshape);
117         svg.dispose();
118 
119         vg.setTransform(transform);
120     }
121 
122     public static void main(String[] args) throws Exception {
123         new TestTransforms(args).runTest();
124     }
125 }