Holger's
Java API

com.antelmann.util.gui
Class DocumentAdapter

java.lang.Object
  extended by com.antelmann.util.gui.DocumentAdapter
All Implemented Interfaces:
Filter<DocumentEvent>, EventListener, DocumentListener

public abstract class DocumentAdapter
extends Object
implements DocumentListener, Filter<DocumentEvent>

a convenience implementation that makes it easier to implement a DocumentListener if you want to perform a certain task in all cases. All methods defined in the DocumentListener interface are implemented here to call the one abstract method. In addition, this method has special support for JFormattedTextField, which allows to avoid the effects from this bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4888144

Since:
10. Januar 2008, 14:20
Author:
Holger Antelmann

Field Summary
protected  Map<JFormattedTextField,Object> fieldValues
          the fields in this map will be checked for their values by the filter to see whether the changes are merely caused by a focus gain/loss to avoid the effects caused by http://bugs.sun.com/bugdatabase/view_bug.do?
 
Fields inherited from interface com.antelmann.util.Filter
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER
 
Constructor Summary
DocumentAdapter(boolean autoCommit, JFormattedTextField... fields)
           
DocumentAdapter(JFormattedTextField... fields)
           
 
Method Summary
 boolean accept(DocumentEvent ev)
          only accepts events that are to actually trigger documentUpdated(DocumentEvent).
 void add(JFormattedTextField field)
          see fieldValues
 void changedUpdate(DocumentEvent ev)
           
abstract  void documentUpdated(DocumentEvent ev)
          only called when the event is accepted by accept(DocumentEvent)
 JFormattedTextField[] getFields()
           
 void insertUpdate(DocumentEvent ev)
           
 boolean isAutoCommit()
           
 void remove(JFormattedTextField field)
           
 void removeUpdate(DocumentEvent ev)
           
 void setAutoCommit(boolean autoCommit)
          allows to specify whether the filter method should call JFormattedTextField.commitEdit(), so that when documentUpdated(DocumentEvent) is called, the getValue() method will return the latest current value based on the text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldValues

protected final Map<JFormattedTextField,Object> fieldValues
the fields in this map will be checked for their values by the filter to see whether the changes are merely caused by a focus gain/loss to avoid the effects caused by http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4888144. This variable is based on a synchronized WeakHashMap.

Constructor Detail

DocumentAdapter

public DocumentAdapter(JFormattedTextField... fields)

DocumentAdapter

public DocumentAdapter(boolean autoCommit,
                       JFormattedTextField... fields)
Parameters:
fields - see fieldValues
Method Detail

isAutoCommit

public boolean isAutoCommit()

setAutoCommit

public void setAutoCommit(boolean autoCommit)
allows to specify whether the filter method should call JFormattedTextField.commitEdit(), so that when documentUpdated(DocumentEvent) is called, the getValue() method will return the latest current value based on the text


add

public void add(JFormattedTextField field)
see fieldValues


remove

public void remove(JFormattedTextField field)

getFields

public JFormattedTextField[] getFields()

documentUpdated

public abstract void documentUpdated(DocumentEvent ev)
only called when the event is accepted by accept(DocumentEvent)


insertUpdate

public void insertUpdate(DocumentEvent ev)
Specified by:
insertUpdate in interface DocumentListener

removeUpdate

public void removeUpdate(DocumentEvent ev)
Specified by:
removeUpdate in interface DocumentListener

changedUpdate

public void changedUpdate(DocumentEvent ev)
Specified by:
changedUpdate in interface DocumentListener

accept

public boolean accept(DocumentEvent ev)
only accepts events that are to actually trigger documentUpdated(DocumentEvent). This implementation also checks the fieldValues and returns false if the value didn't actually change. If setAutoCommit(boolean) is set to true, this method will commit each edit directly, so that when implementing documentUpdated(DocumentEvent) you can already rely on the committed value when calling JFormattedTextField.getValue(). Override this if you want a different behavior.

Specified by:
accept in interface Filter<DocumentEvent>
See Also:
fieldValues


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads