View Javadoc

1   // Copyright 2002, FreeHEP.
2   package org.freehep.graphicsio.emf.gdi;
3   
4   import java.awt.Dimension;
5   import java.awt.Rectangle;
6   import java.awt.geom.RoundRectangle2D;
7   import java.io.IOException;
8   
9   import org.freehep.graphicsio.emf.EMFInputStream;
10  import org.freehep.graphicsio.emf.EMFOutputStream;
11  import org.freehep.graphicsio.emf.EMFTag;
12  import org.freehep.graphicsio.emf.EMFRenderer;
13  
14  /**
15   * RoundRect TAG.
16   *
17   * @author Mark Donszelmann
18   * @version $Id: RoundRect.java 10377 2007-01-23 15:44:34Z duns $
19   */
20  public class RoundRect extends EMFTag {
21  
22      private Rectangle bounds;
23  
24      private Dimension corner;
25  
26      public RoundRect() {
27          super(44, 1);
28      }
29  
30      public RoundRect(Rectangle bounds, Dimension corner) {
31          this();
32          this.bounds = bounds;
33          this.corner = corner;
34      }
35  
36      public EMFTag read(int tagID, EMFInputStream emf, int len)
37              throws IOException {
38  
39          return new RoundRect(emf.readRECTL(), emf.readSIZEL());
40      }
41  
42      public void write(int tagID, EMFOutputStream emf) throws IOException {
43          emf.writeRECTL(bounds);
44          emf.writeSIZEL(corner);
45      }
46  
47      public String toString() {
48          return super.toString() +
49              "\n  bounds: " + bounds +
50              "\n  corner: " + corner;
51      }
52  
53      /**
54       * displays the tag using the renderer
55       *
56       * @param renderer EMFRenderer storing the drawing session data
57       */
58      public void render(EMFRenderer renderer) {
59          renderer.fillAndDrawOrAppend(new RoundRectangle2D.Double(
60              bounds.getX(),
61              bounds.getX(),
62              bounds.getWidth(),
63              bounds.getHeight(),
64              corner.getWidth(),
65              corner.getHeight()));
66      }
67  }