View Javadoc

1   package org.freehep.graphicsio.test;
2   
3   import java.awt.BasicStroke;
4   import java.awt.Color;
5   import java.awt.Dimension;
6   import java.awt.Graphics;
7   import java.awt.Insets;
8   import java.awt.Stroke;
9   
10  import org.freehep.graphics2d.VectorGraphics;
11  
12  /**
13   * @author Andre Bach
14   * @version $Id: TestGraphicsContexts.java 8584 2006-08-10 23:06:37Z duns $
15   */
16  public class TestGraphicsContexts extends TestingPanel {
17  
18      static float[] dash2 = new float[2];
19      static {
20          dash2[0] = 5.f;
21          dash2[1] = 4.f;
22      }
23  
24      Stroke stroke1 = new BasicStroke(5.f);
25  
26      Stroke stroke2 = new BasicStroke(10.f, BasicStroke.CAP_BUTT,
27              BasicStroke.JOIN_BEVEL, 10.f, dash2, 0.f);
28  
29      Stroke stroke3 = new BasicStroke(2.f);
30  
31      public TestGraphicsContexts(String[] args) throws Exception {
32          super(args);
33          setName("Line Styles");
34      }
35  
36      public void paintComponent(Graphics g) {
37  
38          VectorGraphics vg1 = VectorGraphics.create(g);
39  
40          Dimension dim = getSize();
41          Insets insets = getInsets();
42  
43          vg1.setColor(Color.white);
44          vg1.fillRect(insets.left, insets.top, dim.width - insets.left
45                  - insets.right, dim.height - insets.top - insets.bottom);
46  
47          vg1.setColor(Color.black);
48          vg1.setStroke(stroke1);
49          vg1.drawLine(200, 25, 350, 25);
50          vg1.drawSymbol(400, 25, 40, 5);
51  
52          Graphics g2 = vg1.create();
53          VectorGraphics vg2 = VectorGraphics.create(g2);
54          vg2.setStroke(stroke2);
55          vg2.setColor(Color.green);
56          vg2.translate(-137.5, 0);
57          vg2.scale(1.5, 1);
58          vg2.drawLine(200, 125, 350, 125);
59          vg2.drawSymbol(400, 125, 40, 6);
60  
61          Graphics g3 = vg2.create();
62          VectorGraphics vg3 = VectorGraphics.create(g3);
63          vg3.setStroke(stroke3);
64          vg3.setColor(Color.blue);
65          vg3.drawLine(200, 225, 350, 225);
66          vg3.fillSymbol(400, 225, 40, 7);
67          vg3.dispose();
68  
69          vg2.drawLine(200, 325, 350, 325);
70          vg2.drawSymbol(400, 325, 40, 6);
71          vg2.dispose();
72  
73          vg1.drawLine(200, 425, 350, 425);
74          vg1.drawSymbol(400, 425, 40, 5);
75      }
76  
77      public static void main(String[] args) throws Exception {
78          new TestGraphicsContexts(args).runTest();
79      }
80  }