View Javadoc

1   // Copyright 2002, SLAC, Stanford University, U.S.A.
2   package org.freehep.graphicsio.test;
3   
4   import java.awt.Color;
5   import java.awt.Graphics;
6   import java.awt.Image;
7   import java.awt.MediaTracker;
8   
9   import org.freehep.graphics2d.VectorGraphics;
10  import org.freehep.util.images.ImageHandler;
11  
12  /**
13   * 
14   * @author Mark Donszelmann
15   * @author Charles Loomis
16   * @version $Id: TestImages.java 12753 2007-06-12 22:32:31Z duns $
17   */
18  public class TestImages extends TestingPanel {
19  
20      final static Color bg = Color.ORANGE;
21  
22      private Image image;
23  
24      public TestImages(String[] args) throws Exception {
25          super(args);
26          setName("Images");
27  
28          setBackground(bg);
29  
30          MediaTracker t = new MediaTracker(this);
31          image = ImageHandler.getImage("images/transparent-image.gif",
32                  TestImages.class);
33          t.addImage(image, 0);
34          try {
35              t.waitForAll();
36          } catch (InterruptedException e) {
37              e.printStackTrace();
38          }
39      }
40  
41      public void paintComponent(Graphics g) {
42          drawComponent(VectorGraphics.create(g));
43      }
44  
45      protected void drawComponent(VectorGraphics g) {
46  
47          // Fill in the background.
48          g.setBackground(bg);
49          g.clearRect(0, 0, getWidth(), getHeight());
50  
51          int cellWidth = getWidth() / 4;
52          int cellHeight = getHeight() / 2;
53  
54          int x = 0;
55          int y = 0;
56  
57          // Natural size at origin.
58          g.drawImage(image, x, y, Color.black, this);
59  
60          // Scaled to half-width, half-height.
61          x += cellWidth;
62          g.drawImage(image, x + cellWidth / 2, y + cellHeight / 2,
63                  cellWidth / 2, cellHeight / 2, Color.black, this);
64  
65          // Middle part scaled to 3/4 of cell.
66          x += cellWidth;
67          g.drawImage(image, x, y, x + 3 * cellWidth / 4, y + 3 * cellHeight / 4,
68                  64, 64, 192, 192, Color.black, this);
69  
70          // Flip in y-direction.
71          x += cellWidth;
72          g.drawImage(image, x, y, x + cellWidth / 2, y + cellHeight, 256, 256,
73                  0, 0, Color.black, this);
74  
75          // Natural size at origin.
76          x = 0;
77          y += cellHeight;
78          g.drawImage(image, x, y, this);
79  
80          // Scaled to half-width, half-height.
81          x += cellWidth;
82          g.drawImage(image, x + cellWidth / 2, y + cellHeight / 2,
83                  cellWidth / 2, cellHeight / 2, this);
84  
85          // Middle part scaled to 3/4 of cell.
86          x += cellWidth;
87          g.drawImage(image, x, y, x + 3 * cellWidth / 4, y + 3 * cellHeight / 4,
88                  64, 64, 192, 192, this);
89  
90          // Flip in y-direction.
91          x += cellWidth;
92          g.drawImage(image, x, y, x + cellWidth / 2, y + cellHeight, 256, 256,
93                  0, 0, this);
94      }
95  
96      public static void main(String[] args) throws Exception {
97          new TestImages(args).runTest();
98      }
99  }