2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.AlignmentI;
24 import jalview.datamodel.SequenceI;
25 import jalview.gui.AlignViewport;
26 import jalview.gui.AlignmentPanel;
27 import jalview.gui.FeatureRenderer;
28 import jalview.gui.SequenceRenderer;
29 import jalview.util.MessageManager;
31 import java.awt.Color;
33 import java.io.PrintWriter;
35 public class HTMLOutput
41 jalview.renderer.seqfeatures.FeatureRenderer fr;
45 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
51 fr = new FeatureRenderer(ap);
52 fr.transferSettings(fr1);
54 JalviewFileChooser chooser = new JalviewFileChooser(
55 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
56 new String[] { "html" }, new String[] { "HTML files" },
59 chooser.setFileView(new JalviewFileView());
60 chooser.setDialogTitle(MessageManager.getString("label.save_as_html"));
61 chooser.setToolTipText(MessageManager.getString("action.save"));
63 int value = chooser.showSaveDialog(null);
65 if (value == JalviewFileChooser.APPROVE_OPTION)
67 String choice = chooser.getSelectedFile().getPath();
68 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
69 .getSelectedFile().getParent());
73 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
75 out.println("<HTML>");
76 out.println("<style type=\"text/css\">");
78 out.print("td {font-family: \"" + av.getFont().getFamily()
79 + "\", \"" + av.getFont().getName() + "\", mono; "
80 + "font-size: " + av.getFont().getSize() + "px; ");
82 if (av.getFont().getStyle() == Font.BOLD)
84 out.print("font-weight: BOLD; ");
87 if (av.getFont().getStyle() == Font.ITALIC)
89 out.print("font-style: italic; ");
92 out.println("text-align: center; }");
95 out.println("</style>");
96 out.println("<BODY>");
98 if (av.getWrapAlignment())
100 drawWrappedAlignment(out);
104 drawUnwrappedAlignment(out);
107 out.println("\n</body>\n</html>");
109 jalview.util.BrowserLauncher.openURL("file:///" + choice);
110 } catch (Exception ex)
112 ex.printStackTrace();
117 void drawUnwrappedAlignment(PrintWriter out)
119 out.println("<table border=\"1\"><tr><td>\n");
120 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
124 AlignmentI alignment = av.getAlignment();
126 // draws the top row, the measure rule
127 out.println("<tr><td colspan=\"6\"></td>");
131 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
133 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
136 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
138 out.println("</tr>");
140 for (i = 0; i < alignment.getHeight(); i++)
142 seq = alignment.getSequenceAt(i);
144 String id = seq.getDisplayId(av.getShowJVSuffix());
146 out.println("<tr><td nowrap>" + id + " </td>");
148 for (int res = 0; res < seq.getLength(); res++)
150 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
152 color = sr.getResidueBoxColour(seq, res);
154 color = fr.findFeatureColour(color, seq, res);
161 if (color.getRGB() < -1)
163 out.println("<td bgcolor=\"#"
164 + jalview.util.Format.getHexString(color) + "\">"
165 + seq.getCharAt(res) + "</td>");
169 out.println("<td>" + seq.getCharAt(res) + "</td>");
173 out.println("</tr>");
177 out.println("</table>");
178 out.println("</td></tr></table>");
181 void drawWrappedAlignment(PrintWriter out)
183 // //////////////////////////////////
184 // / How many sequences and residues can we fit on a printable page?
185 AlignmentI al = av.getAlignment();
191 out.println("<table border=\"1\"><tr><td>\n");
192 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
194 for (int startRes = 0; startRes < al.getWidth(); startRes += av
197 int endRes = startRes + av.getWrappedWidth();
199 if (endRes > al.getWidth())
201 endRes = al.getWidth();
204 if (av.getScaleAboveWrapped())
208 if (av.getScaleLeftWrapped())
210 out.println("<td colspan=\"7\"> </td>");
214 out.println("<td colspan=\"6\"> </td>");
217 for (int i = startRes + 10; i < endRes; i += 10)
219 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
222 out.println("</tr>");
225 int startPos, endPos;
226 for (int s = 0; s < al.getHeight(); s++)
229 seq = al.getSequenceAt(s);
231 startPos = seq.findPosition(startRes);
232 endPos = seq.findPosition(endRes) - 1;
234 String id = seq.getDisplayId(av.getShowJVSuffix());
236 out.println("<td nowrap>" + id + " </td>");
238 if (av.getScaleLeftWrapped())
240 if (startPos > seq.getEnd() || endPos == 0)
242 out.println("<td nowrap> </td>");
246 out.println("<td nowrap>" + startPos + " </td>");
250 for (int res = startRes; res < endRes; res++)
252 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
254 color = sr.getResidueBoxColour(seq, res);
256 color = fr.findFeatureColour(color, seq, res);
263 if (color.getRGB() < -1)
265 out.println("<td bgcolor=\"#"
266 + jalview.util.Format.getHexString(color) + "\">"
267 + seq.getCharAt(res) + "</td>");
271 out.println("<td>" + seq.getCharAt(res) + "</td>");
276 if (av.getScaleRightWrapped()
277 && endRes < startRes + av.getWrappedWidth())
279 out.println("<td colspan=\""
280 + (startRes + av.getWrappedWidth() - endRes) + "\">"
281 + " </td>");
284 if (av.getScaleRightWrapped() && startPos < endPos)
286 out.println("<td nowrap> " + endPos + " </td>");
289 out.println("</tr>");
292 if (endRes < al.getWidth())
294 out.println("<tr><td height=\"5\"></td></tr>");
298 out.println("</table>");
299 out.println("</table>");
302 public static String getImageMapHTML()
307 + "<script language=\"JavaScript\">\n"
308 + "var ns4 = document.layers;\n"
309 + "var ns6 = document.getElementById && !document.all;\n"
310 + "var ie4 = document.all;\n"
313 + "var toolTipSTYLE=\"\";\n"
314 + "function initToolTips()\n"
316 + " if(ns4||ns6||ie4)\n"
318 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
319 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
320 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
321 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
324 + " toolTipSTYLE.visibility = \"visible\";\n"
325 + " toolTipSTYLE.display = \"none\";\n"
327 + " document.onmousemove = moveToMouseLoc;\n"
330 + "function toolTip(msg, fg, bg)\n"
332 + " if(toolTip.arguments.length < 1) // hide\n"
334 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
335 + " else toolTipSTYLE.display = \"none\";\n"
339 + " if(!fg) fg = \"#555555\";\n"
340 + " if(!bg) bg = \"#FFFFFF\";\n"
342 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
343 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
344 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
345 + " '\" size=\"-2\"> ' + msg +\n"
346 + " ' </font></td></table></td></table>';\n"
349 + " toolTipSTYLE.document.write(content);\n"
350 + " toolTipSTYLE.document.close();\n"
351 + " 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");