2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
25 import jalview.datamodel.*;
27 import jalview.util.MessageManager;
29 public class HTMLOutput
39 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
45 fr = new FeatureRenderer(ap);
46 fr.transferSettings(fr1);
48 JalviewFileChooser chooser = new JalviewFileChooser(
49 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
50 { "html" }, new String[]
51 { "HTML files" }, "HTML files");
53 chooser.setFileView(new JalviewFileView());
54 chooser.setDialogTitle("Save as HTML");
55 chooser.setToolTipText(MessageManager.getString("action.save"));
57 int value = chooser.showSaveDialog(null);
59 if (value == JalviewFileChooser.APPROVE_OPTION)
61 String choice = chooser.getSelectedFile().getPath();
62 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
63 .getSelectedFile().getParent());
67 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
69 out.println("<HTML>");
70 out.println("<style type=\"text/css\">");
72 out.print("td {font-family: \"" + av.getFont().getFamily()
73 + "\", \"" + av.getFont().getName() + "\", mono; "
74 + "font-size: " + av.getFont().getSize() + "px; ");
76 if (av.getFont().getStyle() == Font.BOLD)
78 out.print("font-weight: BOLD; ");
81 if (av.getFont().getStyle() == Font.ITALIC)
83 out.print("font-style: italic; ");
86 out.println("text-align: center; }");
89 out.println("</style>");
90 out.println("<BODY>");
92 if (av.getWrapAlignment())
94 drawWrappedAlignment(out);
98 drawUnwrappedAlignment(out);
101 out.println("\n</body>\n</html>");
103 jalview.util.BrowserLauncher.openURL("file:///" + choice);
104 } catch (Exception ex)
106 ex.printStackTrace();
111 void drawUnwrappedAlignment(PrintWriter out)
113 out.println("<table border=\"1\"><tr><td>\n");
114 out.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");
186 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
188 for (int startRes = 0; startRes < al.getWidth(); startRes += av
191 int endRes = startRes + av.getWrappedWidth();
193 if (endRes > al.getWidth())
195 endRes = al.getWidth();
198 if (av.getScaleAboveWrapped())
202 if (av.getScaleLeftWrapped())
204 out.println("<td colspan=\"7\"> </td>");
208 out.println("<td colspan=\"6\"> </td>");
211 for (int i = startRes + 10; i < endRes; i += 10)
213 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
216 out.println("</tr>");
219 int startPos, endPos;
220 for (int s = 0; s < al.getHeight(); s++)
223 seq = al.getSequenceAt(s);
225 startPos = seq.findPosition(startRes);
226 endPos = seq.findPosition(endRes) - 1;
228 String id = seq.getDisplayId(av.getShowJVSuffix());
230 out.println("<td nowrap>" + id + " </td>");
232 if (av.getScaleLeftWrapped())
234 if (startPos > seq.getEnd() || endPos == 0)
236 out.println("<td nowrap> </td>");
240 out.println("<td nowrap>" + startPos + " </td>");
244 for (int res = startRes; res < endRes; res++)
246 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
248 color = sr.getResidueBoxColour(seq, res);
250 color = fr.findFeatureColour(color, seq, res);
257 if (color.getRGB() < -1)
259 out.println("<td bgcolor=\"#"
260 + jalview.util.Format.getHexString(color) + "\">"
261 + seq.getCharAt(res) + "</td>");
265 out.println("<td>" + seq.getCharAt(res) + "</td>");
270 if (av.getScaleRightWrapped()
271 && endRes < startRes + av.getWrappedWidth())
273 out.println("<td colspan=\""
274 + (startRes + av.getWrappedWidth() - endRes) + "\">"
275 + " </td>");
278 if (av.getScaleRightWrapped() && startPos < endPos)
280 out.println("<td nowrap> " + endPos + " </td>");
283 out.println("</tr>");
286 if (endRes < al.getWidth())
288 out.println("<tr><td height=\"5\"></td></tr>");
292 out.println("</table>");
293 out.println("</table>");
296 public static String getImageMapHTML()
301 + "<script language=\"JavaScript\">\n"
302 + "var ns4 = document.layers;\n"
303 + "var ns6 = document.getElementById && !document.all;\n"
304 + "var ie4 = document.all;\n"
307 + "var toolTipSTYLE=\"\";\n"
308 + "function initToolTips()\n"
310 + " if(ns4||ns6||ie4)\n"
312 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
313 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
314 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
315 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
318 + " toolTipSTYLE.visibility = \"visible\";\n"
319 + " toolTipSTYLE.display = \"none\";\n"
321 + " document.onmousemove = moveToMouseLoc;\n"
324 + "function toolTip(msg, fg, bg)\n"
326 + " if(toolTip.arguments.length < 1) // hide\n"
328 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
329 + " else toolTipSTYLE.display = \"none\";\n"
333 + " if(!fg) fg = \"#555555\";\n"
334 + " if(!bg) bg = \"#FFFFFF\";\n"
336 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
337 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
338 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
339 + " '\" size=\"-2\"> ' + msg +\n"
340 + " ' </font></td></table></td></table>';\n"
343 + " toolTipSTYLE.document.write(content);\n"
344 + " toolTipSTYLE.document.close();\n"
345 + " toolTipSTYLE.visibility = \"visible\";\n"
349 + " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
350 + " toolTipSTYLE.display='block'\n"
354 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
355 + " toolTipSTYLE.display='block'\n"
359 + "function moveToMouseLoc(e)\n"
368 + " x = event.x + document.body.scrollLeft;\n"
369 + " y = event.y + document.body.scrollTop;\n"
371 + " toolTipSTYLE.left = x + offsetX;\n"
372 + " toolTipSTYLE.top = y + offsetY;\n"
378 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
379 + "<script language=\"JavaScript\"><!--\n"
380 + "initToolTips(); //--></script>\n");