Groovy Documentation

com.wordpress.tipsforjava.swing.text
[Java] Class SizeDocumentFilter

java.lang.Object
  javax.swing.text.DocumentFilter
      com.wordpress.tipsforjava.swing.text.ChainedDocumentFilter
          com.wordpress.tipsforjava.swing.text.SizeDocumentFilter

public class SizeDocumentFilter
extends ChainedDocumentFilter

A DocumentFilter that allows you to control the maximum number of characters that can be added to the Document. When the Document is full you can optionally tab to the next component to speed data entry. This class can also be used as a generic size filter for JTextFields. In this case when a size of 0 is speicifed for the size of the Document the getColumns() method of JTextField will be used to determine the size restriction.

Authors:
Rob Camick
Darryl Burke


Field Summary
private boolean autoTab

private int size

 
Fields inherited from class ChainedDocumentFilter
filter
 
Constructor Summary
SizeDocumentFilter()

Generic constructor for use with JTextFields only.

SizeDocumentFilter(int size)

Constructor to set the size for this filter

SizeDocumentFilter(int size, DocumentFilter filter)

Constructor to set the size for this filter as well as provide additional filtering

 
Method Summary
private int getAllowedSize(FilterBypass fb)

When a size isn't specified then we assume the desired size can be obtained from the associated text field.

boolean getAutoTab()

Get the auto tab property

private int getColumns(FilterBypass fb)

int getSize()

Get the maximum size for any Document using this filter

protected void handleAutoTab(int possibleSize, int allowedSize, FilterBypass fb)

void insertString(FilterBypass fb, int offs, String str, AttributeSet a)

Make sure the insertion of text will not cause the Document to exceed its size limit.

void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)

Make sure the replacement of text will not cause the Document to exceed its size limit.

void setAutoTab(boolean autoTab)

Set the auto tab property

void setSize(int size)

Set maximum size for a Document using this filter.

 
Methods inherited from class ChainedDocumentFilter
getFilter, insertString, installFilter, provideErrorFeedback, remove, replace, setFilter, uninstallFilter
 
Methods inherited from class DocumentFilter
replace, remove, insertString, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

autoTab

private boolean autoTab


size

private int size


 
Constructor Detail

SizeDocumentFilter

public SizeDocumentFilter()
Generic constructor for use with JTextFields only. The size of the Document will be determined by the value of the getColumns() method.


SizeDocumentFilter

public SizeDocumentFilter(int size)
Constructor to set the size for this filter
Parameters:
size - maximum number of characters to be added to the Document


SizeDocumentFilter

public SizeDocumentFilter(int size, DocumentFilter filter)
Constructor to set the size for this filter as well as provide additional filtering
Parameters:
size - maximum number of characters to be added to the Document
filter - another DocumentFilter to invoke


 
Method Detail

getAllowedSize

private int getAllowedSize(FilterBypass fb)
When a size isn't specified then we assume the desired size can be obtained from the associated text field. Otherwise, use the class size property.


getAutoTab

public boolean getAutoTab()
Get the auto tab property
Returns:
the auto tab property


getColumns

private int getColumns(FilterBypass fb)


getSize

public int getSize()
Get the maximum size for any Document using this filter
Returns:


handleAutoTab

protected void handleAutoTab(int possibleSize, int allowedSize, FilterBypass fb)


insertString

de
	public
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
Make sure the insertion of text will not cause the Document to exceed its size limit. Also, potentially tab to next component when full.


replace

de
	public
public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
Make sure the replacement of text will not cause the Document to exceed its size limit. Also, potentially tab to next component when full.


setAutoTab

public void setAutoTab(boolean autoTab)
Set the auto tab property
Parameters:
autoTab - the default is true


setSize

public void setSize(int size)
Set maximum size for a Document using this filter. Dynamically changing the size will not affect existing Documents. Characters will not be removed from any Document. The filter will only be invoked on new additions to the Document.
Parameters:
size - the maximum number of character allowed in the Document


 

Groovy Documentation