KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > base > tool > OutputPanel


1 /*
2  * Created on Jul 20, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.base.tool;
8
9 import javax.swing.JPanel JavaDoc;
10
11 import javax.swing.JTextArea JavaDoc;
12 import java.awt.BorderLayout JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.Writer JavaDoc;
15 import javax.swing.JScrollPane JavaDoc;
16 /**
17  * @author slobodan
18  *
19  * TODO To change the template for this generated type comment go to
20  * Window - Preferences - Java - Code Style - Code Templates
21  */

22 public class OutputPanel extends JPanel JavaDoc {
23
24     private JScrollPane JavaDoc jScrollPane = null;
25     private JTextArea JavaDoc output = null;
26     /**
27      * This is the default constructor
28      */

29     public OutputPanel() {
30         super();
31         initialize();
32     }
33     /**
34      * This method initializes this
35      *
36      * @return void
37      */

38     private void initialize() {
39         this.setLayout(new BorderLayout JavaDoc());
40         this.setPreferredSize(new java.awt.Dimension JavaDoc(300,150));
41         this.setSize(300, 150);
42         this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
43     }
44     
45     public void setWriter(Writer JavaDoc writer){
46         try {
47             output.write(writer);
48         } catch (IOException JavaDoc ex){
49             System.out.println("Unable to set writer!");
50         }
51     }
52     
53     public void setText(String JavaDoc text){
54         output.setText(text);
55     }
56     
57     public void appendText(String JavaDoc text){
58         output.append(text);
59     }
60     
61     public void appendTextLine(String JavaDoc text){
62         output.append(text+"\n");
63         jScrollPane.getVerticalScrollBar().setValue(output.getHeight());
64     }
65     
66     public void clearText(){
67         output.setText("");
68     }
69     
70     /**
71      * This method initializes jScrollPane
72      *
73      * @return javax.swing.JScrollPane
74      */

75     private JScrollPane JavaDoc getJScrollPane() {
76         if (jScrollPane == null) {
77             jScrollPane = new JScrollPane JavaDoc();
78             jScrollPane.setViewportView(getOutput());
79         }
80         return jScrollPane;
81     }
82     /**
83      * This method initializes jTextArea
84      *
85      * @return javax.swing.JTextArea
86      */

87     private JTextArea JavaDoc getOutput() {
88         if (output == null) {
89             output = new JTextArea JavaDoc();
90             output.setName("output");
91             output.setEditable(false);
92         }
93         return output;
94     }
95    }
96
Popular Tags