private final CellFormatter format;
private final CellFormatType type;
- private static final Map<String, Color> NAMED_COLORS;
+ static final Map<String, Color> NAMED_COLORS;
static {
NAMED_COLORS = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
- Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
- for (HSSFColor color : colors.values()) {
- Class<? extends HSSFColor> type = color.getClass();
- String name = type.getSimpleName();
- if (name.equals(name.toUpperCase(Locale.ROOT))) {
- short[] rgb = color.getTriplet();
- Color c = new Color(rgb[0], rgb[1], rgb[2]);
- NAMED_COLORS.put(name, c);
- if (name.indexOf('_') > 0)
- NAMED_COLORS.put(name.replace('_', ' '), c);
- if (name.indexOf("_PERCENT") > 0)
- NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
- ' '), c);
- }
+ for (HSSFColor.HSSFColorPredefined color : HSSFColor.HSSFColorPredefined.values()) {
+ String name = color.name();
+ short[] rgb = color.getTriplet();
+ Color c = new Color(rgb[0], rgb[1], rgb[2]);
+ NAMED_COLORS.put(name, c);
+ if (name.indexOf('_') > 0)
+ NAMED_COLORS.put(name.replace('_', ' '), c);
+ if (name.indexOf("_PERCENT") > 0)
+ NAMED_COLORS.put(name.replace("_PERCENT", "%").replace('_',
+ ' '), c);
}
}
package org.apache.poi.ss.format;
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.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.xssf.XSSFITestDataProvider;
});
}
+ @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) {
Matcher m = NUMBER_EXTRACT_FMT.matcher(str);
if (!m.find())