use of jmri.util.PipeListener in project JMRI by JMRI.
the class ScriptOutput method getOutputArea.
/**
* Provide access to the JTextArea containing all ScriptEngine output.
* <P>
* The output JTextArea is not created until this is invoked, so that code
* that doesn't use this feature can run on GUI-less machines.
*
* @return component containing script output
*/
public JTextArea getOutputArea() {
if (output == null) {
try {
// create the output area
output = new JTextArea();
// Add the I/O pipes
PipedWriter pw = new PipedWriter();
ScriptContext context = JmriScriptEngineManager.getDefault().getDefaultContext();
context.setErrorWriter(pw);
context.setWriter(pw);
// ensure the output pipe is read and stored into a
// Swing TextArea data model
PipedReader pr = new PipedReader(pw);
PipeListener pl = new PipeListener(pr, output);
pl.start();
} catch (IOException e) {
log.error("Exception creating script output area", e);
return null;
}
}
return output;
}
Aggregations