Rational Developer for Power Systems Software
V7.6

com.ibm.etools.iseries.ui
Class JFormattedComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.ibm.etools.iseries.ui.JFormattedComboBox
All Implemented Interfaces:
JFormattedComponent, ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener
Direct Known Subclasses:
JFormattedComboBoxCellEditor

public class JFormattedComboBox
extends JComboBox
implements JFormattedComponent, ActionListener

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();
 }
 }
 
 
 

See Also:
FieldModel, AS400FieldModel, JFormattedTextField, FormattedComboBoxEditor, DataAttributes, EditcodeEditwordFormatter, ComparisonRangeValidator, NumericCharacterDocument, Serialized Form

Nested 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 javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setUI, showPopup, 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, 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, setFocusTraversalKeys, 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, 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, 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, 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
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

Copyright

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

JFormattedComboBox

public JFormattedComboBox()
Constructs a new JFormattedComboBox.


JFormattedComboBox

public JFormattedComboBox(Object[] items)
Creates a JFormattedComboBox that contains the elements in the specified array.

Parameters:
items - java.lang.Object[]

JFormattedComboBox

public JFormattedComboBox(Object[] items,
                          FieldModel fm)
Creates a JFormattedComboBox that contains the elements in the specified array and field model.

Parameters:
items - java.lang.Object[]
fm - com.ibm.etools.iseries.ui.FieldModel

JFormattedComboBox

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

Parameters:
fm - com.ibm.etools.iseries.ui.FieldModel

JFormattedComboBox

public JFormattedComboBox(Vector items)
Creates a JFormattedComboBox that contains the elements in the specified Vector.

Parameters:
items - java.util.Vector

JFormattedComboBox

public JFormattedComboBox(Vector items,
                          FieldModel fm)
Creates a JFormattedComboBox that contains the elements in the specified Vector and with field model.

Parameters:
items - Vector
fm - com.ibm.etools.iseries.ui.FieldModel

JFormattedComboBox

public JFormattedComboBox(ComboBoxModel aModel)
Creates a JFormattedComboBox that takes its items from an existing ComboBoxDataModel.

Parameters:
aModel - javax.swing.ComboBoxModel

JFormattedComboBox

public JFormattedComboBox(ComboBoxModel aModel,
                          FieldModel fm)
Creates a JFormattedComboBox that takes its items from an existing ComboBoxDataModel and in specified field model.

Parameters:
aModel - javax.swing.ComboBoxModel
fm - com.ibm.etools.iseries.ui.FieldModel
Method Detail

addItem

public void addItem(Object anObject)
Adds an item to the item list.

Overrides:
addItem in class JComboBox
Parameters:
anObject - java.lang.Object

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

getFont

public Font getFont()
Specified by:
getFont in interface MenuContainer
Overrides:
getFont in class Component

getFormattedComboBoxEditor

public FormattedComboBoxEditor getFormattedComboBoxEditor()

getSelectedItemFormattedValue

public Object getSelectedItemFormattedValue()
The formatted value of the selected item is returned.

Returns:
java.lang.Object

getSelectedItemInternalValue

public Object getSelectedItemInternalValue()
The internal value of the selected item is returned.

Returns:
java.lang.Object

getValues

public String[] getValues()

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()

setFont

public void setFont(Font f)
Sets the font property (java.awt.Font) value.

Overrides:
setFont in class JComponent
Parameters:
f - The new value for the property.
See Also:
getFont()

setFormattedComboBoxEditor

public void setFormattedComboBoxEditor(FormattedComboBoxEditor ed)
Sets the formattedComboBoxEditor property (com.ibm.etools.iseries.ui.FormattedComboBoxEditor) value.

Parameters:
ed - The new value for the property.
See Also:
getFormattedComboBoxEditor()

setSelectedItem

public void setSelectedItem(Object anObject)
Insert the method's description here.

Overrides:
setSelectedItem in class JComboBox
Parameters:
anObject - java.lang.Object

setValues

public void setValues(String[] v)
To set the JFormattedComboBox with a set of String values. All current items in the combo box are removed and the new values in the String array v are added. If JFormattedComboBox is not using the default values of an AS400FieldModel, setValues method should be called after setFieldModel method, because the default values of an AS400FieldModel is set to length of 10 in character type, and if the values in the String array exceed length of 10, then InvalidDataException will be thrown while setting the values.

Parameters:
v - The new value for the property.
See Also:
getValues()

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.