01: /*
02: * Created on Jul 20, 2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07: package org.enhydra.base.tool;
08:
09: import javax.swing.JPanel;
10:
11: import javax.swing.JTextArea;
12: import java.awt.BorderLayout;
13: import java.io.IOException;
14: import java.io.Writer;
15: import javax.swing.JScrollPane;
16:
17: /**
18: * @author slobodan
19: *
20: * TODO To change the template for this generated type comment go to
21: * Window - Preferences - Java - Code Style - Code Templates
22: */
23: public class OutputPanel extends JPanel {
24:
25: private JScrollPane jScrollPane = null;
26: private JTextArea output = null;
27:
28: /**
29: * This is the default constructor
30: */
31: public OutputPanel() {
32: super ();
33: initialize();
34: }
35:
36: /**
37: * This method initializes this
38: *
39: * @return void
40: */
41: private void initialize() {
42: this .setLayout(new BorderLayout());
43: this .setPreferredSize(new java.awt.Dimension(300, 150));
44: this .setSize(300, 150);
45: this .add(getJScrollPane(), java.awt.BorderLayout.CENTER);
46: }
47:
48: public void setWriter(Writer writer) {
49: try {
50: output.write(writer);
51: } catch (IOException ex) {
52: System.out.println("Unable to set writer!");
53: }
54: }
55:
56: public void setText(String text) {
57: output.setText(text);
58: }
59:
60: public void appendText(String text) {
61: output.append(text);
62: }
63:
64: public void appendTextLine(String text) {
65: output.append(text + "\n");
66: jScrollPane.getVerticalScrollBar().setValue(output.getHeight());
67: }
68:
69: public void clearText() {
70: output.setText("");
71: }
72:
73: /**
74: * This method initializes jScrollPane
75: *
76: * @return javax.swing.JScrollPane
77: */
78: private JScrollPane getJScrollPane() {
79: if (jScrollPane == null) {
80: jScrollPane = new JScrollPane();
81: jScrollPane.setViewportView(getOutput());
82: }
83: return jScrollPane;
84: }
85:
86: /**
87: * This method initializes jTextArea
88: *
89: * @return javax.swing.JTextArea
90: */
91: private JTextArea getOutput() {
92: if (output == null) {
93: output = new JTextArea();
94: output.setName("output");
95: output.setEditable(false);
96: }
97: return output;
98: }
99: }
|