added awt methods for contrast color
package io.github.mzmine.util.color;
+import io.github.mzmine.util.javafx.FxColorUtil;
import javafx.scene.paint.Color;
public class ColorUtils {
@@ -30,34 +31,44 @@ public class ColorUtils {
* @return new color
*/
public static Color tintColor(Color color, double factor) {
- return new Color(
- color.getRed() + (1d - color.getRed()) * factor,
+ return new Color(color.getRed() + (1d - color.getRed()) * factor,
color.getGreen() + (1d - color.getGreen()) * factor,
- color.getBlue() + (1d - color.getBlue()) * factor,
- color.getOpacity()
- );
+ color.getBlue() + (1d - color.getBlue()) * factor, color.getOpacity());
}
/**
- * Returns an absolute distance of rgb values between two colors. Can be treated as a metric on colors.
+ * Returns an absolute distance of rgb values between two colors. Can be treated as a metric on
+ * colors.
*/
public static double getColorDistance(Color color1, Color color2) {
- return Math.abs(color1.getRed() - color2.getRed())
- + Math.abs(color1.getGreen() - color2.getGreen())
- + Math.abs(color1.getBlue() - color2.getBlue());
+ return Math.abs(color1.getRed() - color2.getRed()) + Math
+ .abs(color1.getGreen() - color2.getGreen()) + Math.abs(color1.getBlue() - color2.getBlue());
}
/**
- * Returns either positive or negative color from the given palette depending on which one is
- * more contrast to the given color.
+ * Returns either positive or negative color from the given palette depending on which one is more
+ * contrast to the given color.
*/
public static Color getContrastPaletteColor(Color color, SimpleColorPalette palette) {
Color positiveColor = palette.getPositiveColor();
Color negativeColor = palette.getNegativeColor();
return getColorDistance(color, positiveColor) > getColorDistance(color, negativeColor)
- ? positiveColor
- : negativeColor;
+ ? positiveColor : negativeColor;
+ }
+
+ public static Color getContrastPaletteColor(java.awt.Color color, SimpleColorPalette palette) {
+ return getContrastPaletteColor(FxColorUtil.awtColorToFX(color), palette);
+ }
+
+ public static java.awt.Color getContrastPaletteColorAWT(java.awt.Color color, SimpleColorPalette palette) {
+ return FxColorUtil
+ .fxColorToAWT(getContrastPaletteColor(FxColorUtil.awtColorToFX(color), palette));
+ }
+
+ public static java.awt.Color getContrastPaletteColorAWT(Color color, SimpleColorPalette palette) {
+ return FxColorUtil
+ .fxColorToAWT(getContrastPaletteColor(color, palette));
}
}
