From: hansonr Date: Tue, 16 Jul 2019 21:46:06 +0000 (+0100) Subject: issue JAL-3368 and JAL-3253-applet X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=60ade4437409299de040abb15588b052a932bf5c;p=jalview.git issue JAL-3368 and JAL-3253-applet Color names not supported. --- diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 60129fb..3eb080b 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -225,6 +225,7 @@ public class ColorUtils col = new Color(value); } catch (NumberFormatException ex) { + col = Platform.getColorFromName(colour); } if (col == null) @@ -319,57 +320,8 @@ public class ColorUtils */ public static Color getAWTColorFromName(String name) { - if (name == null) - { - return null; - } - Color col = null; - name = name.toLowerCase(); - - // or make a static map; or use reflection on the field name - switch (name) - { - case "black": - col = Color.black; - break; - case "blue": - col = Color.blue; - break; - case "cyan": - col = Color.cyan; - break; - case "darkgray": - col = Color.darkGray; - break; - case "gray": - col = Color.gray; - break; - case "green": - col = Color.green; - break; - case "lightgray": - col = Color.lightGray; - break; - case "magenta": - col = Color.magenta; - break; - case "orange": - col = Color.orange; - break; - case "pink": - col = Color.pink; - break; - case "red": - col = Color.red; - break; - case "white": - col = Color.white; - break; - case "yellow": - col = Color.yellow; - break; - } - - return col; + return Platform.getColorFromName(name); // BH 2019 -- allows for wide range + // of JavaScript colors (for + // JavaScript only) } } diff --git a/src/jalview/util/Platform.java b/src/jalview/util/Platform.java index a1412f2..fe620ed 100644 --- a/src/jalview/util/Platform.java +++ b/src/jalview/util/Platform.java @@ -22,6 +22,7 @@ package jalview.util; import jalview.javascript.json.JSON; +import java.awt.Color; import java.awt.Toolkit; import java.awt.event.MouseEvent; import java.io.BufferedReader; @@ -697,4 +698,55 @@ public class Platform return Regex.perlCode(code); } + /** + * @param c + */ + public static Color getColorFromName(String name) + { + if (name == null) + { + return null; + } + /** + * @j2sNative + * + * return swingjs.JSUtil.getColorFromName$S(name); + */ + { + // or make a static map; or use reflection on the field name + switch (name.toLowerCase()) + { + case "black": + return Color.black; + case "blue": + return Color.blue; + case "cyan": + return Color.cyan; + case "darkgray": + return Color.darkGray; + case "gray": + return Color.gray; + case "green": + return Color.green; + case "lightgray": + return Color.lightGray; + case "magenta": + return Color.magenta; + case "orange": + return Color.orange; + case "pink": + return Color.pink; + case "red": + return Color.red; + case "white": + return Color.white; + case "yellow": + return Color.yellow; + default: + return null; + } + + } + } + }