1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.BorderLayout; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.Dimension; |
26 |
|
import java.awt.GraphicsEnvironment; |
27 |
|
import java.awt.GridBagConstraints; |
28 |
|
import java.awt.GridBagLayout; |
29 |
|
import java.awt.Rectangle; |
30 |
|
import java.awt.Toolkit; |
31 |
|
import java.awt.datatransfer.Clipboard; |
32 |
|
import java.awt.datatransfer.StringSelection; |
33 |
|
import java.awt.event.ActionEvent; |
34 |
|
import java.awt.event.ActionListener; |
35 |
|
import java.awt.event.MouseAdapter; |
36 |
|
import java.awt.event.MouseEvent; |
37 |
|
import java.awt.event.WindowAdapter; |
38 |
|
import java.awt.event.WindowEvent; |
39 |
|
import java.awt.event.WindowListener; |
40 |
|
import java.io.IOException; |
41 |
|
import java.io.PipedInputStream; |
42 |
|
import java.io.PipedOutputStream; |
43 |
|
import java.io.PrintStream; |
44 |
|
|
45 |
|
import javax.swing.BorderFactory; |
46 |
|
import javax.swing.JButton; |
47 |
|
import javax.swing.JComboBox; |
48 |
|
import javax.swing.JFrame; |
49 |
|
import javax.swing.JLabel; |
50 |
|
import javax.swing.JPanel; |
51 |
|
import javax.swing.JScrollPane; |
52 |
|
import javax.swing.JTextArea; |
53 |
|
import javax.swing.SwingUtilities; |
54 |
|
import javax.swing.border.Border; |
55 |
|
import javax.swing.text.DefaultCaret; |
56 |
|
|
57 |
|
import jalview.bin.Cache; |
58 |
|
import jalview.log.JLoggerI.LogLevel; |
59 |
|
import jalview.log.JLoggerLog4j; |
60 |
|
import jalview.log.JalviewAppender; |
61 |
|
import jalview.util.ChannelProperties; |
62 |
|
import jalview.util.MessageManager; |
63 |
|
import jalview.util.Platform; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
|
|
| 51.4% |
Uncovered Elements: 216 (444) |
Complexity: 113 |
Complexity Density: 0.37 |
|
74 |
|
public class Console extends WindowAdapter |
75 |
|
implements WindowListener, ActionListener, Runnable |
76 |
|
{ |
77 |
|
private JFrame frame; |
78 |
|
|
79 |
|
private JTextArea textArea; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
int byteslim = 102400, bytescut = 76800; |
87 |
|
|
88 |
|
private Thread reader, reader2, textAppender; |
89 |
|
|
90 |
|
private boolean quit; |
91 |
|
|
92 |
|
private final PrintStream stdout = System.out, stderr = System.err; |
93 |
|
|
94 |
|
private PipedInputStream pin = new PipedInputStream(); |
95 |
|
|
96 |
|
private PipedInputStream pin2 = new PipedInputStream(); |
97 |
|
|
98 |
|
private StringBuffer displayPipe = new StringBuffer(); |
99 |
|
|
100 |
|
Thread errorThrower; |
101 |
|
|
102 |
|
|
103 |
|
Desktop parent = null; |
104 |
|
|
105 |
|
private int MIN_WIDTH = 300; |
106 |
|
|
107 |
|
private int MIN_HEIGHT = 250; |
108 |
|
|
109 |
|
private JComboBox<LogLevel> logLevelCombo = new JComboBox<LogLevel>(); |
110 |
|
|
111 |
|
protected LogLevel startingLogLevel = null; |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
113 |
0 |
public Console()... |
114 |
|
{ |
115 |
|
|
116 |
0 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
117 |
0 |
frame = initFrame("Java Console", screenSize.width / 2, |
118 |
|
screenSize.height / 2, -1, -1); |
119 |
0 |
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
120 |
0 |
initConsole(true); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
75 |
private void initConsole(boolean visible)... |
124 |
|
{ |
125 |
75 |
initConsole(visible, true); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
|
132 |
|
@param |
133 |
|
|
134 |
|
|
|
|
| 94.6% |
Uncovered Elements: 4 (74) |
Complexity: 3 |
Complexity Density: 0.04 |
|
135 |
75 |
private void initConsole(boolean visible, boolean redirect)... |
136 |
|
{ |
137 |
|
|
138 |
|
|
139 |
75 |
textArea = new JTextArea(); |
140 |
75 |
textArea.setEditable(false); |
141 |
|
|
142 |
75 |
DefaultCaret caret = (DefaultCaret) textArea.getCaret(); |
143 |
75 |
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); |
144 |
|
|
145 |
75 |
Border pausedBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, |
146 |
|
textArea.getForeground()); |
147 |
75 |
Border noBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2); |
148 |
75 |
JScrollPane scrollPane = new JScrollPane(textArea); |
149 |
75 |
scrollPane.setBorder(noBorder); |
150 |
75 |
textArea.addMouseListener(new MouseAdapter() |
151 |
|
{ |
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
152 |
0 |
@Override... |
153 |
|
public void mouseClicked(MouseEvent e) |
154 |
|
{ |
155 |
0 |
if (e.getButton() == MouseEvent.BUTTON1) |
156 |
|
{ |
157 |
0 |
if (caret.getUpdatePolicy() == DefaultCaret.ALWAYS_UPDATE) |
158 |
|
{ |
159 |
0 |
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); |
160 |
0 |
scrollPane.setBorder(pausedBorder); |
161 |
|
} |
162 |
|
else |
163 |
|
{ |
164 |
0 |
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); |
165 |
0 |
textArea.setCaretPosition(textArea.getDocument().getLength()); |
166 |
0 |
scrollPane.setBorder(noBorder); |
167 |
|
} |
168 |
|
} |
169 |
|
} |
170 |
|
}); |
171 |
|
|
172 |
75 |
JButton clearButton = new JButton( |
173 |
|
MessageManager.getString("action.clear")); |
174 |
75 |
JButton copyToClipboardButton = new JButton( |
175 |
|
MessageManager.getString("label.copy_to_clipboard")); |
176 |
75 |
copyToClipboardButton.addActionListener(new ActionListener() |
177 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
0 |
@Override... |
179 |
|
public void actionPerformed(ActionEvent e) |
180 |
|
{ |
181 |
0 |
copyConsoleTextToClipboard(); |
182 |
|
} |
183 |
|
}); |
184 |
75 |
copyToClipboardButton.addMouseListener(new MouseAdapter() |
185 |
|
{ |
186 |
|
private Color bg = textArea.getBackground(); |
187 |
|
|
188 |
|
private Color fg = textArea.getForeground(); |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
190 |
0 |
@Override... |
191 |
|
public void mousePressed(MouseEvent e) |
192 |
|
{ |
193 |
0 |
textArea.setBackground(textArea.getSelectionColor()); |
194 |
0 |
textArea.setForeground(textArea.getSelectedTextColor()); |
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
197 |
0 |
@Override... |
198 |
|
public void mouseReleased(MouseEvent e) |
199 |
|
{ |
200 |
0 |
textArea.setBackground(bg); |
201 |
0 |
textArea.setForeground(fg); |
202 |
|
} |
203 |
|
|
204 |
|
}); |
205 |
75 |
copyToClipboardButton.setToolTipText( |
206 |
|
MessageManager.getString("label.copy_to_clipboard_tooltip")); |
207 |
|
|
208 |
75 |
JLabel logLevelLabel = new JLabel( |
209 |
|
MessageManager.getString("label.log_level") + ":"); |
210 |
|
|
211 |
|
|
212 |
75 |
logLevelCombo.addItem(LogLevel.TRACE); |
213 |
75 |
logLevelCombo.addItem(LogLevel.DEBUG); |
214 |
75 |
logLevelCombo.addItem(LogLevel.INFO); |
215 |
75 |
logLevelCombo.addItem(LogLevel.WARN); |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
75 |
if (jalview.bin.Console.getLogger() == null) |
223 |
|
{ |
224 |
0 |
startingLogLevel = jalview.bin.Console.getCachedLogLevel(); |
225 |
|
} |
226 |
|
else |
227 |
|
{ |
228 |
75 |
startingLogLevel = jalview.bin.Console.getLogger().getLevel(); |
229 |
|
} |
230 |
75 |
setChosenLogLevelCombo(); |
231 |
75 |
logLevelCombo.addActionListener(new ActionListener() |
232 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
233 |
0 |
@Override... |
234 |
|
public void actionPerformed(ActionEvent e) |
235 |
|
{ |
236 |
0 |
if (jalview.bin.Console.log != null) |
237 |
|
{ |
238 |
0 |
jalview.bin.Console.log |
239 |
|
.setLevel((LogLevel) logLevelCombo.getSelectedItem()); |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
}); |
244 |
|
|
245 |
|
|
246 |
75 |
frame.getContentPane().setLayout(new BorderLayout()); |
247 |
75 |
frame.getContentPane().add(scrollPane, BorderLayout.CENTER); |
248 |
75 |
JPanel southPanel = new JPanel(); |
249 |
75 |
southPanel.setLayout(new GridBagLayout()); |
250 |
|
|
251 |
75 |
JPanel logLevelPanel = new JPanel(); |
252 |
75 |
logLevelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
253 |
75 |
logLevelPanel.add(logLevelLabel); |
254 |
75 |
logLevelPanel.add(logLevelCombo); |
255 |
75 |
String logLevelTooltip = MessageManager.formatMessage( |
256 |
|
"label.log_level_tooltip", startingLogLevel.toString()); |
257 |
75 |
logLevelLabel.setToolTipText(logLevelTooltip); |
258 |
75 |
logLevelCombo.setToolTipText(logLevelTooltip); |
259 |
|
|
260 |
75 |
GridBagConstraints gbc = new GridBagConstraints(); |
261 |
75 |
gbc.gridx = 0; |
262 |
75 |
gbc.gridy = 0; |
263 |
75 |
gbc.gridwidth = 1; |
264 |
75 |
gbc.gridheight = 1; |
265 |
75 |
gbc.weightx = 0.1; |
266 |
75 |
southPanel.add(logLevelPanel, gbc); |
267 |
|
|
268 |
75 |
gbc.gridx++; |
269 |
75 |
gbc.weightx = 0.8; |
270 |
75 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
271 |
75 |
southPanel.add(clearButton, gbc); |
272 |
|
|
273 |
75 |
gbc.gridx++; |
274 |
75 |
gbc.weightx = 0.1; |
275 |
75 |
gbc.fill = GridBagConstraints.NONE; |
276 |
75 |
southPanel.add(copyToClipboardButton, gbc); |
277 |
|
|
278 |
75 |
southPanel.setVisible(true); |
279 |
75 |
frame.getContentPane().add(southPanel, BorderLayout.SOUTH); |
280 |
75 |
frame.setVisible(visible); |
281 |
75 |
updateConsole = visible; |
282 |
75 |
frame.addWindowListener(this); |
283 |
75 |
clearButton.addActionListener(this); |
284 |
|
|
285 |
75 |
if (redirect) |
286 |
|
{ |
287 |
75 |
redirectStreams(); |
288 |
|
} |
289 |
|
else |
290 |
|
{ |
291 |
0 |
unredirectStreams(); |
292 |
|
} |
293 |
75 |
quit = false; |
294 |
|
|
295 |
|
|
296 |
|
|
297 |
75 |
reader = new Thread(this); |
298 |
75 |
reader.setDaemon(true); |
299 |
75 |
reader.start(); |
300 |
|
|
301 |
75 |
reader2 = new Thread(this); |
302 |
75 |
reader2.setDaemon(true); |
303 |
75 |
reader2.start(); |
304 |
|
|
305 |
75 |
textAppender = new Thread(this); |
306 |
75 |
textAppender.setDaemon(true); |
307 |
75 |
textAppender.start(); |
308 |
|
|
309 |
|
|
310 |
75 |
frame.setIconImages(ChannelProperties.getIconList()); |
311 |
|
} |
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
313 |
75 |
private void setChosenLogLevelCombo()... |
314 |
|
{ |
315 |
75 |
setChosenLogLevelCombo(startingLogLevel); |
316 |
|
} |
317 |
|
|
|
|
| 12.5% |
Uncovered Elements: 21 (24) |
Complexity: 7 |
Complexity Density: 0.5 |
|
318 |
75 |
private void setChosenLogLevelCombo(LogLevel setLogLevel)... |
319 |
|
{ |
320 |
75 |
logLevelCombo.setSelectedItem(setLogLevel); |
321 |
75 |
if (!logLevelCombo.getSelectedItem().equals(setLogLevel)) |
322 |
|
{ |
323 |
|
|
324 |
0 |
if (setLogLevel != null && setLogLevel instanceof LogLevel) |
325 |
|
{ |
326 |
|
|
327 |
0 |
boolean added = false; |
328 |
0 |
for (int i = 0; i < logLevelCombo.getItemCount(); i++) |
329 |
|
{ |
330 |
0 |
LogLevel l = logLevelCombo.getItemAt(i); |
331 |
0 |
if (l.compareTo(setLogLevel) >= 0) |
332 |
|
{ |
333 |
0 |
logLevelCombo.insertItemAt(setLogLevel, i); |
334 |
0 |
added = true; |
335 |
0 |
break; |
336 |
|
} |
337 |
|
} |
338 |
0 |
if (!added) |
339 |
|
|
340 |
|
{ |
341 |
0 |
logLevelCombo.addItem(setLogLevel); |
342 |
|
} |
343 |
0 |
logLevelCombo.setSelectedItem(setLogLevel); |
344 |
|
} |
345 |
|
else |
346 |
|
{ |
347 |
0 |
logLevelCombo.setSelectedItem(LogLevel.INFO); |
348 |
|
} |
349 |
|
} |
350 |
|
} |
351 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
352 |
0 |
private void copyConsoleTextToClipboard()... |
353 |
|
{ |
354 |
0 |
String consoleText = textArea.getText(); |
355 |
0 |
StringSelection consoleTextSelection = new StringSelection(consoleText); |
356 |
0 |
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); |
357 |
0 |
cb.setContents(consoleTextSelection, null); |
358 |
|
} |
359 |
|
|
360 |
|
PipedOutputStream pout = null, perr = null; |
361 |
|
|
|
|
| 47.1% |
Uncovered Elements: 9 (17) |
Complexity: 6 |
Complexity Density: 0.4 |
|
362 |
75 |
public void redirectStreams()... |
363 |
|
{ |
364 |
75 |
if (pout == null) |
365 |
|
{ |
366 |
75 |
try |
367 |
|
{ |
368 |
75 |
pout = new PipedOutputStream(this.pin); |
369 |
75 |
System.setOut(new PrintStream(pout, true)); |
370 |
|
} catch (java.io.IOException io) |
371 |
|
{ |
372 |
0 |
textArea.append("Couldn't redirect STDOUT to this console\n" |
373 |
|
+ io.getMessage()); |
374 |
0 |
io.printStackTrace(stderr); |
375 |
|
} catch (SecurityException se) |
376 |
|
{ |
377 |
0 |
textArea.append("Couldn't redirect STDOUT to this console\n" |
378 |
|
+ se.getMessage()); |
379 |
0 |
se.printStackTrace(stderr); |
380 |
|
} |
381 |
|
|
382 |
75 |
try |
383 |
|
{ |
384 |
75 |
perr = new PipedOutputStream(this.pin2); |
385 |
75 |
System.setErr(new PrintStream(perr, true)); |
386 |
|
} catch (java.io.IOException io) |
387 |
|
{ |
388 |
0 |
textArea.append("Couldn't redirect STDERR to this console\n" |
389 |
|
+ io.getMessage()); |
390 |
0 |
io.printStackTrace(stderr); |
391 |
|
} catch (SecurityException se) |
392 |
|
{ |
393 |
0 |
textArea.append("Couldn't redirect STDERR to this console\n" |
394 |
|
+ se.getMessage()); |
395 |
0 |
se.printStackTrace(stderr); |
396 |
|
} |
397 |
|
} |
398 |
|
} |
399 |
|
|
|
|
| 60.9% |
Uncovered Elements: 9 (23) |
Complexity: 6 |
Complexity Density: 0.29 |
|
400 |
75 |
public void unredirectStreams()... |
401 |
|
{ |
402 |
75 |
if (pout != null) |
403 |
|
{ |
404 |
75 |
try |
405 |
|
{ |
406 |
75 |
System.setOut(stdout); |
407 |
75 |
pout.flush(); |
408 |
75 |
pout.close(); |
409 |
75 |
pin = new PipedInputStream(); |
410 |
75 |
pout = null; |
411 |
|
} catch (java.io.IOException io) |
412 |
|
{ |
413 |
0 |
textArea.append("Couldn't unredirect STDOUT to this console\n" |
414 |
|
+ io.getMessage()); |
415 |
0 |
io.printStackTrace(stderr); |
416 |
|
} catch (SecurityException se) |
417 |
|
{ |
418 |
0 |
textArea.append("Couldn't unredirect STDOUT to this console\n" |
419 |
|
+ se.getMessage()); |
420 |
0 |
se.printStackTrace(stderr); |
421 |
|
} |
422 |
|
|
423 |
75 |
try |
424 |
|
{ |
425 |
75 |
System.setErr(stderr); |
426 |
75 |
perr.flush(); |
427 |
75 |
perr.close(); |
428 |
75 |
pin2 = new PipedInputStream(); |
429 |
75 |
perr = null; |
430 |
|
} catch (java.io.IOException io) |
431 |
|
{ |
432 |
0 |
textArea.append("Couldn't unredirect STDERR to this console\n" |
433 |
|
+ io.getMessage()); |
434 |
0 |
io.printStackTrace(stderr); |
435 |
|
} catch (SecurityException se) |
436 |
|
{ |
437 |
0 |
textArea.append("Couldn't unredirect STDERR to this console\n" |
438 |
|
+ se.getMessage()); |
439 |
0 |
se.printStackTrace(stderr); |
440 |
|
} |
441 |
|
} |
442 |
|
} |
443 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
444 |
0 |
public void test()... |
445 |
|
{ |
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
0 |
jalview.bin.Console.outPrintln("Hello World 2"); |
451 |
0 |
jalview.bin.Console.outPrintln("All fonts available to Graphic2D:\n"); |
452 |
0 |
GraphicsEnvironment ge = GraphicsEnvironment |
453 |
|
.getLocalGraphicsEnvironment(); |
454 |
0 |
String[] fontNames = ge.getAvailableFontFamilyNames(); |
455 |
0 |
for (int n = 0; n < fontNames.length; n++) |
456 |
|
{ |
457 |
0 |
jalview.bin.Console.outPrintln(fontNames[n]); |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
0 |
jalview.bin.Console.outPrintln("\nLets throw an error on this console"); |
464 |
0 |
errorThrower = new Thread(this); |
465 |
0 |
errorThrower.setDaemon(true); |
466 |
0 |
errorThrower.start(); |
467 |
|
} |
468 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
469 |
75 |
private JFrame initFrame(String string, int i, int j, int x, int y)... |
470 |
|
{ |
471 |
75 |
JFrame frame = new JFrame(string); |
472 |
75 |
frame.setName(string); |
473 |
75 |
if (x == -1) |
474 |
|
{ |
475 |
0 |
x = i / 2; |
476 |
|
} |
477 |
75 |
if (y == -1) |
478 |
|
{ |
479 |
0 |
y = j / 2; |
480 |
|
} |
481 |
75 |
frame.setBounds(x, y, i, j); |
482 |
75 |
return frame; |
483 |
|
} |
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
@param |
489 |
|
|
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 9 |
Complexity Density: 0.56 |
|
490 |
75 |
public Console(Desktop desktop)... |
491 |
|
{ |
492 |
75 |
parent = desktop; |
493 |
|
|
494 |
75 |
Rectangle bounds = parent == null ? null |
495 |
|
: parent.getLastKnownDimensions("JAVA_CONSOLE_"); |
496 |
75 |
if (bounds != null) |
497 |
|
{ |
498 |
59 |
frame = initFrame( |
499 |
|
ChannelProperties.getProperty("app_name") + " Java Console", |
500 |
|
bounds.width, bounds.height, bounds.x, bounds.y); |
501 |
|
} |
502 |
16 |
else if (parent != null && parent.getWidth() > 0 |
503 |
|
&& parent.getHeight() > 0) |
504 |
|
{ |
505 |
0 |
frame = initFrame( |
506 |
|
ChannelProperties.getProperty("app_name") + " Java Console", |
507 |
|
parent.getWidth() / 2, parent.getHeight() / 4, parent.getX(), |
508 |
|
parent.getY()); |
509 |
|
} |
510 |
|
else |
511 |
|
{ |
512 |
16 |
frame = initFrame( |
513 |
|
ChannelProperties.getProperty("app_name") + " Java Console", |
514 |
|
MIN_WIDTH, MIN_HEIGHT, 10, 10); |
515 |
|
} |
516 |
75 |
frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); |
517 |
|
|
518 |
75 |
initConsole(false); |
519 |
75 |
LogLevel level = (LogLevel) logLevelCombo.getSelectedItem(); |
520 |
75 |
if (!Platform.isJS()) |
521 |
|
{ |
522 |
75 |
JalviewAppender jappender = new JalviewAppender(level); |
523 |
75 |
JalviewAppender.setTextArea(textArea); |
524 |
75 |
jappender.start(); |
525 |
75 |
if (jalview.bin.Console.log != null |
526 |
|
&& jalview.bin.Console.log instanceof JLoggerLog4j) |
527 |
|
{ |
528 |
75 |
JLoggerLog4j.addAppender(jalview.bin.Console.log, jappender); |
529 |
|
} |
530 |
|
} |
531 |
|
} |
532 |
|
|
|
|
| 25% |
Uncovered Elements: 12 (16) |
Complexity: 5 |
Complexity Density: 0.36 |
|
533 |
81 |
public synchronized void stopConsole()... |
534 |
|
{ |
535 |
81 |
quit = true; |
536 |
81 |
this.notifyAll(); |
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
|
|
542 |
81 |
if (pout != null) |
543 |
|
{ |
544 |
0 |
try |
545 |
|
{ |
546 |
0 |
reader.join(10); |
547 |
0 |
pin.close(); |
548 |
|
} catch (Exception e) |
549 |
|
{ |
550 |
0 |
jalview.bin.Console.debug("pin.close() error", e); |
551 |
|
} |
552 |
0 |
try |
553 |
|
{ |
554 |
0 |
reader2.join(10); |
555 |
0 |
pin2.close(); |
556 |
|
} catch (Exception e) |
557 |
|
{ |
558 |
0 |
jalview.bin.Console.debug("pin2.close() error", e); |
559 |
|
} |
560 |
0 |
try |
561 |
|
{ |
562 |
0 |
textAppender.join(10); |
563 |
|
} catch (Exception e) |
564 |
|
{ |
565 |
0 |
jalview.bin.Console.debug("textAppender.join(10) error", e); |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
} |
576 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
577 |
0 |
@Override... |
578 |
|
public synchronized void windowClosed(WindowEvent evt) |
579 |
|
{ |
580 |
0 |
frame.setVisible(false); |
581 |
0 |
closeConsoleGui(); |
582 |
|
} |
583 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
584 |
0 |
private void closeConsoleGui()... |
585 |
|
{ |
586 |
0 |
updateConsole = false; |
587 |
0 |
if (parent == null) |
588 |
|
{ |
589 |
|
|
590 |
0 |
stopConsole(); |
591 |
|
} |
592 |
|
else |
593 |
|
{ |
594 |
0 |
parent.showConsole(false); |
595 |
|
} |
596 |
|
} |
597 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
598 |
0 |
@Override... |
599 |
|
public synchronized void windowClosing(WindowEvent evt) |
600 |
|
{ |
601 |
0 |
frame.setVisible(false); |
602 |
0 |
closeConsoleGui(); |
603 |
|
|
604 |
|
|
605 |
|
} |
606 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
607 |
0 |
@Override... |
608 |
|
public synchronized void actionPerformed(ActionEvent evt) |
609 |
|
{ |
610 |
0 |
if (getSelectedLogLevel() == LogLevel.DEBUG) |
611 |
|
{ |
612 |
0 |
setHeader(Cache.getVersionDetailsForConsole(true)); |
613 |
|
} |
614 |
0 |
trimBuffer(true); |
615 |
|
|
616 |
|
} |
617 |
|
|
|
|
| 53.5% |
Uncovered Elements: 40 (86) |
Complexity: 24 |
Complexity Density: 0.44 |
|
618 |
225 |
@Override... |
619 |
|
public synchronized void run() |
620 |
|
{ |
621 |
225 |
try |
622 |
|
{ |
623 |
48544 |
while (Thread.currentThread() == reader) |
624 |
|
{ |
625 |
48391 |
if (pin == null || pin.available() == 0) |
626 |
|
{ |
627 |
48398 |
try |
628 |
|
{ |
629 |
48390 |
this.wait(100); |
630 |
|
} catch (InterruptedException ie) |
631 |
|
{ |
632 |
0 |
jalview.bin.Console.debug("pin.available() error", ie); |
633 |
|
} |
634 |
|
} |
635 |
|
|
636 |
48352 |
while (pin.available() != 0) |
637 |
|
{ |
638 |
1 |
String input = this.readLine(pin); |
639 |
1 |
stdout.print(input); |
640 |
1 |
long time = System.nanoTime(); |
641 |
1 |
appendToTextArea(input); |
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
} |
646 |
48357 |
if (quit) |
647 |
|
{ |
648 |
38 |
return; |
649 |
|
} |
650 |
|
} |
651 |
|
|
652 |
48433 |
while (Thread.currentThread() == reader2) |
653 |
|
{ |
654 |
48362 |
if (pin2.available() == 0) |
655 |
|
{ |
656 |
48371 |
try |
657 |
|
{ |
658 |
48373 |
this.wait(100); |
659 |
48323 |
if (pin2.available() == 0) |
660 |
|
{ |
661 |
48326 |
trimBuffer(false); |
662 |
|
} |
663 |
|
} catch (InterruptedException ie) |
664 |
|
{ |
665 |
0 |
jalview.bin.Console.debug("pin.available() error", ie); |
666 |
|
} |
667 |
|
} |
668 |
48323 |
while (pin2.available() != 0) |
669 |
|
{ |
670 |
0 |
String input = this.readLine(pin2); |
671 |
0 |
stderr.print(input); |
672 |
0 |
long time = System.nanoTime(); |
673 |
0 |
appendToTextArea(input); |
674 |
|
|
675 |
|
|
676 |
|
|
677 |
|
} |
678 |
48327 |
if (quit) |
679 |
|
{ |
680 |
38 |
return; |
681 |
|
} |
682 |
|
} |
683 |
48384 |
while (Thread.currentThread() == textAppender) |
684 |
|
{ |
685 |
48384 |
if (updateConsole) |
686 |
|
{ |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
0 |
while (displayPipe.length() > 0) |
691 |
|
{ |
692 |
0 |
StringBuffer tmp = new StringBuffer(), replace; |
693 |
0 |
synchronized (displayPipe) |
694 |
|
{ |
695 |
0 |
replace = displayPipe; |
696 |
0 |
displayPipe = tmp; |
697 |
|
} |
698 |
|
|
699 |
0 |
SwingUtilities.invokeLater(new Runnable() |
700 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
701 |
0 |
@Override... |
702 |
|
public void run() |
703 |
|
{ |
704 |
0 |
textArea.append(replace.toString()); |
705 |
0 |
trimBuffer(false); |
706 |
|
} |
707 |
|
}); |
708 |
|
} |
709 |
0 |
if (displayPipe.length() == 0) |
710 |
|
{ |
711 |
0 |
try |
712 |
|
{ |
713 |
0 |
this.wait(100); |
714 |
0 |
if (displayPipe.length() == 0) |
715 |
|
{ |
716 |
|
|
717 |
0 |
SwingUtilities.invokeLater(new Runnable() |
718 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
719 |
0 |
@Override... |
720 |
|
public void run() |
721 |
|
{ |
722 |
0 |
trimBuffer(false); |
723 |
|
} |
724 |
|
}); |
725 |
|
} |
726 |
|
} catch (InterruptedException e) |
727 |
|
{ |
728 |
0 |
jalview.bin.Console.debug("displayPipe.length() error", e); |
729 |
|
} |
730 |
|
} |
731 |
|
} |
732 |
|
else |
733 |
|
{ |
734 |
48383 |
try |
735 |
|
{ |
736 |
48394 |
this.wait(100); |
737 |
|
} catch (InterruptedException e) |
738 |
|
{ |
739 |
0 |
jalview.bin.Console.debug("this.wait(100) error", e); |
740 |
|
} |
741 |
|
} |
742 |
48347 |
if (quit) |
743 |
|
{ |
744 |
38 |
return; |
745 |
|
} |
746 |
|
|
747 |
|
} |
748 |
|
} catch (Exception e) |
749 |
|
{ |
750 |
0 |
textArea.append("\nConsole reports an Internal error."); |
751 |
0 |
textArea.append("The error is: " + e.getMessage()); |
752 |
|
|
753 |
|
|
754 |
0 |
stderr.println( |
755 |
|
"Console reports an Internal error.\nThe error is: " + e); |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
0 |
if (Thread.currentThread() == errorThrower) |
760 |
|
{ |
761 |
0 |
try |
762 |
|
{ |
763 |
0 |
this.wait(1000); |
764 |
|
} catch (InterruptedException ie) |
765 |
|
{ |
766 |
0 |
jalview.bin.Console.debug("this.wait(1000) error", ie); |
767 |
|
} |
768 |
0 |
throw new NullPointerException( |
769 |
|
MessageManager.getString("exception.application_test_npe")); |
770 |
|
} |
771 |
|
} |
772 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
773 |
1 |
private void appendToTextArea(final String input)... |
774 |
|
{ |
775 |
1 |
if (updateConsole == false) |
776 |
|
{ |
777 |
|
|
778 |
1 |
return; |
779 |
|
} |
780 |
0 |
long time = System.nanoTime(); |
781 |
0 |
javax.swing.SwingUtilities.invokeLater(new Runnable() |
782 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
783 |
0 |
@Override... |
784 |
|
public void run() |
785 |
|
{ |
786 |
0 |
displayPipe.append(input); |
787 |
|
} |
788 |
|
}); |
789 |
|
|
790 |
|
|
791 |
|
|
792 |
|
} |
793 |
|
|
794 |
|
private String header = null; |
795 |
|
|
796 |
|
private boolean updateConsole = false; |
797 |
|
|
|
|
| 33.3% |
Uncovered Elements: 14 (21) |
Complexity: 9 |
Complexity Density: 0.69 |
|
798 |
48310 |
private synchronized void trimBuffer(boolean clear)... |
799 |
|
{ |
800 |
48327 |
if (header == null && textArea.getLineCount() > 5) |
801 |
|
{ |
802 |
0 |
try |
803 |
|
{ |
804 |
0 |
header = textArea.getText(0, textArea.getLineStartOffset(5)) |
805 |
|
+ "\nTruncated...\n"; |
806 |
|
} catch (Exception e) |
807 |
|
{ |
808 |
0 |
jalview.bin.Console.warn("textArea Exception", e); |
809 |
|
} |
810 |
|
} |
811 |
|
|
812 |
48325 |
int tlength = textArea.getDocument().getLength(); |
813 |
48331 |
if (header != null) |
814 |
|
{ |
815 |
48337 |
if (clear || (tlength > byteslim)) |
816 |
|
{ |
817 |
0 |
try |
818 |
|
{ |
819 |
0 |
if (!clear) |
820 |
|
{ |
821 |
0 |
long time = System.nanoTime(); |
822 |
0 |
textArea.replaceRange(header, 0, tlength - bytescut); |
823 |
|
|
824 |
|
|
825 |
|
} |
826 |
|
else |
827 |
|
{ |
828 |
0 |
textArea.setText(header); |
829 |
|
} |
830 |
|
} catch (Exception e) |
831 |
|
{ |
832 |
0 |
jalview.bin.Console.warn("textArea Exception", e); |
833 |
|
} |
834 |
|
|
835 |
|
} |
836 |
|
} |
837 |
|
|
838 |
|
} |
839 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
840 |
1 |
public synchronized String readLine(PipedInputStream in)... |
841 |
|
throws IOException |
842 |
|
{ |
843 |
1 |
String input = ""; |
844 |
1 |
int lp = -1; |
845 |
1 |
do |
846 |
|
{ |
847 |
1 |
int available = in.available(); |
848 |
1 |
if (available == 0) |
849 |
|
{ |
850 |
0 |
break; |
851 |
|
} |
852 |
1 |
byte b[] = new byte[available]; |
853 |
1 |
in.read(b); |
854 |
1 |
input = input + new String(b, 0, b.length); |
855 |
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
|
860 |
1 |
} while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit); |
861 |
1 |
return input; |
862 |
|
} |
863 |
|
|
864 |
|
|
865 |
|
|
866 |
|
@param |
867 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
868 |
0 |
public static void main(String[] arg)... |
869 |
|
{ |
870 |
0 |
new Console().test(); |
871 |
|
|
872 |
|
} |
873 |
|
|
|
|
| 57.1% |
Uncovered Elements: 6 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
874 |
75 |
public void setVisible(boolean selected)... |
875 |
|
{ |
876 |
75 |
frame.setVisible(selected); |
877 |
75 |
if (selected == true) |
878 |
|
{ |
879 |
0 |
setChosenLogLevelCombo(); |
880 |
0 |
redirectStreams(); |
881 |
0 |
updateConsole = true; |
882 |
0 |
frame.toFront(); |
883 |
|
} |
884 |
|
else |
885 |
|
{ |
886 |
|
|
887 |
75 |
if (jalview.bin.Console.log != null) |
888 |
|
{ |
889 |
75 |
jalview.bin.Console.log.setLevel(startingLogLevel); |
890 |
|
} |
891 |
|
|
892 |
75 |
unredirectStreams(); |
893 |
75 |
updateConsole = false; |
894 |
|
} |
895 |
|
} |
896 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
897 |
81 |
public Rectangle getBounds()... |
898 |
|
{ |
899 |
81 |
if (frame != null) |
900 |
|
{ |
901 |
81 |
return frame.getBounds(); |
902 |
|
} |
903 |
0 |
return null; |
904 |
|
} |
905 |
|
|
906 |
|
|
907 |
|
|
908 |
|
|
909 |
|
@param |
910 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
911 |
75 |
public void setHeader(String string)... |
912 |
|
{ |
913 |
75 |
header = string; |
914 |
75 |
if (header.charAt(header.length() - 1) != '\n') |
915 |
|
{ |
916 |
0 |
header += "\n"; |
917 |
|
} |
918 |
75 |
textArea.insert(header, 0); |
919 |
|
} |
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
|
924 |
|
@return |
925 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
926 |
0 |
public String getHeader()... |
927 |
|
{ |
928 |
0 |
return header; |
929 |
|
} |
930 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
931 |
0 |
public LogLevel getSelectedLogLevel()... |
932 |
|
{ |
933 |
0 |
return logLevelCombo == null ? null |
934 |
|
: (LogLevel) logLevelCombo.getSelectedItem(); |
935 |
|
} |
936 |
|
} |