org.esa.beam.util.StringUtils.formatColor()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.esa.beam.util.StringUtils.formatColor()方法的一些代码示例,展示了StringUtils.formatColor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.formatColor()方法的具体详情如下:
包路径:org.esa.beam.util.StringUtils
类名称:StringUtils
方法名:formatColor

StringUtils.formatColor介绍

[英]Returns a string representation of the given color value.
[中]返回给定颜色值的字符串表示形式。

代码示例

代码示例来源:origin: bcdev/beam

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");
    }
  }

代码示例来源:origin: bcdev/beam

/**
 * 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);
  }
}

代码示例来源:origin: bcdev/beam

/**
 * 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);
}

相关文章