private static void writeColorPalette(RasterDataNode raster, FileWriter writer) throws IOException { ImageInfo imageInfo = raster.getImageInfo(); final ColorPaletteDef paletteDef = imageInfo.getColorPaletteDef(); final Color[] colorPalette = ImageManager.createColorPalette(imageInfo); // Color[] colorPalette = paletteDef.createColorPalette(raster); double s1 = paletteDef.getMinDisplaySample(); double s2 = paletteDef.getMaxDisplaySample(); int numColors = colorPalette.length; writer.write("# Band: " + raster.getName() + "\n"); writer.write("# Sample unit: " + raster.getUnit() + "\n"); writer.write("# Minimum sample value: " + s1 + "\n"); writer.write("# Maximum sample value: " + s2 + "\n"); writer.write("# Number of colors: " + numColors + "\n"); double sf = (s2 - s1) / (numColors - 1.0); writer.write("ID;Sample;RGB\n"); for (int i = 0; i < numColors; i++) { Color color = colorPalette[i]; double s = s1 + i * sf; writer.write(i + ";" + s + ";" + StringUtils.formatColor(color) + "\n"); } }
/** * Sets a value of type <code>Color</code>. * * @param key the key * @param newValue the value * * @throws IllegalArgumentException */ public void setPropertyColor(String key, Color newValue) { Guardian.assertNotNullOrEmpty("key", key); Color oldValue = getPropertyColor(key, null); if (!ObjectUtils.equalObjects(oldValue, newValue)) { if (newValue != null) { _properties.setProperty(key, StringUtils.formatColor(newValue)); } else { _properties.remove(key); } firePropertyChange(key, oldValue, newValue); } }
/** * Returns the given {@link Color color} value as a string, according to the rules of the {@link Parameter parameter}. * If the value is <code>null</code> and {@link #isAllowedNullValue null value is allowed}, * this method returns an empty string, otherwise a {@link ParamFormatException} will be thrown. * * @param parameter the parameter which contains the rules to format * @param value the value to format * * @return the value as string or an empty string. * * @throws ParamFormatException if the value is <code>null</code> and * {@link #isAllowedNullValue null value is not allowed} * or the value is not an instance of {@link java.awt.Color}. */ public String format(Parameter parameter, Object value) throws ParamFormatException { if (isAllowedNullValue(parameter, value)) { return ""; } Color c = castToColor(value); if (c == null) { throw new ParamFormatException(parameter, ParamConstants.ERR_MSG_NOT_COLOR_TYPE); } return StringUtils.formatColor(c); }