2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
24 import jalview.datamodel.*;
27 public class HTMLOutput
37 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
43 fr = new FeatureRenderer(ap);
44 fr.transferSettings(fr1);
46 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
47 .getProperty("LAST_DIRECTORY"), new String[]
48 { "html" }, new String[]
49 { "HTML files" }, "HTML files");
51 chooser.setFileView(new JalviewFileView());
52 chooser.setDialogTitle("Save as HTML");
53 chooser.setToolTipText("Save");
55 int value = chooser.showSaveDialog(null);
57 if (value == JalviewFileChooser.APPROVE_OPTION)
59 String choice = chooser.getSelectedFile().getPath();
60 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
61 .getSelectedFile().getParent());
65 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
67 out.println("<HTML>");
68 out.println("<style type=\"text/css\">");
70 out.print("td {font-family: \"" + av.getFont().getFamily()
71 + "\", \"" + av.getFont().getName() + "\", mono; "
72 + "font-size: " + av.getFont().getSize() + "px; ");
74 if (av.getFont().getStyle() == Font.BOLD)
76 out.print("font-weight: BOLD; ");
79 if (av.getFont().getStyle() == Font.ITALIC)
81 out.print("font-style: italic; ");
84 out.println("text-align: center; }");
87 out.println("</style>");
88 out.println("<BODY>");
90 if (av.getWrapAlignment())
92 drawWrappedAlignment(out);
96 drawUnwrappedAlignment(out);
99 out.println("\n</body>\n</html>");
101 jalview.util.BrowserLauncher.openURL("file:///" + choice);
102 } catch (Exception ex)
104 ex.printStackTrace();
109 void drawUnwrappedAlignment(PrintWriter out)
111 out.println("<table border=\"1\"><tr><td>\n");
113 .println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
117 AlignmentI alignment = av.getAlignment();
119 // draws the top row, the measure rule
120 out.println("<tr><td colspan=\"6\"></td>");
124 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
126 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
129 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
131 out.println("</tr>");
133 for (i = 0; i < alignment.getHeight(); i++)
135 seq = alignment.getSequenceAt(i);
137 String id = seq.getDisplayId(av.getShowJVSuffix());
139 out.println("<tr><td nowrap>" + id + " </td>");
141 for (int res = 0; res < seq.getLength(); res++)
143 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
145 color = sr.getResidueBoxColour(seq, res);
147 color = fr.findFeatureColour(color, seq, res);
154 if (color.getRGB() < -1)
156 out.println("<td bgcolor=\"#"
157 + jalview.util.Format.getHexString(color) + "\">"
158 + seq.getCharAt(res) + "</td>");
162 out.println("<td>" + seq.getCharAt(res) + "</td>");
166 out.println("</tr>");
170 out.println("</table>");
171 out.println("</td></tr></table>");
174 void drawWrappedAlignment(PrintWriter out)
176 // //////////////////////////////////
177 // / How many sequences and residues can we fit on a printable page?
178 AlignmentI al = av.getAlignment();
184 out.println("<table border=\"1\"><tr><td>\n");
186 .println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
188 for (int startRes = 0; startRes < al.getWidth(); startRes += av
191 int endRes = startRes + av.getWrappedWidth();
193 if (endRes > al.getWidth())
195 endRes = al.getWidth();
198 if (av.getScaleAboveWrapped())
202 if (av.getScaleLeftWrapped())
204 out.println("<td colspan=\"7\"> </td>");
208 out.println("<td colspan=\"6\"> </td>");
211 for (int i = startRes + 10; i < endRes; i += 10)
213 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
216 out.println("</tr>");
219 int startPos, endPos;
220 for (int s = 0; s < al.getHeight(); s++)
223 seq = al.getSequenceAt(s);
225 startPos = seq.findPosition(startRes);
226 endPos = seq.findPosition(endRes) - 1;
228 String id = seq.getDisplayId(av.getShowJVSuffix());
230 out.println("<td nowrap>" + id + " </td>");
232 if (av.getScaleLeftWrapped())
234 if (startPos > seq.getEnd() || endPos == 0)
236 out.println("<td nowrap> </td>");
240 out.println("<td nowrap>" + startPos + " </td>");
244 for (int res = startRes; res < endRes; res++)
246 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
248 color = sr.getResidueBoxColour(seq, res);
250 color = fr.findFeatureColour(color, seq, res);
257 if (color.getRGB() < -1)
259 out.println("<td bgcolor=\"#"
260 + jalview.util.Format.getHexString(color) + "\">"
261 + seq.getCharAt(res) + "</td>");
265 out.println("<td>" + seq.getCharAt(res) + "</td>");
270 if (av.getScaleRightWrapped()
271 && endRes < startRes + av.getWrappedWidth())
273 out.println("<td colspan=\""
274 + (startRes + av.getWrappedWidth() - endRes) + "\">"
275 + " </td>");
278 if (av.getScaleRightWrapped() && startPos < endPos)
280 out.println("<td nowrap> " + endPos + " </td>");
283 out.println("</tr>");
286 if (endRes < al.getWidth())
288 out.println("<tr><td height=\"5\"></td></tr>");
292 out.println("</table>");
293 out.println("</table>");
296 public static String getImageMapHTML()
301 + "<script language=\"JavaScript\">\n"
302 + "var ns4 = document.layers;\n"
303 + "var ns6 = document.getElementById && !document.all;\n"
304 + "var ie4 = document.all;\n"
307 + "var toolTipSTYLE=\"\";\n"
308 + "function initToolTips()\n"
310 + " if(ns4||ns6||ie4)\n"
312 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
313 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
314 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
315 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
318 + " toolTipSTYLE.visibility = \"visible\";\n"
319 + " toolTipSTYLE.display = \"none\";\n"
321 + " document.onmousemove = moveToMouseLoc;\n"
324 + "function toolTip(msg, fg, bg)\n"
326 + " if(toolTip.arguments.length < 1) // hide\n"
328 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
329 + " else toolTipSTYLE.display = \"none\";\n"
333 + " if(!fg) fg = \"#555555\";\n"
334 + " if(!bg) bg = \"#FFFFFF\";\n"
336 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
337 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
338 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
339 + " '\" size=\"-2\"> ' + msg +\n"
340 + " ' </font></td></table></td></table>';\n"
343 + " toolTipSTYLE.document.write(content);\n"
344 + " toolTipSTYLE.document.close();\n"
345 + " toolTipSTYLE.visibility = \"visible\";\n"
349 + " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
350 + " toolTipSTYLE.display='block'\n"
354 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
355 + " toolTipSTYLE.display='block'\n"
359 + "function moveToMouseLoc(e)\n"
368 + " x = event.x + document.body.scrollLeft;\n"
369 + " y = event.y + document.body.scrollTop;\n"
371 + " toolTipSTYLE.left = x + offsetX;\n"
372 + " toolTipSTYLE.top = y + offsetY;\n"
378 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
379 + "<script language=\"JavaScript\"><!--\n"
380 + "initToolTips(); //--></script>\n");