src/net/sourceforge/plantuml/klimt/color/HColorSimple.java
<reponame>plantuml/java-zero// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.klimt.color;

import java.awt.Color;

import net.sourceforge.plantuml.StringUtils;

public class HColorSimple extends HColor {

	private final Color color;
	private final HColor dark;

	@Override
	public String toString() {

		final boolean withDark = dark != null;

		final StringBuilder sb = new StringBuilder();
		if (withDark)
			sb.append("WITHDARK ");
		sb.append(color.toString());
		sb.append(" \u03B1=");
		sb.append(color.getAlpha());
		if (isTransparent())
			sb.append(" transparent");
		return sb.toString();
	}


	@Override
	public boolean isDark() {
		return ColorUtils.getGrayScale(color) < 128;
	}

	@Override
	public boolean isTransparent() {
		return color.getAlpha() == 0;
	}

	public static HColorSimple create(Color c) {
		return new HColorSimple(c, null);
	}

	private HColorSimple(Color c, HColor dark) {
		this.color = c;
		this.dark = dark;
	}

	public Color getAwtColor() {
		return color;
	}

	public HColor asMonochrome() {
		return HColorSimple.create(ColorUtils.getGrayScaleColor(color));
	}


	@Override
	public HColor opposite() {
		final Color mono = ColorUtils.getGrayScaleColor(color);
		final int grayScale = 255 - mono.getGreen() > 127 ? 255 : 0;
		return HColorSimple.create(new Color(grayScale, grayScale, grayScale));
	}

	public int distanceTo(HColorSimple other) {
		return ColorUtils.distance(this.color, other.color);
	}

	public boolean isGray() {
		return color.getRed() == color.getGreen() && color.getGreen() == color.getBlue();
	}

	@Override
	public HColor withDark(HColor dark) {
		return new HColorSimple(color, dark);
	}

	@Override
	public HColor darkSchemeTheme() {
		if (dark == null)
			return this;
		return dark;
	}

}
