changeset 10767:5a3cc1b5bb22

8088925: Non opaque background cause NumberFormatException Reviewed-by: arajkumar, ghb
author rkamath
date Wed, 03 Jan 2018 12:47:06 +0530
parents cd2e46a780b0
children 36182d670b61
files modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java
diffstat 1 files changed, 11 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java	Fri Dec 22 05:25:44 2017 -0800
+++ b/modules/javafx.web/src/main/java/javafx/scene/web/HTMLEditorSkin.java	Wed Jan 03 12:47:06 2018 +0530
@@ -1029,15 +1029,13 @@
         fgColorButton.setDisable(!isCommandEnabled(FOREGROUND_COLOR.getCommand()));
         String foregroundColorValue = getCommandValue(FOREGROUND_COLOR.getCommand());
         if (foregroundColorValue != null) {
-            Color c = Color.web(rgbToHex((String)foregroundColorValue));
-            fgColorButton.setValue(c);
+            fgColorButton.setValue(getColor(foregroundColorValue));
         }
 
         bgColorButton.setDisable(!isCommandEnabled(BACKGROUND_COLOR.getCommand()));
         String backgroundColorValue = getCommandValue(BACKGROUND_COLOR.getCommand());
         if (backgroundColorValue != null) {
-            Color c = Color.web(rgbToHex((String)backgroundColorValue));
-            bgColorButton.setValue(c);
+            bgColorButton.setValue(getColor(backgroundColorValue));
         }
 
         atomicityCount = atomicityCount == 0 ? 0 : --atomicityCount;
@@ -1119,29 +1117,16 @@
         return webPage.queryCommandValue(command);
     }
 
-    private static String rgbToHex(String value) {
-        if (value.startsWith("rgba")) {
-            String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(",");
-            value = String.format("#%02X%02X%02X%02X",
-                Integer.parseInt(components[0].trim()),
-                Integer.parseInt(components[1].trim()),
-                Integer.parseInt(components[2].trim()),
-                Integer.parseInt(components[3].trim()));
-            // The default background color for WebView, according to the HTML
-            // standard is rgba=#00000000 (black). The canvas background is expected
-            // to be white.
-            if ("#00000000".equals(value)) {
-                return "#FFFFFFFF";
-            }
-        } else if (value.startsWith("rgb")) {
-            String[] components = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(",");
-            value = String.format("#%02X%02X%02X",
-                Integer.parseInt(components[0].trim()),
-                Integer.parseInt(components[1].trim()),
-                Integer.parseInt(components[2].trim()));
+    private Color getColor(String value) {
+        Color color = Color.web(value);
+        /* The default background color for WebView, according to the HTML
+         * standard is rgba=#00000000 (transparent). The canvas background is expected
+         * to be white.
+         */
+        if (color.equals(Color.TRANSPARENT)) {
+            color = Color.WHITE;
         }
-
-        return value;
+        return color;
     }
 
     private void applyTextFormatting() {