2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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(AlignViewport av, SequenceRenderer sr, FeatureRenderer fr1)
40 fr = new FeatureRenderer(av);
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>");
143 for (int res = 0; res < seq.getLength(); res++)
145 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
147 color = sr.getResidueBoxColour(seq, res);
149 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())
204 out.println("<td colspan=\"7\"> </td>");
206 out.println("<td colspan=\"6\"> </td>");
209 for (int i = startRes + 10; i < endRes; i += 10)
211 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
214 out.println("</tr>");
217 int startPos, endPos;
218 for (int s = 0; s < al.getHeight(); s++)
221 seq = al.getSequenceAt(s);
223 startPos = seq.findPosition( startRes );
224 endPos = seq.findPosition( endRes )-1;
226 String id = seq.getDisplayId(av.getShowJVSuffix());
228 out.println("<td nowrap>" + id +
229 " </td>");
232 if(av.getScaleLeftWrapped())
234 if(startPos > seq.getEnd() || endPos==0)
235 out.println("<td nowrap> </td>");
237 out.println("<td nowrap>" + startPos +
238 " </td>");
242 for (int res = startRes; res < endRes; res++)
244 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
246 color = sr.getResidueBoxColour(seq, res);
248 color = fr.findFeatureColour(color, seq, res);
253 if (color.getRGB() < -1)
255 r = Integer.toHexString(color.getRed());
262 g = Integer.toHexString(color.getGreen());
269 b = Integer.toHexString(color.getBlue());
276 out.println("<td bgcolor=\"#" + r + g + b + "\">" +
277 seq.getCharAt(res) + "</td>");
281 out.println("<td>" + seq.getCharAt(res) + "</td>");
287 if(av.getScaleRightWrapped() &&
288 endRes < startRes + av.getWrappedWidth())
290 out.println("<td colspan=\""+ (startRes+av.getWrappedWidth()-endRes) +"\">"
291 +" </td>");
295 if(av.getScaleRightWrapped() && startPos<endPos)
297 out.println("<td nowrap> " + endPos +
298 " </td>");
302 out.println("</tr>");
305 if (endRes < al.getWidth())
307 out.println("<tr><td height=\"5\"></td></tr>");
311 out.println("</table>");
312 out.println("</table>");
315 public static String getImageMapHTML()
320 +"<script language=\"JavaScript\">\n"
321 +"var ns4 = document.layers;\n"
322 +"var ns6 = document.getElementById && !document.all;\n"
323 +"var ie4 = document.all;\n"
326 +"var toolTipSTYLE=\"\";\n"
327 +"function initToolTips()\n"
329 +" if(ns4||ns6||ie4)\n"
331 +" if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
332 +" else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
333 +" else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
334 +" if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
337 +" toolTipSTYLE.visibility = \"visible\";\n"
338 +" toolTipSTYLE.display = \"none\";\n"
340 +" document.onmousemove = moveToMouseLoc;\n"
343 +"function toolTip(msg, fg, bg)\n"
345 +" if(toolTip.arguments.length < 1) // hide\n"
347 +" if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
348 +" else toolTipSTYLE.display = \"none\";\n"
352 +" if(!fg) fg = \"#555555\";\n"
353 +" if(!bg) bg = \"#FFFFFF\";\n"
355 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
356 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
357 +" '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
358 +" '\" size=\"-2\"> ' + msg +\n"
359 +" ' </font></td></table></td></table>';\n"
362 +" toolTipSTYLE.document.write(content);\n"
363 +" toolTipSTYLE.document.close();\n"
364 +" toolTipSTYLE.visibility = \"visible\";\n"
368 +" document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
369 +" toolTipSTYLE.display='block'\n"
373 +" document.all(\"toolTipLayer\").innerHTML=content;\n"
374 +" toolTipSTYLE.display='block'\n"
378 +"function moveToMouseLoc(e)\n"
387 +" x = event.x + document.body.scrollLeft;\n"
388 +" y = event.y + document.body.scrollTop;\n"
390 +" toolTipSTYLE.left = x + offsetX;\n"
391 +" toolTipSTYLE.top = y + offsetY;\n"
397 +"<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
398 +"<script language=\"JavaScript\"><!--\n"
399 +"initToolTips(); //--></script>\n");