add ability to launch jalview from exported html + svg file. Abstracted Jalview build...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 11 Aug 2015 13:07:59 +0000 (14:07 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Tue, 11 Aug 2015 13:07:59 +0000 (14:07 +0100)
src/jalview/api/BuildDetailsI.java [new file with mode: 0644]
src/jalview/bin/BuildDetails.java [new file with mode: 0644]
src/jalview/bin/Cache.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JSONFile.java

diff --git a/src/jalview/api/BuildDetailsI.java b/src/jalview/api/BuildDetailsI.java
new file mode 100644 (file)
index 0000000..7a9bbff
--- /dev/null
@@ -0,0 +1,10 @@
+package jalview.api;
+
+public interface BuildDetailsI
+{
+  public String getBuildDate();
+
+  public String getVersion();
+
+  public String getInstallation();
+}
diff --git a/src/jalview/bin/BuildDetails.java b/src/jalview/bin/BuildDetails.java
new file mode 100644 (file)
index 0000000..0a1e227
--- /dev/null
@@ -0,0 +1,58 @@
+package jalview.bin;
+
+import jalview.api.BuildDetailsI;
+
+
+public class BuildDetails implements BuildDetailsI
+{
+  private static String buildDate;
+
+  private static String version;
+
+  private static String installation;
+
+  public BuildDetails()
+  {
+
+  }
+
+  public BuildDetails(String version, String buildDate, String installation)
+  {
+    BuildDetails.version = version;
+    BuildDetails.buildDate = buildDate;
+    BuildDetails.installation = installation;
+  }
+
+  public String getBuildDate()
+  {
+    return buildDate;
+  }
+
+  public static void setBuilddate(String buildDate)
+  {
+    BuildDetails.buildDate = buildDate;
+  }
+
+  public String getVersion()
+  {
+    return version;
+  }
+
+  public static void setVersion(String version)
+  {
+    BuildDetails.version = version;
+  }
+
+  public String getInstallation()
+  {
+    return installation;
+  }
+
+  public static void setInstallation(String installation)
+  {
+    BuildDetails.installation = installation;
+  }
+
+
+
+}
index 10aba00..641815d 100755 (executable)
@@ -391,7 +391,7 @@ public class Cache
     {
       codeInstallation = " (" + codeInstallation + ")";
     }
-
+    new BuildDetails(codeVersion, null, codeInstallation);
     System.out
             .println("Jalview Version: " + codeVersion + codeInstallation);
 
index 781eace..1eb86b7 100644 (file)
@@ -276,6 +276,7 @@ public class HtmlSvgOutput
     htmlSvg.append("<html>\n");
     if (jsonData != null)
     {
+      htmlSvg.append("<button onclick=\"javascipt:openJalviewUsingCurrentUrl();\">Launch in Jalview</button>");
       htmlSvg.append("<input type=\"hidden\" name=\"seqData\" id=\"seqData\" value='"
               + jsonData + "'>");
     }
@@ -310,8 +311,35 @@ public class HtmlSvgOutput
             + "subCatContainer.scroll(\nfunction() {\n"
             + "subCatContainer.scrollTop($(this).scrollTop());\n});\n");
 
-    htmlSvg.append("</script></hmtl>");
-
+    htmlSvg.append("</script>\n");
+
+    // javascript for launching file in Jalview
+
+    htmlSvg.append("<script language=\"JavaScript\">\n");
+    htmlSvg.append("function openJalviewUsingCurrentUrl(){\n");
+    htmlSvg.append("    var json = JSON.parse(document.getElementById(\"seqData\").value);\n");
+    htmlSvg.append("    var jalviewVersion = json['appSettings'].version;\n");
+    htmlSvg.append("    var url = json['appSettings'].webStartUrl;\n");
+    htmlSvg.append("    var myForm = document.createElement(\"form\");\n\n");
+    htmlSvg.append("    var heap = document.createElement(\"input\");\n");
+    htmlSvg.append("    heap.setAttribute(\"name\", \"jvm-max-heap\") ;\n");
+    htmlSvg.append("    heap.setAttribute(\"value\", \"2G\");\n\n");
+    htmlSvg.append("    var target = document.createElement(\"input\");\n");
+    htmlSvg.append("    target.setAttribute(\"name\", \"open\");\n");
+    htmlSvg.append("    target.setAttribute(\"value\", document.URL);\n\n");
+    htmlSvg.append("    var jvVersion = document.createElement(\"input\");\n");
+    htmlSvg.append("    jvVersion.setAttribute(\"name\", \"version\") ;\n");
+    htmlSvg.append("    jvVersion.setAttribute(\"value\", jalviewVersion);\n\n");
+    htmlSvg.append("    myForm.action = url;\n");
+    htmlSvg.append("    myForm.appendChild(heap);\n");
+    htmlSvg.append("    myForm.appendChild(target);\n");
+    htmlSvg.append("    myForm.appendChild(jvVersion);\n");
+    htmlSvg.append("    document.body.appendChild(myForm);\n");
+    htmlSvg.append("    myForm.submit() ;\n");
+    htmlSvg.append("    document.body.removeChild(myForm);\n");
+    htmlSvg.append("}\n");
+    htmlSvg.append("</script>\n");
+    htmlSvg.append("</hmtl>");
     return htmlSvg.toString();
   }
 }
index b079a3c..b8e2454 100644 (file)
@@ -27,6 +27,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.api.ComplexAlignFile;
 import jalview.api.FeatureRenderer;
 import jalview.api.FeaturesDisplayedI;
+import jalview.bin.BuildDetails;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
@@ -64,9 +65,9 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
 {
   private ColourSchemeI colourScheme;
 
-  private String version = "2.9";
+  private static String version = new BuildDetails().getVersion();
 
-  private String webstartUrl = "www.jalview.org/services/launchApp";
+  private String webstartUrl = "http://www.jalview.org/services/launchApp";
 
   private String application = "Jalview";
 
@@ -176,7 +177,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         jsonSeqPojo.setSeq(seq.getSequenceAsString());
         jsonAlignmentPojo.getSeqs().add(jsonSeqPojo);
       }
-
       jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme);
       jsonAlignmentPojo.getAppSettings().put("application", application);
       jsonAlignmentPojo.getAppSettings().put("version", version);