+ // and a thread to append text to the textarea
+ textAppender = new Thread(this);
+ textAppender.setDaemon(true);
+ textAppender.start();
+
+ // set icons
+ frame.setIconImages(ChannelProperties.getIconList());
+ }
+
+ private void setChosenLogLevelCombo()
+ {
+ setChosenLogLevelCombo(startingLogLevel);
+ }
+
+ private void setChosenLogLevelCombo(LogLevel setLogLevel)
+ {
+ logLevelCombo.setSelectedItem(setLogLevel);
+ if (!logLevelCombo.getSelectedItem().equals(setLogLevel))
+ {
+ // setLogLevel not (yet) in list
+ if (setLogLevel != null && setLogLevel instanceof LogLevel)
+ {
+ // add new item to list (might be set via .jalview_properties)
+ boolean added = false;
+ for (int i = 0; i < logLevelCombo.getItemCount(); i++)
+ {
+ LogLevel l = logLevelCombo.getItemAt(i);
+ if (l.compareTo(setLogLevel) >= 0)
+ {
+ logLevelCombo.insertItemAt(setLogLevel, i);
+ added = true;
+ break;
+ }
+ }
+ if (!added) // lower priority than others or some confusion -- add to
+ // end of list
+ {
+ logLevelCombo.addItem(setLogLevel);
+ }
+ logLevelCombo.setSelectedItem(setLogLevel);
+ }
+ else
+ {
+ logLevelCombo.setSelectedItem(LogLevel.INFO);
+ }
+ }
+ }
+
+ private void copyConsoleTextToClipboard()
+ {
+ String consoleText = textArea.getText();
+ StringSelection consoleTextSelection = new StringSelection(consoleText);
+ Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
+ cb.setContents(consoleTextSelection, null);
+ }
+
+ PipedOutputStream pout = null, perr = null;
+
+ public void redirectStreams()
+ {
+ if (pout == null)
+ {
+ try
+ {
+ pout = new PipedOutputStream(this.pin);
+ System.setOut(new PrintStream(pout, true));
+ } catch (java.io.IOException io)
+ {
+ textArea.append("Couldn't redirect STDOUT to this console\n"
+ + io.getMessage());
+ io.printStackTrace(stderr);
+ } catch (SecurityException se)
+ {
+ textArea.append("Couldn't redirect STDOUT to this console\n"
+ + se.getMessage());
+ se.printStackTrace(stderr);
+ }
+
+ try
+ {
+ perr = new PipedOutputStream(this.pin2);
+ System.setErr(new PrintStream(perr, true));
+ } catch (java.io.IOException io)
+ {
+ textArea.append("Couldn't redirect STDERR to this console\n"
+ + io.getMessage());
+ io.printStackTrace(stderr);
+ } catch (SecurityException se)
+ {
+ textArea.append("Couldn't redirect STDERR to this console\n"
+ + se.getMessage());
+ se.printStackTrace(stderr);
+ }
+ }
+ }
+
+ public void unredirectStreams()
+ {
+ if (pout != null)
+ {
+ try
+ {
+ System.setOut(stdout);
+ pout.flush();
+ pout.close();
+ pin = new PipedInputStream();
+ pout = null;
+ } catch (java.io.IOException io)
+ {
+ textArea.append("Couldn't unredirect STDOUT to this console\n"
+ + io.getMessage());
+ io.printStackTrace(stderr);
+ } catch (SecurityException se)
+ {
+ textArea.append("Couldn't unredirect STDOUT to this console\n"
+ + se.getMessage());
+ se.printStackTrace(stderr);
+ }
+
+ try
+ {
+ System.setErr(stderr);
+ perr.flush();
+ perr.close();
+ pin2 = new PipedInputStream();
+ perr = null;
+ } catch (java.io.IOException io)
+ {
+ textArea.append("Couldn't unredirect STDERR to this console\n"
+ + io.getMessage());
+ io.printStackTrace(stderr);
+ } catch (SecurityException se)
+ {
+ textArea.append("Couldn't unredirect STDERR to this console\n"
+ + se.getMessage());
+ se.printStackTrace(stderr);
+ }
+ }