Java Code Examples for java.awt.Color#getColor()

The following examples show how to use java.awt.Color#getColor() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public PrintImageMapCommand()
{
	for(int i = 0; i < 256; i++)
	{
		colorMap[i] = Color.getColor("", (i << 16) + (i << 8) + i);
	}
}
 
Example 2
Source Project: pdfxtk   File: Style.java    License: Apache License 2.0 5 votes vote down vote up
public void setParam(BrowserContext c, Object o, String v) throws ParameterException {
  Style s = (Style) o;
  s.foreground = Color.getColor(v);
  if (s.foreground == null) {
    c.log("Color "+v+" not found, using red instead");
    s.foreground = Color.red;
  }
}
 
Example 3
Source Project: pdfxtk   File: Style.java    License: Apache License 2.0 5 votes vote down vote up
public void setParam(BrowserContext c, Object o, String v) throws ParameterException {
  Style s = (Style) o;
  s.background = Color.getColor(v);
  if (s.background == null) {
    c.log("Color "+v+" not found, using red instead");
    s.background = Color.red;
  }
}
 
Example 4
Source Project: dingtalk-plugin   File: JavaFxColor.java    License: MIT License 4 votes vote down vote up
public static Color web(String colorString, float opacity) {
  if (colorString == null) {
    throw new NullPointerException(
        "The color components or name must be specified");
  }
  if (colorString.isEmpty()) {
    throw new IllegalArgumentException("Invalid color specification");
  }

  String color = colorString.toLowerCase(Locale.ROOT);

  if (color.startsWith("#")) {
    color = color.substring(1);
  } else if (color.startsWith("0x")) {
    color = color.substring(2);
  } else if (color.startsWith("rgb")) {
    if (color.startsWith("(", 3)) {
      return parseRGBColor(color, 4, false, opacity);
    } else if (color.startsWith("a(", 3)) {
      return parseRGBColor(color, 5, true, opacity);
    }
  } else if (color.startsWith("hsl")) {
    if (color.startsWith("(", 3)) {
      return parseHSLColor(color, 4, false, opacity);
    } else if (color.startsWith("a(", 3)) {
      return parseHSLColor(color, 5, true, opacity);
    }
  } else {
    Color namedColor = Color.getColor(colorString);
    if (namedColor != null) {
      if (opacity == 1.0) {
        return namedColor;
      } else {
        return color(
            namedColor.getRed(),
            namedColor.getGreen(),
            namedColor.getBlue(),
            opacity);
      }
    }
  }

  int len = color.length();

  try {
    int r;
    int g;
    int b;
    int a;

    if (len == 3) {
      r = Integer.parseInt(color.substring(0, 1), 16);
      g = Integer.parseInt(color.substring(1, 2), 16);
      b = Integer.parseInt(color.substring(2, 3), 16);
      return color(r / 15.0f, g / 15.0f, b / 15.0f, opacity);
    } else if (len == 4) {
      r = Integer.parseInt(color.substring(0, 1), 16);
      g = Integer.parseInt(color.substring(1, 2), 16);
      b = Integer.parseInt(color.substring(2, 3), 16);
      a = Integer.parseInt(color.substring(3, 4), 16);
      return color(r / 15.0f, g / 15.0f, b / 15.0f,
          opacity * a / 15.0f);
    } else if (len == 6) {
      r = Integer.parseInt(color.substring(0, 2), 16);
      g = Integer.parseInt(color.substring(2, 4), 16);
      b = Integer.parseInt(color.substring(4, 6), 16);
      return rgb(r, g, b, opacity);
    } else if (len == 8) {
      r = Integer.parseInt(color.substring(0, 2), 16);
      g = Integer.parseInt(color.substring(2, 4), 16);
      b = Integer.parseInt(color.substring(4, 6), 16);
      a = Integer.parseInt(color.substring(6, 8), 16);
      return rgb(r, g, b, opacity * a / 255.0f);
    }
  } catch (NumberFormatException ignored) {
  }

  throw new IllegalArgumentException("Invalid color specification");
}
 
Example 5
Source Project: svg2vector   File: Svg2Vector_FH.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int executeApplication(String[] args) {
	// parse command line, exit with help screen if error
	int ret = super.executeApplication(args);
	if(ret!=0){
		return ret;
	}

	SvgTargets target = this.getProps().getTarget();

	FhConverter converter = TARGET_2_CONVERTER(target);
	if(converter==null){
		this.printErrorMessage("no converter found for target <" + target.name() + ">");
		return -20;
	}

	converter.setPropertyTransparent(!this.optionNotTransparent.inCli());
	converter.setPropertyClip(this.optionClip.inCli());
	converter.setPropertyBackground(!this.optionNoBackground.inCli());
	converter.setPropertyTextAsShapes(this.getProps().doesTextAsShape());
	if(this.optionBackgroundColor.inCli()){
		Color color = Color.getColor(this.optionBackgroundColor.getValue());
		converter.setPropertyBackgroundColor(color);
	}

	UserProperties up = converter.getProperties();
	Set<Object> keys = up.keySet();
	Iterator<Object>it = keys.iterator();
	while(it.hasNext()){
		String key = it.next().toString();
		String val = up.getProperty(key);
		key=key.substring(key.lastIndexOf('.')+1, key.length());
		this.printDetailMessage("using SVG property " + key + "=" + val);
	}

	String err;
	BatikLoader loader = this.getProps().getLoader();
	if(this.getProps().doesLayers()){
		for(Entry<String, Integer> entry : loader.getLayers().entrySet()){
			loader.switchOffAllLayers();
			loader.switchOnLayer(entry.getKey());
			this.printProgressMessage("processing layer " + entry.getKey());
			this.printDetailMessage("writing to file " + this.getProps().getFnOut(entry) + "." + target.name());
			if(this.getProps().canWriteFiles()){
				err = converter.convertDocument(loader, new File(this.getProps().getFnOut(entry) + "." + target.name()));
				if(err!=null){
					this.printErrorMessage(err);
					return -99;//TODO
				}
			}
		}
	}
	else{
		this.printProgressMessage("converting input");
		this.printDetailMessage("writing to file " + this.getProps().getFoutFile());
		if(this.getProps().canWriteFiles()){
			err = converter.convertDocument(loader, this.getProps().getFoutFile());
			if(err!=null){
				this.printErrorMessage(err);
				return -99;//TODO
			}
		}
	}

	this.printProgressMessage("finished successfully");
	return 0;
}
 
Example 6
Source Project: TFC2   File: HexBiome.java    License: GNU General Public License v3.0 4 votes vote down vote up
public HexBiome(int c)
{
	color = Color.getColor("", c);
}