bill.util.gui
Class  JTextFieldMaxCharsDocument
java.lang.Object
  |
  +--javax.swing.text.AbstractDocument
        |
        +--javax.swing.text.PlainDocument
              |
              +--bill.util.gui.JTextFieldMaxCharsDocument
- All Implemented Interfaces: 
 - Document, Serializable
 
- Direct Known Subclasses: 
 - JTextFieldFilterDocument
 
- public class JTextFieldMaxCharsDocument
- extends PlainDocument
  
This class is a special subclass of the default (PlainDocument) document
 model. It restricts the number of characters that can be entered in the
 text field it is associated with. It also allows the user to indicate if
 they wish to shift focus to the next component if this text field reaches
 its maximum capacity.
- See Also: 
 - Serialized Form
 
 
| 
Field Summary | 
protected  int | 
_maxChars
 
          The maximum number of characters that may be entered in the text field | 
protected  boolean | 
_shiftFocusWhenFull
 
          Indicates if focus should shift to the next component when this one
has had the maximum number of characters entered in it. | 
protected  JTextFieldMaxChars | 
_textField
 
          The text field associated with this document | 
 
 
 
 
 
| 
Method Summary | 
 int | 
getMaxChars()
 
          Gets the maximum number of characters that are allowed in the text field
 associated with this document. | 
 void | 
insertString(int offs,
             String str,
             AttributeSet a)
 
          Called when a character (or characters) are added to the document
 Checks to make sure the addition does not put us over the maximum number
 of characters that can be in this field. | 
 boolean | 
isShiftFocusWhenFull()
 
          Checks if the focus should change to the next component when this text
 field has reached it's maximum number of characters. | 
 void | 
setMaxChars(int maxChars)
 
          Sets the maximum number of characters that are allowed in the text field
 associated with this document. | 
 void | 
setShiftFocusWhenFull(boolean shift)
 
          Sets the shift focus indicator. | 
 
 
| Methods inherited from class javax.swing.text.AbstractDocument | 
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentProperties, writeLock, writeUnlock | 
 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
 
_maxChars
protected int _maxChars
- The maximum number of characters that may be entered in the text field
 
_textField
protected JTextFieldMaxChars _textField
- The text field associated with this document
 
_shiftFocusWhenFull
protected boolean _shiftFocusWhenFull
- Indicates if focus should shift to the next component when this one
has had the maximum number of characters entered in it. Defaults to
false. 
JTextFieldMaxCharsDocument
public JTextFieldMaxCharsDocument(JTextFieldMaxChars textField)
- Creates a new instance with no maximum number of characters set.
- Parameters:
 textField - The text field widget associated with this document.
 
 
JTextFieldMaxCharsDocument
public JTextFieldMaxCharsDocument(JTextFieldMaxChars textField,
                                  int maxChars)
- Creates a new instance with the specified maximum number of characters
 set.
- Parameters:
 textField - The text field widget associated with this document.maxChars - The maximum number of characters allowed in the text
 field.
 
 
setMaxChars
public void setMaxChars(int maxChars)
- Sets the maximum number of characters that are allowed in the text field
 associated with this document.
- Parameters:
 maxChars - The maximum number of characters allowed in the text
 field.
 
 
getMaxChars
public int getMaxChars()
- Gets the maximum number of characters that are allowed in the text field
 associated with this document.
- Returns:
 - The maximum number of characters.
 
 
 
setShiftFocusWhenFull
public void setShiftFocusWhenFull(boolean shift)
- Sets the shift focus indicator. This indicates if the focus should change
 to the next component when this text field has reached it's maximum
 number of characters. A value of 
true indicates to shift
 focus.
- Parameters:
 shift - Value of true indicates to shift focus, value
 of false indicates not to.
 
 
isShiftFocusWhenFull
public boolean isShiftFocusWhenFull()
- Checks if the focus should change to the next component when this text
 field has reached it's maximum number of characters. A value of 
 true indicates to shift focus.
- Returns:
 - If shift is on, returns 
true, otherwise returns
 false. 
 
 
insertString
public void insertString(int offs,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
- Called when a character (or characters) are added to the document
 Checks to make sure the addition does not put us over the maximum number
 of characters that can be in this field. If it does, than then entire
 addition is cancelled. Also checks to see if the addition fills the field.
 If it does fill it and the "shift focus when full" falg has been set, we
 shift focus to the next component.
- Overrides:
 insertString in class AbstractDocument
 
- Parameters:
 offs - The starting offset to insert at (>=0).str - The string to insert, does nothing with null/empty strings.a - The attributes for the inserted content.