FileDocCategorySizeDatePackage
HSSFClientAnchor.javaAPI DocApache Poi 3.0.17052Mon Jan 01 12:39:36 GMT 2007org.apache.poi.hssf.usermodel

HSSFClientAnchor

public class HSSFClientAnchor extends HSSFAnchor
A client anchor is attached to an excel worksheet. It anchors against a top-left and buttom-right cell.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
short
col1
int
row1
short
col2
int
row2
int
anchorType
Constructors Summary
public HSSFClientAnchor()
Creates a new client anchor and defaults all the anchor positions to 0.

    
public HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)
Creates a new client anchor and sets the top-left and bottom-right coordinates of the anchor.

param
dx1 the x coordinate within the first cell.
param
dy1 the y coordinate within the first cell.
param
dx2 the x coordinate within the second cell.
param
dy2 the y coordinate within the second cell.
param
col1 the column (0 based) of the first cell.
param
row1 the row (0 based) of the first cell.
param
col2 the column (0 based) of the second cell.
param
row2 the row (0 based) of the second cell.

        super( dx1, dy1, dx2, dy2 );

        checkRange(dx1, 0, 1023, "dx1");
        checkRange(dx2, 0, 1023, "dx2");
        checkRange(dy1, 0, 255, "dy1");
        checkRange(dy2, 0, 255, "dy2");
        checkRange(col1, 0, 255, "col1");
        checkRange(col2, 0, 255, "col2");
        checkRange(row1, 0, 255 * 256, "row1");
        checkRange(row2, 0, 255 * 256, "row2");

        this.col1 = col1;
        this.row1 = row1;
        this.col2 = col2;
        this.row2 = row2;
    
Methods Summary
private voidcheckRange(int value, int minRange, int maxRange, java.lang.String varName)

        if (value < minRange || value > maxRange)
            throw new IllegalArgumentException(varName + " must be between " + minRange + " and " + maxRange);
    
public floatgetAnchorHeightInPoints(org.apache.poi.hssf.usermodel.HSSFSheet sheet)
Calculates the height of a client anchor in points.

param
sheet the sheet the anchor will be attached to
return
the shape height.

        int y1 = Math.min( getDy1(), getDy2() );
        int y2 = Math.max( getDy1(), getDy2() );
        int row1 = Math.min( getRow1(), getRow2() );
        int row2 = Math.max( getRow1(), getRow2() );

        float points = 0;
        if (row1 == row2)
        {
            points = ((y2 - y1) / 256.0f) * getRowHeightInPoints(sheet, row2);
        }
        else
        {
            points += ((256.0f - y1) / 256.0f) * getRowHeightInPoints(sheet, row1);
            for (int i = row1 + 1; i < row2; i++)
            {
                points += getRowHeightInPoints(sheet, i);
            }
            points += (y2 / 256.0f) * getRowHeightInPoints(sheet, row2);
        }

        return points;
    
public intgetAnchorType()
Gets the anchor type

0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.

        return anchorType;
    
public shortgetCol1()

        return col1;
    
public shortgetCol2()

        return col2;
    
public intgetRow1()

        return row1;
    
public intgetRow2()

        return row2;
    
private floatgetRowHeightInPoints(org.apache.poi.hssf.usermodel.HSSFSheet sheet, int rowNum)

        HSSFRow row = sheet.getRow(rowNum);
        if (row == null)
            return sheet.getDefaultRowHeightInPoints();
        else
            return row.getHeightInPoints();
    
public booleanisHorizontallyFlipped()

return
true if the anchor goes from right to left.

        if (col1 == col2)
            return dx1 > dx2;
        else
            return col1 > col2;
    
public booleanisVerticallyFlipped()

return
true if the anchor goes from bottom to top.

        if (row1 == row2)
            return dy1 > dy2;
        else
            return row1 > row2;
    
public voidsetAnchor(short col1, int row1, int x1, int y1, short col2, int row2, int x2, int y2)
Dets the top-left and bottom-right coordinates of the anchor.

param
x1 the x coordinate within the first cell.
param
y1 the y coordinate within the first cell.
param
x2 the x coordinate within the second cell.
param
y2 the y coordinate within the second cell.
param
col1 the column (0 based) of the first cell.
param
row1 the row (0 based) of the first cell.
param
col2 the column (0 based) of the second cell.
param
row2 the row (0 based) of the second cell.

        checkRange(dx1, 0, 1023, "dx1");
        checkRange(dx2, 0, 1023, "dx2");
        checkRange(dy1, 0, 255, "dy1");
        checkRange(dy2, 0, 255, "dy2");
        checkRange(col1, 0, 255, "col1");
        checkRange(col2, 0, 255, "col2");
        checkRange(row1, 0, 255 * 256, "row1");
        checkRange(row2, 0, 255 * 256, "row2");

        this.col1 = col1;
        this.row1 = row1;
        this.dx1 = x1;
        this.dy1 = y1;
        this.col2 = col2;
        this.row2 = row2;
        this.dx2 = x2;
        this.dy2 = y2;
    
public voidsetAnchorType(int anchorType)
Sets the anchor type

0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.

        this.anchorType = anchorType;
    
public voidsetCol1(short col1)

        checkRange(col1, 0, 255, "col1");
        this.col1 = col1;
    
public voidsetCol2(short col2)

        checkRange(col2, 0, 255, "col2");
        this.col2 = col2;
    
public voidsetRow1(int row1)

        checkRange(row1, 0, 256 * 256, "row1");
        this.row1 = row1;
    
public voidsetRow2(int row2)

        checkRange(row2, 0, 256 * 256, "row2");
        this.row2 = row2;