1 16 17 package org.apache.poi.hssf.usermodel; 18 19 import junit.framework.TestCase; 20 21 import java.awt.*; 22 23 28 public class TestEscherGraphics extends TestCase 29 { 30 private HSSFShapeGroup escherGroup; 31 private EscherGraphics graphics; 32 33 protected void setUp() throws Exception 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 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 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 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 68 { 69 graphics.setColor(Color.red); 70 assertEquals(Color.red, graphics.getColor()); 71 } 72 73 public void testFillRect() throws Exception 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 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 |