2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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
38 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
44 fr = new FeatureRenderer(ap);
45 fr.transferSettings(fr1);
47 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
48 .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");
114 .println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
118 AlignmentI alignment = av.getAlignment();
120 // draws the top row, the measure rule
121 out.println("<tr><td colspan=\"6\"></td>");
125 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
127 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
130 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
132 out.println("</tr>");
134 for (i = 0; i < alignment.getHeight(); i++)
136 seq = alignment.getSequenceAt(i);
138 String id = seq.getDisplayId(av.getShowJVSuffix());
140 out.println("<tr><td nowrap>" + id + " </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 .println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
189 for (int startRes = 0; startRes < al.getWidth(); startRes += av
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 + " </td>");
233 if (av.getScaleLeftWrapped())
235 if (startPos > seq.getEnd() || endPos == 0)
237 out.println("<td nowrap> </td>");
241 out.println("<td nowrap>" + startPos + " </td>");
245 for (int res = startRes; res < endRes; res++)
247 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
249 color = sr.getResidueBoxColour(seq, res);
251 color = fr.findFeatureColour(color, seq, res);
258 if (color.getRGB() < -1)
260 out.println("<td bgcolor=\"#"
261 + jalview.util.Format.getHexString(color) + "\">"
262 + seq.getCharAt(res) + "</td>");
266 out.println("<td>" + seq.getCharAt(res) + "</td>");
271 if (av.getScaleRightWrapped()
272 && endRes < startRes + av.getWrappedWidth())
274 out.println("<td colspan=\""
275 + (startRes + av.getWrappedWidth() - endRes) + "\">"
276 + " </td>");
279 if (av.getScaleRightWrapped() && startPos < endPos)
281 out.println("<td nowrap> " + endPos + " </td>");
284 out.println("</tr>");
287 if (endRes < al.getWidth())
289 out.println("<tr><td height=\"5\"></td></tr>");
293 out.println("</table>");
294 out.println("</table>");
297 public static String getImageMapHTML()
302 + "<script language=\"JavaScript\">\n"
303 + "var ns4 = document.layers;\n"
304 + "var ns6 = document.getElementById && !document.all;\n"
305 + "var ie4 = document.all;\n"
308 + "var toolTipSTYLE=\"\";\n"
309 + "function initToolTips()\n"
311 + " if(ns4||ns6||ie4)\n"
313 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
314 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
315 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
316 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
319 + " toolTipSTYLE.visibility = \"visible\";\n"
320 + " toolTipSTYLE.display = \"none\";\n"
322 + " document.onmousemove = moveToMouseLoc;\n"
325 + "function toolTip(msg, fg, bg)\n"
327 + " if(toolTip.arguments.length < 1) // hide\n"
329 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
330 + " else toolTipSTYLE.display = \"none\";\n"
334 + " if(!fg) fg = \"#555555\";\n"
335 + " if(!bg) bg = \"#FFFFFF\";\n"
337 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
338 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
339 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
340 + " '\" size=\"-2\"> ' + msg +\n"
341 + " ' </font></td></table></td></table>';\n"
344 + " toolTipSTYLE.document.write(content);\n"
345 + " toolTipSTYLE.document.close();\n"
346 + " toolTipSTYLE.visibility = \"visible\";\n"
350 + " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
351 + " toolTipSTYLE.display='block'\n"
355 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
356 + " toolTipSTYLE.display='block'\n"
360 + "function moveToMouseLoc(e)\n"
369 + " x = event.x + document.body.scrollLeft;\n"
370 + " y = event.y + document.body.scrollTop;\n"
372 + " toolTipSTYLE.left = x + offsetX;\n"
373 + " toolTipSTYLE.top = y + offsetY;\n"
379 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
380 + "<script language=\"JavaScript\"><!--\n"
381 + "initToolTips(); //--></script>\n");