use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFTable method setRowHeight.
@Override
public void setRowHeight(int row, final double height) {
if (row < 0 || row >= cells.length) {
throw new IllegalArgumentException("Row index '" + row + "' is not within range [0-" + (cells.length - 1) + "]");
}
// update row height in the table properties
AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherUserDefined.typeID);
EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES);
byte[] masterBytes = p.getElement(row);
double currentHeight = Units.masterToPoints(LittleEndian.getInt(masterBytes, 0));
LittleEndian.putInt(masterBytes, 0, Units.pointsToMaster(height));
p.setElement(row, masterBytes);
// move the cells
double dy = height - currentHeight;
for (int i = row; i < cells.length; i++) {
for (HSLFTableCell c : cells[i]) {
if (c == null) {
continue;
}
Rectangle2D anchor = c.getAnchor();
if (i == row) {
anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
} else {
anchor.setRect(anchor.getX(), anchor.getY() + dy, anchor.getWidth(), anchor.getHeight());
}
c.setAnchor(anchor);
}
}
Rectangle2D tblanchor = getAnchor();
tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth(), tblanchor.getHeight() + dy);
setExteriorAnchor(tblanchor);
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFTableCell method anchorBorder.
private void anchorBorder(BorderEdge edge, final HSLFLine line) {
if (line == null) {
return;
}
Rectangle2D cellAnchor = getAnchor();
double x, y, w, h;
switch(edge) {
case top:
x = cellAnchor.getX();
y = cellAnchor.getY();
w = cellAnchor.getWidth();
h = 0;
break;
case right:
x = cellAnchor.getX() + cellAnchor.getWidth();
y = cellAnchor.getY();
w = 0;
h = cellAnchor.getHeight();
break;
case bottom:
x = cellAnchor.getX();
y = cellAnchor.getY() + cellAnchor.getHeight();
w = cellAnchor.getWidth();
h = 0;
break;
case left:
x = cellAnchor.getX();
y = cellAnchor.getY();
w = 0;
h = cellAnchor.getHeight();
break;
default:
throw new IllegalArgumentException();
}
line.setAnchor(new Rectangle2D.Double(x, y, w, h));
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFTable method cellListToArray.
private void cellListToArray() {
List<HSLFTableCell> htc = new ArrayList<HSLFTableCell>();
for (HSLFShape h : getShapes()) {
if (h instanceof HSLFTableCell) {
htc.add((HSLFTableCell) h);
}
}
if (htc.isEmpty()) {
throw new IllegalStateException("HSLFTable without HSLFTableCells");
}
SortedSet<Double> colSet = new TreeSet<Double>();
SortedSet<Double> rowSet = new TreeSet<Double>();
// #1 pass - determine cols and rows
for (HSLFTableCell sh : htc) {
Rectangle2D anchor = sh.getAnchor();
colSet.add(anchor.getX());
rowSet.add(anchor.getY());
}
cells = new HSLFTableCell[rowSet.size()][colSet.size()];
List<Double> colLst = new ArrayList<Double>(colSet);
List<Double> rowLst = new ArrayList<Double>(rowSet);
// #2 pass - assign shape to table cells
for (HSLFTableCell sh : htc) {
Rectangle2D anchor = sh.getAnchor();
int row = rowLst.indexOf(anchor.getY());
int col = colLst.indexOf(anchor.getX());
assert (row != -1 && col != -1);
cells[row][col] = sh;
// determine gridSpan / rowSpan
int gridSpan = calcSpan(colLst, anchor.getWidth(), col);
int rowSpan = calcSpan(rowLst, anchor.getHeight(), row);
sh.setGridSpan(gridSpan);
sh.setRowSpan(rowSpan);
}
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class HSLFTextShape method resizeToFitText.
/**
* Adjust the size of the shape so it encompasses the text inside it.
*
* @return a <code>Rectangle2D</code> that is the bounds of this shape.
*/
public Rectangle2D resizeToFitText() {
Rectangle2D anchor = getAnchor();
if (anchor.getWidth() == 0.) {
LOG.log(POILogger.WARN, "Width of shape wasn't set. Defaulting to 200px");
anchor.setRect(anchor.getX(), anchor.getY(), 200., anchor.getHeight());
setAnchor(anchor);
}
double height = getTextHeight();
// add a pixel to compensate rounding errors
height += 1;
anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
setAnchor(anchor);
return anchor;
}
use of java.awt.geom.Rectangle2D in project poi by apache.
the class TestTable method moveTable.
@Test
public void moveTable() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
int rows = 3, cols = 5;
HSLFTable table = slide.createTable(rows, cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
HSLFTableCell c = table.getCell(row, col);
c.setText("r" + row + "c" + col);
}
}
new DrawTableShape(table).setAllBorders(1.0, Color.black, StrokeStyle.LineDash.DASH_DOT);
table.setAnchor(new Rectangle2D.Double(100, 100, 400, 400));
Rectangle2D rectExp = new Rectangle2D.Double(420, 366.625, 80, 133.375);
Rectangle2D rectAct = table.getCell(rows - 1, cols - 1).getAnchor();
assertEquals(rectExp, rectAct);
ppt.close();
}
Aggregations