1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.xmlhammer.gui.output;
23
24 import java.awt.BorderLayout;
25 import java.awt.Font;
26 import java.io.OutputStream;
27
28 import javax.swing.JScrollPane;
29 import javax.swing.JTextArea;
30 import javax.swing.text.Element;
31
32 /***
33 * Log Panel.
34 *
35 * @version $Revision: 1.9 $, $Date: 2007/06/13 15:36:33 $
36 * @author Edwin Dankert <edankert@gmail.com>
37 */
38
39 public class LogPanel extends SearchablePanel {
40 private static final long serialVersionUID = -5024093857377606353L;
41
42 private OutputStream stream = null;
43 private LogPane logPane = null;
44
45 /***
46 * Constructs a new Input Panel.
47 */
48 public LogPanel() {
49 super( new BorderLayout());
50
51
52 stream = new OutputStream() {
53 private StringBuffer buffer = new StringBuffer();
54
55 public void write(int b) {
56 buffer.append( (char)b);
57 }
58
59 public void flush () {
60 logPane.append( buffer.toString());
61 buffer = new StringBuffer();
62 }
63 };
64
65 logPane = new LogPane();
66 JScrollPane scrollPane = new JScrollPane( logPane,
67 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
68 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
69 add( scrollPane, BorderLayout.CENTER);
70 }
71
72 public OutputStream getOutputStream() {
73 return stream;
74 }
75
76 public boolean search(String search, boolean matchCase, boolean forward) {
77 return search(logPane, search, matchCase, forward);
78 }
79
80 public class LogPane extends JTextArea {
81
82 private static final long serialVersionUID = 6426276169097189726L;
83
84 public LogPane() {
85
86 setFont( new Font( "monospaced", Font.PLAIN, 12));
87 }
88
89 public void startLogging( String text) {
90 setText( text+"\n");
91 }
92
93 public void stopLogging( String text) {
94 append( "\n"+text);
95 }
96
97 public void clear() {
98 setText("");
99 }
100
101 public void updatePreferences() {
102 setFont( new Font( "monospaced", Font.PLAIN, 12));
103 }
104
105 public void append( String text) {
106 super.append(text);
107
108 Element root = getDocument().getDefaultRootElement();
109 Element last = root.getElement( root.getElementCount()-1);
110 final int pos = last.getStartOffset();
111 setCaretPosition( pos);
112
113
114
115
116
117
118
119
120
121
122 }
123 }
124 }