FileDocCategorySizeDatePackage
TextViewer.javaAPI DocGlassfish v2 API3906Mon May 14 15:29:52 BST 2007com.sun.activation.viewers

TextViewer

public class TextViewer extends Panel implements CommandObject

Fields Summary
private TextArea
text_area
private File
text_file
private String
text_buffer
private DataHandler
_dh
private boolean
DEBUG
Constructors Summary
public TextViewer()
Constructor

          
      
	setLayout( new GridLayout(1,1));
	// create the text area
	text_area = new TextArea("", 24, 80, 
				 TextArea.SCROLLBARS_VERTICAL_ONLY );
	text_area.setEditable( false );
	
	add(text_area);
    
Methods Summary
public voidaddNotify()

	super.addNotify();
	invalidate();
    
public java.awt.DimensiongetPreferredSize()

	return text_area.getMinimumSize(24, 80);
    
public voidsetCommandContext(java.lang.String verb, javax.activation.DataHandler dh)

	_dh = dh;
	this.setInputStream( _dh.getInputStream() );
    
public voidsetInputStream(java.io.InputStream ins)
set the data stream, component to assume it is ready to be read.

      
      int bytes_read = 0;
      // check that we can actually read
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      byte data[] = new byte[1024];
      
      while((bytes_read = ins.read(data)) >0)
	  baos.write(data, 0, bytes_read);
      
      ins.close();

      // convert the buffer into a string
      // popuplate the buffer
      text_buffer = baos.toString();

      // place in the text area
      text_area.setText(text_buffer);