001package horstmann.ch08_umleditor; 002import java.awt.Component; 003import java.beans.PropertyEditorSupport; 004 005import javax.swing.JScrollPane; 006import javax.swing.JTextArea; 007import javax.swing.event.DocumentEvent; 008import javax.swing.event.DocumentListener; 009 010/** 011 A property editor for the MultiLineString type. 012 */ 013public class MultiLineStringEditor extends PropertyEditorSupport 014{ 015 public boolean supportsCustomEditor() 016 { 017 return true; 018 } 019 020 public Component getCustomEditor() 021 { 022 final MultiLineString value = (MultiLineString) getValue(); 023 final JTextArea textArea = new JTextArea(value.getText(),10, 40); 024 textArea.getDocument().addDocumentListener(new 025 DocumentListener() 026 { 027 public void insertUpdate(DocumentEvent e) 028 { 029 value.setText(textArea.getText()); 030 firePropertyChange(); 031 } 032 public void removeUpdate(DocumentEvent e) 033 { 034 value.setText(textArea.getText()); 035 firePropertyChange(); 036 } 037 public void changedUpdate(DocumentEvent e) 038 { 039 } 040 }); 041 return new JScrollPane(textArea); 042 } 043}