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,17 +54,14 @@ 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();
|
|
||||||
String name = type.getSimpleName();
|
|
||||||
if (name.equals(name.toUpperCase(Locale.ROOT))) {
|
|
||||||
short[] rgb = color.getTriplet();
|
short[] rgb = color.getTriplet();
|
||||||
Color c = new Color(rgb[0], rgb[1], rgb[2]);
|
Color c = new Color(rgb[0], rgb[1], rgb[2]);
|
||||||
NAMED_COLORS.put(name, c);
|
NAMED_COLORS.put(name, c);
|
||||||
|
@ -75,7 +72,6 @@ public class CellFormatPart {
|
||||||
' '), c);
|
' '), c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Pattern for the color part of a cell format part. */
|
/** Pattern for the color part of a cell format part. */
|
||||||
public static final Pattern COLOR_PAT;
|
public static final Pattern COLOR_PAT;
|
||||||
|
|
|
@ -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