Example usage for org.apache.poi.hssf.usermodel HSSFShapeGroup setCoordinates

List of usage examples for org.apache.poi.hssf.usermodel HSSFShapeGroup setCoordinates

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFShapeGroup setCoordinates.

Prototype

public void setCoordinates(int x1, int y1, int x2, int y2) 

Source Link

Document

Sets the coordinate space of this group.

Usage

From source file:poi.hssf.usermodel.examples.OfficeDrawing.java

License:Apache License

private static void drawPolygon(HSSFPatriarch patriarch) {
    //        HSSFClientAnchor a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 2, 2, (short) 3, 3 );
    //        HSSFPolygon p = patriarch.createPolygon(a);
    //        p.setPolygonDrawArea(100,100);
    //        p.setPoints( new int[]{30, 90, 50}, new int[]{88, 5, 44} );

    HSSFClientAnchor a = new HSSFClientAnchor();
    a.setAnchor((short) 2, 2, 0, 0, (short) 3, 3, 1023, 255);
    HSSFShapeGroup g = patriarch.createGroup(a);
    g.setCoordinates(0, 0, 200, 200);
    HSSFPolygon p1 = g.createPolygon(new HSSFChildAnchor(0, 0, 200, 200));
    p1.setPolygonDrawArea(100, 100);/*from   www  . j a v  a 2s .com*/
    p1.setPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 });
    p1.setFillColor(0, 255, 0);
    HSSFPolygon p2 = g.createPolygon(new HSSFChildAnchor(20, 20, 200, 200));
    p2.setPolygonDrawArea(200, 200);
    p2.setPoints(new int[] { 120, 20, 150 }, new int[] { 105, 30, 195 });
    p2.setFillColor(255, 0, 0);
}

From source file:poi.hssf.usermodel.examples.OfficeDrawingWithGraphics.java

License:Apache License

public static void main(String[] args) throws IOException {
    // Create a workbook with one sheet and size the first three somewhat
    // larger so we can fit the chemical structure diagram in.
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("my drawing");
    sheet.setColumnWidth(1, 256 * 27);/*from w w  w  .ja  v  a 2 s. co  m*/
    HSSFRow row1 = sheet.createRow(0);
    row1.setHeightInPoints(10 * 15);
    HSSFRow row2 = sheet.createRow(1);
    row2.setHeightInPoints(5 * 15);
    HSSFRow row3 = sheet.createRow(2);
    row3.setHeightInPoints(10 * 15);

    // Add some cells so we can test that the anchoring works when we
    // sort them.
    row1.createCell(0).setCellValue("C");
    row2.createCell(0).setCellValue("A");
    row3.createCell(0).setCellValue("B");

    // Create the top level drawing patriarch.
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();

    HSSFClientAnchor a;
    HSSFShapeGroup group;
    EscherGraphics g;
    EscherGraphics2d g2d;
    // Anchor entirely within one cell.
    a = new HSSFClientAnchor(0, 0, 1023, 255, (short) 1, 0, (short) 1, 0);
    group = patriarch.createGroup(a);
    group.setCoordinates(0, 0, 320, 276);
    float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
    g = new EscherGraphics(group, wb, Color.black, verticalPointsPerPixel);
    g2d = new EscherGraphics2d(g);
    drawStar(g2d);

    a = new HSSFClientAnchor(0, 0, 1023, 255, (short) 1, 1, (short) 1, 1);
    group = patriarch.createGroup(a);
    group.setCoordinates(0, 0, 640, 276);
    verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / Math.abs(group.getY2() - group.getY1());
    //        verticalPixelsPerPoint = (float)Math.abs(group.getY2() - group.getY1()) / a.getAnchorHeightInPoints(sheet);
    g = new EscherGraphics(group, wb, Color.black, verticalPointsPerPixel);
    g2d = new EscherGraphics2d(g);
    drawStar(g2d);

    FileOutputStream out = new FileOutputStream("workbook.xls");
    wb.write(out);
    out.close();

}