Patch to synchronize title svg and allignment svg scrolling
[jalview.git] / src / jalview / io / HtmlSvgOutput.java
index 4643858..3c9c608 100644 (file)
@@ -29,20 +29,26 @@ public class HtmlSvgOutput
 
   AnnotationPanel annotationPanel;
 
-  public HtmlSvgOutput(AlignmentPanel ap)
+  public HtmlSvgOutput(File file, AlignmentPanel ap)
   {
 
       this.av = ap.av;
       this.ap = ap;
       this.annotationPanel = ap.getAnnotationPanel();
-    generateHtmlSvgOutput();
+    generateHtmlSvgOutput(file);
   }
 
-  public void generateHtmlSvgOutput()
+  public void generateHtmlSvgOutput(File file)
   {
-    File file = null;
     try
     {
+      if (file == null /*
+                        * && !(System.getProperty("java.awt.headless") != null
+                        * && System
+                        * .getProperty("java.awt.headless").equals("true"))
+                        */)
+      {
+
       JalviewFileChooser chooser = getHTMLChooser();
       chooser.setFileView(new jalview.io.JalviewFileView());
       chooser.setDialogTitle(ap.alignFrame.getTitle());
@@ -55,6 +61,7 @@ public class HtmlSvgOutput
                 .getSelectedFile().getParent());
         file = chooser.getSelectedFile();
       }
+      }
 
       AlignmentDimension aDimension = ap.getAlignmentDimension();
       SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(),
@@ -98,8 +105,11 @@ public class HtmlSvgOutput
       out.write(htmlData.getBytes());
       out.flush();
       out.close();
-
+      if (!(System.getProperty("java.awt.headless") != null && System
+              .getProperty("java.awt.headless").equals("true")))
+      {
       jalview.util.BrowserLauncher.openURL("file:///" + file);
+      }
     } catch (Exception e)
     {
       e.printStackTrace();
@@ -250,15 +260,40 @@ public class HtmlSvgOutput
   private String getHtml(String titleSvg, String alignmentSvg)
   {
     StringBuilder htmlSvg = new StringBuilder();
-    htmlSvg.append("<html><style type=\"text/css\">" + "div.title {"
-            + "height: 100%;" + "width: 9%;" + "float: left;" + "}"
-            + "div.align {" + "height: 100%;" + "width: 91%;"
-            + "overflow: scroll;" + "float: right;" + "}" + "</style>"
-            + "<div style=\"width:100%; height:100%; overflow: hidden\">"
-            + "<div class=\"title\">");
-    htmlSvg.append(titleSvg);
-    htmlSvg.append("</div><div class=\"align\">").append(alignmentSvg);
+    htmlSvg.append("<html>"
+            + "<style type=\"text/css\"> "
+            + "div.parent{ width:100%;<!-- overflow: auto; -->}\n"
+            + "div.titlex{ width:11%; float: left; }\n"
+            + "div.align{ width:89%; float: right; }\n"
+            + ".sub-category-container {overflow-y: scroll; overflow-x: hidden; width: 100%; height: 100%;}\n"
+            + "object {pointer-events: none;}"
+            + "</style>");
+    htmlSvg.append("<div>");
+    htmlSvg.append(
+"<div class=\"titlex\">");
+    htmlSvg.append(
+"<div class=\"sub-category-container\"> ")
+            .append(titleSvg)
+            .append("</div>")
+            .append("</div>\n\n<!-- ========================================================================================== -->\n\n");
+    htmlSvg.append(
+"<div class=\"align\" >");
+    htmlSvg.append(
+            "<div class=\"sub-category-container\"> <div style=\"overflow-x: scroll;\">")
+            .append(alignmentSvg)
+.append("</div></div>")
+            .append("</div>");
     htmlSvg.append("</div>");
+
+    htmlSvg.append("<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js\"></script>\n"
+            + "<script language=\"JavaScript\" type=\"text/javascript\"  src=\"//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js\"></script>\n"
+            + "<script>\n"
+            + "var subCatContainer = $(\".sub-category-container\");\n"
+            + "subCatContainer.scroll(\nfunction() {\n"
+            + "subCatContainer.scrollTop($(this).scrollTop());\n});\n");
+
+    htmlSvg.append("</script></hmtl>");
+
     return htmlSvg.toString();
   }
 }