2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.
27 import jalview.datamodel.*;
29 import jalview.util.MessageManager;
31 public class HTMLOutput
41 public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
47 fr = new FeatureRenderer(ap);
48 fr.transferSettings(fr1);
50 JalviewFileChooser chooser = new JalviewFileChooser(
51 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
52 { "html" }, new String[]
53 { "HTML files" }, "HTML files");
55 chooser.setFileView(new JalviewFileView());
56 chooser.setDialogTitle(MessageManager.getString("label.save_as_html"));
57 chooser.setToolTipText(MessageManager.getString("action.save"));
59 int value = chooser.showSaveDialog(null);
61 if (value == JalviewFileChooser.APPROVE_OPTION)
63 String choice = chooser.getSelectedFile().getPath();
64 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
65 .getSelectedFile().getParent());
69 PrintWriter out = new java.io.PrintWriter(new java.io.FileWriter(
71 out.println("<HTML>");
72 out.println("<style type=\"text/css\">");
74 out.print("td {font-family: \"" + av.getFont().getFamily()
75 + "\", \"" + av.getFont().getName() + "\", mono; "
76 + "font-size: " + av.getFont().getSize() + "px; ");
78 if (av.getFont().getStyle() == Font.BOLD)
80 out.print("font-weight: BOLD; ");
83 if (av.getFont().getStyle() == Font.ITALIC)
85 out.print("font-style: italic; ");
88 out.println("text-align: center; }");
91 out.println("</style>");
92 out.println("<BODY>");
94 if (av.getWrapAlignment())
96 drawWrappedAlignment(out);
100 drawUnwrappedAlignment(out);
103 out.println("\n</body>\n</html>");
105 jalview.util.BrowserLauncher.openURL("file:///" + choice);
106 } catch (Exception ex)
108 ex.printStackTrace();
113 void drawUnwrappedAlignment(PrintWriter out)
115 out.println("<table border=\"1\"><tr><td>\n");
116 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
120 AlignmentI alignment = av.getAlignment();
122 // draws the top row, the measure rule
123 out.println("<tr><td colspan=\"6\"></td>");
127 for (i = 10; i < (alignment.getWidth() - 10); i += 10)
129 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
132 out.println("<td colspan=\"3\"></td><td colspan=\"3\">" + i
134 out.println("</tr>");
136 for (i = 0; i < alignment.getHeight(); i++)
138 seq = alignment.getSequenceAt(i);
140 String id = seq.getDisplayId(av.getShowJVSuffix());
142 out.println("<tr><td nowrap>" + id + " </td>");
144 for (int res = 0; res < seq.getLength(); res++)
146 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
148 color = sr.getResidueBoxColour(seq, res);
150 color = fr.findFeatureColour(color, seq, res);
157 if (color.getRGB() < -1)
159 out.println("<td bgcolor=\"#"
160 + jalview.util.Format.getHexString(color) + "\">"
161 + seq.getCharAt(res) + "</td>");
165 out.println("<td>" + seq.getCharAt(res) + "</td>");
169 out.println("</tr>");
173 out.println("</table>");
174 out.println("</td></tr></table>");
177 void drawWrappedAlignment(PrintWriter out)
179 // //////////////////////////////////
180 // / How many sequences and residues can we fit on a printable page?
181 AlignmentI al = av.getAlignment();
187 out.println("<table border=\"1\"><tr><td>\n");
188 out.println("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
190 for (int startRes = 0; startRes < al.getWidth(); startRes += av
193 int endRes = startRes + av.getWrappedWidth();
195 if (endRes > al.getWidth())
197 endRes = al.getWidth();
200 if (av.getScaleAboveWrapped())
204 if (av.getScaleLeftWrapped())
206 out.println("<td colspan=\"7\"> </td>");
210 out.println("<td colspan=\"6\"> </td>");
213 for (int i = startRes + 10; i < endRes; i += 10)
215 out.println("<td colspan=\"9\">" + i + "<br>|</td><td></td>");
218 out.println("</tr>");
221 int startPos, endPos;
222 for (int s = 0; s < al.getHeight(); s++)
225 seq = al.getSequenceAt(s);
227 startPos = seq.findPosition(startRes);
228 endPos = seq.findPosition(endRes) - 1;
230 String id = seq.getDisplayId(av.getShowJVSuffix());
232 out.println("<td nowrap>" + id + " </td>");
234 if (av.getScaleLeftWrapped())
236 if (startPos > seq.getEnd() || endPos == 0)
238 out.println("<td nowrap> </td>");
242 out.println("<td nowrap>" + startPos + " </td>");
246 for (int res = startRes; res < endRes; res++)
248 if (!jalview.util.Comparison.isGap(seq.getCharAt(res)))
250 color = sr.getResidueBoxColour(seq, res);
252 color = fr.findFeatureColour(color, seq, res);
259 if (color.getRGB() < -1)
261 out.println("<td bgcolor=\"#"
262 + jalview.util.Format.getHexString(color) + "\">"
263 + seq.getCharAt(res) + "</td>");
267 out.println("<td>" + seq.getCharAt(res) + "</td>");
272 if (av.getScaleRightWrapped()
273 && endRes < startRes + av.getWrappedWidth())
275 out.println("<td colspan=\""
276 + (startRes + av.getWrappedWidth() - endRes) + "\">"
277 + " </td>");
280 if (av.getScaleRightWrapped() && startPos < endPos)
282 out.println("<td nowrap> " + endPos + " </td>");
285 out.println("</tr>");
288 if (endRes < al.getWidth())
290 out.println("<tr><td height=\"5\"></td></tr>");
294 out.println("</table>");
295 out.println("</table>");
298 public static String getImageMapHTML()
303 + "<script language=\"JavaScript\">\n"
304 + "var ns4 = document.layers;\n"
305 + "var ns6 = document.getElementById && !document.all;\n"
306 + "var ie4 = document.all;\n"
309 + "var toolTipSTYLE=\"\";\n"
310 + "function initToolTips()\n"
312 + " if(ns4||ns6||ie4)\n"
314 + " if(ns4) toolTipSTYLE = document.toolTipLayer;\n"
315 + " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n"
316 + " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n"
317 + " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n"
320 + " toolTipSTYLE.visibility = \"visible\";\n"
321 + " toolTipSTYLE.display = \"none\";\n"
323 + " document.onmousemove = moveToMouseLoc;\n"
326 + "function toolTip(msg, fg, bg)\n"
328 + " if(toolTip.arguments.length < 1) // hide\n"
330 + " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n"
331 + " else toolTipSTYLE.display = \"none\";\n"
335 + " if(!fg) fg = \"#555555\";\n"
336 + " if(!bg) bg = \"#FFFFFF\";\n"
338 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n"
339 + " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n"
340 + " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n"
341 + " '\" size=\"-2\"> ' + msg +\n"
342 + " ' </font></td></table></td></table>';\n"
345 + " toolTipSTYLE.document.write(content);\n"
346 + " toolTipSTYLE.document.close();\n"
347 + " toolTipSTYLE.visibility = \"visible\";\n"
351 + " document.getElementById(\"toolTipLayer\").innerHTML = content;\n"
352 + " toolTipSTYLE.display='block'\n"
356 + " document.all(\"toolTipLayer\").innerHTML=content;\n"
357 + " toolTipSTYLE.display='block'\n"
361 + "function moveToMouseLoc(e)\n"
370 + " x = event.x + document.body.scrollLeft;\n"
371 + " y = event.y + document.body.scrollTop;\n"
373 + " toolTipSTYLE.left = x + offsetX;\n"
374 + " toolTipSTYLE.top = y + offsetY;\n"
380 + "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n"
381 + "<script language=\"JavaScript\"><!--\n"
382 + "initToolTips(); //--></script>\n");