2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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 fr1)
\r
40 fr = new FeatureRenderer(av);
\r
41 fr.transferSettings(fr1);
\r
43 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
45 "LAST_DIRECTORY"), new String[]
\r
48 {"HTML files"}, "HTML files");
\r
50 chooser.setFileView(new JalviewFileView());
\r
51 chooser.setDialogTitle("Save as HTML");
\r
52 chooser.setToolTipText("Save");
\r
54 int value = chooser.showSaveDialog(null);
\r
56 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
58 String choice = chooser.getSelectedFile().getPath();
\r
59 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
\r
60 chooser.getSelectedFile().getParent());
\r
64 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
\r
66 out.println("<HTML>");
\r
67 out.println("<style type=\"text/css\">");
\r
68 out.println("<!--");
\r
69 out.print("td {font-family: \"" + av.getFont().getFamily() +
\r
70 "\", \"" + av.getFont().getName() + "\", mono; " +
\r
71 "font-size: " + av.getFont().getSize() + "px; ");
\r
73 if (av.getFont().getStyle() == Font.BOLD)
\r
75 out.print("font-weight: BOLD; ");
\r
78 if (av.getFont().getStyle() == Font.ITALIC)
\r
80 out.print("font-style: italic; ");
\r
83 out.println("text-align: center; }");
\r
86 out.println("</style>");
\r
87 out.println("<BODY>");
\r
89 if (av.getWrapAlignment())
\r
91 drawWrappedAlignment(out);
\r
95 drawUnwrappedAlignment(out);
\r
98 out.println("\n</body>\n</html>");
\r
100 jalview.util.BrowserLauncher.openURL("file:///" + choice);
\r
102 catch (Exception ex)
\r
104 ex.printStackTrace();
\r
109 void drawUnwrappedAlignment(PrintWriter out)
\r
111 out.println("<table border=\"1\"><tr><td>\n");
\r
113 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
\r
117 AlignmentI alignment = av.getAlignment();
\r
119 // draws the top row, the measure rule
\r
120 out.println("<tr><td colspan=\"6\"></td>");
\r
124 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
\r
126 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
\r
129 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i +
\r
131 out.println("</tr>");
\r
133 for (i = 0; i < alignment.getHeight(); i++)
\r
135 seq = alignment.getSequenceAt(i);
\r
137 String id = seq.getDisplayId(av.getShowJVSuffix());
\r
139 out.println("<tr><td nowrap>" + id +
\r
140 " </td>");
\r
143 for (int res = 0; res < seq.getLength(); res++)
\r
145 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
\r
147 color = sr.getResidueBoxColour(seq, res);
\r
149 color = fr.findFeatureColour(color, seq, res);
\r
152 color = Color.white;
\r
155 if (color.getRGB() < -1)
\r
157 out.println("<td bgcolor=\"#" +
\r
158 jalview.util.Format.getHexString(color) + "\">" +
\r
159 seq.getCharAt(res) + "</td>");
\r
163 out.println("<td>" + seq.getCharAt(res) + "</td>");
\r
167 out.println("</tr>");
\r
171 out.println("</table>");
\r
172 out.println("</td></tr></table>");
\r
175 void drawWrappedAlignment(PrintWriter out)
\r
177 ////////////////////////////////////
\r
178 /// How many sequences and residues can we fit on a printable page?
\r
179 AlignmentI al = av.getAlignment();
\r
185 out.println("<table border=\"1\"><tr><td>\n");
\r
187 "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
\r
189 for (int startRes = 0; startRes < al.getWidth();
\r
190 startRes += av.getWrappedWidth())
\r
192 int endRes = startRes + av.getWrappedWidth();
\r
194 if (endRes > al.getWidth())
\r
196 endRes = al.getWidth();
\r
199 if(av.getScaleAboveWrapped())
\r
201 out.println("<tr>");
\r
203 if (av.getScaleLeftWrapped())
\r
204 out.println("<td colspan=\"7\"> </td>");
\r
206 out.println("<td colspan=\"6\"> </td>");
\r
209 for (int i = startRes + 10; i < endRes; i += 10)
\r
211 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
\r
214 out.println("</tr>");
\r
217 int startPos, endPos;
\r
218 for (int s = 0; s < al.getHeight(); s++)
\r
220 out.println("<tr>");
\r
221 seq = al.getSequenceAt(s);
\r
223 startPos = seq.findPosition( startRes );
\r
224 endPos = seq.findPosition( endRes )-1;
\r
226 String id = seq.getDisplayId(av.getShowJVSuffix());
\r
228 out.println("<td nowrap>" + id +
\r
229 " </td>");
\r
232 if(av.getScaleLeftWrapped())
\r
234 if(startPos > seq.getEnd() || endPos==0)
\r
235 out.println("<td nowrap> </td>");
\r
237 out.println("<td nowrap>" + startPos +
\r
238 " </td>");
\r
242 for (int res = startRes; res < endRes; res++)
\r
244 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
\r
246 color = sr.getResidueBoxColour(seq, res);
\r
248 color = fr.findFeatureColour(color, seq, res);
\r
251 color = Color.white;
\r
253 if (color.getRGB() < -1)
\r
255 r = Integer.toHexString(color.getRed());
\r
257 if (r.length() < 2)
\r
262 g = Integer.toHexString(color.getGreen());
\r
264 if (g.length() < 2)
\r
269 b = Integer.toHexString(color.getBlue());
\r
271 if (b.length() < 2)
\r
276 out.println("<td bgcolor=\"#" + r + g + b + "\">" +
\r
277 seq.getCharAt(res) + "</td>");
\r
281 out.println("<td>" + seq.getCharAt(res) + "</td>");
\r
287 if(av.getScaleRightWrapped() &&
\r
288 endRes < startRes + av.getWrappedWidth())
\r
290 out.println("<td colspan=\""+ (startRes+av.getWrappedWidth()-endRes) +"\">"
\r
291 +" </td>");
\r
295 if(av.getScaleRightWrapped() && startPos<endPos)
\r
297 out.println("<td nowrap> " + endPos +
\r
298 " </td>");
\r
302 out.println("</tr>");
\r
305 if (endRes < al.getWidth())
\r
307 out.println("<tr><td height=\"5\"></td></tr>");
\r
311 out.println("</table>");
\r
312 out.println("</table>");
\r
315 public static String getImageMapHTML()
\r
320 +"<script language=\"JavaScript\">\n"
\r
321 +"var ns4 = document.layers;\n"
\r
322 +"var ns6 = document.getElementById && !document.all;\n"
\r
323 +"var ie4 = document.all;\n"
\r
326 +"var toolTipSTYLE=\"\";\n"
\r
327 +"function initToolTips()\n"
\r
329 +" if(ns4||ns6||ie4)\n"
\r
331 +" if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
\r
332 +" else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
\r
333 +" else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
\r
334 +" if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
\r
337 +" toolTipSTYLE.visibility = \"visible\";\n"
\r
338 +" toolTipSTYLE.display = \"none\";\n"
\r
340 +" document.onmousemove = moveToMouseLoc;\n"
\r
343 +"function toolTip(msg, fg, bg)\n"
\r
345 +" if(toolTip.arguments.length < 1) // hide\n"
\r
347 +" if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
\r
348 +" else toolTipSTYLE.display = \"none\";\n"
\r
352 +" if(!fg) fg = \"#555555\";\n"
\r
353 +" if(!bg) bg = \"#FFFFFF\";\n"
\r
354 +" var content =\n"
\r
355 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
\r
356 +" '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
\r
357 +" '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
\r
358 +" '\" size=\"-2\"> ' + msg +\n"
\r
359 +" ' </font></td></table></td></table>';\n"
\r
362 +" toolTipSTYLE.document.write(content);\n"
\r
363 +" toolTipSTYLE.document.close();\n"
\r
364 +" toolTipSTYLE.visibility = \"visible\";\n"
\r
368 +" document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
\r
369 +" toolTipSTYLE.display='block'\n"
\r
373 +" document.all(\"toolTipLayer\").innerHTML=content;\n"
\r
374 +" toolTipSTYLE.display='block'\n"
\r
378 +"function moveToMouseLoc(e)\n"
\r
387 +" x = event.x + document.body.scrollLeft;\n"
\r
388 +" y = event.y + document.body.scrollTop;\n"
\r
390 +" toolTipSTYLE.left = x + offsetX;\n"
\r
391 +" toolTipSTYLE.top = y + offsetY;\n"
\r
397 +"<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
\r
398 +"<script language=\"JavaScript\"><!--\n"
\r
399 +"initToolTips(); //--></script>\n");
\r