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