2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import jalview.datamodel.*;
28 public class HTMLOutput
38 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
44 fr = new FeatureRenderer(ap);
45 fr.transferSettings(fr1);
47 JalviewFileChooser chooser = new JalviewFileChooser(
48 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
49 { "html" }, new String[]
50 { "HTML files" }, "HTML files");
52 chooser.setFileView(new JalviewFileView());
53 chooser.setDialogTitle("Save as HTML");
54 chooser.setToolTipText("Save");
56 int value = chooser.showSaveDialog(null);
58 if (value == JalviewFileChooser.APPROVE_OPTION)
60 String choice = chooser.getSelectedFile().getPath();
61 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
62 .getSelectedFile().getParent());
66 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
68 out.println("<HTML>");
69 out.println("<style type=\"text/css\">");
71 out.print("td {font-family: \"" + av.getFont().getFamily()
72 + "\", \"" + av.getFont().getName() + "\", mono; "
73 + "font-size: " + av.getFont().getSize() + "px; ");
75 if (av.getFont().getStyle() == Font.BOLD)
77 out.print("font-weight: BOLD; ");
80 if (av.getFont().getStyle() == Font.ITALIC)
82 out.print("font-style: italic; ");
85 out.println("text-align: center; }");
88 out.println("</style>");
89 out.println("<BODY>");
91 if (av.getWrapAlignment())
93 drawWrappedAlignment(out);
97 drawUnwrappedAlignment(out);
100 out.println("\n</body>\n</html>");
102 jalview.util.BrowserLauncher.openURL("file:///" + choice);
103 } catch (Exception ex)
105 ex.printStackTrace();
110 void drawUnwrappedAlignment(PrintWriter out)
112 out.println("<table border=\"1\"><tr><td>\n");
113 out.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");
185 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
187 for (int startRes = 0; startRes < al.getWidth(); startRes += av
190 int endRes = startRes + av.getWrappedWidth();
192 if (endRes > al.getWidth())
194 endRes = al.getWidth();
197 if (av.getScaleAboveWrapped())
201 if (av.getScaleLeftWrapped())
203 out.println("<td colspan=\"7\"> </td>");
207 out.println("<td colspan=\"6\"> </td>");
210 for (int i = startRes + 10; i < endRes; i += 10)
212 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
215 out.println("</tr>");
218 int startPos, endPos;
219 for (int s = 0; s < al.getHeight(); s++)
222 seq = al.getSequenceAt(s);
224 startPos = seq.findPosition(startRes);
225 endPos = seq.findPosition(endRes) - 1;
227 String id = seq.getDisplayId(av.getShowJVSuffix());
229 out.println("<td nowrap>" + id + " </td>");
231 if (av.getScaleLeftWrapped())
233 if (startPos > seq.getEnd() || endPos == 0)
235 out.println("<td nowrap> </td>");
239 out.println("<td nowrap>" + startPos + " </td>");
243 for (int res = startRes; res < endRes; res++)
245 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
247 color = sr.getResidueBoxColour(seq, res);
249 color = fr.findFeatureColour(color, seq, res);
256 if (color.getRGB() < -1)
258 out.println("<td bgcolor=\"#"
259 + jalview.util.Format.getHexString(color) + "\">"
260 + seq.getCharAt(res) + "</td>");
264 out.println("<td>" + seq.getCharAt(res) + "</td>");
269 if (av.getScaleRightWrapped()
270 && endRes < startRes + av.getWrappedWidth())
272 out.println("<td colspan=\""
273 + (startRes + av.getWrappedWidth() - endRes) + "\">"
274 + " </td>");
277 if (av.getScaleRightWrapped() && startPos < endPos)
279 out.println("<td nowrap> " + endPos + " </td>");
282 out.println("</tr>");
285 if (endRes < al.getWidth())
287 out.println("<tr><td height=\"5\"></td></tr>");
291 out.println("</table>");
292 out.println("</table>");
295 public static String getImageMapHTML()
300 + "<script language=\"JavaScript\">\n"
301 + "var ns4 = document.layers;\n"
302 + "var ns6 = document.getElementById && !document.all;\n"
303 + "var ie4 = document.all;\n"
306 + "var toolTipSTYLE=\"\";\n"
307 + "function initToolTips()\n"
309 + " if(ns4||ns6||ie4)\n"
311 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
312 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
313 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
314 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
317 + " toolTipSTYLE.visibility = \"visible\";\n"
318 + " toolTipSTYLE.display = \"none\";\n"
320 + " document.onmousemove = moveToMouseLoc;\n"
323 + "function toolTip(msg, fg, bg)\n"
325 + " if(toolTip.arguments.length < 1) // hide\n"
327 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
328 + " else toolTipSTYLE.display = \"none\";\n"
332 + " if(!fg) fg = \"#555555\";\n"
333 + " if(!bg) bg = \"#FFFFFF\";\n"
335 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
336 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
337 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
338 + " '\" size=\"-2\"> ' + msg +\n"
339 + " ' </font></td></table></td></table>';\n"
342 + " toolTipSTYLE.document.write(content);\n"
343 + " toolTipSTYLE.document.close();\n"
344 + " toolTipSTYLE.visibility = \"visible\";\n"
348 + " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
349 + " toolTipSTYLE.display='block'\n"
353 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
354 + " toolTipSTYLE.display='block'\n"
358 + "function moveToMouseLoc(e)\n"
367 + " x = event.x + document.body.scrollLeft;\n"
368 + " y = event.y + document.body.scrollTop;\n"
370 + " toolTipSTYLE.left = x + offsetX;\n"
371 + " toolTipSTYLE.top = y + offsetY;\n"
377 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
378 + "<script language=\"JavaScript\"><!--\n"
379 + "initToolTips(); //--></script>\n");