Modified for wrapAlignement
authoramwaterhouse <Andrew Waterhouse>
Wed, 2 Feb 2005 17:17:07 +0000 (17:17 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 2 Feb 2005 17:17:07 +0000 (17:17 +0000)
src/jalview/io/HTMLOutput.java

index d15a6e8..b70ba68 100755 (executable)
@@ -11,12 +11,14 @@ import java.util.*;
 \r
 public class HTMLOutput\r
 {\r
-\r
+  AlignViewport av;\r
+  SequenceRenderer sr;\r
+  Color color;\r
 \r
   public HTMLOutput(AlignViewport av)\r
   {\r
-    SequenceRenderer sr = new SequenceRenderer(av);\r
-    Color color;\r
+    this.av = av;\r
+    sr = new SequenceRenderer(av);\r
     JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);\r
     chooser.setDialogTitle("Save as HTML");\r
     chooser.setToolTipText("Save");\r
@@ -45,80 +47,180 @@ public class HTMLOutput
         out.println("-->");\r
         out.println("</style>");\r
         out.println("<BODY>");\r
-        out.println("<table border=\"1\"><tr><td>\n");\r
-        out.println("<table border=\"0\"  cellpadding=\"0\" cellspacing=\"0\">\n");\r
 \r
 \r
-        //////////////\r
-        SequenceGroup [] groups;\r
-        SequenceI seq;\r
-        ColourSchemeI cs = null;\r
-        AlignmentI alignment = av.getAlignment();\r
-        String r,g,b;\r
+        if(av.getWrapAlignment())\r
+           drawWrappedAlignment(out);\r
+        else\r
+           drawUnwrappedAlignment(out);\r
 \r
-      // draws the top row, the measure rule\r
-        out.println("<tr><td colspan=\"6\"></td>");\r
-        int i=0;\r
-        for(i=10; i<alignment.getWidth()-10; i+=10)\r
-          out.println("<td colspan=\"9\">"+i+"<br>|</td><td></td>");\r
+        out.println("\n</body>\n</html>");\r
+        out.close();\r
+        jalview.util.BrowserLauncher.openURL( "file:///"+choice );\r
+      }\r
+      catch(Exception ex){ex.printStackTrace();}\r
+    }\r
+  }\r
 \r
-        out.println("<td colspan=\"3\"></td><td colspan=\"3\">"+i+"<br>|</td>");\r
-        out.println("</tr>");\r
+  void drawUnwrappedAlignment(PrintWriter out)\r
+  {\r
 \r
-        for (i = 0; i < alignment.getHeight(); i++)\r
-        {\r
-          seq = alignment.getSequenceAt(i);\r
-          groups = alignment.findAllGroups( seq );\r
-          out.println("<tr><td nowrap>"+seq.getDisplayId()+"&nbsp;&nbsp;</td>");\r
+    out.println("<table border=\"1\"><tr><td>\n");\r
+    out.println("<table border=\"0\"  cellpadding=\"0\" cellspacing=\"0\">\n");\r
+\r
+\r
+    //////////////\r
+    SequenceGroup [] groups;\r
+    SequenceI seq;\r
+    ColourSchemeI cs = null;\r
+    AlignmentI alignment = av.getAlignment();\r
+    String r,g,b;\r
 \r
+  // draws the top row, the measure rule\r
+    out.println("<tr><td colspan=\"6\"></td>");\r
+    int i=0;\r
+    for(i=10; i<alignment.getWidth()-10; i+=10)\r
+      out.println("<td colspan=\"9\">"+i+"<br>|</td><td></td>");\r
 \r
-          for (int res = 0; res < seq.getLength(); res++)\r
-          {\r
-            cs = av.getGlobalColourScheme();\r
+    out.println("<td colspan=\"3\"></td><td colspan=\"3\">"+i+"<br>|</td>");\r
+    out.println("</tr>");\r
 \r
-            if(groups!=null)\r
+    for (i = 0; i < alignment.getHeight(); i++)\r
+    {\r
+      seq = alignment.getSequenceAt(i);\r
+      groups = alignment.findAllGroups( seq );\r
+      out.println("<tr><td nowrap>"+seq.getDisplayId()+"&nbsp;&nbsp;</td>");\r
+\r
+\r
+      for (int res = 0; res < seq.getLength(); res++)\r
+      {\r
+        cs = av.getGlobalColourScheme();\r
+\r
+        if(groups!=null)\r
+         {\r
+           for (int k = 0; k < groups.length; k++)\r
+             if (groups[k].getStartRes() <= res && groups[k].getEndRes() >= res)\r
              {\r
-               for (int k = 0; k < groups.length; k++)\r
-                 if (groups[k].getStartRes() <= res && groups[k].getEndRes() >= res)\r
+               cs = groups[k].cs;\r
+               break;\r
+             }\r
+         }\r
+\r
+\r
+        color = sr.getResidueBoxColour(cs, seq, res);\r
+\r
+        if(color.getRGB()<-1)\r
+        {\r
+          r = Integer.toHexString(color.getRed());\r
+          if(r.length()<2)\r
+            r = "0"+r;\r
+          g = Integer.toHexString(color.getGreen());\r
+          if(g.length()<2)\r
+            g = "0"+g;\r
+          b = Integer.toHexString(color.getBlue());\r
+          if(b.length()<2)\r
+            b = "0"+b;\r
+          out.println("<td bgcolor=\"#"+ r + g + b + "\">"+seq.getCharAt(res)+"</td>");\r
+        }\r
+        else\r
+          out.println("<td>"+seq.getCharAt(res)+"</td>");\r
+\r
+      }\r
+\r
+      out.println("</tr>");\r
+    }\r
+    //////////////\r
+    out.println("</table>");\r
+    out.println("</td></tr></table>");\r
+\r
+  }\r
+\r
+  void drawWrappedAlignment(PrintWriter out)\r
+  {\r
+     ////////////////////////////////////\r
+     /// How many sequences and residues can we fit on a printable page?\r
+     AlignmentI al = av.getAlignment();\r
+     SequenceGroup [] groups;\r
+     SequenceI seq;\r
+     ColourSchemeI cs = null;\r
+     String r,g,b;\r
+\r
+     out.println("<table border=\"1\"><tr><td>\n");\r
+     out.println("<table border=\"0\"  cellpadding=\"0\" cellspacing=\"0\">\n");\r
+\r
+     for(int startRes=0; startRes<al.getWidth(); startRes+=av.getChunkWidth())\r
+     {\r
+\r
+       int endRes = startRes+av.getChunkWidth();\r
+       if(endRes>al.getWidth())\r
+           endRes = al.getWidth();\r
+\r
+     out.println("<tr>");\r
+     out.println("<td colspan=\"6\">&nbsp;</td>");\r
+     for (int i = startRes+10; i < endRes; i += 10)\r
+       out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");\r
+\r
+    // out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i +\r
+    //             "<br>|</td>");\r
+     out.println("</tr>");\r
+\r
+\r
+\r
+       for (int s = 0; s < al.getHeight(); s++)\r
+       {\r
+         out.println("<tr>");\r
+         seq = al.getSequenceAt(s);\r
+         groups = al.findAllGroups( seq );\r
+         out.println("<td nowrap>"+seq.getDisplayId()+"&nbsp;&nbsp;</td>");\r
+\r
+         for (int res = startRes; res < endRes; res++)\r
+              {\r
+                cs = av.getGlobalColourScheme();\r
+                if(groups!=null)\r
                  {\r
-                   cs = groups[k].cs;\r
-                   break;\r
+                   for (int k = 0; k < groups.length; k++)\r
+                     if (groups[k].getStartRes() <= res && groups[k].getEndRes() >= res)\r
+                     {\r
+                       cs = groups[k].cs;\r
+                       break;\r
+                     }\r
                  }\r
-             }\r
 \r
+                color = sr.getResidueBoxColour(cs, seq, res);\r
 \r
-            color = sr.getResidueBoxColour(cs, seq, res);\r
+                if(color.getRGB()<-1)\r
+                {\r
+                  r = Integer.toHexString(color.getRed());\r
+                  if(r.length()<2)\r
+                    r = "0"+r;\r
+                  g = Integer.toHexString(color.getGreen());\r
+                  if(g.length()<2)\r
+                    g = "0"+g;\r
+                  b = Integer.toHexString(color.getBlue());\r
+                  if(b.length()<2)\r
+                    b = "0"+b;\r
+                  out.println("<td bgcolor=\"#"+ r + g + b + "\">"+seq.getCharAt(res)+"</td>");\r
+                }\r
+                else\r
+                  out.println("<td>"+seq.getCharAt(res)+"</td>");\r
 \r
-            if(color.getRGB()<-1)\r
-            {\r
-              r = Integer.toHexString(color.getRed());\r
-              if(r.length()<2)\r
-                r = "0"+r;\r
-              g = Integer.toHexString(color.getGreen());\r
-              if(g.length()<2)\r
-                g = "0"+g;\r
-              b = Integer.toHexString(color.getBlue());\r
-              if(b.length()<2)\r
-                b = "0"+b;\r
-              out.println("<td bgcolor=\"#"+ r + g + b + "\">"+seq.getCharAt(res)+"</td>");\r
-            }\r
-            else\r
-              out.println("<td>"+seq.getCharAt(res)+"</td>");\r
+              }\r
 \r
-          }\r
+         out.println("</tr>");\r
+\r
+       }\r
+       if(endRes<al.getWidth())\r
+           out.println("<tr><td height=\"5\"></td></tr>");\r
+\r
+\r
+\r
+     }\r
+\r
+    out.println("</table>");\r
+    out.println("</table>");\r
 \r
-          out.println("</tr>");\r
-        }\r
-        //////////////\r
-        out.println("</table>");\r
-        out.println("</td></tr></table>\n</body>\n</html>");\r
 \r
-        out.close();\r
 \r
-        jalview.util.BrowserLauncher.openURL( "file:///"+choice );\r
-      }\r
-      catch(Exception ex){ex.printStackTrace();}\r
-    }\r
   }\r
 \r
 \r