ProgramixGenericLib v5.0.1

com.programix.gui.text
Class FormatField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by com.programix.gui.text.FormatField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
IntegerField

public class FormatField
extends JTextField

A special kind of JTextField that generally restricts the characters that can be typed in the field and has the ability to retrieve the state as a Value.

Author:
Paul Hyde
See Also:
Serialized Form

Nested Class Summary
static interface FormatField.ValueListener
          Implementations of this interface can use addValueListener(ValueListener) to be notified when the value inside a FormatField changes.
 
Nested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  boolean allowValueListenerNotification
           
protected  Value emptyReplacement
           
protected  Object lock
           
protected  Value value
           
protected  String valueStr
           
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FormatField()
           
FormatField(int maxColumnCount)
           
FormatField(int maxColumnCount, int visibleColumnCount, String validInputChar, Value initialValue)
           
FormatField(int maxColumnCount, String validInputChar, Value initialValue)
           
FormatField(int maxColumnCount, Value initialValue)
           
 
Method Summary
 void addValueListener(FormatField.ValueListener l)
           
 FilterChainDocument appendFilter(FilterChainDocument.Filter filter)
           
protected  Value approveValue(Value proposedValue)
          Gives subclasses a chance to approved the proposed new value.
 Value getEmptyReplacement()
          Returns the current Value to substitute when the proposed value is empty.
 FilterChainDocument getFilterChainDocument()
           
 String getString()
          Returns the current value as a trimmed String or null if the field is empty.
 Value getValue()
          Returns the current contents of the field as a Value.
 boolean isEmpty()
          Returns true if the current value of this field is null, a zero-length string, or a string of all whitespace.
 boolean isNotEmpty()
          Returns true if the current value of this field is not "empty" (see isEmpty()}.
protected  void notifyValueListeners()
           
protected  void parseCurrentText()
           
 void removeValueListener(FormatField.ValueListener l)
           
 void setEmptyReplacement(String emptyReplacement)
          Specifies the String to substitute when the proposed value is empty.
 void setEmptyReplacement(Value newEmptyReplacement)
          Specifies the Value to substitute when the proposed value is empty.
 void setText(String text)
          Overridden to call setValue(String).
 void setValue(String text)
          Sets the value specified as a String.
 void setValue(Value newValue)
          Specifies the value to display and notifies any value listeners if there is a visible change in the value.
protected  void signalWarning()
           
 
Methods inherited from class javax.swing.JTextField
addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, 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, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, 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, 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, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lock

protected final Object lock

value

protected Value value

valueStr

protected String valueStr

emptyReplacement

protected Value emptyReplacement

allowValueListenerNotification

protected boolean allowValueListenerNotification
Constructor Detail

FormatField

public FormatField(int maxColumnCount,
                   int visibleColumnCount,
                   String validInputChar,
                   Value initialValue)

FormatField

public FormatField(int maxColumnCount,
                   String validInputChar,
                   Value initialValue)

FormatField

public FormatField(int maxColumnCount,
                   Value initialValue)

FormatField

public FormatField(int maxColumnCount)

FormatField

public FormatField()
Method Detail

parseCurrentText

protected void parseCurrentText()

setText

public void setText(String text)
Overridden to call setValue(String).

If a subclass needs to override this method, the subclass should call super.setText().

Overrides:
setText in class JTextComponent

setValue

public void setValue(Value newValue)
Specifies the value to display and notifies any value listeners if there is a visible change in the value. This method automatically substitutes the "empty replacement" (see getEmptyReplacement()) if the passed newValue is either null or if the Value's isEmpty() method returns true.

If a subclass needs to override this method, the subclass should call super.setValue().

Parameters:
newValue - the value to try. If null, then the empty replacement is used instead.

approveValue

protected Value approveValue(Value proposedValue)
Gives subclasses a chance to approved the proposed new value. If the subclass wants to override the proposed value, the subclass should override this method to return a different value. This method should also be overridden in subclasses that want to add formatting for the displayed text.

The original version of this method on FormatField simply returns the value unchanged.


getValue

public Value getValue()
Returns the current contents of the field as a Value. Unlike most of the other getters, a Value is always returned—null is never returned.


setValue

public void setValue(String text)
Sets the value specified as a String. It is OK to pass null as it will displayed as a zero-length String (or whatever has been specified as the "empty replacement"—see setEmptyReplacement(Value)).


getString

public String getString()
Returns the current value as a trimmed String or null if the field is empty. Note that this is different than what is returned from JTextComponent.getText(). Specifically, if isEmpty() returns true then this method returns null.


isEmpty

public boolean isEmpty()
Returns true if the current value of this field is null, a zero-length string, or a string of all whitespace.


isNotEmpty

public boolean isNotEmpty()
Returns true if the current value of this field is not "empty" (see isEmpty()}.


getFilterChainDocument

public FilterChainDocument getFilterChainDocument()

appendFilter

public FilterChainDocument appendFilter(FilterChainDocument.Filter filter)

setEmptyReplacement

public void setEmptyReplacement(Value newEmptyReplacement)
Specifies the Value to substitute when the proposed value is empty. If no "empty replacement" is ever specified, then FormatField defaults to use a zero-length string as the "empty replacement".


setEmptyReplacement

public void setEmptyReplacement(String emptyReplacement)
Specifies the String to substitute when the proposed value is empty. If no "empty replacement" is ever specified, then FormatField defaults to use a zero-length string as the "empty replacement".


getEmptyReplacement

public Value getEmptyReplacement()
Returns the current Value to substitute when the proposed value is empty. If no "empty replacement" is ever specified, then FormatField defaults to use a zero-length string as the "empty replacement".


signalWarning

protected void signalWarning()

addValueListener

public void addValueListener(FormatField.ValueListener l)

removeValueListener

public void removeValueListener(FormatField.ValueListener l)

notifyValueListeners

protected void notifyValueListeners()

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.