Sikuli log output to JTextArea

Asked by Nathan Ash-Vie

I've put together a small app for testing an insurance system. I've created a progress form that displays 2 progress bars, one for the progress of the current test and the other to display the progress through the current batch e.g. there might be 112 fields to enter to complete a single test and there might be 500 tests in the batch. All works well but what I would really love to do is add a JTextArea to the progress form that displays the log generated within System.out.println so the user can see exactly which keys are being simulated. Is it possible to switch the output from System.out.println to a JTextArea in this way? If the model doesn't support changing the output does anyone know if it is possible to hook System.out.println and display it's contents in a text area?

Thanks,

Nathan

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Nathan Ash-Vie
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

So you seem to be in Java.

What about using a logger, that provides this feature (I do not know wether it exists though, but I guess it should ;-).

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#2

Oh sorry, yes, using Java.

Will Google loggers, thanks.

Revision history for this message
Nathan Ash-Vie (nathaniel-ash-vie) said :
#3

Really should have Googled it before posting as the solution turns out to be quite simple, extend OutputStream to write to a text area:

public class Log extends OutputStream {

    private final JTextArea textControl;

    public Log(JTextArea control) {
        textControl = control;
    }

    @Override public void write(int b) throws IOException {

        // append the data as characters to the JTextArea control
        textControl.append(String.valueOf((char)b));
    }
}

Then switch the output:

PrintStream out = new PrintStream(new Log(keyLog));
System.setOut(out);

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Ok, found that in parallel.

For running in Java this is a rather easy solution.

Thanks anyway for the triggering idea.
I will implement such a feature into the SikuliX Debug.user feature, so it might be used all over in SikuliX to get selected stuff displayed in a configurable text area.