KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TextInternalizer


1 /*
2  * @(#)TextInternalizer.java 1.2 99/12/06
3  *
4  * Copyright 1997-1999 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This software is the proprietary information of Sun Microsystems, Inc.
7  * Use is subject to license terms.
8  *
9  */

10
11 import java.awt.*;
12 import java.io.*;
13 import java.beans.*;
14 import javax.activation.*;
15
16 public class TextInternalizer extends Panel implements Externalizable {
17     // UI Vars...
18
private TextArea text_area = null;
19     
20     // File Vars
21
private File text_file = null;
22     private String JavaDoc text_buffer = null;
23     
24     private DataHandler _dh = null;
25     private boolean DEBUG = false;
26     /**
27      * Constructor
28      */

29     public TextInternalizer() {
30     System.out.println("TextInternalizer!!!!!");
31
32     setLayout( new GridLayout(1,1));
33     // create the text area
34
text_area = new TextArea("", 24, 80,
35                  TextArea.SCROLLBARS_VERTICAL_ONLY );
36     text_area.setEditable( false );
37     
38     add(text_area);
39     }
40     
41     public void writeExternal(ObjectOutput out) throws IOException{
42
43     }
44
45     public void readExternal(ObjectInput in) throws IOException,
46     ClassNotFoundException JavaDoc {
47
48     
49     this.setObjectInput(in);
50     }
51
52
53
54     //--------------------------------------------------------------------
55
// public void setCommandContext(String verb, DataHandler dh) throws IOException {
56
// _dh = dh;
57
// this.setInputStream( _dh.getInputStream() );
58
// }
59
//--------------------------------------------------------------------
60

61   /**
62    * set the data stream, component to assume it is ready to
63    * be read.
64    */

65   public void setObjectInput(ObjectInput ins) throws IOException {
66       try {
67
68       text_buffer = (String JavaDoc)ins.readObject();
69       } catch(Exception JavaDoc e){ e.printStackTrace(); }
70       // place in the text area
71
text_area.setText(text_buffer);
72
73     }
74   //--------------------------------------------------------------------
75
public void addNotify() {
76     super.addNotify();
77     invalidate();
78     }
79   //--------------------------------------------------------------------
80
public Dimension getPreferredSize() {
81     return text_area.getMinimumSize(24, 80);
82     }
83
84 }
85
86
87
88
89
90
91
Popular Tags