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.api.AlignExportSettingsI; |
24 |
|
import jalview.bin.Cache; |
25 |
|
import jalview.datamodel.AlignExportSettingsAdapter; |
26 |
|
import jalview.datamodel.AlignmentExportData; |
27 |
|
import jalview.gui.AlignmentPanel; |
28 |
|
import jalview.gui.IProgressIndicator; |
29 |
|
import jalview.util.MessageManager; |
30 |
|
|
31 |
|
import java.io.BufferedReader; |
32 |
|
import java.io.File; |
33 |
|
import java.io.IOException; |
34 |
|
import java.io.InputStreamReader; |
35 |
|
import java.net.URL; |
36 |
|
import java.util.Objects; |
37 |
|
|
|
|
| 23.4% |
Uncovered Elements: 72 (94) |
Complexity: 27 |
Complexity Density: 0.44 |
|
38 |
|
public abstract class HTMLOutput implements Runnable |
39 |
|
{ |
40 |
|
protected AlignmentPanel ap; |
41 |
|
|
42 |
|
protected long pSessionId; |
43 |
|
|
44 |
|
protected IProgressIndicator pIndicator; |
45 |
|
|
46 |
|
protected File generatedFile; |
47 |
|
|
48 |
|
String _bioJson = null; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
55 |
0 |
public HTMLOutput(AlignmentPanel ap)... |
56 |
|
{ |
57 |
0 |
this.ap = ap; |
58 |
0 |
this.pIndicator = ap.alignFrame; |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@return |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
68 |
0 |
public String getBioJSONData()... |
69 |
|
{ |
70 |
0 |
if (!isEmbedData()) |
71 |
|
{ |
72 |
0 |
return null; |
73 |
|
} |
74 |
0 |
if (_bioJson == null) |
75 |
|
{ |
76 |
0 |
AlignExportSettingsI options = new AlignExportSettingsAdapter(true); |
77 |
0 |
AlignmentExportData exportData = ap.getAlignViewport() |
78 |
|
.getAlignExportData(options); |
79 |
0 |
_bioJson = new FormatAdapter(ap, options).formatSequences( |
80 |
|
FileFormat.Json, exportData.getAlignment(), |
81 |
|
exportData.getOmitHidden(), exportData.getStartEndPostions(), |
82 |
|
ap.getAlignViewport().getAlignment().getHiddenColumns()); |
83 |
|
} |
84 |
|
|
85 |
0 |
return _bioJson; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
|
93 |
|
@return |
94 |
|
@throws |
95 |
|
|
|
|
| 77.8% |
Uncovered Elements: 6 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
96 |
1 |
public static String readFileAsString(File file) throws IOException... |
97 |
|
{ |
98 |
1 |
InputStreamReader isReader = null; |
99 |
1 |
BufferedReader buffReader = null; |
100 |
1 |
StringBuilder sb = new StringBuilder(); |
101 |
1 |
Objects.requireNonNull(file, "File must not be null!"); |
102 |
1 |
@SuppressWarnings("deprecation") |
103 |
|
URL url = file.toURL(); |
104 |
1 |
if (url != null) |
105 |
|
{ |
106 |
1 |
try |
107 |
|
{ |
108 |
1 |
isReader = new InputStreamReader(url.openStream()); |
109 |
1 |
buffReader = new BufferedReader(isReader); |
110 |
1 |
String line; |
111 |
1 |
String lineSeparator = System.getProperty("line.separator"); |
112 |
? |
while ((line = buffReader.readLine()) != null) |
113 |
|
{ |
114 |
9670 |
sb.append(line).append(lineSeparator); |
115 |
|
} |
116 |
|
|
117 |
|
} catch (Exception ex) |
118 |
|
{ |
119 |
0 |
ex.printStackTrace(); |
120 |
|
} finally |
121 |
|
{ |
122 |
1 |
if (isReader != null) |
123 |
|
{ |
124 |
1 |
isReader.close(); |
125 |
|
} |
126 |
|
|
127 |
1 |
if (buffReader != null) |
128 |
|
{ |
129 |
1 |
buffReader.close(); |
130 |
|
} |
131 |
|
} |
132 |
|
} |
133 |
1 |
return sb.toString(); |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
public static String getImageMapHTML()... |
137 |
|
{ |
138 |
0 |
return new String("<html>\n" + "<head>\n" |
139 |
|
+ "<script language=\"JavaScript\">\n" |
140 |
|
+ "var ns4 = document.layers;\n" |
141 |
|
+ "var ns6 = document.getElementById && !document.all;\n" |
142 |
|
+ "var ie4 = document.all;\n" + "offsetX = 0;\n" |
143 |
|
+ "offsetY = 20;\n" + "var toolTipSTYLE=\"\";\n" |
144 |
|
+ "function initToolTips()\n" + "{\n" + " if(ns4||ns6||ie4)\n" |
145 |
|
+ " {\n" |
146 |
|
+ " if(ns4) toolTipSTYLE = document.toolTipLayer;\n" |
147 |
|
+ " else if(ns6) toolTipSTYLE = document.getElementById(\"toolTipLayer\").style;\n" |
148 |
|
+ " else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;\n" |
149 |
|
+ " if(ns4) document.captureEvents(Event.MOUSEMOVE);\n" |
150 |
|
+ " else\n" + " {\n" |
151 |
|
+ " toolTipSTYLE.visibility = \"visible\";\n" |
152 |
|
+ " toolTipSTYLE.display = \"none\";\n" + " }\n" |
153 |
|
+ " document.onmousemove = moveToMouseLoc;\n" + " }\n" |
154 |
|
+ "}\n" + "function toolTip(msg, fg, bg)\n" + "{\n" |
155 |
|
+ " if(toolTip.arguments.length < 1) // hide\n" + " {\n" |
156 |
|
+ " if(ns4) toolTipSTYLE.visibility = \"hidden\";\n" |
157 |
|
+ " else toolTipSTYLE.display = \"none\";\n" + " }\n" |
158 |
|
+ " else // show\n" + " {\n" |
159 |
|
+ " if(!fg) fg = \"#555555\";\n" |
160 |
|
+ " if(!bg) bg = \"#FFFFFF\";\n" + " var content =\n" |
161 |
|
+ " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + fg + '\"><td>' +\n" |
162 |
|
+ " '<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" bgcolor=\"' + bg + \n" |
163 |
|
+ " '\"><td align=\"center\"><font face=\"sans-serif\" color=\"' + fg +\n" |
164 |
|
+ " '\" size=\"-2\"> ' + msg +\n" |
165 |
|
+ " ' </font></td></table></td></table>';\n" |
166 |
|
+ " if(ns4)\n" + " {\n" |
167 |
|
+ " toolTipSTYLE.document.write(content);\n" |
168 |
|
+ " toolTipSTYLE.document.close();\n" |
169 |
|
+ " toolTipSTYLE.visibility = \"visible\";\n" + " }\n" |
170 |
|
+ " if(ns6)\n" + " {\n" |
171 |
|
+ " document.getElementById(\"toolTipLayer\").innerHTML = content;\n" |
172 |
|
+ " toolTipSTYLE.display='block'\n" + " }\n" |
173 |
|
+ " if(ie4)\n" + " {\n" |
174 |
|
+ " document.all(\"toolTipLayer\").innerHTML=content;\n" |
175 |
|
+ " toolTipSTYLE.display='block'\n" + " }\n" + " }\n" |
176 |
|
+ "}\n" + "function moveToMouseLoc(e)\n" + "{\n" |
177 |
|
+ " if(ns4||ns6)\n" + " {\n" + " x = e.pageX;\n" |
178 |
|
+ " y = e.pageY;\n" + " }\n" + " else\n" + " {\n" |
179 |
|
+ " x = event.x + document.body.scrollLeft;\n" |
180 |
|
+ " y = event.y + document.body.scrollTop;\n" + " }\n" |
181 |
|
+ " toolTipSTYLE.left = x + offsetX;\n" |
182 |
|
+ " toolTipSTYLE.top = y + offsetY;\n" + " return true;\n" |
183 |
|
+ "}\n" + "</script>\n" + "</head>\n" + "<body>\n" |
184 |
|
+ "<div id=\"toolTipLayer\" style=\"position:absolute; visibility: hidden\"></div>\n" |
185 |
|
+ "<script language=\"JavaScript\"><!--\n" |
186 |
|
+ "initToolTips(); //--></script>\n"); |
187 |
|
|
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
@return |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
196 |
0 |
public String getOutputFile()... |
197 |
|
{ |
198 |
0 |
String selectedFile = null; |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
0 |
JalviewFileChooser jvFileChooser = new JalviewFileChooser("html", |
203 |
|
"HTML files"); |
204 |
0 |
jvFileChooser.setFileView(new JalviewFileView()); |
205 |
|
|
206 |
0 |
jvFileChooser |
207 |
|
.setDialogTitle(MessageManager.getString("label.save_as_html")); |
208 |
0 |
jvFileChooser.setToolTipText(MessageManager.getString("action.save")); |
209 |
|
|
210 |
0 |
int fileChooserOpt = jvFileChooser.showSaveDialog(null); |
211 |
0 |
if (fileChooserOpt == JalviewFileChooser.APPROVE_OPTION) |
212 |
|
{ |
213 |
0 |
Cache.setProperty("LAST_DIRECTORY", |
214 |
|
jvFileChooser.getSelectedFile().getParent()); |
215 |
0 |
selectedFile = jvFileChooser.getSelectedFile().getPath(); |
216 |
|
} |
217 |
|
|
218 |
0 |
return selectedFile; |
219 |
|
} |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
221 |
0 |
protected void setProgressMessage(String message)... |
222 |
|
{ |
223 |
0 |
if (pIndicator != null && !isHeadless()) |
224 |
|
{ |
225 |
0 |
pIndicator.setProgressBar(message, pSessionId); |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
0 |
System.out.println(message); |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
@return |
237 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
238 |
0 |
protected boolean isHeadless()... |
239 |
|
{ |
240 |
0 |
return System.getProperty("java.awt.headless") != null |
241 |
|
&& System.getProperty("java.awt.headless").equals("true"); |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
249 |
0 |
protected void exportStarted()... |
250 |
|
{ |
251 |
0 |
pSessionId = System.currentTimeMillis(); |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 1 |
|
259 |
0 |
protected void exportCompleted()... |
260 |
|
{ |
261 |
0 |
if (isLaunchInBrowserAfterExport() && !isHeadless()) |
262 |
|
{ |
263 |
0 |
try |
264 |
|
{ |
265 |
0 |
jalview.util.BrowserLauncher |
266 |
|
.openURL("file:///" + getExportedFile()); |
267 |
|
} catch (IOException e) |
268 |
|
{ |
269 |
0 |
e.printStackTrace(); |
270 |
|
} |
271 |
|
} |
272 |
|
} |
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
@return |
279 |
|
|
280 |
|
public abstract boolean isEmbedData(); |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
@return |
287 |
|
|
288 |
|
public abstract boolean isLaunchInBrowserAfterExport(); |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
@return |
294 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
0 |
public File getExportedFile()... |
296 |
|
{ |
297 |
0 |
return generatedFile; |
298 |
|
} |
299 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
300 |
0 |
public void exportHTML(String outputFile)... |
301 |
|
{ |
302 |
0 |
exportStarted(); |
303 |
0 |
try |
304 |
|
{ |
305 |
0 |
if (outputFile == null) |
306 |
|
{ |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
0 |
outputFile = getOutputFile(); |
311 |
0 |
if (outputFile == null) |
312 |
|
{ |
313 |
0 |
setProgressMessage(MessageManager.formatMessage( |
314 |
|
"status.cancelled_image_export_operation", |
315 |
|
getDescription())); |
316 |
0 |
return; |
317 |
|
} |
318 |
|
} |
319 |
0 |
generatedFile = new File(outputFile); |
320 |
|
} catch (Exception e) |
321 |
|
{ |
322 |
0 |
setProgressMessage(MessageManager |
323 |
|
.formatMessage("info.error_creating_file", getDescription())); |
324 |
0 |
e.printStackTrace(); |
325 |
0 |
return; |
326 |
|
} |
327 |
0 |
new Thread(this).start(); |
328 |
|
|
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
@return |
336 |
|
|
337 |
|
protected abstract String getDescription(); |
338 |
|
} |