|
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.JComboBox com.ibm.etools.iseries.ui.JFormattedComboBox
public class JFormattedComboBox
JFormattedComboBox extends javax.swing.JComboBox and implements com.ibm.etools.iseries.ui.JFormattedComponent. It is a combo box that allows you to define a field model, which can then specify a formatter, a validator, a keystroke verifier, and data attributes. By default, JFormattedComboBox uses AS400FieldModel which by default uses EditcodeEditwordFormatter, ComparisonRangeValidator, NumericCharacterDocument, 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. If the combo box is set to editable, the editor used is a JFormattedTextField. Any data that the user types in will be validated by the validator and will be formatted automatically in the format defined in the formatter when the user has finished typing in the field; that is, when the focus is lost from the comboBox. Data input into an editable field and any string that is added to the combo box pull down list will be validated and formatted automatically. There is an 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 editwords meet the user requirements, users can create their own formatter class and set the JFormattedComboBox's field model to use the user-defined formatter.
A validator is a class that can validate field values. Text that is entered in an editable field or items added to the combo box list can be passed to a validator for validation prior passing it to formatting and setting the text. Apart from the validator that validates the data, the JFormattedComboBox itself also validates the data type, data length, and decimal places of an editable field or an item added to the list. 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 the user requirements, users can write their own validator class and set the JFormattedComboBox'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 an 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 the user at a keystroke level. There are two predefined keystroke verifier classes: NumericCharacterDocument and UpperCaseDocument. If none of these keystroke verifier document classes meet the user requirements, users can write their own document class and set the JFormattedComboBox's field model to use the user-defined class.
DataAttributes is a class that is 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, autoAdvance is set to false, which means that if a JFormattedComboBox component is editable, 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; the data length is 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.
JFormattedComboBox does not support the editmask feature.
Experienced users can also define or change the FormattedComboBoxEditor. FormattedComboBoxEditor is a ComboBoxEditor, which defines the editor of the editable field. The default editor is MetalFormattedComboBoxEditor which uses JFormattedTextField as the editor. The predefined FormattedComboBoxEditor classes are BasicFormattedComboBoxEditor and MetalFormattedComboBoxEditor.
Experienced users can also define their own ListCellRenderer. The default ListCellRenderer is FormattedTextRenderer which uses JFormattedLabel as cells in the pull down list of the combo box.
The following is a sample:
import javax.swing.*; import java.awt.*; import java.awt.event.*; import com.ibm.etools.iseries.ui.*; public class JFormattedComboBoxSample extends javax.swing.JFrame { class MyWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) {System.exit(0);} } public JFormattedComboBoxSample() { super("JFormattedComboBox"); setSize(350,100); getContentPane().setLayout(new java.awt.FlowLayout()); JPanel pr = new JPanel(); Attributes att = new DataAttributes(DataAttributes.DATATYPE_NUMERIC, 10); Formatter formatter = new EditcodeEditwordFormatter(att, '0', EditcodeEditwordFormatter.EDITCODEPARM_NONE, "0( ) - "); String data[] = {"4161112222", "1234567890", "9057778888", "4165556666"}; JFormattedComboBox cb = new JFormattedComboBox(data,new AS400FieldModel(att, formatter)); cb.setPreferredSize(new Dimension(150,25)); cb.setSelectedIndex(0); pr.add(cb); getContentPane().add(pr); addWindowListener(new MyWindowListener()); setVisible(true); } public static void main(String args[]) { new JFormattedComboBoxSample(); } }
FieldModel
,
AS400FieldModel
,
JFormattedTextField
,
FormattedComboBoxEditor
,
DataAttributes
,
EditcodeEditwordFormatter
,
ComparisonRangeValidator
,
NumericCharacterDocument
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComboBox |
---|
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager |
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.JComboBox |
---|
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder |
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 java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JFormattedComboBox()
Constructs a new JFormattedComboBox. |
|
JFormattedComboBox(ComboBoxModel aModel)
Creates a JFormattedComboBox that takes its items from an existing ComboBoxDataModel. |
|
JFormattedComboBox(ComboBoxModel aModel,
FieldModel fm)
Creates a JFormattedComboBox that takes its items from an existing ComboBoxDataModel and in specified field model. |
|
JFormattedComboBox(FieldModel fm)
Creates a JFormattedComboBox with the specified field model. |
|
JFormattedComboBox(Object[] items)
Creates a JFormattedComboBox that contains the elements in the specified array. |
|
JFormattedComboBox(Object[] items,
FieldModel fm)
Creates a JFormattedComboBox that contains the elements in the specified array and field model. |
|
JFormattedComboBox(Vector items)
Creates a JFormattedComboBox that contains the elements in the specified Vector. |
|
JFormattedComboBox(Vector items,
FieldModel fm)
Creates a JFormattedComboBox that contains the elements in the specified Vector and with field model. |
Method Summary | |
---|---|
void |
addItem(Object anObject)
Adds an item to the item list. |
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()
|
Font |
getFont()
|
FormattedComboBoxEditor |
getFormattedComboBoxEditor()
|
Object |
getSelectedItemFormattedValue()
The formatted value of the selected item is returned. |
Object |
getSelectedItemInternalValue()
The internal value of the selected item is returned. |
String[] |
getValues()
|
void |
setFieldModel(FieldModel fm)
Sets the fieldModel property (com.ibm.etools.iseries.ui.FieldModel) value. |
void |
setFont(Font f)
Sets the font property (java.awt.Font) value. |
void |
setFormattedComboBoxEditor(FormattedComboBoxEditor ed)
Sets the formattedComboBoxEditor property (com.ibm.etools.iseries.ui.FormattedComboBoxEditor) value. |
void |
setSelectedItem(Object anObject)
Insert the method's description here. |
void |
setValues(String[] v)
To set the JFormattedComboBox with a set of String values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.event.ActionListener |
---|
actionPerformed |
Field Detail |
---|
public static final String Copyright
Constructor Detail |
---|
public JFormattedComboBox()
public JFormattedComboBox(Object[] items)
items
- java.lang.Object[]public JFormattedComboBox(Object[] items, FieldModel fm)
items
- java.lang.Object[]fm
- com.ibm.etools.iseries.ui.FieldModelpublic JFormattedComboBox(FieldModel fm)
fm
- com.ibm.etools.iseries.ui.FieldModelpublic JFormattedComboBox(Vector items)
items
- java.util.Vectorpublic JFormattedComboBox(Vector items, FieldModel fm)
items
- Vectorfm
- com.ibm.etools.iseries.ui.FieldModelpublic JFormattedComboBox(ComboBoxModel aModel)
aModel
- javax.swing.ComboBoxModelpublic JFormattedComboBox(ComboBoxModel aModel, FieldModel fm)
aModel
- javax.swing.ComboBoxModelfm
- com.ibm.etools.iseries.ui.FieldModelMethod Detail |
---|
public void addItem(Object anObject)
addItem
in class JComboBox
anObject
- java.lang.Objectpublic String convertInternalToUnformatted(String value)
value
- java.lang.String
public String convertUnformattedToInternal(String text)
value
- java.lang.String
public static String Copyright()
public FieldModel getFieldModel()
getFieldModel
in interface JFormattedComponent
public Font getFont()
getFont
in interface MenuContainer
getFont
in class Component
public FormattedComboBoxEditor getFormattedComboBoxEditor()
public Object getSelectedItemFormattedValue()
public Object getSelectedItemInternalValue()
public String[] getValues()
public void setFieldModel(FieldModel fm)
setFieldModel
in interface JFormattedComponent
fm
- The new value for the property.getFieldModel()
public void setFont(Font f)
setFont
in class JComponent
f
- The new value for the property.getFont()
public void setFormattedComboBoxEditor(FormattedComboBoxEditor ed)
ed
- The new value for the property.getFormattedComboBoxEditor()
public void setSelectedItem(Object anObject)
setSelectedItem
in class JComboBox
anObject
- java.lang.Objectpublic void setValues(String[] v)
v
- The new value for the property.getValues()
|
Rational Developer for Power Systems Software V7.6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |