|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
org.opensha.commons.param.editor.document.NumericPlainDocument
public class NumericPlainDocument
Title: NumericPlainDocument
Description: Model ( or data) associated with an Numeric Text Field. The insertString() function is called whenever data is being entered into the text field. This is where the text field is checked to make sure only numeric valid charachters are being added.
This is an extention of the Model View Controller (MVC) design pattern that all Java Swing elements are built upon. For example, the Java class JTextField contains a PlainDocument model that actually contains the text of the JTextField. This class simply replaces the JTextField PlainDocument with this document. Then as a user types in text into the textfield, this class instance is consulted to see if they are valid characters the user is typing.
You don't have to know the details on how this class works in order to
use it. To make text field that uses this document model simply extend
JTextField and overide the method createDefaultModel() by creating
an instance of you subclass of Plain Document.
protected Document createDefaultModel() {
return new NumericPlainDocument();
}
Note: SWR: This class was implemented with java JDK 1.3. In the new java JDK 1.4 there is a much simpler way to do this. Now you can create a Formatter (Decimal, Date, etc. ) and simply pass the formatter to a Standard JTextField. No subclasses to make.
NumericTextField,
IntegerPlainDocument,
IntegerTextField,
Serialized Form| Nested Class Summary | |
|---|---|
static interface |
NumericPlainDocument.InsertErrorListener
Local interface definition that listeners must implement to be notified when isert fails occur due to invalid chars, etc. |
| Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument |
|---|
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement |
| Field Summary | |
|---|---|
protected static String |
C
Class name for debugging. |
protected static boolean |
D
If true print out debug statements. |
protected char |
decimalSeparator
valid char for decimal point |
protected static DecimalFormat |
defaultFormat
Format of this Decimal. |
protected NumericPlainDocument.InsertErrorListener |
errorListener
Listener to be notified of insert errors, typically the text field |
protected DecimalFormat |
format
Format of this Decimal. |
protected char |
groupingSeparator
valid char for thousands seperator |
protected String |
negativePrefix
|
protected int |
negativePrefixLen
|
protected String |
negativeSuffix
|
protected int |
negativeSuffixLen
|
protected ParsePosition |
parsePos
|
protected String |
positivePrefix
|
protected int |
positivePrefixLen
|
protected String |
positiveSuffix
|
protected int |
positiveSuffixLen
|
| Fields inherited from class javax.swing.text.PlainDocument |
|---|
lineLimitAttribute, tabSizeAttribute |
| Fields inherited from class javax.swing.text.AbstractDocument |
|---|
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
| Fields inherited from interface javax.swing.text.Document |
|---|
StreamDescriptionProperty, TitleProperty |
| Constructor Summary | |
|---|---|
NumericPlainDocument()
Default constructor, sets a null format |
|
NumericPlainDocument(AbstractDocument.Content content,
DecimalFormat format)
Constructor that lets you set the content and the decimal format. |
|
NumericPlainDocument(DecimalFormat format)
Constructor that lets you set the decimal format. |
|
| Method Summary | |
|---|---|
void |
addInsertErrorListener(NumericPlainDocument.InsertErrorListener l)
Adds a listener that is notified when insertString() fails because text is not a decimal number |
Double |
getDoubleValue()
Helper function that converts the String representation model data into an Double, i.e. |
DecimalFormat |
getFormat()
Returns the Deciaml format. |
Long |
getLongValue()
Helper function that converts the String representation model data into an Long. |
Number |
getNumberValue()
Helper function that converts the String representation model data into a Number, the superclass of a Double. |
void |
insertString(int offset,
String str,
AttributeSet a)
Method called to add data to the text field. |
void |
removeInsertErrorListener(NumericPlainDocument.InsertErrorListener l)
Removes a listener that was notified when insertString() fails because text is not a decimal number |
void |
setFormat(DecimalFormat fmt)
Sets the Deciaml format. |
| Methods inherited from class javax.swing.text.PlainDocument |
|---|
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final String C
protected static final boolean D
protected NumericPlainDocument.InsertErrorListener errorListener
protected static DecimalFormat defaultFormat
protected DecimalFormat format
protected char decimalSeparator
protected char groupingSeparator
protected String positivePrefix
protected int positivePrefixLen
protected String positiveSuffix
protected int positiveSuffixLen
protected String negativePrefix
protected int negativePrefixLen
protected String negativeSuffix
protected int negativeSuffixLen
protected transient ParsePosition parsePos
| Constructor Detail |
|---|
public NumericPlainDocument()
public NumericPlainDocument(DecimalFormat format)
public NumericPlainDocument(AbstractDocument.Content content,
DecimalFormat format)
| Method Detail |
|---|
public DecimalFormat getFormat()
public void setFormat(DecimalFormat fmt)
public Number getNumberValue()
throws ParseException
ParseException
public Long getLongValue()
throws ParseException
ParseException
public Double getDoubleValue()
throws ParseException
ParseException
public void insertString(int offset,
String str,
AttributeSet a)
throws BadLocationException
insertString in interface DocumentinsertString in class PlainDocumentBadLocationExceptionpublic void addInsertErrorListener(NumericPlainDocument.InsertErrorListener l)
public void removeInsertErrorListener(NumericPlainDocument.InsertErrorListener l)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||