From d7e781d3499b34f1dda4c95f4b83f94b0f763018 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 14 Jul 2015 20:52:07 +0000 Subject: [PATCH] #58138 Color object support for HSSF CF borders git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691079 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFBorderFormatting.java | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java index 7dad25d75d..c5c9964563 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java @@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.record.CFRuleBase; import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.util.HSSFColor; +import org.apache.poi.ss.usermodel.Color; /** * High level representation for Border Formatting component @@ -72,23 +73,42 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B public short getDiagonalBorderColor() { return (short)borderFormatting.getDiagonalBorderColor(); } + public HSSFColor getDiagonalBorderColorColor() { + return workbook.getCustomPalette().getColor( + borderFormatting.getDiagonalBorderColor() + ); + } public short getLeftBorderColor() { return (short)borderFormatting.getLeftBorderColor(); } + public HSSFColor getLeftBorderColorColor() { + return workbook.getCustomPalette().getColor( + borderFormatting.getLeftBorderColor() + ); + } public short getRightBorderColor() { return (short)borderFormatting.getRightBorderColor(); } + public HSSFColor getRightBorderColorColor() { + return workbook.getCustomPalette().getColor( + borderFormatting.getRightBorderColor() + ); + } public short getTopBorderColor() { return (short)borderFormatting.getTopBorderColor(); } + public HSSFColor getTopBorderColorColor() { + return workbook.getCustomPalette().getColor( + borderFormatting.getTopBorderColor() + ); + } public boolean isBackwardDiagonalOn() { return borderFormatting.isBackwardDiagonalOn(); } - public boolean isForwardDiagonalOn() { return borderFormatting.isForwardDiagonalOn(); } @@ -99,6 +119,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setTopLeftBottomRightBorderModified(on); } } + public void setForwardDiagonalOn(boolean on) { + borderFormatting.setForwardDiagonalOn(on); + if (on) { + cfRuleRecord.setBottomLeftTopRightBorderModified(on); + } + } public void setBorderBottom(short border) { borderFormatting.setBorderBottom(border); @@ -155,6 +181,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setBottomBorderModified(false); } } + public void setBottomBorderColor(Color color) { + HSSFColor hcolor = HSSFColor.toHSSFColor(color); + if (hcolor == null) { + setBottomBorderColor((short)0); + } else { + setBottomBorderColor(hcolor.getIndex()); + } + } public void setDiagonalBorderColor(short color) { borderFormatting.setDiagonalBorderColor(color); @@ -166,11 +200,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setTopLeftBottomRightBorderModified(false); } } - - public void setForwardDiagonalOn(boolean on) { - borderFormatting.setForwardDiagonalOn(on); - if (on) { - cfRuleRecord.setBottomLeftTopRightBorderModified(on); + public void setDiagonalBorderColor(Color color) { + HSSFColor hcolor = HSSFColor.toHSSFColor(color); + if (hcolor == null) { + setDiagonalBorderColor((short)0); + } else { + setDiagonalBorderColor(hcolor.getIndex()); } } @@ -182,6 +217,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setLeftBorderModified(false); } } + public void setLeftBorderColor(Color color) { + HSSFColor hcolor = HSSFColor.toHSSFColor(color); + if (hcolor == null) { + setLeftBorderColor((short)0); + } else { + setLeftBorderColor(hcolor.getIndex()); + } + } public void setRightBorderColor(short color) { borderFormatting.setRightBorderColor(color); @@ -191,6 +234,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setRightBorderModified(false); } } + public void setRightBorderColor(Color color) { + HSSFColor hcolor = HSSFColor.toHSSFColor(color); + if (hcolor == null) { + setRightBorderColor((short)0); + } else { + setRightBorderColor(hcolor.getIndex()); + } + } public void setTopBorderColor(short color) { borderFormatting.setTopBorderColor(color); @@ -200,4 +251,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B cfRuleRecord.setTopBorderModified(false); } } + public void setTopBorderColor(Color color) { + HSSFColor hcolor = HSSFColor.toHSSFColor(color); + if (hcolor == null) { + setTopBorderColor((short)0); + } else { + setTopBorderColor(hcolor.getIndex()); + } + } } -- 2.39.5