mirror of https://github.com/apache/poi.git
[bug-62908] populate NamedColors
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846520 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d0af7b3a9a
commit
d1deecfc9c
|
@ -54,26 +54,22 @@ public class CellFormatPart {
|
||||||
private final CellFormatter format;
|
private final CellFormatter format;
|
||||||
private final CellFormatType type;
|
private final CellFormatType type;
|
||||||
|
|
||||||
private static final Map<String, Color> NAMED_COLORS;
|
static final Map<String, Color> NAMED_COLORS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NAMED_COLORS = new TreeMap<>(
|
NAMED_COLORS = new TreeMap<>(
|
||||||
String.CASE_INSENSITIVE_ORDER);
|
String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
|
for (HSSFColor.HSSFColorPredefined color : HSSFColor.HSSFColorPredefined.values()) {
|
||||||
for (HSSFColor color : colors.values()) {
|
String name = color.name();
|
||||||
Class<? extends HSSFColor> type = color.getClass();
|
short[] rgb = color.getTriplet();
|
||||||
String name = type.getSimpleName();
|
Color c = new Color(rgb[0], rgb[1], rgb[2]);
|
||||||
if (name.equals(name.toUpperCase(Locale.ROOT))) {
|
NAMED_COLORS.put(name, c);
|
||||||
short[] rgb = color.getTriplet();
|
if (name.indexOf('_') > 0)
|
||||||
Color c = new Color(rgb[0], rgb[1], rgb[2]);
|
NAMED_COLORS.put(name.replace('_', ' '), c);
|
||||||
NAMED_COLORS.put(name, c);
|
if (name.indexOf("_PERCENT") > 0)
|
||||||
if (name.indexOf('_') > 0)
|
NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
|
||||||
NAMED_COLORS.put(name.replace('_', ' '), c);
|
' '), c);
|
||||||
if (name.indexOf("_PERCENT") > 0)
|
|
||||||
NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
|
|
||||||
' '), c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,15 @@
|
||||||
package org.apache.poi.ss.format;
|
package org.apache.poi.ss.format;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.util.LocaleUtil;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
@ -153,6 +156,19 @@ public class TestCellFormatPart extends CellFormatTestBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNamedColors() {
|
||||||
|
assertTrue(CellFormatPart.NAMED_COLORS.size() >= HSSFColor.HSSFColorPredefined.values().length);
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("GREEN"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("Green"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("RED"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("Red"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("BLUE"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("Blue"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("YELLOW"));
|
||||||
|
assertNotNull(CellFormatPart.NAMED_COLORS.get("Yellow"));
|
||||||
|
}
|
||||||
|
|
||||||
private double extractNumber(String str) {
|
private double extractNumber(String str) {
|
||||||
Matcher m = NUMBER_EXTRACT_FMT.matcher(str);
|
Matcher m = NUMBER_EXTRACT_FMT.matcher(str);
|
||||||
if (!m.find())
|
if (!m.find())
|
||||||
|
|
Loading…
Reference in New Issue