Rational Developer for Power Systems Software
V7.6

com.ibm.etools.iseries.ui
Class JFormattedLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by com.ibm.etools.iseries.ui.JFormattedLabel
All Implemented Interfaces:
JFormattedComponent, ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants
Direct Known Subclasses:
FormattedTextRenderer, JFormattedLabelCellRenderer

public class JFormattedLabel
extends JLabel
implements JFormattedComponent

JFormattedLabel extends javax.swing.JLabel and implements com.ibm.etools.iseries.ui.JFormattedComponent. It is a label that allows you to define a field model, which can then specify a formatter, a validator, a keystroke verifier, and data attributes. Keystroke verifier has no effect on this component, because it is not a data entry type component. By default, JFormattedLabel uses AS400FieldModel which by default uses EditcodeEditwordFormatter, ComparisonRangeValidator, and the default data type is character, data length is 10, and decimal places is 0.

A formatter defines how a string can be formatted. Any data that is set using setUnformattedText method is formatted automatically and shown in the label in the format defined by the formatter. There is a EditcodeEditwordFormatter class that the AS/400 user can use. It allows you to select an editcode or set a user-defined editword. If none of the editcodes or editword meet the user requirements, users can create their own formatter class and set the JFormattedLabel's field model to use the user-defined formatter.

A validator is a class which can validate field values. Any data that is set in the field will be passed to a validator for validation prior to formatting and setting the text. Apart from the validator that validates the data, the JFormattedLabel itself also validates the data type, data length, and decimal places of the field. There is a ComparisonRangeValidator class which performs comparison validation or range validation. A comparison validation compares a field value in relation to another value. A range validation validates against a range of values. Again, if ComparisonRangeValidator does not meet the user requirements, users can write their own validator class and set the JFormattedLabel's field model to use the newly defined validator.

A keystroke verifier is a document class to that is used to verify keystroke entry. Since JFormattedLabel is not an entry type of component, anything that is set in the keystroke verifier field will be ignored. This property is only useful in JFormattedTextField and JFormattedComboBox.

DataAttributes is a used to hold field attributes such as auto advance flag (this flag is ignored in JFormattedLabel and is only used by JFormattedTextField and JFormattedComboBox), data type, data length, decimal point symbol, size of decimal places and background color when invalid entry occurs. By default, auto advance flag is set to false, data type is set to character, data length is 10, decimal point symbol will automatically pick up the locale value of a decimal point; decimal places is set to 0, and the reverseImageColor is set to java.awt.Color.red. These are bound properties, so you can change these values as you wish. Please note that the Attributes field must be an instance of com.ibm.etools.iseries.ui.DataAttributes; otherwise java.beans.PropertyVetoException will be thrown at run time. Property autoAdvance and reverseImageColor have no effect on a JFormattedLabel, whatever is set will be ignored.

        Attributes dataAtt   = new DataAttributes(DataAttributes.DATATYPE_NUMERIC, 10, 2, '.');
        Formatter  formatter = new EditcodeEditwordFormatter(dataAtt,'A',
                                                                EditcodeEditwordFormatter.EDITCODEPARM_CURRENCY,
                                                                null);
        Validator  val       = new ComparisonRangeValidator(dataAtt, 
                                                                ComparisonRangeValidator.VALIDITYTYPE_COMPARISON,
                                                                ComparisonRangeValidator.COMPARISON_EQ, 
                                                                "1000.00", null, null);
        JFormattedLabel jfLabel = new JFormattedLabel("1000.00", null, SwingConstants.CENTER,
                                 new AS400FieldModel(dataAtt, formatter, val));
 

See Also:
FieldModel, AS400FieldModel, DataAttributes, EditcodeEditwordFormatter, ComparisonRangeValidator, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
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 Copyright
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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.ibm.etools.iseries.ui.JFormattedComponent
copyright
 
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
JFormattedLabel()
          Constructs a new JFormattedLabel.
JFormattedLabel(Attributes dataAttributes, Formatter formatter, Validator validator, Font font)
          /** Creates a JFormattedLabel with the specified dataAttributes, formatter, validator and font.
JFormattedLabel(FieldModel fm)
          Creates a JFormattedLabel with the specified field model.
JFormattedLabel(Icon image)
          Creates a JFormattedLabel instance with the specified image.
JFormattedLabel(Icon image, int horizontalAlignment)
          Creates a JLabel instance with the specified image and horizontal alignment.
JFormattedLabel(String text)
          JFormattedLabel constructor comment.
JFormattedLabel(String text, Icon icon, int horizontalAlignment)
          JFormattedLabel constructor comment.
JFormattedLabel(String text, Icon icon, int horizontalAlignment, FieldModel fm)
          This method was created in VisualAge.
JFormattedLabel(String text, int horizontalAlignment)
          JFormattedLabel constructor comment.
 
Method Summary
 String convertInternalToUnformatted(String value)
          Convert an internal value to an unformatted value.
 String convertUnformattedToInternal(String text)
          Convert an unformatted value to an internal value.
static String Copyright()
          This method returns the copyright notice for this class.
 FieldModel getFieldModel()
           
 String getInternalValue()
           
 String getUnformattedText()
           
protected  boolean isValueValid(String strText)
           
protected  boolean isValueValidForNumeric(String strText)
           
 void setFieldModel(FieldModel fm)
          Sets the fieldModel property (com.ibm.etools.iseries.ui.FieldModel) value.
 void setInternalValue(String value)
          The specified value will be validated by calling isValueValid method and by the validator, then it will be formatted by the formatter before setting it to the component.
 void setText(String text)
          Defines the single line of text this component will display.
 void setUnformattedText(String text)
          Defines the single line of text this component will validated and formatted prior to the display.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, 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, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, 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, addInputMethodListener, 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, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, 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

Copyright

public static final String Copyright
See Also:
Constant Field Values
Constructor Detail

JFormattedLabel

public JFormattedLabel()
Constructs a new JFormattedLabel.


JFormattedLabel

public JFormattedLabel(Attributes dataAttributes,
                       Formatter formatter,
                       Validator validator,
                       Font font)
/** Creates a JFormattedLabel with the specified dataAttributes, formatter, validator and font. Please note that the first parameter must be an instance of com.ibm.etools.iseries.ui.DataAttributes; otherwise ClassCastException will be thrown at run time.

Parameters:
dataAttributes - The data attributes sucn as data type, data length, decimal places, etc.
formatter - The formatting used.
validator - The validation used.
font - The font in the label.

JFormattedLabel

public JFormattedLabel(FieldModel fm)
Creates a JFormattedLabel with the specified field model.

Parameters:
fm - The field model for formatting and validating.

JFormattedLabel

public JFormattedLabel(String text)
JFormattedLabel constructor comment.

Parameters:
text - The text to be displayed by the label.

JFormattedLabel

public JFormattedLabel(String text,
                       int horizontalAlignment)
JFormattedLabel constructor comment.

Parameters:
text - The text to be displayed by the label.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, or RIGHT.

JFormattedLabel

public JFormattedLabel(String text,
                       Icon icon,
                       int horizontalAlignment)
JFormattedLabel constructor comment.

Parameters:
text - The text to be displayed by the label.
icon - The image to be displayed by the label.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, or RIGHT.

JFormattedLabel

public JFormattedLabel(String text,
                       Icon icon,
                       int horizontalAlignment,
                       FieldModel fm)
This method was created in VisualAge.

Parameters:
text - The text to be displayed by the label.
icon - The image to be displayed by the label.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, or RIGHT.
fm - The field model for formatting and validating.

JFormattedLabel

public JFormattedLabel(Icon image)
Creates a JFormattedLabel instance with the specified image.

Parameters:
image - The image to be displayed by the label.

JFormattedLabel

public JFormattedLabel(Icon image,
                       int horizontalAlignment)
Creates a JLabel instance with the specified image and horizontal alignment.

Parameters:
image - The image to be displayed by the label.
horizontalAlignment - One of the following constants defined in SwingConstants: LEFT, CENTER, or RIGHT.
Method Detail

convertInternalToUnformatted

public String convertInternalToUnformatted(String value)
Convert an internal value to an unformatted value.

Parameters:
value - java.lang.String
Returns:
java.lang.String

convertUnformattedToInternal

public String convertUnformattedToInternal(String text)
Convert an unformatted value to an internal value.

Parameters:
value - java.lang.String
Returns:
java.lang.String

Copyright

public static String Copyright()
This method returns the copyright notice for this class.

Returns:
java.lang.String

getFieldModel

public FieldModel getFieldModel()
Specified by:
getFieldModel in interface JFormattedComponent

getInternalValue

public String getInternalValue()

getUnformattedText

public String getUnformattedText()

isValueValid

protected boolean isValueValid(String strText)

isValueValidForNumeric

protected boolean isValueValidForNumeric(String strText)

setFieldModel

public void setFieldModel(FieldModel fm)
Sets the fieldModel property (com.ibm.etools.iseries.ui.FieldModel) value.

Specified by:
setFieldModel in interface JFormattedComponent
Parameters:
fm - The new value for the property.
See Also:
getFieldModel()

setInternalValue

public void setInternalValue(String value)
                      throws InvalidDataException
The specified value will be validated by calling isValueValid method and by the validator, then it will be formatted by the formatter before setting it to the component. If the text string is an invalid data, InvalidDataException will be thrown and text will not be set.

Parameters:
value - java.lang.String
Throws:
InvalidDataException
See Also:
getInternalValue()

setText

public void setText(String text)
Defines the single line of text this component will display. Whatever specified in the parameter string will be formatted only if data is valid. If data is invalid, exception will not be thrown as in setUnformattedText().

Overrides:
setText in class JLabel
Parameters:
text - java.lang.String

setUnformattedText

public void setUnformattedText(String text)
                        throws InvalidDataException
Defines the single line of text this component will validated and formatted prior to the display. If the text string is an invalid data, InvalidDataException will be thrown.

Parameters:
text - java.lang.String
Throws:
InvalidDataException

Rational Developer for Power Systems Software
V7.6

Copyright © 2011 IBM Corp. All Rights Reserved.

Note: This documentation is for part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.