public static java.awt.Color decodeColor(String colorString) { java.awt.Color color = null; char firstChar = colorString.charAt(0); if (firstChar == '#') { color = new java.awt.Color(Integer.parseInt(colorString.substring(1), 16)); } else if ('0' <= firstChar && firstChar <= '9') { color = new java.awt.Color(Integer.parseInt(colorString)); } else { if (ColorEnum.getByName(colorString) != null) { color = ColorEnum.getByName(colorString).getColor(); } else { color = java.awt.Color.black; } } return color; }
@Override public Object getEvaluatedValue(ItemProperty property, JRFillExpressionEvaluator evaluator, byte evaluation) throws JRException { Object result = super.getEvaluatedValue(property, evaluator, evaluation); return PROPERTY_COLOR.equals(property.getName()) ? JRColorUtil.getColorHexa(JRColorUtil.getColor((String)result, ColorEnum.RED.getColor())) : result; }
@Override public Object getEvaluatedValue(ItemProperty property, JRFillExpressionEvaluator evaluator, byte evaluation) throws JRException { Object result = super.getEvaluatedValue(property, evaluator, evaluation); return MapComponent.ITEM_PROPERTY_address.equals(property.getName()) ? getCoords((String)result) : (PROPERTY_COLOR.equals(property.getName()) ? JRColorUtil.getColorHexa(JRColorUtil.getColor((String)result, ColorEnum.RED.getColor())) : result); }
/** * Given the hexadecimal value of a color, it will be converted into an AWT color object * * @param colorString a string representing the hexadecimal value of a color, it can have or not the * starting symbol "#". * * @return an AWT color */ public static Color decodeColor(String colorString) { java.awt.Color color = null; if (colorString == null) return null; char firstChar = colorString.charAt(0); if (firstChar == '#') { color = new java.awt.Color(Integer.parseInt(colorString.substring(1), 16)); } else if ('0' <= firstChar && firstChar <= '9') { color = new java.awt.Color(Integer.parseInt(colorString)); } else { if (ColorEnum.getByName(colorString) != null) { color = ColorEnum.getByName(colorString).getColor(); } else { color = java.awt.Color.black; } } return color; }