PageRenderTime 31ms CodeModel.GetById 27ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/3.3.0/src/org/getopt/luke/PanelPrintWriter.java

http://luke.googlecode.com/
Java | 45 lines | 36 code | 5 blank | 4 comment | 3 complexity | b1da9cc163a209d8614d3a8165d922dd MD5 | raw file
 1package org.getopt.luke;
 2
 3import java.io.*;
 4
 5public class PanelPrintWriter extends PrintStream {
 6  static ByteArrayOutputStream baos = new ByteArrayOutputStream();
 7  Object panel;
 8  Luke luke;
 9  
10  public PanelPrintWriter(Luke luke, Object panel) {
11    super(baos);
12    baos.reset();
13    // retrieve previous text and separate it
14    String text = luke.getString(panel, "text");
15    if (text != null && text.length() > 0) {
16      try {
17        baos.write(text.getBytes());
18        baos.write('\n');
19        baos.write('\n');
20      } catch (IOException e) {
21        e.printStackTrace();
22      }
23    }
24    this.panel = panel;
25    this.luke = luke;
26  }
27
28  /* (non-Javadoc)
29   * @see java.io.PrintWriter#println(java.lang.String)
30   */
31  @Override
32  public void println(String x) {
33    try {
34      baos.write(x.getBytes());
35      baos.write('\n');
36    } catch (IOException e) {
37      e.printStackTrace();
38    }
39    String text = new String(baos.toByteArray());
40    luke.setString(panel, "text", text);
41    luke.setInteger(panel, "start", text.length());
42    luke.setInteger(panel, "end", text.length());
43  }
44
45}