org.opensha.commons.param.editor.impl
Class NumericTextField
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
org.opensha.commons.param.editor.impl.NumericTextField
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants, NumericPlainDocument.InsertErrorListener
public class NumericTextField
- extends JTextField
- implements NumericPlainDocument.InsertErrorListener
Title: NumericTextField
Description: Special JTextField that only allows numbers to be typed in. This
text field allows for normal number synatx, such as a negative sign, period for decimal point,
and commas for deliminating thousands, millions, etc.
Note: This is a fairly complex GUI customization that relies upon a NumjericDocument model
to determine what types of characters are allowed for a numerical number ( digits, - sign
in first location, etc. ) It is beyond the scope of this javadoc to explain it's use
fully. It is not necessary for programmers to understand the details. They can just
use it like a normal JTextField and just expect it to work.
Please consult Swing doucmentation for further details, specifically JTextField and
PlainDocument. It is required a programmer understands the Model View Component
design architeture to understand the relationship between JTextField and PlainDocument
( and our corresponding NumericTextField and NumericDocument ).
- Version:
- 1.0
- Author:
- Steven W. Rock
- See Also:
- Serialized Form
|
Field Summary |
protected static String |
C
Class name for debugging. |
protected static boolean |
D
If true print out debug statements. |
protected static String |
S
|
protected static String |
S2
|
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Methods inherited from class javax.swing.JTextField |
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset |
| Methods inherited from class javax.swing.text.JTextComponent |
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write |
| Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
C
protected static final String C
- Class name for debugging.
- See Also:
- Constant Field Values
D
protected static final boolean D
- If true print out debug statements.
- See Also:
- Constant Field Values
S
protected static final String S
- See Also:
- Constant Field Values
S2
protected static final String S2
- See Also:
- Constant Field Values
NumericTextField
public NumericTextField()
NumericTextField
public NumericTextField(String text,
int columns,
DecimalFormat format)
NumericTextField
public NumericTextField(int columns,
DecimalFormat format)
NumericTextField
public NumericTextField(String text)
NumericTextField
public NumericTextField(String text,
int columns)
setFormat
public void setFormat(DecimalFormat format)
getFormat
public DecimalFormat getFormat()
formatChanged
public void formatChanged()
getLongValue
public Long getLongValue()
throws ParseException
- Throws:
ParseException
getDoubleValue
public Double getDoubleValue()
throws ParseException
- Throws:
ParseException
getNumberValue
public Number getNumberValue()
throws ParseException
- Throws:
ParseException
setValue
public void setValue(Number number)
setValue
public void setValue(long l)
setValue
public void setValue(double d)
normalize
public void normalize()
throws ParseException
- Throws:
ParseException
setText
public void setText(String t)
- Sets the text of this
TextComponent
to the specified text. If the text is null
or empty, has the effect of simply deleting the old text.
When text has been inserted, the resulting caret location
is determined by the implementation of the caret class.
This method is thread safe, although most Swing methods
are not. Please see
Threads
and Swing for more information.
Note: This is where the text field Document model is consulted to see if
the text is viable for insertion.
- Overrides:
setText in class JTextComponent
- Parameters:
t - the new text to be set- See Also:
getText(),
DefaultCaret
getText
public String getText()
- Returns the text contained in this
TextComponent.
If the underlying document is null,
will give a NullPointerException.
- Overrides:
getText in class JTextComponent
- Returns:
- the text
- Throws:
NullPointerException - if the document is null- See Also:
setText(java.lang.String)
insertFailed
public void insertFailed(NumericPlainDocument doc,
int offset,
String str,
AttributeSet a)
- Specified by:
insertFailed in interface NumericPlainDocument.InsertErrorListener
createDefaultModel
protected Document createDefaultModel()
- Function that must be overidded to return the PlainDocument subclass
- Overrides:
createDefaultModel in class JTextField
main
public static void main(String[] args)
- Tester main function that shows how to use this class.