Search in sources :

Example 1 with PipeListener

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;
}
Also used : PipedWriter(java.io.PipedWriter) JTextArea(javax.swing.JTextArea) ScriptContext(javax.script.ScriptContext) PipeListener(jmri.util.PipeListener) IOException(java.io.IOException) PipedReader(java.io.PipedReader)

Aggregations

IOException (java.io.IOException)1 PipedReader (java.io.PipedReader)1 PipedWriter (java.io.PipedWriter)1 ScriptContext (javax.script.ScriptContext)1 JTextArea (javax.swing.JTextArea)1 PipeListener (jmri.util.PipeListener)1