1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import jalview.bin.Cache; |
24 |
|
import jalview.gui.AlignmentPanel; |
25 |
|
import jalview.gui.LineartOptions; |
26 |
|
import jalview.gui.OOMWarning; |
27 |
|
import jalview.math.AlignmentDimension; |
28 |
|
import jalview.util.MessageManager; |
29 |
|
import jalview.util.dialogrunner.RunResponse; |
30 |
|
|
31 |
|
import java.awt.Graphics; |
32 |
|
import java.awt.print.PrinterException; |
33 |
|
import java.io.File; |
34 |
|
import java.io.FileOutputStream; |
35 |
|
import java.io.IOException; |
36 |
|
import java.util.concurrent.atomic.AtomicBoolean; |
37 |
|
|
38 |
|
import javax.swing.JOptionPane; |
39 |
|
|
40 |
|
import org.jfree.graphics2d.svg.SVGGraphics2D; |
41 |
|
import org.jfree.graphics2d.svg.SVGHints; |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 144 (144) |
Complexity: 27 |
Complexity Density: 0.24 |
|
43 |
|
public class HtmlSvgOutput extends HTMLOutput |
44 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
0 |
public HtmlSvgOutput(AlignmentPanel ap)... |
46 |
|
{ |
47 |
0 |
super(ap); |
48 |
|
} |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
50 |
0 |
@Override... |
51 |
|
public void exportHTML(String outputFile) |
52 |
|
{ |
53 |
0 |
exportStarted(); |
54 |
0 |
try |
55 |
|
{ |
56 |
0 |
if (outputFile == null) |
57 |
|
{ |
58 |
0 |
outputFile = getOutputFile(); |
59 |
0 |
if (outputFile == null) |
60 |
|
{ |
61 |
0 |
setProgressMessage(MessageManager.formatMessage( |
62 |
|
"status.cancelled_image_export_operation", "HTML")); |
63 |
0 |
return; |
64 |
|
} |
65 |
|
} |
66 |
0 |
generatedFile = new File(outputFile); |
67 |
|
} catch (Exception e) |
68 |
|
{ |
69 |
0 |
setProgressMessage(MessageManager |
70 |
|
.formatMessage("info.error_creating_file", "HTML")); |
71 |
0 |
e.printStackTrace(); |
72 |
0 |
return; |
73 |
|
} |
74 |
0 |
new Thread(this).start(); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public int printUnwrapped(int pwidth, int pheight, int pi,... |
78 |
|
Graphics idGraphics, Graphics alignmentGraphics) |
79 |
|
throws PrinterException |
80 |
|
{ |
81 |
0 |
return ap.printUnwrapped(pwidth, pheight, pi, idGraphics, |
82 |
|
alignmentGraphics); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
0 |
public int printWrapped(int pwidth, int pheight, int pi, Graphics... pg)... |
86 |
|
throws PrinterException |
87 |
|
{ |
88 |
0 |
return ap.printWrappedAlignment(pwidth, pheight, pi, pg[0]); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 64 (64) |
Complexity: 6 |
Complexity Density: 0.11 |
|
91 |
0 |
String getHtml(String titleSvg, String alignmentSvg,... |
92 |
|
String jsonData, boolean wrapped) |
93 |
|
{ |
94 |
0 |
StringBuilder htmlSvg = new StringBuilder(); |
95 |
0 |
htmlSvg.append("<html>\n"); |
96 |
0 |
if (jsonData != null) |
97 |
|
{ |
98 |
0 |
htmlSvg.append( |
99 |
|
"<button onclick=\"javascipt:openJalviewUsingCurrentUrl();\">Launch in Jalview</button> "); |
100 |
0 |
htmlSvg.append( |
101 |
|
"<input type=\"submit\" value=\"View raw BioJSON Data\" onclick=\"jQuery.facebox({ div:'#seqData' }); return false;\" />"); |
102 |
0 |
htmlSvg.append( |
103 |
|
"<div style=\"display: none;\" name=\"seqData\" id=\"seqData\" >" |
104 |
|
+ jsonData + "</div>"); |
105 |
0 |
htmlSvg.append("<br/> "); |
106 |
|
} |
107 |
0 |
htmlSvg.append("\n<style type=\"text/css\"> " |
108 |
|
+ "div.parent{ width:100%;<!-- overflow: auto; -->}\n" |
109 |
|
+ "div.titlex{ width:11%; float: left; }\n" |
110 |
|
+ "div.align{ width:89%; float: right; }\n" |
111 |
|
+ "div.main-container{ border: 2px solid blue; border: 2px solid blue; width: 99%; min-height: 99%; }\n" |
112 |
|
+ ".sub-category-container {overflow-y: scroll; overflow-x: hidden; width: 100%; height: 100%;}\n" |
113 |
|
+ "object {pointer-events: none;}"); |
114 |
0 |
if (jsonData != null) |
115 |
|
{ |
116 |
|
|
117 |
0 |
htmlSvg.append( |
118 |
|
"#facebox { position: absolute; top: 0; left: 0; z-index: 100; text-align: left; }\n" |
119 |
|
+ "#facebox .popup{ position:relative; border:3px solid rgba(0,0,0,0); -webkit-border-radius:5px;" |
120 |
|
+ "-moz-border-radius:5px; border-radius:5px; -webkit-box-shadow:0 0 18px rgba(0,0,0,0.4); -moz-box-shadow:0 0 18px rgba(0,0,0,0.4);" |
121 |
|
+ "box-shadow:0 0 18px rgba(0,0,0,0.4); }\n" |
122 |
|
+ "#facebox .content { display:table; width: 98%; padding: 10px; background: #fff; -webkit-border-radius:4px; -moz-border-radius:4px;" |
123 |
|
+ " border-radius:4px; }\n" |
124 |
|
+ "#facebox .content > p:first-child{ margin-top:0; }\n" |
125 |
|
+ "#facebox .content > p:last-child{ margin-bottom:0; }\n" |
126 |
|
+ "#facebox .close{ position:absolute; top:5px; right:5px; padding:2px; background:#fff; }\n" |
127 |
|
+ "#facebox .close img{ opacity:0.3; }\n" |
128 |
|
+ "#facebox .close:hover img{ opacity:1.0; }\n" |
129 |
|
+ "#facebox .loading { text-align: center; }\n" |
130 |
|
+ "#facebox .image { text-align: center;}\n" |
131 |
|
+ "#facebox img { border: 0; margin: 0; }\n" |
132 |
|
+ "#facebox_overlay { position: fixed; top: 0px; left: 0px; height:100%; width:100%; }\n" |
133 |
|
+ ".facebox_hide { z-index:-100; }\n" |
134 |
|
+ ".facebox_overlayBG { background-color: #000; z-index: 99; }"); |
135 |
|
} |
136 |
0 |
htmlSvg.append("</style>"); |
137 |
0 |
if (!wrapped) |
138 |
|
{ |
139 |
0 |
htmlSvg.append("<div class=\"main-container\" \n>"); |
140 |
0 |
htmlSvg.append("<div class=\"titlex\">\n"); |
141 |
0 |
htmlSvg.append("<div class=\"sub-category-container\"> \n"); |
142 |
0 |
htmlSvg.append(titleSvg); |
143 |
0 |
htmlSvg.append("</div>"); |
144 |
0 |
htmlSvg.append( |
145 |
|
"</div>\n\n<!-- ========================================================================================== -->\n\n"); |
146 |
0 |
htmlSvg.append("<div class=\"align\" >"); |
147 |
0 |
htmlSvg.append( |
148 |
|
"<div class=\"sub-category-container\"> <div style=\"overflow-x: scroll;\">") |
149 |
|
.append(alignmentSvg).append("</div></div>").append("</div>"); |
150 |
0 |
htmlSvg.append("</div>"); |
151 |
|
|
152 |
0 |
htmlSvg.append( |
153 |
|
"<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js\"></script>\n" |
154 |
|
+ "<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js\"></script>\n" |
155 |
|
+ "<script>\n" |
156 |
|
+ "var subCatContainer = $(\".sub-category-container\");\n" |
157 |
|
+ "subCatContainer.scroll(\nfunction() {\n" |
158 |
|
+ "subCatContainer.scrollTop($(this).scrollTop());\n});\n"); |
159 |
|
|
160 |
0 |
htmlSvg.append("</script>\n"); |
161 |
|
} |
162 |
|
else |
163 |
|
{ |
164 |
0 |
htmlSvg.append("<div>\n").append(alignmentSvg).append("</div>"); |
165 |
0 |
htmlSvg.append( |
166 |
|
"<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js\"></script>\n" |
167 |
|
+ "<script language=\"JavaScript\" type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js\"></script>\n"); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
0 |
htmlSvg.append("<script language=\"JavaScript\">\n"); |
172 |
0 |
htmlSvg.append("function openJalviewUsingCurrentUrl(){\n"); |
173 |
0 |
htmlSvg.append( |
174 |
|
" var json = JSON.parse(document.getElementById(\"seqData\").innerHTML);\n"); |
175 |
0 |
htmlSvg.append( |
176 |
|
" var jalviewVersion = json['appSettings'].version;\n"); |
177 |
0 |
htmlSvg.append(" var url = json['appSettings'].webStartUrl;\n"); |
178 |
0 |
htmlSvg.append( |
179 |
|
" var myForm = document.createElement(\"form\");\n\n"); |
180 |
0 |
htmlSvg.append(" var heap = document.createElement(\"input\");\n"); |
181 |
0 |
htmlSvg.append(" heap.setAttribute(\"name\", \"jvm-max-heap\") ;\n"); |
182 |
0 |
htmlSvg.append(" heap.setAttribute(\"value\", \"2G\");\n\n"); |
183 |
0 |
htmlSvg.append(" var target = document.createElement(\"input\");\n"); |
184 |
0 |
htmlSvg.append(" target.setAttribute(\"name\", \"open\");\n"); |
185 |
0 |
htmlSvg.append(" target.setAttribute(\"value\", document.URL);\n\n"); |
186 |
0 |
htmlSvg.append( |
187 |
|
" var jvVersion = document.createElement(\"input\");\n"); |
188 |
0 |
htmlSvg.append(" jvVersion.setAttribute(\"name\", \"version\") ;\n"); |
189 |
0 |
htmlSvg.append( |
190 |
|
" jvVersion.setAttribute(\"value\", jalviewVersion);\n\n"); |
191 |
0 |
htmlSvg.append(" myForm.action = url;\n"); |
192 |
0 |
htmlSvg.append(" myForm.appendChild(heap);\n"); |
193 |
0 |
htmlSvg.append(" myForm.appendChild(target);\n"); |
194 |
0 |
htmlSvg.append(" myForm.appendChild(jvVersion);\n"); |
195 |
0 |
htmlSvg.append(" document.body.appendChild(myForm);\n"); |
196 |
0 |
htmlSvg.append(" myForm.submit() ;\n"); |
197 |
0 |
htmlSvg.append(" document.body.removeChild(myForm);\n"); |
198 |
0 |
htmlSvg.append("}\n"); |
199 |
|
|
200 |
0 |
if (jsonData != null) |
201 |
|
{ |
202 |
|
|
203 |
0 |
File faceBoxJsFile = new File("examples/javascript/facebox-1.3.js"); |
204 |
0 |
try |
205 |
|
{ |
206 |
0 |
htmlSvg.append(HTMLOutput.readFileAsString(faceBoxJsFile)); |
207 |
|
} catch (IOException e) |
208 |
|
{ |
209 |
0 |
e.printStackTrace(); |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
0 |
htmlSvg.append("</script>\n"); |
214 |
0 |
htmlSvg.append("</html>"); |
215 |
0 |
return htmlSvg.toString(); |
216 |
|
} |
217 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
0 |
@Override... |
219 |
|
public boolean isEmbedData() |
220 |
|
{ |
221 |
0 |
return Boolean.valueOf( |
222 |
|
jalview.bin.Cache.getDefault("EXPORT_EMBBED_BIOJSON", "true")); |
223 |
|
} |
224 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
0 |
@Override... |
226 |
|
public boolean isLaunchInBrowserAfterExport() |
227 |
|
{ |
228 |
0 |
return true; |
229 |
|
} |
230 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.31 |
|
231 |
0 |
@Override... |
232 |
|
public void run() |
233 |
|
{ |
234 |
0 |
try |
235 |
|
{ |
236 |
0 |
setProgressMessage(null); |
237 |
0 |
setProgressMessage(MessageManager.formatMessage( |
238 |
|
"status.exporting_alignment_as_x_file", getDescription())); |
239 |
|
|
240 |
0 |
String renderStyle = Cache.getDefault("HTML_RENDERING", |
241 |
|
"Prompt each time"); |
242 |
0 |
AtomicBoolean textOption = new AtomicBoolean( |
243 |
|
!"Lineart".equals(renderStyle)); |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
0 |
RunResponse okAction = new RunResponse(JOptionPane.OK_OPTION) |
249 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
250 |
0 |
@Override... |
251 |
|
public void run() |
252 |
|
{ |
253 |
0 |
doOutput(textOption.get()); |
254 |
|
} |
255 |
|
}; |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
0 |
if (renderStyle.equalsIgnoreCase("Prompt each time") && !isHeadless()) |
261 |
|
{ |
262 |
0 |
LineartOptions svgOption = new LineartOptions("HTML", textOption); |
263 |
0 |
svgOption.setResponseAction(new RunResponse(JOptionPane.NO_OPTION) |
264 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
0 |
@Override... |
266 |
|
public void run() |
267 |
|
{ |
268 |
0 |
setProgressMessage(MessageManager.formatMessage( |
269 |
|
"status.cancelled_image_export_operation", |
270 |
|
getDescription())); |
271 |
|
} |
272 |
|
}); |
273 |
0 |
svgOption.setResponseAction(okAction); |
274 |
0 |
svgOption.showDialog(); |
275 |
|
|
276 |
|
} |
277 |
|
else |
278 |
|
{ |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
0 |
doOutput(textOption.get()); |
283 |
|
} |
284 |
|
} catch (OutOfMemoryError err) |
285 |
|
{ |
286 |
0 |
System.out.println("########################\n" + "OUT OF MEMORY " |
287 |
|
+ generatedFile + "\n" + "########################"); |
288 |
0 |
new OOMWarning("Creating Image for " + generatedFile, err); |
289 |
|
} catch (Exception e) |
290 |
|
{ |
291 |
0 |
e.printStackTrace(); |
292 |
0 |
setProgressMessage(MessageManager |
293 |
|
.formatMessage("info.error_creating_file", getDescription())); |
294 |
|
} |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@param |
302 |
|
|
303 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 4 |
Complexity Density: 0.18 |
|
304 |
0 |
protected void doOutput(boolean textCharacters)... |
305 |
|
{ |
306 |
0 |
try |
307 |
|
{ |
308 |
0 |
AlignmentDimension aDimension = ap.getAlignmentDimension(); |
309 |
0 |
SVGGraphics2D idPanelGraphics = new SVGGraphics2D( |
310 |
|
aDimension.getWidth(), aDimension.getHeight()); |
311 |
0 |
SVGGraphics2D alignPanelGraphics = new SVGGraphics2D( |
312 |
|
aDimension.getWidth(), aDimension.getHeight()); |
313 |
0 |
if (!textCharacters) |
314 |
|
{ |
315 |
0 |
idPanelGraphics.setRenderingHint( |
316 |
|
SVGHints.KEY_DRAW_STRING_TYPE, |
317 |
|
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); |
318 |
0 |
alignPanelGraphics.setRenderingHint( |
319 |
|
SVGHints.KEY_DRAW_STRING_TYPE, |
320 |
|
SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); |
321 |
|
} |
322 |
0 |
if (ap.av.getWrapAlignment()) |
323 |
|
{ |
324 |
0 |
printWrapped(aDimension.getWidth(), aDimension.getHeight(), 0, |
325 |
|
alignPanelGraphics); |
326 |
|
} |
327 |
|
else |
328 |
|
{ |
329 |
0 |
printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), |
330 |
|
0, idPanelGraphics, alignPanelGraphics); |
331 |
|
} |
332 |
|
|
333 |
0 |
String idPanelSvgData = idPanelGraphics.getSVGDocument(); |
334 |
0 |
String alignPanelSvgData = alignPanelGraphics.getSVGDocument(); |
335 |
0 |
String jsonData = getBioJSONData(); |
336 |
0 |
String htmlData = getHtml(idPanelSvgData, alignPanelSvgData, |
337 |
|
jsonData, ap.av.getWrapAlignment()); |
338 |
0 |
FileOutputStream out = new FileOutputStream(generatedFile); |
339 |
0 |
out.write(htmlData.getBytes()); |
340 |
0 |
out.flush(); |
341 |
0 |
out.close(); |
342 |
0 |
setProgressMessage(MessageManager |
343 |
|
.formatMessage("status.export_complete", getDescription())); |
344 |
0 |
exportCompleted(); |
345 |
|
} catch (Exception e) |
346 |
|
{ |
347 |
0 |
e.printStackTrace(); |
348 |
0 |
setProgressMessage(MessageManager |
349 |
|
.formatMessage("info.error_creating_file", getDescription())); |
350 |
|
} |
351 |
|
} |
352 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
353 |
0 |
@Override... |
354 |
|
protected String getDescription() |
355 |
|
{ |
356 |
0 |
return "HTML"; |
357 |
|
} |
358 |
|
} |