ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui
Class JxTextArea

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.JTextArea
                      extended by com.ehsbe.commons.gui.JxTextArea
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class JxTextArea
extends JTextArea

A JTextArea, which checks the Column.length definition of the given entity class and method, to restrict the number of insertable characters. It also validates the field input of editable fields wrt. to the entities nullable annotated method, i.e. the coresponding label is set to color red if validation fails.

Actually this is pure code duplication from JxTextField and could not be avoided because both are direct children of JTextComponent.

Version:
$Revision: 432 $
Author:
Jens Elkner
See Also:
DocumentSizeFilter, JLabel.setLabelFor(java.awt.Component), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTextArea
JTextArea.AccessibleJTextArea
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, 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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String LABEL_COLOR
          property, which is used to remember the original foreground color of the text from an label.
static String LABELED_BY_PROPERTY
          property used by JLabel.setLabelFor(java.awt.Component)
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JxTextArea()
          Default constructor.
JxTextArea(Class<?> entityClass, String methodName, int rows, int columns)
          As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.
JxTextArea(int rows, int columns)
          As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.
JxTextArea(String text)
          As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.
JxTextArea(String text, int rows, int columns)
          As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.
JxTextArea(String text, int rows, int columns, int maxLength, boolean nullable)
          Create a textarea with the given max. input length.
 
Method Summary
 String getDefaultTooltipText()
          Get the default tooltip for this component.
 int getMaxCharacters()
          Get the max. number of characters allowed in this text field.
 String getText()
          
 String getToolTipText()
          If tooltip is set to an empty String, this component tries to obtain the Tooltip from its corresponding label or more exactly from the JComponent stored in this client property map with the key LABELED_BY_PROPERTY.
 Validator<String> getValidator()
          Get the Validator used to check, whether the fields input is valid.
protected  void processFocusEvent(FocusEvent e)
          
 void setDocument(Document doc)
          Same as JTextField.setDocument(javax.swing.text.Document), but sets a document size filter, if the corresponding entity has a size limit and the given document is of type AbstractDocument.
 void setSelectOnFocus(boolean enable)
          Set, whether the component should select all the available text, if it get the focus.
 void setTemplate(Class<?> entityClass, String methodName)
          Adjust the document size filter wrt. the given entity class and method.
 void setText(String t)
          
 void setToolTipText(String text)
          
 void setValidator(Validator<String> validator)
          Set the Validator used to check, whether the fields input is valid.
protected  void validate(String txt)
          If a validator is set, this method validates the input and decorates the component, which used this component in a setLabelFor method.
 
Methods inherited from class javax.swing.JTextArea
append, createDefaultModel, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, replaceRange, setColumns, setFont, setLineWrap, setRows, setTabSize, setWrapStyleWord
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, 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, 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

LABELED_BY_PROPERTY

public static final String LABELED_BY_PROPERTY
property used by JLabel.setLabelFor(java.awt.Component)

See Also:
Constant Field Values

LABEL_COLOR

public static final String LABEL_COLOR
property, which is used to remember the original foreground color of the text from an label.

See Also:
Constant Field Values
Constructor Detail

JxTextArea

public JxTextArea()
Default constructor. As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.


JxTextArea

public JxTextArea(String text)
As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.

Parameters:
text - text to insert into the area

JxTextArea

public JxTextArea(int rows,
                  int columns)
As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.

Parameters:
rows - number of rows of the area
columns - number of columns of the area

JxTextArea

public JxTextArea(String text,
                  int rows,
                  int columns)
As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.

Parameters:
text - text to insert into the area
rows - number of rows of the area
columns - number of columns of the area

JxTextArea

public JxTextArea(String text,
                  int rows,
                  int columns,
                  int maxLength,
                  boolean nullable)
Create a textarea with the given max. input length.

Parameters:
text - text to insert into the area
rows - number of rows of the area
columns - number of columns of the area
maxLength - max length of text, which might be entered.
nullable - if false, an internal validator gets assigned to the field, which makes sure, that only none-empty values are excepted. Furthermore if validation fails and the text filed contains a client property named LABELED_BY_PROPERTY, which contains a JComponent, the components foreground color is set to the color stored in the textfield's property LABEL_COLOR or RED if not set.

JxTextArea

public JxTextArea(Class<?> entityClass,
                  String methodName,
                  int rows,
                  int columns)
As long as no template is set, it behaves like a normal JTextArea, i.e. unrestricted content length.

Parameters:
entityClass - entity class
methodName - name of the method, which should be used to obtain the Column.length() for the field
rows - number of rows of the area. Use 0 for default values.
columns - number of columns of the area. Use 0 for default values.
See Also:
setTemplate(Class, String)
Method Detail

setTemplate

public void setTemplate(Class<?> entityClass,
                        String methodName)
Adjust the document size filter wrt. the given entity class and method.

If both parameters are null or no appropriate annotations are found, this method does nothing. Otherwise it set a new Validator and if the underlying document is not an AbstractDocument, it gets replaced with a new one as well.

Parameters:
entityClass - entity class
methodName - name of the method, which should be used to obtain the Column.length() for the field

getText

public String getText()

Overrides:
getText in class JTextComponent

setText

public void setText(String t)

Overrides:
setText in class JTextComponent

validate

protected void validate(String txt)
If a validator is set, this method validates the input and decorates the component, which used this component in a setLabelFor method.

Parameters:
txt - text to validate

getMaxCharacters

public int getMaxCharacters()
Get the max. number of characters allowed in this text field.

Returns:
-1 if not limited, the max. number of characters otherwise

setDocument

public void setDocument(Document doc)
Same as JTextField.setDocument(javax.swing.text.Document), but sets a document size filter, if the corresponding entity has a size limit and the given document is of type AbstractDocument.

Overrides:
setDocument in class JTextComponent
Parameters:
doc - @inheritDoc

getToolTipText

public String getToolTipText()
If tooltip is set to an empty String, this component tries to obtain the Tooltip from its corresponding label or more exactly from the JComponent stored in this client property map with the key LABELED_BY_PROPERTY. If it is still an empty string and there is a template set, which restricts the number of characters in this document, the max number of character message is returned.

Overrides:
getToolTipText in class JComponent
Returns:
See Also:
getDefaultTooltipText()

setToolTipText

public void setToolTipText(String text)

Overrides:
setToolTipText in class JComponent

getDefaultTooltipText

public String getDefaultTooltipText()
Get the default tooltip for this component.

Returns:
always a none-null value

getValidator

public Validator<String> getValidator()
Get the Validator used to check, whether the fields input is valid.

Per default a validator gets automatically installed, if the @Column's nullable property is set to false. It accepts none-whitespace/null values, only.

Returns:
null if not set, the validator otherwise.

setValidator

public void setValidator(Validator<String> validator)
Set the Validator used to check, whether the fields input is valid.

Parameters:
validator - null to disable validation, the validator otherwise.

setSelectOnFocus

public void setSelectOnFocus(boolean enable)
Set, whether the component should select all the available text, if it get the focus.

Parameters:
enable - if true enable select all on focus gained.

processFocusEvent

protected void processFocusEvent(FocusEvent e)

Overrides:
processFocusEvent in class Component

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.