JAL-3368 'web' colour parsing reinstated (for now)
[jalview.git] / src / jalview / util / Platform.java
index fba669b..feb6bee 100644 (file)
@@ -23,6 +23,7 @@ package jalview.util;
 import jalview.javascript.json.JSON;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Toolkit;
 import java.awt.event.MouseEvent;
 import java.io.BufferedReader;
@@ -40,6 +41,7 @@ import java.util.logging.ConsoleHandler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.swing.JComponent;
 import javax.swing.SwingUtilities;
 
 import org.json.simple.parser.JSONParser;
@@ -333,13 +335,12 @@ public class Platform
     if (!isJS() || data == null)
     {
       return;
-    }
-    /**
-     * @j2sNative
-     * 
-     *            swingjs.JSUtil.cacheFileData$S$O(path, data);
-     * 
-     */
+    } /**
+       * @j2sNative
+       * 
+       *            swingjs.JSUtil.cacheFileData$S$O(path, data);
+       * 
+       */
   }
 
   public static void cacheFileData(File file)
@@ -438,13 +439,12 @@ public class Platform
     {
       BrowserLauncher.openURL(url);
       return false;
-    }
-    /**
-     * @j2sNative
-     * 
-     * 
-     *            window.open(url);
-     */
+    } /**
+       * @j2sNative
+       * 
+       * 
+       *            window.open(url);
+       */
     return true;
   }
 
@@ -533,8 +533,7 @@ public class Platform
 
   public static Object parseJSON(String json) throws ParseException
   {
-    return (isJS() ? JSON.parse(json)
-            : new JSONParser().parse(json));
+    return (isJS() ? JSON.parse(json) : new JSONParser().parse(json));
   }
 
   public static Object parseJSON(Reader r)
@@ -612,13 +611,12 @@ public class Platform
     if (isJS())
     {
       System.out.println(
-            "Platform adding known access-control-allow-origin * for domain "
-                    + domain);
-      /**
-       * @j2sNative
-       * 
-       *            J2S.addDirectDatabaseCall(domain);
-       */
+              "Platform adding known access-control-allow-origin * for domain "
+                      + domain);/**
+                                 * @j2sNative
+                                 * 
+                                 *            J2S.addDirectDatabaseCall(domain);
+                                 */
     }
 
   }
@@ -718,6 +716,9 @@ public class Platform
   }
 
   /**
+   * Convert a color name to a Color object.
+   * 
+   * 
    * @param c
    */
   public static Color getColorFromName(String name)
@@ -726,13 +727,20 @@ public class Platform
     {
       return null;
     }
+
+    /*
+     * JSUtil provides code that will convert any web colour name to the
+     * AWT color; but preferred solution is to add these colours for Java
+     * also (preferably read from a resource file).
+     * NB there are some conflicts (differing colours for the same name)
+     * - see JAL-3368
+     */
     /**
      * @j2sNative
      * 
      *            return swingjs.JSUtil.getColorFromName$S(name);
      */
     {
-      // or make a static map; or use reflection on the field name
       switch (name.toLowerCase())
       {
       case "black":
@@ -764,7 +772,6 @@ public class Platform
       default:
         return null;
       }
-
     }
   }
 
@@ -836,7 +843,26 @@ public class Platform
      */
   }
 
-  public final static String EMBEDDED_DIM = "dim";
+  /**
+   * Retrieve the object's embedded size from a div's style on a page if
+   * embedded in SwingJS.
+   * 
+   * @param frame
+   *          JFrame or JInternalFrame
+   * @param defaultWidth
+   *          use -1 to return null (no default size)
+   * @param defaultHeight
+   * @return the embedded dimensions or null (no default size or not embedded)
+   */
+  public static Dimension getDimIfEmbedded(JComponent frame,
+          int defaultWidth, int defaultHeight)
+  {
+    Dimension d = /** @j2sNative frame.ui.getEmbedded$S("dim") || */
+            null;
+    return (d == null && defaultWidth >= 0
+            ? new Dimension(defaultWidth, defaultHeight)
+            : d);
+  }
 
   /**
    *
@@ -853,7 +879,7 @@ public class Platform
     {
       return null;
     }
-    return (/** swingjs@j2sNative || frame.ui.getEmbedded(type) */
+    return (/** @j2sNative frame.ui.getEmbedded$S(type) || */
     null);
   }