2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import jalview.datamodel.*;
28 public class HTMLOutput
35 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr, FeatureRenderer fr1)
40 fr = new FeatureRenderer(ap);
41 fr.transferSettings(fr1);
43 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
45 "LAST_DIRECTORY"), new String[]
48 {"HTML files"}, "HTML files");
50 chooser.setFileView(new JalviewFileView());
51 chooser.setDialogTitle("Save as HTML");
52 chooser.setToolTipText("Save");
54 int value = chooser.showSaveDialog(null);
56 if (value == JalviewFileChooser.APPROVE_OPTION)
58 String choice = chooser.getSelectedFile().getPath();
59 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
60 chooser.getSelectedFile().getParent());
64 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
66 out.println("<HTML>");
67 out.println("<style type=\"text/css\">");
69 out.print("td {font-family: \"" + av.getFont().getFamily() +
70 "\", \"" + av.getFont().getName() + "\", mono; " +
71 "font-size: " + av.getFont().getSize() + "px; ");
73 if (av.getFont().getStyle() == Font.BOLD)
75 out.print("font-weight: BOLD; ");
78 if (av.getFont().getStyle() == Font.ITALIC)
80 out.print("font-style: italic; ");
83 out.println("text-align: center; }");
86 out.println("</style>");
87 out.println("<BODY>");
89 if (av.getWrapAlignment())
91 drawWrappedAlignment(out);
95 drawUnwrappedAlignment(out);
98 out.println("\n</body>\n</html>");
100 jalview.util.BrowserLauncher.openURL("file:///" + choice);
104 ex.printStackTrace();
109 void drawUnwrappedAlignment(PrintWriter out)
111 out.println("<table border=\"1\"><tr><td>\n");
113 "<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 +
140 " </td>");
142 for (int res = 0; res < seq.getLength(); res++)
144 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
146 color = sr.getResidueBoxColour(seq, res);
148 color = fr.findFeatureColour(color, seq, res);
155 if (color.getRGB() < -1)
157 out.println("<td bgcolor=\"#" +
158 jalview.util.Format.getHexString(color) + "\">" +
159 seq.getCharAt(res) + "</td>");
163 out.println("<td>" + seq.getCharAt(res) + "</td>");
167 out.println("</tr>");
171 out.println("</table>");
172 out.println("</td></tr></table>");
175 void drawWrappedAlignment(PrintWriter out)
177 ////////////////////////////////////
178 /// How many sequences and residues can we fit on a printable page?
179 AlignmentI al = av.getAlignment();
185 out.println("<table border=\"1\"><tr><td>\n");
187 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
189 for (int startRes = 0; startRes < al.getWidth();
190 startRes += av.getWrappedWidth())
192 int endRes = startRes + av.getWrappedWidth();
194 if (endRes > al.getWidth())
196 endRes = al.getWidth();
199 if (av.getScaleAboveWrapped())
203 if (av.getScaleLeftWrapped())
205 out.println("<td colspan=\"7\"> </td>");
209 out.println("<td colspan=\"6\"> </td>");
212 for (int i = startRes + 10; i < endRes; i += 10)
214 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
217 out.println("</tr>");
220 int startPos, endPos;
221 for (int s = 0; s < al.getHeight(); s++)
224 seq = al.getSequenceAt(s);
226 startPos = seq.findPosition(startRes);
227 endPos = seq.findPosition(endRes) - 1;
229 String id = seq.getDisplayId(av.getShowJVSuffix());
231 out.println("<td nowrap>" + id +
232 " </td>");
234 if (av.getScaleLeftWrapped())
236 if (startPos > seq.getEnd() || endPos == 0)
238 out.println("<td nowrap> </td>");
242 out.println("<td nowrap>" + startPos +
243 " </td>");
247 for (int res = startRes; res < endRes; res++)
249 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
251 color = sr.getResidueBoxColour(seq, res);
253 color = fr.findFeatureColour(color, seq, res);
260 if (color.getRGB() < -1)
262 out.println("<td bgcolor=\"#" +
263 jalview.util.Format.getHexString(color) + "\">" +
264 seq.getCharAt(res) + "</td>");
268 out.println("<td>" + seq.getCharAt(res) + "</td>");
273 if (av.getScaleRightWrapped() &&
274 endRes < startRes + av.getWrappedWidth())
276 out.println("<td colspan=\"" +
277 (startRes + av.getWrappedWidth() - endRes) + "\">"
278 + " </td>");
281 if (av.getScaleRightWrapped() && startPos < endPos)
283 out.println("<td nowrap> " + endPos +
284 " </td>");
287 out.println("</tr>");
290 if (endRes < al.getWidth())
292 out.println("<tr><td height=\"5\"></td></tr>");
296 out.println("</table>");
297 out.println("</table>");
300 public static String getImageMapHTML()
305 + "<script language=\"JavaScript\">\n"
306 + "var ns4 = document.layers;\n"
307 + "var ns6 = document.getElementById && !document.all;\n"
308 + "var ie4 = document.all;\n"
311 + "var toolTipSTYLE=\"\";\n"
312 + "function initToolTips()\n"
314 + " if(ns4||ns6||ie4)\n"
316 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
317 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
318 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
319 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
322 + " toolTipSTYLE.visibility = \"visible\";\n"
323 + " toolTipSTYLE.display = \"none\";\n"
325 + " document.onmousemove = moveToMouseLoc;\n"
328 + "function toolTip(msg, fg, bg)\n"
330 + " if(toolTip.arguments.length < 1) // hide\n"
332 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
333 + " else toolTipSTYLE.display = \"none\";\n"
337 + " if(!fg) fg = \"#555555\";\n"
338 + " if(!bg) bg = \"#FFFFFF\";\n"
340 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
341 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
343 " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
344 + " '\" size=\"-2\"> ' + msg +\n"
345 + " ' </font></td></table></td></table>';\n"
348 + " toolTipSTYLE.document.write(content);\n"
349 + " toolTipSTYLE.document.close();\n"
350 + " toolTipSTYLE.visibility = \"visible\";\n"
355 " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
356 + " toolTipSTYLE.display='block'\n"
360 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
361 + " toolTipSTYLE.display='block'\n"
365 + "function moveToMouseLoc(e)\n"
374 + " x = event.x + document.body.scrollLeft;\n"
375 + " y = event.y + document.body.scrollTop;\n"
377 + " toolTipSTYLE.left = x + offsetX;\n"
378 + " toolTipSTYLE.top = y + offsetY;\n"
384 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
385 + "<script language=\"JavaScript\"><!--\n"
386 + "initToolTips(); //--></script>\n");