DESY ACOP Beans Home

com.cosylab.gui.components.numberfield
Class AbstractNumberDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.cosylab.gui.components.numberfield.AbstractNumberDocument
All Implemented Interfaces:
java.io.Serializable, javax.swing.text.Document
Direct Known Subclasses:
DoubleDocument, IntegerDocument, LongDocument, NumberDescriptorDocument

public abstract class AbstractNumberDocument
extends javax.swing.text.PlainDocument

Abstract base for implementation of number parsers, hiding the details of the javax.swing.text.Document interface. This class handles parsing of the string and caching last value. It ensures that only acceptable numbers are entered (within the numeric range of the desired class).

Version:
$id$
Author:
Ales Pucelj
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
 
Field Summary
protected  java.lang.Number max
           
protected  java.lang.Number min
           
 
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
AbstractNumberDocument()
          Constructor for AbstractNumberDocument.
 
Method Summary
protected  boolean checkBounds(java.lang.Number newVal)
           
 java.lang.Number getMaxValue()
          Returns the maximum value.
 java.lang.Number getMinValue()
          Returns the minimum value.
 java.lang.Number getValue()
          Returns last successfully entered number.
 void insertString(int offs, java.lang.String str, javax.swing.text.AttributeSet attributes)
          Inserts the string at str parameter into existing string, but only if the result is valid number.
 boolean isUpdated()
          Returns the updated.
protected abstract  java.lang.Number parseNumber(java.lang.String s)
          Parses the given string and returns the number represented.
 void remove(int offs, int len)
          Removes the string specified by offs and len, but only if the resulting string is a valid number.
 void setMaxValue(java.lang.Number max)
          Sets the maximum value.
 void setMinValue(java.lang.Number min)
          Sets the minimum value.
 void setUpdated(boolean updated)
          Sets the updated property.
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

min

protected java.lang.Number min

max

protected java.lang.Number max
Constructor Detail

AbstractNumberDocument

public AbstractNumberDocument()
Constructor for AbstractNumberDocument.

Method Detail

insertString

public void insertString(int offs,
                         java.lang.String str,
                         javax.swing.text.AttributeSet attributes)
                  throws javax.swing.text.BadLocationException
Inserts the string at str parameter into existing string, but only if the result is valid number.

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.PlainDocument
Parameters:
offs - int
str - String
attributes - AttributeSet
Throws:
javax.swing.text.BadLocationException
See Also:
Document#insertString(int, String, AttributeSet)

checkBounds

protected boolean checkBounds(java.lang.Number newVal)

remove

public void remove(int offs,
                   int len)
            throws javax.swing.text.BadLocationException
Removes the string specified by offs and len, but only if the resulting string is a valid number.

Specified by:
remove in interface javax.swing.text.Document
Overrides:
remove in class javax.swing.text.AbstractDocument
Parameters:
offs - int
len - int
Throws:
javax.swing.text.BadLocationException
See Also:
Document#remove(int, int)

parseNumber

protected abstract java.lang.Number parseNumber(java.lang.String s)
Parses the given string and returns the number represented. If the string is not a valid representation of the number, return value will be null. This method throws no exceptions, since all parse errors result in invalid number and must be handled internally.

Parameters:
s - String
Returns:
Number value of the number represented by string or null if no or invalid number

getValue

public java.lang.Number getValue()
Returns last successfully entered number. This value will not change if the string passed to the document is invalid.

Returns:
Number number parsed by this Document

getMaxValue

public java.lang.Number getMaxValue()
Returns the maximum value.

Returns:
maximum value

setMaxValue

public void setMaxValue(java.lang.Number max)
Sets the maximum value.

Parameters:
max - new maximum

getMinValue

public java.lang.Number getMinValue()
Returns the minimum value.

Returns:
minimum value

setMinValue

public void setMinValue(java.lang.Number min)
Sets the minimum value.

Parameters:
min - minimum value

isUpdated

public boolean isUpdated()
Returns the updated.

Returns:

setUpdated

public void setUpdated(boolean updated)
Sets the updated property.

Parameters:
updated -


Copyright © 2010. All Rights Reserved.