com.abstractics.utils.swing
Class CaseAndLengthDocumentFilter

java.lang.Object
  extended byjavax.swing.text.DocumentFilter
      extended bycom.abstractics.utils.swing.CaseAndLengthDocumentFilter

public class CaseAndLengthDocumentFilter
extends javax.swing.text.DocumentFilter

Implementation of a DocumentFilter that can place length restrictions on the document, as well as force case (upper or lower) if necessary.

Version:
$Id: CaseAndLengthDocumentFilter.java,v 1.2 2006/03/15 05:37:30 andyman99 Exp $
Author:
Andrew Lawrence, Copyright 2006 Abstractics, L.L.C., Licensed under the Apache License, Version 2.0

Nested Class Summary
 
Nested classes inherited from class javax.swing.text.DocumentFilter
javax.swing.text.DocumentFilter.FilterBypass
 
Field Summary
static java.lang.String ANYCASE
           
static java.lang.String LOWERCASE
           
static java.lang.String UPPERCASE
           
 
Constructor Summary
CaseAndLengthDocumentFilter(int maxLength)
           
CaseAndLengthDocumentFilter(java.lang.String forceCase)
           
CaseAndLengthDocumentFilter(java.lang.String forceCase, int maxLength)
           
 
Method Summary
static void applyTo(javax.swing.text.JTextComponent comp, java.lang.String forceCase, int maxLength)
          Convenience method to make the necessary adjustments to the given JTextComponent to apply a CaseAndLengthDocumentFilter.
 void insertString(javax.swing.text.DocumentFilter.FilterBypass fb, int offset, java.lang.String string, javax.swing.text.AttributeSet attr)
           
 void replace(javax.swing.text.DocumentFilter.FilterBypass fb, int offset, int length, java.lang.String string, javax.swing.text.AttributeSet attrs)
           
 
Methods inherited from class javax.swing.text.DocumentFilter
remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANYCASE

public static final java.lang.String ANYCASE
See Also:
Constant Field Values

UPPERCASE

public static final java.lang.String UPPERCASE
See Also:
Constant Field Values

LOWERCASE

public static final java.lang.String LOWERCASE
See Also:
Constant Field Values
Constructor Detail

CaseAndLengthDocumentFilter

public CaseAndLengthDocumentFilter(java.lang.String forceCase)
Parameters:
forceCase - One of three values: ANYCASE, UPPERCASE, or {@link #LOWERCASE)
Throws:
java.lang.IllegalArgumentException - Thrown if the forceCase parameter is not a valid value

CaseAndLengthDocumentFilter

public CaseAndLengthDocumentFilter(int maxLength)
Parameters:
maxLength - Maximumm length of text allowed - or zero to not enforce a maximum length
Throws:
java.lang.IllegalArgumentException - Thrown if the forceCase parameter is not a valid value

CaseAndLengthDocumentFilter

public CaseAndLengthDocumentFilter(java.lang.String forceCase,
                                   int maxLength)
Parameters:
forceCase - One of three values: ANYCASE, UPPERCASE, or {@link #LOWERCASE)
maxLength - Maximumm length of text allowed - or zero to not enforce a maximum length
Throws:
java.lang.IllegalArgumentException - Thrown if the forceCase parameter is not a valid value
Method Detail

applyTo

public static void applyTo(javax.swing.text.JTextComponent comp,
                           java.lang.String forceCase,
                           int maxLength)
Convenience method to make the necessary adjustments to the given JTextComponent to apply a CaseAndLengthDocumentFilter. This method makes sure that the document being used by the JTextComponent is an instance of javax.swing.text.AbstractDocument and then takes that document and calls setDocumentFilter() with a new instance of CaseAndLengthDocumentFilter.

Parameters:
comp - JTextComponent to add the DocumentFilter to
forceCase - One of three values: ANYCASE, UPPERCASE, or {@link #LOWERCASE)
maxLength - Maximumm length of text allowed - or zero to not enforce a maximum length

insertString

public void insertString(javax.swing.text.DocumentFilter.FilterBypass fb,
                         int offset,
                         java.lang.String string,
                         javax.swing.text.AttributeSet attr)
                  throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

replace

public void replace(javax.swing.text.DocumentFilter.FilterBypass fb,
                    int offset,
                    int length,
                    java.lang.String string,
                    javax.swing.text.AttributeSet attrs)
             throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException