com.metamatrix.toolbox.ui.widget
Class TextFieldWidget

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.metamatrix.toolbox.ui.widget.TextFieldWidget
All Implemented Interfaces:
TextConstants, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable, javax.swing.SwingConstants
Direct Known Subclasses:
NoMinTextFieldWidget, URLTextFieldWidget

public class TextFieldWidget
extends javax.swing.JTextField
implements TextConstants

This class is intended to be used everywhere within the application that a single-line text Textor (similar to JTextField) needs to be displayed. It provides the following features:

Since:
2.0
Version:
2.0
Author:
John P. A. Verhaeg
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTextField
javax.swing.JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String BACKGROUND_COLOR_PROPERTY
           
static java.lang.String COLUMN_WIDTH_CHARACTER_PROPERTY
           
static java.lang.String FOREGROUND_COLOR_PROPERTY
           
static java.lang.String INVALID_BACKGROUND_COLOR_PROPERTY
           
static java.lang.String INVALID_FOREGROUND_COLOR_PROPERTY
           
static java.lang.String PROPERTY_PREFIX
           
 
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 com.metamatrix.toolbox.ui.widget.text.TextConstants
IS_MODIFIED_PROPERTY, IS_VALID_PROPERTY, MAXIMUM_LENGTH_PROPERTY, TEXT_PROPERTY
 
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
TextFieldWidget()
          Creates a blank field with no constraints.
TextFieldWidget(int characters)
          Creates a blank field wide enough to display the specified number of characters.
TextFieldWidget(java.lang.String text)
          Creates a field populated with the specified text, and wide enough to display the text.
TextFieldWidget(java.lang.String text, int characters)
          Creates a field populated with the specified text, and wide enough to display the specified number of characters.
 
Method Summary
protected  void buildContextMenu()
          Builds a context menu containing a default set of options to cut, copy, and paste.
 boolean commit()
          Commits any new text set on the model.
protected  javax.swing.text.Document createDefaultModel()
          Overridden to create a DefaultTextFieldModel instead of the default model created by JTextField.
 javax.swing.JToolTip createToolTip()
           
 void cut()
           
 int getColumnWidth()
           
 char getColumnWidthCharacter()
           
 javax.swing.JPopupMenu getContextMenu()
           
 java.awt.Dimension getMaximumSize()
          Overridden to force the field's maximum height to match its preferred height.
 java.awt.Dimension getMinimumSize()
          Overridden to force the field's minimum height to match its preferred height.
 java.awt.Dimension getPreferredSize()
          Overridden to force the field's preferred height to be immutable.
protected  void initializeTextFieldWidget()
          Builds a context menu containing a default set of options to cut, copy, and paste.
 boolean isClipTipEnabled()
           
 boolean isContextMenuEnabled()
           
 boolean isErrorTipEnabled()
           
 boolean isTextValid()
           
 void paste()
           
 void rollback()
          Rollsback to the previous value in the model.
 void scrollRectToVisible(java.awt.Rectangle rectangle)
          Overridden to provide a tooltip containing the full text whenever the text is clipped.
 void selectText()
          Selects all of the current text.
 void setClipTipEnabled(boolean isClipTipEnabled)
          Sets whether a tooltip will be displayed containing the full text whenever the text is clipped.
protected  void setClipTipText()
          Sets a tooltip containing the full text whenever the text is clipped.
 void setColumnWidth(int width)
          Setting the column width to zero will cause the column width to be recalculated from the current column width character.
 void setColumnWidthCharacter(char character)
          Sets the character to use when calculating pixel widths that are based upon a character count.
 void setContextMenuEnabled(boolean isMenuEnabled)
          Sets whether a pop-up context menu will be displayed when the user right-clicks the mouse.
 void setErrorTipEnabled(boolean isErrorTipEnabled)
          Sets whether a tooltip will be displayed when the text is marked as invalid.
 void setFont(java.awt.Font font)
           
 void setInvalidCharacters(java.lang.String invalidCharacters)
          A convenience method to set the list of invalid characters in the model.
 void setMaximumSize(java.awt.Dimension size)
          Overridden to force the field's maximum height to match its preferred height.
 void setMaximumWidth(int width)
          Sets the maximum pixel width of the field.
 void setMinimumSize(java.awt.Dimension size)
          Overridden to force the field's minimum height to match its preferred height.
 void setMinimumWidth(int width)
          Sets the minimum pixel width of the field.
 void setPreferredSize(java.awt.Dimension size)
          Overridden to force the field's preferred height to be immutable.
 void setPreferredWidth(int width)
          Sets the preferred pixel width of the field.
 void setText(java.lang.String text)
           
 void setValidCharacters(java.lang.String validCharacters)
          A convenience method to set the list of valid characters in the model.
 java.lang.String toString()
           
protected  void validateModel()
          Determines if the model is valid.
 
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getHorizontalAlignment, getHorizontalVisibility, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, setAction, setActionCommand, setColumns, setDocument, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, 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, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, 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, 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, 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, setNextFocusableComponent, setOpaque, 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, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_PREFIX

public static final java.lang.String PROPERTY_PREFIX
See Also:
Constant Field Values

BACKGROUND_COLOR_PROPERTY

public static final java.lang.String BACKGROUND_COLOR_PROPERTY
See Also:
Constant Field Values

FOREGROUND_COLOR_PROPERTY

public static final java.lang.String FOREGROUND_COLOR_PROPERTY
See Also:
Constant Field Values

INVALID_BACKGROUND_COLOR_PROPERTY

public static final java.lang.String INVALID_BACKGROUND_COLOR_PROPERTY
See Also:
Constant Field Values

INVALID_FOREGROUND_COLOR_PROPERTY

public static final java.lang.String INVALID_FOREGROUND_COLOR_PROPERTY
See Also:
Constant Field Values

COLUMN_WIDTH_CHARACTER_PROPERTY

public static final java.lang.String COLUMN_WIDTH_CHARACTER_PROPERTY
See Also:
Constant Field Values
Constructor Detail

TextFieldWidget

public TextFieldWidget()
Creates a blank field with no constraints.

Since:
2.0

TextFieldWidget

public TextFieldWidget(java.lang.String text)
Creates a field populated with the specified text, and wide enough to display the text.

Parameters:
text - The initial text
Since:
2.0

TextFieldWidget

public TextFieldWidget(int characters)
Creates a blank field wide enough to display the specified number of characters.

Parameters:
characters - The width of the field
Since:
2.0

TextFieldWidget

public TextFieldWidget(java.lang.String text,
                       int characters)
Creates a field populated with the specified text, and wide enough to display the specified number of characters.

Parameters:
text - The initial text
characters - The width of the field
Since:
2.0
Method Detail

buildContextMenu

protected void buildContextMenu()
Builds a context menu containing a default set of options to cut, copy, and paste.

Since:
2.0

paste

public void paste()
Overrides:
paste in class javax.swing.text.JTextComponent

cut

public void cut()
Overrides:
cut in class javax.swing.text.JTextComponent

commit

public boolean commit()
Commits any new text set on the model.

Returns:
True if text is valid and successfully committed
Since:
2.0

createDefaultModel

protected javax.swing.text.Document createDefaultModel()
Overridden to create a DefaultTextFieldModel instead of the default model created by JTextField. Called by JTextField's constructor.

Overrides:
createDefaultModel in class javax.swing.JTextField
Returns:
An instance of DefaultTextFieldModel
Since:
2.0

createToolTip

public javax.swing.JToolTip createToolTip()
Overrides:
createToolTip in class javax.swing.JComponent

getColumnWidth

public int getColumnWidth()
Overrides:
getColumnWidth in class javax.swing.JTextField
Returns:
The width of a column as determined by the current column width character
Since:
2.0

getColumnWidthCharacter

public char getColumnWidthCharacter()
Since:
2.0

getContextMenu

public javax.swing.JPopupMenu getContextMenu()
Since:
2.0

getMaximumSize

public java.awt.Dimension getMaximumSize()
Overridden to force the field's maximum height to match its preferred height.

Overrides:
getMaximumSize in class javax.swing.JComponent
Returns:
The maximum size of the field
Since:
2.0

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overridden to force the field's minimum height to match its preferred height.

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
The minimum size of the field
Since:
2.0

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overridden to force the field's preferred height to be immutable.

Overrides:
getPreferredSize in class javax.swing.JTextField
Returns:
The preferred size of the field
Since:
2.0

initializeTextFieldWidget

protected void initializeTextFieldWidget()
Builds a context menu containing a default set of options to cut, copy, and paste.

Since:
2.0

isClipTipEnabled

public boolean isClipTipEnabled()
Returns:
True if the clip tip feature is enabled
Since:
2.0

isContextMenuEnabled

public boolean isContextMenuEnabled()
Returns:
True if the context menu is enabled
Since:
2.0

isErrorTipEnabled

public boolean isErrorTipEnabled()
Returns:
True if the error tip feature is enabled
Since:
2.0

isTextValid

public boolean isTextValid()
Since:
2.0

rollback

public void rollback()
Rollsback to the previous value in the model.

Since:
2.0

scrollRectToVisible

public void scrollRectToVisible(java.awt.Rectangle rectangle)
Overridden to provide a tooltip containing the full text whenever the text is clipped.

Overrides:
scrollRectToVisible in class javax.swing.JTextField
Since:
2.0
See Also:
JTextField.scrollRectToVisible(Rectangle), setClipTipText()

selectText

public void selectText()
Selects all of the current text.

Since:
2.0

setClipTipEnabled

public void setClipTipEnabled(boolean isClipTipEnabled)
Sets whether a tooltip will be displayed containing the full text whenever the text is clipped.

Parameters:
isClipTipEnabled - True if a tooltip should be displayed when text is clipped
Since:
2.0

setClipTipText

protected void setClipTipText()
Sets a tooltip containing the full text whenever the text is clipped.

Since:
2.0

setColumnWidth

public void setColumnWidth(int width)
Setting the column width to zero will cause the column width to be recalculated from the current column width character.

Parameters:
width - The preferred pixel width
Since:
2.0

setColumnWidthCharacter

public void setColumnWidthCharacter(char character)
Sets the character to use when calculating pixel widths that are based upon a character count.

Since:
2.0

setContextMenuEnabled

public void setContextMenuEnabled(boolean isMenuEnabled)
Sets whether a pop-up context menu will be displayed when the user right-clicks the mouse.

Parameters:
isMenuEnabled - True if a menu should be displayed
Since:
2.0

setErrorTipEnabled

public void setErrorTipEnabled(boolean isErrorTipEnabled)
Sets whether a tooltip will be displayed when the text is marked as invalid.

Parameters:
isErrorTipEnabled - True if a tooltip should be displayed when text is marked as invalid
Since:
2.0

setFont

public void setFont(java.awt.Font font)
Overrides:
setFont in class javax.swing.JTextField
Since:
2.0

setInvalidCharacters

public void setInvalidCharacters(java.lang.String invalidCharacters)
                          throws java.text.ParseException
A convenience method to set the list of invalid characters in the model.

Parameters:
invalidCharacters - A list of invalid characters and/or character ranges
Throws:
java.text.ParseException - If a syntax error was found while parsing invalidCharacters
Since:
2.0
See Also:
DefaultTextFieldModel.setInvalidCharacters(String)

setMaximumSize

public void setMaximumSize(java.awt.Dimension size)
Overridden to force the field's maximum height to match its preferred height.

Overrides:
setMaximumSize in class javax.swing.JComponent
Since:
2.0
See Also:
JComponent.setMaximumSize(Dimension)

setMaximumWidth

public void setMaximumWidth(int width)
Sets the maximum pixel width of the field.

Parameters:
width - The maximum pixel width
Since:
2.0

setMinimumSize

public void setMinimumSize(java.awt.Dimension size)
Overridden to force the field's minimum height to match its preferred height.

Overrides:
setMinimumSize in class javax.swing.JComponent
Since:
2.0
See Also:
JComponent.setMinimumSize(Dimension)

setMinimumWidth

public void setMinimumWidth(int width)
Sets the minimum pixel width of the field.

Parameters:
width - The minimum pixel width
Since:
2.0

setPreferredSize

public void setPreferredSize(java.awt.Dimension size)
Overridden to force the field's preferred height to be immutable.

Overrides:
setPreferredSize in class javax.swing.JComponent
Since:
2.0
See Also:
JComponent.setPreferredSize(Dimension)

setPreferredWidth

public void setPreferredWidth(int width)
Sets the preferred pixel width of the field.

Parameters:
width - The preferred pixel width
Since:
2.0

setText

public void setText(java.lang.String text)
Overrides:
setText in class javax.swing.text.JTextComponent
Since:
2.0

setValidCharacters

public void setValidCharacters(java.lang.String validCharacters)
                        throws java.text.ParseException
A convenience method to set the list of valid characters in the model.

Parameters:
validCharacters - A list of valid characters and/or character ranges
Throws:
java.text.ParseException - If a syntax error was found while parsing validCharacters
Since:
2.0
See Also:
DefaultTextFieldModel.setValidCharacters(String)

toString

public java.lang.String toString()
Overrides:
toString in class java.awt.Component
Since:
2.0

validateModel

protected void validateModel()
Determines if the model is valid. Changes the field's colors to white on red by default and creates an error tooltip if not.

Since:
2.0


Copyright © 2009. All Rights Reserved.