KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > TestEscherGraphics


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.usermodel;
18
19 import junit.framework.TestCase;
20
21 import java.awt.*;
22
23 /**
24  * Tests the capabilities of the EscherGraphics class.
25  *
26  * @author Glen Stampoultzis (glens at apache.org)
27  */

28 public class TestEscherGraphics extends TestCase
29 {
30     private HSSFShapeGroup escherGroup;
31     private EscherGraphics graphics;
32
33     protected void setUp() throws Exception JavaDoc
34     {
35         HSSFWorkbook workbook = new HSSFWorkbook();
36         HSSFSheet sheet = workbook.createSheet("test");
37         escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0));
38         escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
39         graphics = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f);
40         super.setUp();
41     }
42
43     public void testGetFont() throws Exception JavaDoc
44     {
45         Font f = graphics.getFont();
46         if (f.toString().indexOf("dialog") == -1)
47             assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
48     }
49
50     public void testGetFontMetrics() throws Exception JavaDoc
51     {
52         Font f = graphics.getFont();
53         if (f.toString().indexOf("dialog") != -1)
54             return;
55         FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
56         assertEquals(7, fontMetrics.charWidth('X'));
57         assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
58     }
59
60     public void testSetFont() throws Exception JavaDoc
61     {
62         Font f = new Font("Helvetica", 0, 12);
63         graphics.setFont(f);
64         assertEquals(f, graphics.getFont());
65     }
66
67     public void testSetColor() throws Exception JavaDoc
68     {
69         graphics.setColor(Color.red);
70         assertEquals(Color.red, graphics.getColor());
71     }
72
73     public void testFillRect() throws Exception JavaDoc
74     {
75         graphics.fillRect( 10, 10, 20, 20 );
76         HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
77         assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType());
78         assertEquals(10, s.getAnchor().getDx1());
79         assertEquals(10, s.getAnchor().getDy1());
80         assertEquals(30, s.getAnchor().getDy2());
81         assertEquals(30, s.getAnchor().getDx2());
82     }
83
84     public void testDrawString() throws Exception JavaDoc
85     {
86         graphics.drawString("This is a test", 10, 10);
87         HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
88         assertEquals("This is a test", t.getString().toString());
89     }
90
91 }
92
Popular Tags