int lastCol = range.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstCol; col <= lastCol; col++) {
- removeProperties(row, col, BORDER_DIRECTION_PROPERTY_NAMES);
+ CellAddress cell = new CellAddress(row, col);
+ removeProperties(cell, BORDER_DIRECTION_PROPERTY_NAMES);
}
}
removeBorderColors(range);
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
+ CellAddress cell = new CellAddress(row, i);
// if BORDER_TOP is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(row, i, CellUtil.BORDER_TOP) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_TOP) == null) {
drawTopBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.TOP_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.TOP_BORDER_COLOR, color);
}
}
int firstCol = range.getFirstColumn();
int lastCol = range.getLastColumn();
for (int i = firstCol; i <= lastCol; i++) {
+ CellAddress cell = new CellAddress(row, i);
// if BORDER_BOTTOM is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(row, i, CellUtil.BORDER_BOTTOM) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_BOTTOM) == null) {
drawBottomBorder(new CellRangeAddress(row, row, i, i), BorderStyle.THIN);
}
- addProperty(row, i, CellUtil.BOTTOM_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.BOTTOM_BORDER_COLOR, color);
}
}
int lastRow = range.getLastRow();
int col = range.getFirstColumn();
for (int i = firstRow; i <= lastRow; i++) {
+ CellAddress cell = new CellAddress(i, col);
// if BORDER_LEFT is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(i, col, CellUtil.BORDER_LEFT) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_LEFT) == null) {
drawLeftBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.LEFT_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.LEFT_BORDER_COLOR, color);
}
}
int lastRow = range.getLastRow();
int col = range.getLastColumn();
for (int i = firstRow; i <= lastRow; i++) {
+ CellAddress cell = new CellAddress(i, col);
// if BORDER_RIGHT is not set on BorderPropertyTemplate, make a thin border so that there's something to color
- if (getTemplateProperty(i, col, CellUtil.BORDER_RIGHT) == null) {
+ if (getTemplateProperty(cell, CellUtil.BORDER_RIGHT) == null) {
drawRightBorder(new CellRangeAddress(i, i, col, col), BorderStyle.THIN);
}
- addProperty(i, col, CellUtil.RIGHT_BORDER_COLOR, color);
+ addProperty(cell, CellUtil.RIGHT_BORDER_COLOR, color);
}
}
int lastColumn = range.getLastColumn();
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstColumn; col <= lastColumn; col++) {
- removeProperties(row, col, BORDER_COLOR_PROPERTY_NAMES);
+ CellAddress cell = new CellAddress(row, col);
+ removeProperties(cell, BORDER_COLOR_PROPERTY_NAMES);
}
}
}
/**
* Adds a property to this BorderPropertyTemplate for a given cell
*
- * @param row
- * @param col
- * @param property
- * @param value
+ * @param cell The cell to add the property to in the property template.
+ * @param property The property key to add to the property template.
+ * @param value The property value to add to the property template.
*/
- private void addProperty(int row, int col, String property, Object value) {
- CellAddress cell = new CellAddress(row, col);
+ private void addProperty(CellAddress cell, String property, Object value) {
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties == null) {
cellProperties = new HashMap<String, Object>();
cellProperties.put(property, value);
_propertyTemplate.put(cell, cellProperties);
}
+ /**
+ * Adds a property to this BorderPropertyTemplate for a given cell
+ *
+ * @param row The row number of the cell to add the property to
+ * @param col
+ * @param property The property key to add to the property template.
+ * @param value The property value to add to the property template.
+ */
+ private void addProperty(int row, int col, String property, Object value) {
+ CellAddress cell = new CellAddress(row, col);
+ addProperty(cell, property, value);
+ }
/**
* Removes a set of properties from this BorderPropertyTemplate for a
* @param col the column index of the cell to remove properties from
* @param properties a list of the property names to remove from the cell
*/
- private void removeProperties(int row, int col, Set<String> properties) {
- CellAddress cell = new CellAddress(row, col);
+ private void removeProperties(CellAddress cell, Set<String> properties) {
Map<String, Object> cellProperties = _propertyTemplate.get(cell);
if (cellProperties != null) {
cellProperties.keySet().removeAll(properties);
return count;
}
- /**
- * Retrieves the number of borders assigned to a cell
- *
- * @param row
- * @param col
- * @since 3.15 beta 2
- */
- public int getNumBorders(int row, int col) {
- return getNumBorders(new CellAddress(row, col));
- }
-
/**
* Retrieves the number of border colors assigned to a cell
*
return count;
}
- /**
- * Retrieves the number of border colors assigned to a cell
- *
- * @param row The row number of the cell to get the number of border colors from.
- * @param col The column number of the cell to get the number of border colors from.
- * @since 3.15 beta 2
- */
- public int getNumBorderColors(int row, int col) {
- return getNumBorderColors(new CellAddress(row, col));
- }
-
/**
* Retrieves the border style for a given cell
*
}
return null;
}
-
- /**
- * Retrieves the border style for a given cell
- *
- * @param row The row number of the cell to get a template property from.
- * @param col The column number of the cell to get a template property from.
- * @param property the template property to get from the BorderPropertyTemplate. Example: {@link CellUtil#BORDER_TOP}.
- * @since 3.15 beta 2
- */
- public Object getTemplateProperty(int row, int col, String property) {
- return getTemplateProperty(new CellAddress(row, col), property);
- }
}
@Test
public void getNumBorders() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorders(a1a1, BorderStyle.THIN, BorderExtent.TOP);
- assertEquals(1, pt.getNumBorders(0, 0));
+ assertEquals(1, pt.getNumBorders(a1));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.BOTTOM);
- assertEquals(2, pt.getNumBorders(0, 0));
+ assertEquals(2, pt.getNumBorders(a1));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.NONE);
- assertEquals(0, pt.getNumBorders(0, 0));
+ assertEquals(0, pt.getNumBorders(a1));
}
@Test
public void getNumBorderColors() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.TOP);
- assertEquals(1, pt.getNumBorderColors(0, 0));
+ assertEquals(1, pt.getNumBorderColors(a1));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.BOTTOM);
- assertEquals(2, pt.getNumBorderColors(0, 0));
+ assertEquals(2, pt.getNumBorderColors(a1));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.NONE);
- assertEquals(0, pt.getNumBorderColors(0, 0));
+ assertEquals(0, pt.getNumBorderColors(a1));
}
@Test
public void getTemplateProperties() throws IOException {
CellRangeAddress a1a1 = new CellRangeAddress(0, 0, 0, 0); //A1:A1
+ CellAddress a1 = new CellAddress(0, 0); //A1
+
BorderPropertyTemplate pt = new BorderPropertyTemplate();
pt.drawBorders(a1a1, BorderStyle.THIN, BorderExtent.TOP);
- assertThin(pt.getTemplateProperty(0, 0, CellUtil.BORDER_TOP));
+ assertThin(pt.getTemplateProperty(a1, CellUtil.BORDER_TOP));
pt.drawBorders(a1a1, BorderStyle.MEDIUM, BorderExtent.BOTTOM);
- assertMedium(pt.getTemplateProperty(0, 0, CellUtil.BORDER_BOTTOM));
+ assertMedium(pt.getTemplateProperty(a1, CellUtil.BORDER_BOTTOM));
pt.drawBorderColors(a1a1, IndexedColors.RED.getIndex(), BorderExtent.TOP);
- assertRed(pt.getTemplateProperty(0, 0, CellUtil.TOP_BORDER_COLOR));
+ assertRed(pt.getTemplateProperty(a1, CellUtil.TOP_BORDER_COLOR));
pt.drawBorderColors(a1a1, IndexedColors.BLUE.getIndex(), BorderExtent.BOTTOM);
- assertBlue(pt.getTemplateProperty(0, 0, CellUtil.BOTTOM_BORDER_COLOR));
+ assertBlue(pt.getTemplateProperty(a1, CellUtil.BOTTOM_BORDER_COLOR));
}
@Test
assertMedium(pt.getTemplateProperty(addr, CellUtil.BORDER_LEFT));
} else if (j == 2) {
assertEquals(1, pt.getNumBorders(addr));
- assertMedium(pt.getTemplateProperty(i ,j, CellUtil.BORDER_RIGHT));
+ assertMedium(pt.getTemplateProperty(addr, CellUtil.BORDER_RIGHT));
} else {
assertEquals(0, pt.getNumBorders(addr));
}