1
16package org.tp23.gui.widget;
17
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20import java.io.PrintStream;
21
22import javax.swing.JButton;
23import javax.swing.JScrollPane;
24
25
34
35public class SystemOutJTextArea extends JScrollPane{
36
37 private JTextAreaPrintStream stream;
38 private FollowingJTextArea textArea = new FollowingJTextArea();
39
40 public SystemOutJTextArea() {
41 jInit();
42 }
43
44 private void jInit(){
45 this.getViewport().setView(textArea);
46 textArea.setEditable(false);
47 JButton jumpButton = new JButton("");
48 setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
49 setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_ALWAYS);
50 setCorner(this.LOWER_RIGHT_CORNER,jumpButton);
51 jumpButton.addActionListener(new ActionListener(){
52 public void actionPerformed(ActionEvent e) {
53 textArea.setCaretPosition(textArea.getDocument().getLength());
54 }
55 });
56 jumpButton.setToolTipText("Click to jump to the end");
57
58
59 }
60
61 public synchronized PrintStream getOut(){
62 if(stream==null){
63 stream = new JTextAreaPrintStream(textArea);
64 }
65 return stream;
66 }
67 public void setAsSystemErr(){
68 System.setErr(getOut());
69 }
70 public void setAsSystemOut(){
71 System.setOut(getOut());
72 }
73
74
75}
76