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.Color;
6   import java.awt.Dimension;
7   import java.awt.Graphics;
8   import java.awt.Insets;
9   
10  import org.freehep.graphics2d.VectorGraphics;
11  import org.freehep.graphics2d.VectorGraphicsConstants;
12  
13  /**
14   * @author Charles Loomis
15   * @author Mark Donszelmann
16   * @version $Id: TestSymbols2D.java 8584 2006-08-10 23:06:37Z duns $
17   */
18  public class TestSymbols2D extends TestingPanel implements
19          VectorGraphicsConstants {
20  
21      public TestSymbols2D(String[] args) throws Exception {
22          super(args);
23          setName("Symbols");
24      }
25  
26      public void paintComponent(Graphics g) {
27  
28          if (g != null) {
29              VectorGraphics vg = VectorGraphics.create(g);
30  
31              Dimension dim = getSize();
32              Insets insets = getInsets();
33  
34              vg.setColor(Color.RED);
35              vg.fillRect(insets.left, insets.top, dim.width - insets.left
36                      - insets.right, dim.height - insets.top - insets.bottom);
37  
38              int cols = 5;
39              int rows = 8;
40  
41              int dw = dim.width / cols;
42              int dh = dim.height / rows;
43  
44              int size = Math.min(dw, dh) * 2 / 3;
45  
46              vg.setColor(Color.BLACK);
47              int symbol = 0;
48              for (int y = 0; y < rows; y++) {
49                  symbol = (y / 2) * cols;
50                  if ((y % 2) == 0) {
51                      vg.setLineWidth(1);
52                  } else {
53                      vg.setLineWidth(5.0);
54                  }
55                  int iy = dh / 2 + dh * y;
56                  if (y >= 2)
57                      symbol = SYMBOL_CIRCLE;
58                  for (int x = 0; x < cols; x++) {
59                      int ix = dw / 2 + dw * x;
60                      if (y < 4) {
61                          vg.drawSymbol(ix, iy, size, symbol++);
62                      } else if (y < 6) {
63                          vg.fillSymbol(ix, iy, size, symbol++);
64                      } else {
65                          vg
66                                  .fillAndDrawSymbol(ix, iy, size, symbol++,
67                                          Color.CYAN);
68                      }
69                  }
70              }
71          }
72      }
73  
74      public static void main(String[] args) throws Exception {
75          new TestSymbols2D(args).runTest();
76      }
77  }