2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
25 import jalview.datamodel.*;
\r
26 import jalview.gui.*;
\r
28 public class HTMLOutput
\r
31 SequenceRenderer sr;
\r
35 public HTMLOutput(AlignViewport av, SequenceRenderer sr, FeatureRenderer fr)
\r
41 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
43 "LAST_DIRECTORY"), new String[]
\r
46 {"HTML files"}, "HTML files");
\r
48 chooser.setFileView(new JalviewFileView());
\r
49 chooser.setDialogTitle("Save as HTML");
\r
50 chooser.setToolTipText("Save");
\r
52 int value = chooser.showSaveDialog(null);
\r
54 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
56 String choice = chooser.getSelectedFile().getPath();
\r
57 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
58 chooser.getSelectedFile().getParent());
\r
62 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
\r
64 out.println("<HTML>");
\r
65 out.println("<style type=\"text/css\">");
\r
66 out.println("<!--");
\r
67 out.print("td {font-family: \"" + av.getFont().getFamily() +
\r
68 "\", \"" + av.getFont().getName() + "\", mono; " +
\r
69 "font-size: " + av.getFont().getSize() + "px; ");
\r
71 if (av.getFont().getStyle() == Font.BOLD)
\r
73 out.print("font-weight: BOLD; ");
\r
76 if (av.getFont().getStyle() == Font.ITALIC)
\r
78 out.print("font-style: italic; ");
\r
81 out.println("text-align: center; }");
\r
84 out.println("</style>");
\r
85 out.println("<BODY>");
\r
87 if (av.getWrapAlignment())
\r
89 drawWrappedAlignment(out);
\r
93 drawUnwrappedAlignment(out);
\r
96 out.println("\n</body>\n</html>");
\r
98 jalview.util.BrowserLauncher.openURL("file:///" + choice);
\r
100 catch (Exception ex)
\r
102 ex.printStackTrace();
\r
107 void drawUnwrappedAlignment(PrintWriter out)
\r
109 out.println("<table border=\"1\"><tr><td>\n");
\r
111 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
\r
115 AlignmentI alignment = av.getAlignment();
\r
117 // draws the top row, the measure rule
\r
118 out.println("<tr><td colspan=\"6\"></td>");
\r
122 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
\r
124 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
\r
127 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i +
\r
129 out.println("</tr>");
\r
131 for (i = 0; i < alignment.getHeight(); i++)
\r
133 seq = alignment.getSequenceAt(i);
\r
135 String id = seq.getDisplayId(av.getShowJVSuffix());
\r
137 out.println("<tr><td nowrap>" + id +
\r
138 " </td>");
\r
141 for (int res = 0; res < seq.getLength(); res++)
\r
143 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
\r
145 color = sr.getResidueBoxColour(seq, res);
\r
147 color = fr.findFeatureColour(color, seq, res);
\r
150 color = Color.white;
\r
153 if (color.getRGB() < -1)
\r
155 out.println("<td bgcolor=\"#" +
\r
156 jalview.util.Format.getHexString(color) + "\">" +
\r
157 seq.getCharAt(res) + "</td>");
\r
161 out.println("<td>" + seq.getCharAt(res) + "</td>");
\r
165 out.println("</tr>");
\r
169 out.println("</table>");
\r
170 out.println("</td></tr></table>");
\r
173 void drawWrappedAlignment(PrintWriter out)
\r
175 ////////////////////////////////////
\r
176 /// How many sequences and residues can we fit on a printable page?
\r
177 AlignmentI al = av.getAlignment();
\r
183 out.println("<table border=\"1\"><tr><td>\n");
\r
185 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
\r
187 for (int startRes = 0; startRes < al.getWidth();
\r
188 startRes += av.getWrappedWidth())
\r
190 int endRes = startRes + av.getWrappedWidth();
\r
192 if (endRes > al.getWidth())
\r
194 endRes = al.getWidth();
\r
197 if(av.getScaleAboveWrapped())
\r
199 out.println("<tr>");
\r
201 if (av.getScaleLeftWrapped())
\r
202 out.println("<td colspan=\"7\"> </td>");
\r
204 out.println("<td colspan=\"6\"> </td>");
\r
207 for (int i = startRes + 10; i < endRes; i += 10)
\r
209 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
\r
212 out.println("</tr>");
\r
215 int startPos, endPos;
\r
216 for (int s = 0; s < al.getHeight(); s++)
\r
218 out.println("<tr>");
\r
219 seq = al.getSequenceAt(s);
\r
221 startPos = seq.findPosition( startRes );
\r
222 endPos = seq.findPosition( endRes )-1;
\r
224 String id = seq.getDisplayId(av.getShowJVSuffix());
\r
226 out.println("<td nowrap>" + id +
\r
227 " </td>");
\r
230 if(av.getScaleLeftWrapped())
\r
232 if(startPos > seq.getEnd() || endPos==0)
\r
233 out.println("<td nowrap> </td>");
\r
235 out.println("<td nowrap>" + startPos +
\r
236 " </td>");
\r
240 for (int res = startRes; res < endRes; res++)
\r
242 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
\r
244 color = sr.getResidueBoxColour(seq, res);
\r
246 color = fr.findFeatureColour(color, seq, res);
\r
249 color = Color.white;
\r
251 if (color.getRGB() < -1)
\r
253 r = Integer.toHexString(color.getRed());
\r
255 if (r.length() < 2)
\r
260 g = Integer.toHexString(color.getGreen());
\r
262 if (g.length() < 2)
\r
267 b = Integer.toHexString(color.getBlue());
\r
269 if (b.length() < 2)
\r
274 out.println("<td bgcolor=\"#" + r + g + b + "\">" +
\r
275 seq.getCharAt(res) + "</td>");
\r
279 out.println("<td>" + seq.getCharAt(res) + "</td>");
\r
285 if(av.getScaleRightWrapped() &&
\r
286 endRes < startRes + av.getWrappedWidth())
\r
288 out.println("<td colspan=\""+ (startRes+av.getWrappedWidth()-endRes) +"\">"
\r
289 +" </td>");
\r
293 if(av.getScaleRightWrapped() && startPos<endPos)
\r
295 out.println("<td nowrap> " + endPos +
\r
296 " </td>");
\r
300 out.println("</tr>");
\r
303 if (endRes < al.getWidth())
\r
305 out.println("<tr><td height=\"5\"></td></tr>");
\r
309 out.println("</table>");
\r
310 out.println("</table>");
\r
313 public static String getImageMapHTML()
\r
318 +"<script language=\"JavaScript\">\n"
\r
319 +"var ns4 = document.layers;\n"
\r
320 +"var ns6 = document.getElementById && !document.all;\n"
\r
321 +"var ie4 = document.all;\n"
\r
324 +"var toolTipSTYLE=\"\";\n"
\r
325 +"function initToolTips()\n"
\r
327 +" if(ns4||ns6||ie4)\n"
\r
329 +" if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
\r
330 +" else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
\r
331 +" else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
\r
332 +" if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
\r
335 +" toolTipSTYLE.visibility = \"visible\";\n"
\r
336 +" toolTipSTYLE.display = \"none\";\n"
\r
338 +" document.onmousemove = moveToMouseLoc;\n"
\r
341 +"function toolTip(msg, fg, bg)\n"
\r
343 +" if(toolTip.arguments.length < 1) // hide\n"
\r
345 +" if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
\r
346 +" else toolTipSTYLE.display = \"none\";\n"
\r
350 +" if(!fg) fg = \"#555555\";\n"
\r
351 +" if(!bg) bg = \"#FFFFFF\";\n"
\r
352 +" var content =\n"
\r
353 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
\r
354 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
\r
355 +" '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
\r
356 +" '\" size=\"-2\"> ' + msg +\n"
\r
357 +" ' </font></td></table></td></table>';\n"
\r
360 +" toolTipSTYLE.document.write(content);\n"
\r
361 +" toolTipSTYLE.document.close();\n"
\r
362 +" toolTipSTYLE.visibility = \"visible\";\n"
\r
366 +" document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
\r
367 +" toolTipSTYLE.display='block'\n"
\r
371 +" document.all(\"toolTipLayer\").innerHTML=content;\n"
\r
372 +" toolTipSTYLE.display='block'\n"
\r
376 +"function moveToMouseLoc(e)\n"
\r
385 +" x = event.x + document.body.scrollLeft;\n"
\r
386 +" y = event.y + document.body.scrollTop;\n"
\r
388 +" toolTipSTYLE.left = x + offsetX;\n"
\r
389 +" toolTipSTYLE.top = y + offsetY;\n"
\r
395 +"<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
\r
396 +"<script language=\"JavaScript\"><!--\n"
\r
397 +"initToolTips(); //--></script>\n");
\r