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