JIDE 3.5.15

com.jidesoft.combobox
Class AbstractComboBox.EditorComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.combobox.AbstractComboBox.EditorComponent
All Implemented Interfaces:
AlignmentSupport, ImageObserver, MenuContainer, Serializable, Accessible, ComboBoxEditor
Direct Known Subclasses:
AbstractComboBox.DefaultRendererComponent, AbstractComboBox.DefaultTextFieldEditorComponent, AbstractComboBox.SpinnerEditorComponent
Enclosing class:
AbstractComboBox

public abstract class AbstractComboBox.EditorComponent
extends JPanel
implements ComboBoxEditor, AlignmentSupport

The EditorComponent is the one that used as editor. If you want to create your own EditorComponent that can be used in AbstractComboBox, you should always extend this class. EditorComponent is actually a JPanel. So you create whatever component you want to use it as editor and add it using BorderLayout to this EditorComponent. For example, the code below creates a JTextField as editor and add it to the EditorComponent. You can put this code in the constructor.

 if (LookAndFeelFactory.isLnfInUse(LookAndFeelFactory.AQUA_LNF)) {
     setLayout(new BorderLayout(0, 0));
 }
 else {
     setLayout(new BorderLayout(2, 2));
     setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
 }
 _textField = createTextField();
 if (!LookAndFeelFactory.isLnfInUse(LookAndFeelFactory.AQUA_LNF)
 || AbstractComboBox.this.getClientProperty(CLIENT_PROPERTY_TABLE_CELL_EDITOR ||
 AbstractComboBox.this.getClientProperty(CLIENT_PROPERTY_TABLE_CELL_RENDERER) instanceof TableCellRenderer)
 instanceof CellEditor) {
     _textField.setBorder(BorderFactory.createEmptyBorder());
 }
 add(_textField, BorderLayout.CENTER);
 
It has nothing but a value. Subclass should implement stringToObject which can convert from the text to the actual value.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
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
protected  Class<?> _class
           
protected  Object _value
           
 
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
AbstractComboBox.EditorComponent(Class<?> clazz)
          Constructs an EditorComponent for a specified type.
 
Method Summary
protected  String convertElementToString(Object value)
          Converts the value to string so that it can display in text field.
protected  Object convertStringToElement(String text)
          Converts string to a value.
 int getHorizontalAlignment()
          Returns the horizontal alignment of the content.
 Object getItem()
          Gets the item (aka value) from this editor component.
 Dimension getPreferredSize()
          Gets the default preferred size {100, 18}.
abstract  String getText()
          Gets the text.
 int getVerticalAlignment()
          Returns the vertical alignment of the content.
abstract  boolean isEditable()
          Gets the editable attribute.
protected  void registerKeys(JComponent component)
           
abstract  void setEditable(boolean editable)
          Sets the editable attribute.
 void setHorizontalAlignment(int alignment)
          Sets the horizontal alignment of the content.
 void setItem(Object value)
          Sets the item (aka value) of the editor component.
abstract  void setText(String text)
          Sets the text.
 void setVerticalAlignment(int alignment)
          Sets the vertical alignment of the content.
protected  void textChanged()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, 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, 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 javax.swing.ComboBoxEditor
addActionListener, getEditorComponent, removeActionListener, selectAll
 

Field Detail

_class

protected Class<?> _class

_value

protected Object _value
Constructor Detail

AbstractComboBox.EditorComponent

public AbstractComboBox.EditorComponent(Class<?> clazz)
Constructs an EditorComponent for a specified type.

Parameters:
clazz - the type
Method Detail

getText

public abstract String getText()
Gets the text. Since subclass can use different components to edit text, this method will provide a common interface to retrieve text from those different components.

Returns:
the text.

setText

public abstract void setText(String text)
Sets the text. Since subclass can use different components to edit text, this method will provide a common interface to set text to those different components.

Parameters:
text - the text

setEditable

public abstract void setEditable(boolean editable)
Sets the editable attribute. Since subclass can use different components to edit text, this method will provide a common interface to change editable attribute to those different components.

Parameters:
editable - true or false.

isEditable

public abstract boolean isEditable()
Gets the editable attribute. Since subclass can use different components to edit text, this method will provide a common interface to check editable attribute for those different components.

Returns:
true if the editor component is editable

getItem

public Object getItem()
Gets the item (aka value) from this editor component.

The implementation in base class did the conversion from text that is displayed in the JTextField to the Object that is clazz type using ObjectConverterManager. If you want to do your own conversion, you should override this method.

Specified by:
getItem in interface ComboBoxEditor
Returns:
the item from this editor component.

convertElementToString

protected String convertElementToString(Object value)
Converts the value to string so that it can display in text field.

Parameters:
value - the value to be converted to string
Returns:
the string representation of the value.

convertStringToElement

protected Object convertStringToElement(String text)
Converts string to a value.

Parameters:
text - the text to be converted to element
Returns:
the value.

setItem

public void setItem(Object value)
Sets the item (aka value) of the editor component. Subclass can override this method to set the value other components. For example ColorEditorComponent has a color component which displays the actual color. So it overrides this method and set the value (which is a Color) to the color component.

The implementation in base class did the conversion from Object to the text that will be displayed in the JTextField using ObjectConverterManager. If you want to do your own conversion, you should override this method too.

Specified by:
setItem in interface ComboBoxEditor
Parameters:
value - the new value

textChanged

protected void textChanged()

registerKeys

protected void registerKeys(JComponent component)

getPreferredSize

public Dimension getPreferredSize()
Gets the default preferred size {100, 18}.

Overrides:
getPreferredSize in class JComponent
Returns:
preferred size

getHorizontalAlignment

public int getHorizontalAlignment()
Description copied from interface: AlignmentSupport
Returns the horizontal alignment of the content. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.

Specified by:
getHorizontalAlignment in interface AlignmentSupport
Returns:
the horizontalAlignment property, one of the following values:
  • SwingConstants.RIGHT
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)
Description copied from interface: AlignmentSupport
Sets the horizontal alignment of the content. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.

Specified by:
setHorizontalAlignment in interface AlignmentSupport
Parameters:
alignment - the alignment value, one of the following values:
  • SwingConstants.RIGHT
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING

getVerticalAlignment

public int getVerticalAlignment()
Description copied from interface: AlignmentSupport
Returns the vertical alignment of the content.

Specified by:
getVerticalAlignment in interface AlignmentSupport
Returns:
the verticalAlignment property, one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM

setVerticalAlignment

public void setVerticalAlignment(int alignment)
Description copied from interface: AlignmentSupport
Sets the vertical alignment of the content.

Specified by:
setVerticalAlignment in interface AlignmentSupport
Parameters:
alignment - one of the following values:
  • SwingConstants.CENTER (the default)
  • SwingConstants.TOP
  • SwingConstants.BOTTOM

JIDE 3.5.15