FileDocCategorySizeDatePackage
TestEscherGraphics2d.javaAPI DocApache Poi 3.0.14307Mon Jan 01 12:39:46 GMT 2007org.apache.poi.hssf.usermodel

TestEscherGraphics2d

public class TestEscherGraphics2d extends TestCase
Tests the Graphics2d drawing capability.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
private HSSFShapeGroup
escherGroup
private EscherGraphics2d
graphics
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("test");
        escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0));
        escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
        EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f);
        graphics = new EscherGraphics2d(g);

    
public voidtestDraw()

        graphics.draw(new Line2D.Double(10,10,20,20));
        HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
        assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE);
        assertEquals(10, s.getAnchor().getDx1());
        assertEquals(10, s.getAnchor().getDy1());
        assertEquals(20, s.getAnchor().getDx2());
        assertEquals(20, s.getAnchor().getDy2());
        System.out.println("s = " + s);
    
public voidtestDrawString()

        graphics.drawString("This is a test", 10, 10);
        HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
        assertEquals("This is a test", t.getString().getString().toString());
    
public voidtestFillRect()

        graphics.fillRect( 10, 10, 20, 20 );
        HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
        assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType());
        assertEquals(10, s.getAnchor().getDx1());
        assertEquals(10, s.getAnchor().getDy1());
        assertEquals(30, s.getAnchor().getDy2());
        assertEquals(30, s.getAnchor().getDx2());
    
public voidtestGetFont()

        Font f = graphics.getFont();
        if (graphics.getFont().toString().indexOf("dialog") != -1 || graphics.getFont().toString().indexOf("Dialog") != -1) // if dialog is returned we can't run the test properly.
            return;

        assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
    
public voidtestGetFontMetrics()

        FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
    if (graphics.getFont().toString().indexOf("dialog") != -1 || graphics.getFont().toString().indexOf("Dialog") != -1) // if dialog is returned we can't run the test properly.
            return;
        assertEquals(7, fontMetrics.charWidth('X"));
        assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
    
public voidtestSetColor()

        graphics.setColor(Color.red);
        assertEquals(Color.red, graphics.getColor());
    
public voidtestSetFont()

        Font f = new Font("Helvetica", 0, 12);
        graphics.setFont(f);
        assertEquals(f, graphics.getFont());