1 21 22 27 28 package com.sun.activation.viewers; 29 30 import java.awt.*; 31 import java.io.*; 32 import java.beans.*; 33 import javax.activation.*; 34 35 public class TextViewer extends Panel implements CommandObject { 36 private TextArea text_area = null; 38 39 private File text_file = null; 41 private String text_buffer = null; 42 43 private DataHandler _dh = null; 44 private boolean DEBUG = false; 45 48 public TextViewer() { 49 setLayout( new GridLayout(1,1)); 50 text_area = new TextArea("", 24, 80, 52 TextArea.SCROLLBARS_VERTICAL_ONLY ); 53 text_area.setEditable( false ); 54 55 add(text_area); 56 } 57 58 public void setCommandContext(String verb, DataHandler dh) throws IOException { 60 _dh = dh; 61 this.setInputStream( _dh.getInputStream() ); 62 } 63 65 69 public void setInputStream(InputStream ins) throws IOException { 70 71 int bytes_read = 0; 72 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 74 byte data[] = new byte[1024]; 75 76 while((bytes_read = ins.read(data)) >0) 77 baos.write(data, 0, bytes_read); 78 79 ins.close(); 80 81 text_buffer = baos.toString(); 84 85 text_area.setText(text_buffer); 87 88 } 89 public void addNotify() { 91 super.addNotify(); 92 invalidate(); 93 } 94 public Dimension getPreferredSize() { 96 return text_area.getMinimumSize(24, 80); 97 } 98 99 } 100 101 102 103 104 105 106 | Popular Tags |