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;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import org.json.simple.parser.JSONParser;
*
* Platform.timeCheck("some message", Platform.TIME_MARK);
*
+ * reset...[set/mark]n...get
+ *
* @param msg
* @param mode
*/
{
case TIME_RESET:
time = mark = t;
+ duration = 0;
if (msg != null)
{
System.err.println("Platform: timer reset\t\t\t" + msg);
case TIME_MARK:
if (set > 0)
{
+ // total time between set/mark points
duration += (t - set);
}
else
case TIME_GET:
if (msg != null)
{
- System.err.println("Platform: timer dur\t" + ((t - time) / 1000f)
+ System.err.println("Platform: timer get\t" + ((t - time) / 1000f)
+ "\t" + ((duration) / 1000f) + "\t" + msg);
}
set = 0;
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)
{
BrowserLauncher.openURL(url);
return false;
- }
- /**
- * @j2sNative
- *
- *
- * window.open(url);
- */
+ } /**
+ * @j2sNative
+ *
+ *
+ * window.open(url);
+ */
return true;
}
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)
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);
+ */
}
}
}
/**
+ * Convert a color name to a Color object.
+ *
+ *
* @param c
*/
public static Color getColorFromName(String name)
{
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":
default:
return null;
}
-
}
}
}
}
+ /**
+ * Set the "app" property of the HTML5 applet object, for example,
+ * "testApplet.app", to point to the Jalview instance. This will be the object
+ * that page developers use that is similar to the original Java applet object
+ * that was accessed via LiveConnect.
+ *
+ * @param j
+ */
+ public static void setAppClass(Object j)
+ {
+ if (!isJS())
+ {
+ return;
+ }
+ @SuppressWarnings("unused")
+ Thread t = Thread.currentThread();
+ /**
+ * Set up "testApplet.app" to be this instance
+ *
+ * @j2sNative
+ *
+ * try {self[t.name].app = j}catch(e){}
+ */
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ *
+ * If this frame Is this frame embedded in a web page, return a known type.
+ *
+ * @param frame
+ * a JFrame or JInternalFrame
+ * @param type
+ * @return null if frame is not embedded.
+ */
+ public static Object getEmbeddedAttribute(Object frame, String type)
+ {
+ if (!isJS())
+ {
+ return null;
+ }
+ return (/** @j2sNative frame.ui.getEmbedded$S(type) || */
+ null);
+ }
+
+ public static void stackTrace()
+ {
+ try
+ {
+ throw new NullPointerException();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ }
}