package com.macfaq; import java.beans.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class FilledTextAreaCustomizer extends Panel implements Customizer { PropertyChangeSupport pce = new PropertyChangeSupport(this); FilledTextArea bean; TextArea ta = new TextArea(); Button b1 = new Button("Load File"); public void addPropertyChangeListener(PropertyChangeListener pcl) { pce.addPropertyChangeListener(pcl); } public void removePropertyChangeListener(PropertyChangeListener pcl) { pce.removePropertyChangeListener(pcl); } public void setObject(Object bean) { this.bean = (FilledTextArea) bean; ta.setText(this.bean.getText()); } public FilledTextAreaCustomizer() { setLayout(new BorderLayout()); Panel p1 = new Panel(); p1.add(b1); add("South", p1); add("Center", ta); b1.addActionListener(new FileChooser()); ta.addTextListener(new TextWatcher()); } class TextWatcher implements TextListener { public void textValueChanged(TextEvent e) { String oldValue = bean.getText(); String newValue = ta.getText(); bean.setText(newValue); pce.firePropertyChange("Text", oldValue , newValue); } } class FileChooser implements ActionListener { public void actionPerformed(ActionEvent evt) { FileDialog fd = new FileDialog(new Frame(), "Please select the file:", FileDialog.LOAD); fd.setVisible(true); String file = fd.getFile(); String dir = fd.getDirectory(); if (file != null) { try { FileReader fr = new FileReader(dir + file); StringBuffer sb = new StringBuffer(); int c; while ((c = fr.read()) != -1) { sb.append((char) c); } ta.setText(sb.toString()); } catch (IOException ex) { } } } } }