Subclass of {@link javax.swing.JTextArea} that attempts to behave in the same way asthe corresponding Forte component(s). In particular, the behaviour that is replicated is to keep the carat at the beginning of the text area when initially displaying text that is bound to a property in a model bean. This ensures that any associated {@link javax.swing.JViewPort}displays the beginning and not the end of the text (as in Forte). When a user changes the value of the bean property via this text area, the behaviour should be the same as in
JTextArea
.
BoundPropertyTextArea
is implemented to work with the property binding framework, particularly {@link DisplayProject.binding.adapter.DocumentAdapter}.
DocumentAdapter
is a wrapper around a {@link javax.swing.text.Document} which listensfor {@link java.beans.PropertyChangeEvent}s fired by an associated {@link com.jgoodies.binding.value.ValueModel}and updates the underlying document to reflect the changes.
DocumentAdapter
detects changes by the user by intercepting {@link javax.swing.event.DocumentEvent}s and updates the
ValueModel
accordingly.
The Forte behaviour is realised by associating an instance of ValueModel
with an instance of BoundPropertyTextArea
. BoundPropertyTextArea
makes use of two internal {@link java.beans.PropertyChangeListener}s and a {@link javax.swing.event.DocumentListener}. These determine whether a change to the associated bean model property was caused by the user typing in the text area or by a change in the backend. One PropertyChangeListener
intercepts PropertyChangeEvent
s before the DocumentAdapter
. The second PropertyChangeListener
intercepts PropertyChangeEvent
s after the DocumentAdapter
. It is the responsibility of the client to ensure that these listeners are registered in the correct sequence.
Refer to {@link DisplayProject.binding.TextComponentBinder} for an example ofusage.
The other advantage of this class is that it fires the same events as the Forte event model at the same time.
@see DisplayProject.binding.TextComponentBinder
@author Tim Faulkes