|
Rational Developer for Power Systems Software V7.6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.text.JTextComponent javax.swing.JTextField com.ibm.etools.iseries.ui.JFormattedTextField
public class JFormattedTextField
JFormattedTextField extends javax.swing.JTextField and implements com.ibm.etools.iseries.ui.JFormattedComponent. It is a text field that allows you to define a field model, from which a formatter, validator, keystroke verifier, and data attributes can be specified. By default, JFormattedTextField uses AS400FieldModel. By default, the AS400FieldModel uses EditcodeEditwordFormatter, ComparisonRangeValidator, NumericCharacterDocument, character data type, a data length of 10, and 0 decimal places.
A formatter defines how a string can be formatted. Any data that the you enter will be validated by the validator and formatted automatically in the format defined by the formatter. Using the EditcodeEditwordFormatter class allows you to select an editcode or set a user-defined editword. If none of the editcodes or editwords provided meet your requirements, you can create your own formatter class and set the field model of the JFormattedTextField to use your defined formatter.
A validator is a class that can validate field values. Text that is set to the field is passed to a validator for validation before being formatted and set. In addition to validating data, the JFormattedTextField also validates the data type, data length, and decimal places of the data. There is a ComparisonRangeValidator class which performs a 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 your requirements, you can write your own validator class and set the JFormattedTextField's field model to use the newly-defined validator.
A keystroke verifier is a document class that is used to verify keystroke entry. A document is a data model in a Model-View-Controller (MVC) relationship that controls the data input. Characters that are not defined in the data model are not allowed to be entered; there will be a beep to notify you at a keystroke level. There are two predefined keystroke verifier classes: NumericCharacterDocument and UpperCaseDocument. If none of these keystroke verifier document classes meet your requirements, you can write your own document class and set the JFormattedTextField's field model to use that class.
DataAttributes is a used to hold the field attributes such as auto advance flag, 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, which means that the control will not automatically advance to the next component when the maximum data length of the field is reached. Additionally, the data type is set to character; data length is set to 10; the decimal point symbol will automatically pick up the locale value of a decimal point; the decimal places are 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.
There is a property called editmaskAttributes. When editmask is set together with editword in an EditmaskAttributes property, the view (i.e. the look of the textfield component) will change with the editmask characters appearing as part of the field. For example, if editword is "(bbb)bbb-bbbb" (where b is a blank) and editmask is "&bbb&bbb&bbbb", then the parentheses, ( and ), and hyphen (-) characters will appear in the field prior to any data entry. These characters will stay anchored in the field and you will not be able to change or delete them. You can only enter characters where a blank is specified, and the cursor will automatically skip over the editmask characters. Note: the editmask feature can only work with an editword that is specified in EditmaskAttributes. It can work for both numeric and character data types.The length of both editmask and editword should be identical and their number of blanks should be equal to the dataLength set in DataAttributes; otherwise unpredictable results may occur. Please also note that the editmaskAttributes property must be set to an instance of com.ibm.etools.iseries.ui.EditmaskAttributes; otherwise, java.beans.PropertyVetoException will be thrown at run time.
The editmask feature has to change the view (i.e. the look of a textfield component) of the JFormattedTextField and will automatically change its UI to EditmaskViewMetalTextFieldUI by default. It is not necessary for you to change the EditmaskViewUI, however, experienced users can explicitly set the appropriate UI. EditmaskViewUI should be set after EditmaskAttributes is set. Experienced users can even create their own UI class to completely change the look of the textfield component as they like. If both editword and editmask are set to "" in editmaskAttributes, then JFormattedTextField will use the default UI of JTextField, which is normally MetalTextFieldUI. There are three predefined UIs for EditmaskPlainView. They are: EditmaskViewMetalTextFieldUI, EditmaskViewBasicTextFieldUI and EditmaskViewWindowsTextFieldUI.
// JFormattedTextField in numeric data type with length of 9 and // size of decimal places is 2, and with editcode '1' format // and validity check in range from "1000.00" to "4999999.99". // The field is right aligned. Attributes dataAtt1 = new DataAttributes(DataAttributes.DATATYPE_NUMERIC, 9, 2, '.'); Formatter formatter1 = new EditcodeEditwordFormatter(dataAtt1,'1', EditcodeEditwordFormatter.EDITCODEPARM_CURRENCY, null); Validator val1 = new ComparisonRangeValidator(dataAtt1, ComparisonRangeValidator.VALIDITYTYPE_RANGE, ComparisonRangeValidator.COMPARISON_NONE, null, "1000.00", "4999999.99"); JFormattedTextField jfTextField1 = new JFormattedTextField(new AS400FieldModel(dataAtt1, formatter1, val1)); jfTextField1.setHorizontalAlignment(JTextField.RIGHT); jfTextField1.setPreferredSize(new Dimension(150,25)); panel.add(jfTextField1);
// JFormattedTextField in numeric data type with length of 10 and // using editmask feature, without formatting and validation. // The default keystroke verifier is NumericCharacterDocument // in AS400FieldModel. Attributes dataAtt2 = new DataAttributes(DataAttributes.DATATYPE_NUMERIC, 10); Attributes editmaskAtt2 = new EditmaskAttributes("( ) - ", "& & & "); JFormattedTextField jfTextField2 = new JFormattedTextField(new AS400FieldModel(dataAtt2)); try { jfTextField2.setEditmaskAttributes(editmaskAtt2); } catch (Exception ex) { ex.printStackTrace(); } jfTextField2.setPreferredSize(new Dimension(150,25)); panel.add(jfTextField2);
// JFormattedTextField in character data type of length 15, // use UpperCaseDocument as the keystroke verifier. No formatting and // validation. Attributes dataAtt3 = new DataAttributes(DataAttributes.DATATYPE_CHARACTER, 15); javax.swing.text.Document keyVer = new UpperCaseDocument(dataAtt3); JFormattedTextField jfTextField3 = new JFormattedTextField(new AS400FieldModel(dataAtt3, null, null, keyVer)); jfTextField3.setPreferredSize(new Dimension(150,25)); panel.add(jfTextField3);
FieldModel
,
AS400FieldModel
,
JFormattedTextField
,
FormattedComboBoxEditor
,
DataAttributes
,
EditcodeEditwordFormatter
,
ComparisonRangeValidator
,
NumericCharacterDocument
,
UpperCaseDocument
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JTextField |
---|
JTextField.AccessibleJTextField |
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 |
Copyright
|
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.ibm.etools.iseries.ui.JFormattedComponent |
---|
copyright |
Fields inherited from interface com.ibm.etools.iseries.ui.EditmaskAttributesChangeListener |
---|
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 | |
---|---|
JFormattedTextField()
Constructs a new JFormattedTextField. |
|
JFormattedTextField(Document doc,
String text,
int columns)
Constructs a new JFormattedTextField. |
|
JFormattedTextField(Document doc,
String text,
int columns,
FieldModel fieldModel)
Constructs a new JFormattedTextField. |
|
JFormattedTextField(FieldModel fieldModel)
Creates a JFormattedTextField with the specified field model. |
|
JFormattedTextField(int columns)
Constructs a new JFormattedTextField with the specified number of columns. |
|
JFormattedTextField(String text)
Constructs a new JFormattedTextField. |
|
JFormattedTextField(String text,
int columns)
Constructs a new JFormattedTextField. |
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. |
void |
editmaskAttributesChanged(EditmaskAttributesChangeEvent evt)
Whenever a bound property of EditmaskAttributes changes, a EditmaskAttributesChangeEvent is fired and this method will be called by the EditmaskAttributesChangeListener. |
void |
focusGained(FocusEvent e)
Called when the component gain focus. |
void |
focusLost(FocusEvent e)
Called when the component lost focus. |
Color |
getBackground()
Get the current background color of the component. |
Attributes |
getEditmaskAttributes()
|
EditmaskViewInterface |
getEditmaskViewUI()
Gets the editmaskViewUI property (com.ibm.etools.iseries.ui.EditmaskViewInterface) value. |
FieldModel |
getFieldModel()
|
String |
getInternalValue()
|
String |
getText()
Get the current text with format. |
String |
getUnformattedText()
|
protected boolean |
isValueValid(String strText)
|
protected boolean |
isValueValidForNumeric(String strText)
|
protected void |
processFocusEvent(FocusEvent fEvent)
|
void |
setBackground(Color c)
Set the background color of the component. |
void |
setEditmaskAttributes(Attributes ea)
Sets the editmaskAttributes property (com.ibm.etools.iseries.ui.Attributes) value. |
void |
setEditmaskViewUI(EditmaskViewInterface newui)
Sets the editmaskViewUI property value. |
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)
Whatever specified in the parameter string will be formatted only if data is valid. |
void |
setUnformattedText(String text)
The specified text 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String Copyright
Constructor Detail |
---|
public JFormattedTextField()
public JFormattedTextField(int columns)
columns
- the number of columns to use to calculate the preferred width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.public JFormattedTextField(FieldModel fieldModel)
fieldModel
- The field model for formatting, validating and keystroke verifying.public JFormattedTextField(String text)
text
- the initial string to display, or null.public JFormattedTextField(String text, int columns)
text
- the initial string to display, or null.columns
- the number of columns to use to calculate the preferred width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.public JFormattedTextField(Document doc, String text, int columns)
doc
- the text storage to use.text
- the initial string to display, or null.columns
- the number of columns to use to calculate the preferred width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.public JFormattedTextField(Document doc, String text, int columns, FieldModel fieldModel)
doc
- the text storage to use.text
- the initial string to display, or null.columns
- the number of columns to use to calculate the preferred width. If columns is set to zero, the preferred width will be whatever
naturally results from the component implementation.fieldModel
- The field model for formatting, validating and keystroke verifying.Method Detail |
---|
public String convertInternalToUnformatted(String value)
value
- java.lang.String
public String convertUnformattedToInternal(String text)
value
- java.lang.String
public static String Copyright()
public void editmaskAttributesChanged(EditmaskAttributesChangeEvent evt)
editmaskAttributesChanged
in interface EditmaskAttributesChangeListener
evt
- com.ibm.etools.iseries.ui.EditmaskAttributesChangeEventpublic void focusGained(FocusEvent e)
focusGained
in interface FocusListener
e
- java.awt.event.FocusEventpublic void focusLost(FocusEvent e)
focusLost
in interface FocusListener
e
- java.awt.event.FocusEventpublic Color getBackground()
getBackground
in class Component
public Attributes getEditmaskAttributes()
public EditmaskViewInterface getEditmaskViewUI()
public FieldModel getFieldModel()
getFieldModel
in interface JFormattedComponent
public String getInternalValue()
public String getText()
getText
in class JTextComponent
public String getUnformattedText()
protected boolean isValueValid(String strText)
protected boolean isValueValidForNumeric(String strText)
protected void processFocusEvent(FocusEvent fEvent)
processFocusEvent
in class Component
public void setBackground(Color c)
setBackground
in class JComponent
c
- java.awt.ColorgetBackground()
public void setEditmaskAttributes(Attributes ea) throws PropertyVetoException
ea
- The new value for the property.
PropertyVetoException
getEditmaskAttributes()
public void setEditmaskViewUI(EditmaskViewInterface newui)
newui
- The new value for the property.getEditmaskViewUI()
public void setFieldModel(FieldModel fm)
setFieldModel
in interface JFormattedComponent
fm
- The new value for the property.getFieldModel()
public void setInternalValue(String value) throws InvalidDataException
value
- java.lang.String
InvalidDataException
getInternalValue()
public void setText(String text)
setText
in class JTextComponent
text
- java.lang.StringgetText()
public void setUnformattedText(String text) throws InvalidDataException
text
- java.lang.String
InvalidDataException
getUnformattedText()
|
Rational Developer for Power Systems Software V7.6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |